Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
processor.php
1<?php
2
4
5use Bitrix\Crm\Activity\Provider\Tasks\Task;
14
16{
18
19 protected $select = [];
20 protected $filterData = false;
21 protected $filterContent = false;
22 protected $eventsList = [];
23 protected $tasksCount = 0;
24 protected $showPinnedPanel = true;
25
26 protected function getLogPageProcessorInstance()
27 {
28 if (
29 ($this->logPageProcessorInstance === null)
30 && $this->getComponent()
31 )
32 {
33 $this->logPageProcessorInstance = $this->getComponent()->getLogPageProcessorInstance();
34 }
36 }
37
38 public function setFilterData(array $value = []): void
39 {
40 $this->filterData = $value;
41 }
42
43 public function getFilterData()
44 {
45 return $this->filterData;
46 }
47
48 public function getFilterDataKey($key = '')
49 {
50 if ($key == '')
51 {
52 return false;
53 }
54 return ($this->filterData[$key] ?? false);
55 }
56
57 public function setFilterContent($value = false): void
58 {
59 $this->filterContent = $value;
60 }
61
62 public function getFilterContent()
63 {
65 }
66
67 public function setSelect($value = []): void
68 {
69 $this->select = $value;
70 }
71
72 public function getSelect(): array
73 {
74 return $this->select;
75 }
76
77 public function setEventsList(array $value = [], $type = 'main'): void
78 {
79 $this->eventsList[$type] = $value;
80 }
81
82 public function setEventsListKey($key = '', array $value = [], $type = 'main'): void
83 {
84 if ($key == '')
85 {
86 return;
87 }
88
89 if (!isset($this->eventsList[$type]))
90 {
91 $this->eventsList[$type] = [];
92 }
93
94 $this->eventsList[$type][$key] = $value;
95 }
96
97 public function appendEventsList(array $value = [], $type = 'main'): void
98 {
99 if (!isset($this->eventsList[$type]))
100 {
101 $this->eventsList[$type] = [];
102 }
103
104 $this->eventsList[$type][] = $value;
105 }
106
107 public function unsetEventsListKey($key = '', $type = 'main'): void
108 {
109 if ($key === '')
110 {
111 return;
112 }
113
114 if (!isset($this->eventsList[$type]))
115 {
116 return;
117 }
118
119 unset($this->eventsList[$type][$key]);
120 }
121
122 public function getEventsList($type = 'main')
123 {
124 return $this->eventsList[$type] ?? [];
125 }
126
127 public function incrementTasksCount(): void
128 {
129 $this->tasksCount++;
130 }
131
132 public function getTasksCount(): int
133 {
134 return $this->tasksCount;
135 }
136
137 public function makeTimeStampFromDateTime($value, $type = 'FULL')
138 {
139 static $siteDateFormatShort = null;
140 static $siteDateFormatFull = null;
141
142 if ($siteDateFormatShort === null)
143 {
144 $siteDateFormatShort = \CSite::getDateFormat('SHORT');
145 }
146 if ($siteDateFormatFull === null)
147 {
148 $siteDateFormatFull = \CSite::getDateFormat();
149 }
150
151 return makeTimeStamp($value, ($type === 'SHORT' ? $siteDateFormatShort : $siteDateFormatFull));
152 }
153
154 public function prepareContextData(&$result): void
155 {
156 $params = $this->getComponent()->arParams;
157
158 if (
159 $params['SET_TITLE'] === 'Y'
160 || $params['SET_NAV_CHAIN'] !== 'N'
161 || $params['GROUP_ID'] > 0
162 )
163 {
164 if ($params['ENTITY_TYPE'] === SONET_ENTITY_USER)
165 {
166 $res = \CUser::getById($params['USER_ID']);
167 $result['User'] = $res->fetch();
168 }
169 elseif ($params['ENTITY_TYPE'] === SONET_ENTITY_GROUP)
170 {
171 $result['Group'] = \CSocNetGroup::getById($params['GROUP_ID']);
172
173 if (
174 $result['Group']['OPENED'] === 'Y'
176 && !$this->getComponent()->getCurrentUserAdmin()
177 && !in_array(
178 \CSocNetUserToGroup::getUserRole($result['currentUserId'], $result['Group']['ID']),
180 true
181 )
182 )
183 {
184 $result['Group']['READ_ONLY'] = 'Y';
185 }
186 }
187 }
188 }
189
190 public function processFilterData(&$result): void
191 {
192 global $USER;
193
194 $params = $this->getComponent()->arParams;
195
196 if ($params['LOG_ID'] > 0)
197 {
198 $this->setFilterKey('ID', $params['LOG_ID']);
199 $this->showPinnedPanel = false;
200 }
201
202 $turnFollowModeOff = false;
203
204 if (isset($params['DISPLAY']))
205 {
206 $result['SHOW_UNREAD'] = 'N';
207
208 if (in_array($params['DISPLAY'], [ 'forme', 'my']))
209 {
210 $accessCodesList = $USER->getAccessCodes();
211 foreach ($accessCodesList as $i => $code)
212 {
213 if (!preg_match('/^(U|D|DR)/', $code)) //Users and Departments
214 {
215 unset($accessCodesList[$i]);
216 }
217 }
218 $this->setFilterKey('LOG_RIGHTS', $accessCodesList);
219 }
220
221 if ($params['DISPLAY'] === 'forme')
222 {
223 $this->setFilterKey('!USER_ID', $result['currentUserId']);
224 }
225 elseif ($params['DISPLAY'] === 'mine')
226 {
227 $this->setFilterKey('USER_ID', $result['currentUserId']);
228 }
229 elseif (is_numeric($params['DISPLAY']))
230 {
231 $this->setFilterKey('USER_ID', (int)$params['DISPLAY']);
232 }
233
234 if (
235 is_numeric($params['DISPLAY'])
236 || in_array($params['DISPLAY'], [ 'forme', 'mine'])
237 )
238 {
239 $result['IS_FILTERED'] = true;
240 }
241 $this->showPinnedPanel = false;
242 }
243
244 if (
245 !empty($params['DESTINATION'])
246 && is_array($params['DESTINATION'])
247 )
248 {
249 $this->setFilterKey('LOG_RIGHTS', $params['DESTINATION']);
250 if (count($params['DESTINATION']) == 1)
251 {
252 $code = array_shift($params['DESTINATION']);
253 if (preg_match('/^U(\d+)$/', $code, $matches))
254 {
255 $this->setFilterKey('!USER_ID', $matches[1]);
256 }
257 }
258
259 if (
260 $params['MODE'] === 'LANDING'
261 && !empty($params['DESTINATION_AUTHOR_ID'])
262 && (int)$params['DESTINATION_AUTHOR_ID'] > 0
263 ) // landing author filter
264 {
265 $this->setFilterKey('USER_ID', (int)$params['DESTINATION_AUTHOR_ID']);
266 }
267 }
268 elseif ($params['GROUP_ID'] > 0)
269 {
270 $this->setFilterKey('LOG_RIGHTS', 'SG'.$params['GROUP_ID']);
271
272 if (
273 isset($result['Group'])
274 && $result['Group']['OPENED'] === 'Y'
275 )
276 {
277 $this->setFilterKey('LOG_RIGHTS_SG', 'OSG' . $params['GROUP_ID'].'_' . (Util::checkUserAuthorized() ? SONET_ROLES_AUTHORIZED : SONET_ROLES_ALL));
278 }
279
280 $result['SHOW_FOLLOW_CONTROL'] = 'N';
281 $this->showPinnedPanel = false;
282 }
283 elseif ($params['TO_USER_ID'] > 0)
284 {
285 $this->setFilterKey('LOG_RIGHTS', 'U'.$params['TO_USER_ID']);
286 $this->setFilterKey('!USER_ID', $params['TO_USER_ID']);
287
288 $result['SHOW_FOLLOW_CONTROL'] = 'N';
289
290 $res = UserTable::getList([
291 'filter' => [
292 '=ID' => $params['TO_USER_ID']
293 ],
294 'select' => [ 'ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN' ]
295 ]);
296 if ($userFields = $res->fetch())
297 {
298 $result['ToUser'] = [
299 'ID' => $userFields['ID'],
300 'NAME' => \CUser::formatName($params['NAME_TEMPLATE'], $userFields, $this->getComponent()->useLogin)
301 ];
302 }
303 }
304 elseif ($params['USER_ID'] > 0)
305 {
306 $this->setFilterKey('ENTITY_TYPE', SONET_ENTITY_USER);
307 $this->setFilterKey('ENTITY_ID', $params['USER_ID']);
308 }
309 elseif ($params['ENTITY_TYPE'] <> '')
310 {
311 $this->setFilterKey('ENTITY_TYPE', $params['ENTITY_TYPE']);
312 }
313
314 if ($params['~TAG'] <> '')
315 {
316 $this->setFilterKey('=TAG', $params['~TAG']);
317 $turnFollowModeOff = true;
318 }
319 elseif ($params['FIND'] <> '')
320 {
321 $this->setFilterKey('*CONTENT', LogIndex::prepareToken($params['FIND']));
322 $this->showPinnedPanel = false;
323 }
324
325 if (
326 isset($params['!EXACT_EVENT_ID'])
327 && $params['!EXACT_EVENT_ID'] <> ''
328 )
329 {
330 $this->setFilterKey('!EVENT_ID', $params['!EXACT_EVENT_ID']);
331 $turnFollowModeOff = true;
332 }
333
334 if (
335 isset($params['EXACT_EVENT_ID'])
336 && $params['EXACT_EVENT_ID'] <> ''
337 )
338 {
339 $this->setFilterKey('EVENT_ID', [ $params['EXACT_EVENT_ID'] ]);
340 $turnFollowModeOff = true;
341 }
342 elseif (
343 isset($params['EVENT_ID'])
344 && is_array($params['EVENT_ID'])
345 )
346 {
347 if (!in_array('all', $params['EVENT_ID'], true))
348 {
349 $eventIdList = [];
350 foreach ($params['EVENT_ID'] as $eventId)
351 {
352 $eventIdList = array_merge($eventIdList, \CSocNetLogTools::findFullSetByEventID($eventId));
353 }
354
355 if (!empty($eventIdList))
356 {
357 $this->setFilterKey('EVENT_ID', array_unique($eventIdList));
358 }
359 $turnFollowModeOff = true;
360 }
361 }
362 elseif (
363 isset($params['EVENT_ID'])
364 && $params['EVENT_ID'] <> ''
365 )
366 {
367 $this->setFilterKey('EVENT_ID', \CSocNetLogTools::findFullSetByEventID($params['EVENT_ID']));
368 $turnFollowModeOff = true;
369 }
370 elseif ($this->getComponent()->getPresetFilterIdValue() === 'extranet')
371 {
372 $turnFollowModeOff = true;
373 }
374
375 if ($params['CREATED_BY_ID'] > 0)
376 {
377 if ($this->getComponent()->getCommentsNeededValue())
378 {
379 $this->setFilterKey('USER_ID|COMMENT_USER_ID', $params['CREATED_BY_ID']);
380 }
381 else
382 {
383 $this->setFilterKey('USER_ID', $params['CREATED_BY_ID']);
384 }
385 $this->unsetFilterKey('!USER_ID');
386 $turnFollowModeOff = true;
387 }
388
389 if ($params['GROUP_ID'] > 0)
390 {
391 $result['IS_FILTERED'] = true;
392 }
393
394 if (
395 isset($params['FLT_ALL'])
396 && $params['FLT_ALL'] === 'Y'
397 )
398 {
399 $this->setFilterKey('ALL', 'Y');
400 }
401
402 if (isset($params['FILTER_SITE_ID']))
403 {
404 $this->setFilterKey('SITE_ID', $params['FILTER_SITE_ID']);
405 }
406 elseif ($params['MODE'] !== 'LANDING')
407 {
408 $this->setFilterKey('SITE_ID', (
409 $result['isExtranetSite']
410 ? SITE_ID
411 : [ SITE_ID, false ]
412 ));
413 }
414
415 if (
416 isset($params['LOG_DATE_FROM'])
417 && $params['LOG_DATE_FROM'] <> ''
418 && $this->makeTimeStampFromDateTime($params['LOG_DATE_FROM'], 'SHORT') < time() + $result['TZ_OFFSET']
419 )
420 {
421 $this->setFilterKey('>=LOG_DATE', $params['LOG_DATE_FROM']);
422 $turnFollowModeOff = true;
423 }
424 else
425 {
426 unset($_REQUEST['flt_date_from']);
427 }
428
429 if (
430 isset($params['LOG_DATE_TO'])
431 && $params['LOG_DATE_TO'] <> ''
432 && $this->makeTimeStampFromDateTime($params['LOG_DATE_TO'], 'SHORT') < time() + $result['TZ_OFFSET']
433 )
434 {
435 $this->setFilterKey('<=LOG_DATE', convertTimeStamp($this->makeTimeStampFromDateTime($params['LOG_DATE_TO'], 'SHORT')+86399, 'FULL'));
436 $turnFollowModeOff = true;
437 }
438 else
439 {
440 $this->setFilterKey('<=LOG_DATE', 'NOW');
441 unset($_REQUEST['flt_date_to']);
442 }
443
444 $this->processMainUIFilterData($result);
445
446 if ($params['IS_CRM'] === 'Y')
447 {
448 if (Loader::includeModule('crm'))
449 {
450 $result['CRM_ENTITY_TYPE_NAME'] = \CCrmOwnerType::resolveName(\CCrmLiveFeedEntity::resolveEntityTypeID($params['CRM_ENTITY_TYPE']));
451 $result['CRM_ENTITY_ID'] = $params['CRM_ENTITY_ID'];
452 }
453
454 if (
455 $params['CRM_ENTITY_TYPE'] <> ''
456 || $this->getComponent()->getPresetFilterTopIdValue()
457 )
458 {
459 $result['SHOW_UNREAD'] = 'N';
460 }
461 $this->showPinnedPanel = false;
462 }
463
464 $result['presetFilterTopIdValue'] = $this->getComponent()->getPresetFilterTopIdValue();
465 $result['presetFilterIdValue'] = $this->getComponent()->getPresetFilterIdValue();
466
467 if (
468 (
469 !isset($params['USE_FAVORITES'])
470 || $params['USE_FAVORITES'] !== 'N'
471 )
472 && isset($params['FAVORITES'])
473 && $params['FAVORITES'] === 'Y'
474 )
475 {
476 $this->setFilterKey('>FAVORITES_USER_ID', 0);
477 $result['SHOW_UNREAD'] = 'N';
478 }
479
480 if ($turnFollowModeOff)
481 {
482 $result['SHOW_UNREAD'] = 'N';
483 $result['SHOW_FOLLOW_CONTROL'] = 'N';
484 $result['IS_FILTERED'] = true;
485 }
486
487 if (
488 $params["IS_CRM"] !== "Y"
490 )
491 {
492 $eventIdFilter = $this->getFilterKey('EVENT_ID');
493 $notEventIdFilter = $this->getFilterKey('!EVENT_ID');
494
495 if (empty($notEventIdFilter))
496 {
497 $notEventIdFilter = [];
498 }
499 elseif (!is_array($notEventIdFilter))
500 {
501 $notEventIdFilter = [ $notEventIdFilter ];
502 }
503
504 if (empty($eventIdFilter))
505 {
506 $eventIdFilter = [];
507 }
508 elseif (!is_array($eventIdFilter))
509 {
510 $eventIdFilter = [ $eventIdFilter ];
511 }
512
513 if (ModuleManager::isModuleInstalled('tasks'))
514 {
515 $notEventIdFilter = array_merge($notEventIdFilter, [ 'tasks' ]);
516 $eventIdFilter = array_filter($eventIdFilter, static function($eventId) { return ($eventId !== 'tasks'); });
517 }
518 if (
519 ModuleManager::isModuleInstalled('crm')
520 && Option::get('crm', 'enable_livefeed_merge', 'N') === 'Y'
521 )
522 {
523 $notEventIdFilter = array_merge($notEventIdFilter, [ 'crm_activity_add' ]);
524 $eventIdFilter = array_filter($eventIdFilter, static function($eventId) { return ($eventId !== 'crm_activity_add'); });
525 }
526
527 if (!empty($notEventIdFilter))
528 {
529 $this->setFilterKey('!EVENT_ID', $notEventIdFilter);
530 }
531 $this->setFilterKey('EVENT_ID', $eventIdFilter);
532 }
533
534 $result['USE_PINNED'] = 'N';
535 $result['SHOW_PINNED_PANEL'] = 'N';
536
537 if (
538 $result['currentUserId'] > 0
539 && $params['MODE'] !== 'LANDING'
540 && $params['IS_CRM'] !== 'Y'
541 )
542 {
543 $result['USE_PINNED'] = 'Y';
544
545 if ($this->showPinnedPanel)
546 {
547 $this->setFilterKey('PINNED_USER_ID', 0);
548 $result['SHOW_PINNED_PANEL'] = 'Y';
549 }
550 }
551 }
552
553 protected function processMainUIFilterData(&$result): void
554 {
555 $request = $this->getRequest();
556 $params = $this->getComponent()->arParams;
557
558 if (
559 (
560 (
561 defined('SITE_TEMPLATE_ID')
562 && SITE_TEMPLATE_ID === 'bitrix24'
563 )
564 || (
565 isset($params['siteTemplateId'])
566 && in_array($params['siteTemplateId'], [ 'bitrix24', 'landing24' ])
567 )
568 )
569 && (int)$params['LOG_ID'] <= 0
570 && (
571 $request->get('useBXMainFilter') === 'Y'
572 || (($params['useBXMainFilter'] ?? '') === 'Y')
573 )
574 )
575 {
576 $filtered = false;
577 $filterOption = new \Bitrix\Main\UI\Filter\Options($result['FILTER_ID']);
578 $filterData = $filterOption->getFilter();
579
580 $result['FILTER_USED'] = (!empty($filterData) ? 'Y' : 'N');
581
583
584 if (
585 !empty($filterData['GROUP_ID'])
586 && preg_match('/^SG(\d+)$/', $filterData['GROUP_ID'], $matches)
587 )
588 {
589 $this->setFilterKey('LOG_RIGHTS', 'SG' . (int)$matches[1]);
590 }
591
592 if (
593 !empty($filterData['AUTHOR_ID'])
594 && preg_match('/^U(\d+)$/', $filterData['AUTHOR_ID'], $matches)
595 )
596 {
597 $this->setFilterKey('USER_ID', (int)$matches[1]);
598 }
599
600 if (
601 !empty($filterData['CREATED_BY_ID'])
602 && preg_match('/^U(\d+)$/', $filterData['CREATED_BY_ID'], $matches)
603 )
604 {
605 $filtered = true;
606 $this->setFilterKey('USER_ID', (int)$matches[1]);
607 }
608
609 if (!empty($filterData['TO']))
610 {
611 if (preg_match('/^U(\d+)$/', $filterData['TO'], $matches))
612 {
613 $this->setFilterKey('LOG_RIGHTS', 'U' . (int)$matches[1]);
614 if (empty($this->getFilterKey('USER_ID')))
615 {
616 $this->setFilterKey('!USER_ID', (int)$matches[1]);
617 }
618 }
619 elseif (preg_match('/^SG(\d+)$/', $filterData['TO'], $matches))
620 {
621 $this->setFilterKey('LOG_RIGHTS', 'SG' . (int)$matches[1]);
622 }
623 elseif (preg_match('/^DR(\d+)$/', $filterData['TO'], $matches))
624 {
625 $this->setFilterKey('LOG_RIGHTS', 'DR' . (int)$matches[1]);
626 }
627 elseif ($filterData['TO'] === 'UA')
628 {
629 $this->setFilterKey('LOG_RIGHTS', 'G2');
630 }
631
632 $filtered = !empty($this->getFilterKey('LOG_RIGHTS'));
633 }
634
635 if (
636 !empty($filterData['EXACT_EVENT_ID'])
637 && !is_array($filterData['EXACT_EVENT_ID'])
638 )
639 {
640 $filtered = true;
641 $this->setFilterKey('EVENT_ID', [ $filterData['EXACT_EVENT_ID'] ]);
642 }
643
644 if (
645 !empty($filterData['EVENT_ID'])
646 && is_array($filterData['EVENT_ID'])
647 )
648 {
649 $filtered = true;
650 $this->setFilterKey('EVENT_ID', []);
651
652 $eventIdFilterValue = $this->getFilterKey('EVENT_ID');
653 foreach ($filterData['EVENT_ID'] as $filterEventId)
654 {
655 // if specific blog_post event (important, vote, grat)
656 if (in_array($filterEventId, [ 'blog_post_important', 'blog_post_grat', 'blog_post_vote' ]))
657 {
658 $eventIdFilterValue[] = $filterEventId;
659 }
660 else
661 {
662 $eventIdFilterValue = array_merge($eventIdFilterValue, \CSocNetLogTools::findFullSetByEventID($filterEventId));
663 }
664 }
665 $this->setFilterKey('EVENT_ID', array_unique($eventIdFilterValue));
666 }
667
668 if (
669 !empty($filterData['FAVORITES_USER_ID'])
670 && $filterData['FAVORITES_USER_ID'] === 'Y'
671 )
672 {
673 $filtered = true;
674 $this->setFilterKey('>FAVORITES_USER_ID', 0);
675 }
676
677 if (
678 is_numeric($filterData['TAG'] ?? null)
679 || !empty(trim($filterData['TAG'] ?? ''))
680 )
681 {
682 $filtered = true;
683 $this->setFilterKey('=TAG', trim($filterData['TAG']));
684 }
685
686 $this->setFilterContent(trim($filterData['FIND'] ?? ''));
687 $findValue = (string)$this->getFilterContent();
688 if ($findValue !== '')
689 {
690 $filtered = true;
691 $this->setFilterKey('*CONTENT', LogIndex::prepareToken($findValue));
692 }
693
694 if (
695 !empty($filterData['EXTRANET'])
696 && $filterData['EXTRANET'] === 'Y'
697 && Loader::includeModule('extranet')
698 )
699 {
700 $filtered = true;
701 $this->setFilterKey('SITE_ID', \CExtranet::getExtranetSiteID());
702 $this->setFilterKey('!EVENT_ID', [ 'lists_new_element', 'tasks', 'timeman_entry', 'report', 'crm_activity_add' ]);
703 }
704
705 if (!empty($filterData['DATE_CREATE_from']))
706 {
707 $filtered = true;
708 if (!empty($this->getFilterContent()))
709 {
710 $this->setFilterKey('>=CONTENT_DATE_CREATE', $filterData['DATE_CREATE_from']);
711 }
712 else
713 {
714 $this->setFilterKey('>=LOG_DATE', $filterData['DATE_CREATE_from']);
715 }
716 }
717
718 if (!empty($filterData['DATE_CREATE_to']))
719 {
720 $filtered = true;
721 $dateCreateToValue = convertTimeStamp($this->makeTimeStampFromDateTime($filterData['DATE_CREATE_to'], 'SHORT') + 86399, 'FULL');
722
723 if (!empty($this->getFilterContent()))
724 {
725 $this->setFilterKey('<=CONTENT_DATE_CREATE', $dateCreateToValue);
726 }
727 else
728 {
729 $this->setFilterKey('<=LOG_DATE', $dateCreateToValue);
730 }
731 }
732
733 if ($filtered)
734 {
735 // extraordinal case, we cannot set arParams earlier
736 $params['SET_LOG_COUNTER'] = 'N';
737 $params['SET_LOG_PAGE_CACHE'] = 'N';
738 $params['USE_FOLLOW'] = 'N';
739 $params['SHOW_UNREAD'] = 'N';
740
741 $this->getComponent()->arParams = $params;
742
743 $result['SHOW_UNREAD'] = 'N';
744 $result['IS_FILTERED'] = true;
745 $this->showPinnedPanel = false;
746 }
747 }
748 elseif (
749 (
750 defined('SITE_TEMPLATE_ID')
751 && SITE_TEMPLATE_ID === 'bitrix24'
752 )
753 || $params['MODE'] === 'LANDING'
754 )
755 {
756 $filterOption = new \Bitrix\Main\UI\Filter\Options($result['FILTER_ID']);
757 $filterOption->reset();
758 }
759
760 $this->setComposition();
761
762 if (
763 (
764 $params['TAG'] !== ''
765 || $params['FIND'] !== ''
766 )
767 && $this->getRequest()->get('apply_filter') === 'Y'
768 )
769 {
770 $this->getComponent()->arParams['useBXMainFilter'] = 'Y';
771 }
772 }
773
774 public function processNavData(&$result): void
775 {
776 global $NavNum;
777
778 $request = $this->getRequest();
779 $params = $this->getComponent()->arParams;
780
781 $this->setNavParams([
782 'nPageSize' => $params['PAGE_SIZE'],
783 'bShowAll' => false,
784 'iNavAddRecords' => 1,
785 'bSkipPageReset' => true,
786 'nRecordCount' => 1000000
787 ]);
788 if ($params['LOG_CNT'] > 0)
789 {
790 $this->setNavParams([
791 'nTopCount' => $params['LOG_CNT']
792 ]);
793 $result['PAGE_NUMBER'] = 1;
794 $this->setFirstPage(true);
795 }
796 elseif (
797 !$result['AJAX_CALL']
798 || $result['bReload']
799 )
800 {
801 $this->setNavParams([
802 'nTopCount' => $params['PAGE_SIZE']
803 ]);
804 $result['PAGE_NUMBER'] = 1;
805 $this->setFirstPage(true);
806 }
807 elseif ((int)$request->get('PAGEN_' . ($NavNum + 1)) > 0)
808 {
809 $result['PAGE_NUMBER'] = (int)$request->get('PAGEN_' . ($NavNum + 1));
810 }
811 elseif ((int)$params['PAGE_NUMBER'] > 0)
812 {
813 $result['PAGE_NUMBER'] = (int)$params['PAGE_NUMBER'];
814 $navParams = $this->getNavParams();
815 $navParams['iNumPage'] = $result['PAGE_NUMBER'];
816 $this->setNavParams($navParams);
817 }
818 }
819
820 public function processOrderData(): void
821 {
822 $params = $this->getComponent()->arParams;
823
824 if (
825 !empty($params['ORDER'])
826 && is_array($params['ORDER'])
827 )
828 {
829 $this->setOrder($params['ORDER']);
830 }
831 elseif ($this->getComponent()->getCommentsNeededValue())
832 {
833 $this->setOrder(
834 !empty($this->getFilterContent())
835 ? []
836 : [ 'LOG_UPDATE' => 'DESC' ]
837 );
838 }
839 elseif ($params['USE_FOLLOW'] === 'Y')
840 {
841 $this->setOrder([ 'DATE_FOLLOW' => 'DESC' ]);
842 }
843 elseif ($params['USE_COMMENTS'] === 'Y')
844 {
845 $this->setOrder(
846 !empty($this->getFilterContent())
847 ? [ 'CONTENT_LOG_UPDATE' => 'DESC' ]
848 : [ 'LOG_UPDATE' => 'DESC' ]
849 );
850// $this->setOrder(!empty($this->->getProcessorInstance()->getFilterContent()) ? [] : [ 'LOG_UPDATE' => 'DESC' ]);
851 }
852
853 $this->setOrderKey('ID', 'DESC');
854 $order = $this->getOrder();
855 $res = getModuleEvents('socialnetwork', 'OnBuildSocNetLogOrder');
856 while ($eventFields = $res->fetch())
857 {
858 executeModuleEventEx($eventFields, [ &$order, $params ]);
859 }
860 $this->setOrder($order);
861 }
862
863 public function processLastTimestamp(&$result): void
864 {
865 $request = $this->getRequest();
866 $params = $this->getComponent()->arParams;
867
868 $result['LAST_LOG_TS'] = (isset($params['LAST_LOG_TIMESTAMP']) ? (int)$params['LAST_LOG_TIMESTAMP'] : (int)$request->get('ts'));
869
870 if (
871 $params['LOG_ID'] <= 0
872 && (
873 !$result['AJAX_CALL']
874 || $result['bReload']
875 )
876 )
877 {
878 $result['LAST_LOG_TS'] = \CUserCounter::getLastDate($result['currentUserId'], $result['COUNTER_TYPE']);
879
880 if ($result['LAST_LOG_TS'] == 0)
881 {
882 $result['LAST_LOG_TS'] = 1;
883 }
884 else
885 {
886 //We substruct TimeZone offset in order to get server time
887 //because of template compatibility
888 $result['LAST_LOG_TS'] -= $result['TZ_OFFSET'];
889 }
890 }
891 }
892
893 public function processListParams(&$result): void
894 {
895 $params = $this->getComponent()->arParams;
896
897 if ($params['IS_CRM'] === 'Y')
898 {
899 $this->setListParams([
900 'IS_CRM' => 'Y',
901 'CHECK_CRM_RIGHTS' => 'Y'
902 ]);
903
904 $filterParams = [
905 'ENTITY_TYPE' => $params['CRM_ENTITY_TYPE'],
906 'ENTITY_ID' => $params['CRM_ENTITY_ID'],
907 'AFFECTED_TYPES' => [],
908 'OPTIONS' => [
909 'CUSTOM_DATA' => (
910 isset($params['CUSTOM_DATA'])
911 && is_array($params['CUSTOM_DATA'])
912 ? $params['CUSTOM_DATA']
913 : []
914 )
915 ]
916 ];
917
918 $res = getModuleEvents('socialnetwork', 'OnBuildSocNetLogFilter'); // crm handler used
919 while ($eventFields = $res->fetch())
920 {
921 $filter = $this->getFilter();
922 executeModuleEventEx($eventFields, [ &$filter, &$filterParams, &$params ]);
923 $this->setFilter($filter);
924 $this->getComponent()->arParams = $params;
925 }
926
927 $this->setListParamsKey('CUSTOM_FILTER_PARAMS' , $filterParams);
928 }
929 else
930 {
931 if (
932 $params['PUBLIC_MODE'] !== 'Y'
933 && ModuleManager::isModuleInstalled('crm')
934 )
935 {
936 $this->addFilter('!MODULE_ID', ( // can't use !@MODULE_ID because of null
937 Option::get('crm', 'enable_livefeed_merge', 'N') === 'Y'
938 || (
939 !empty($this->getFilterKey('LOG_RIGHTS'))
940 && !is_array($this->getFilterKey('LOG_RIGHTS'))
941 && preg_match('/^SG(\d+)$/', $this->getFilterKey('LOG_RIGHTS'), $matches)
942 )
943 ? [ 'crm']
944 : [ 'crm', 'crm_shared' ]
945 ));
946 }
947
948 $this->setListParamsKey('CHECK_RIGHTS', ($params['MODE'] !== 'LANDING' ? 'Y' : 'N'));
949
950 if (
951 $params['MODE'] !== 'LANDING'
952 && $params['LOG_ID'] <= 0
953 && empty($this->getFilterDataKey('EVENT_ID'))
954 )
955 {
956 $this->setListParamsKey('CHECK_VIEW', 'Y');
957 }
958 }
959
960 if (
961 $params['USE_FOLLOW'] !== 'N'
962 && !ModuleManager::isModuleInstalled('intranet')
964 ) // BSM
965 {
966 $result['USE_SMART_FILTER'] = 'Y';
967 $this->setListParamsKey('MY_GROUPS_ONLY', (
968 \CSocNetLogSmartFilter::getDefaultValue($result['currentUserId']) === 'Y'
969 ? 'Y'
970 : 'N'
971 ));
972 }
973
974 if (
975 $result['isExtranetSite']
976 || $this->getFilterDataKey('EXTRANET') === 'Y'
977 || $this->getComponent()->getPresetFilterIdValue() === 'extranet'
978 )
979 {
980 $this->setListParamsKey('MY_GROUPS_ONLY', 'Y');
981 }
982
983 $result['MY_GROUPS_ONLY'] = $this->getListParamsKey('MY_GROUPS_ONLY');
984
985 if ($this->getComponent()->getCurrentUserAdmin())
986 {
987 $this->setListParamsKey('USER_ID', 'A');
988 }
989
990 if ($params['USE_FOLLOW'] === 'Y')
991 {
992 $this->setListParamsKey('USE_FOLLOW', 'Y');
993 }
994 else
995 {
996 $this->setListParamsKey('USE_FOLLOW', 'N');
997 $this->setListParamsKey('USE_SUBSCRIBE', 'N');
998 }
999
1000 if (
1001 isset($params['USE_FAVORITES'])
1002 && $params['USE_FAVORITES'] === 'N'
1003 )
1004 {
1005 $this->setListParamsKey('USE_FAVORITES', 'N');
1006 }
1007
1008 if (
1009 empty($result['RETURN_EMPTY_LIST'])
1010 && !empty($params['EMPTY_EXPLICIT'])
1011 && $params['EMPTY_EXPLICIT'] === 'Y'
1012 )
1013 {
1014 $this->setListParamsKey('EMPTY_LIST', 'Y');
1015 }
1016
1017 if ($result['USE_PINNED'] === 'Y')
1018 {
1019 $this->setListParamsKey('USE_PINNED', 'Y');
1020 }
1021 }
1022
1023 public function setListFilter(array $componentResult = []): void
1024 {
1025 if (!empty($componentResult['GRAT_POST_FILTER']))
1026 {
1027 $this->setFilterKey('EVENT_ID', 'blog_post_grat');
1028 $this->setFilterKey('SOURCE_ID', $componentResult['GRAT_POST_FILTER']);
1029 }
1030 }
1031
1032 public function processSelectData(&$result): void
1033 {
1034 $params = $this->getComponent()->arParams;
1035
1036 $select = [
1037 'ID', 'TMP_ID', 'MODULE_ID',
1038 'LOG_DATE', 'LOG_UPDATE', 'DATE_FOLLOW',
1039 'ENTITY_TYPE', 'ENTITY_ID', 'EVENT_ID', 'SOURCE_ID', 'USER_ID', 'FOLLOW',
1040 'RATING_TYPE_ID', 'RATING_ENTITY_ID',
1041 'LOG_DATE_TS',
1042 ];
1043
1044 if (
1045 !isset($params['USE_FAVORITES'])
1046 || $params['USE_FAVORITES'] !== 'N'
1047 )
1048 {
1049 $select[] = 'FAVORITES_USER_ID';
1050 }
1051
1052 if ($result['currentUserId'] > 0)
1053 {
1054 $select[] = 'PINNED_USER_ID';
1055 }
1056
1057 $this->setSelect($select);
1058 }
1059
1060 public function processDiskUFEntities(): void
1061 {
1062 $diskUFEntityList = $this->getComponent()->getDiskUFEntityListValue();
1063 if (
1064 !empty($diskUFEntityList['SONET_LOG'])
1065 || !empty($diskUFEntityList['BLOG_POST'])
1066 )
1067 {
1068 $res = getModuleEvents('socialnetwork', 'OnAfterFetchDiskUfEntity');
1069 while ($eventFields = $res->fetch())
1070 {
1071 executeModuleEventEx($eventFields, [ $diskUFEntityList ]);
1072 }
1073 }
1074 }
1075
1076 public function processCrmActivities($result): void
1077 {
1078 $activity2LogList = $this->getComponent()->getActivity2LogListValue();
1079
1080 if (
1081 !empty($activity2LogList)
1082 && Loader::includeModule('crm')
1083 && Loader::includeModule('tasks')
1084 )
1085 {
1086 $res = \CCrmActivity::getList(
1087 [],
1088 [
1089 '@ID' => array_keys($activity2LogList),
1090 'CHECK_PERMISSIONS' => 'N'
1091 ],
1092 false,
1093 false,
1094 ['ID', 'ASSOCIATED_ENTITY_ID', 'TYPE_ID', 'PROVIDER_ID']
1095 );
1096 while (
1097 ($activityFields = $res->fetch())
1098 && ((int)$activityFields['ASSOCIATED_ENTITY_ID'] > 0)
1099 )
1100 {
1101 if (
1102 (int)$activityFields['TYPE_ID'] === \CCrmActivityType::Task
1103 || (
1104 (int)$activityFields['TYPE_ID'] === \CCrmActivityType::Provider
1105 && $activityFields['PROVIDER_ID'] === Task::getId()
1106 )
1107 )
1108 {
1109 try
1110 {
1111 $taskItem = new \CTaskItem((int)$activityFields['ASSOCIATED_ENTITY_ID'], $result['currentUserId']);
1112 if (!$taskItem->checkCanRead())
1113 {
1114 $activity2LogList = $this->getComponent()->getActivity2LogListValue();
1115 unset($activity2LogList[$activityFields['ID']]);
1116 $this->getComponent()->setActivity2LogListValue($activity2LogList);
1117 unset($activity2LogList);
1118 }
1119 else
1120 {
1121 $task2LogList = $this->getComponent()->getTask2LogListValue();
1122 $task2LogList[(int)$activityFields['ASSOCIATED_ENTITY_ID']] = (int)$activity2LogList[$activityFields['ID']];
1123 $this->getComponent()->setTask2LogListValue($task2LogList);
1124 unset($task2LogList);
1125 }
1126 }
1127 catch (\CTaskAssertException $e)
1128 {
1129 }
1130 }
1131 }
1132 }
1133 }
1134
1135 public function processNextPageSize(&$result): void
1136 {
1137 $request = $this->getRequest();
1138 $params = $this->getComponent()->arParams;
1139 $filter = $this->getFilter();
1140
1141 $result['NEXT_PAGE_SIZE'] = 0;
1142
1143 if (
1144 isset($filter['>=LOG_UPDATE'])
1145 && count($result['arLogTmpID']) < $params['PAGE_SIZE']
1146 )
1147 {
1148 $result['NEXT_PAGE_SIZE'] = count($result['arLogTmpID']);
1149 }
1150 elseif ((int)$request->get('pagesize') > 0)
1151 {
1152 $result['NEXT_PAGE_SIZE'] = (int)$request->get('pagesize');
1153 }
1154 }
1155
1156 public function processContentList(&$result): void
1157 {
1158 $contentIdList = [];
1159 if (is_array($result['Events']))
1160 {
1161 foreach ($result['Events'] as $key => $eventFields)
1162 {
1163 if ($contentId = Livefeed\Provider::getContentId($eventFields))
1164 {
1165 $contentIdList[] = $result['Events'][$key]['CONTENT_ID'] = $contentId['ENTITY_TYPE'].'-'.$contentId['ENTITY_ID'];
1166 }
1167 }
1168 }
1169
1170 $result['ContentViewData'] = (
1171 !empty($contentIdList)
1172 ? \Bitrix\Socialnetwork\Item\UserContentView::getViewData([
1173 'contentId' => $contentIdList
1174 ])
1175 : []
1176 );
1177 }
1178
1179 public function processEventsList(&$result, $type = 'main'): void
1180 {
1181 $params = $this->getComponent()->arParams;
1182 $activity2LogList = $this->getComponent()->getActivity2LogListValue();
1183
1184 $eventsList = $this->getEventsList($type);
1185
1186 $prevPageLogIdList = [];
1187 if ($type === 'main')
1188 {
1191 {
1192 return;
1193 }
1194
1195 $prevPageLogIdList = $logPageProcessorInstance->getPrevPageLogIdList();
1196 }
1197
1198 foreach ($eventsList as $key => $eventFields)
1199 {
1200 if (
1201 $eventFields['EVENT_ID'] === 'crm_activity_add'
1202 && !empty($activity2LogList)
1203 && !in_array($eventFields['ID'], $activity2LogList)
1204 )
1205 {
1206 $this->unsetEventsListKey($key);
1207 }
1208 elseif (
1209 empty($prevPageLogIdList)
1210 || !in_array((int)$eventFields['ID'], $prevPageLogIdList, true)
1211 )
1212 {
1213 $eventFields['EVENT_ID_FULLSET'] = \CSocNetLogTools::findFullSetEventIDByEventID($eventFields['EVENT_ID']);
1214 $this->setEventsListKey($key, $eventFields, $type);
1215
1216 if (
1217 $type === 'main'
1218 && $eventFields['EVENT_ID'] === 'tasks'
1219 )
1220 {
1221 $this->incrementTasksCount();
1222 }
1223
1224 if (
1225 $type === 'main'
1226 && $key == 0
1227 )
1228 {
1229 if ($eventFields['DATE_FOLLOW'])
1230 {
1231 $logPageProcessorInstance->setDateFirstPageTimestamp($this->makeTimeStampFromDateTime($eventFields['DATE_FOLLOW']));
1232 }
1233 elseif (
1234 $params['USE_FOLLOW'] === 'N'
1235 && $eventFields['LOG_UPDATE']
1236 )
1237 {
1238 $logPageProcessorInstance->setDateFirstPageTimestamp($this->makeTimeStampFromDateTime($eventFields['LOG_UPDATE']));
1239 }
1240 }
1241 }
1242 else
1243 {
1244 $this->unsetEventsListKey($key, $type);
1245 }
1246 }
1247
1248 if ($type === 'main')
1249 {
1250 $result['Events'] = $this->getEventsList($type);
1251 }
1252 elseif ($type === 'pinned')
1253 {
1254 $result['pinnedEvents'] = $this->getEventsList($type);
1255 }
1256 }
1257
1258 public function processFavoritesData($result): void
1259 {
1260 $params = $this->getComponent()->arParams;
1261
1262 $idList = array_merge($result['arLogTmpID'], $result['pinnedIdList']);
1263
1264 if (
1265 !empty($idList)
1266 && $result['currentUserId'] > 0
1267 && (
1268 !isset($params['USE_FAVORITES'])
1269 || $params['USE_FAVORITES'] !== 'N'
1270 )
1271 )
1272 {
1273 $favLogIdList = [];
1274 $res = \Bitrix\Socialnetwork\LogFavoritesTable::getList([
1275 'filter' => [
1276 '@LOG_ID' => $idList,
1277 'USER_ID' => $result['currentUserId']
1278 ],
1279 'select' => [ 'LOG_ID' ]
1280 ]);
1281 while ($favEntry = $res->fetch())
1282 {
1283 $favLogIdList[] = (int)$favEntry['LOG_ID'];
1284 }
1285
1286 $eventsList = $this->getEventsList();
1287 foreach ($eventsList as $key => $entry)
1288 {
1289 $entry['FAVORITES_USER_ID'] = $entry['!FAVORITES_USER_ID'] = (
1290 in_array((int)$entry['ID'], $favLogIdList, true)
1291 ? $result['currentUserId']
1292 : 0
1293 );
1294 $this->setEventsListKey($key, $entry);
1295 }
1296 }
1297 }
1298
1299 public function getSmiles(&$result): void
1300 {
1301 global $CACHE_MANAGER;
1302
1303 if (!empty($this->getComponent()->getErrors()))
1304 {
1305 return;
1306 }
1307
1308 if (Loader::includeModule('forum'))
1309 {
1310 $result['Smiles'] = Option::get('forum', 'smile_gallery_id', 0);
1311 }
1312 else
1313 {
1314 $cacheId = 'b_sonet_smile_'.LANGUAGE_ID;
1315
1316 if ($CACHE_MANAGER->read(604800, $cacheId))
1317 {
1318 $result['Smiles'] = $CACHE_MANAGER->get($cacheId);
1319 }
1320 else
1321 {
1322 $result['Smiles'] = [];
1323
1324 $res = \CSocNetSmile::getList(
1325 [ 'SORT' => 'ASC' ],
1326 [
1327 'SMILE_TYPE' => 'S',
1328 'LANG_LID' => LANGUAGE_ID
1329 ],
1330 false,
1331 false,
1332 [ 'ID', 'IMAGE', 'DESCRIPTION', 'TYPING', 'SMILE_TYPE', 'SORT', 'LANG_NAME' ]
1333 );
1334 while ($smileFields = $res->fetch())
1335 {
1336 [$type] = explode(' ', $smileFields['TYPING']);
1337 $smileFields['TYPE'] = str_replace("'", "\'", $type);
1338 $smileFields['TYPE'] = str_replace("\\", "\\\\", $smileFields['TYPE']);
1339 $smileFields['NAME'] = $smileFields['LANG_NAME'];
1340 $smileFields['IMAGE'] = '/bitrix/images/socialnetwork/smile/'.$smileFields['IMAGE'];
1341
1342 $result['Smiles'][] = $smileFields;
1343 }
1344
1345 $CACHE_MANAGER->set($cacheId, $result['Smiles']);
1346 }
1347 }
1348 }
1349
1350 public function getExpertModeValue(&$result): void
1351 {
1352 $params = $this->getComponent()->arParams;
1353
1354 if (
1355 $params['USE_TASKS'] === 'Y'
1357 )
1358 {
1359 $result['EXPERT_MODE'] = 'N';
1360
1361 $res = LogViewTable::getList([
1362 'order' => [],
1363 'filter' => [
1364 'USER_ID' => $result['currentUserId'],
1365 '=EVENT_ID' => 'tasks'
1366 ],
1367 'select' => [ 'TYPE' ]
1368 ]);
1369 if ($logViewFields = $res->fetch())
1370 {
1371 $result['EXPERT_MODE'] = ($logViewFields['TYPE'] === 'N' ? 'Y' : 'N');
1372 }
1373 }
1374 }
1375
1376 public function warmUpStaticCache($result): void
1377 {
1378 $logEventsData = [];
1379
1380 if (is_array($result['Events']))
1381 {
1382 foreach ($result['Events'] as $eventFields)
1383 {
1384 $logEventsData[(int)$eventFields['ID']] = $eventFields['EVENT_ID'];
1385 }
1386 }
1387 if (is_array($result['pinnedEvents']))
1388 {
1389 foreach ($result['pinnedEvents'] as $eventFields)
1390 {
1391 $logEventsData[(int)$eventFields['ID']] = $eventFields['EVENT_ID'];
1392 }
1393 }
1394
1395 $forumPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\ForumPost();
1396 $forumPostLivefeedProvider->warmUpAuxCommentsStaticCache([
1397 'logEventsData' => $logEventsData,
1398 ]);
1399 }
1400
1401 private function setComposition(): void
1402 {
1403 if (!$this->isSpace())
1404 {
1405 return;
1406 }
1407 $composition = new Composition($this->userId, $this->groupId);
1408 $deselectedItems = $composition->getDeselectedSettings();
1409 $this->addFilter('!' . Composition::FILTER, $deselectedItems);
1410 }
1411}
setEventsList(array $value=[], $type='main')
Definition processor.php:77
appendEventsList(array $value=[], $type='main')
Definition processor.php:97
setEventsListKey($key='', array $value=[], $type='main')
Definition processor.php:82