Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
livefeed.php
1<?php
4
5Loc::loadMessages(__FILE__);
6
8{
9 public static function setMessageLiveFeed($users, $elementId, $workflowId, $flagCompleteProcess)
10 {
11 $elementId = intval($elementId);
12 $elementObject = CIBlockElement::getList(
13 array(),
14 array('ID' => $elementId),
15 false,
16 false,
17 array('ID', 'CREATED_BY', 'IBLOCK_NAME', 'NAME', 'IBLOCK_ID', 'LANG_DIR', 'IBLOCK_CODE')
18 );
19 $element = $elementObject->fetch();
20
21 if(!CLists::getLiveFeed($element["IBLOCK_ID"]))
22 return false;
23
24 $listSystemIblockCode = array(
25 'bitrix_holiday',
26 'bitrix_invoice',
27 'bitrix_trip',
28 'bitrix_cash',
29 'bitrix_incoming_doc',
30 'bitrix_outgoing_doc'
31 );
32
33 $params = serialize(array("ELEMENT_NAME" => $element['NAME']));
34
35 if(in_array($element['IBLOCK_CODE'], $listSystemIblockCode))
36 {
37 $element['NAME'] = preg_replace_callback(
38 '#^[^\[\]]+?\[(\d+)\]#i',
39 function ($matches)
40 {
41 $userId = $matches[1];
42 $db = CUser::GetByID($userId);
43 if ($ar = $db->GetNext())
44 {
45 $ix = randString(5);
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>';
48 }
49 return $matches[0];
50 },
51 htmlspecialcharsbx($element['NAME'])
52 );
53 }
54
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)
59 return false;
60
61 $sourceId = CBPStateService::getWorkflowIntegerId($workflowId);
62 $logId = 0;
63 $userObject = CUser::getByID($createdBy);
64 $siteId = array();
65 $siteObject = CSite::getList($by="sort", $order="desc", array("ACTIVE" => "Y"));
66 while ($site = $siteObject->fetch())
67 $siteId[] = $site['LID'];
68
69 if ($userObject->fetch())
70 {
71 global $DB;
72 $soFields = Array(
73 'ENTITY_TYPE' => SONET_LISTS_NEW_POST_ENTITY,
74 'EVENT_ID' => 'lists_new_element',
75 'ENTITY_ID' => 1,
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'],
82 'PARAMS' => $params,
83 'MESSAGE' => $workflowId,
84 'CALLBACK_FUNC' => false,
85 'SITE_ID' => $siteId,
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/'
90 );
91
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'],
97 ));
98
99 $iblockPicture = CIBlock::getArrayByID($element['IBLOCK_ID'], 'PICTURE');
100 $imageFile = CFile::getFileArray($iblockPicture);
101 if($imageFile !== false)
102 {
103 $imageFile = CFile::ResizeImageGet(
104 $imageFile,
105 array("width" => 36, "height" => 30),
106 BX_RESIZE_IMAGE_PROPORTIONAL,
107 false
108 );
109 }
110 if(empty($imageFile['src']))
111 $imageFile['src'] = '/bitrix/images/lists/default.png';
112
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" />
117 </span>
118 '.in_array($element['IBLOCK_CODE'], $listSystemIblockCode) ? $element['NAME'] : htmlspecialcharsbx($element['NAME']).'
119 </span>
120 ';
121
122 if($log = $logObject->fetch())
123 {
124 if (intval($log['ID']) > 0)
125 {
126 if(empty($users))
127 {
128 CSocNetLog::update($log['ID'], $soFields);
129 }
130 else
131 {
132 $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
133
134 $rights = self::getRights($activeUsers, $log['ID'], $createdBy, 'post');
135 $usersRight = self::getUserIdForRight($rights);
136
137 self::setSocnetFollow($usersRight, $log['ID'], 'Y', true);
138 /* Recipients tasks bp */
139 CSocNetLog::update($log['ID'], $soFields);
140
141 /* Increment the counter for participants */
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);
146
147 /* Return previous state rights */
148 CSocNetLogRights::deleteByLogID($log['ID']);
149 CSocNetLogRights::add($log['ID'], $rights, false, false);
150
151 self::setSocnetFollow($users, $log['ID'], 'Y');
152 self::setSocnetFollow($users, $log['ID'], 'N');
153 }
154
155 /* Completion of the process for the author */
156 if ($flagCompleteProcess)
157 {
158 $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
159 $rights = self::getRights($activeUsers, $log['ID'], $createdBy, 'post');
160 $usersRight = self::getUserIdForRight($rights);
161
162 /* Increment the counter for author */
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);
168
169 /* Return previous state rights */
170 CSocNetLogRights::deleteByLogID($log['ID']);
171 CSocNetLogRights::add($log['ID'], $rights, false, false);
172
173 self::setSocnetFollow($users, $log['ID'], 'Y');
174 self::setSocnetFollow($usersRight, $log['ID'], 'N');
175 }
176 }
177 }
178 else
179 {
180 $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
181
182 $soFields['=LOG_DATE'] = $DB->currentTimeFunction();
183 $logId = CSocNetLog::add($soFields, false);
184 if (intval($logId) > 0)
185 {
186 $rights = self::getRights($activeUsers, $logId, $createdBy, 'post');
187 CSocNetLogRights::add($logId, $rights, false, false);
188 $usersRight = self::getUserIdForRight($rights);
189 self::setSocnetFollow($usersRight, $logId, 'N');
190 }
191 CSocNetLog::counterIncrement($logId, $soFields['EVENT_ID'], false, 'L', false);
192 }
193 }
194 return $logId;
195 }
196
197 public static function onFillSocNetAllowedSubscribeEntityTypes(&$socnetEntityTypes)
198 {
199 $socnetEntityTypes[] = SONET_LISTS_NEW_POST_ENTITY;
200
201 global $arSocNetAllowedSubscribeEntityTypesDesc;
202 $arSocNetAllowedSubscribeEntityTypesDesc[SONET_LISTS_NEW_POST_ENTITY] = array(
203 'TITLE_LIST' => '',
204 'TITLE_ENTITY' => ''
205 );
206 }
207
208 public static function onFillSocNetLogEvents(&$socnetLogEvents)
209 {
210 $socnetLogEvents['lists_new_element'] = array(
211 'ENTITIES' => array(
212 SONET_LISTS_NEW_POST_ENTITY => array(),
213 ),
214 'FORUM_COMMENT_ENTITY' => 'WF',
215 'CLASS_FORMAT' => 'CListsLiveFeed',
216 'METHOD_FORMAT' => 'formatListsElement',
217 'HAS_CB' => 'Y',
218 'FULL_SET' => array('lists_new_element', 'lists_new_element_comment'),
219 'COMMENT_EVENT' => array(
220 'MODULE_ID' => 'lists_new_element',
221 'EVENT_ID' => 'lists_new_element_comment',
222 'OPERATION' => 'view',
223 'OPERATION_ADD' => 'log_rights',
224 'ADD_CALLBACK' => array('CListsLiveFeed', 'addCommentLists'),
225 'UPDATE_CALLBACK' => array('CSocNetLogTools', 'UpdateComment_Forum'),
226 'DELETE_CALLBACK' => array('CSocNetLogTools', 'DeleteComment_Forum'),
227 'CLASS_FORMAT' => 'CSocNetLogTools',
228 'METHOD_FORMAT' => 'FormatComment_Forum',
229 "RATING_TYPE_ID" => "FORUM_POST"
230 )
231 );
232 }
233
234 public static function formatListsElement($fields, $params, $mail = false)
235 {
236 global $CACHE_MANAGER;
237
238 $element = array(
239 'EVENT' => $fields,
240 'CREATED_BY' => array(),
241 'ENTITY' => array(),
242 'EVENT_FORMATTED' => array(),
243 );
244
245 $userObject = CUser::getByID($fields['ENTITY_ID']);
246 $user = $userObject->fetch();
247 if ($user)
248 {
249 if(!$mail)
250 {
251 global $APPLICATION;
252 $rights = array();
253 $rightsQuery = CSocNetLogRights::getList(array(), array('LOG_ID' => $fields['ID']));
254 while ($right = $rightsQuery->fetch())
255 {
256 $rights[] = $right['GROUP_CODE'];
257 }
258
259 if(defined('BX_COMP_MANAGED_CACHE'))
260 {
261 $CACHE_MANAGER->registerTag('LISTS_ELEMENT_LIVE_FEED');
262 }
263
264 $componentResult = $APPLICATION->includeComponent(
265 'bitrix:bizproc.workflow.livefeed',
266 '',
267 Array(
268 'WORKFLOW_ID' => $fields['MESSAGE'],
269 ),
270 null,
271 array('HIDE_ICONS' => 'Y')
272 );
273
274 $siteDir = rtrim(SITE_DIR, '/');
275 $url = CSocNetLogTools::formatEvent_GetURL($fields, true);
276 $url = str_replace('#SITE_DIR#', $siteDir, $url);
277 $url .= ''.$fields['ID'].'/';
278
279 $element = array(
280 'EVENT' => $fields,
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']))),
288 'URL' => $url
289 ),
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']
294 );
295 if ($params['MOBILE'] == 'Y')
296 {
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']);
300 }
301
302 if (CModule::IncludeModule('bizproc'))
303 {
304 $workflowId = \CBPStateService::getWorkflowByIntegerId($element['EVENT']['SOURCE_ID']);
305 }
306
307 if ($workflowId)
308 {
309 $element['EVENT']['SOURCE_ID'] = $workflowId;
310 }
311 }
312 return $element;
313 }
314 }
315
316 public static function addCommentLists($fields)
317 {
318 global $DB, $USER_FIELD_MANAGER;
319
320 if (!CModule::IncludeModule('forum') || !CModule::IncludeModule('bizproc'))
321 return false;
322
323 $ufFileId = array();
324 $ufDocId = array();
325 $fieldsMessage = array();
326 $messageId = array();
327 $error = array();
328 $note = array();
329
330 $sonetLogQuery = CSocNetLog::GetList(
331 array(),
332 array('ID' => $fields['LOG_ID']),
333 false,
334 false,
335 array('ID', 'SOURCE_ID', 'SITE_ID', 'MESSAGE', 'USER_ID')
336 );
337 if($sonetLog = $sonetLogQuery->fetch())
338 {
339 $users = CBPTaskService::getWorkflowParticipants($sonetLog['MESSAGE'], CBPTaskUserStatus::Waiting);
340
341 if(preg_match_all("/(?<=\[USER=)(?P<id>[0-9]+)(?=\])/", $fields['TEXT_MESSAGE'], $matches))
342 $users = array_unique(array_merge($users, $matches['id']));
343
344 $users[] = $sonetLog['USER_ID'];
345 self::setSocnetFollow($users, $sonetLog['ID'], 'Y', false, true);
346
347 $forumId = CBPHelper::getForumId();
348 if($forumId)
349 {
350 $topicQuery = CForumTopic::GetList(array(), array('FORUM_ID' => $forumId, 'XML_ID' => 'WF_'.$sonetLog['MESSAGE']));
351 if ($topicQuery && ($topic = $topicQuery->fetch()))
352 {
353 $topicId = $topic['ID'];
354 }
355 else
356 {
357 $dataTopic = array(
358 'AUTHOR_ID' => 0,
359 'TITLE' => 'WF_'.$sonetLog['MESSAGE'],
360 'TAGS' => '',
361 'MESSAGE' => 'WF_'.$sonetLog['MESSAGE'],
362 'XML_ID' => 'WF_'.$sonetLog['MESSAGE']
363 );
364
365 $userStart = array(
366 "ID" => $dataTopic["AUTHOR_ID"],
367 "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]
368 );
369
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"],
379 "APPROVED" => "Y",
380 "PERMISSION_EXTERNAL" =>'Q',
381 "PERMISSION" => 'Y',
382 );
383
384 $topicId = CForumTopic::Add($topicFields);
385
386 if (intval($topicId) > 0)
387 {
388 $dataTopic['MESSAGE'] = strip_tags($dataTopic['MESSAGE']);
389
390 $dataFields = Array(
391 "POST_MESSAGE" => $dataTopic['MESSAGE'],
392 "AUTHOR_ID" => $userStart["ID"],
393 "AUTHOR_NAME" => $userStart["NAME"],
394 "FORUM_ID" => $forumId,
395 "TOPIC_ID" => $topicId,
396 "APPROVED" => "Y",
397 "NEW_TOPIC" => "Y",
398 "PARAM1" => "WF",
399 "PARAM2" => 0,
400 "PERMISSION_EXTERNAL" => 'Q',
401 "PERMISSION" => 'Y',
402 );
403 $startMessageId = CForumMessage::Add($dataFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
404 if (intVal($startMessageId) <= 0)
405 {
406 CForumTopic::Delete($topicId);
407 $topicId = 0;
408 }
409 }
410
411 if (intval($topicId) <= 0)
412 {
413 $DB->Rollback();
414 }
415 else
416 {
417 $DB->Commit();
418 }
419 }
420
421 if ($topicId)
422 {
423 $fieldsMessage = array(
424 'POST_MESSAGE' => $fields['TEXT_MESSAGE'],
425 'USE_SMILES' => 'Y',
426 'PERMISSION_EXTERNAL' => 'Q',
427 'PERMISSION' => 'Y',
428 'APPROVED' => 'Y'
429 );
430
431 $tmp = false;
432 $USER_FIELD_MANAGER->editFormAddFields('SONET_COMMENT', $tmp);
433 if (is_array($tmp))
434 {
435 if (array_key_exists('UF_SONET_COM_DOC', $tmp))
436 {
437 $GLOBALS['UF_FORUM_MESSAGE_DOC'] = $tmp['UF_SONET_COM_DOC'];
438 }
439 elseif (array_key_exists('UF_SONET_COM_FILE', $tmp))
440 {
441 $fieldsMessage['FILES'] = array();
442 foreach($tmp['UF_SONET_COM_FILE'] as $fileId)
443 {
444 $fieldsMessage['FILES'][] = array('FILE_ID' => $fileId);
445 }
446 }
447
448 if (array_key_exists("UF_SONET_COM_URL_PRV", $tmp))
449 {
450 $GLOBALS["UF_FORUM_MES_URL_PRV"] = $tmp["UF_SONET_COM_URL_PRV"];
451 }
452 }
453
454 $messageId = ForumAddMessage("REPLY", $forumId, $topicId, 0, $fieldsMessage, $error, $note);
455
456 if ($messageId > 0)
457 {
458 $addedMessageFilesQuery = CForumFiles::getList(array('ID' => 'ASC'), array('MESSAGE_ID' => $messageId));
459 while ($addedMessageFiles = $addedMessageFilesQuery->fetch())
460 {
461 $ufFileId[] = $addedMessageFiles['FILE_ID'];
462 }
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);
465 }
466 }
467 }
468 }
469
470 if (!$messageId)
471 {
472 $error = Loc::getMessage('LISTS_LF_ADD_COMMENT_SOURCE_ERROR');
473 }
474
475 return array(
476 'SOURCE_ID' => $messageId,
477 'MESSAGE' => ($fieldsMessage ? $fieldsMessage['POST_MESSAGE'] : false),
478 'RATING_TYPE_ID' => 'FORUM_POST',
479 'RATING_ENTITY_ID' => $messageId,
480 'ERROR' => $error,
481 'NOTES' => $note,
482 'UF' => array(
483 'FILE' => $ufFileId,
484 'DOC' => $ufDocId,
485 'URL_PREVIEW' => $ufUrlPreview
486 )
487 );
488 }
489
490 protected static function getRights($users, $logId, $createdBy, $method)
491 {
492 $rights = array();
493 $rights[] = 'SA'; //socnet admin
494
495 if(!empty($users))
496 {
497 if($method == 'post')
498 $users[] = $createdBy;
499
500 foreach($users as $userId)
501 {
502 $rights[] = 'U'.$userId;
503 }
504 }
505
506 $rights = array_unique($rights);
507
508 return $rights;
509 }
510
511 protected static function getUserIdForRight($rights)
512 {
513 $users = array();
514 foreach($rights as $user)
515 {
516 if($user != 'SA')
517 {
518 $users[] = substr($user, 1);
519 }
520 }
521 return $users;
522 }
523
524 protected static function setSocnetFollow($users = array(), $logId, $type, $manualMode = false, $addingComment = false)
525 {
526 if($manualMode)
527 {
528 foreach($users as $userId)
529 {
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'])
534 {
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);
538
539 if (
540 $type == 'Y'
541 && method_exists('\Bitrix\Socialnetwork\ComponentHelper','userLogSubscribe')
542 )
543 {
544 \Bitrix\Socialnetwork\ComponentHelper::userLogSubscribe(array(
545 'logId' => $logId,
546 'userId' => $userId,
547 'typeList' => array(
548 'COUNTER_COMMENT_PUSH'
549 )
550 ));
551 }
552 }
553 }
554 }
555 else
556 {
557 if($type == 'Y')
558 {
559 foreach($users as $userId)
560 {
561 $logFollowObject = CSocNetLogFollow::getList(
562 array('USER_ID' => $userId, 'REF_ID' => $logId), array('BY_WF'));
563 $logFollow = $logFollowObject->fetch();
564
565 if(
566 empty($logFollow)
567 || ($logFollow['BY_WF'] == 'Y' || $addingComment)
568 )
569 {
570 CSocNetLogFollow::delete($userId, 'L'.$logId, false);
571
572 if (method_exists('\Bitrix\Socialnetwork\ComponentHelper','userLogSubscribe'))
573 {
574 \Bitrix\Socialnetwork\ComponentHelper::userLogSubscribe(array(
575 'logId' => $logId,
576 'userId' => $userId,
577 'typeList' => array(
578 'FOLLOW',
579 'COUNTER_COMMENT_PUSH'
580 ),
581 'followDate' => 'CURRENT',
582 'followByWF' => true
583 ));
584 }
585 else
586 {
587 CSocNetLogFollow::set($userId, 'L'.$logId, 'Y',
588 ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL", SITE_ID), SITE_ID, true);
589 }
590 }
591 }
592 }
593 else
594 {
595 foreach($users as $userId)
596 {
597 $logFollowObject = CSocNetLogFollow::getList(
598 array('USER_ID' => $userId, 'REF_ID' => $logId), array('BY_WF'));
599 $logFollow = $logFollowObject->fetch();
600
601 if(
602 empty($logFollow)
603 || $logFollow['BY_WF'] == 'Y'
604 )
605 {
606 CSocNetLogFollow::set($userId, 'L'.$logId, 'N', false, SITE_ID, true);
607 }
608 }
609 }
610 }
611 }
612
613 protected static function getSiteName()
614 {
615 return COption::getOptionString('main', 'site_name', '');
616 }
617
618 function BeforeIndexSocNet($bxSocNetSearch, $fields)
619 {
620 static $bizprocForumId = false;
621
622 if (!$bizprocForumId)
623 {
624 $bizprocForumId = intval(COption::GetOptionString('bizproc', 'forum_id'));
625 }
626
627 if(
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")
634 )
635 {
636 $topic = CForumTopic::GetByID($fields['PARAM2']);
637
638 if (
639 !empty($topic)
640 && is_array($topic)
641 && !empty($topic["XML_ID"])
642 )
643 {
644 if (preg_match('/^WF_([0-9a-f\.]+)/', $topic["XML_ID"], $match))
645 {
646 $workflowId = $match[1];
647 $state = CBPStateService::GetStateDocumentId($workflowId);
648
649 if (
650 $state[0] == 'lists'
651 && $state[1] == 'BizprocDocument'
652 && CModule::IncludeModule('iblock')
653 && (intval($state[2]) > 0)
654 )
655 {
656 $iblockElementQuery = CIBlockElement::GetList(
657 array(),
658 array(
659 "ID" => intval($state[2])
660 ),
661 false,
662 false,
663 array("ID", "IBLOCK_ID")
664 );
665
666 if ($iblockElement = $iblockElementQuery->Fetch())
667 {
668 $listId = $iblockElement["IBLOCK_ID"];
669
670 $fields["URL"] = $bxSocNetSearch->Url(
671 str_replace(
672 array("#list_id#", "#workflow_id#"),
673 array($listId, urlencode($workflowId)),
674 $bxSocNetSearch->_params["PATH_TO_WORKFLOW"]
675 ),
676 array(
677 "MID" => $fields["ENTITY_ID"]
678 ),
679 "message".$fields["ENTITY_ID"]
680 );
681
682 if (
683 !empty($fields["LID"])
684 && is_array($fields["LID"])
685 )
686 {
687 foreach ($fields["LID"] as $siteId => $url)
688 {
689 $fields["LID"][$siteId] = $fields["URL"];
690 }
691 }
692 }
693 }
694 }
695 }
696 }
697
698 return $fields;
699 }
700
705 public static function OnAfterSonetLogEntryAddComment($comment)
706 {
707 if ($comment["EVENT_ID"] != "lists_new_element_comment")
708 {
709 return;
710 }
711
712 $logQuery = CSocNetLog::getList(
713 array(),
714 array(
715 "ID" => $comment["LOG_ID"],
716 "EVENT_ID" => "lists_new_element"
717 ),
718 false,
719 false,
720 array("SOURCE_ID", "URL", "TITLE", "USER_ID", "PARAMS")
721 );
722
723 if (($log = $logQuery->fetch()) && (intval($log["SOURCE_ID"]) > 0))
724 {
725 $params = unserialize($log["PARAMS"]);
726 $title = $log["TITLE"]." - ".$params["ELEMENT_NAME"];
727 CListsLiveFeed::notifyComment(
728 array(
729 "LOG_ID" => $comment["LOG_ID"],
730 "MESSAGE_ID" => $comment["SOURCE_ID"],
731 "TO_USER_ID" => $log["USER_ID"],
732 "FROM_USER_ID" => $comment["USER_ID"],
733 "URL" => $log["URL"],
734 "TITLE" => $title
735 )
736 );
737 }
738 }
739
746 public static function OnForumCommentIMNotify($entityType, $entityId, $comment)
747 {
748 if ($entityType != "WF")
749 return;
750
751 $logQuery = CSocNetLog::getList(
752 array(),
753 array(
754 "ID" => $comment["LOG_ID"],
755 "EVENT_ID" => "lists_new_element"
756 ),
757 false,
758 false,
759 array("ID", "SOURCE_ID", "URL", "TITLE", "USER_ID", "PARAMS")
760 );
761
762 if (($log = $logQuery->fetch()) && (intval($log["SOURCE_ID"]) > 0))
763 {
764 $params = unserialize($log["PARAMS"]);
765 $title = $log["TITLE"]." - ".$params["ELEMENT_NAME"];
766 CListsLiveFeed::notifyComment(
767 array(
768 "LOG_ID" => $log["ID"],
769 "MESSAGE_ID" => $comment["MESSAGE_ID"],
770 "TO_USER_ID" => $log["USER_ID"],
771 "FROM_USER_ID" => $comment["USER_ID"],
772 "URL" => $log["URL"],
773 "TITLE" => $title
774 )
775 );
776 }
777 }
778
779 public static function NotifyComment($comment)
780 {
781 if (!Loader::includeModule("im"))
782 return;
783 if($comment["TO_USER_ID"] == $comment["FROM_USER_ID"])
784 return;
785
786 $siteDir = rtrim(SITE_DIR, '/');
787 $url = str_replace('#SITE_DIR#', $siteDir, $comment["URL"]);
788 $url .= ''.$comment['LOG_ID'].'/';
789
790 $messageAddComment = Loc::getMessage("LISTS_LF_COMMENT_MESSAGE_ADD",
791 array("#PROCESS#" => '<a href="'.$url.'" class="bx-notifier-item-action">'.$comment["TITLE"].'</a>'));
792 $userQuery = CUser::getList(
793 $by = "id",
794 $order = "asc",
795 array("ID_EQUAL_EXACT" => intval($comment["FROM_USER_ID"])),
796 array("FIELDS" => array("PERSONAL_GENDER"))
797 );
798 if ($user = $userQuery->fetch())
799 {
800 switch ($user["PERSONAL_GENDER"])
801 {
802 case "F":
803 case "M":
804 $messageAddComment = Loc::getMessage("LISTS_LF_COMMENT_MESSAGE_ADD" . '_' . $user["PERSONAL_GENDER"],
805 array("#PROCESS#" => '<a href="'.$url.'" class="bx-notifier-item-action">'.$comment["TITLE"].'</a>'));
806 break;
807 default:
808 break;
809 }
810 }
811
812 $messageFields = array(
813 "TO_USER_ID" => $comment["TO_USER_ID"],
814 "FROM_USER_ID" => $comment["FROM_USER_ID"],
815 "NOTIFY_TYPE" => IM_NOTIFY_FROM,
816 "NOTIFY_MODULE" => "lists",
817 "NOTIFY_TAG" => "SONET|EVENT|".$comment["LOG_ID"],
818 "NOTIFY_SUB_TAG" => "FORUM|COMMENT|".$comment["MESSAGE_ID"]."|".$comment["TO_USER_ID"],
819 "NOTIFY_EVENT" => "event_lists_comment_add",
820 "NOTIFY_MESSAGE" => $messageAddComment
821 );
822
823 CIMNotify::Add($messageFields);
824 }
825
826 public static function OnSendMentionGetEntityFields($commentFields)
827 {
828 if (!in_array($commentFields["EVENT_ID"], array("lists_new_element_comment")))
829 {
830 return false;
831 }
832
833 if (!CModule::IncludeModule("socialnetwork"))
834 {
835 return true;
836 }
837
838 $dbLog = CSocNetLog::GetList(
839 array(),
840 array(
841 "ID" => $commentFields["LOG_ID"],
842 ),
843 false,
844 false,
845 array("ID", "TITLE", "SOURCE_ID", "PARAMS")
846 );
847
848 if ($log = $dbLog->GetNext())
849 {
850 $genderSuffix = "";
851 $dbUser = CUser::GetByID($commentFields["USER_ID"]);
852 if($user = $dbUser->Fetch())
853 {
854 $genderSuffix = $user["PERSONAL_GENDER"];
855 }
856
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#)";
862
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"];
865
866 $return = array(
867 "URL" => $strPathToLogEntryComment,
868 "NOTIFY_MODULE" => "lists",
869 "NOTIFY_TAG" => "LISTS|COMMENT_MENTION|".$commentFields["ID"],
870 "NOTIFY_MESSAGE" => $notifyMessage,
871 "NOTIFY_MESSAGE_OUT" => $notifyMessageOut
872 );
873
874 return $return;
875 }
876 else
877 {
878 return false;
879 }
880 }
881
882 public static function OnSocNetGroupDelete($groupId)
883 {
884 $iblockIdList = array();
885 $res = \CIBlock::getList(array(), array("SOCNET_GROUP_ID" => $groupId));
886 while($iblock = $res->fetch())
887 {
888 $iblockIdList[] = $iblock["ID"];
889 }
890
891 if (empty($iblockIdList))
892 {
893 return true;
894 }
895
896 foreach($iblockIdList as $iblockId)
897 {
898 CIBlock::Delete($iblockId);
899 }
900
901 return true;
902 }
903}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static OnSendMentionGetEntityFields($commentFields)
Definition livefeed.php:826
static OnForumCommentIMNotify($entityType, $entityId, $comment)
Definition livefeed.php:746
static getRights($users, $logId, $createdBy, $method)
Definition livefeed.php:490
static OnSocNetGroupDelete($groupId)
Definition livefeed.php:882
static onFillSocNetAllowedSubscribeEntityTypes(&$socnetEntityTypes)
Definition livefeed.php:197
static getSiteName()
Definition livefeed.php:613
static getUserIdForRight($rights)
Definition livefeed.php:511
BeforeIndexSocNet($bxSocNetSearch, $fields)
Definition livefeed.php:618
static NotifyComment($comment)
Definition livefeed.php:779
static formatListsElement($fields, $params, $mail=false)
Definition livefeed.php:234
static addCommentLists($fields)
Definition livefeed.php:316
static OnAfterSonetLogEntryAddComment($comment)
Definition livefeed.php:705
static onFillSocNetLogEvents(&$socnetLogEvents)
Definition livefeed.php:208
static setSocnetFollow($users=array(), $logId, $type, $manualMode=false, $addingComment=false)
Definition livefeed.php:524
static setMessageLiveFeed($users, $elementId, $workflowId, $flagCompleteProcess)
Definition livefeed.php:9