1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
forumpost.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Livefeed;
4
5use Bitrix\Forum\Comments\Service\Manager;
6use Bitrix\Forum\ForumTable;
7use Bitrix\Forum\TopicTable;
8use Bitrix\Main\Config\Option;
9use Bitrix\Main\Loader;
10use Bitrix\Main\Localization\Loc;
11use Bitrix\Forum\MessageTable;
12use Bitrix\Main\UrlPreview\UrlPreview;
13use Bitrix\Main\Web\Json;
14use Bitrix\Socialnetwork\LogCommentTable;
15use Bitrix\Main\ORM\Fields\Relations\Reference;
16use Bitrix\Main\ORM\Query\Join;
17use Bitrix\Socialnetwork\CommentAux;
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 [
67 'EV' => CalendarEvent::CONTENT_TYPE_ID,
68 'DEFAULT' => ForumTopic::CONTENT_TYPE_ID,
72 'IBLOCK' => Wiki::CONTENT_TYPE_ID,
74 ];
75 }
76
77 public function initSourceFields(): void
78 {
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']);
128
129 $CBXSanitizer = new \CBXSanitizer;
130 $CBXSanitizer->delAllTags();
131 $title = preg_replace(
132 [
133 "/\n+/isu",
134 "/\s+/isu"
135 ],
136 ' ',
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 {
210 return self::PERMISSION_READ;
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 '3';
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 return match ($logEventId)
737 {
738 'tasks' => 'tasks_comment',
739 'crm_activity_add' => 'crm_activity_add_comment',
740 'calendar' => 'calendar_comment',
741 'forum' => 'forum',
742 'timeman_entry' => 'timeman_entry_comment',
743 'report' => 'report_comment',
744 'photo_photo' => 'photo_comment',
745 'wiki' => 'wiki_comment',
746 'lists_new_element' => 'lists_new_element_comment',
747 default => false,
748 };
749 }
750
751 private function getModuleId()
752 {
753 $result = false;
754
755 $logEventId = $this->getLogEventId();
756 if (!$logEventId)
757 {
758 return $result;
759 }
760
761 return match ($logEventId)
762 {
763 'tasks' => 'tasks',
764 'calendar' => 'calendar',
765 'forum' => 'forum',
766 'timeman_entry' => 'timeman',
767 'photo_photo' => 'photogallery',
768 'wiki' => 'wiki',
769 default => false,
770 };
771 }
772
773 public function getFeedParams(): array
774 {
775 global $USER;
776
777 $result = [];
778
779 $entityType = false;
780 $entityId = 0;
781 $entityData = [];
782
784 if ($parentProvider)
785 {
786 $entityType = $parentProvider->getContentTypeId();
787 $entityId = $parentProvider->getEntityId();
788 $entityData = $parentProvider->getAdditionalParams();
789 }
790 else
791 {
792 $logId = $this->getLogId();
793
794 if (!$logId)
795 {
796 return $result;
797 }
798
799 $res = self::$logTable::getList(array(
800 'filter' => array(
801 'ID' => $logId
802 ),
803 'select' => array('EVENT_ID', 'SOURCE_ID')
804 ));
805
806 if (
807 ($logFields = $res->fetch())
808 && (!empty($logFields['EVENT_ID']))
809 && ((int)$logFields['SOURCE_ID'] > 0)
810 )
811 {
812 $this->setLogEventId($logFields['EVENT_ID']);
813
814 $providerTasksTask = new TasksTask();
815 if (in_array($logFields['EVENT_ID'], $providerTasksTask->getEventId(), true))
816 {
817 $entityType = $providerTasksTask->getContentTypeId();
818 $entityId = (int)$logFields['SOURCE_ID'];
819 }
820
821 if ($entityId <= 0)
822 {
823 $providerCalendarEvent = new CalendarEvent();
824 if (in_array($logFields['EVENT_ID'], $providerCalendarEvent->getEventId(), true))
825 {
826 $entityType = $providerCalendarEvent->getContentTypeId();
827 $entityId = (int)$logFields['SOURCE_ID'];
828 }
829 }
830
831 if ($entityId <= 0)
832 {
833 $providerForumTopic = new ForumTopic();
834 if (in_array($logFields['EVENT_ID'], $providerForumTopic->getEventId(), true))
835 {
836 $entityType = $providerForumTopic->getContentTypeId();
837 $entityId = (int)$logFields['SOURCE_ID'];
838 }
839 }
840
841 if ($entityId <= 0)
842 {
843 $providerTimemanEntry = new TimemanEntry();
844 if (in_array($logFields['EVENT_ID'], $providerTimemanEntry->getEventId(), true))
845 {
846 $entityType = $providerTimemanEntry->getContentTypeId();
847 $entityId = (int)$logFields['SOURCE_ID'];
848 }
849 }
850
851 if ($entityId <= 0)
852 {
853 $providerTimemanReport = new TimemanReport();
854 if (in_array($logFields['EVENT_ID'], $providerTimemanReport->getEventId(), true))
855 {
856 $entityType = $providerTimemanReport->getContentTypeId();
857 $entityId = (int)$logFields['SOURCE_ID'];
858 }
859 }
860
861 if ($entityId <= 0)
862 {
863 $providerPhotogalleryPhoto = new PhotogalleryPhoto();
864 if (in_array($logFields['EVENT_ID'], $providerPhotogalleryPhoto->getEventId(), true))
865 {
866 $entityType = $providerPhotogalleryPhoto->getContentTypeId();
867 $entityId = (int)$logFields['SOURCE_ID'];
868 }
869 }
870
871 if ($entityId <= 0)
872 {
873 $providerWiki = new Wiki();
874 if (in_array($logFields['EVENT_ID'], $providerWiki->getEventId(), true))
875 {
876 $entityType = $providerWiki->getContentTypeId();
877 $entityId = (int)$logFields['SOURCE_ID'];
878 }
879 }
880
881 if ($entityId <= 0)
882 {
883 $providerListsItem = new ListsItem();
884 if (in_array($logFields['EVENT_ID'], $providerListsItem->getEventId(), true))
885 {
886 $entityType = $providerListsItem->getContentTypeId();
887 $entityId = (int)$logFields['SOURCE_ID'];
888 }
889 }
890 }
891 }
892
893 if (
894 $entityType
895 && $entityId > 0
896 )
897 {
898 $xmlId = $entityId;
899 $type = array_search($entityType, \Bitrix\Socialnetwork\Livefeed\ForumPost::getForumTypeMap(), true);
900
901 if ($type)
902 {
903 switch ($entityType)
904 {
906 $xmlId = 'TASK_'.$entityId;
907 break;
908 case CalendarEvent::CONTENT_TYPE_ID:
909 $xmlId = 'EVENT_' . $entityId;
910 if (
911 is_array($entityData)
912 && !empty($entityData['parentId'])
913 && !empty($entityData['dateFrom'])
914 && Loader::includeModule('calendar')
915 )
916 {
917 $calendarEntry = \CCalendarEvent::getEventForViewInterface($entityData['parentId'], [
918 'eventDate' => $entityData['dateFrom'],
919 'userId' => $USER->getId(),
920 ]);
921
922 if ($calendarEntry)
923 {
924 $xmlId = \CCalendarEvent::getEventCommentXmlId($calendarEntry);
925 }
926 }
927 break;
929 $xmlId = 'TOPIC_'.$entityId;
930 break;
932 $xmlId = 'TIMEMAN_ENTRY_'.$entityId;
933 break;
935 $xmlId = 'TIMEMAN_REPORT_'.$entityId;
936 break;
938 $xmlId = 'PHOTO_'.$entityId;
939 break;
941 $xmlId = 'IBLOCK_'.$entityId;
942 break;
944 if (
945 Loader::includeModule('bizproc')
947 )
948 {
949 $xmlId = 'WF_' . $workflowId;
950 }
951 break;
952 default:
953 }
954
955 $result = [
956 'type' => $type,
957 'id' => $entityId,
958 'xml_id' => $xmlId,
959 ];
960 }
961 }
962
963 return $result;
964 }
965
966 public function getAdditionalData($params = array()): array
967 {
968 $result = [];
969
970 if (
972 || !Loader::includeModule('forum')
973 )
974 {
975 return $result;
976 }
977
978 $res = MessageTable::getList([
979 'filter' => array(
980 '@ID' => $params['id']
981 ),
982 'select' => array('ID', 'USE_SMILES')
983 ]);
984
985 while ($message = $res->fetch())
986 {
987 $data = $message;
988 unset($data['ID']);
989 $result[$message['ID']] = $data;
990 }
991
992 return $result;
993 }
994
995 public function warmUpAuxCommentsStaticCache(array $params = []): void
996 {
997 if (!Loader::includeModule('forum'))
998 {
999 return;
1000 }
1001
1002 $logEventsData = (isset($params['logEventsData']) && is_array($params['logEventsData']) ? $params['logEventsData'] : []);
1003
1004 $forumCommentEventIdList = $this->getEventId();
1005
1006 $logIdList = [];
1007 foreach($logEventsData as $logId => $logEventId)
1008 {
1009 $commentEvent = \CSocNetLogTools::findLogCommentEventByLogEventID($logEventId);
1010 if (empty($commentEvent['EVENT_ID']))
1011 {
1012 continue;
1013 }
1014
1015 if (in_array($commentEvent['EVENT_ID'], $forumCommentEventIdList, true))
1016 {
1017 $logIdList[] = $logId;
1018 }
1019 }
1020
1021 if (!empty($logIdList))
1022 {
1023 $query = MessageTable::query();
1024 $query->setSelect([ 'ID', 'POST_MESSAGE', 'SERVICE_DATA', 'SERVICE_TYPE' ]);
1025 $query->whereIn('SERVICE_TYPE', Manager::getTypesList());
1026 $query->registerRuntimeField(
1027 new Reference(
1028 'LOG_COMMENT', LogCommentTable::class, Join::on('this.ID', 'ref.SOURCE_ID'), [ 'join_type' => 'INNER' ]
1029 )
1030 );
1031 $query->whereIn('LOG_COMMENT.LOG_ID', $logIdList);
1032 $query->setLimit(1000);
1033
1034 $messages = $query->exec()->fetchCollection();
1035 while ($message = $messages->current())
1036 {
1037 $messageFields = $message->collectValues();
1038 self::$auxCommentsCache[$messageFields['ID']] = $messageFields;
1039 $messages->next();
1040 }
1041 }
1042 }
1043
1044 public function getAuxCommentCachedData(int $messageId = 0): array
1045 {
1046 $result = [];
1047
1048 if ($messageId <= 0)
1049 {
1050 return $result;
1051 }
1052
1053 return (self::$auxCommentsCache[$messageId] ?? []);
1054 }
1055
1056 public function getParentEntityId(): int
1057 {
1058 $result = 0;
1059
1060 $this->initSourceFields();
1061 $message = $this->getSourceFields();
1062
1063 if (
1064 empty($message)
1065 || (int)$message['TOPIC_ID'] <= 0
1066 )
1067 {
1068 return $result;
1069 }
1070
1071 $res = TopicTable::getList([
1072 'filter' => [
1073 '=ID' => (int)$message['TOPIC_ID']
1074 ],
1075 'select' => [ 'XML_ID' ],
1076 ]);
1077 if (
1078 ($topic = $res->fetch())
1079 && !empty($topic['XML_ID'])
1080 )
1081 {
1082 if (preg_match('/^(TASK|EVENT|TOPIC|TIMEMAN_ENTRY|TIMEMAN_REPORT|PHOTO|IBLOCK)_(\d+)$/i', $topic['XML_ID'], $matches))
1083 {
1084 $result = (int)$matches[2];
1085 }
1086 elseif (
1087 preg_match('/^(WF)_(.+)$/i', $topic['XML_ID'], $matches)
1088 && Loader::includeModule('bizproc')
1089 && $workflowIntegerId = \CBPStateService::getWorkflowIntegerId($matches[2])
1090 )
1091 {
1092 $result = $workflowIntegerId;
1093 }
1094 }
1095
1096 return $result;
1097 }
1098}
$type
Определения options.php:106
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
Определения options.php:32
$messageFields
Определения callback_ednaru.php:22
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
Определения callback_ismscenter.php:26
const TYPE_TASK_CREATED
Определения manager.php:8
static getTypesList()
Определения manager.php:12
static find(array $params=[])
Определения manager.php:22
const TYPE_ENTITY_CREATED
Определения manager.php:9
static getList(array $parameters=array())
Определения datamanager.php:431
static clear(string $text='')
Определения mention.php:98
Определения forumpost.php:22
initSourceFields()
Определения forumpost.php:77
getUserTypeEntityId()
Определения forumpost.php:58
static getForumTypeMap()
Определения forumpost.php:63
getAdditionalData($params=array())
Определения forumpost.php:966
getAuxCommentCachedData(int $messageId=0)
Определения forumpost.php:1044
const CONTENT_TYPE_ID
Определения forumpost.php:24
getPermissions(array $post)
Определения forumpost.php:208
getRatingTypeId()
Определения forumpost.php:53
add($params=[])
Определения forumpost.php:449
getAttachedDiskObjects($clone=false)
Определения forumpost.php:194
getFeedParams()
Определения forumpost.php:773
warmUpAuxCommentsStaticCache(array $params=[])
Определения forumpost.php:995
getType()
Определения forumpost.php:48
getLiveFeedUrl()
Определения forumpost.php:213
getEventId()
Определения forumpost.php:33
static canRead($params)
Определения forumpost.php:203
static getId()
Определения forumpost.php:28
const PROVIDER_ID
Определения forumpost.php:23
getParentEntityId()
Определения forumpost.php:1056
static $auxCommentsCache
Определения forumpost.php:26
getSuffix($defaultValue='')
Определения forumpost.php:387
setSourceFields(array $fields)
Определения provider.php:639
setSourceAuxData($auxData)
Определения provider.php:736
checkAdditionalDataParams(&$params)
Определения provider.php:1466
static getProvider($entityType)
Определения provider.php:186
setSourceDateTime(DateTime $datetime)
Определения provider.php:801
setSourceDiskObjects(array $files)
Определения provider.php:756
setSourceAttachedDiskObjects(array $diskAttachedObjects)
Определения provider.php:751
getEntityAttachedDiskObjects(array $params=[])
Определения provider.php:1495
setSourceAuthorId($authorId=0)
Определения provider.php:811
setSourceOriginalText($text)
Определения provider.php:721
setLogEventId($eventId='')
Определения provider.php:1337
setSourceDescription($description)
Определения provider.php:654
getLogId($params=[])
Определения provider.php:336
getDiskObjects($entityId, $clone=false)
Определения provider.php:834
Определения timemanentry.php:13
const CONTENT_TYPE_ID
Определения timemanentry.php:15
const CONTENT_TYPE_ID
Определения wiki.php:13
static getWorkflowIntegerId($workflowId)
Определения stateservice.php:404
static getWorkflowByIntegerId($integerId)
Определения stateservice.php:440
static makePathFromTemplate($template, $arParams=array())
Определения component_engine.php:355
static clearAllTags($text)
Определения textparser.php:2358
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$activity
Определения options.php:214
global $USER
Определения csv_new_run.php:40
$siteId
Определения ajax.php:8
htmlspecialcharsback($str)
Определения tools.php:2693
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$messages
Определения template.php:8
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$post
Определения template.php:8
$title
Определения pdf.php:123
$matches
Определения index.php:22
const SITE_ID
Определения sonet_set_content_view.php:12
$url
Определения iframe.php:7