beforeValidate() public method

The default implementation raises a beforeValidate event. You may override this method to do preliminary checks before validation. Make sure the parent implementation is invoked so that the event can be raised.
public beforeValidate ( ) : boolean
return boolean whether the validation should be executed. Defaults to true. If false is returned, the validation will stop and the model is considered invalid.
Example #1
0
 /**
  * Method description
  *
  * @return mixed The return value
  */
 public function beforeValidate()
 {
     if (!empty($this->otherType)) {
         $this->type = $this->otherType;
     }
     return parent::beforeValidate();
 }
Example #2
0
 public function beforeValidate()
 {
     foreach ($this->jsonAttributes as $attribute) {
         $this->jsonValidation($attribute);
     }
     return parent::beforeValidate();
 }
Example #3
0
 public function beforeValidate()
 {
     if ($this->is_organization == 1) {
         $this->scenario = 'jur-validate';
     }
     return parent::beforeValidate();
 }
Example #4
0
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         $this->beforeValidateParamRows();
         return true;
     } else {
         return false;
     }
 }
 /** @inheritdoc */
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         $this->user = User::findIdentityByLogin($this->login);
         return true;
     } else {
         return false;
     }
 }
Example #6
0
 /** @inheritdoc */
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         $this->user = $this->module->manager->findUserByUsernameOrEmail($this->login);
         return true;
     } else {
         return false;
     }
 }
Example #7
0
 public function beforeValidate()
 {
     if ($this->rememberMe == 'on') {
         $this->rememberMe = 1;
     } else {
         $this->rememberMe = 0;
     }
     return parent::beforeValidate();
 }
 /** @inheritdoc */
 public function beforeValidate()
 {
     if (Model::beforeValidate()) {
         $this->user = $this->finder->findUserByEmail($this->email);
         return true;
     } else {
         return false;
     }
 }
Example #9
0
 /** @inheritdoc */
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         $this->user = User::findIdentityByUsernameOrEmail(trim($this->login));
         return true;
     } else {
         return false;
     }
 }
Example #10
0
 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     if (!parent::beforeValidate()) {
         return false;
     }
     foreach ($this->activeAttributes() as $attribute) {
         $this->preparedData[$attribute] = $this->{$attribute};
     }
     return true;
 }
Example #11
0
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         if (Yii::$app->getModule('auth')->signupWithEmailOnly) {
             $this->username = $this->email;
         }
         return true;
     }
     return false;
 }
Example #12
0
 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         foreach ($this->items as $item) {
             if (!$item->validate()) {
                 return false;
             }
         }
     }
     return true;
 }
Example #13
0
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         $this->prepareRows($this->queryKeys, $this->queryValues, $this->queryActives);
         $this->prepareRows($this->bodyKeys, $this->bodyValues, $this->bodyActives);
         $this->prepareRows($this->headerKeys, $this->headerValues, $this->headerActives);
         return true;
     } else {
         return false;
     }
 }
Example #14
0
 public function beforeValidate()
 {
     $dateObj = \yii::$app->DateComponent;
     if ($this->end_date == null) {
         $this->end_date = $this->start_date;
     }
     $this->start_datetime_uk = sprintf('%s %s', $this->start_date, $this->start_time);
     $this->end_datetime_uk = sprintf('%s %s', $this->end_date, $this->end_time);
     $this->start_timestamp = $dateObj->ukDateTimeToTimestamp($this->start_datetime_uk);
     $this->end_timestamp = $dateObj->ukDateTimeToTimestamp($this->end_datetime_uk);
     if ($this->end_timestamp - $this->start_timestamp > $this->secsInDay) {
         $this->all_day_option_id = Types::$boolean['true']['id'];
     }
     return parent::beforeValidate();
 }
 /**
  * Перед валидацией получаем
  * экземпляр объекта файла
  *
  * @return bool
  */
 public function beforeValidate()
 {
     $this->file = UploadedFile::getInstanceByName('file');
     return parent::beforeValidate();
 }
Example #16
0
 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     if (!parent::beforeValidate()) {
         return false;
     }
     if ($this->scenario == 'create' || $this->scenario == 'update') {
         $this->categoriesValid = Category::findAll($this->categories);
         $this->usersValid = User::findAll($this->users);
     }
     return true;
 }
Example #17
0
 /** @inheritdoc */
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         // Load the user before the validation takes place
         $this->user = $this->finder->findUserByUsernameOrEmail(trim($this->login));
         return true;
     } else {
         return false;
     }
 }
Example #18
0
 /**
  * Converts date to timestamp
  */
 public function beforeValidate()
 {
     try {
         $this->date = Yii::$app->formatter->asTimestamp($this->date);
     } catch (\Exception $e) {
         $this->addError('date', 'Wrong date release book');
         return false;
     }
     return parent::beforeValidate();
 }
Example #19
0
 /** @inheritdoc */
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         if (!empty($this->Login)) {
             $this->user = $this->finder->findUser(['Login' => $this->Login])->one();
             /**
              * Generate password
              */
             $hash = Yii::$app->security->generatePasswordHash($this->Password);
             ////$this->Password = $this->Password . ':' . $hash;
             ////list($password, $hash) = explode(':', $this->Password);
             //                if ($this->user !== null && Yii::$app->getSecurity()->validatePassword($this->Password, $hash) ) {
             //                    $this->user->updateAttributes(['Password' => $hash]);
             //                    echo $this->Password . ':' . $hash. ' OK  ';
             //                }
             //                exit;
         }
         if ($this->user === null) {
             if (CardRecord::check($this->Login)) {
                 $card = CardRecord::findCard($this->Login);
                 if ($card !== null && $card->person) {
                     //                    $this->user = $card->person->ServiceCard ? $card->person : null;
                     $this->user = $card->person;
                     return true;
                 }
             }
             $this->addError('Login', \Yii::t('user', 'Invalid login or password'));
             return false;
         } else {
             return true;
         }
     } else {
         return false;
     }
 }
