add task, fixed executors in all projects
This commit is contained in:
@ -2,7 +2,8 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "project_user".
|
||||
@ -52,7 +53,7 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getProject()
|
||||
{
|
||||
@ -60,7 +61,7 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
@ -70,16 +71,44 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getCard()
|
||||
{
|
||||
return $this->hasOne(UserCard::className(), ['id_user' => 'user_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getTasks()
|
||||
{
|
||||
return $this->hasMany(Task::className(), ['project_user_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getTasksByProject()
|
||||
{
|
||||
return $this->hasMany(Task::className(), ['project_id' => 'project_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getTaskUsers()
|
||||
{
|
||||
return $this->hasMany(TaskUser::className(), ['project_user_id' => 'id']);
|
||||
}
|
||||
|
||||
public static function usersByProjectArr($project_id): array
|
||||
{
|
||||
return ArrayHelper::map(
|
||||
self::find()->joinWith('user')->where(['project_id' => $project_id])->all(), 'id', 'user.username');
|
||||
}
|
||||
|
||||
public static function usersByTaskArr($task_id): array
|
||||
{
|
||||
return ArrayHelper::map(
|
||||
self::find()->joinWith(['tasksByProject', 'user'])->where(['task.id' => $task_id])->all(), 'id', 'user.username');
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,11 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use phpDocumentor\Reflection\Types\This;
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\Expression;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "task".
|
||||
@ -32,13 +36,25 @@ class Task extends \yii\db\ActiveRecord
|
||||
return 'task';
|
||||
}
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'class' => TimestampBehavior::class,
|
||||
'createdAtAttribute' => 'created_at',
|
||||
'updatedAtAttribute' => 'updated_at',
|
||||
'value' => new Expression('NOW()'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['project_id'], 'required'],
|
||||
[['project_id', 'status', 'title', 'description', 'project_user_id'], 'required'],
|
||||
[['project_id', 'status', 'project_user_id', 'user_id'], 'integer'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['title'], 'string', 'max' => 255],
|
||||
@ -56,17 +72,25 @@ class Task extends \yii\db\ActiveRecord
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'project_id' => 'Project ID',
|
||||
'title' => 'Title',
|
||||
'status' => 'Status',
|
||||
'created_at' => 'Created At',
|
||||
'updated_at' => 'Updated At',
|
||||
'project_user_id' => 'Project User ID',
|
||||
'user_id' => 'User ID',
|
||||
'description' => 'Description',
|
||||
'project_id' => 'Проект',
|
||||
'title' => 'Название задачи',
|
||||
'status' => 'Статус',
|
||||
'created_at' => 'Дата создания',
|
||||
'updated_at' => 'Дата обновления',
|
||||
'project_user_id' => 'Создатель',
|
||||
'user_id' => 'Наблюдатель',
|
||||
'description' => 'Описание',
|
||||
];
|
||||
}
|
||||
|
||||
public function beforeDelete()
|
||||
{
|
||||
foreach ($this->taskUsers as $taskUser){
|
||||
$taskUser->delete();
|
||||
}
|
||||
return parent::beforeDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
@ -98,4 +122,10 @@ class Task extends \yii\db\ActiveRecord
|
||||
{
|
||||
return $this->hasMany(TaskUser::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');
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\db\ActiveQuery;
|
||||
|
||||
/**
|
||||
* This is the model class for table "task_user".
|
||||
@ -43,13 +44,13 @@ class TaskUser extends \yii\db\ActiveRecord
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'task_id' => 'Task ID',
|
||||
'project_user_id' => 'Project User ID',
|
||||
'task_id' => 'Задача',
|
||||
'project_user_id' => 'Сотрудник',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getProjectUser()
|
||||
{
|
||||
@ -57,7 +58,7 @@ class TaskUser extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getTask()
|
||||
{
|
||||
|
Reference in New Issue
Block a user