1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
WorkflowStateToGet.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\Api\Data\WorkflowStateService;
4
5use Bitrix\Bizproc\Workflow\Entity\WorkflowUserCommentTable;
6use Bitrix\Bizproc\Workflow\Entity\WorkflowUserTable;
7use Bitrix\Bizproc\Workflow\Task\TaskSearchContentTable;
8use Bitrix\Main\ArgumentException;
9use Bitrix\Main\DB\SqlExpression;
10use Bitrix\Main\ORM\Fields\Relations\Reference;
11use Bitrix\Main\ORM\Query;
12use Bitrix\Main\Type\DateTime;
13
15{
16 private const SEARCH_REF_NAME = 'SEARCH_CONTENT';
17 private array $select = ['ID', 'MODULE_ID', 'DOCUMENT_ID', 'ENTITY'];
18 private int $filterUserId = 0;
19 private ?string $filterPresetId;
20 private ?array $filterWorkflowIds;
21 private ?string $filterSearchQuery;
22 private array $filter = [];
23 private int $limit = 0;
24 private int $offset = 0;
25 private bool $isSelectAllFields = false;
26
27 private array $selectTaskFields = [];
28 private ?int $selectTaskLimit = 50;
29
30 private bool $countTotal = false;
31
32 public function setAdditionalSelectFields(array $additionalSelect): static
33 {
34 $allowedFields = $this->getAllowedAdditionalFields();
35
36 foreach ($additionalSelect as $fieldId)
37 {
38 if (in_array($fieldId, $allowedFields, true) && !in_array($fieldId, $this->select, true))
39 {
40 $this->select[] = $fieldId;
41 }
42 }
43
44 return $this;
45 }
46
47 public function setFilter(array $filter): static
48 {
49 $this->filter = $filter;
50
51 return $this;
52 }
53
54 public function setTaskSelectFields(array $taskSelect): static
55 {
56 $allowedTaskFields = $this->getAllowedTaskFields();
57
58 foreach ($taskSelect as $fieldId)
59 {
60 if (in_array($fieldId, $allowedTaskFields, true))
61 {
62 $this->selectTaskFields[] = $fieldId;
63 }
64 }
65
66 $this->selectTaskFields = array_unique($this->selectTaskFields);
67
68 return $this;
69 }
70
71 public function getSelectTaskFields(): array
72 {
73 return $this->selectTaskFields;
74 }
75
83 public function setSelectTaskLimit(?int $taskLimit): static
84 {
85 if (is_int($taskLimit))
86 {
87 if ($taskLimit <= 0)
88 {
89 throw new ArgumentException('Task limit must be positive integer or null');
90 }
91 $this->selectTaskLimit = $taskLimit;
92 }
93 else
94 {
95 $this->selectTaskLimit = null;
96 }
97
98 return $this;
99 }
100
101 public function getSelectTaskLimit(): ?int
102 {
103 return $this->selectTaskLimit;
104 }
105
106 public function setSelectAllFields(bool $flag = true): static
107 {
108 $this->isSelectAllFields = $flag;
109
110 return $this;
111 }
112
113 public function setFilterUserId(int $userId): static
114 {
115 $this->filterUserId = $userId;
116
117 return $this;
118 }
119
120 public function getFilterUserId(): int
121 {
122 return $this->filterUserId;
123 }
124
125 public function setFilterPresetId(string $presetId): static
126 {
127 if (WorkflowStateFilter::isDefined($presetId))
128 {
129 $this->filterPresetId = $presetId;
130 }
131
132 return $this;
133 }
134
135 public function getFilterPresetId(): ?string
136 {
137 return $this->filterPresetId;
138 }
139
140 public function setFilterWorkflowIds(array $workflowIds): static
141 {
142 $this->filterWorkflowIds = $workflowIds;
143
144 return $this;
145 }
146
147 public function getFilterWorkflowIds(): ?array
148 {
149 return $this->filterWorkflowIds;
150 }
151
152 public function setFilterSearchQuery(string $query): static
153 {
154 $this->filterSearchQuery = TaskSearchContentTable::prepareSearchContent($query);
155
156 return $this;
157 }
158
159 public function getFilterSearchQuery(): ?string
160 {
161 return $this->filterSearchQuery;
162 }
163
164 public function setLimit(int $limit): static
165 {
166 if ($limit >= 0)
167 {
168 $this->limit = $limit;
169 }
170
171 return $this;
172 }
173
174 public function setOffset(int $offset): static
175 {
176 if ($offset >= 0)
177 {
178 $this->offset = $offset;
179 }
180
181 return $this;
182 }
183
184 public function countTotal(bool $count = true): static
185 {
186 $this->countTotal = $count;
187
188 return $this;
189 }
190
191 public function isCountingTotal(): bool
192 {
193 return $this->countTotal;
194 }
195
196 public function getSelect(): array
197 {
198 if ($this->isSelectAllFields)
199 {
200 return array_merge($this->select, $this->getAllowedAdditionalFields());
201 }
202
203 return $this->select;
204 }
205
206 public function getOrmFilter(): array
207 {
208 $filter = $this->filter;
209 $filter['=USER_ID'] = $this->filterUserId;
210
211 if (!empty($this->filterWorkflowIds))
212 {
213 $filter['@WORKFLOW_ID'] = $this->filterWorkflowIds;
214 }
215
216 $filterPresetId = $this->filterPresetId ?? null;
217
218 if ($filterPresetId === WorkflowStateFilter::PRESET_STARTED)
219 {
220 $filter['=IS_AUTHOR'] = 1;
221 }
222 elseif ($filterPresetId === WorkflowStateFilter::PRESET_HAS_TASK)
223 {
224 $filter['>TASK_STATUS'] = WorkflowUserTable::TASK_STATUS_NONE;
225 }
227 {
228 $filter['=WORKFLOW_STATUS'] = WorkflowUserTable::WORKFLOW_STATUS_COMPLETED;
229 }
230 elseif ($filterPresetId === WorkflowStateFilter::PRESET_IN_WORK)
231 {
232 $inWorkFilter = ['LOGIC' => 'OR'];
233 $inWorkFilter[] = [
234 '=WORKFLOW_STATUS' => new SqlExpression('?i', WorkflowUserTable::WORKFLOW_STATUS_ACTIVE),
235 0 => [
236 'LOGIC' => 'OR',
237 '=IS_AUTHOR' => 1,
238 '=TASK_STATUS' => WorkflowUserTable::TASK_STATUS_ACTIVE,
239 ],
240 ];
241
242 $inWorkFilter[] = [
243 '!=COMMENTS.UNREAD_CNT' => null,
244 0 => [
245 'LOGIC' => 'OR',
246 '=COMMENTS.LAST_TYPE' => new SqlExpression('?i', WorkflowUserCommentTable::COMMENT_TYPE_DEFAULT),
247 0 => [
248 '=COMMENTS.LAST_TYPE' => WorkflowUserCommentTable::COMMENT_TYPE_SYSTEM,
249 '>COMMENTS.MODIFIED' => DateTime::createFromTimestamp(time() - 86400) // one day
250 ],
251 ],
252 ];
253
254 $filter[] = $inWorkFilter;
255 }
257 {
258 $filter['=TASK_STATUS'] = WorkflowUserTable::TASK_STATUS_ACTIVE;
259 }
260 elseif ($filterPresetId === WorkflowStateFilter::PRESET_COMMENT)
261 {
262 $filter['!=COMMENTS.UNREAD_CNT'] = null;
263 }
264
265 if (!empty($this->filterSearchQuery))
266 {
267 $find = Query\Filter\Helper::matchAgainstWildcard($this->filterSearchQuery);
268
269 $filter[] = [
270 'LOGIC' => 'AND',
271 '*' . static::SEARCH_REF_NAME . '.SEARCH_CONTENT' => $find,
272 '=' . static::SEARCH_REF_NAME . '.USERS.USER_ID' => $this->filterUserId,
273 ];
274 }
275
276 return $filter;
277 }
278
279 public function getOrmRuntime(): ?Reference
280 {
281 if (empty($this->filterSearchQuery))
282 {
283 return null;
284 }
285
286 $ref = new Reference(
287 static::SEARCH_REF_NAME,
289 [
290 '=this.WORKFLOW_ID' => 'ref.WORKFLOW_ID',
291 ],
292 );
293 $ref->configureJoinType(Query\Join::TYPE_INNER);
294
295 return $ref;
296 }
297
298 public function getOrder(): array
299 {
300 return ['MODIFIED' => 'DESC'];
301 }
302
303 public function getLimit(): int
304 {
305 return $this->limit;
306 }
307
308 public function getOffset(): int
309 {
310 return $this->offset;
311 }
312
313 private function getAllowedAdditionalFields(): array
314 {
315 return array_merge(
316 [
317 'STARTED_BY',
318 'STARTED',
319 'MODIFIED',
320 'WORKFLOW_TEMPLATE_ID',
321 'TEMPLATE.NAME',
322 // 'DOCUMENT_ID_INT',
323 //'STATE',
324 'STATE_TITLE',
325 // 'STATE_PARAMETERS',
326 ],
327 array_map(static fn($metaFieldName) => 'META.' . $metaFieldName, $this->getAllowedMetaFields()),
328 );
329 }
330
331 private function getAllowedTaskFields(): array
332 {
333 return [
334 'ID',
335 'ACTIVITY',
336 'MODIFIED',
337 'OVERDUE_DATE',
338 'NAME',
339 'DESCRIPTION',
340 'STATUS',
341 'IS_INLINE',
342 'DELEGATION_TYPE',
343 'PARAMETERS',
344
345 'TASK_USERS.USER_ID',
346 'TASK_USERS.STATUS',
347 'TASK_USERS.DATE_UPDATE',
348 'TASK_USERS.ORIGINAL_USER_ID',
349 ];
350 }
351
352 private function getAllowedMetaFields(): array
353 {
354 return ['ID', 'WORKFLOW_ID', 'START_DURATION'];
355 }
356}
return select
Определения access_edit.php:440
$count
Определения admin_tab.php:4
$allowedFields
Определения push.php:9
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getEntity()
Определения datamanager.php:65
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
$select
Определения iblock_catalog_list.php:194
$filter
Определения iblock_catalog_list.php:54
Определения chain.php:3
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393