5use Bitrix\Disk\AttachedObject;
12use Bitrix\Socialnetwork\Internals\LiveFeed\Counter\CounterService;
107 $this->options[$key] = $value;
117 return ($this->options[$key] ??
null);
142 $this->ratingTypeId = $value;
152 $this->ratingEntityId = $value;
167 $this->parentProvider = $value;
175 private static function getTypes(): array
189 'onLogProviderGetProvider',
191 'entityType' => $entityType
194 $moduleEvent->send();
196 foreach ($moduleEvent->getResults() as $moduleEventResult)
198 if ($moduleEventResult->getType() === EventResult::SUCCESS)
200 $moduleEventParams = $moduleEventResult->getParameters();
203 is_array($moduleEventParams)
204 && !empty($moduleEventParams[
'provider'])
207 $provider = $moduleEventParams[
'provider'];
254 $provider =
new Wiki();
276 public static function init(array $params)
282 $provider->setEntityId($params[
'ENTITY_ID']);
283 $provider->setSiteId($params[
'SITE_ID'] ?? SITE_ID);
286 isset($params[
'CLONE_DISK_OBJECTS'])
287 && $params[
'CLONE_DISK_OBJECTS'] ===
true
290 $provider->cloneDiskObjects =
true;
294 isset($params[
'LOG_ID'])
295 && (
int)$params[
'LOG_ID'] > 0
298 $provider->setLogId((
int)$params[
'LOG_ID']);
301 if (isset($params[
'RATING_TYPE_ID']))
303 $provider->setRatingTypeId($params[
'RATING_TYPE_ID']);
306 if (isset($params[
'RATING_ENTITY_ID']))
308 $provider->setRatingEntityId($params[
'RATING_ENTITY_ID']);
312 isset($params[
'ADDITIONAL_PARAMS'])
313 && is_array($params[
'ADDITIONAL_PARAMS'])
316 $provider->setAdditionalParams($params[
'ADDITIONAL_PARAMS']);
337 if ($this->logId > 0)
347 || $this->entityId <= 0
356 'EVENT_ID' => $eventId
370 && isset($params[
'inactive'])
371 && $params[
'inactive']
374 $filter[
'=INACTIVE'] =
'Y';
377 $res = \CSocNetLog::getList(
381 [
'nTopCount' => 1 ],
385 $logEntry = $res->fetch();
389 && Loader::includeModule(
'crm')
392 $res = \CCrmActivity::getList(
395 'ASSOCIATED_ENTITY_ID' => $this->entityId,
396 'TYPE_ID' => \CCrmActivityType::Task,
397 'CHECK_PERMISSIONS' =>
'N'
403 if ($activityFields = $res->fetch())
405 $res = \CSocNetLog::getList(
408 'EVENT_ID' => $eventId,
409 '=ENTITY_TYPE' =>
'CRMACTIVITY',
410 '=ENTITY_ID' => $activityFields[
'ID'],
413 [
'nTopCount' => 1 ],
416 $logEntry = $res->fetch();
422 && ((
int)$logEntry[
'ID'] > 0)
425 $result = $this->logId = (int)$logEntry[
'ID'];
431 'EVENT_ID' => $eventId
443 $res = \CSocNetLogComments::getList(
447 [
'nTopCount' => 1 ],
452 ($logCommentEntry = $res->fetch())
453 && ((
int)$logCommentEntry[
'LOG_ID'] > 0)
456 $result = $this->logId = (int)$logCommentEntry[
'LOG_ID'];
471 || $this->
getType() !== self::TYPE_COMMENT
478 'EVENT_ID' => $eventId
490 $res = \CSocNetLogComments::getList(
494 [
'nTopCount' => 1 ],
498 if ($logCommentEntry = $res->fetch())
500 $result = (int)$logCommentEntry[
'ID'];
501 if ((
int)$logCommentEntry[
'LOG_ID'] > 0)
503 $this->logId = (int)$logCommentEntry[
'LOG_ID'];
519 && is_array($logRights)
522 foreach ($logRights as $groupCode)
524 if (preg_match(
'/^SG(\d+)/', $groupCode, $matches))
526 $result[] = (int)$matches[1];
537 $activity = \CSocNetFeatures::isActiveFeature(
542 $availability = \CSocNetFeaturesPerms::canPerformOperation(
549 foreach ($result as $key => $groupId)
552 !isset($activity[$groupId])
553 || !$activity[$groupId]
554 || !isset($availability[$groupId])
555 || !$availability[$groupId]
558 unset($result[$key]);
562 $result = array_unique($result);
584 if ($this->logId > 0)
586 $res = \CSocNetLogRights::getList(
589 'LOG_ID' => $this->logId
593 while ($right = $res->fetch())
595 $result[] = $right[
'GROUP_CODE'];
629 $this->sourceFields = $fields;
644 $this->sourceDescription = $description;
649 if (empty($this->sourceFields))
656 if ($this->cloneDiskObjects ===
true)
659 $result = $this->processDescription($result);
667 $this->sourceTitle = $title;
672 if (empty($this->sourceFields))
682 if (empty($this->sourceFields))
688 if ($result ===
null)
698 if (empty($this->sourceFields))
704 $result = truncateText(\CTextParser::clearAllTags($result), 100);
711 $this->sourceOriginalText = $text;
716 if (empty($this->sourceFields))
726 $this->sourceAuxData = $auxData;
731 if (empty($this->sourceFields))
741 $this->sourceAttachedDiskObjects = $diskAttachedObjects;
746 $this->sourceDiskObjects = $files;
751 $this->diskObjectsCloned = $values;
766 if (empty($this->sourceFields))
776 if (empty($this->sourceFields))
791 $this->sourceDateTime = $datetime;
801 $this->sourceAuthorId = (int)$authorId;
814 if (Loader::includeModule(
'disk'))
816 $result = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager()->cloneUfValuesFromAttachedObject($values, $USER->getId());
831 empty($this->diskObjectsCloned)
832 && Loader::includeModule(
'disk')
835 foreach ($result as $clonedDiskObjectId)
838 in_array($clonedDiskObjectId, $this->attachedDiskObjectsCloned)
839 && ($attachedDiskObjectId = array_search($clonedDiskObjectId, $this->attachedDiskObjectsCloned))
842 $attachedObject = AttachedObject::loadById($attachedDiskObjectId);
845 $this->diskObjectsCloned[\Bitrix\Disk\Uf\FileUserType::NEW_FILE_PREFIX.$attachedObject->getObjectId()] = $this->attachedDiskObjectsCloned[$attachedDiskObjectId];
858 && Loader::includeModule(
'disk')
861 foreach ($diskObjects as $attachedObjectId)
863 $attachedObject = AttachedObject::loadById($attachedObjectId);
866 $result[] = \Bitrix\Disk\Uf\FileUserType::NEW_FILE_PREFIX . $attachedObject->getObjectId();
874 private function processDescription($text)
886 $result = preg_replace_callback(
887 "#\\[disk file id=(n\\d+)\\]#is" . BX_UTF_PCRE_MODIFIER,
888 [ $this,
'parseDiskObjectsCloned' ],
898 $result = preg_replace_callback(
899 "#\\[disk file id=(\\d+)\\]#is" . BX_UTF_PCRE_MODIFIER,
900 [ $this,
'parseAttachedDiskObjectsCloned' ],
908 private function parseDiskObjectsCloned($matches)
922 private function parseAttachedDiskObjectsCloned($matches)
943 return static::CONTENT_TYPE_ID;
950 if (!is_array($event))
955 $contentEntityType =
false;
956 $contentEntityId =
false;
960 'onLogProviderGetContentId',
962 'eventFields' => $event,
965 $moduleEvent->send();
967 foreach ($moduleEvent->getResults() as $moduleEventResult)
969 if ($moduleEventResult->getType() === EventResult::SUCCESS)
971 $moduleEventParams = $moduleEventResult->getParameters();
974 is_array($moduleEventParams)
975 && !empty($moduleEventParams[
'contentEntityType'])
976 && !empty($moduleEventParams[
'contentEntityId'])
979 $contentEntityType = $moduleEventParams[
'contentEntityType'];
980 $contentEntityId = $moduleEventParams[
'contentEntityId'];
988 && $contentEntityId > 0
992 'ENTITY_TYPE' => $contentEntityType,
993 'ENTITY_ID' => $contentEntityId
1000 !empty($event[
'EVENT_ID'])
1001 && $event[
'EVENT_ID'] ===
'photo'
1005 $contentEntityId = (int)$event[
'SOURCE_ID'];
1008 !empty($event[
'EVENT_ID'])
1009 && $event[
'EVENT_ID'] ===
'photo_photo'
1013 $contentEntityId = (int)$event[
'SOURCE_ID'];
1016 !empty($event[
'EVENT_ID'])
1017 && $event[
'EVENT_ID'] ===
'data'
1021 $contentEntityId = (int)$event[
'ID'];
1024 !empty($event[
'RATING_TYPE_ID'])
1025 && !empty($event[
'RATING_ENTITY_ID'])
1026 && (
int)$event[
'RATING_ENTITY_ID'] > 0
1029 $contentEntityType = $event[
'RATING_TYPE_ID'];
1030 $contentEntityId = (int)$event[
'RATING_ENTITY_ID'];
1032 if (in_array($event[
'RATING_TYPE_ID'], [
'IBLOCK_ELEMENT',
'IBLOCK_SECTION' ]))
1034 $res = self::$logTable::getList([
1036 '=RATING_TYPE_ID' => $event[
'RATING_TYPE_ID'],
1037 '=RATING_ENTITY_ID' => $event[
'RATING_ENTITY_ID'],
1039 'select' => [
'EVENT_ID' ]
1041 if ($logEntryFields = $res->fetch())
1043 if ($event[
'RATING_TYPE_ID'] ===
'IBLOCK_ELEMENT')
1046 $photogalleryPhotoProvider = new \Bitrix\Socialnetwork\Livefeed\PhotogalleryPhoto;
1047 if (in_array($logEntryFields[
'EVENT_ID'], $photogalleryPhotoProvider->getEventId(),
true))
1050 $contentEntityId = (int)$event[
'RATING_ENTITY_ID'];
1056 $wikiProvider = new \Bitrix\Socialnetwork\Livefeed\Wiki;
1057 if (in_array($logEntryFields[
'EVENT_ID'], $wikiProvider->getEventId()))
1060 $contentEntityId = (int)$event[
'RATING_ENTITY_ID'];
1065 elseif ($event[
'RATING_TYPE_ID'] ===
'IBLOCK_SECTION')
1067 $photogalleryalbumProvider = new \Bitrix\Socialnetwork\Livefeed\PhotogalleryAlbum;
1068 if (in_array($logEntryFields[
'EVENT_ID'], $photogalleryalbumProvider->getEventId(),
true))
1071 $contentEntityId = (int)$event[
'RATING_ENTITY_ID'];
1076 elseif (preg_match(
'/^wiki_[\d]+_page$/i', $event[
'RATING_TYPE_ID'], $matches))
1079 $contentEntityId = (int)$event[
'SOURCE_ID'];
1084 !empty($event[
'EVENT_ID'])
1085 && !empty($event[
'SOURCE_ID'])
1086 && (
int)$event[
'SOURCE_ID'] > 0
1089 switch ($event[
'EVENT_ID'])
1093 $contentEntityId = (int)$event[
'SOURCE_ID'];
1097 $contentEntityId = (int)$event[
'SOURCE_ID'];
1099 case 'timeman_entry':
1101 $contentEntityId = (int)$event[
'SOURCE_ID'];
1105 $contentEntityId = (int)$event[
'SOURCE_ID'];
1107 case 'lists_new_element':
1109 $contentEntityId = (int)$event[
'SOURCE_ID'];
1117 && $contentEntityId > 0
1121 'ENTITY_TYPE' => $contentEntityType,
1122 'ENTITY_ID' => $contentEntityId
1133 if (!is_array($params))
1139 !isset($params[
'user_id'])
1141 && \CSocNetUser::isCurrentUserModuleAdmin()
1148 isset($params[
'user_id'])
1149 && (int)$params[
'user_id'] > 0
1150 ? (
int)$params[
'user_id']
1153 if ($userId <= 0 && is_object($USER))
1155 $userId = $USER->getId();
1161 $save = (!isset($params[
'save']) || (bool)$params[
'save']);
1166 || !$contentEntityId
1173 'userId' => $userId,
1174 'typeId' => $contentTypeId,
1175 'entityId' => $contentEntityId,
1181 $pool->useMasterOnly(
true);
1188 $logItem = Log::getById(
$logId);
1191 $fields = $logItem->getFields();
1192 $contentTypeId = $fields[
'RATING_TYPE_ID'] ??
null;
1193 $contentEntityId = $fields[
'RATING_ENTITY_ID'] ??
null;
1194 if ($contentTypeId && $contentEntityId)
1197 'userId' => $userId,
1198 'typeId' => $contentTypeId,
1199 'entityId' => $contentEntityId,
1207 $pool->useMasterOnly(
false);
1211 && isset($result[
'success'])
1212 && $result[
'success']
1219 if (UserContentView::getAvailability())
1222 isset($result[
'savedInDB'])
1223 && $result[
'savedInDB']
1226 if (Loader::includeModule(
'pull') && !$this->isComment($this->
getContentTypeId()))
1228 \CPullWatch::addToStack(
'CONTENTVIEW' . $viewParams[
'typeId'] .
'-' . $viewParams[
'entityId'],
1230 'module_id' =>
'contentview',
1234 'USER_ID' => $userId,
1235 'TYPE_ID' => $viewParams[
'typeId'],
1236 'ENTITY_ID' => $viewParams[
'entityId'],
1237 'CONTENT_ID' => $viewParams[
'typeId'] .
'-' . $viewParams[
'entityId']
1246 Subscription::onContentViewed([
1247 'userId' => $userId,
1251 \Bitrix\Socialnetwork\Internals\EventService\Service::addEvent(
1252 \
Bitrix\Socialnetwork\Internals\EventService\EventDictionary::EVENT_SPACE_LIVEFEED_POST_VIEW,
1254 'SONET_LOG_ID' => (
int)
$logId,
1255 'USER_ID' => (
int)$userId,
1256 'TYPE_ID' => $contentTypeId,
1257 'ENTITY_ID' => $contentEntityId,
1263 'socialnetwork',
'onContentViewed',
1275 $entityType =
false;
1279 isset($params[
'TYPE'])
1280 && in_array($params[
'TYPE'], self::getTypes())
1285 if (!empty($params[
'EVENT_ID']))
1287 $blogPostLivefeedProvider =
new BlogPost;
1289 $type === self::TYPE_POST
1290 && in_array($params[
'EVENT_ID'], $blogPostLivefeedProvider->getEventId(),
true)
1294 $entityId = (isset($params[
'SOURCE_ID']) ? (int)$params[
'SOURCE_ID'] :
false);
1302 'ENTITY_TYPE' => $entityType,
1326 $this->logEventId = $eventId;
1331 private function setLogEntityType($entityType =
''): bool
1333 if ($entityType ==
'')
1338 $this->logEntityType = $entityType;
1343 private function setLogEntityId(
$entityId = 0): bool
1365 $res = self::$logTable::getList([
1369 'select' => [
'EVENT_ID',
'ENTITY_TYPE',
'ENTITY_ID' ]
1371 if ($logFields = $res->fetch())
1373 $return = $logFields;
1376 $this->setLogEntityType($logFields[
'ENTITY_TYPE']);
1377 $this->setLogEntityId($logFields[
'ENTITY_ID']);
1387 if ($this->logEventId !==
null)
1394 if (!empty($logFields[
'EVENT_ID']))
1396 $result = $logFields[
'EVENT_ID'];
1407 if ($this->logEntityType !==
null)
1414 if (!empty($logFields[
'ENTITY_TYPE']))
1416 $result = $logFields[
'ENTITY_TYPE'];
1427 if ($this->logEntityId !==
null)
1434 if (!empty($logFields[
'ENTITY_ID']))
1436 $result = $logFields[
'ENTITY_ID'];
1452 || !is_array($params)
1453 || empty($params[
'id'])
1459 if (!is_array($params[
'id']))
1461 $params[
'id'] = [ $params[
'id'] ];
1479 global $USER_FIELD_MANAGER;
1483 $userFieldEntity = (string)($params[
'userFieldEntity'] ??
'');
1485 $userFieldCode = (string)($params[
'userFieldCode'] ??
'');
1486 $clone = (boolean)($params[
'clone'] ??
false);
1489 $userFieldEntity ===
''
1490 || $userFieldCode ===
''
1491 || $userFieldEntityId <= 0
1499 $cacheKey = $userFieldEntity . $userFieldEntityId . $clone;
1501 if (isset($cache[$cacheKey]))
1503 $result = $cache[$cacheKey];
1507 $entityUF = $USER_FIELD_MANAGER->getUserFields($userFieldEntity, $userFieldEntityId, LANGUAGE_ID);
1509 !empty($entityUF[$userFieldCode])
1510 && !empty($entityUF[$userFieldCode][
'VALUE'])
1511 && is_array($entityUF[$userFieldCode][
'VALUE'])
1516 $this->attachedDiskObjectsCloned =
self::cloneUfValues($entityUF[$userFieldCode][
'VALUE']);
1517 $result = $cache[$cacheKey] = array_values($this->attachedDiskObjectsCloned);
1521 $result = $cache[$cacheKey] = $entityUF[$userFieldCode][
'VALUE'];
1526 if (!is_array($result))
1539 private function isComment(
string $contentTypeId): bool
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
const DATA_ENTITY_TYPE_PHOTOGALLERY_ALBUM
setParentProvider($value)
setDiskObjectsCloned(array $values)
const DATA_ENTITY_TYPE_PHOTOGALLERY_PHOTO
setSourceFields(array $fields)
const DATA_ENTITY_TYPE_LOG_ENTRY
getPermissions(array $entity)
setSourceAuxData($auxData)
const DATA_ENTITY_TYPE_TIMEMAN_ENTRY
const DATA_ENTITY_TYPE_LISTS_ITEM
getAdditionalData($params=[])
const DATA_ENTITY_TYPE_BLOG_POST
const DATA_ENTITY_TYPE_RATING_LIST
setOption(string $key, $value)
$sourceAttachedDiskObjects
checkAdditionalDataParams(&$params)
const DATA_ENTITY_TYPE_TIMEMAN_REPORT
setRatingTypeId(string $value)
getAttachedDiskObjects($clone=false)
setContentView($params=[])
warmUpAuxCommentsStaticCache(array $params=[])
const DATA_ENTITY_TYPE_FORUM_POST
static cloneUfValues(array $values)
static getProvider($entityType)
setSourceDateTime(DateTime $datetime)
const DATA_ENTITY_TYPE_CALENDAR_EVENT
static init(array $params)
setSourceDiskObjects(array $files)
const DATA_RESULT_TYPE_SOURCE
setAdditionalParams(array $additionalParams)
setSourceAttachedDiskObjects(array $diskAttachedObjects)
getEntityAttachedDiskObjects(array $params=[])
const DATA_ENTITY_TYPE_INTRANET_NEW_USER
setRatingEntityId(int $value)
const DATA_ENTITY_TYPE_BLOG_COMMENT
static getContentId($event=[])
static getEntityData(array $params)
setSourceAuthorId($authorId=0)
$attachedDiskObjectsCloned
setSourceOriginalText($text)
setLogEventId($eventId='')
const DATA_ENTITY_TYPE_BITRIX24_NEW_USER
const DATA_ENTITY_TYPE_FORUM_TOPIC
setSourceDescription($description)
getAttachedDiskObjectsCloned()
const DATA_ENTITY_TYPE_WIKI
const DATA_ENTITY_TYPE_TASKS_TASK
const DATA_ENTITY_TYPE_LOG_COMMENT
getSonetGroupsAvailable($feature=false, $operation=false)
getDiskObjects($entityId, $clone=false)
getSourceAttachedDiskObjects()
static set($params=array())