22 private const CONVERTER_VERSION = 2;
29 $responseCollection =
new EO_WorkflowState_Collection();
31 $queryResult = WorkflowUserTable::query()
32 ->addSelect(
'WORKFLOW_ID')
43 $response->setTotalCount($queryResult->getCount());
45 $workflowStates = $queryResult->fetchAll();
46 $ids = array_column($workflowStates,
'WORKFLOW_ID');
49 $query = WorkflowStateTable::query()->setSelect($toGet->
getSelect());
50 if (count($ids) === 1)
52 $query->where(
'ID',
'=', $ids[0]);
56 $query->whereIn(
'ID', $ids);
59 $collection = $query->exec()->fetchCollection();
63 $workflowState = $collection->getByPrimary($id);
66 $responseCollection->add($workflowState);
71 return $response->setWorkflowStatesCollection($responseCollection);
79 $getListResult = $this->
getList($toGet);
80 $collection = $getListResult->getWorkflowStatesCollection();
83 return $response->setWorkflowStatesList([]);
88 foreach ($collection as $stateElement)
90 $tasksInfo = $stateElement->getTasksInfo();
91 foreach ($tasksInfo as $task)
93 if (!empty($task[
'TASK_USERS']))
95 foreach ($task[
'TASK_USERS'] as $row)
97 $userIds[$row[
'USER_ID']] =
true;
98 $userIds[$row[
'ORIGINAL_USER_ID']] =
true;
102 $fullFilledList[] = [
103 'ID' => $stateElement->getId(),
104 'STATE_INFO' => $stateElement->getStateInfo(),
105 'DOCUMENT_INFO' => $this->getDocumentInfo($stateElement->getComplexDocumentId()),
106 'STARTED_USER_INFO' => [
107 'ID' => $stateElement->getStartedBy(),
109 'TASKS_INFO' => $tasksInfo,
110 'TEMPLATE_NAME' => $stateElement->getTemplate()?->getName(),
113 $userIds[$stateElement->getStartedBy()] =
true;
118 ->setWorkflowStatesList($fullFilledList)
119 ->setMembersInfo($this->getMembersInfo(array_keys($userIds)))
135 private function getDocumentInfo(array $complexDocumentId): array
137 $documentService = \CBPRuntime::getRuntime()->getDocumentService();
142 $complexDocumentType = $documentService->getDocumentType($complexDocumentId);
143 $key = $complexDocumentId[0] .
'@' . $complexDocumentId[1] .
'@' . $complexDocumentType[2];
147 $complexDocumentType =
null;
151 if ($key && !isset($cache[$key]))
153 $cache[$key] = $documentService->getDocumentTypeCaption($complexDocumentType);
155 $typeCaption = $key ? $cache[$key] :
'';
158 'COMPLEX_ID' => $complexDocumentId,
159 'COMPLEX_TYPE' => $complexDocumentType,
160 'NAME' => $documentService->getDocumentName($complexDocumentId),
161 'TYPE_CAPTION' => $typeCaption,
165 private function getMembersInfo(array $ids): array
172 $userFields = [
'ID',
'NAME',
'SECOND_NAME',
'LAST_NAME',
'LOGIN',
'TITLE',
'EMAIL',
'PERSONAL_PHOTO'];
174 $users = \CUser::GetList(
177 [
'ID' => implode(
'|', $ids)],
178 [
'FIELDS' => $userFields]
182 while ($user = $users->Fetch())
184 $fullName = \CUser::FormatName(\CSite::GetNameFormat(
false), $user,
true,
false);
185 $personalPhoto = (int)$user[
'PERSONAL_PHOTO'];
188 'ID' => (int)($user[
'ID'] ?? 0),
189 'FULL_NAME' => $fullName,
190 'PERSONAL_PHOTO' => $personalPhoto,
197 private function convertProcesses(
int $userId)
204 $converterVersion = \CUserOptions::getOption(
206 'processes_converted',
211 if ($converterVersion === self::CONVERTER_VERSION)
216 WorkflowUserTable::convertUserProcesses($userId);
218 \CUserOptions::setOption(
220 'processes_converted',
221 self::CONVERTER_VERSION,
234 if ($request->templateId <= 0)
236 $response->addError(
new Error(
'incorrect template id'));
239 if ($response->isSuccess())
241 $averageDuration = WorkflowDurationStatTable::getAverageDurationByTemplateId($request->templateId);
242 if ($averageDuration !==
null)
244 $response->setAverageDuration($averageDuration);