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

public static range ( $value, $lower = null, $upper = null )
 /**
  * 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;
 }
Пример #2
0
 /**
  * testRange method
  *
  * @return void
  */
 public function testRange()
 {
     $this->assertFalse(Validation::range(20, 100, 1));
     $this->assertTrue(Validation::range(20, 1, 100));
     $this->assertFalse(Validation::range(0.5, 1, 100));
     $this->assertTrue(Validation::range(0.5, 0, 100));
     $this->assertTrue(Validation::range(5));
     $this->assertTrue(Validation::range(-5, -10, 1));
     $this->assertFalse(Validation::range('word'));
 }
Пример #3
0
 /**
  * Test range type checks
  *
  * @return void
  */
 public function testRangeTypeChecks()
 {
     $this->assertFalse(Validation::range('\\x028', 1, 5), 'hexish encoding fails');
     $this->assertFalse(Validation::range('0b010', 1, 5), 'binary string data fails');
     $this->assertFalse(Validation::range('0x01', 1, 5), 'hex string data fails');
     $this->assertFalse(Validation::range('0x1', 1, 5), 'hex string data fails');
     $this->assertFalse(Validation::range('\\x028', 1, 5), 'hexish encoding fails');
     $this->assertFalse(Validation::range('0b010', 1, 5), 'binary string data fails');
     $this->assertFalse(Validation::range('0x02', 1, 5), 'hex string data fails');
 }
Пример #4
0
 /**
  * @testdox range should return false to non-numerical value
  */
 public function testInvalidRangeWithNonNumericValue()
 {
     $value = 'Non numeric';
     $this->assertFalse(Validation::range($value));
 }
 /**
  * checkDateRange
  *
  * @param array $question question
  * @param string $answer answer value
  * @return array error message
  */
 public function checkDateRange($question, $answer)
 {
     $errors = array();
     if ($question['is_range'] == QuestionnairesComponent::USES_USE) {
         if (!Validation::range(strtotime($answer), strtotime($question['min']) - 1, strtotime($question['max']) + 1)) {
             if ($question['question_type_option'] == QuestionnairesComponent::TYPE_OPTION_DATE) {
                 $fmt = 'Y-m-d';
             } elseif ($question['question_type_option'] == QuestionnairesComponent::TYPE_OPTION_TIME) {
                 $fmt = 'H:i';
             } else {
                 $fmt = 'Y-m-d H:i';
             }
             $errors[] = sprintf(__d('questionnaires', 'Please enter the answer between %s and %s.', date($fmt, strtotime($question['min'])), date($fmt, strtotime($question['max']))));
         }
     }
     return $errors;
 }
Пример #6
0
 /**
  * パスワードの確認
  * 入力フォームと登録時のバリデーションの文字数が異なるため、独自実装する
  * 
  * @param type $fields
  * @return boolean
  */
 function checkRangePassword($fields = array())
 {
     if (isset($this->data["TmpUser"]["id"])) {
         return true;
     } else {
         return Validation::range(mb_strlen($this->data["TmpUser"]["password"]), 5, 21);
     }
 }
 /**
  * _validateDatetime 日付・時間の正当性
  *
  * @param object &$model use model
  * @param array $question 登録データに対応する項目
  * @param string $answer 登録データ
  * @return bool
  */
 protected function _validateTimeRange(&$model, $question, $answer)
 {
     if ($question['is_range'] != RegistrationsComponent::USES_USE) {
         return true;
     }
     $rangeResult = Validation::range(strtotime($answer), strtotime($question['min']) - 1, strtotime($question['max']) + 1);
     if ($rangeResult) {
         return true;
     }
     $model->validationErrors['answer_value'][] = sprintf(__d('registrations', 'Please enter the answer between %s and %s.'), date($this->_datetimeFormat[$question['question_type_option']], strtotime($question['min'])), date($this->_datetimeFormat[$question['question_type_option']], strtotime($question['max'])));
     return false;
 }