Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
processor.php
1<?php
2
4
11use Bitrix\Tasks\Internals\Task\Status;
12
14{
15 protected $component;
16 protected $request;
17
18 protected $filter = [];
19 protected $order = [ 'LOG_DATE' => 'DESC' ];
20 protected $listParams = [];
21 protected $navParams = false;
22 protected $firstPage = false;
23 protected string $context = '';
24 protected int $userId = 0;
25 protected int $groupId = 0;
26
27 public function __construct($params)
28 {
29 $this->init($params);
30 }
31
32 public function setUserId(?int $userId): static
33 {
34 $this->userId = (int)$userId;
35 return $this;
36 }
37
38 public function setGroupId(?int $groupId): static
39 {
40 $this->groupId = (int)$groupId;
41 return $this;
42 }
43
44 protected function getComponent()
45 {
46 return $this->component;
47 }
48
49 public function getRequest()
50 {
51 return $this->request;
52 }
53
54 public function setFilter(array $value = []): void
55 {
56 $this->filter = $value;
57 }
58
59 public function getFilter(): array
60 {
61 return $this->filter;
62 }
63
64 public function setFilterKey($key = '', $value = false): void
65 {
66 if ($key == '')
67 {
68 return;
69 }
70 $this->filter[$key] = $value;
71 }
72
73 public function addFilter($key = '', $value = false): void
74 {
75 if (!isset($this->filter[$key]))
76 {
77 $this->setFilterKey($key, $value);
78 }
79 else
80 {
81 $value = is_array($value) ? $value : [$value];
82 $this->filter[$key] = array_merge($this->filter[$key], $value);
83 }
84 }
85
86 public function unsetFilterKey($key = ''): void
87 {
88 if ($key == '')
89 {
90 return;
91 }
92 unset($this->filter[$key]);
93 }
94
95 public function getFilterKey($key = '')
96 {
97 if ($key == '')
98 {
99 return false;
100 }
101 return ($this->filter[$key] ?? false);
102 }
103
104 public function setOrder(array $value = []): void
105 {
106 $this->order = $value;
107 }
108
109 public function setOrderKey($key = '', $value = false): void
110 {
111 if ($key == '')
112 {
113 return;
114 }
115 $this->order[$key] = $value;
116 }
117
118 public function getOrder(): array
119 {
120 return $this->order;
121 }
122
123 public function getOrderKey($key = '')
124 {
125 if ($key == '')
126 {
127 return false;
128 }
129 return ($this->order[$key] ?? false);
130 }
131
132 public function setListParams(array $value = []): void
133 {
134 $this->listParams = $value;
135 }
136
137 public function setListParamsKey($key = '', $value = false): void
138 {
139 if ($key == '')
140 {
141 return;
142 }
143 $this->listParams[$key] = $value;
144 }
145
146 public function getListParams(): array
147 {
148 return $this->listParams;
149 }
150
151 public function getListParamsKey($key = '')
152 {
153 if ($key == '')
154 {
155 return false;
156 }
157 return ($this->listParams[$key] ?? false);
158 }
159
160 public function setNavParams($value = false): void
161 {
162 $this->navParams = $value;
163 }
164
165 public function getNavParams()
166 {
167 return $this->navParams;
168 }
169
170 public function setFirstPage($value = false): void
171 {
172 $this->firstPage = $value;
173 }
174
175 public function getFirstPage(): bool
176 {
177 return $this->firstPage;
178 }
179
180 public function getUnreadTaskCommentsIdList(&$result): void
181 {
182 $result['UNREAD_COMMENTS_ID_LIST'] = [];
183
184 if ((int) ($result['LOG_COUNTER'] ?? null) <= 0)
185 {
186 return;
187 }
188
189 $tasks2LogList = $this->getComponent()->getTask2LogListValue();
190 if (empty($tasks2LogList))
191 {
192 return;
193 }
194
195 $result['UNREAD_COMMENTS_ID_LIST'] = self::getUnreadCommentsIdList([
196 'userId' => $result['currentUserId'],
197 'logIdList' => array_values($tasks2LogList),
198 ]);
199 }
200
201 protected static function getUnreadCommentsIdList($params): array
202 {
203 $result = [];
204
205 $userId = (int)($params['userId'] ?? 0);
206 $logIdList = (is_set($params['logIdList']) && is_array($params['logIdList']) ? $params['logIdList'] : []);
207
208 if (
209 $userId <= 0
210 || empty($logIdList)
211 )
212 {
213 return $result;
214 }
215
216 foreach($logIdList as $logId)
217 {
218 $result[(int)$logId] = [];
219 }
220
221 $query = UserCounterTable::query();
222 $query->addFilter('=USER_ID', $userId);
223 $query->addFilter('=SITE_ID', SITE_ID);
224
225 $subQuery = LogCommentTable::query();
226 $subQuery->whereIn('LOG_ID', $logIdList);
227 $subQuery->addSelect(new \Bitrix\Main\Entity\ExpressionField('COMMENT_CODE', "CONCAT('**LC', %s)", [ 'ID' ]));
228
229 $query->addFilter('@CODE', new SqlExpression($subQuery->getQuery()));
230 $query->addSelect('CODE');
231 $res = $query->exec();
232
233 $unreadCommentIdList = [];
234
235 while ($counterFields = $res->fetch())
236 {
237 if (preg_match('/\*\*LC(\d+)/i', $counterFields['CODE'], $matches))
238 {
239 $unreadCommentIdList[] = (int)$matches[1];
240 }
241 }
242
243 if (!empty($unreadCommentIdList))
244 {
246 'filter' => [
247 '@ID' => $unreadCommentIdList,
248 ],
249 'select' => [ 'ID', 'LOG_ID' ],
250 ]);
251 while ($logCommentFields = $res->fetch())
252 {
253 $result[(int)$logCommentFields['LOG_ID']][] = (int)$logCommentFields['ID'];
254 }
255 }
256
257 return $result;
258 }
259
260 public function getResultTaskCommentsIdList(&$result): void
261 {
262 $result['RESULT_TASKS_DATA'] = [];
263 $result['RESULT_FIELD_TASKS_ID'] = [];
264 $result['RESULT_COMMENTS_DATA'] = [];
265
266 $tasks2LogList = $this->getComponent()->getTask2LogListValue();
267 if (
268 empty($tasks2LogList)
269 || !Loader::includeModule('tasks')
270 || !class_exists("Bitrix\\Tasks\\Internals\\Task\\Result\\ResultManager")
271 )
272 {
273 return;
274 }
275
276 foreach ($tasks2LogList as $taskId => $logId)
277 {
278 $result['RESULT_TASKS_DATA'][(int)$logId] = (int)$taskId;
279 }
280
281 $taskIdList = [];
282
283 $res = \Bitrix\Tasks\Internals\TaskTable::getList([
284 'filter' => [
285 '@ID' => array_keys($tasks2LogList),
286 '!=STATUS' => Status::COMPLETED,
287 ],
288 'select' => [ 'ID' ],
289 ]);
290 while ($taskFields = $res->fetch())
291 {
292 $taskIdList[] = (int)$taskFields['ID'];
293 }
294
295 if (empty($taskIdList))
296 {
297 return;
298 }
299
300 $result['RESULT_FIELD_TASKS_ID'] = $taskIdList;
301
302 $resultCommentIdList = \Bitrix\Tasks\Internals\Task\Result\ResultManager::findResultComments($taskIdList);
303 foreach ($tasks2LogList as $taskId => $logId)
304 {
305 if (isset($resultCommentIdList[$taskId]))
306 {
307 $res = [];
308 foreach ($resultCommentIdList[$taskId] as $value)
309 {
310 $res[$value] = [
311 'taskId' => $taskId,
312 'logId' => $logId,
313 'commentId' => $value,
314 ];
315 }
316 $result['RESULT_COMMENTS_DATA'][$taskId] = $res;
317 }
318 }
319 }
320
321 public function getMicroblogUserId(&$result): void
322 {
323 $params = $this->getComponent()->arParams;
324
325 $result['MICROBLOG_USER_ID'] = (
326 $result['currentUserId'] > 0
327 && (
328 ($params['ENTITY_TYPE'] ?? null) !== SONET_ENTITY_GROUP
329 || (
330 \CSocNetFeaturesPerms::canPerformOperation($result['currentUserId'], SONET_ENTITY_GROUP, $params['GROUP_ID'], 'blog', 'full_post', $this->getComponent()->getCurrentUserAdmin())
331 || \CSocNetFeaturesPerms::canPerformOperation($result['currentUserId'], SONET_ENTITY_GROUP, $params['GROUP_ID'], 'blog', 'write_post')
332 || \CSocNetFeaturesPerms::canPerformOperation($result['currentUserId'], SONET_ENTITY_GROUP, $params['GROUP_ID'], 'blog', 'moderate_post')
333 || \CSocNetFeaturesPerms::canPerformOperation($result['currentUserId'], SONET_ENTITY_GROUP, $params['GROUP_ID'], 'blog', 'premoderate_post')
334 )
335 )
336 ? $result['currentUserId']
337 : 0
338 );
339 }
340
341 public function setContext(): void
342 {
343 $parameters = $this->getComponent()->arParams;
344 $this->context = $parameters['CONTEXT'] ?? '';
345 }
346
347 public function isSpace(): bool
348 {
349 return mb_strtolower($this->context) === Context::SPACES;
350 }
351
352 private function init(array $params): void
353 {
354 if(!empty($params['component']))
355 {
356 $this->component = $params['component'];
357 }
358
359 if(!empty($params['request']))
360 {
361 $this->request = $params['request'];
362 }
363 else
364 {
365 $this->request = Util::getRequest();
366 }
367 $this->setContext();
368 }
369}
static getList(array $parameters=array())