Example #1
0
 /**
  * Метод выполняемый перед сохранением:
  * 
  * @return void
  */
 public function beforeSave()
 {
     if ($this->getIsNewRecord()) {
         $this->registration_date = new CDbExpression('NOW()');
         $this->code = mt_rand(100000, 999999);
         if (empty($this->role)) {
             $this->role = User::getAuthenticatedRole();
         }
     } else {
         // Запрещаем действия, при которых администратор
         // может быть заблокирован или сайт останется без
         // администратора:
         if ($this->admin()->count() == 1 && $this->_oldRole === User::getSuperuserRole() && ($this->role !== User::getSuperuserRole() || (int) $this->status !== self::STATUS_ACTIVE)) {
             $this->addError('role', Yii::t('UserModule.user', 'You can\'t make this changes!'));
             return false;
         }
     }
     // Меняем дату изменения профиля:
     $this->change_date = new CDbExpression('NOW()');
     return parent::beforeSave();
 }
Example #2
0
 /**
  * Метод выполняемый перед валидацией:
  * 
  * @return void
  */
 public function beforeValidate()
 {
     if ($this->getIsNewRecord()) {
         if ($this->role == '') {
             $this->role = User::getAuthenticatedRole();
         }
     }
     return parent::beforeValidate();
 }