public function rules() { return [[['mobileNumber', 'employeeName', 'beginDate', 'endDate', 'rentNumberDate', 'destination'], 'required'], ['mobileNumber', MobileNumberValidator::className()], ['mobileNumber', function ($attribute) { $number = Number::findOne(['number' => $this->{$attribute}]); if (!$number->isTrip) { $this->addError($attribute, "Номер не является командировачным"); return; } $trip = self::findOne(['numberId' => $number->getPrimaryKey(), 'complete' => false]); if ($trip !== null && $this->getPrimaryKey() != $trip->getPrimaryKey()) { $this->addError($attribute, "Номер уже выдан в командировку"); return; } }], ['employeeName', EmployeeNameValidator::className(), 'postAttribute' => 'employeePost'], [['beginDate', 'endDate', 'rentNumberDate'], 'date', 'format' => 'dd.mm.yyyy'], ['beginDate', function ($attribute) { if (strtotime($this->{$attribute}) > strtotime($this->endDate)) { $this->addError($attribute, "Дата начала больше даты конца"); } }], ['rentNumberDate', function ($attribute) { if (strtotime($this->{$attribute}) > strtotime($this->beginDate)) { $this->addError($attribute, "Дата выдачи номера больше даты начала командировки"); } }], [['employeePost', 'destination'], 'safe']]; }
protected function setUp() { parent::setUp(); $this->model = new DynamicModel(['ownerName']); $this->model->addRule('ownerName', EmployeeNameValidator::className()); }