32 $tasksToDelegate =
null;
35 $tasksToDelegate = TasksToBeDelegated::createFromRequest($request);
40 in_array($e->
getParameter(), [
'fromUserId',
'toUserId'],
true)
41 ?
Loc::getMessage(
'BIZPROC_LIB_API_TASK_SERVICE_DELEGATE_TASK_ERROR_INCORRECT_USER_ID')
44 $delegateResponse->addError(
new Error($errorMessage));
48 $delegateResponse->addError(
52 if (!$tasksToDelegate || !$delegateResponse->isSuccess())
54 return $delegateResponse;
57 $checkAccessResult = $this->accessService->checkDelegateTask(
58 $tasksToDelegate->getToUserId(),
59 $tasksToDelegate->getFromUserId()
61 if (!$checkAccessResult->isSuccess())
63 return $delegateResponse->addErrors($checkAccessResult->getErrors());
66 $allowedDelegationType = $checkAccessResult->getAllowedDelegationTypes();
69 $isDelegated = \CBPDocument::delegateTasks(
70 $tasksToDelegate->getFromUserId(),
71 $tasksToDelegate->getToUserId(),
72 $tasksToDelegate->getTaskIds(),
74 $allowedDelegationType
77 if (!$isDelegated && !$errors)
79 $errors = [
Loc::getMessage(
'BIZPROC_LIB_API_TASK_SERVICE_DELEGATE_TASK_ERROR_TASKS_NOT_FOUND')];
81 foreach ($errors as $errorMessage)
83 $delegateResponse->addError(
new Error($errorMessage));
86 if ($delegateResponse->isSuccess())
88 $delegateResponse->setData([
90 'BIZPROC_LIB_API_TASK_SERVICE_DELEGATE_TASK_SUCCESS_MESSAGE',
91 [
'#USER_NAME#' => \CBPHelper::convertUserToPrintableForm($tasksToDelegate->getToUserId(),
'',
false)]
96 return $delegateResponse;
112 $tasksToGet = TasksToGet::createFromRequest($request);
118 $getTasksResponse->addError(
new Error($exception->getMessage()));
120 if (!$tasksToGet || !$getTasksResponse->isSuccess())
122 return $getTasksResponse;
125 $checkAccessResult = $this->accessService->checkViewTasks($tasksToGet->getTargetUserId());
126 if (!$checkAccessResult->isSuccess())
128 return $getTasksResponse->addErrors($checkAccessResult->getErrors());
131 $tasksIterator = \CBPTaskService::getList(
132 $tasksToGet->getSort(),
133 $tasksToGet->getFilter(),
136 'nPageSize' => $tasksToGet->getLimit(),
137 'iNumPage' => (
int)($tasksToGet->getOffset() / $tasksToGet->getLimit()) + 1,
139 $tasksToGet->buildSelectFields()
142 while ($task = $tasksIterator->fetch())
145 $task[
'STATUS'] = (int)$task[
'STATUS'];
146 $task[
'MODIFIED'] = FormatDateFromDB($task[
'MODIFIED']);
148 is_array($task[
'PARAMETERS'][
'DOCUMENT_ID'] ??
null)
149 ? $task[
'PARAMETERS'][
'DOCUMENT_ID']
152 $task[
'DOCUMENT_URL'] = $documentId ? \CBPDocument::getDocumentAdminPage($documentId) :
'';
154 $task[
'MODULE_ID'] = $documentId ? $documentId[0] :
'';
155 $task[
'ENTITY'] = $documentId ? $documentId[1] :
'';
156 $task[
'DOCUMENT_ID'] = $documentId ? $documentId[2] :
'';
157 $task[
'COMPLEX_DOCUMENT_ID'] = $documentId;
159 if (isset($arRecord[
'WORKFLOW_TEMPLATE_NAME']))
161 $task[
'WORKFLOW_NAME'] = $task[
'WORKFLOW_TEMPLATE_NAME'];
163 if (isset($arRecord[
'WORKFLOW_STARTED']))
165 $task[
'WORKFLOW_STARTED'] = FormatDateFromDB($task[
'WORKFLOW_STARTED']);
168 $controls = \CBPDocument::getTaskControls($task);
170 $task[
'BUTTONS'] = $controls[
'BUTTONS'] ??
null;
171 $task[
'FIELDS'] = $controls[
'FIELDS'] ??
null;
176 return $getTasksResponse->setData([
'tasks' => $taskList]);
184 $checkAccessResult = $this->accessService->checkViewTasks($request->userId);
185 if (!$checkAccessResult->isSuccess())
187 return $result->addErrors($checkAccessResult->getErrors());
190 if ($request->taskId > 0)
192 $task = \CBPTaskService::GetList(
195 "ID" => $request->taskId,
196 "USER_ID" => $request->userId
217 return $result->addError(
new Error(
Loc::getMessage(
'BIZPROC_LIB_API_TASK_SERVICE_DO_TASK_ERROR_NO_TASK')));
220 if ((
int)$task[
'USER_STATUS'] !== \CBPTaskUserStatus::Waiting)
222 return $result->addError(
new Error(
Loc::getMessage(
'BIZPROC_LIB_API_TASK_SERVICE_DO_TASK_ERROR_ALREADY_DONE')));
225 $task[
"PARAMETERS"][
"DOCUMENT_ID"] = \CBPStateService::GetStateDocumentId($task[
'WORKFLOW_ID']);
226 $task[
"MODULE_ID"] = $task[
"PARAMETERS"][
"DOCUMENT_ID"][0];
227 $task[
"ENTITY"] = $task[
"PARAMETERS"][
"DOCUMENT_ID"][1];
228 $task[
"DOCUMENT_ID"] = $task[
"PARAMETERS"][
"DOCUMENT_ID"][2];
230 if (!\CBPDocument::PostTaskForm($task, $request->userId, $request->taskRequest, $errors))
232 $error = reset($errors);
233 if ($task[
'MODULE_ID'] ===
'rpa' && $error[
'code'] === \CBPRuntime::EXCEPTION_CODE_INSTANCE_TERMINATED)
238 $result->addError(
new Error($error[
'message']));