1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
workflow.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\Controller;
4
5use Bitrix\Bizproc\Api\Request\WorkflowStateService\GetEfficiencyDataRequest;
6use Bitrix\Main\Loader;
7use Bitrix\Main\Error;
8use Bitrix\Main\Localization\Loc;
9use Bitrix\Bizproc\Api\Data\UserService\UsersToGet;
10use Bitrix\Bizproc\Api\Request\WorkflowStateService\GetAverageWorkflowDurationRequest;
11use Bitrix\Bizproc\Api\Request\WorkflowStateService\GetTimelineRequest;
12use Bitrix\Bizproc\Api\Service\UserService;
13use Bitrix\Bizproc\Api\Service\WorkflowStateService;
14use Bitrix\Main\Engine\CurrentUser;
15use Bitrix\Bizproc;
16
17class Workflow extends Base
18{
19 private const PAGE_SIZE = 20;
20
21 public function getTimelineAction(string $workflowId): ?array
22 {
23 $workflowStateService = new WorkflowStateService();
24
25 $request = new GetTimelineRequest(workflowId: $workflowId, userId: CurrentUser::get()->getId());
26 $response = $workflowStateService->getTimeline($request);
27 $timeline = $response->getTimeline();
28
29 if (!$timeline || !$response->isSuccess())
30 {
31 $this->addErrors($response->getErrors());
32
33 return null;
34 }
35
36 $workflowState = $timeline->getWorkflowState();
37
38 $userIds = [$workflowState->getStartedBy()];
39 foreach ($timeline->getTasks() as $task)
40 {
41 $userIds = array_merge($userIds, $task->getTaskUserIds());
42 }
43
44 $userService = new UserService();
45
46 $request = new UsersToGet($userIds);
47 $response = $userService->getUsersView($request);
48
49 if (!$response->isSuccess())
50 {
51 $this->addErrors($response->getErrors());
52
53 return null;
54 }
55
56 $data = $timeline->jsonSerialize();
57 $data['users'] = $response->getUserViews();
58 $duration = $workflowStateService->getAverageWorkflowDuration(
59 new GetAverageWorkflowDurationRequest($workflowState->getWorkflowTemplateId())
60 )->getRoundedAverageDuration();
61 $executionTime = $workflowStateService->getExecutionTime(
62 new Bizproc\Api\Request\WorkflowStateService\GetExecutionTimeRequest(
63 workflowId: $workflowState->getId(),
64 workflowStarted: $workflowState->getStarted(),
65 workflowModified: $workflowState->getModified()
66 )
67 )->getRoundedExecutionTime();
68 $efficiencyData = $workflowStateService->getEfficiencyData(
70 executionTime: $executionTime ?? 0,
71 averageDuration: $duration
72 )
73 );
74
75 $data['stats'] = [
76 'averageDuration' => $efficiencyData->getAverageDuration(),
77 'efficiency' => $efficiencyData->getEfficiency(),
78 ];
79
80 $data['biMenu'] = $this->getBiMenu($workflowState->getWorkflowTemplateId());
81
82 return $data;
83 }
84
85 private function getBiMenu(int $workflowTemplateId): ?array
86 {
87 if (!Loader::includeModule('biconnector'))
88 {
89 return null;
90 }
91
92 if (!defined('\Bitrix\BIConnector\Superset\Scope\ScopeService::BIC_SCOPE_WORKFLOW_TEMPLATE'))
93 {
94 return null;
95 }
96
97 $menu = \Bitrix\BIConnector\Superset\Scope\ScopeService::getInstance()->prepareScopeMenuItem(
98 \Bitrix\BIConnector\Superset\Scope\ScopeService::BIC_SCOPE_WORKFLOW_TEMPLATE,
99 [
100 'workflow_template_id' => $workflowTemplateId,
101 ]
102 );
103
104 return $menu ?: null;
105 }
106
107 public function terminateAction(string $workflowId): bool
108 {
109 $currentUserId = $this->getCurrentUser()?->getId();
110
111 $workflowService = new \Bitrix\Bizproc\Api\Service\WorkflowService(
112 accessService: new \Bitrix\Bizproc\Api\Service\WorkflowAccessService(),
113 );
114
116 workflowId: $workflowId,
117 userId: $currentUserId,
118 );
119
120 $result = $workflowService->terminateWorkflow($request);
121 if ($result->isSuccess())
122 {
123 return true;
124 }
125
126 $this->addErrors($result->getErrors());
127
128 return false;
129 }
130
131 public function terminateByTemplateAction(int $templateId, string $signedDocument): bool
132 {
133 $currentUserId = $this->getCurrentUser()?->getId();
134
135 $workflowService = new \Bitrix\Bizproc\Api\Service\WorkflowService(
136 new \Bitrix\Bizproc\Api\Service\WorkflowAccessService(),
137 );
138
139 [$documentType, $documentCategoryId, $documentId] = \CBPDocument::unSignParameters($signedDocument);
140 $complexDocumentId = [$documentType[0], $documentType[1], $documentId];
141
144 $complexDocumentId,
145 $currentUserId,
146 );
147
148 $result = $workflowService->terminateWorkflowsByTemplate($request);
149 if ($result->isSuccess())
150 {
151 return true;
152 }
153
154 $this->addErrors($result->getErrors());
155
156 return false;
157 }
158
159 public function getTemplateInstancesAction(int $templateId, int $offset = 0): ?array
160 {
161 $template = Bizproc\Workflow\Template\Entity\WorkflowTemplateTable::getById($templateId)->fetchObject();
162 $hasPermission = false;
163
164 if ($template)
165 {
166 $hasPermission = \CBPDocument::canUserOperateDocumentType(
168 $this->getCurrentUser()->getId(),
169 $template->getDocumentComplexType(),
170 );
171 }
172
173 if (!$hasPermission)
174 {
175 $this->addError(new Error(Loc::getMessage('BIZPROC_CONTROLLER_WORKFLOW_TEMPLATE_NO_PRERMISSIONS')));
176
177 return null;
178 }
179
181 $query->addFilter('WORKFLOW_TEMPLATE_ID', $templateId)
182 ->addSelect('ID')
183 ->setOrder(['STARTED' => 'ASC'])
184 ->setLimit(self::PAGE_SIZE + 1)
185 ->setOffset($offset)
186 ;
187 $result = $query->exec();
188 $ids = array_column($result->fetchAll(), 'ID');
189
190 if (!$ids)
191 {
192 $this->addError(new Error(Loc::getMessage('BIZPROC_CONTROLLER_WORKFLOW_TEMPLATE_NO_LIST')));
193
194 return null;
195 }
196
197 $hasNextPage = count($ids) > self::PAGE_SIZE;
198
199 if ($hasNextPage)
200 {
201 $ids = array_slice($ids, 0, self::PAGE_SIZE);
202 }
203
204 return [
205 'list' => array_map(
206 static fn($id) => new Bizproc\UI\WorkflowFacesView($id),
207 $ids,
208 ),
209 'hasNextPage' => $hasNextPage,
210 ];
211 }
212}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static addError($error)
Определения base.php:278
static addErrors(array $errors)
Определения base.php:287
getTimelineAction(string $workflowId)
Определения workflow.php:21
terminateByTemplateAction(int $templateId, string $signedDocument)
Определения workflow.php:131
getTemplateInstancesAction(int $templateId, int $offset=0)
Определения workflow.php:159
terminateAction(string $workflowId)
Определения workflow.php:107
Определения error.php:15
Определения request.php:10
const StartWorkflow
Определения constants.php:212
$templateId
Определения component_props2.php:51
$data['IS_AVAILABLE']
Определения .description.php:13
$template
Определения file_edit.php:49
</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
$query
Определения get_search.php:11
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$response
Определения result.php:21