Example #1
0
 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         if ($this->scenario == 'user-update') {
             // Верификация должностей и пользователей
             foreach ($this->position as $key => $positionId) {
                 if (!isset($this->user[$key])) {
                     continue;
                 }
                 if (!($position = Position::findOne($positionId))) {
                     continue;
                 }
                 if (is_numeric($this->user[$key])) {
                     $user = User::findIdentity($this->user[$key]);
                 } else {
                     $user = User::findByUsername(trim($this->user[$key]));
                 }
                 if (!$user) {
                     continue;
                 }
                 $this->_verifyPositions[] = ['positionId' => $position->id, 'userId' => $user->id];
             }
             if (empty($this->_verifyPositions)) {
                 $this->addError('position', 'Вы должны указать минимум одну должность');
             }
         }
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * Finds the Position model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Position the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Position::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }