Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
TasksToGet.php
1<?php
2
4
7
8final class TasksToGet
9{
10 private array $additionalSelectFields = [];
11 private array $sort = [];
12 private array $filter = [];
13 private int $offset = 0;
14 private int $limit = 10;
15
16 private function __construct(
17 private int $targetUserId,
18 )
19 {}
20
24 public static function createFromRequest(GetUserTasksRequest $request): self
25 {
26 $targetUserId = self::validateUserId($request->filter['USER_ID'] ?? 0);
27 if (!$targetUserId)
28 {
29 throw new ArgumentOutOfRangeException('targetUserId', 1, null);
30 }
31
32 $tasksToGet = new self($targetUserId);
33
34 if ($request->additionalSelectFields)
35 {
36 $tasksToGet->setAdditionalSelectFields($request->additionalSelectFields);
37 }
38 if ($request->sort)
39 {
40 $tasksToGet->setSort($request->sort);
41 }
42
43 $tasksToGet->offset = $request->offset;
44 $tasksToGet->limit = $request->limit;
45 $tasksToGet->filter = $request->filter;
46
47 return $tasksToGet;
48 }
49
54 private static function validateUserId(int $userId): int
55 {
56 return max($userId, 0);
57 }
58
62 public function getTargetUserId(): int
63 {
64 return $this->targetUserId;
65 }
66
71 private function setAdditionalSelectFields(array $additionalSelectFields): void
72 {
73 $additionalAllowedFields = [
74 'ACTIVITY_NAME',
75 'NAME',
76 'DESCRIPTION',
77 'DELEGATION_TYPE',
78 'WORKFLOW_TEMPLATE_ID',
79 'MODULE_ID',
80 'ENTITY',
81 'DOCUMENT_ID',
82 'WORKFLOW_TEMPLATE_NAME',
83 'WORKFLOW_TEMPLATE_TEMPLATE_ID',
84 'WORKFLOW_STARTED',
85 'WORKFLOW_STARTED_BY',
86 ];
87
88 $fields = [];
89 foreach ($additionalSelectFields as $fieldId)
90 {
91 if (in_array($fieldId, $additionalAllowedFields, true))
92 {
93 $fields[] = $fieldId;
94 }
95 }
96
97 $this->additionalSelectFields = $fields;
98 }
99
103 public function getAdditionalSelectFields(): array
104 {
105 return $this->additionalSelectFields;
106 }
107
112 private function setSort(array $sort): void
113 {
114 $this->sort = $sort;
115 }
116
120 public function getSort(): array
121 {
122 return $this->sort;
123 }
124
128 public function getFilter(): array
129 {
130 return $this->filter;
131 }
132
136 public function getOffset(): int
137 {
138 return $this->offset;
139 }
140
144 public function getLimit(): int
145 {
146 return $this->limit;
147 }
148
152 public function buildSelectFields(): array
153 {
154 $selectFields = [
155 'ID' => 'ID',
156 'WORKFLOW_ID' => 'WORKFLOW_ID',
157 'ACTIVITY' => 'ACTIVITY',
158 'MODIFIED' => 'MODIFIED',
159 'OVERDUE_DATE' => 'OVERDUE_DATE',
160 'PARAMETERS' => 'PARAMETERS',
161 'IS_INLINE' => 'IS_INLINE',
162 'STATUS' => 'STATUS',
163 'DOCUMENT_NAME' => 'DOCUMENT_NAME',
164 'USER_ID' => 'USER_ID',
165 'USER_STATUS' => 'USER_STATUS',
166 'WORKFLOW_STATE' => 'WORKFLOW_STATE',
167 ];
168
169 foreach ($this->getAdditionalSelectFields() as $fieldId)
170 {
171 $selectFields[$fieldId] = $fieldId;
172 }
173
174 return array_keys($selectFields);
175 }
176}
static createFromRequest(GetUserTasksRequest $request)