maxLength() публичный статический Метод

public static maxLength ( $value, $length )
 /**
  * answerValidation 登録内容の正当性
  *
  * @param object &$model use model
  * @param array $data Validation対象データ
  * @param array $question 登録データに対応する項目
  * @param array $allAnswers 入力された登録すべて
  * @return bool
  */
 public function answerTextValidation(&$model, $data, $question, $allAnswers)
 {
     if (!in_array($question['question_type'], $this->_textValidateType)) {
         return true;
     }
     $ret = true;
     // 数値型登録を望まれている場合
     if ($question['question_type_option'] == RegistrationsComponent::TYPE_OPTION_NUMERIC) {
         if (!Validation::numeric($data['answer_value'])) {
             $ret = false;
             $model->validationErrors['answer_value'][] = __d('registrations', 'Number required');
         }
         if ($question['is_range'] == RegistrationsComponent::USES_USE) {
             $rangeRes = Validation::range($data['answer_value'], intval($question['min']), intval($question['max']));
             if (!$rangeRes) {
                 $ret = false;
                 $model->validationErrors['answer_value'][] = sprintf(__d('registrations', 'Please enter the answer between %s and %s.'), $question['min'], $question['max']);
             }
         }
     } else {
         if ($question['is_range'] == RegistrationsComponent::USES_USE) {
             if (!Validation::minLength($data['answer_value'], intval($question['min'])) || !Validation::maxLength($data['answer_value'], intval($question['max']))) {
                 $ret = false;
                 $model->validationErrors['answer_value'][] = sprintf(__d('registrations', 'Please enter the answer between %s letters and %s letters.'), $question['min'], $question['max']);
             }
         }
     }
     return $ret;
 }
 /**
  * answerMaxLength 登録が登録フォームが許す最大長を超えていないかの確認
  *
  * @param object &$model use model
  * @param array $data Validation対象データ
  * @param array $question 登録データに対応する項目
  * @param int $max 最大長
  * @return bool
  */
 public function answerMaxLength(&$model, $data, $question, $max)
 {
     if ($question['question_type'] != $this->_myType) {
         return true;
     }
     return Validation::maxLength($data['answer_value'], $max);
 }
 /**
  * checkTextAreaAnswerValue 入力回答の正当性をチェックする
  *
  * @param object &$model use model
  * @param array &$data Postされた回答データ
  * @param array &$question 回答データに対応する質問
  * @param array &$answers all answer data of this question (for matrix)
  * @return array error messages
  */
 public function checkTextAreaAnswerValue(&$model, &$data, &$question, &$answers)
 {
     $errors = array();
     if (!Validation::maxLength($data, QuestionnairesComponent::QUESTIONNAIRE_MAX_ANSWER_LENGTH)) {
         $errors = array_merge($errors, sprintf(__d('questionnaires', 'the answer is too long. Please enter under %d letters.', QuestionnairesComponent::QUESTIONNAIRE_MAX_ANSWER_LENGTH)));
     }
     return $errors;
 }
Пример #4
0
 /**
  * testMaxLength method
  *
  * @return void
  */
 public function testMaxLength()
 {
     $this->assertTrue(Validation::maxLength('ab', 3));
     $this->assertTrue(Validation::maxLength('abc', 3));
     $this->assertTrue(Validation::maxLength('ÆΔΩЖÇ', 10));
     $this->assertFalse(Validation::maxLength('abcd', 3));
     $this->assertFalse(Validation::maxLength('ÆΔΩЖÇ', 3));
 }
Пример #5
0
 /**
  * @testdox maxLength should return false to strings exceeding specified length
  */
 public function testInvalidMaxLength()
 {
     $value = '424242';
     $this->assertFalse(Validation::maxLength($value, 5));
 }
 /**
  * Validates that at least one field is not empty
  * 
  * @param string $check field to check
  * @param string $params array of fields that are related
  * @return boolean true if at least one field has been filled, false otherwise
  * @author Jose Diaz-Gonzalez
  * @access public
  */
 function validateDependentFields(&$model, $check, $params = array())
 {
     $fieldKey = array_pop(array_keys($check));
     $i = count($params['fields']) + 1;
     $j = count($params['fields']);
     foreach ($params['fields'] as $fieldname) {
         if (empty($model->data[$model->alias][$fieldname])) {
             $i--;
         } else {
             if (!Validation::minLength($model->data[$model->alias][$fieldname], $params['minLength']) or !Validation::maxLength($model->data[$model->alias][$fieldname], $params['maxLength'])) {
                 $j--;
             }
         }
     }
     if (empty($model->data[$model->alias][$fieldKey])) {
         $i--;
     }
     if (Validation::minLength($model->data[$model->alias][$fieldKey], $params['minLength'])) {
         $j--;
     }
     if ($i === 0 or $j === 0) {
         return false;
     }
     return true;
 }
 /**
  * checkRange
  *
  * @param array $question question
  * @param string $answer answer value
  * @return array error message
  */
 public function checkRange($question, $answer)
 {
     $errors = array();
     // 現在の機能は数値型か文字列型のみ
     if ($question['question_type_option'] == QuestionnairesComponent::TYPE_OPTION_NUMERIC) {
         if ($question['is_range'] == QuestionnairesComponent::USES_USE) {
             if (!Validation::range($answer, intval($question['min']), intval($question['max']))) {
                 $errors[] = sprintf(__d('questionnaires', 'Please enter the answer between %s and %s.', $question['min'], $question['max']));
             }
         }
     } else {
         if ($question['is_range'] == QuestionnairesComponent::USES_USE) {
             if (!Validation::minLength($answer, intval($question['min'])) || !Validation::maxLength($answer, intval($question['max']))) {
                 $errors[] = sprintf(__d('questionnaires', 'Please enter the answer between %s letters and %s letters.', $question['min'], $question['max']));
             }
         }
     }
     return $errors;
 }