Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
task.php
1<?php
2
4
8
9class Task extends Base
10{
11 public function delegateAction(array $taskIds, int $toUserId, int $fromUserId): ?array
12 {
13 if (!$taskIds)
14 {
15 $this->addError(new Error(Loc::getMessage('BIZPROC_CONTROLLER_TASK_DELEGATE_EMPTY_TASK_IDS')));
16
17 return null;
18 }
19 if ($toUserId <= 0 || $fromUserId <= 0)
20 {
21 $this->addError(new Error(Loc::getMessage('BIZPROC_CONTROLLER_TASK_DELEGATE_INCORRECT_USER_ID')));
22
23 return null;
24 }
25
26 $currentUserId = $this->getCurrentUser()->getId();
27
28 $taskService = new Bizproc\Api\Service\TaskService(
29 new Bizproc\Api\Service\TaskAccessService($currentUserId)
30 );
31
32 $tasksRequest = new Bizproc\Api\Request\TaskService\DelegateTasksRequest($taskIds, $fromUserId, $toUserId, $currentUserId);
33 $delegateTaskResult = $taskService->delegateTasks($tasksRequest);
34
35 if (!$delegateTaskResult->isSuccess())
36 {
37 $this->addErrors($delegateTaskResult->getErrors());
38
39 return null;
40 }
41
42 return [
43 'message' => $delegateTaskResult->getSuccessDelegateTaskMessage(),
44 ];
45 }
46
50 private function getListAction(?int $targetUserId = null): ?array
51 {
52 $currentUserId = $this->getCurrentUser()->getId();
53 if (!$targetUserId)
54 {
55 $targetUserId = $currentUserId;
56 }
57
58 // todo: check that $targetUserId > 0
59
60 $taskService = new Bizproc\Api\Service\TaskService(
61 new Bizproc\Api\Service\TaskAccessService($currentUserId)
62 );
63
65 additionalSelectFields: ['NAME', 'DESCRIPTION'],
66 filter: [
67 'USER_ID' => $targetUserId,
68 ],
69 );
70 $getTasksResult = $taskService->getTasks($tasksRequest);
71 if (!$getTasksResult->isSuccess())
72 {
73 $this->addErrors($getTasksResult->getErrors());
74
75 return null;
76 }
77
78 return [
79 'tasks' => $getTasksResult->getTasks(),
80 ];
81 }
82
83 public function doAction(int $taskId, array $taskRequest): ?bool
84 {
85 $currentUserId = $this->getCurrentUser()->getId();
86
87 $taskService = new Bizproc\Api\Service\TaskService(
88 new Bizproc\Api\Service\TaskAccessService($currentUserId)
89 );
90
91 //todo: send DTO ?
92 $getTasksResult = $taskService->doTask($taskId, $currentUserId, $taskRequest);
93 if (!$getTasksResult->isSuccess())
94 {
95 $this->addErrors($getTasksResult->getErrors());
96
97 return null;
98 }
99
100 return true;
101 }
102
108 public function doInlineTasksAction(array $taskIds, int $newStatus): ?bool
109 {
110 $currentUserId = $this->getCurrentUser()->getId();
111
112 $preparedTaskIds = [];
113 foreach ($taskIds as $id)
114 {
115 if (is_numeric($id))
116 {
117 $preparedTaskIds[] = (int)$id;
118 }
119 }
120
122 taskIds: $preparedTaskIds,
123 userId: $currentUserId,
124 newTaskStatusId: $newStatus,
125 );
126
127 $service = new Bizproc\Api\Service\TaskService(
128 new Bizproc\Api\Service\TaskAccessService($request->userId),
129 );
130
131 $response = $service->doInlineTasks($request);
132
133 if (!$response->isSuccess())
134 {
135 $this->addErrors($response->getErrors());
136 return null;
137 }
138
139 return true;
140 }
141}
static addError($error)
Definition base.php:278
static addErrors(array $errors)
Definition base.php:287
doInlineTasksAction(array $taskIds, int $newStatus)
Definition task.php:108
delegateAction(array $taskIds, int $toUserId, int $fromUserId)
Definition task.php:11
doAction(int $taskId, array $taskRequest)
Definition task.php:83
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29