1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
WorkflowFacesView.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\UI;
4
5use Bitrix\Bizproc\Api\Data\UserService\UsersToGet;
6use Bitrix\Bizproc\Api\Request\WorkflowFacesService\GetDataRequest;
7use Bitrix\Bizproc\Api\Response\WorkflowFacesService\GetDataByStepsResponse;
8use Bitrix\Bizproc\Api\Service\UserService;
9use Bitrix\Bizproc\Api\Service\WorkflowAccessService;
10use Bitrix\Bizproc\Api\Service\WorkflowFacesService;
11
12class WorkflowFacesView implements \JsonSerializable
13{
14 private string $workflowId;
15 private int $runningTaskId;
16 private array $usersView = [];
17 private ?GetDataByStepsResponse $data = null;
18
19 public function __construct(string $workflowId, ?int $runningTaskId = null)
20 {
21 $this->workflowId = $workflowId;
22 $this->runningTaskId = max($runningTaskId ?? 0, 0);
23 }
24
25 public function jsonSerialize(): array
26 {
27 $data = $this->loadData();
28 if (!$data->isSuccess())
29 {
30 return [];
31 }
32
33 $this->loadUsersView($this->getUniqueUserIds());
34
35 $result = [
36 'workflowId' => $this->workflowId,
37 'steps' => $this->getSteps(),
38 'timeStep' => $this->getTimeStep(),
39 'isWorkflowFinished' => $data->getIsWorkflowFinished(),
40 ];
41
42 $progressBox = $data->getProgressBox();
43 if ($progressBox && $progressBox->getProgressTasksCount() > 0)
44 {
45 $result['progressBox'] = $progressBox->getData();
46 }
47
48 return $result;
49 }
50
51 public function getUniqueUserIds(): array
52 {
53 $data = $this->loadData();
54 if ($data->isSuccess())
55 {
56 return $data->getUniqueUserIds();
57 }
58
59 return [];
60 }
61
62 public function getSteps(): array
63 {
64 $data = $this->loadData();
65 if (!$data->isSuccess())
66 {
67 return [];
68 }
69
70 $steps = [];
71 foreach ($data->getSteps() as $step)
72 {
73 if ($step)
74 {
75 $stepData = $step->getData();
76 $stepData['avatarsData'] = $this->getStepAvatars($step->getAvatars());
77
78 if ($step->getDuration() <= 0)
79 {
80 $stepData['duration'] = $step::getEmptyDurationText();
81 }
82
83 $steps[] = $stepData;
84 }
85 }
86
87 return $steps;
88 }
89
90 public function getTimeStep(): ?array
91 {
92 $data = $this->loadData();
93 if ($data->isSuccess())
94 {
95 return $data->getTimeStep()?->getData();
96 }
97
98 return null;
99 }
100
101 private function loadData(): GetDataByStepsResponse
102 {
103 if ($this->data === null)
104 {
105 $workflowFacesService = new WorkflowFacesService(
107 );
108
110 workflowId: $this->workflowId,
111 runningTaskId: $this->runningTaskId,
112 skipAccessCheck: true,
113 );
114
115 $this->data = $workflowFacesService->getDataBySteps($request);
116 }
117
118 return $this->data;
119 }
120
121 private function loadUsersView(array $userIds): void
122 {
123 $userService = new UserService();
124 $response = $userService->getUsersView(new UsersToGet($userIds));
125 if ($response->isSuccess())
126 {
127 foreach ($response->getUserViews() as $userView)
128 {
129 $userId = $userView->getUserId();
130
131 $this->usersView[$userId] = [
132 'id' => $userId,
133 'avatarUrl' => $userView->getUserAvatar(),
134 ];
135 }
136 }
137 }
138
139 private function getStepAvatars(array $userIds): array
140 {
141 $result = [];
142 foreach ($userIds as $userId)
143 {
144 $result[] = $this->getUserById((int)$userId);
145 }
146
147 return $result;
148 }
149
150 private function getUserById(int $userId): array
151 {
152 if ($userId <= 0)
153 {
154 return ['id' => 0, 'avatarUrl' => null];
155 }
156
157 if (array_key_exists($userId, $this->usersView))
158 {
159 return $this->usersView[$userId];
160 }
161
162 return [];
163 }
164}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
__construct(string $workflowId, ?int $runningTaskId=null)
Определения WorkflowFacesView.php:19
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$response
Определения result.php:21