Esempio n. 1
0
 public function rules()
 {
     return array_merge(parent::rules(), [[['topic', 'dateInput', 'beginTimeInput', 'endTimeInput', 'mode', 'foreignOrganizations'], 'required'], ['dateInput', MongoDateValidator::className(), 'format' => 'dd.MM.yyyy', 'min' => \Yii::$app->formatter->asDate(mktime(0, 0, 0), 'dd.MM.yyyy'), 'max' => \Yii::$app->formatter->asDate(strtotime("+1 week"), 'dd.MM.yyyy')], ['beginTimeInput', MinuteValidator::className(), 'min' => MinuteFormatter::asString(\Yii::$app->params['vks.minTime']), 'max' => $this->endTimeInput, 'minuteAttribute' => 'beginTime'], ['beginTimeInput', 'compare', 'compareAttribute' => 'endTimeInput', 'operator' => '!=='], ['beginTimeInput', function ($attribute) {
         if (\Yii::$app->user->can(SystemPermission::APPROVE_REQUEST)) {
             return;
         }
         $allowTimeStamp = $this->date->sec + ($this->beginTime - \Yii::$app->params['vks.allowRequestUpdateMinute']) * 60;
         $now = time() + 3 * 60 * 60;
         if ($now > $allowTimeStamp) {
             $this->addError($attribute, "Должно быть не меньше 20 минут от текущего времени");
         }
     }], ['endTimeInput', MinuteValidator::className(), 'min' => $this->beginTimeInput, 'max' => MinuteFormatter::asString(\Yii::$app->params['vks.maxTime']), 'minuteAttribute' => 'endTime'], ['audioRecord', 'boolean'], ['audioRecord', 'filter', 'filter' => function ($value) {
         return boolval($value);
     }], ['mode', 'in', 'range' => [self::MODE_WITH_VKS, self::MODE_WITHOUT_VKS]], ['mode', 'filter', 'filter' => function ($value) {
         return intval($value);
     }], ['participantsId', 'required', 'on' => 'default', 'message' => 'Необходимо выбрать участников'], ['participantsId', function ($attribute) {
         $value = $this->{$attribute};
         if ($this->mode === self::MODE_WITH_VKS && count($value) < 2) {
             $this->addError($attribute, 'Количество участников должно быть не менее двух');
             return;
         }
         if ($this->mode === self::MODE_WITHOUT_VKS && count($value) !== 1) {
             $this->addError($attribute, 'Помещение для совещания должно быть только одно');
             return;
         }
         $allParticipants = Participant::findAllByRequest($this);
         $allParticipantsId = ArrayHelper::getColumn($allParticipants, '_id');
         foreach ($value as $participant) {
             $key = array_search($participant, $allParticipantsId);
             if ($key === false) {
                 $this->addError($attribute, 'Участник не найден');
                 return;
             } elseif ($allParticipants[$key]->isBusy) {
                 $busyParticipant = $allParticipants[$key];
                 $this->addError($attribute, "Участник '{$busyParticipant->name}' занят с " . MinuteFormatter::asString($busyParticipant->busyFrom) . " до " . MinuteFormatter::asString($busyParticipant->busyTo));
             }
         }
     }, 'on' => 'default'], ['foreignOrganizations', 'boolean'], ['rsoUploadedFiles', 'file', 'skipOnEmpty' => false, 'mimeTypes' => ['image/*', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'], 'maxSize' => 3 * 1024 * 1024, 'maxFiles' => 3, 'when' => function ($model) {
         return (bool) $model->foreignOrganizations && count($model->rsoFiles) == 0;
     }], [['note', 'equipment'], 'safe']]);
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [['cancellationReason', 'required'], ['dateInput', MongoDateValidator::className(), 'format' => 'dd.MM.yyyy', 'mongoDateAttribute' => 'date'], ['deployServerId', 'default', 'value' => null], ['deployServerId', MongoIdValidator::className(), 'forceFormat' => 'object'], ['deployServerId', 'exist', 'targetClass' => DeployServer::className(), 'targetAttribute' => '_id'], ['participantsId', 'checkParticipantsIdFormat']]);
 }