Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
forumpost.php
1<?php
2
4
18
19Loc::loadMessages(__FILE__);
20
21final class ForumPost extends Provider
22{
23 public const PROVIDER_ID = 'FORUM_POST';
24 public const CONTENT_TYPE_ID = 'FORUM_POST';
25
26 public static $auxCommentsCache = [];
27
28 public static function getId(): string
29 {
30 return self::PROVIDER_ID;
31 }
32
33 public function getEventId(): array
34 {
35 return [
36 'forum',
37 'tasks_comment',
38 'calendar_comment',
39 'timeman_entry_comment',
40 'report_comment',
41 'photo_comment',
42 'wiki_comment',
43 'lists_new_element_comment',
44 'crm_activity_add_comment',
45 ];
46 }
47
48 public function getType(): string
49 {
51 }
52
53 public function getRatingTypeId(): string
54 {
55 return 'FORUM_POST';
56 }
57
58 public function getUserTypeEntityId(): string
59 {
60 return 'FORUM_MESSAGE';
61 }
62
63 public static function getForumTypeMap(): array
64 {
65 return [
68 'DEFAULT' => ForumTopic::CONTENT_TYPE_ID,
72 'IBLOCK' => Wiki::CONTENT_TYPE_ID,
74 ];
75 }
76
77 public function initSourceFields(): void
78 {
79 $messageId = $this->entityId;
80
81 if (
82 $messageId <= 0
83 || !Loader::includeModule('forum')
84 )
85 {
86 return;
87 }
88
89 $res = MessageTable::getList([
90 'filter' => [
91 '=ID' => $messageId
92 ],
93 'select' => [ 'ID', 'POST_MESSAGE', 'SERVICE_TYPE', 'SERVICE_DATA', 'POST_DATE', 'AUTHOR_ID', 'TOPIC_ID' ]
94 ]);
95 $message = $res->fetch();
96
97 if (!$message)
98 {
99 return;
100 }
101
102 $auxData = [
103 'SHARE_DEST' => $message['SERVICE_DATA'],
104 'SOURCE_ID' => $messageId,
105 ];
106
107 $logId = false;
108
110 'filter' => [
111 'SOURCE_ID' => $messageId,
112 '@EVENT_ID' => $this->getEventId(),
113 ],
114 'select' => ['ID', 'LOG_ID', 'SHARE_DEST', 'MESSAGE', 'EVENT_ID', 'RATING_TYPE_ID']
115 ]);
116 if ($logComentFields = $res->fetch())
117 {
118 $logId = (int)$logComentFields['LOG_ID'];
119
120 $auxData['ID'] = (int)$logComentFields['ID'];
121 $auxData['LOG_ID'] = $logId;
122 }
123
124 $this->setSourceDescription($message['POST_MESSAGE']);
125
126 $title = htmlspecialcharsback($message['POST_MESSAGE']);
127 $title = \Bitrix\Socialnetwork\Helper\Mention::clear($title);
128
129 $CBXSanitizer = new \CBXSanitizer;
130 $CBXSanitizer->delAllTags();
131 $title = preg_replace(
132 [
133 "/\n+/is".BX_UTF_PCRE_MODIFIER,
134 "/\s+/is".BX_UTF_PCRE_MODIFIER
135 ],
136 ' ',
137 \CTextParser::clearAllTags($title)
138 );
139 $this->setSourceTitle(truncateText($title, 100));
140 $this->setSourceAttachedDiskObjects($this->getAttachedDiskObjects($this->cloneDiskObjects));
141 $this->setSourceDiskObjects($this->getDiskObjects($messageId, $this->cloneDiskObjects));
142 $this->setSourceDateTime($message['POST_DATE']);
143 $this->setSourceAuthorId((int)$message['AUTHOR_ID']);
144
145 if ($logId)
146 {
147 $res = \CSocNetLog::getList(
148 [],
149 [
150 '=ID' => $logId
151 ],
152 false,
153 false,
154 [ 'ID', 'EVENT_ID' ],
155 [
156 'CHECK_RIGHTS' => 'Y',
157 'USE_FOLLOW' => 'N',
158 'USE_SUBSCRIBE' => 'N',
159 ]
160 );
161 if ($logFields = $res->fetch())
162 {
163 $this->setLogId($logFields['ID']);
164 $this->setSourceFields(array_merge($message, [ 'LOG_EVENT_ID' => $logFields['EVENT_ID'] ]));
165
166 if(
167 !empty($logComentFields)
168 && in_array((int)$message['SERVICE_TYPE'], Manager::getTypesList(), true)
169 )
170 {
171 $this->setSourceOriginalText($logComentFields['MESSAGE']);
172 $auxData['SHARE_DEST'] = '';
173 $auxData['EVENT_ID'] = $logComentFields['EVENT_ID'];
174 $auxData['SOURCE_ID'] = $messageId;
175 $auxData['RATING_TYPE_ID'] = $logComentFields['RATING_TYPE_ID'];
176 }
177 else
178 {
179 $this->setSourceOriginalText($message['POST_MESSAGE']);
180 }
181
182 $this->setSourceAuxData($auxData);
183 }
184 }
185 else
186 {
187 $this->setSourceFields($message);
188 $this->setSourceDescription($message['POST_MESSAGE']);
189 $this->setSourceOriginalText($message['POST_MESSAGE']);
190 $this->setSourceAuxData($auxData);
191 }
192 }
193
194 protected function getAttachedDiskObjects($clone = false)
195 {
196 return $this->getEntityAttachedDiskObjects([
197 'userFieldEntity' => 'FORUM_MESSAGE',
198 'userFieldCode' => 'UF_FORUM_MESSAGE_DOC',
199 'clone' => $clone,
200 ]);
201 }
202
203 public static function canRead($params): bool
204 {
205 return true;
206 }
207
208 protected function getPermissions(array $post): string
209 {
211 }
212
213 public function getLiveFeedUrl()
214 {
215 static $urlCache = [];
216 $result = '';
217
218 $entityUrl = false;
219
220 $logId = $this->getLogId();
221
222 if ($logId)
223 {
224 if (isset($urlCache[$logId]))
225 {
226 $entityUrl = $urlCache[$logId];
227 }
228 else
229 {
230 $res = self::$logTable::getList([
231 'filter' => [
232 'ID' => $logId,
233 ],
234 'select' => [ 'ENTITY_ID', 'EVENT_ID', 'SOURCE_ID', 'RATING_TYPE_ID', 'RATING_ENTITY_ID', 'PARAMS' ],
235 ]);
236 if ($logEntryFields = $res->fetch())
237 {
238 $provider = false;
239
240 $providerTasksTask = new TasksTask();
241 if (in_array((string)$logEntryFields['EVENT_ID'], $providerTasksTask->getEventId(), true))
242 {
243 $entityId = (int)$logEntryFields['SOURCE_ID'];
244 if ($logEntryFields['EVENT_ID'] === 'crm_activity_add')
245 {
246 if ($logEntryFields['RATING_TYPE_ID'] === 'TASK')
247 {
248 $entityId = (int)$logEntryFields['RATING_ENTITY_ID'];
249 }
250 elseif (
251 $logEntryFields['RATING_TYPE_ID'] === 'LOG_ENTRY'
252 && Loader::includeModule('crm')
253 && ($activity = \CCrmActivity::getById($logEntryFields['ENTITY_ID'], false))
254 && (int)$activity['TYPE_ID'] === \CCrmActivityType::Task
255 )
256 {
257 $entityId = (int)$activity['ASSOCIATED_ENTITY_ID'];
258 }
259 else
260 {
261 $entityId = 0;
262 }
263 }
264
265 if ($entityId > 0)
266 {
267 $provider = $providerTasksTask;
268 $provider->setOption('checkAccess', false);
269
270 $provider->setEntityId($entityId);
271 $provider->setLogId($logId);
272 $provider->initSourceFields();
273
274 $postUrl = $provider->getLiveFeedUrl();
275 $entityUrl = $postUrl.(mb_strpos($postUrl, '?') === false ? '?' : '&').'commentId='.$this->getEntityId().'#com'.$this->getEntityId();
276 }
277 }
278
279 if (!$provider)
280 {
281 $providerCalendarEvent = new CalendarEvent();
282 if (in_array($logEntryFields['EVENT_ID'], $providerCalendarEvent->getEventId(), true))
283 {
284 $provider = $providerCalendarEvent;
285 $provider->setEntityId((int)$logEntryFields['SOURCE_ID']);
286 $provider->setLogId($logId);
287 $provider->initSourceFields();
288
289 $postUrl = $provider->getLiveFeedUrl();
290 $entityUrl = $postUrl.(mb_strpos($postUrl, '?') === false ? '?' : '&').'commentId='.$this->getEntityId().'#com'.$this->getEntityId();
291 }
292 }
293
294 if (!$provider)
295 {
296 $providerTimemanEntry = new TimemanEntry();
297 if (in_array($logEntryFields['EVENT_ID'], $providerTimemanEntry->getEventId(), true))
298 {
299 $provider = $providerTimemanEntry;
300 $provider->setEntityId((int)$logEntryFields['SOURCE_ID']);
301 $provider->setLogId($logId);
302 $provider->initSourceFields();
303 $entityUrl = $provider->getLiveFeedUrl();
304 }
305 }
306
307 if (!$provider)
308 {
309 $providerTimemanReport = new TimemanReport();
310 if (in_array($logEntryFields['EVENT_ID'], $providerTimemanReport->getEventId(), true))
311 {
312 $provider = $providerTimemanReport;
313 $provider->setEntityId((int)$logEntryFields['SOURCE_ID']);
314 $provider->setLogId($logId);
315 $provider->initSourceFields();
316 $entityUrl = $provider->getLiveFeedUrl();
317 }
318 }
319
320 if (!$provider)
321 {
322 $providerPhotogalleryPhoto = new PhotogalleryPhoto();
323 if (in_array($logEntryFields['EVENT_ID'], $providerPhotogalleryPhoto->getEventId(), true))
324 {
325 $provider = $providerPhotogalleryPhoto;
326 $provider->setEntityId((int)$logEntryFields['SOURCE_ID']);
327 $provider->setLogId($logId);
328 $provider->initSourceFields();
329 $entityUrl = $provider->getLiveFeedUrl();
330 }
331 }
332
333 if (!$provider)
334 {
335 $providerWiki = new Wiki();
336 if (in_array($logEntryFields['EVENT_ID'], $providerWiki->getEventId(), true))
337 {
338 $provider = $providerWiki;
339 $provider->setEntityId((int)($logEntryFields['SOURCE_ID']));
340 $provider->setLogId($logId);
341 $provider->initSourceFields();
342 $entityUrl = $provider->getLiveFeedUrl();
343 }
344 }
345
346 if (!$provider)
347 {
348 $providerListsItem = new ListsItem();
349 if (in_array($logEntryFields['EVENT_ID'], $providerListsItem->getEventId(), true))
350 {
351 $provider = $providerListsItem;
352 $provider->setEntityId((int)($logEntryFields['SOURCE_ID']));
353 $provider->setLogId($logId);
354 $provider->initSourceFields();
355 $entityUrl = $provider->getLiveFeedUrl().'?commentId='.$this->getEntityId().'#com'.$this->getEntityId();
356 }
357 }
358
359 if (!$provider)
360 {
361 $providerForumTopic = new ForumTopic();
362 if (
363 !empty($logEntryFields['PARAMS'])
364 && unserialize($logEntryFields['PARAMS'], ['allowed_classes' => false])
365 && in_array($logEntryFields['EVENT_ID'], $providerForumTopic->getEventId(), true)
366 )
367 {
368 $paramsList = unserialize($logEntryFields["PARAMS"], ['allowed_classes' => false]);
369 if (!empty($paramsList["PATH_TO_MESSAGE"]))
370 {
371 $entityUrl = \CComponentEngine::makePathFromTemplate($paramsList["PATH_TO_MESSAGE"], [ "MID" => $this->getEntityId() ]);
372 }
373 }
374 }
375 }
376 }
377 }
378
379 if (!empty($entityUrl))
380 {
381 $result = $entityUrl;
382 }
383
384 return $result;
385 }
386
387 public function getSuffix($defaultValue = '')
388 {
389 $logEventId = $this->getLogEventId();
390
391 if (!empty($logEventId))
392 {
393 $providerTasksTask = new TasksTask();
394 if (in_array($logEventId, $providerTasksTask->getEventId(), true))
395 {
396 return 'TASK';
397 }
398
399 $providerCalendarEvent = new CalendarEvent();
400 if (in_array($logEventId, $providerCalendarEvent->getEventId(), true))
401 {
402 return 'CALENDAR';
403 }
404
405 $providerForumTopic = new ForumTopic();
406 if (in_array($logEventId, $providerForumTopic->getEventId(), true))
407 {
408 return 'FORUM_TOPIC';
409 }
410
411 $providerTimemanEntry = new TimemanEntry();
412 if (in_array($logEventId, $providerTimemanEntry->getEventId(), true))
413 {
414 return 'TIMEMAN_ENTRY';
415 }
416
417 $providerTimemanReport = new TimemanReport();
418 if (in_array($logEventId, $providerTimemanReport->getEventId(), true))
419 {
420 return 'TIMEMAN_REPORT';
421 }
422
423 $providerPhotogalleryPhoto = new PhotogalleryPhoto();
424 if (in_array($logEventId, $providerPhotogalleryPhoto->getEventId(), true))
425 {
426 return 'PHOTO_PHOTO';
427 }
428
429 $providerWiki = new Wiki();
430 if (in_array($logEventId, $providerWiki->getEventId(), true))
431 {
432 return 'WIKI';
433 }
434
435 $providerListsItem = new ListsItem();
436 if (in_array($logEventId, $providerListsItem->getEventId(), true))
437 {
438 return 'LISTS_NEW_ELEMENT';
439 }
440 }
441 elseif (!empty ($defaultValue))
442 {
443 return $defaultValue;
444 }
445
446 return '2';
447 }
448
449 public function add($params = [])
450 {
451 global $USER;
452
453 static $parser = null;
454
455 $siteId = (
456 isset($params['SITE_ID'])
457 && $params['SITE_ID'] <> ''
458 ? $params['SITE_ID']
459 : SITE_ID
460 );
461
462 $authorId = (
463 isset($params['AUTHOR_ID'])
464 && (int)$params['AUTHOR_ID'] > 0
465 ? (int)$params['AUTHOR_ID']
466 : $USER->getId()
467 );
468
469 $message = (string)($params['MESSAGE'] ?? '');
470
471 if (
472 $message === ''
473 || !Loader::includeModule('forum')
474 )
475 {
476 return false;
477 }
478
479 $logId = $this->getLogId();
480
481 $this->setLogId($logId);
482 $feedParams = $this->getFeedParams();
483 if (empty($feedParams))
484 {
485 return false;
486 }
487
488 $forumId = self::getForumId(array_merge($feedParams, [
489 'SITE_ID' => $siteId,
490 ]));
491
492 if (!$forumId)
493 {
494 return false;
495 }
496
497 $feed = new \Bitrix\Forum\Comments\Feed(
498 $forumId,
499 $feedParams,
500 $authorId
501 );
502
503 $forumMessageFields = [
504 'POST_MESSAGE' => $message,
505 'AUTHOR_ID' => $authorId,
506 'USE_SMILES' => 'Y',
507 'AUX' => (isset($params['AUX']) && $params['AUX'] === 'Y' ? $params['AUX'] : 'N')
508 ];
509
510 if ($message === CommentAux\CreateEntity::getPostText())
511 {
512 $forumMessageFields['SERVICE_TYPE'] = Manager::TYPE_ENTITY_CREATED;
513 $forumMessageFields['SERVICE_DATA'] = Json::encode(isset($params['AUX_DATA']) && is_array($params['AUX_DATA']) ? $params['AUX_DATA'] : []);
514 $forumMessageFields['POST_MESSAGE'] = Manager::find([
515 'SERVICE_TYPE' => Manager::TYPE_ENTITY_CREATED
516 ])->getText($forumMessageFields['SERVICE_DATA']);
517 $params['SHARE_DEST'] = '';
518
519 if (
520 is_array($params['AUX_DATA'])
521 && !empty($params['AUX_DATA']['entityType'])
522 && (int)$params['AUX_DATA']['entityId'] > 0
523 )
524 {
525 $entityLivefeedPovider = Provider::getProvider($params['AUX_DATA']['entityType']);
526 $entityLivefeedPovider->setEntityId((int)$params['AUX_DATA']['entityId']);
527 $entityLivefeedPovider->initSourceFields();
528
529 $url = $entityLivefeedPovider->getLiveFeedUrl();
530 if (!empty($url))
531 {
532 $metaData = UrlPreview::getMetadataAndHtmlByUrl($url, true, false);
533
534 if (
535 !empty($metaData)
536 && !empty($metaData['ID'])
537 && (int)$metaData['ID'] > 0
538 )
539 {
540 $signer = new \Bitrix\Main\Security\Sign\Signer();
541 $forumMessageFields['UF_FORUM_MES_URL_PRV'] = $signer->sign($metaData['ID'] . '', UrlPreview::SIGN_SALT);
542 }
543 }
544 }
545 }
546 elseif ($message === CommentAux\CreateTask::getPostText())
547 {
548 $forumMessageFields['SERVICE_TYPE'] = Manager::TYPE_TASK_CREATED;
549 $forumMessageFields['SERVICE_DATA'] = Json::encode(isset($params['AUX_DATA']) && is_array($params['AUX_DATA']) ? $params['AUX_DATA'] : []);
550 $forumMessageFields['POST_MESSAGE'] = Manager::find([
551 'SERVICE_TYPE' => Manager::TYPE_TASK_CREATED
552 ])->getText($forumMessageFields['SERVICE_DATA']);
553 $params['SHARE_DEST'] = '';
554 }
555
556 $forumComment = $feed->add($forumMessageFields);
557
558 if (!$forumComment)
559 {
560 return false;
561 }
562
563 $sonetCommentId = false;
564
565 if ($logId > 0)
566 {
567 if ($params['AUX'] === 'Y')
568 {
569 if ($parser === null)
570 {
571 $parser = new \CTextParser();
572 }
573
574 $sonetCommentFields = [
575 "ENTITY_TYPE" => $this->getLogEntityType(),
576 "ENTITY_ID" => $this->getLogEntityId(),
577 "EVENT_ID" => $this->getCommentEventId(),
578 "MESSAGE" => $message,
579 "TEXT_MESSAGE" => $parser->convert4mail($message),
580 "MODULE_ID" => $this->getModuleId(),
581 "SOURCE_ID" => $forumComment['ID'],
582 "LOG_ID" => $logId,
583 "RATING_TYPE_ID" => "FORUM_POST",
584 "RATING_ENTITY_ID" => $forumComment['ID'],
585 "USER_ID" => $authorId,
586 "=LOG_DATE" => \CDatabase::currentTimeFunction(),
587 ];
588
589 if (!empty($params['SHARE_DEST']))
590 {
591 $sonetCommentFields['SHARE_DEST'] = $params['SHARE_DEST'];
592 }
593
594 if (!empty($forumMessageFields['UF_FORUM_MES_URL_PRV']))
595 {
596 $sonetCommentFields['UF_SONET_COM_URL_PRV'] = $forumMessageFields['UF_FORUM_MES_URL_PRV'];
597 }
598
599 $sonetCommentId = \CSocNetLogComments::add($sonetCommentFields, false, false);
600 }
601 else // comment is added on event
602 {
604 'filter' => [
605 'EVENT_ID' => $this->getCommentEventId(),
606 'SOURCE_ID' => $forumComment['ID'],
607 ],
608 'select' => [ 'ID' ],
609 ]);
610 if ($sonetCommentFields = $res->fetch())
611 {
612 $sonetCommentId = $sonetCommentFields['ID'];
613 }
614 }
615 }
616
617 return [
618 'sonetCommentId' => $sonetCommentId,
619 'sourceCommentId' => $forumComment['ID']
620 ];
621 }
622
623 private static function getForumId($params = [])
624 {
625 $result = 0;
626
627 $siteId = (
628 isset($params['SITE_ID'])
629 && $params['SITE_ID'] <> ''
630 ? $params['SITE_ID']
631 : SITE_ID
632 );
633
634 if (isset($params['type']))
635 {
636 if ($params['type'] === 'TK')
637 {
638 $result = Option::get('tasks', 'task_forum_id', 0, $siteId);
639
640 if (
641 (int)$result <= 0
642 && Loader::includeModule('forum')
643 )
644 {
645 $res = ForumTable::getList([
646 'filter' => [
647 '=XML_ID' => 'intranet_tasks',
648 ],
649 'select' => [ 'ID' ],
650 ]);
651 if ($forumFields = $res->fetch())
652 {
653 $result = (int)$forumFields['ID'];
654 }
655 }
656 }
657 elseif ($params['type'] === 'WF')
658 {
659 $result = Option::get('bizproc', 'forum_id', 0, $siteId);
660
661 if ((int)$result <= 0)
662 {
663 $res = ForumTable::getList([
664 'filter' => [
665 '=XML_ID' => 'bizproc_workflow',
666 ],
667 'select' => [ 'ID' ],
668 ]);
669 if ($forumFields = $res->fetch())
670 {
671 $result = (int)$forumFields['ID'];
672 }
673 }
674 }
675 elseif (in_array($params['type'], [ 'TM', 'TR' ]))
676 {
677 $result = Option::get('timeman', 'report_forum_id', 0, $siteId);
678 }
679 elseif (
680 $params['type'] === 'EV'
681 && Loader::includeModule('calendar')
682 )
683 {
684 $calendarSettings = \CCalendar::getSettings();
685 $result = $calendarSettings["forum_id"];
686 }
687 elseif (
688 $params['type'] === 'PH'
689 && Loader::includeModule('forum')
690 )
691 {
692 $res = ForumTable::getList(array(
693 'filter' => array(
694 '=XML_ID' => 'PHOTOGALLERY_COMMENTS'
695 ),
696 'select' => array('ID')
697 ));
698 if ($forumFields = $res->fetch())
699 {
700 $result = (int)$forumFields['ID'];
701 }
702 }
703 elseif ($params['type'] === 'IBLOCK')
704 {
705 $result = Option::get('wiki', 'socnet_forum_id', 0, $siteId);
706 }
707 else
708 {
709 $res = ForumTable::getList(array(
710 'filter' => array(
711 '=XML_ID' => 'USERS_AND_GROUPS'
712 ),
713 'select' => array('ID')
714 ));
715 if ($forumFields = $res->fetch())
716 {
717 $result = (int)$forumFields['ID'];
718 }
719 }
720 }
721
722 return $result;
723 }
724
725 private function getCommentEventId()
726 {
727
728 $result = false;
729
730 $logEventId = $this->getLogEventId();
731 if (!$logEventId)
732 {
733 return $result;
734 }
735
736 switch($logEventId)
737 {
738 case 'tasks':
739 $result = 'tasks_comment';
740 break;
741 case 'crm_activity_add':
742 $result = 'crm_activity_add_comment';
743 break;
744 case 'calendar':
745 $result = 'calendar_comment';
746 break;
747 case 'forum':
748 $result = 'forum';
749 break;
750 case 'timeman_entry':
751 $result = 'timeman_entry_comment';
752 break;
753 case 'report':
754 $result = 'report_comment';
755 break;
756 case 'photo_photo':
757 $result = 'photo_comment';
758 break;
759 case 'wiki':
760 $result = 'wiki_comment';
761 break;
762 case 'lists_new_element':
763 $result = 'lists_new_element_comment';
764 break;
765 default:
766 $result = false;
767 }
768
769 return $result;
770 }
771
772 private function getModuleId()
773 {
774 $result = false;
775
776 $logEventId = $this->getLogEventId();
777 if (!$logEventId)
778 {
779 return $result;
780 }
781
782 switch($logEventId)
783 {
784 case 'tasks':
785 $result = 'tasks';
786 break;
787 case 'calendar':
788 $result = 'calendar';
789 break;
790 case 'forum':
791 $result = 'forum';
792 break;
793 case 'timeman_entry':
794 $result = 'timeman';
795 break;
796 case 'photo_photo':
797 $result = 'photogallery';
798 break;
799 case 'wiki':
800 $result = 'wiki';
801 break;
802 default:
803 $result = false;
804 }
805
806 return $result;
807 }
808
809 public function getFeedParams(): array
810 {
811 global $USER;
812
813 $result = [];
814
815 $entityType = false;
816 $entityId = 0;
817 $entityData = [];
818
820 if ($parentProvider)
821 {
822 $entityType = $parentProvider->getContentTypeId();
823 $entityId = $parentProvider->getEntityId();
824 $entityData = $parentProvider->getAdditionalParams();
825 }
826 else
827 {
828 $logId = $this->getLogId();
829
830 if (!$logId)
831 {
832 return $result;
833 }
834
835 $res = self::$logTable::getList(array(
836 'filter' => array(
837 'ID' => $logId
838 ),
839 'select' => array('EVENT_ID', 'SOURCE_ID')
840 ));
841
842 if (
843 ($logFields = $res->fetch())
844 && (!empty($logFields['EVENT_ID']))
845 && ((int)$logFields['SOURCE_ID'] > 0)
846 )
847 {
848 $this->setLogEventId($logFields['EVENT_ID']);
849
850 $providerTasksTask = new TasksTask();
851 if (in_array($logFields['EVENT_ID'], $providerTasksTask->getEventId(), true))
852 {
853 $entityType = $providerTasksTask->getContentTypeId();
854 $entityId = (int)$logFields['SOURCE_ID'];
855 }
856
857 if ($entityId <= 0)
858 {
859 $providerCalendarEvent = new CalendarEvent();
860 if (in_array($logFields['EVENT_ID'], $providerCalendarEvent->getEventId(), true))
861 {
862 $entityType = $providerCalendarEvent->getContentTypeId();
863 $entityId = (int)$logFields['SOURCE_ID'];
864 }
865 }
866
867 if ($entityId <= 0)
868 {
869 $providerForumTopic = new ForumTopic();
870 if (in_array($logFields['EVENT_ID'], $providerForumTopic->getEventId(), true))
871 {
872 $entityType = $providerForumTopic->getContentTypeId();
873 $entityId = (int)$logFields['SOURCE_ID'];
874 }
875 }
876
877 if ($entityId <= 0)
878 {
879 $providerTimemanEntry = new TimemanEntry();
880 if (in_array($logFields['EVENT_ID'], $providerTimemanEntry->getEventId(), true))
881 {
882 $entityType = $providerTimemanEntry->getContentTypeId();
883 $entityId = (int)$logFields['SOURCE_ID'];
884 }
885 }
886
887 if ($entityId <= 0)
888 {
889 $providerTimemanReport = new TimemanReport();
890 if (in_array($logFields['EVENT_ID'], $providerTimemanReport->getEventId(), true))
891 {
892 $entityType = $providerTimemanReport->getContentTypeId();
893 $entityId = (int)$logFields['SOURCE_ID'];
894 }
895 }
896
897 if ($entityId <= 0)
898 {
899 $providerPhotogalleryPhoto = new PhotogalleryPhoto();
900 if (in_array($logFields['EVENT_ID'], $providerPhotogalleryPhoto->getEventId(), true))
901 {
902 $entityType = $providerPhotogalleryPhoto->getContentTypeId();
903 $entityId = (int)$logFields['SOURCE_ID'];
904 }
905 }
906
907 if ($entityId <= 0)
908 {
909 $providerWiki = new Wiki();
910 if (in_array($logFields['EVENT_ID'], $providerWiki->getEventId(), true))
911 {
912 $entityType = $providerWiki->getContentTypeId();
913 $entityId = (int)$logFields['SOURCE_ID'];
914 }
915 }
916
917 if ($entityId <= 0)
918 {
919 $providerListsItem = new ListsItem();
920 if (in_array($logFields['EVENT_ID'], $providerListsItem->getEventId(), true))
921 {
922 $entityType = $providerListsItem->getContentTypeId();
923 $entityId = (int)$logFields['SOURCE_ID'];
924 }
925 }
926 }
927 }
928
929 if (
930 $entityType
931 && $entityId > 0
932 )
933 {
934 $xmlId = $entityId;
935 $type = array_search($entityType, \Bitrix\Socialnetwork\Livefeed\ForumPost::getForumTypeMap(), true);
936
937 if ($type)
938 {
939 switch ($entityType)
940 {
942 $xmlId = 'TASK_'.$entityId;
943 break;
945 $xmlId = 'EVENT_' . $entityId;
946 if (
947 is_array($entityData)
948 && !empty($entityData['parentId'])
949 && !empty($entityData['dateFrom'])
950 && Loader::includeModule('calendar')
951 )
952 {
953 $calendarEntry = \CCalendarEvent::getEventForViewInterface($entityData['parentId'], [
954 'eventDate' => $entityData['dateFrom'],
955 'userId' => $USER->getId(),
956 ]);
957
958 if ($calendarEntry)
959 {
960 $xmlId = \CCalendarEvent::getEventCommentXmlId($calendarEntry);
961 }
962 }
963 break;
965 $xmlId = 'TOPIC_'.$entityId;
966 break;
968 $xmlId = 'TIMEMAN_ENTRY_'.$entityId;
969 break;
971 $xmlId = 'TIMEMAN_REPORT_'.$entityId;
972 break;
974 $xmlId = 'PHOTO_'.$entityId;
975 break;
977 $xmlId = 'IBLOCK_'.$entityId;
978 break;
980 if (
981 Loader::includeModule('bizproc')
982 && ($workflowId = \CBPStateService::getWorkflowByIntegerId($entityId))
983 )
984 {
985 $xmlId = 'WF_' . $workflowId;
986 }
987 break;
988 default:
989 }
990
991 $result = [
992 'type' => $type,
993 'id' => $entityId,
994 'xml_id' => $xmlId,
995 ];
996 }
997 }
998
999 return $result;
1000 }
1001
1002 public function getAdditionalData($params = array()): array
1003 {
1004 $result = [];
1005
1006 if (
1007 !$this->checkAdditionalDataParams($params)
1008 || !Loader::includeModule('forum')
1009 )
1010 {
1011 return $result;
1012 }
1013
1014 $res = MessageTable::getList([
1015 'filter' => array(
1016 '@ID' => $params['id']
1017 ),
1018 'select' => array('ID', 'USE_SMILES')
1019 ]);
1020
1021 while ($message = $res->fetch())
1022 {
1023 $data = $message;
1024 unset($data['ID']);
1025 $result[$message['ID']] = $data;
1026 }
1027
1028 return $result;
1029 }
1030
1031 public function warmUpAuxCommentsStaticCache(array $params = []): void
1032 {
1033 if (!Loader::includeModule('forum'))
1034 {
1035 return;
1036 }
1037
1038 $logEventsData = (isset($params['logEventsData']) && is_array($params['logEventsData']) ? $params['logEventsData'] : []);
1039
1040 $forumCommentEventIdList = $this->getEventId();
1041
1042 $logIdList = [];
1043 foreach($logEventsData as $logId => $logEventId)
1044 {
1045 $commentEvent = \CSocNetLogTools::findLogCommentEventByLogEventID($logEventId);
1046 if (empty($commentEvent['EVENT_ID']))
1047 {
1048 continue;
1049 }
1050
1051 if (in_array($commentEvent['EVENT_ID'], $forumCommentEventIdList, true))
1052 {
1053 $logIdList[] = $logId;
1054 }
1055 }
1056
1057 if (!empty($logIdList))
1058 {
1059 $query = MessageTable::query();
1060 $query->setSelect([ 'ID', 'POST_MESSAGE', 'SERVICE_DATA', 'SERVICE_TYPE' ]);
1061 $query->whereIn('SERVICE_TYPE', Manager::getTypesList());
1062 $query->registerRuntimeField(
1063 new Reference(
1064 'LOG_COMMENT', LogCommentTable::class, Join::on('this.ID', 'ref.SOURCE_ID'), [ 'join_type' => 'INNER' ]
1065 )
1066 );
1067 $query->whereIn('LOG_COMMENT.LOG_ID', $logIdList);
1068 $query->setLimit(1000);
1069
1070 $messages = $query->exec()->fetchCollection();
1071 while ($message = $messages->current())
1072 {
1073 $messageFields = $message->collectValues();
1074 self::$auxCommentsCache[$messageFields['ID']] = $messageFields;
1075 $messages->next();
1076 }
1077 }
1078 }
1079
1080 public function getAuxCommentCachedData(int $messageId = 0): array
1081 {
1082 $result = [];
1083
1084 if ($messageId <= 0)
1085 {
1086 return $result;
1087 }
1088
1089 return (self::$auxCommentsCache[$messageId] ?? []);
1090 }
1091
1092 public function getParentEntityId(): int
1093 {
1094 $result = 0;
1095
1096 $this->initSourceFields();
1097 $message = $this->getSourceFields();
1098
1099 if (
1100 empty($message)
1101 || (int)$message['TOPIC_ID'] <= 0
1102 )
1103 {
1104 return $result;
1105 }
1106
1107 $res = TopicTable::getList([
1108 'filter' => [
1109 '=ID' => (int)$message['TOPIC_ID']
1110 ],
1111 'select' => [ 'XML_ID' ],
1112 ]);
1113 if (
1114 ($topic = $res->fetch())
1115 && !empty($topic['XML_ID'])
1116 )
1117 {
1118 if (preg_match('/^(TASK|EVENT|TOPIC|TIMEMAN_ENTRY|TIMEMAN_REPORT|PHOTO|IBLOCK)_(\d+)$/i', $topic['XML_ID'], $matches))
1119 {
1120 $result = (int)$matches[2];
1121 }
1122 elseif (
1123 preg_match('/^(WF)_(.+)$/i', $topic['XML_ID'], $matches)
1124 && Loader::includeModule('bizproc')
1125 && $workflowIntegerId = \CBPStateService::getWorkflowIntegerId($matches[2])
1126 )
1127 {
1128 $result = $workflowIntegerId;
1129 }
1130 }
1131
1132 return $result;
1133 }
1134}
static find(array $params=[])
Definition manager.php:21
static loadMessages($file)
Definition loc.php:64
static getList(array $parameters=array())
Definition forumpost.php:22
initSourceFields()
Definition forumpost.php:77
getUserTypeEntityId()
Definition forumpost.php:58
static getForumTypeMap()
Definition forumpost.php:63
getAdditionalData($params=array())
getAuxCommentCachedData(int $messageId=0)
const CONTENT_TYPE_ID
Definition forumpost.php:24
getPermissions(array $post)
getRatingTypeId()
Definition forumpost.php:53
add($params=[])
getAttachedDiskObjects($clone=false)
getFeedParams()
warmUpAuxCommentsStaticCache(array $params=[])
getType()
Definition forumpost.php:48
getLiveFeedUrl()
getEventId()
Definition forumpost.php:33
static canRead($params)
static getId()
Definition forumpost.php:28
const PROVIDER_ID
Definition forumpost.php:23
getParentEntityId()
static $auxCommentsCache
Definition forumpost.php:26
getSuffix($defaultValue='')
setSourceDateTime(DateTime $datetime)
Definition provider.php:789
setSourceAttachedDiskObjects(array $diskAttachedObjects)
Definition provider.php:739
getEntityAttachedDiskObjects(array $params=[])
getDiskObjects($entityId, $clone=false)
Definition provider.php:822
const CONTENT_TYPE_ID