/**
  * @see ValueValidatorObject::doValidation
  *
  * @since 0.1
  *
  * @param mixed $value
  * @throws \Exception
  */
 public function doValidation($value)
 {
     if (!is_string($value)) {
         $this->addErrorMessage('Not a string');
         // TODO
         return;
     }
     $lowerBound = false;
     $upperBound = false;
     if (array_key_exists('length', $this->options)) {
         $lowerBound = $this->options['length'];
         $upperBound = $this->options['length'];
     } else {
         if (array_key_exists('minlength', $this->options)) {
             $lowerBound = $this->options['minlength'];
         }
         if (array_key_exists('maxlength', $this->options)) {
             $upperBound = $this->options['maxlength'];
         }
     }
     if ($lowerBound !== false || $upperBound !== false) {
         $rangeValidator = new RangeValidator();
         $rangeValidator->setRange($lowerBound, $upperBound);
         $this->runSubValidator(strlen($value), $rangeValidator, 'length');
     }
     // TODO: this needs tests
     if (array_key_exists('regex', $this->options)) {
         $match = preg_match($this->options['regex'], $value);
         if ($match === false) {
             throw new \Exception('The regex argument must be a valid Perl regular expression.');
         } elseif ($match === 0) {
             $this->addErrorMessage('String does not match the regular expression ' . $this->options['regex']);
         }
     }
 }
 protected function getPresentationClass($presentation, $questionName, $configs = null)
 {
     $event = new OW_Event('base.questions_field_get_label', array('presentation' => $presentation, 'fieldName' => $questionName, 'configs' => $configs, 'type' => 'edit'));
     OW::getEventManager()->trigger($event);
     $label = $event->getData();
     $class = null;
     $event = new OW_Event('base.questions_field_init', array('type' => 'search', 'presentation' => $presentation, 'fieldName' => $questionName, 'configs' => $configs));
     OW::getEventManager()->trigger($event);
     $class = $event->getData();
     if (empty($class)) {
         switch ($presentation) {
             case BOL_QuestionService::QUESTION_PRESENTATION_TEXT:
             case BOL_QuestionService::QUESTION_PRESENTATION_TEXTAREA:
                 $class = new TextField($questionName);
                 break;
             case BOL_QuestionService::QUESTION_PRESENTATION_CHECKBOX:
                 $class = new CheckboxField($questionName);
                 break;
             case BOL_QuestionService::QUESTION_PRESENTATION_RADIO:
             case BOL_QuestionService::QUESTION_PRESENTATION_SELECT:
             case BOL_QuestionService::QUESTION_PRESENTATION_MULTICHECKBOX:
                 $class = new Selectbox($questionName);
                 break;
             case BOL_QuestionService::QUESTION_PRESENTATION_BIRTHDATE:
             case BOL_QuestionService::QUESTION_PRESENTATION_AGE:
                 $class = new USEARCH_CLASS_AgeRangeField($questionName);
                 if (!empty($configs) && mb_strlen(trim($configs)) > 0) {
                     $configsList = json_decode($configs, true);
                     foreach ($configsList as $name => $value) {
                         if ($name = 'year_range' && isset($value['from']) && isset($value['to'])) {
                             $class->setMinYear($value['from']);
                             $class->setMaxYear($value['to']);
                         }
                     }
                 }
                 $class->addValidator(new USEARCH_CLASS_AgeRangeValidator($class->getMinAge(), $class->getMaxAge()));
                 break;
             case self::QUESTION_PRESENTATION_RANGE:
                 $class = new Range($fieldName);
                 if (empty($this->birthdayConfig)) {
                     $birthday = $this->findQuestionByName("birthdate");
                     if (!empty($birthday)) {
                         $this->birthdayConfig = $birthday->custom;
                     }
                 }
                 $rangeValidator = new RangeValidator();
                 if (!empty($this->birthdayConfig) && mb_strlen(trim($this->birthdayConfig)) > 0) {
                     $configsList = json_decode($this->birthdayConfig, true);
                     foreach ($configsList as $name => $value) {
                         if ($name = 'year_range' && isset($value['from']) && isset($value['to'])) {
                             $class->setMinValue(date("Y") - $value['to']);
                             $class->setMaxValue(date("Y") - $value['from']);
                             $rangeValidator->setMinValue(date("Y") - $value['to']);
                             $rangeValidator->setMaxValue(date("Y") - $value['from']);
                         }
                     }
                 }
                 $class->addValidator($rangeValidator);
                 break;
             case self::QUESTION_PRESENTATION_DATE:
                 $class = new DateRange($fieldName);
                 if (!empty($configs) && mb_strlen(trim($configs)) > 0) {
                     $configsList = json_decode($configs, true);
                     foreach ($configsList as $name => $value) {
                         if ($name = 'year_range' && isset($value['from']) && isset($value['to'])) {
                             $class->setMinYear($value['from']);
                             $class->setMaxYear($value['to']);
                         }
                     }
                 }
                 $class->addValidator(new DateValidator($class->getMinYear(), $class->getMaxYear()));
                 break;
             case BOL_QuestionService::QUESTION_PRESENTATION_URL:
                 $class = new TextField($questionName);
                 $class->addValidator(new UrlValidator());
                 break;
         }
         if (!empty($label)) {
             $class->setLabel($label);
         }
         if (empty($class)) {
             $class = BOL_QuestionService::getInstance()->getSearchPresentationClass($presentation, $questionName, $configs);
         }
     }
     return $class;
 }
예제 #3
0
 if (!isset($result->fieldErrors['first_name'])) {
     $__validator = new LengthValidator(array('maxLength' => 30, 'valueName' => 'first_name'));
     $__validatorError = $__validator->validate($db, $row);
     if ($__validatorError != '') {
         $result->fieldErrors['first_name'] = $__validatorError;
     }
 }
 if (!isset($result->fieldErrors['last_name'])) {
     $__validator = new LengthValidator(array('maxLength' => 30, 'valueName' => 'last_name'));
     $__validatorError = $__validator->validate($db, $row);
     if ($__validatorError != '') {
         $result->fieldErrors['last_name'] = $__validatorError;
     }
 }
 if (!isset($result->fieldErrors['is_active'])) {
     $__validator = new RangeValidator(array('type' => 'int', 'min' => 0, 'max' => 1, 'valueName' => 'is_active'));
     $__validatorError = $__validator->validate($db, $row);
     if ($__validatorError != '') {
         $result->fieldErrors['is_active'] = $__validatorError;
     }
 }
 if (!isset($result->fieldErrors['password'])) {
     $__validator = new LengthValidator(array('maxLength' => 30, 'valueName' => 'password'));
     $__validatorError = $__validator->validate($db, $row);
     if ($__validatorError != '') {
         $result->fieldErrors['password'] = $__validatorError;
     }
 }
 if (!isset($result->fieldErrors['reEnterPassword'])) {
     $__validator = new LengthValidator(array('maxLength' => 30, 'valueName' => 'reEnterPassword'));
     $__validatorError = $__validator->validate($db, $row);