<commit_before><?php
class Kwc_Form_Dynamic_Form_Component extends Kwc_Form_Component
{
    public static function getSettings()
    {
        $ret = parent::getSettings();
        $ret['generators']['child']['component']['success'] = 'Kwc_Form_Dynamic_Form_Success_Component';
        return $ret;
    }

    public function getTemplateVars()
    {
        $ret = parent::getTemplateVars();
        $ret['paragraphs'] = $this->getData()->parent->getChildComponent('-paragraphs');
        return $ret;
    }

    protected function _initForm()
    {
        $this->_form = new Kwf_Form('form');
        $referenceMap = array();
        $dependentModels = array();
        foreach ($this->getData()->parent->getChildComponent('-paragraphs')->getRecursiveChildComponents(array('flags'=>array('formField'=>true))) as $c) {
            $f = $c->getComponent()->getFormField();
            $this->_form->fields->add($f);
            if ($f instanceof Kwf_Form_Field_File) {
                $referenceMap[$f->getName()] = array(
                    'refModelClass' => 'Kwf_Uploads_Model',
                    'column' => $f->getName()
                );
            } else if ($f instanceof Kwf_Form_Field_MultiCheckbox) {
                $dependentModels[$f->getName()] = 'Kwc_Form_Field_MultiCheckbox_DataToValuesModel';
            }
        }
        $this->_form->setModel($this->_createModel(array('referenceMap'=>$referenceMap,
                                                         'dependentModels'=>$dependentModels)));
    }

    protected function _createModel(array $config)
    {
        $config['componentClass'] = get_class($this);
        $config['mailerClass'] = 'Kwf_Mail';
        return new Kwc_Form_Dynamic_Form_MailModel($config);
    }

    protected function _beforeInsert(Kwf_Model_Row_Interface $row)
    {
        parent::_beforeInsert($row);
        $row->component_id = $this->getData()->parent->dbId;
    }

    protected function _afterInsert(Kwf_Model_Row_Interface $row)
    {
        parent::_afterInsert($row);

        if (isset($_SERVER['HTTP_HOST'])) {
            $host = $_SERVER['HTTP_HOST'];
        } else {
            $host = Kwf_Registry::get('config')->server->domain;
        }
        if (substr($host, 0, 4) == 'www.') {
            $host = substr($host, 4);
        }
        $row->setFrom("noreply@$host");
        $settings = $this->getData()->parent->getComponent()->getMailSettings();
        $row->addTo($settings['recipient']);
        $row->addCc($settings['recipient_cc']);
        $row->setSubject($settings['subject']);
        $msg = '';
        foreach ($this->getData()->parent->getChildComponent('-paragraphs')->getRecursiveChildComponents(array('flags'=>array('formField'=>true))) as $c) {
            $f = $c->getComponent()->getFormField();
            if ($f->getName()) {
                if ($f instanceof Kwf_Form_Field_File) {
                    $uploadRow = $row->getParentRow($f->getName());
                    if ($uploadRow) {
                        $row->addAttachment($uploadRow);
                        $msg .= $f->getFieldLabel().": {$uploadRow->filename}.{$uploadRow->extension} ".trlKwf('attached')."\n";
                    }
                } else if ($f instanceof Kwf_Form_Field_Checkbox) {
                    $label = $f->getFieldLabel();
                    if (!$label) {
                        $label = $f->getBoxLabel();
                    }
                    if ($label) {
                        if ($row->{$f->getName()}) {
                            $msg .= $label.': '.$this->getData()->trlKwf('Yes')."\n";
                        } else {
                            $msg .= $label.': '.$this->getData()->trlKwf('No')."\n";
                        }
                    }
                } else if ($f instanceof Kwf_Form_Field_MultiCheckbox) {
                    $values = array();
                    foreach ($row->getChildRows($f->getName()) as $r) {
                        if (substr($r->value_id, 0, strlen($f->getName())) == $f->getName()) {
                            $values[] = $r->value_id;
                        }
                    }
                    $valuesText = array();
                    foreach ($f->getValues() as $k=>$i) {
                        if (in_array($k, $values)) {
                            $valuesText[] = $i;
                        }
                    }
                    $msg .= $f->getFieldLabel().': '.implode(', ', $valuesText)."\n";

                } else {
                    $msg .= $f->getFieldLabel().': '.$row->{$f->getName()}."\n";
                }
            }
        }

        $row->sent_mail_content_text = $msg;

        $this->_beforeSendMail($row);

        $row->sendMail(); //manuell aufrufen weils beim speichern nicht automatisch gemacht wird (da da der content nocht nicht vorhanden ist)

        if ($settings['send_confirm_mail']) {
            $c = Kwf_Component_Data_Root::getInstance()->getComponentById($settings['confirm_field_component_id']);
            if ($c && ($recipient = $row->{$c->getComponent()->getFormField()->getName()})) {
                $mail = new Kwf_Mail();
                $body = $this->getData()->trlKwf('Thank you for your inquiry, it will be processed as soon as posible.');
                $body .= "\n\n";
                $body .= $msg;
                $mail->setSubject($settings['confirm_subject']);
                $mail->setBodyText($body);
                $mail->addTo($recipient);
                $mail->send();
            }
        }
    }

    protected function _beforeSendMail(Kwf_Model_Row_Interface $row)
    {
    }<commit_msg>properly format dateField values<commit_after><?php
class Kwc_Form_Dynamic_Form_Component extends Kwc_Form_Component
{
    public static function getSettings()
    {
        $ret = parent::getSettings();
        $ret['generators']['child']['component']['success'] = 'Kwc_Form_Dynamic_Form_Success_Component';
        return $ret;
    }

