guild/common/models/ProjectTaskUser.php

83 lines
1.9 KiB
PHP
Raw Normal View History

2021-11-23 13:13:19 +03:00
<?php
namespace common\models;
use yii\db\ActiveQuery;
2021-11-23 13:13:19 +03:00
/**
* This is the model class for table "task_user".
*
* @property int $id
* @property int $task_id
2023-04-25 01:32:15 +03:00
* @property int $user_id
2021-11-23 13:13:19 +03:00
*
* @property ProjectTask $task
2023-11-10 15:55:01 +03:00
* @property User $user
2021-11-23 13:13:19 +03:00
*/
class ProjectTaskUser extends \yii\db\ActiveRecord
2021-11-23 13:13:19 +03:00
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'project_task_user';
2021-11-23 13:13:19 +03:00
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
2023-04-25 01:32:15 +03:00
[['task_id', 'user_id'], 'required'],
['user_id', 'unique', 'targetAttribute' => ['task_id', 'user_id'], 'message' => 'Уже закреплён(ы) за задачей'],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
[['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectTask::className(), 'targetAttribute' => ['task_id' => 'id']],
2021-11-23 13:13:19 +03:00
];
}
2023-04-25 01:32:15 +03:00
/**
* @return string[]
*/
public function fields(): array
{
return [
'id',
'task_id',
'user_id',
'fio' => function () {
return $this->user->userCard->fio ?? $this->user->username;
},
'avatar' => function () {
return $this->user->userCard->photo ?? '';
}
];
}
2021-11-23 13:13:19 +03:00
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'task_id' => 'Задача',
2023-04-25 01:32:15 +03:00
'user_id' => 'Сотрудник',
2021-11-23 13:13:19 +03:00
];
}
2023-04-25 01:32:15 +03:00
public function getUser()
2021-11-23 13:13:19 +03:00
{
2023-04-25 01:32:15 +03:00
return $this->hasOne(User::class, ['id' => 'user_id']);
2021-11-23 13:13:19 +03:00
}
/**
* @return ActiveQuery
2021-11-23 13:13:19 +03:00
*/
public function getTask()
{
return $this->hasOne(ProjectTask::className(), ['id' => 'task_id']);
2021-11-23 13:13:19 +03:00
}
}