guild/common/services/TaskService.php

55 lines
1.4 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
{
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
}
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
$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
}
}