    public function getTemplateVars()
    {
        $ret = parent::getTemplateVars();
        $ret['paragraphs'] = $this->getData()->parent->getChildComponent('-paragraphs');
        return $ret;
    }

    protected function _initForm()
    {
        $this->_form = new Kwf_Form('form');
        $referenceMap = array();
        $dependentModels = array();
        foreach ($this->getData()->parent->getChildComponent('-paragraphs')->getRecursiveChildComponents(array('flags'=>array('formField'=>true))) as $c) {
            $f = $c->getComponent()->getFormField();
            $this->_form->fields->add($f);
            if ($f instanceof Kwf_Form_Field_File) {
                $referenceMap[$f->getName()] = array(
                    'refModelClass' => 'Kwf_Uploads_Model',
                    'column' => $f->getName()
                );
            } else if ($f instanceof Kwf_Form_Field_MultiCheckbox) {
                $dependentModels[$f->getName()] = 'Kwc_Form_Field_MultiCheckbox_DataToValuesModel';
            }
        }
        $this->_form->setModel($this->_createModel(array('referenceMap'=>$referenceMap,
                                                         'dependentModels'=>$dependentModels)));
    }

    protected function _createModel(array $config)
    {
        $config['componentClass'] = get_class($this);
        $config['mailerClass'] = 'Kwf_Mail';
        return new Kwc_Form_Dynamic_Form_MailModel($config);
    }

    protected function _beforeInsert(Kwf_Model_Row_Interface $row)
    {
        parent::_beforeInsert($row);
        $row->component_id = $this->getData()->parent->dbId;
    }

    protected function _afterInsert(Kwf_Model_Row_Interface $row)
    {
        parent::_afterInsert($row);

        if (isset($_SERVER['HTTP_HOST'])) {
            $host = $_SERVER['HTTP_HOST'];
        } else {
            $host = Kwf_Registry::get('config')->server->domain;
        }
        if (substr($host, 0, 4) == 'www.') {
            $host = substr($host, 4);
        }
        $row->setFrom("noreply@$host");
        $settings = $this->getData()->parent->getComponent()->getMailSettings();
        $row->addTo($settings['recipient']);
        $row->addCc($settings['recipient_cc']);
        $row->setSubject($settings['subject']);
        $msg = '';
        foreach ($this->getData()->parent->getChildComponent('-paragraphs')->getRecursiveChildComponents(array('flags'=>array('formField'=>true))) as $c) {
            $f = $c->getComponent()->getFormField();
            if ($f->getName()) {
                if ($f instanceof Kwf_Form_Field_File) {
                    $uploadRow = $row->getParentRow($f->getName());
                    if ($uploadRow) {
                        $row->addAttachment($uploadRow);
                        $msg .= $f->getFieldLabel().": {$uploadRow->filename}.{$uploadRow->extension} ".trlKwf('attached')."\n";
                    }
                } else if ($f instanceof Kwf_Form_Field_Checkbox) {
                    $label = $f->getFieldLabel();
                    if (!$label) {
                        $label = $f->getBoxLabel();
                    }
                    if ($label) {
                        if ($row->{$f->getName()}) {
                            $msg .= $label.': '.$this->getData()->trlKwf('Yes')."\n";
                        } else {
                            $msg .= $label.': '.$this->getData()->trlKwf('No')."\n";
                        }
                    }
                } else if ($f instanceof Kwf_Form_Field_MultiCheckbox) {
                    $values = array();
                    foreach ($row->getChildRows($f->getName()) as $r) {
                        if (substr($r->value_id, 0, strlen($f->getName())) == $f->getName()) {
                            $values[] = $r->value_id;
                        }
                    }
                    $valuesText = array();
                    foreach ($f->getValues() as $k=>$i) {
                        if (in_array($k, $values)) {
                            $valuesText[] = $i;
                        }
                    }
                    $msg .= $f->getFieldLabel().': '.implode(', ', $valuesText)."\n";
                } else if ($f instanceof Kwf_Form_Field_DateField) {
                    if ($f->getFieldLabel()) $msg .= $f->getFieldLabel().': ';
                    $t = strtotime($row->{$f->getName()});
                    $msg .= date($this->getData()->trlKwf('Y-m-d'), $t)."\n";
                } else {
                    if ($f->getFieldLabel()) $msg .= $f->getFieldLabel().': ';
                    $msg .= $row->{$f->getName()}."\n";
                }
            }
        }

        $row->sent_mail_content_text = $msg;

        $this->_beforeSendMail($row);

        $row->sendMail(); //manuell aufrufen weils beim speichern nicht automatisch gemacht wird (da da der content nocht nicht vorhanden ist)

        if ($settings['send_confirm_mail']) {
            $c = Kwf_Component_Data_Root::getInstance()->getComponentById($settings['confirm_field_component_id']);
            if ($c && ($recipient = $row->{$c->getComponent()->getFormField()->getName()})) {
                $mail = new Kwf_Mail();
                $body = $this->getData()->trlKwf('Thank you for your inquiry, it will be processed as soon as posible.');
                $body .= "\n\n";
                $body .= $msg;
                $mail->setSubject($settings['confirm_subject']);
                $mail->setBodyText($body);
                $mail->addTo($recipient);
                $mail->send();
            }
        }
    }

    protected function _beforeSendMail(Kwf_Model_Row_Interface $row)
    {
    }
{'fraction_non_alphanumeric': 0.16508181273023215, 'fraction_numerical': 0.0006853422427824896, 'mean_word_length': 1.7650402652771198, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 186, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7640755', 'n_tokens_mistral': 3281, 'n_tokens_neox': 3149, 'n_words': 506}