<commit_before><?php
class Vps_Form_Field_NumberField extends Vps_Form_Field_TextField
{
    public function __construct($field_name = null, $field_label = null)
    {
        parent::__construct($field_name, $field_label);
        $this->setXtype('numberfield');
        $this->setDecimalSeparator(trlcVps('decimal separator', '.'));
        $this->setDecimalPrecision(2);
    }
    protected function _addValidators()
    {
        parent::_addValidators();

        if ($this->getMaxValue()) {
            $this->addValidator(new Zend_Validate_LessThan($this->getMaxValue()+0.000001));
        }
        if ($this->getMinValue()) {
            $this->addValidator(new Zend_Validate_GreaterThan($this->getMinValue()-0.000001));
        }
        if ($this->getAllowNegative() === false) {
            $this->addValidator(new Vps_Validate_NotNegative());
        }
        if ($this->getAllowDecimals() === false) {
            $this->addValidator(new Vps_Validate_Digits(true));
        } else {
            $l = null;
            if (trlcVps('locale', 'C') != 'C') {
                $l = Zend_Locale::findLocale(trlcVps('locale', 'C'));
            }
            $this->addValidator(new Zend_Validate_Float($l));
        }
    }

    protected function _getValueFromPostData($postData)
    {
        $fieldName = $this->getFieldName();
        if (!isset($postData[$fieldName])) $postData[$fieldName] = null;
        if ($postData[$fieldName] == ''
            && !(is_int($postData[$fieldName]) && $postData[$fieldName] === 0)
        ) {
            $postData[$fieldName] = null;
        }
        if (!is_null($postData[$fieldName])) {
            if ($this->getDecimalSeparator() != '.') {
                $postData[$fieldName] = str_replace($this->getDecimalSeparator(), '.', $postData[$fieldName]);
            }
            $postData[$fieldName] = (float)$postData[$fieldName];
            $postData[$fieldName] = round($postData[$fieldName], $this->getDecimalPrecision());
        }
        return $postData[$fieldName];
    }

    protected function _getOutputValueFromValues($values)
    {
        $ret = parent::_getOutputValueFromValues($values);
        $ret = number_format($ret, $this->getDecimalPrecision(), $this->getDecimalSeparator(), '');
        return $ret;
    }

    public static function getSettings()
    {
        return array_merge(parent::getSettings(), array(
            'componentName' => trlVps('Number Field')
        ));
    }
}
<commit_msg>ein numberField kann auch leer sein<commit_after><?php
class Vps_Form_Field_NumberField extends Vps_Form_Field_TextField
{
    public function __construct($field_name = null, $field_label = null)
    {
        parent::__construct($field_name, $field_label);
        $this->setXtype('numberfield');
        $this->setDecimalSeparator(trlcVps('decimal separator', '.'));
        $this->setDecimalPrecision(2);
    }
    protected function _addValidators()
    {
        parent::_addValidators();

        if ($this->getMaxValue()) {
            $this->addValidator(new Zend_Validate_LessThan($this->getMaxValue()+0.000001));
        }
        if ($this->getMinValue()) {
            $this->addValidator(new Zend_Validate_GreaterThan($this->getMinValue()-0.000001));
        }
        if ($this->getAllowNegative() === false) {
            $this->addValidator(new Vps_Validate_NotNegative());
        }
        if ($this->getAllowDecimals() === false) {
            $this->addValidator(new Vps_Validate_Digits(true));
        } else {
            $l = null;
            if (trlcVps('locale', 'C') != 'C') {
                $l = Zend_Locale::findLocale(trlcVps('locale', 'C'));
            }
            $this->addValidator(new Zend_Validate_Float($l));
        }
    }

    protected function _getValueFromPostData($postData)
    {
        $fieldName = $this->getFieldName();
        if (!isset($postData[$fieldName])) $postData[$fieldName] = null;
        if ($postData[$fieldName] == ''
            && !(is_int($postData[$fieldName]) && $postData[$fieldName] === 0)
        ) {
            $postData[$fieldName] = null;
        }
        if (!is_null($postData[$fieldName])) {
            if ($this->getDecimalSeparator() != '.') {
                $postData[$fieldName] = str_replace($this->getDecimalSeparator(), '.', $postData[$fieldName]);
            }
            $postData[$fieldName] = (float)$postData[$fieldName];
            $postData[$fieldName] = round($postData[$fieldName], $this->getDecimalPrecision());
        }
        return $postData[$fieldName];
    }

    protected function _getOutputValueFromValues($values)
    {
        $ret = parent::_getOutputValueFromValues($values);
        if (!$ret) return '';
        $ret = number_format($ret, $this->getDecimalPrecision(), $this->getDecimalSeparator(), '');
        return $ret;
    }

    public static function getSettings()
    {
        return array_merge(parent::getSettings(), array(
            'componentName' => trlVps('Number Field')
        ));
    }
}

{'fraction_non_alphanumeric': 0.16021548284118117, 'fraction_numerical': 0.006384676775738229, 'mean_word_length': 2.648471615720524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '7563709', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1473, 'n_words': 212}