1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
provider.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Livefeed;
4
5use Bitrix\Disk\AttachedObject;
6use Bitrix\Main;
7use Bitrix\Main\Application;
8use Bitrix\Main\EventResult;
9use Bitrix\Main\Loader;
10use Bitrix\Main\Localization\Loc;
11use Bitrix\Main\Type\DateTime;
12use Bitrix\Socialnetwork\Internals\LiveFeed\Counter\CounterService;
13use Bitrix\Socialnetwork\Item\Subscription;
14use Bitrix\Socialnetwork\LogTable;
15use Bitrix\Socialnetwork\UserContentViewTable;
16use Bitrix\Socialnetwork\Item\UserContentView;
17use Bitrix\Socialnetwork\Item\Log;
18
19Loc::loadMessages(__FILE__);
20
21abstract class Provider
22{
23 public const DATA_RESULT_TYPE_SOURCE = 'SOURCE';
24
25 public const TYPE_POST = 'POST';
26 public const TYPE_COMMENT = 'COMMENT';
27
28 public const DATA_ENTITY_TYPE_BLOG_POST = 'BLOG_POST';
29 public const DATA_ENTITY_TYPE_BLOG_COMMENT = 'BLOG_COMMENT';
30 public const DATA_ENTITY_TYPE_TASKS_TASK = 'TASK';
31 public const DATA_ENTITY_TYPE_FORUM_TOPIC = 'FORUM_TOPIC';
32 public const DATA_ENTITY_TYPE_FORUM_POST = 'FORUM_POST';
33 public const DATA_ENTITY_TYPE_CALENDAR_EVENT = 'CALENDAR_EVENT';
34 public const DATA_ENTITY_TYPE_LOG_ENTRY = 'LOG_ENTRY';
35 public const DATA_ENTITY_TYPE_LOG_COMMENT = 'LOG_COMMENT';
36 public const DATA_ENTITY_TYPE_RATING_LIST = 'RATING_LIST';
37 public const DATA_ENTITY_TYPE_PHOTOGALLERY_ALBUM = 'PHOTO_ALBUM';
38 public const DATA_ENTITY_TYPE_PHOTOGALLERY_PHOTO = 'PHOTO_PHOTO';
39 public const DATA_ENTITY_TYPE_LISTS_ITEM = 'LISTS_NEW_ELEMENT';
40 public const DATA_ENTITY_TYPE_WIKI = 'WIKI';
41 public const DATA_ENTITY_TYPE_TIMEMAN_ENTRY = 'TIMEMAN_ENTRY';
42 public const DATA_ENTITY_TYPE_TIMEMAN_REPORT = 'TIMEMAN_REPORT';
43 public const DATA_ENTITY_TYPE_INTRANET_NEW_USER = 'INTRANET_NEW_USER';
44 public const DATA_ENTITY_TYPE_BITRIX24_NEW_USER = 'BITRIX24_NEW_USER';
45 public const DATA_ENTITY_TYPE_LIVE_FEED_VIEW = 'LIVE_FEED_VIEW';
46
47 public const PERMISSION_DENY = 'D';
48 public const PERMISSION_READ = 'I';
49 public const PERMISSION_FULL = 'W';
50
51 public const CONTENT_TYPE_ID = '';
52
53 protected $entityId = 0;
54 protected $additionalParams = [];
55 protected $logId = 0;
56 protected $sourceFields = [];
57 protected $siteId = false;
58 protected $options = [];
59 protected string $ratingTypeId = '';
60 protected int|null $ratingEntityId = null;
61 protected $parentProvider = false;
62
63 protected $cloneDiskObjects = false;
64 protected $sourceDescription = '';
65 protected $sourceTitle = '';
66 protected $pinnedTitle = '';
67 protected $sourceOriginalText = '';
68 protected $sourceAuxData = [];
70 protected $sourceDiskObjects = [];
71 protected $diskObjectsCloned = [];
73 protected $sourceDateTime = null;
74 protected $sourceAuthorId = 0;
75
76 protected $logEventId = null;
77 protected $logEntityType = null;
78 protected $logEntityId = null;
79
80 protected static $logTable = LogTable::class;
81
82 private static array $logIdCache = [];
83
87 public static function className(): string
88 {
89 return static::class;
90 }
91
92 public function setSiteId($siteId): void
93 {
94 $this->siteId = $siteId;
95 }
96
97 public function getSiteId()
98 {
99 return $this->siteId;
100 }
101
108 public function setOption(string $key, $value): void
109 {
110 $this->options[$key] = $value;
111 }
112
118 public function getOption(string $key)
119 {
120 return ($this->options[$key] ?? null);
121 }
122
123 public static function getId()
124 {
125 return 'BASE';
126 }
127
128 public function getEventId()
129 {
130 return false;
131 }
132
133 public function getType()
134 {
135 return '';
136 }
137
138 public function getRatingTypeId(): string
139 {
140 return $this->ratingTypeId;
141 }
142
143 public function setRatingTypeId(string $value): void
144 {
145 $this->ratingTypeId = $value;
146 }
147
148 public function getRatingEntityId(): int|null
149 {
150 return $this->ratingEntityId;
151 }
152
153 public function setRatingEntityId(int $value): void
154 {
155 $this->ratingEntityId = $value;
156 }
157
158 public function getUserTypeEntityId(): string
159 {
160 return '';
161 }
162
163 public function getCommentProvider()
164 {
165 return false;
166 }
167
168 public function setParentProvider($value): void
169 {
170 $this->parentProvider = $value;
171 }
172
173 public function getParentProvider()
174 {
175 return $this->parentProvider;
176 }
177
178 private static function getTypes(): array
179 {
180 return [
181 self::TYPE_POST,
182 self::TYPE_COMMENT,
183 ];
184 }
185
186 final public static function getProvider($entityType)
187 {
188 $provider = false;
189
190 $moduleEvent = new Main\Event(
191 'socialnetwork',
192 'onLogProviderGetProvider',
193 [
194 'entityType' => $entityType
195 ]
196 );
197 $moduleEvent->send();
198
199 foreach ($moduleEvent->getResults() as $moduleEventResult)
200 {
201 if ($moduleEventResult->getType() === EventResult::SUCCESS)
202 {
203 $moduleEventParams = $moduleEventResult->getParameters();
204
205 if (
206 is_array($moduleEventParams)
207 && !empty($moduleEventParams['provider'])
208 )
209 {
210 $provider = $moduleEventParams['provider'];
211 }
212 break;
213 }
214 }
215
216 if (!$provider)
217 {
218 switch($entityType)
219 {
220 case self::DATA_ENTITY_TYPE_BLOG_POST:
221 $provider = new BlogPost();
222 break;
223 case self::DATA_ENTITY_TYPE_BLOG_COMMENT:
224 $provider = new BlogComment();
225 break;
226 case self::DATA_ENTITY_TYPE_TASKS_TASK:
227 $provider = new TasksTask();
228 break;
229 case self::DATA_ENTITY_TYPE_FORUM_TOPIC:
230 $provider = new ForumTopic();
231 break;
232 case self::DATA_ENTITY_TYPE_FORUM_POST:
233 $provider = new ForumPost();
234 break;
235 case self::DATA_ENTITY_TYPE_CALENDAR_EVENT:
236 $provider = new CalendarEvent();
237 break;
238 case self::DATA_ENTITY_TYPE_LOG_ENTRY:
239 $provider = new LogEvent();
240 break;
241 case self::DATA_ENTITY_TYPE_LOG_COMMENT:
242 $provider = new LogComment();
243 break;
244 case self::DATA_ENTITY_TYPE_RATING_LIST:
246 break;
247 case self::DATA_ENTITY_TYPE_PHOTOGALLERY_ALBUM:
249 break;
250 case self::DATA_ENTITY_TYPE_PHOTOGALLERY_PHOTO:
252 break;
253 case self::DATA_ENTITY_TYPE_LISTS_ITEM:
254 $provider = new ListsItem();
255 break;
256 case self::DATA_ENTITY_TYPE_WIKI:
257 $provider = new Wiki();
258 break;
259 case self::DATA_ENTITY_TYPE_TIMEMAN_ENTRY:
260 $provider = new TimemanEntry();
261 break;
262 case self::DATA_ENTITY_TYPE_TIMEMAN_REPORT:
263 $provider = new TimemanReport();
264 break;
265 case self::DATA_ENTITY_TYPE_INTRANET_NEW_USER:
267 break;
268 case self::DATA_ENTITY_TYPE_BITRIX24_NEW_USER:
270 break;
271 default:
272 $provider = false;
273 }
274 }
275
276 return $provider;
277 }
278
279 public static function init(array $params)
280 {
281 $provider = self::getProvider($params['ENTITY_TYPE']);
282
283 if ($provider)
284 {
285 $provider->setEntityId($params['ENTITY_ID']);
286 $provider->setSiteId($params['SITE_ID'] ?? SITE_ID);
287
288 if (
289 isset($params['CLONE_DISK_OBJECTS'])
290 && $params['CLONE_DISK_OBJECTS'] === true
291 )
292 {
293 $provider->cloneDiskObjects = true;
294 }
295
296 if (
297 isset($params['LOG_ID'])
298 && (int)$params['LOG_ID'] > 0
299 )
300 {
301 $provider->setLogId((int)$params['LOG_ID']);
302 }
303
304 if (isset($params['RATING_TYPE_ID']))
305 {
306 $provider->setRatingTypeId($params['RATING_TYPE_ID']);
307 }
308
309 if (isset($params['RATING_ENTITY_ID']))
310 {
311 $provider->setRatingEntityId($params['RATING_ENTITY_ID']);
312 }
313
314 if (
315 isset($params['ADDITIONAL_PARAMS'])
316 && is_array($params['ADDITIONAL_PARAMS'])
317 )
318 {
319 $provider->setAdditionalParams($params['ADDITIONAL_PARAMS']);
320 }
321 }
322
323 return $provider;
324 }
325
326 public static function canRead($params)
327 {
328 return false;
329 }
330
331 protected function getPermissions(array $entity)
332 {
333 return self::PERMISSION_DENY;
334 }
335
336 public function getLogId($params = [])
337 {
338 $result = false;
339
340 $cacheKey = $this->generateLogIdCacheKey($params);
341
342 if (isset(self::$logIdCache[$cacheKey]))
343 {
344 return self::$logIdCache[$cacheKey];
345 }
346
347 if ($this->logId > 0)
348 {
349 $result = $this->logId;
350 }
351 else
352 {
353 $eventId = $this->getEventId();
354
355 if (
356 empty($eventId)
357 || $this->entityId <= 0
358 )
359 {
360 return false;
361 }
362
363 if ($this->getType() === Provider::TYPE_POST)
364 {
365 $filter = [
366 'EVENT_ID' => $eventId
367 ];
368
369 if (static::getId() === LogEvent::PROVIDER_ID)
370 {
371 $filter['=ID'] = $this->entityId;
372 }
373 else
374 {
375 $filter['=SOURCE_ID'] = $this->entityId;
376 }
377
378 if (
379 is_array($params)
380 && isset($params['inactive'])
381 && $params['inactive']
382 )
383 {
384 $filter['=INACTIVE'] = 'Y';
385 }
386
387 $res = \CSocNetLog::getList(
388 [],
389 $filter,
390 false,
391 [ 'nTopCount' => 1 ],
392 [ 'ID' ]
393 );
394
395 $logEntry = $res->fetch();
396 if (
397 !$logEntry
398 && static::getId() === TasksTask::PROVIDER_ID
399 && Loader::includeModule('crm')
400 )
401 {
402 $res = \CCrmActivity::getList(
403 [],
404 [
405 'ASSOCIATED_ENTITY_ID' => $this->entityId,
406 'TYPE_ID' => \CCrmActivityType::Task,
407 'CHECK_PERMISSIONS' => 'N'
408 ],
409 false,
410 false,
411 [ 'ID' ]
412 );
413 if ($activityFields = $res->fetch())
414 {
415 $res = \CSocNetLog::getList(
416 [],
417 [
418 'EVENT_ID' => $eventId,
419 '=ENTITY_TYPE' => 'CRMACTIVITY',
420 '=ENTITY_ID' => $activityFields['ID'],
421 ],
422 false,
423 [ 'nTopCount' => 1 ],
424 [ 'ID' ]
425 );
426 $logEntry = $res->fetch();
427 }
428 }
429
430 if (
431 $logEntry
432 && ((int)$logEntry['ID'] > 0)
433 )
434 {
435 $result = $this->logId = (int)$logEntry['ID'];
436 }
437 }
439 {
440 $filter = [
441 'EVENT_ID' => $eventId
442 ];
443
444 if (static::getId() === LogComment::PROVIDER_ID)
445 {
446 $filter['ID'] = $this->entityId;
447 }
448 else
449 {
450 $filter['SOURCE_ID'] = $this->entityId;
451 }
452
453 $res = \CSocNetLogComments::getList(
454 [],
455 $filter,
456 false,
457 [ 'nTopCount' => 1 ],
458 [ 'ID', 'LOG_ID' ]
459 );
460
461 if (
462 ($logCommentEntry = $res->fetch())
463 && ((int)$logCommentEntry['LOG_ID'] > 0)
464 )
465 {
466 $result = $this->logId = (int)$logCommentEntry['LOG_ID'];
467 }
468 }
469 }
470
471 self::$logIdCache[$cacheKey] = $result;
472
473 return $result;
474 }
475
476 public function getLogCommentId()
477 {
478 $result = false;
479
480 $eventId = $this->getEventId();
481 if (
482 empty($eventId)
483 || $this->getType() !== self::TYPE_COMMENT
484 )
485 {
486 return $result;
487 }
488
489 $filter = [
490 'EVENT_ID' => $eventId
491 ];
492
493 if (static::getId() === LogComment::PROVIDER_ID)
494 {
495 $filter['ID'] = $this->entityId;
496 }
497 else
498 {
499 $filter['SOURCE_ID'] = $this->entityId;
500 }
501
502 $res = \CSocNetLogComments::getList(
503 [],
504 $filter,
505 false,
506 [ 'nTopCount' => 1 ],
507 [ 'ID', 'LOG_ID' ]
508 );
509
510 if ($logCommentEntry = $res->fetch())
511 {
512 $result = (int)$logCommentEntry['ID'];
513 if ((int)$logCommentEntry['LOG_ID'] > 0)
514 {
515 $this->logId = (int)$logCommentEntry['LOG_ID'];
516 }
517 }
518
519 return $result;
520 }
521
522 public function getSonetGroupsAvailable($feature = false, $operation = false): array
523 {
524 global $USER;
525
526 $result = [];
527
528 $logRights = $this->getLogRights();
529 if (
530 !empty($logRights)
531 && is_array($logRights)
532 )
533 {
534 foreach ($logRights as $groupCode)
535 {
536 if (preg_match('/^SG(\d+)/', $groupCode, $matches))
537 {
538 $result[] = (int)$matches[1];
539 }
540 }
541 }
542
543 if (
544 !empty($result)
545 && !!$feature
546 && !!$operation
547 )
548 {
549 $activity = \CSocNetFeatures::isActiveFeature(
551 $result,
552 $feature
553 );
554 $availability = \CSocNetFeaturesPerms::canPerformOperation(
555 $USER->getId(),
557 $result,
558 $feature,
559 $operation
560 );
561 foreach ($result as $key => $groupId)
562 {
563 if (
564 !isset($activity[$groupId])
565 || !$activity[$groupId]
566 || !isset($availability[$groupId])
567 || !$availability[$groupId]
568 )
569 {
570 unset($result[$key]);
571 }
572 }
573 }
574 $result = array_unique($result);
575
576 return $result;
577 }
578
579 public function getLogRights(): array
580 {
581 $result = [];
582 $logId = $this->getLogId();
583
584 if ($logId > 0)
585 {
586 $result = $this->getLogRightsEntry();
587 }
588
589 return $result;
590 }
591
592 protected function getLogRightsEntry(): array
593 {
594 $result = [];
595
596 if ($this->logId > 0)
597 {
598 $res = \CSocNetLogRights::getList(
599 [],
600 [
601 'LOG_ID' => $this->logId
602 ]
603 );
604
605 while ($right = $res->fetch())
606 {
607 $result[] = $right['GROUP_CODE'];
608 }
609 }
610
611 return $result;
612 }
613
614 public function setEntityId($entityId)
615 {
616 $this->entityId = $entityId;
617 }
618
619 final public function getEntityId()
620 {
621 return $this->entityId;
622 }
623
624 final public function setLogId($logId): void
625 {
626 $this->logId = $logId;
627 }
628
629 final public function setAdditionalParams(array $additionalParams): void
630 {
631 $this->additionalParams = $additionalParams;
632 }
633
634 final public function getAdditionalParams(): array
635 {
636 return $this->additionalParams;
637 }
638
639 final protected function setSourceFields(array $fields): void
640 {
641 $this->sourceFields = $fields;
642 }
643
644 public function initSourceFields()
645 {
646 return $this->sourceFields;
647 }
648
649 final public function getSourceFields(): array
650 {
651 return $this->sourceFields;
652 }
653
654 final protected function setSourceDescription($description): void
655 {
656 $this->sourceDescription = $description;
657 }
658
659 public function getSourceDescription()
660 {
661 if (empty($this->sourceFields))
662 {
663 $this->initSourceFields();
664 }
665
666 $result = $this->sourceDescription;
667
668 if ($this->cloneDiskObjects === true)
669 {
670 $this->getAttachedDiskObjects(true);
671 $result = $this->processDescription($result);
672 }
673
674 return $result;
675 }
676
677 final protected function setSourceTitle($title): void
678 {
679 $this->sourceTitle = $title;
680 }
681
682 public function getSourceTitle(): string
683 {
684 if (empty($this->sourceFields))
685 {
686 $this->initSourceFields();
687 }
688
689 return $this->sourceTitle;
690 }
691
692 public function getPinnedTitle()
693 {
694 if (empty($this->sourceFields))
695 {
696 $this->initSourceFields();
697 }
698
699 $result = $this->pinnedTitle;
700 if ($result === null)
701 {
702 $result = $this->getSourceTitle();
703 }
704
705 return $result;
706 }
707
708 public function getPinnedDescription()
709 {
710 if (empty($this->sourceFields))
711 {
712 $this->initSourceFields();
713 }
714
715 $result = $this->getSourceDescription();
716 $result = truncateText(\CTextParser::clearAllTags($result), 100);
717
718 return $result;
719 }
720
721 final protected function setSourceOriginalText($text): void
722 {
723 $this->sourceOriginalText = $text;
724 }
725
726 public function getSourceOriginalText(): string
727 {
728 if (empty($this->sourceFields))
729 {
730 $this->initSourceFields();
731 }
732
733 return $this->sourceOriginalText;
734 }
735
736 final protected function setSourceAuxData($auxData): void
737 {
738 $this->sourceAuxData = $auxData;
739 }
740
741 public function getSourceAuxData(): array
742 {
743 if (empty($this->sourceFields))
744 {
745 $this->initSourceFields();
746 }
747
748 return $this->sourceAuxData;
749 }
750
751 final protected function setSourceAttachedDiskObjects(array $diskAttachedObjects): void
752 {
753 $this->sourceAttachedDiskObjects = $diskAttachedObjects;
754 }
755
756 final protected function setSourceDiskObjects(array $files): void
757 {
758 $this->sourceDiskObjects = $files;
759 }
760
761 final public function setDiskObjectsCloned(array $values): void
762 {
763 $this->diskObjectsCloned = $values;
764 }
765
766 final public function getDiskObjectsCloned(): array
767 {
768 return $this->diskObjectsCloned;
769 }
770
771 final public function getAttachedDiskObjectsCloned(): array
772 {
773 return $this->attachedDiskObjectsCloned;
774 }
775
777 {
778 if (empty($this->sourceFields))
779 {
780 $this->initSourceFields();
781 }
782
783 return $this->sourceAttachedDiskObjects;
784 }
785
786 public function getSourceDiskObjects(): array
787 {
788 if (empty($this->sourceFields))
789 {
790 $this->initSourceFields();
791 }
792
793 return $this->sourceDiskObjects;
794 }
795
796 protected function getAttachedDiskObjects($clone = false)
797 {
798 return [];
799 }
800
801 final protected function setSourceDateTime(DateTime $datetime): void
802 {
803 $this->sourceDateTime = $datetime;
804 }
805
806 final public function getSourceDateTime(): ?DateTime
807 {
808 return $this->sourceDateTime;
809 }
810
811 final protected function setSourceAuthorId($authorId = 0): void
812 {
813 $this->sourceAuthorId = (int)$authorId;
814 }
815
816 final public function getSourceAuthorId(): int
817 {
818 return $this->sourceAuthorId;
819 }
820
821 protected static function cloneUfValues(array $values)
822 {
823 global $USER;
824
825 $result = [];
826 if (Loader::includeModule('disk'))
827 {
828 $result = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager()->cloneUfValuesFromAttachedObject($values, $USER->getId());
829 }
830
831 return $result;
832 }
833
834 public function getDiskObjects($entityId, $clone = false): array
835 {
836 $result = [];
837
838 if ($clone)
839 {
840 $result = $this->getAttachedDiskObjects(true);
841
842 if (
843 empty($this->diskObjectsCloned)
844 && Loader::includeModule('disk')
845 )
846 {
847 foreach ($result as $clonedDiskObjectId)
848 {
849 if (
850 in_array($clonedDiskObjectId, $this->attachedDiskObjectsCloned)
851 && ($attachedDiskObjectId = array_search($clonedDiskObjectId, $this->attachedDiskObjectsCloned))
852 )
853 {
854 $attachedObject = AttachedObject::loadById($attachedDiskObjectId);
855 if ($attachedObject)
856 {
857 $this->diskObjectsCloned[\Bitrix\Disk\Uf\FileUserType::NEW_FILE_PREFIX.$attachedObject->getObjectId()] = $this->attachedDiskObjectsCloned[$attachedDiskObjectId];
858 }
859 }
860 }
861 }
862
863 return $result;
864 }
865
866 $diskObjects = $this->getAttachedDiskObjects(false);
867
868 if (
869 !empty($diskObjects)
870 && Loader::includeModule('disk')
871 )
872 {
873 foreach ($diskObjects as $attachedObjectId)
874 {
875 $attachedObject = AttachedObject::loadById($attachedObjectId);
876 if ($attachedObject)
877 {
878 $result[] = \Bitrix\Disk\Uf\FileUserType::NEW_FILE_PREFIX . $attachedObject->getObjectId();
879 }
880 }
881 }
882
883 return $result;
884 }
885
886 private function processDescription($text)
887 {
888 $result = $text;
889
890 $diskObjectsCloned = $this->getDiskObjectsCloned();
891 $attachedDiskObjectsCloned = $this->getAttachedDiskObjectsCloned();
892
893 if (
894 !empty($diskObjectsCloned)
895 && is_array($diskObjectsCloned)
896 )
897 {
898 $result = preg_replace_callback(
899 "#\\[disk file id=(n\\d+)\\]#isu",
900 [ $this, 'parseDiskObjectsCloned' ],
901 $result
902 );
903 }
904
905 if (
906 !empty($attachedDiskObjectsCloned)
907 && is_array($attachedDiskObjectsCloned)
908 )
909 {
910 $result = preg_replace_callback(
911 "#\\[disk file id=(\\d+)\\]#isu",
912 [ $this, 'parseAttachedDiskObjectsCloned' ],
913 $result
914 );
915 }
916
917 return $result;
918 }
919
920 private function parseDiskObjectsCloned($matches)
921 {
922 $text = $matches[0];
923
924 $diskObjectsCloned = $this->getDiskObjectsCloned();
925
926 if (array_key_exists($matches[1], $diskObjectsCloned))
927 {
928 $text = str_replace($matches[1], $diskObjectsCloned[$matches[1]], $text);
929 }
930
931 return $text;
932 }
933
934 private function parseAttachedDiskObjectsCloned($matches)
935 {
936 $text = $matches[0];
937
939
940 if (array_key_exists($matches[1], $attachedDiskObjectsCloned))
941 {
943 }
944
945 return $text;
946 }
947
948 public function getLiveFeedUrl()
949 {
950 return '';
951 }
952
953 final public function getContentTypeId(): string
954 {
955 return static::CONTENT_TYPE_ID;
956 }
957
958 public static function getContentId($event = [])
959 {
960 $result = false;
961
962 if (!is_array($event))
963 {
964 return $result;
965 }
966
967 $contentEntityType = false;
968 $contentEntityId = false;
969
970 $moduleEvent = new Main\Event(
971 'socialnetwork',
972 'onLogProviderGetContentId',
973 [
974 'eventFields' => $event,
975 ]
976 );
977 $moduleEvent->send();
978
979 foreach ($moduleEvent->getResults() as $moduleEventResult)
980 {
981 if ($moduleEventResult->getType() === EventResult::SUCCESS)
982 {
983 $moduleEventParams = $moduleEventResult->getParameters();
984
985 if (
986 is_array($moduleEventParams)
987 && !empty($moduleEventParams['contentEntityType'])
988 && !empty($moduleEventParams['contentEntityId'])
989 )
990 {
991 $contentEntityType = $moduleEventParams['contentEntityType'];
992 $contentEntityId = $moduleEventParams['contentEntityId'];
993 }
994 break;
995 }
996 }
997
998 if (
999 $contentEntityType
1000 && $contentEntityId > 0
1001 )
1002 {
1003 return [
1004 'ENTITY_TYPE' => $contentEntityType,
1005 'ENTITY_ID' => $contentEntityId
1006 ];
1007 }
1008
1009 // getContent
1010
1011 if (
1012 !empty($event['EVENT_ID'])
1013 && $event['EVENT_ID'] === 'photo'
1014 )
1015 {
1016 $contentEntityType = self::DATA_ENTITY_TYPE_PHOTOGALLERY_ALBUM;
1017 $contentEntityId = (int)$event['SOURCE_ID'];
1018 }
1019 elseif (
1020 !empty($event['EVENT_ID'])
1021 && $event['EVENT_ID'] === 'photo_photo'
1022 )
1023 {
1024 $contentEntityType = self::DATA_ENTITY_TYPE_PHOTOGALLERY_PHOTO;
1025 $contentEntityId = (int)$event['SOURCE_ID'];
1026 }
1027 elseif (
1028 !empty($event['EVENT_ID'])
1029 && $event['EVENT_ID'] === 'data'
1030 )
1031 {
1032 $contentEntityType = self::DATA_ENTITY_TYPE_LOG_ENTRY;
1033 $contentEntityId = (int)$event['ID'];
1034 }
1035 elseif (
1036 !empty($event['RATING_TYPE_ID'])
1037 && !empty($event['RATING_ENTITY_ID'])
1038 && (int)$event['RATING_ENTITY_ID'] > 0
1039 )
1040 {
1041 $contentEntityType = $event['RATING_TYPE_ID'];
1042 $contentEntityId = (int)$event['RATING_ENTITY_ID'];
1043
1044 if (in_array($event['RATING_TYPE_ID'], [ 'IBLOCK_ELEMENT', 'IBLOCK_SECTION' ]))
1045 {
1046 $res = self::$logTable::getList([
1047 'filter' => [
1048 '=RATING_TYPE_ID' => $event['RATING_TYPE_ID'],
1049 '=RATING_ENTITY_ID' => $event['RATING_ENTITY_ID'],
1050 ],
1051 'select' => [ 'EVENT_ID' ]
1052 ]);
1053 if ($logEntryFields = $res->fetch())
1054 {
1055 if ($event['RATING_TYPE_ID'] === 'IBLOCK_ELEMENT')
1056 {
1057 $found = false;
1058 $photogalleryPhotoProvider = new \Bitrix\Socialnetwork\Livefeed\PhotogalleryPhoto;
1059 if (in_array($logEntryFields['EVENT_ID'], $photogalleryPhotoProvider->getEventId(), true))
1060 {
1061 $contentEntityType = self::DATA_ENTITY_TYPE_PHOTOGALLERY_PHOTO;
1062 $contentEntityId = (int)$event['RATING_ENTITY_ID'];
1063 $found = true;
1064 }
1065
1066 if (!$found)
1067 {
1068 $wikiProvider = new \Bitrix\Socialnetwork\Livefeed\Wiki;
1069 if (in_array($logEntryFields['EVENT_ID'], $wikiProvider->getEventId()))
1070 {
1071 $contentEntityType = self::DATA_ENTITY_TYPE_WIKI;
1072 $contentEntityId = (int)$event['RATING_ENTITY_ID'];
1073 $found = true;
1074 }
1075 }
1076 }
1077 elseif ($event['RATING_TYPE_ID'] === 'IBLOCK_SECTION')
1078 {
1079 $photogalleryalbumProvider = new \Bitrix\Socialnetwork\Livefeed\PhotogalleryAlbum;
1080 if (in_array($logEntryFields['EVENT_ID'], $photogalleryalbumProvider->getEventId(), true))
1081 {
1082 $contentEntityType = self::DATA_ENTITY_TYPE_PHOTOGALLERY_ALBUM;
1083 $contentEntityId = (int)$event['RATING_ENTITY_ID'];
1084 }
1085 }
1086 }
1087 }
1088 elseif (preg_match('/^wiki_[\d]+_page$/i', $event['RATING_TYPE_ID'], $matches))
1089 {
1090 $contentEntityType = self::DATA_ENTITY_TYPE_WIKI;
1091 $contentEntityId = (int)$event['SOURCE_ID'];
1092 $found = true;
1093 }
1094 }
1095 elseif (
1096 !empty($event['EVENT_ID'])
1097 && !empty($event['SOURCE_ID'])
1098 && (int)$event['SOURCE_ID'] > 0
1099 )
1100 {
1101 switch ($event['EVENT_ID'])
1102 {
1103 case 'tasks':
1104 $contentEntityType = self::DATA_ENTITY_TYPE_TASKS_TASK;
1105 $contentEntityId = (int)$event['SOURCE_ID'];
1106 break;
1107 case 'calendar':
1108 $contentEntityType = self::DATA_ENTITY_TYPE_CALENDAR_EVENT;
1109 $contentEntityId = (int)$event['SOURCE_ID'];
1110 break;
1111 case 'timeman_entry':
1112 $contentEntityType = self::DATA_ENTITY_TYPE_TIMEMAN_ENTRY;
1113 $contentEntityId = (int)$event['SOURCE_ID'];
1114 break;
1115 case 'report':
1116 $contentEntityType = self::DATA_ENTITY_TYPE_TIMEMAN_REPORT;
1117 $contentEntityId = (int)$event['SOURCE_ID'];
1118 break;
1119 case 'lists_new_element':
1120 $contentEntityType = self::DATA_ENTITY_TYPE_LISTS_ITEM;
1121 $contentEntityId = (int)$event['SOURCE_ID'];
1122 break;
1123 default:
1124 }
1125 }
1126
1127 if (
1128 $contentEntityType
1129 && $contentEntityId > 0
1130 )
1131 {
1132 $result = [
1133 'ENTITY_TYPE' => $contentEntityType,
1134 'ENTITY_ID' => $contentEntityId
1135 ];
1136 }
1137
1138 return $result;
1139 }
1140
1141 public function setContentView($params = [])
1142 {
1143 global $USER;
1144
1145 if (!is_array($params))
1146 {
1147 $params = [];
1148 }
1149
1150 if (
1151 !isset($params['user_id'])
1152 && is_object($USER)
1153 && \CSocNetUser::isCurrentUserModuleAdmin()
1154 ) // don't track users on God Mode
1155 {
1156 return false;
1157 }
1158
1159 $userId = (
1160 isset($params['user_id'])
1161 && (int)$params['user_id'] > 0
1162 ? (int)$params['user_id']
1163 : 0
1164 );
1165 if ($userId <= 0 && is_object($USER))
1166 {
1167 $userId = $USER->getId();
1168 }
1169
1170 $contentTypeId = $this->getContentTypeId();
1171 $contentEntityId = $this->getEntityId();
1172 $logId = $this->getLogId();
1173 $save = (!isset($params['save']) || (bool)$params['save']);
1174
1175 if (
1176 (int)$userId <= 0
1177 || !$contentTypeId
1178 || !$contentEntityId
1179 )
1180 {
1181 return false;
1182 }
1183
1184 $viewParams = [
1185 'userId' => $userId,
1186 'typeId' => $contentTypeId,
1187 'entityId' => $contentEntityId,
1188 'logId' => $logId,
1189 'save' => $save
1190 ];
1191
1192 $pool = Application::getInstance()->getConnectionPool();
1193 $pool->useMasterOnly(true);
1194
1195 $result = UserContentViewTable::set($viewParams);
1196
1197 // we need to update the last DATE_VIEW for the parent post if it is a comment
1198 if ($this->isComment($this->getContentTypeId()))
1199 {
1200 $logItem = Log::getById($logId);
1201 if ($logItem)
1202 {
1203 $fields = $logItem->getFields();
1204 $contentTypeId = $fields['RATING_TYPE_ID'] ?? null;
1205 $contentEntityId = $fields['RATING_ENTITY_ID'] ?? null;
1206 if ($contentTypeId && $contentEntityId)
1207 {
1209 'userId' => $userId,
1210 'typeId' => $contentTypeId,
1211 'entityId' => $contentEntityId,
1212 'logId' => $logId,
1213 'save' => true
1214 ]);
1215 }
1216 }
1217 }
1218
1219 $pool->useMasterOnly(false);
1220
1221 if (
1222 $result
1223 && isset($result['success'])
1224 && $result['success']
1225 )
1226 {
1227 /*
1228 TODO: markAsRead sonet module notifications
1229 ContentViewHandler::onContentViewed($viewParams);
1230 */
1231 if (UserContentView::getAvailability())
1232 {
1233 if (
1234 isset($result['savedInDB'])
1235 && $result['savedInDB']
1236 )
1237 {
1238 if (Loader::includeModule('pull') && !$this->isComment($this->getContentTypeId()))
1239 {
1240 $contentId = $viewParams['typeId'] . '-' . $viewParams['entityId'];
1242 'contentId' => [$contentId]
1243 ]);
1244
1245 \CPullWatch::addToStack('CONTENTVIEW' . $viewParams['typeId'] . '-' . $viewParams['entityId'],
1246 [
1247 'module_id' => 'contentview',
1248 'command' => 'add',
1249 'expiry' => 0,
1250 'params' => [
1251 'USER_ID' => $userId,
1252 'TYPE_ID' => $viewParams['typeId'],
1253 'ENTITY_ID' => $viewParams['entityId'],
1254 'CONTENT_ID' => $contentId,
1255 'TOTAL_VIEWS' => (int)($views[$contentId]['CNT'] ?? 0),
1256 ]
1257 ]
1258 );
1259 }
1260 }
1261
1262 if ($logId > 0)
1263 {
1264 Subscription::onContentViewed([
1265 'userId' => $userId,
1266 'logId' => $logId
1267 ]);
1268
1270 \Bitrix\Socialnetwork\Internals\EventService\EventDictionary::EVENT_SPACE_LIVEFEED_POST_VIEW,
1271 [
1272 'SONET_LOG_ID' => (int)$logId,
1273 'USER_ID' => (int)$userId,
1274 'ENTITY_TYPE_ID' => $contentTypeId,
1275 'ENTITY_ID' => $contentEntityId,
1276 ]
1277 );
1278 }
1279
1280 $event = new Main\Event(
1281 'socialnetwork', 'onContentViewed',
1282 $viewParams
1283 );
1284 $event->send();
1285 }
1286 }
1287
1288 return $result;
1289 }
1290
1291 final public static function getEntityData(array $params)
1292 {
1293 $entityType = false;
1294 $entityId = false;
1295
1296 $type = (
1297 isset($params['TYPE'])
1298 && in_array($params['TYPE'], self::getTypes())
1299 ? $params['TYPE']
1300 : self::TYPE_POST
1301 );
1302
1303 if (!empty($params['EVENT_ID']))
1304 {
1305 $blogPostLivefeedProvider = new BlogPost;
1306 if (
1307 $type === self::TYPE_POST
1308 && in_array($params['EVENT_ID'], $blogPostLivefeedProvider->getEventId(), true)
1309 )
1310 {
1311 $entityType = self::DATA_ENTITY_TYPE_BLOG_POST;
1312 $entityId = (isset($params['SOURCE_ID']) ? (int)$params['SOURCE_ID'] : false);
1313 }
1314 }
1315
1316 return (
1317 $entityType
1318 && $entityId
1319 ? [
1320 'ENTITY_TYPE' => $entityType,
1321 'ENTITY_ID' => $entityId
1322 ]
1323 : false
1324 );
1325 }
1326
1327 public function getSuffix()
1328 {
1329 return '';
1330 }
1331
1332 public function add()
1333 {
1334 return false;
1335 }
1336
1337 final public function setLogEventId($eventId = ''): bool
1338 {
1339 if ($eventId == '')
1340 {
1341 return false;
1342 }
1343
1344 $this->logEventId = $eventId;
1345
1346 return true;
1347 }
1348
1349 private function setLogEntityType($entityType = ''): bool
1350 {
1351 if ($entityType == '')
1352 {
1353 return false;
1354 }
1355
1356 $this->logEntityType = $entityType;
1357
1358 return true;
1359 }
1360
1361 private function setLogEntityId($entityId = 0): bool
1362 {
1363 if ((int)$entityId <= 0)
1364 {
1365 return false;
1366 }
1367
1368 $this->logEntityId = $entityId;
1369
1370 return true;
1371 }
1372
1373 final protected function getLogFields(): array
1374 {
1375 $return = [];
1376
1377 $logId = $this->getLogId();
1378 if ((int)$logId <= 0)
1379 {
1380 return $return;
1381 }
1382
1383 $res = self::$logTable::getList([
1384 'filter' => [
1385 'ID' => $logId,
1386 ],
1387 'select' => [ 'EVENT_ID', 'ENTITY_TYPE', 'ENTITY_ID' ]
1388 ]);
1389 if ($logFields = $res->fetch())
1390 {
1391 $return = $logFields;
1392
1393 $this->setLogEventId($logFields['EVENT_ID']);
1394 $this->setLogEntityType($logFields['ENTITY_TYPE']);
1395 $this->setLogEntityId($logFields['ENTITY_ID']);
1396 }
1397
1398 return $return;
1399 }
1400
1401 protected function getLogEventId()
1402 {
1403 $result = false;
1404
1405 if ($this->logEventId !== null)
1406 {
1407 $result = $this->logEventId;
1408 }
1409 else
1410 {
1411 $logFields = $this->getLogFields();
1412 if (!empty($logFields['EVENT_ID']))
1413 {
1414 $result = $logFields['EVENT_ID'];
1415 }
1416 }
1417
1418 return $result;
1419 }
1420
1421 protected function getLogEntityType()
1422 {
1423 $result = false;
1424
1425 if ($this->logEntityType !== null)
1426 {
1427 $result = $this->logEntityType;
1428 }
1429 else
1430 {
1431 $logFields = $this->getLogFields();
1432 if (!empty($logFields['ENTITY_TYPE']))
1433 {
1434 $result = $logFields['ENTITY_TYPE'];
1435 }
1436 }
1437
1438 return $result;
1439 }
1440
1441 protected function getLogEntityId()
1442 {
1443 $result = false;
1444
1445 if ($this->logEntityId !== null)
1446 {
1447 $result = $this->logEntityId;
1448 }
1449 else
1450 {
1451 $logFields = $this->getLogFields();
1452 if (!empty($logFields['ENTITY_ID']))
1453 {
1454 $result = $logFields['ENTITY_ID'];
1455 }
1456 }
1457
1458 return $result;
1459 }
1460
1461 public function getAdditionalData($params = [])
1462 {
1463 return [];
1464 }
1465
1466 protected function checkAdditionalDataParams(&$params): bool
1467 {
1468 if (
1469 empty($params)
1470 || !is_array($params)
1471 || empty($params['id'])
1472 )
1473 {
1474 return false;
1475 }
1476
1477 if (!is_array($params['id']))
1478 {
1479 $params['id'] = [ $params['id'] ];
1480 }
1481
1482 return true;
1483 }
1484
1485 public function warmUpAuxCommentsStaticCache(array $params = []): void
1486 {
1487
1488 }
1489
1490 protected function getUnavailableTitle()
1491 {
1492 return Loc::getMessage('SONET_LIVEFEED_BASE_TITLE_UNAVAILABLE');
1493 }
1494
1496 {
1497 global $USER_FIELD_MANAGER;
1498
1499 $result = [];
1500
1501 $userFieldEntity = (string)($params['userFieldEntity'] ?? '');
1502 $userFieldEntityId = $this->entityId;
1503 $userFieldCode = (string)($params['userFieldCode'] ?? '');
1504 $clone = (boolean)($params['clone'] ?? false);
1505
1506 if (
1507 $userFieldEntity === ''
1508 || $userFieldCode === ''
1509 || $userFieldEntityId <= 0
1510 )
1511 {
1512 return $result;
1513 }
1514
1515 static $cache = [];
1516
1517 $cacheKey = $userFieldEntity . $userFieldEntityId . $clone;
1518
1519 if (isset($cache[$cacheKey]))
1520 {
1521 $result = $cache[$cacheKey];
1522 }
1523 else
1524 {
1525 $entityUF = $USER_FIELD_MANAGER->getUserFields($userFieldEntity, $userFieldEntityId, LANGUAGE_ID);
1526 if (
1527 !empty($entityUF[$userFieldCode])
1528 && !empty($entityUF[$userFieldCode]['VALUE'])
1529 && is_array($entityUF[$userFieldCode]['VALUE'])
1530 )
1531 {
1532 if ($clone)
1533 {
1534 $this->attachedDiskObjectsCloned = self::cloneUfValues($entityUF[$userFieldCode]['VALUE']);
1535 $result = $cache[$cacheKey] = array_values($this->attachedDiskObjectsCloned);
1536 }
1537 else
1538 {
1539 $result = $cache[$cacheKey] = $entityUF[$userFieldCode]['VALUE'];
1540 }
1541 }
1542 }
1543
1544 if (!is_array($result))
1545 {
1546 $result = [];
1547 }
1548
1549 return $result;
1550 }
1551
1552 public function getParentEntityId(): int
1553 {
1554 return 0;
1555 }
1556
1557 private function isComment(string $contentTypeId): bool
1558 {
1559 return $contentTypeId === LogComment::CONTENT_TYPE_ID
1560 || $contentTypeId === BlogComment::CONTENT_TYPE_ID
1561 || $contentTypeId === ForumPost::CONTENT_TYPE_ID;
1562 }
1563
1564 private function generateLogIdCacheKey(array $params): string
1565 {
1566 return md5(serialize($params));
1567 }
1568}
$type
Определения options.php:106
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getInstance()
Определения application.php:98
Определения event.php:5
static includeModule($moduleName)
Определения loader.php:67
static addEvent(string $type, array $data)
Определения service.php:45
static getViewData($params=[])
Определения usercontentview.php:53
Определения blogpost.php:13
Определения forumpost.php:22
const CONTENT_TYPE_ID
Определения forumpost.php:24
const DATA_ENTITY_TYPE_PHOTOGALLERY_ALBUM
Определения provider.php:37
setParentProvider($value)
Определения provider.php:168
setDiskObjectsCloned(array $values)
Определения provider.php:761
const DATA_ENTITY_TYPE_PHOTOGALLERY_PHOTO
Определения provider.php:38
setSourceFields(array $fields)
Определения provider.php:639
const DATA_ENTITY_TYPE_LOG_ENTRY
Определения provider.php:34
getOption(string $key)
Определения provider.php:118
getPermissions(array $entity)
Определения provider.php:331
setSourceAuxData($auxData)
Определения provider.php:736
const DATA_ENTITY_TYPE_TIMEMAN_ENTRY
Определения provider.php:41
const DATA_ENTITY_TYPE_LISTS_ITEM
Определения provider.php:39
getAdditionalData($params=[])
Определения provider.php:1461
const DATA_ENTITY_TYPE_BLOG_POST
Определения provider.php:28
const DATA_ENTITY_TYPE_RATING_LIST
Определения provider.php:36
setOption(string $key, $value)
Определения provider.php:108
checkAdditionalDataParams(&$params)
Определения provider.php:1466
const DATA_ENTITY_TYPE_TIMEMAN_REPORT
Определения provider.php:42
setRatingTypeId(string $value)
Определения provider.php:143
getAttachedDiskObjects($clone=false)
Определения provider.php:796
setEntityId($entityId)
Определения provider.php:614
const DATA_ENTITY_TYPE_LIVE_FEED_VIEW
Определения provider.php:45
setContentView($params=[])
Определения provider.php:1141
warmUpAuxCommentsStaticCache(array $params=[])
Определения provider.php:1485
const DATA_ENTITY_TYPE_FORUM_POST
Определения provider.php:32
static cloneUfValues(array $values)
Определения provider.php:821
static getProvider($entityType)
Определения provider.php:186
setSourceDateTime(DateTime $datetime)
Определения provider.php:801
const DATA_ENTITY_TYPE_CALENDAR_EVENT
Определения provider.php:33
static init(array $params)
Определения provider.php:279
setSourceDiskObjects(array $files)
Определения provider.php:756
const DATA_RESULT_TYPE_SOURCE
Определения provider.php:23
setAdditionalParams(array $additionalParams)
Определения provider.php:629
static canRead($params)
Определения provider.php:326
setSourceAttachedDiskObjects(array $diskAttachedObjects)
Определения provider.php:751
getEntityAttachedDiskObjects(array $params=[])
Определения provider.php:1495
const DATA_ENTITY_TYPE_INTRANET_NEW_USER
Определения provider.php:43
setRatingEntityId(int $value)
Определения provider.php:153
const DATA_ENTITY_TYPE_BLOG_COMMENT
Определения provider.php:29
static getContentId($event=[])
Определения provider.php:958
static getEntityData(array $params)
Определения provider.php:1291
setSourceAuthorId($authorId=0)
Определения provider.php:811
setSourceOriginalText($text)
Определения provider.php:721
setLogEventId($eventId='')
Определения provider.php:1337
const DATA_ENTITY_TYPE_BITRIX24_NEW_USER
Определения provider.php:44
const DATA_ENTITY_TYPE_FORUM_TOPIC
Определения provider.php:31
setSourceDescription($description)
Определения provider.php:654
const DATA_ENTITY_TYPE_WIKI
Определения provider.php:40
const DATA_ENTITY_TYPE_TASKS_TASK
Определения provider.php:30
const DATA_ENTITY_TYPE_LOG_COMMENT
Определения provider.php:35
getLogId($params=[])
Определения provider.php:336
int null $ratingEntityId
Определения provider.php:60
getSonetGroupsAvailable($feature=false, $operation=false)
Определения provider.php:522
getDiskObjects($entityId, $clone=false)
Определения provider.php:834
Определения timemanentry.php:13
static set($params=[])
Определения usercontentview.php:92
static clearAllTags($text)
Определения textparser.php:2358
$right
Определения options.php:8
</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
global $USER_FIELD_MANAGER
Определения attempt.php:6
$result
Определения get_property_values.php:14
$entity
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$activity
Определения options.php:214
$save
Определения iblock_catalog_edit.php:365
$filter
Определения iblock_catalog_list.php:54
global $USER
Определения csv_new_run.php:40
$siteId
Определения ajax.php:8
$files
Определения mysql_to_pgsql.php:30
$entityId
Определения payment.php:4
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$text
Определения template_pdf.php:79
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$title
Определения pdf.php:123
$matches
Определения index.php:22
const SONET_ENTITY_GROUP
Определения include.php:117
$contentId
Определения sonet_set_content_view.php:27
const SITE_ID
Определения sonet_set_content_view.php:12
$fields
Определения yandex_run.php:501