TimestampBehavior::class, 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => new Expression('NOW()'), ], ]; } /** * {@inheritdoc} */ public function rules() { return [ [['project_id', 'status', 'title', 'description',], 'required'], [['project_id', 'status', 'column_id', 'user_id'], 'integer'], [['created_at', 'updated_at'], 'safe'], ['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'], [['title'], 'string', 'max' => 255], [['description'], 'string', 'max' => 500], [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']], [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], [['column_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectColumn::className(), 'targetAttribute' => ['column_id' => 'id']], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'project_id' => 'Проект', 'title' => 'Название задачи', 'status' => 'Статус', 'created_at' => 'Дата создания', 'updated_at' => 'Дата обновления', 'description' => 'Описание', 'user_id' => 'Создатель задачи', 'column_id' => 'Колонка', ]; } /** * @return string[] */ public function fields(): array { return [ 'id', 'project_id', 'title', 'created_at', 'updated_at', 'description', 'status', 'column_id', 'user_id', 'taskUsers', ]; } /** * @return string[] */ public static function getStatus(): array { return [ self::STATUS_ACTIVE => 'Активен', self::STATUS_DISABLE => 'Выключен' ]; } public function beforeDelete() { foreach ($this->taskUsers as $taskUser) { $taskUser->delete(); } return parent::beforeDelete(); } /** * @return ActiveQuery */ public function getProject() { return $this->hasOne(Project::className(), ['id' => 'project_id']); } /** * @return ActiveQuery */ public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); } /** * @return ActiveQuery */ public function getColumn(): ActiveQuery { return $this->hasOne(ProjectColumn::class, ['id' => 'column_id']); } /** * @return ActiveQuery */ public function getTaskUsers() { return $this->hasMany(ProjectTaskUser::className(), ['task_id' => 'id']); } public static function usersByTaskArr($task_id): array { return ArrayHelper::map( self::find()->joinWith(['user', 'project'])->where(['project_id' => $task_id])->all(), 'id', 'user.username'); } }