['manager_id', 'employee_id'], 'message' => 'Этот сотрудник уже закреплён за менеджером'], [['employee_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['employee_id' => 'id']], [['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'manager_id' => 'Менеджер', 'employee_id' => 'Карточка работника', ]; } public function fields(): array { return [ 'id', 'manager_id', 'employee_id', 'user_id' => function(){ return $this->employee_id; }, 'employee' => function () { return [ "fio" => $this->employee->userCard->fio ?? $this->employee->username, "avatar" => $this->employee->userCard->photo ?? '', ]; }, ]; } /** * @return ActiveQuery */ public function getEmployee() { return $this->hasOne(User::class, ['id' => 'employee_id']); } public function getUser() { return $this->hasOne(User::class, ['id' => 'employee_id']); } /** * @return ActiveQuery */ public function getManager() { return $this->hasOne(Manager::className(), ['id' => 'manager_id']); } }