<commit_before><?php
abstract class Vps_Form_Field_SimpleAbstract extends Vps_Form_Field_Abstract
{
    public function load($row, $postData = array())
    {
        $ret = array();
        if (isset($postData[$this->getFieldName()])) {
            $ret[$this->getFieldName()] = $postData[$this->getFieldName()];
        } else {
            if ($this->getSave() !== false && $this->getInternalSave() !== false) {
                $ret[$this->getFieldName()] = $this->getData()->load($row);
            }
        }
        return array_merge($ret, parent::load($row, $postData));
    }

    protected function _addValidators()
    {
        parent::_addValidators();
    }

    public function validate($row, $postData)
    {
        $ret = parent::validate($row, $postData);

        if ($this->getInternalSave() !== false) {

            $data = $this->_getValueFromPostData($postData);

            $name = $this->getFieldLabel();
            if (!$name) $name = $this->getName();
            if ($this->getAllowBlank() === false
                || $this->getAllowBlank() === 0
                || $this->getAllowBlank() === '0') {
                $v = new Vps_Validate_NotEmpty();
                if (!$v->isValid($data)) {
                    $ret[] = $name.": ".implode("<br />\n", $v->getMessages());
                }
            }
            if ($data) {
                foreach ($this->getValidators() as $v) {
                    if ($v instanceof Vps_Validate_Row_Abstract) {
                        $v->setField($this->getName());
                        $isValid = $v->isValidRow($data, $row);
                    } else {
                        $isValid = $v->isValid($data);
                    }
                    if (!$isValid) {
                        $ret[] = $name.": ".implode("<br />\n", $v->getMessages());
                    }
                }
            }
        }
        return $ret;
    }

    public function prepareSave(Vps_Model_Row_Interface $row, $postData)
    {
        parent::prepareSave($row, $postData);
        if ($this->getSave() !== false && $this->getInternalSave() !== false) {
            $data = $this->_getValueFromPostData($postData);
            $this->getData()->save($row, $data);
        }
    }

    protected function _getValueFromPostData($postData)
    {
        $fieldName = $this->getFieldName();
        if (!isset($postData[$fieldName])) $postData[$fieldName] = null;
        return $postData[$fieldName];
    }
}<commit_msg>defaultValue berücksichtigen beim laden (für Vpc_Form)<commit_after><?php
abstract class Vps_Form_Field_SimpleAbstract extends Vps_Form_Field_Abstract
{
    public function load($row, $postData = array())
    {
        $ret = array();
        if (isset($postData[$this->getFieldName()])) {
            $ret[$this->getFieldName()] = $postData[$this->getFieldName()];
        } else {
            if ($this->getSave() !== false && $this->getInternalSave() !== false) {
                $ret[$this->getFieldName()] = $this->getData()->load($row);
            }
        }
        return array_merge($ret, parent::load($row, $postData));
    }

    protected function _addValidators()
    {
        parent::_addValidators();
    }

    public function validate($row, $postData)
    {
        $ret = parent::validate($row, $postData);

        if ($this->getInternalSave() !== false) {

            $data = $this->_getValueFromPostData($postData);

            $name = $this->getFieldLabel();
            if (!$name) $name = $this->getName();
            if ($this->getAllowBlank() === false
                || $this->getAllowBlank() === 0
                || $this->getAllowBlank() === '0') {
                $v = new Vps_Validate_NotEmpty();
                if (!$v->isValid($data)) {
                    $ret[] = $name.": ".implode("<br />\n", $v->getMessages());
                }
            }
            if ($data) {
                foreach ($this->getValidators() as $v) {
                    if ($v instanceof Vps_Validate_Row_Abstract) {
                        $v->setField($this->getName());
                        $isValid = $v->isValidRow($data, $row);
                    } else {
                        $isValid = $v->isValid($data);
                    }
                    if (!$isValid) {
                        $ret[] = $name.": ".implode("<br />\n", $v->getMessages());
                    }
                }
            }
        }
        return $ret;
    }

    public function prepareSave(Vps_Model_Row_Interface $row, $postData)
    {
        parent::prepareSave($row, $postData);
        if ($this->getSave() !== false && $this->getInternalSave() !== false) {
            $data = $this->_getValueFromPostData($postData);
            $this->getData()->save($row, $data);
        }
    }

    protected function _getValueFromPostData($postData)
    {
        $fieldName = $this->getFieldName();
        if (!isset($postData[$fieldName])) $postData[$fieldName] = null;
        return $postData[$fieldName];
    }

    public function processInput($postData)
    {
        $fieldName = $this->getFieldName();
        if (!isset($postData[$fieldName]) && $this->getDefaultValue()) {
            $postData[$fieldName] = $this->getDefaultValue();
        }
        return $postData;
    }
}
{'fraction_non_alphanumeric': 0.17091114883984154, 'fraction_numerical': 0.0007545746085644218, 'mean_word_length': 1.8008452192287374, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5504308', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1491, 'n_words': 259}