guild/common/services/TaskService.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2022-01-16 23:54:13 +03:00
<?php
namespace common\services;
2023-04-26 01:22:02 +03:00
use common\classes\Debug;
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)
{
$task = new ProjectTask();
2022-01-16 23:54:13 +03:00
$task->load($taskParams, '');
$task->save();
return $task;
}
public static function getTask($task_id): ?ProjectTask
2022-01-16 23:54:13 +03:00
{
return ProjectTask::findOne($task_id);
2022-01-16 23:54:13 +03:00
}
public static function getTaskList($task_id): array
{
return ProjectTask::find()->asArray()->all();
2022-01-16 23:54:13 +03:00
}
public static function getTaskListByProject($project_id): array
{
2023-10-09 23:57:01 +03:00
return ProjectTask::find()->where(['project_id' => $project_id])->orderBy('priority DESC')->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();
2023-10-09 23:57:01 +03:00
return ProjectTask::find()->where([ 'IN', 'id', $taskIdList])->orWhere(['user_id' => $user_id])->orderBy('priority DESC')->all();
2023-04-25 01:32:15 +03:00
}
public static function updateTask($task_params): ?ProjectTask
2022-01-16 23:54:13 +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
{
return ProjectTask::find()->where(['id' => $task_id])->exists();
2022-01-16 23:54:13 +03:00
}
}