Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
WorkflowStateToGet.php
1<?php
2
4
7
9{
10 private array $select = ['ID', 'MODULE_ID', 'DOCUMENT_ID', 'ENTITY'];
11 private int $filterUserId = 0;
12 private ?string $filterPresetId;
13 private ?array $filterWorkflowIds;
14 private int $limit = 0;
15 private int $offset = 0;
16 private bool $isSelectAllFields = false;
17
18 private bool $countTotal = false;
19
20 public function setAdditionalSelectFields(array $additionalSelect): static
21 {
22 $allowedFields = $this->getAllowedAdditionalFields();
23
24 foreach ($additionalSelect as $fieldId)
25 {
26 if (in_array($fieldId, $allowedFields, true) && !in_array($fieldId, $this->select, true))
27 {
28 $this->select[] = $fieldId;
29 }
30 }
31
32 return $this;
33 }
34
35 public function setSelectAllFields(bool $flag = true): static
36 {
37 $this->isSelectAllFields = $flag;
38
39 return $this;
40 }
41
42 public function setFilterUserId(int $userId): static
43 {
44 $this->filterUserId = $userId;
45
46 return $this;
47 }
48
49 public function getFilterUserId(): int
50 {
51 return $this->filterUserId;
52 }
53
54 public function setFilterPresetId(string $presetId): static
55 {
56 if (WorkflowStateFilter::isDefined($presetId))
57 {
58 $this->filterPresetId = $presetId;
59 }
60
61 return $this;
62 }
63
64 public function getFilterPresetId(): ?string
65 {
66 return $this->filterPresetId;
67 }
68
69 public function setFilterWorkflowIds(array $workflowIds): static
70 {
71 $this->filterWorkflowIds = $workflowIds;
72
73 return $this;
74 }
75
76 public function getFilterWorkflowIds(): ?array
77 {
78 return $this->filterWorkflowIds;
79 }
80
81 public function setLimit(int $limit): static
82 {
83 if ($limit >= 0)
84 {
85 $this->limit = $limit;
86 }
87
88 return $this;
89 }
90
91 public function setOffset(int $offset): static
92 {
93 if ($offset >= 0)
94 {
95 $this->offset = $offset;
96 }
97
98 return $this;
99 }
100
101 public function countTotal(bool $count = true): static
102 {
103 $this->countTotal = $count;
104
105 return $this;
106 }
107
108 public function isCountingTotal(): bool
109 {
110 return $this->countTotal;
111 }
112
113 public function getSelect(): array
114 {
115 if ($this->isSelectAllFields)
116 {
117 return array_merge($this->select, $this->getAllowedAdditionalFields());
118 }
119
120 return $this->select;
121 }
122
123 public function getOrmFilter(): array
124 {
125 $filter = [
126 '=USER_ID' => $this->filterUserId,
127 ];
128
129 if (!empty($this->filterWorkflowIds))
130 {
131 $filter['@WORKFLOW_ID'] = $this->filterWorkflowIds;
132 }
133
134 $filterPresetId = $this->filterPresetId ?? WorkflowStateFilter::PRESET_DEFAULT;
135
136 if ($filterPresetId === WorkflowStateFilter::PRESET_STARTED)
137 {
138 $filter['=IS_AUTHOR'] = 1;
139 }
140 elseif ($filterPresetId === WorkflowStateFilter::PRESET_HAS_TASK)
141 {
142 $filter['>TASK_STATUS'] = WorkflowUserTable::TASK_STATUS_NONE;
143 }
144 elseif ($filterPresetId === WorkflowStateFilter::PRESET_ALL_COMPLETED)
145 {
146 $filter['=WORKFLOW_STATUS'] = WorkflowUserTable::WORKFLOW_STATUS_COMPLETED;
147 }
148 else // ($filterPresetId === WorkflowStateFilter::PRESET_IN_WORK)
149 {
150 $filter['=WORKFLOW_STATUS'] = new SqlExpression('?i', WorkflowUserTable::WORKFLOW_STATUS_ACTIVE);
151 $filter[] = [
152 'LOGIC' => 'OR',
153 '=IS_AUTHOR' => 1,
155 ];
156 }
157
158 return $filter;
159 }
160
161 public function getOrder(): array
162 {
163 $filterPresetId = $this->filterPresetId ?? WorkflowStateFilter::PRESET_DEFAULT;
164
165 if (
167 || $filterPresetId === WorkflowStateFilter::PRESET_STARTED
168 )
169 {
170 return ['MODIFIED' => 'DESC'];
171 }
172
173 return ['TASK_STATUS' => 'DESC', 'MODIFIED' => 'DESC'];
174 }
175
176 public function getLimit(): int
177 {
178 return $this->limit;
179 }
180
181 public function getOffset(): int
182 {
183 return $this->offset;
184 }
185
186 private function getAllowedAdditionalFields(): array
187 {
188 return [
189 'STARTED_BY',
190 'STARTED',
191 'MODIFIED',
192 'WORKFLOW_TEMPLATE_ID',
193 'TEMPLATE.NAME',
194 // 'DOCUMENT_ID_INT',
195 //'STATE',
196 'STATE_TITLE',
197 // 'STATE_PARAMETERS',
198
199 'TASKS.ID',
200 'TASKS.ACTIVITY',
201 'TASKS.MODIFIED',
202 'TASKS.OVERDUE_DATE',
203 'TASKS.NAME',
204 'TASKS.DESCRIPTION',
205 'TASKS.STATUS',
206 'TASKS.IS_INLINE',
207 'TASKS.DELEGATION_TYPE',
208 'TASKS.PARAMETERS',
209
210 'TASKS.TASK_USERS.USER_ID',
211 'TASKS.TASK_USERS.STATUS',
212 'TASKS.TASK_USERS.DATE_UPDATE',
213 'TASKS.TASK_USERS.ORIGINAL_USER_ID',
214 ];
215 }
216}