2022-01-16 23:54:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace common\services;
|
|
|
|
|
2023-04-26 01:22:02 +03:00
|
|
|
use common\classes\Debug;
|
2023-01-18 15:30:38 +03:00
|
|
|
use common\models\ProjectTask;
|
2023-04-26 01:22:02 +03:00
|
|
|
use common\models\ProjectTaskUser;
|
|
|
|
use common\models\ProjectUser;
|
2022-01-16 23:54:13 +03:00
|
|
|
|
|
|
|
class TaskService
|
|
|
|
{
|
|
|
|
public static function createTask($taskParams)
|
|
|
|
{
|
2023-01-18 15:30:38 +03:00
|
|
|
$task = new ProjectTask();
|
2022-01-16 23:54:13 +03:00
|
|
|
$task->load($taskParams, '');
|
|
|
|
$task->save();
|
|
|
|
return $task;
|
|
|
|
}
|
|
|
|
|
2023-01-18 15:30:38 +03:00
|
|
|
public static function getTask($task_id): ?ProjectTask
|
2022-01-16 23:54:13 +03:00
|
|
|
{
|
2023-01-18 15:30:38 +03:00
|
|
|
return ProjectTask::findOne($task_id);
|
2022-01-16 23:54:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getTaskList($task_id): array
|
|
|
|
{
|
2023-01-18 15:30:38 +03:00
|
|
|
return ProjectTask::find()->asArray()->all();
|
2022-01-16 23:54:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getTaskListByProject($project_id): array
|
|
|
|
{
|
2023-01-18 15:30:38 +03:00
|
|
|
return ProjectTask::find()->where(['project_id' => $project_id])->asArray()->all();
|
2022-01-16 23:54:13 +03:00
|
|
|
}
|
|
|
|
|
2023-04-25 01:32:15 +03:00
|
|
|
public static function getTaskListByUser($user_id): array
|
|
|
|
{
|
2023-04-26 01:22:02 +03:00
|
|
|
$taskIdList = ProjectTaskUser::find()->where(['user_id' => $user_id])->select('task_id')->column();
|
|
|
|
return ProjectTask::find()->where([ 'IN', 'id', $taskIdList])->orWhere(['user_id' => $user_id])->all();
|
2023-04-25 01:32:15 +03:00
|
|
|
}
|
|
|
|
|
2023-01-18 15:30:38 +03:00
|
|
|
public static function updateTask($task_params): ?ProjectTask
|
2022-01-16 23:54:13 +03:00
|
|
|
{
|
2023-01-18 15:30:38 +03:00
|
|
|
$modelTask = ProjectTask::findOne($task_params['task_id']);
|
2022-01-16 23:54:13 +03:00
|
|
|
|
2023-05-25 02:13:29 +03:00
|
|
|
if (isset($task_params['executor_id']) && $task_params['executor_id'] == 0){
|
2023-05-24 01:22:03 +03:00
|
|
|
$task_params['executor_id'] = null;
|
|
|
|
}
|
|
|
|
|
2022-01-16 23:54:13 +03:00
|
|
|
$modelTask->load($task_params, '');
|
|
|
|
$modelTask->save();
|
|
|
|
|
|
|
|
return $modelTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function taskExists($task_id): bool
|
|
|
|
{
|
2023-01-18 15:30:38 +03:00
|
|
|
return ProjectTask::find()->where(['id' => $task_id])->exists();
|
2022-01-16 23:54:13 +03:00
|
|
|
}
|
|
|
|
}
|