1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Starter.php
См. документацию.
1<?php
2
4
11
12final class Starter
13{
14 private WorkflowService $workflowService;
15 private int $currentUserId;
16 private bool $isEnabled;
17 private int $elementId = 0;
18 private array $parameters = [];
19 private array $changedFields = [];
20 private ?int $timeToStart = null;
21
22 private ?bool $hasTemplatesOnStartup = null;
23
24 public function __construct(array $iBlockInfo, int $currentUserId)
25 {
26 $this->isEnabled = (
27 Loader::includeModule('bizproc')
28 && \CLists::isBpFeatureEnabled($iBlockInfo['IBLOCK_TYPE_ID'])
29 && (isset($iBlockInfo['BIZPROC']) && $iBlockInfo['BIZPROC'] === 'Y') // $iBlockInfo['BIZPROC'] != 'N'
30 );
31
32 $this->workflowService = new WorkflowService($iBlockInfo);
33 $this->currentUserId = max($currentUserId, 0);
34 }
35
36 public function setElementId(int $elementId): void
37 {
38 if ($elementId > 0)
39 {
40 $this->elementId = $elementId;
41 $this->hasTemplatesOnStartup = null;
42 }
43 }
44
45 public function setTimeToStart(?int $timeToStart = null): self
46 {
47 $this->timeToStart = $timeToStart;
48
49 return $this;
50 }
51
52 public function setParameters(array $parameters): Result
53 {
54 $result = new Result();
55
56 $parameterValuesResponse = $this->workflowService->getParameterValuesFromRequest($parameters, $this->elementId);
57 if ($parameterValuesResponse->isSuccess())
58 {
59 $this->parameters = $parameterValuesResponse->getParameters();
60 $this->hasTemplatesOnStartup = $this->elementId > 0 && $parameterValuesResponse->hasTemplatesOnStartup();
61 }
62
63 return (
65 ->addErrors($parameterValuesResponse->getErrors())
66 ->setData(['parameters' => $parameterValuesResponse->getParameters()])
67 );
68 }
69
70 public function hasTemplatesOnStartup(): bool
71 {
72 if ($this->hasTemplatesOnStartup === null)
73 {
74 $this->hasTemplatesOnStartup = $this->workflowService->hasTemplatesOnStartup(
75 $this->workflowService->getComplexDocumentId($this->elementId)
76 );
77 }
78
79 return $this->hasTemplatesOnStartup;
80 }
81
82 public function setChangedFields(array $changedFields): void
83 {
84 $this->changedFields = $changedFields;
85 }
86
87 public function isEnabled(): bool
88 {
89 return $this->isEnabled;
90 }
91
92 public function isRunnable(int $createdBy): Result
93 {
94 $result = new Result();
95
96 if (!$this->isEnabled())
97 {
98 return $result->addError(
99 new Error(Loc::getMessage('LISTS_LIB_WORKFLOW_STARTER_BP_NOT_AVAILABLE') ?? '')
100 );
101 }
102
103 $currentUserGroups = $this->getCurrentUserGroups($this->currentUserId > 0 && $this->currentUserId === $createdBy);
104 if (!$this->workflowService->canUserWriteDocument($this->elementId, $this->currentUserId, $currentUserGroups))
105 {
106 return $result->addError(
107 new Error(Loc::getMessage('LISTS_LIB_WORKFLOW_STARTER_USER_CANT_WRITE_DOCUMENT') ?? '')
108 );
109 }
110
111 if (!$this->workflowService->isConstantsTuned())
112 {
113 return $result->addError(
114 new Error(Loc::getMessage('LISTS_LIB_WORKFLOW_STARTER_CONSTANTS_NOT_CONFIGURED') ?? '')
115 );
116 }
117
118 return $result;
119 }
120
121 private function getCurrentUserGroups(bool $isAuthor = false): array
122 {
123 $userGroups = $this->currentUserId ? \CUser::GetUserGroup($this->currentUserId) : [];
124 if ($isAuthor && is_array($userGroups))
125 {
126 $userGroups[] = 'author';
127 }
128
129 return is_array($userGroups) ? $userGroups : [];
130 }
131
132 public function run(bool $isNewElement = false): Result
133 {
134 $result = new Result();
135
136 $startWorkflowResponse = $this->workflowService->startWorkflows(
138 $this->elementId,
139 $this->currentUserId,
140 $this->parameters,
141 !$isNewElement && $this->hasTemplatesOnStartup() ? $this->changedFields : [],
142 $isNewElement,
143 $this->timeToStart,
144 )
145 );
146
147 return (
148 $result
149 ->addErrors($startWorkflowResponse->getErrors())
150 ->setData(['workflowIds' => $startWorkflowResponse->getWorkflowIds()])
151 );
152 }
153}
run(bool $isNewElement=false)
Определения Starter.php:132
setChangedFields(array $changedFields)
Определения Starter.php:82
setTimeToStart(?int $timeToStart=null)
Определения Starter.php:45
setElementId(int $elementId)
Определения Starter.php:36
setParameters(array $parameters)
Определения Starter.php:52
__construct(array $iBlockInfo, int $currentUserId)
Определения Starter.php:24
hasTemplatesOnStartup()
Определения Starter.php:70
isRunnable(int $createdBy)
Определения Starter.php:92
Определения loader.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
Определения Starter.php:3