9 public static function setMessageLiveFeed($users, $elementId, $workflowId, $flagCompleteProcess)
11 $elementId = intval($elementId);
12 $elementObject = CIBlockElement::getList(
14 array(
'ID' => $elementId),
17 array(
'ID',
'CREATED_BY',
'IBLOCK_NAME',
'NAME',
'IBLOCK_ID',
'LANG_DIR',
'IBLOCK_CODE')
19 $element = $elementObject->fetch();
21 if(!CLists::getLiveFeed($element[
"IBLOCK_ID"]))
24 $listSystemIblockCode = array(
29 'bitrix_incoming_doc',
33 $params = serialize(array(
"ELEMENT_NAME" => $element[
'NAME']));
35 if(in_array($element[
'IBLOCK_CODE'], $listSystemIblockCode))
37 $element[
'NAME'] = preg_replace_callback(
38 '#^[^\[\]]+?\[(\d+)\]#i',
41 $userId = $matches[1];
42 $db = CUser::GetByID($userId);
43 if ($ar = $db->GetNext())
46 return '<a class="feed-post-user-name" href="/company/personal/user/'.$userId.
'/"
47 bx-post-author-id="'.$userId.
'" bx-post-author-gender="'.$ar[
'PERSONAL_GENDER'].
'" bx-tooltip-user-id="'.$userId.
'">'.CUser::FormatName(CSite::GetNameFormat(
false), $ar,
true,
false).
'</a>';
51 htmlspecialcharsbx($element[
'NAME'])
55 $path = rtrim($element[
'LANG_DIR'],
'/');
56 $urlElement = $path.COption::GetOptionString(
'lists',
'livefeed_url').
'?livefeed=y&list_id='.$element[
"IBLOCK_ID"].
'&element_id='.$elementId;
57 $createdBy = $element[
'CREATED_BY'];
58 if(!Loader::includeModule(
'socialnetwork') || $createdBy <= 0)
61 $sourceId = CBPStateService::getWorkflowIntegerId($workflowId);
63 $userObject = CUser::getByID($createdBy);
65 $siteObject = CSite::getList($by=
"sort", $order=
"desc", array(
"ACTIVE" =>
"Y"));
66 while ($site = $siteObject->fetch())
67 $siteId[] = $site[
'LID'];
69 if ($userObject->fetch())
73 'ENTITY_TYPE' => SONET_LISTS_NEW_POST_ENTITY,
74 'EVENT_ID' =>
'lists_new_element',
76 '=LOG_UPDATE' => $DB->currentTimeFunction(),
77 'SOURCE_ID' => $sourceId,
78 'USER_ID' => $createdBy,
79 'MODULE_ID' =>
'lists',
80 'TITLE_TEMPLATE' => $urlElement,
81 'TITLE' => $element[
'IBLOCK_NAME'],
83 'MESSAGE' => $workflowId,
84 'CALLBACK_FUNC' =>
false,
86 'ENABLE_COMMENTS' =>
'Y',
87 'RATING_TYPE_ID' =>
'LISTS_NEW_ELEMENT',
88 'RATING_ENTITY_ID' => $sourceId,
89 'URL' =>
'#SITE_DIR#'.COption::GetOptionString(
'socialnetwork',
'user_page',
false, SITE_ID).
'log/'
92 $logObject = CSocNetLog::getList(array(), array(
93 'ENTITY_TYPE' => $soFields[
'ENTITY_TYPE'],
94 'ENTITY_ID' => $soFields[
'ENTITY_ID'],
95 'EVENT_ID' => $soFields[
'EVENT_ID'],
96 'SOURCE_ID' => $soFields[
'SOURCE_ID'],
99 $iblockPicture = CIBlock::getArrayByID($element[
'IBLOCK_ID'],
'PICTURE');
100 $imageFile = CFile::getFileArray($iblockPicture);
101 if($imageFile !==
false)
103 $imageFile = CFile::ResizeImageGet(
105 array(
"width" => 36,
"height" => 30),
106 BX_RESIZE_IMAGE_PROPORTIONAL,
110 if(empty($imageFile[
'src']))
111 $imageFile[
'src'] =
'/bitrix/images/lists/default.png';
113 $soFields[
'TEXT_MESSAGE'] =
'
114 <span class="bp-title-desc">
115 <span class="bp-title-desc-icon">
116 <img src="'.$imageFile[
'src'].
'" width="36" height="30" border="0" />
118 '.in_array($element[
'IBLOCK_CODE'], $listSystemIblockCode) ? $element[
'NAME'] : htmlspecialcharsbx($element[
'NAME']).
'
122 if($log = $logObject->fetch())
124 if (intval($log[
'ID']) > 0)
128 CSocNetLog::update($log[
'ID'], $soFields);
132 $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
134 $rights =
self::getRights($activeUsers, $log[
'ID'], $createdBy,
'post');
139 CSocNetLog::update($log[
'ID'], $soFields);
142 CSocNetLogRights::deleteByLogID($log[
'ID']);
143 $rightsCounter =
self::getRights($users, $log[
'ID'], $createdBy,
'counter');
144 CSocNetLogRights::add($log[
'ID'], $rightsCounter,
false,
false);
145 CSocNetLog::counterIncrement($log[
'ID'], $soFields[
'EVENT_ID'],
false,
'L',
false);
148 CSocNetLogRights::deleteByLogID($log[
'ID']);
149 CSocNetLogRights::add($log[
'ID'], $rights,
false,
false);
156 if ($flagCompleteProcess)
158 $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
159 $rights =
self::getRights($activeUsers, $log[
'ID'], $createdBy,
'post');
163 $users[] = $createdBy;
164 CSocNetLogRights::deleteByLogID($log[
'ID']);
165 $rightsCounter =
self::getRights($users, $log[
'ID'], $createdBy,
'counter');
166 CSocNetLogRights::add($log[
'ID'], $rightsCounter,
false,
false);
167 CSocNetLog::counterIncrement($log[
'ID'], $soFields[
'EVENT_ID'],
false,
'L',
false);
170 CSocNetLogRights::deleteByLogID($log[
'ID']);
171 CSocNetLogRights::add($log[
'ID'], $rights,
false,
false);
180 $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
182 $soFields[
'=LOG_DATE'] = $DB->currentTimeFunction();
183 $logId = CSocNetLog::add($soFields,
false);
184 if (intval($logId) > 0)
187 CSocNetLogRights::add($logId, $rights,
false,
false);
191 CSocNetLog::counterIncrement($logId, $soFields[
'EVENT_ID'],
false,
'L',
false);
236 global $CACHE_MANAGER;
240 'CREATED_BY' => array(),
242 'EVENT_FORMATTED' => array(),
245 $userObject = CUser::getByID($fields[
'ENTITY_ID']);
246 $user = $userObject->fetch();
253 $rightsQuery = CSocNetLogRights::getList(array(), array(
'LOG_ID' => $fields[
'ID']));
254 while ($right = $rightsQuery->fetch())
256 $rights[] = $right[
'GROUP_CODE'];
259 if(defined(
'BX_COMP_MANAGED_CACHE'))
261 $CACHE_MANAGER->registerTag(
'LISTS_ELEMENT_LIVE_FEED');
264 $componentResult = $APPLICATION->includeComponent(
265 'bitrix:bizproc.workflow.livefeed',
268 'WORKFLOW_ID' => $fields[
'MESSAGE'],
271 array(
'HIDE_ICONS' =>
'Y')
274 $siteDir = rtrim(SITE_DIR,
'/');
275 $url = CSocNetLogTools::formatEvent_GetURL($fields,
true);
276 $url = str_replace(
'#SITE_DIR#', $siteDir, $url);
277 $url .=
''.$fields[
'ID'].
'/';
281 'EVENT_FORMATTED' => array(
282 'TITLE_24' =>
'<a href="'.$fields[
'TITLE_TEMPLATE'].
'" class="bx-lists-live-feed-title-link">'.$fields[
'TITLE'].
'</a>',
283 'MESSAGE' => $fields[
'TEXT_MESSAGE'].$componentResult[
'MESSAGE'],
284 'IS_IMPORTANT' =>
false,
285 'STYLE' =>
'new-employee',
286 'AVATAR_STYLE' =>
'avatar-info',
287 'DESTINATION' => CSocNetLogTools::formatDestinationFromRights($rights, array_merge($params, array(
'CREATED_BY' => $fields[
'USER_ID']))),
290 'CREATED_BY' => CSocNetLogTools::formatEvent_GetCreatedBy($fields, $params, $mail),
291 'AVATAR_SRC' => CSocNetLog::formatEvent_CreateAvatar($fields, $params),
292 'CACHED_JS_PATH' => $componentResult[
'CACHED_JS_PATH'],
293 'CACHED_CSS_PATH' => $componentResult[
'CACHED_CSS_PATH']
295 if ($params[
'MOBILE'] ==
'Y')
297 $element[
'EVENT_FORMATTED'][
'TITLE_24'] =
Loc::getMessage(
'LISTS_LF_MOBILE_DESTINATION');
298 $element[
'EVENT_FORMATTED'][
'TITLE_24_2'] = $fields[
'TITLE'];
299 unset($element[
'CACHED_CSS_PATH']);
302 if (CModule::IncludeModule(
'bizproc'))
304 $workflowId = \CBPStateService::getWorkflowByIntegerId($element[
'EVENT'][
'SOURCE_ID']);
309 $element[
'EVENT'][
'SOURCE_ID'] = $workflowId;
318 global $DB, $USER_FIELD_MANAGER;
320 if (!CModule::IncludeModule(
'forum') || !CModule::IncludeModule(
'bizproc'))
325 $fieldsMessage = array();
326 $messageId = array();
330 $sonetLogQuery = CSocNetLog::GetList(
332 array(
'ID' => $fields[
'LOG_ID']),
335 array(
'ID',
'SOURCE_ID',
'SITE_ID',
'MESSAGE',
'USER_ID')
337 if($sonetLog = $sonetLogQuery->fetch())
339 $users = CBPTaskService::getWorkflowParticipants($sonetLog[
'MESSAGE'], CBPTaskUserStatus::Waiting);
341 if(preg_match_all(
"/(?<=\[USER=)(?P<id>[0-9]+)(?=\])/", $fields[
'TEXT_MESSAGE'], $matches))
342 $users = array_unique(array_merge($users, $matches[
'id']));
344 $users[] = $sonetLog[
'USER_ID'];
347 $forumId = CBPHelper::getForumId();
350 $topicQuery = CForumTopic::GetList(array(), array(
'FORUM_ID' => $forumId,
'XML_ID' =>
'WF_'.$sonetLog[
'MESSAGE']));
351 if ($topicQuery && ($topic = $topicQuery->fetch()))
353 $topicId = $topic[
'ID'];
359 'TITLE' =>
'WF_'.$sonetLog[
'MESSAGE'],
361 'MESSAGE' =>
'WF_'.$sonetLog[
'MESSAGE'],
362 'XML_ID' =>
'WF_'.$sonetLog[
'MESSAGE']
366 "ID" => $dataTopic[
"AUTHOR_ID"],
367 "NAME" => $GLOBALS[
"FORUM_STATUS_NAME"][
"guest"]
370 $DB->StartTransaction();
371 $topicFields = Array(
372 "TITLE" => $dataTopic[
"TITLE"],
373 "TAGS" => $dataTopic[
"TAGS"],
374 "FORUM_ID" => $forumId,
375 "USER_START_ID" => $userStart[
"ID"],
376 "USER_START_NAME" => $userStart[
"NAME"],
377 "LAST_POSTER_NAME" => $userStart[
"NAME"],
378 "XML_ID" => $dataTopic[
"XML_ID"],
380 "PERMISSION_EXTERNAL" =>
'Q',
384 $topicId = CForumTopic::Add($topicFields);
386 if (intval($topicId) > 0)
388 $dataTopic[
'MESSAGE'] = strip_tags($dataTopic[
'MESSAGE']);
391 "POST_MESSAGE" => $dataTopic[
'MESSAGE'],
392 "AUTHOR_ID" => $userStart[
"ID"],
393 "AUTHOR_NAME" => $userStart[
"NAME"],
394 "FORUM_ID" => $forumId,
395 "TOPIC_ID" => $topicId,
400 "PERMISSION_EXTERNAL" =>
'Q',
403 $startMessageId = CForumMessage::Add($dataFields,
false, array(
"SKIP_INDEXING" =>
"Y",
"SKIP_STATISTIC" =>
"N"));
404 if (intVal($startMessageId) <= 0)
406 CForumTopic::Delete($topicId);
411 if (intval($topicId) <= 0)
423 $fieldsMessage = array(
424 'POST_MESSAGE' => $fields[
'TEXT_MESSAGE'],
426 'PERMISSION_EXTERNAL' =>
'Q',
432 $USER_FIELD_MANAGER->editFormAddFields(
'SONET_COMMENT', $tmp);
435 if (array_key_exists(
'UF_SONET_COM_DOC', $tmp))
437 $GLOBALS[
'UF_FORUM_MESSAGE_DOC'] = $tmp[
'UF_SONET_COM_DOC'];
439 elseif (array_key_exists(
'UF_SONET_COM_FILE', $tmp))
441 $fieldsMessage[
'FILES'] = array();
442 foreach($tmp[
'UF_SONET_COM_FILE'] as $fileId)
444 $fieldsMessage[
'FILES'][] = array(
'FILE_ID' => $fileId);
448 if (array_key_exists(
"UF_SONET_COM_URL_PRV", $tmp))
450 $GLOBALS[
"UF_FORUM_MES_URL_PRV"] = $tmp[
"UF_SONET_COM_URL_PRV"];
454 $messageId = ForumAddMessage(
"REPLY", $forumId, $topicId, 0, $fieldsMessage, $error, $note);
458 $addedMessageFilesQuery = CForumFiles::getList(array(
'ID' =>
'ASC'), array(
'MESSAGE_ID' => $messageId));
459 while ($addedMessageFiles = $addedMessageFilesQuery->fetch())
461 $ufFileId[] = $addedMessageFiles[
'FILE_ID'];
463 $ufDocId = $USER_FIELD_MANAGER->getUserFieldValue(
'FORUM_MESSAGE',
'UF_FORUM_MESSAGE_DOC', $messageId, LANGUAGE_ID);
464 $ufUrlPreview = $USER_FIELD_MANAGER->GetUserFieldValue(
"FORUM_MESSAGE",
"UF_FORUM_MES_URL_PRV", $messageId, LANGUAGE_ID);
476 'SOURCE_ID' => $messageId,
477 'MESSAGE' => ($fieldsMessage ? $fieldsMessage[
'POST_MESSAGE'] :
false),
478 'RATING_TYPE_ID' =>
'FORUM_POST',
479 'RATING_ENTITY_ID' => $messageId,
485 'URL_PREVIEW' => $ufUrlPreview
524 protected static function setSocnetFollow($users = array(), $logId, $type, $manualMode =
false, $addingComment =
false)
528 foreach($users as $userId)
530 $logFollowObject = CSocNetLogFollow::getList(
531 array(
'USER_ID' => $userId,
'REF_ID' => $logId), array(
'BY_WF',
'TYPE'));
532 $logFollow = $logFollowObject->fetch();
533 if(!empty($logFollow) && $logFollow[
'TYPE'] ==
'Y' && !$logFollow[
'BY_WF'])
535 CSocNetLogFollow::delete($userId,
'L'.$logId,
false);
536 CSocNetLogFollow::set($userId,
'L'.$logId, $type,
537 ConvertTimeStamp(time() + CTimeZone::GetOffset(),
"FULL", SITE_ID), SITE_ID,
true);
541 && method_exists(
'\Bitrix\Socialnetwork\ComponentHelper',
'userLogSubscribe')
544 \Bitrix\Socialnetwork\ComponentHelper::userLogSubscribe(array(
548 'COUNTER_COMMENT_PUSH'
559 foreach($users as $userId)
561 $logFollowObject = CSocNetLogFollow::getList(
562 array(
'USER_ID' => $userId,
'REF_ID' => $logId), array(
'BY_WF'));
563 $logFollow = $logFollowObject->fetch();
567 || ($logFollow[
'BY_WF'] ==
'Y' || $addingComment)
570 CSocNetLogFollow::delete($userId,
'L'.$logId,
false);
572 if (method_exists(
'\Bitrix\Socialnetwork\ComponentHelper',
'userLogSubscribe'))
574 \Bitrix\Socialnetwork\ComponentHelper::userLogSubscribe(array(
579 'COUNTER_COMMENT_PUSH'
581 'followDate' =>
'CURRENT',
587 CSocNetLogFollow::set($userId,
'L'.$logId,
'Y',
588 ConvertTimeStamp(time() + CTimeZone::GetOffset(),
"FULL", SITE_ID), SITE_ID,
true);
595 foreach($users as $userId)
597 $logFollowObject = CSocNetLogFollow::getList(
598 array(
'USER_ID' => $userId,
'REF_ID' => $logId), array(
'BY_WF'));
599 $logFollow = $logFollowObject->fetch();
603 || $logFollow[
'BY_WF'] ==
'Y'
606 CSocNetLogFollow::set($userId,
'L'.$logId,
'N',
false, SITE_ID,
true);
620 static $bizprocForumId =
false;
622 if (!$bizprocForumId)
624 $bizprocForumId = intval(COption::GetOptionString(
'bizproc',
'forum_id'));
628 $fields[
'ENTITY_TYPE_ID'] ==
'FORUM_POST'
629 && intval($fields[
'PARAM1']) == $bizprocForumId
630 && !empty($fields[
'PARAM2'])
631 && !empty($bxSocNetSearch->_params[
"PATH_TO_WORKFLOW"])
632 && CModule::IncludeModule(
"forum")
633 && CModule::IncludeModule(
"bizproc")
636 $topic = CForumTopic::GetByID($fields[
'PARAM2']);
641 && !empty($topic[
"XML_ID"])
644 if (preg_match(
'/^WF_([0-9a-f\.]+)/', $topic[
"XML_ID"], $match))
646 $workflowId = $match[1];
647 $state = CBPStateService::GetStateDocumentId($workflowId);
651 && $state[1] ==
'BizprocDocument'
652 && CModule::IncludeModule(
'iblock')
653 && (intval($state[2]) > 0)
656 $iblockElementQuery = CIBlockElement::GetList(
659 "ID" => intval($state[2])
663 array(
"ID",
"IBLOCK_ID")
666 if ($iblockElement = $iblockElementQuery->Fetch())
668 $listId = $iblockElement[
"IBLOCK_ID"];
670 $fields[
"URL"] = $bxSocNetSearch->Url(
672 array(
"#list_id#",
"#workflow_id#"),
673 array($listId, urlencode($workflowId)),
674 $bxSocNetSearch->_params[
"PATH_TO_WORKFLOW"]
677 "MID" => $fields[
"ENTITY_ID"]
679 "message".$fields[
"ENTITY_ID"]
683 !empty($fields[
"LID"])
684 && is_array($fields[
"LID"])
687 foreach ($fields[
"LID"] as $siteId => $url)
689 $fields[
"LID"][$siteId] = $fields[
"URL"];
828 if (!in_array($commentFields[
"EVENT_ID"], array(
"lists_new_element_comment")))
833 if (!CModule::IncludeModule(
"socialnetwork"))
838 $dbLog = CSocNetLog::GetList(
841 "ID" => $commentFields[
"LOG_ID"],
845 array(
"ID",
"TITLE",
"SOURCE_ID",
"PARAMS")
848 if ($log = $dbLog->GetNext())
851 $dbUser = CUser::GetByID($commentFields[
"USER_ID"]);
852 if($user = $dbUser->Fetch())
854 $genderSuffix = $user[
"PERSONAL_GENDER"];
857 $params = unserialize($log[
"~PARAMS"]);
858 $title = $log[
"TITLE"].
" - ".$params[
"ELEMENT_NAME"];
859 $entityName = GetMessage(
"LISTS_LF_COMMENT_MENTION_TITLE", Array(
"#PROCESS#" => $title));
860 $notifyMessage = GetMessage(
"LISTS_LF_COMMENT_MENTION" . (strlen($genderSuffix) > 0 ?
"_" . $genderSuffix :
""), Array(
"#title#" =>
"<a href=\"#url#\" class=\"bx-notifier-item-action\">".$entityName.
"</a>"));
861 $notifyMessageOut = GetMessage(
"LISTS_LF_COMMENT_MENTION" . (strlen($genderSuffix) > 0 ?
"_" . $genderSuffix :
""), Array(
"#title#" => $entityName)) .
" (" .
"#server_name##url#)";
863 $strPathToLogEntry = str_replace(
"#log_id#", $log[
"ID"], COption::GetOptionString(
"socialnetwork",
"log_entry_page",
"/company/personal/log/#log_id#/", SITE_ID));
864 $strPathToLogEntryComment = $strPathToLogEntry . (strpos($strPathToLogEntry,
"?") !==
false ?
"&" :
"?") .
"commentID=" . $commentFields[
"ID"] .
"#com" . $commentFields[
"ID"];
867 "URL" => $strPathToLogEntryComment,
868 "NOTIFY_MODULE" =>
"lists",
869 "NOTIFY_TAG" =>
"LISTS|COMMENT_MENTION|".$commentFields[
"ID"],
870 "NOTIFY_MESSAGE" => $notifyMessage,
871 "NOTIFY_MESSAGE_OUT" => $notifyMessageOut