Example #20
0
 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         $query = $this->getModule()->factory->createUserQuery();
         switch ($this->getModule()->loginType) {
             case 'email':
                 $condition = ['email' => $this->login];
                 break;
             case 'username':
                 $condition = ['username' => $this->login];
                 break;
             case 'both':
                 $condition = ['or', ['email' => $this->login], ['username' => $this->login]];
                 break;
             default:
                 throw new \RuntimeException('Unknown login type');
         }
         $this->user = $query->where($condition)->one();
         return true;
     } else {
         return false;
     }
 }
Example #21
0
 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     $value = $this->value;
     if ($value === null || $value === false || $value === '') {
         if ($this->default !== null) {
             $this->value = $this->default;
         }
     }
     return parent::beforeValidate();
 }
Example #22
0
 public function beforeValidate()
 {
     $this->info_hash = bin2hex($this->info_hash);
     return parent::beforeValidate();
 }
Example #23
0
 /**
  * @return bool
  */
 public function beforeValidate()
 {
     if (urldecode($this->key) !== $this->key) {
         $this->key = urldecode($this->key);
     }
     if ($this->field && Html::decode($this->field) !== $this->field) {
         $this->field = Html::decode($this->field);
     }
     if (!$this->type) {
         $this->type = Redisman::getInstance()->type($this->key);
     }
     return parent::beforeValidate();
 }
Example #24
0
 public function beforeValidate()
 {
     //======================================================
     // дополнительные валидации
     //======================================================
     if (preg_match('/^[a-zA-Z_0-9]+$/', $this->id) != 1) {
         $this->addError('id', Yii::t('modelDynamicField', 'Разрешены только латинский буквы, цифры и подчеркивание'));
     }
     switch ($this->type) {
         case self::TYPE_TEXT:
         case self::TYPE_EMAIL:
             if ($this->getOption(self::OPTION_MAX_LEN) < 1) {
                 $this->addError(self::OPTION_MAX_LEN, Yii::t('modelDynamicField', 'Неверная длина поля'));
             }
             break;
             //-----------------------------------------
         //-----------------------------------------
         case self::TYPE_DROPDOWN:
         case self::TYPE_MULTISELECT:
         case self::TYPE_RADIOS:
             $_ = trim($this->getOption(self::OPTION_ITEMS));
             if (!$_ || empty($_)) {
                 $this->addError(self::OPTION_ITEMS, Yii::t('modelDynamicField', 'Необходимо задать значения'));
             }
             break;
             //-----------------------------------------
         //-----------------------------------------
         case self::TYPE_DATE:
             $this->setOption(self::OPTION_FIRST_YEAR, preg_replace('/[^0-9\\-\\+]/', '', $this->getOption(self::OPTION_FIRST_YEAR)));
             if (preg_match('/^[+\\-]{0,1}[0-9]{1,4}$/', $this->getOption(self::OPTION_FIRST_YEAR)) != 1) {
                 $this->addError(self::OPTION_FIRST_YEAR, Yii::t('modelDynamicField', 'Формат: [+-]<год>'));
             }
             $this->setOption(self::OPTION_LAST_YEAR, preg_replace('/[^0-9\\-\\+]/', '', $this->getOption(self::OPTION_LAST_YEAR)));
             if (preg_match('/^[+\\-]{0,1}[0-9]{1,4}$/', $this->getOption(self::OPTION_LAST_YEAR)) != 1) {
                 $this->addError(self::OPTION_LAST_YEAR, Yii::t('modelDynamicField', 'Формат: [+-]<год>'));
             }
     }
     return parent::beforeValidate();
 }
Example #25
0
 public function beforeValidate()
 {
     $this->password = DStringHelper::generate_password(7);
     $date_str = $this->birth_day . '-' . $this->birth_month . '-' . $this->birth_year;
     //13-07-2015
     $this->birthday = DDateTimeHelper::DateToUnix($date_str);
     //		$date_str = '02-01-1996';
     //		echo'<pre>';print_r($date_str);echo'</pre>';//die;
     //		echo'<pre>';print_r($this->birthday);echo'</pre>';//die;
     //		$this->birthday = DDateTimeHelper::DateToUnix($date_str, '', 2);
     //		echo'<pre>';print_r($this->birthday);echo'</pre>';//die;
     //		echo'<pre>';print_r(date('d-m-y', $this->birthday));echo'</pre>';die;
     return parent::beforeValidate();
 }
 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     $this->configureRules();
     return parent::beforeValidate();
 }
Example #27
0
 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         $this->getUser();
         return true;
     } else {
         return false;
     }
 }
Example #28
0
 public function beforeValidate()
 {
     $file = UploadedFile::getInstance($this, 'file');
     $this->file = $file->tempName ? $file : null;
     return parent::beforeValidate();
 }
Example #29
-1
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         $this->file = UploadedFile::getInstanceByName('file');
         return true;
     }
     return false;
 }