71 $counterEntityType =
'',
90 is_array($counterEntityId)
91 && isset($counterEntityId[
"LOG_ID"])
96 $counterEntityId = (int)
$arFields[
"LOG_ID"];
97 $counterEntityType = (string)(
$arFields[
"ENTITY_TYPE"] ??
'');
98 $logEventId = (string)(
$arFields[
"EVENT_ID"] ??
'');
99 $createdById = (int)(
$arFields[
"CREATED_BY_ID"] ?? 0);
103 $decrement = (
$arFields[
"DECREMENT"] ??
false);
105 $setTimestamp = (isset(
$arFields[
'SET_TIMESTAMP']) &&
$arFields[
'SET_TIMESTAMP'] ===
'Y');
107 $forAllAccessOnly =
false;
108 if (isset(
$arFields[
"FOR_ALL_ACCESS_ONLY"]))
110 $forAllAccessOnly = (
$arFields[
"FOR_ALL_ACCESS_ONLY"] ?
"Y" :
"N");
114 $forAllAccessOnly ===
'Y'
118 $tagSet = (
$arFields[
"TAG_SET"] ??
false);
124 $userIdListToIncrement = (
130 $workgroupMode = (bool)(
$arFields[
"WORKGROUP_MODE"] ??
false);
134 $sendToAuthor =
false;
135 $forAllAccessOnly =
false;
139 $setTimestamp =
false;
140 $userIdListToIncrement = [];
141 $workgroupMode =
false;
144 $intranetInstalled = static::$moduleManagerClass::isModuleInstalled(
'intranet');
145 if ((
int)$counterEntityId <= 0)
150 $arSocNetAllowedSubscribeEntityTypesDesc = static::$allowedClass::GetAllowedEntityTypesDesc();
154 $code = CUserCounter::LIVEFEED_CODE . ($multiple ?
$type.$counterEntityId :
"");
178 && ($arLog = static::$logClass::GetByID($counterEntityId))
181 $logId = $counterEntityId;
182 $counterEntityType = (string)$arLog[
"ENTITY_TYPE"];
183 $logEventId = (string)$arLog[
"EVENT_ID"];
184 $createdById = (int)$arLog[
"USER_ID"];
188 && ($arLogComment = static::$logCommentClass::GetByID($counterEntityId))
191 $counterEntityType = (string)$arLogComment[
"ENTITY_TYPE"];
192 $logEventId = (string)$arLogComment[
"EVENT_ID"];
193 $createdById = (int)$arLogComment[
"USER_ID"];
194 $logId = $arLogComment[
"LOG_ID"];
198 $logId = $counterEntityId;
203 || !in_array($counterEntityType, static::$allowedClass::GetAllowedEntityTypes(),
true)
210 $res = static::$logRightTableClass::getList([
214 'select' => [
'GROUP_CODE' ],
216 while ($logRightFields =
$res->fetch())
218 $logRightCodes[] = $logRightFields[
'GROUP_CODE'];
221 $useUASubSelect =
false;
227 !defined(
'DisableSonetLogFollow')
228 || DisableSonetLogFollow !== true
232 $defaultFollowValue = static::$optionClass::get(
'socialnetwork',
'follow_default_type',
'Y');
239 if ($defaultFollowValue ===
'Y')
245 FROM b_sonet_log_follow
249 AND (CODE = 'L" . $logId .
"' OR CODE = '**')
253 FROM b_sonet_log_follow
256 AND TYPE = 'Y' AND CODE = 'L" . $logId .
"'
265 [ $join, $condition ] = static::getFollowJoin($logId,
'U.ID',
'positive');
266 $followJoin .= $join .
' AND ' . $condition .
' ';
268 [ $join, $condition ] = static::getFollowJoin($logId,
'U.ID',
'negative');
269 $followJoin .= $join .
' AND ' . $condition .
' ';
271 $wherePositive = static::getFollowWhere(
'positive');
272 $whereNegative = static::getFollowWhere(
'negative');
275 AND (LFW.USER_ID IS NOT NULL AND " . $wherePositive .
")
276 AND " . $whereNegative .
"
282 LEFT JOIN b_sonet_log_view LFV
285 AND LFV.EVENT_ID = '" .
$DB->ForSql($logEventId) .
"'";
287 $viewWhere =
"AND (LFV.USER_ID IS NULL OR LFV.TYPE = 'Y')";
289 $logRightFilterValue = [];
291 if (!empty($userIdListToIncrement))
293 $userWhere =
" AND U.ID IN (".implode(
",", $userIdListToIncrement).
")";
297 $workgroupIdList = [];
298 foreach ($logRightCodes as $rightCode)
301 !preg_match(
'/^SG(\d+)/i', $rightCode,
$matches)
307 $workgroupIdList[] = (int)
$matches[1];
310 $workgroupIdList = array_unique($workgroupIdList);
311 if (empty($workgroupIdList))
317 AND SU2G.GROUP_ID IN (" . static::implodeArrayOfIntegers($workgroupIdList) .
")
318 AND SU2G.ROLE IN (" . static::implodeArrayOfStrings(UserToGroupTable::getRolesMember()) .
")
321 elseif (!$intranetInstalled)
323 if (static::$optionClass::get(
'socialnetwork',
'sonet_log_smart_filter',
'N') ===
'Y')
333 " . (!$forAllAccess ?
' AND (UA.ACCESS_CODE = SLR.GROUP_CODE)' :
'') .
"
335 SLR.GROUP_CODE LIKE 'SG%'
336 OR SLR.GROUP_CODE = " .
$DB->Concat(
"'U'",
'U.ID') .
"
342 SLR.GROUP_CODE IN ('AU', 'G2')
343 " . (!$forAllAccess ?
' OR (UA.ACCESS_CODE = SLR.GROUP_CODE)' :
'') .
"
360 SLR.GROUP_CODE IN ('AU', 'G2')
361 " . ($forAllAccess ?
'' :
' OR (UA.ACCESS_CODE = SLR.GROUP_CODE)') .
"
366 " . ($forAllAccess ?
'' :
' AND (UA.ACCESS_CODE = SLR.GROUP_CODE)') .
"
368 SLR.GROUP_CODE LIKE 'SG%'
369 OR SLR.GROUP_CODE = " .
$DB->Concat(
"'U'",
'U.ID') .
"
378 $userLogRightsIntersectCondition =
'';
379 if (!$forAllAccess && $forAllAccessOnly !==
'Y')
381 foreach ($logRightCodes as $rightCode)
383 if (in_array($rightCode, [
'AU',
'G2' ],
true))
388 $logRightFilterValue[] = $rightCode;
391 $userLogRightsIntersectCondition = (
392 !empty($logRightFilterValue)
393 ?
' OR UA.ACCESS_CODE IN (' . static::implodeArrayOfStrings($logRightFilterValue) .
') '
394 :
' OR UA.ACCESS_CODE = SLR.GROUP_CODE '
400 && $defaultFollowValue !==
'Y'
402 && $forAllAccessOnly !==
'Y'
403 && !empty($logRightFilterValue)
406 $useUASubSelect =
true;
408 [ $join, $condition ] = static::getFollowJoin($logId,
'UA.USER_ID',
'positive');
409 $where = static::getFollowWhere(
'positive');
413 SELECT DISTINCT UA.USER_ID
414 FROM b_user_access UA
417 UA.ACCESS_CODE IN (" . static::implodeArrayOfStrings($logRightFilterValue) .
")
419 AND " . $condition .
"
423 [ $join, $condition ] = static::getFollowJoin($logId,
'U.ID',
'negative');
424 $where = static::getFollowWhere(
'negative');
426 $followJoin = $join .
' AND ' . $condition .
' ';
427 $followWhere =
" AND " . $where .
" ";
435 $forAllAccessOnly !==
'N' || $forAllAccess
436 ?
"OR (SLR.GROUP_CODE IN ('AU', 'G2'))"
439 " . $userLogRightsIntersectCondition .
"
449 array_key_exists(
"USE_CB_FILTER", $arSocNetAllowedSubscribeEntityTypesDesc[$counterEntityType])
450 && $arSocNetAllowedSubscribeEntityTypesDesc[$counterEntityType][
"USE_CB_FILTER"] ===
"Y"
455 ?
" AND U.ID <> " . $createdById
467 ," . ($decrement ?
"-1" :
"1") .
" as CNT
469 ," .
$DB->Concat(
$params[
'CODE'],
'SU2G.GROUP_ID') .
" as CODE,
471 " . ($tagSet ?
", '" .
$DB->ForSQL($tagSet) .
"' as TAG" :
"") .
"
472 " . ($setTimestamp ?
', ' . CDatabase::currentTimeFunction() .
' as TIMESTAMP_X' :
'') .
"
475 INNER JOIN b_sonet_user2group SU2G ON SU2G.USER_ID = U.ID" .
479 AND U.LAST_ACTIVITY_DATE IS NOT NULL
480 AND U.LAST_ACTIVITY_DATE > " . $helper->addDaysToDateTime(-14) .
"
481 AND CASE WHEN U.EXTERNAL_AUTH_ID IN ('".implode(
"','", static::$userTableClass::getExternalUserTypes()).
"') THEN 'N' ELSE 'Y' END = 'Y'
492 ," . ($decrement ?
"-1" :
"1").
" as CNT
493 , " .
$DB->IsNull(
"SLS.SITE_ID",
"'**'").
" as SITE_ID
494 ," .
$params[
'CODE'].
" as CODE,
496 " . ($tagSet ?
", '".$DB->ForSQL($tagSet).
"' as TAG" :
"") .
"
497 " . ($setTimestamp ?
', ' . CDatabase::currentTimeFunction() .
' as TIMESTAMP_X' :
'') .
"
500 INNER JOIN b_sonet_log_right SLR ON SLR.LOG_ID = ".$logId.
"
502 !$forAllAccess && !$useUASubSelect
503 ?
'INNER JOIN b_user_access UA
504 ON UA.USER_ID = U.ID' .
505 (!empty($logRightFilterValue) ?
' AND (UA.ACCESS_CODE = SLR.GROUP_CODE)' :
'')
508 LEFT JOIN b_sonet_log_site SLS ON SLS.LOG_ID = SLR.LOG_ID
509 " . ($followJoin !==
'' ? $followJoin :
"") .
"
511 ".(!$intranetInstalled ?
"LEFT JOIN b_sonet_log_smartfilter SLSF ON SLSF.USER_ID = U.ID " :
"").
"
515 AND U.LAST_ACTIVITY_DATE IS NOT NULL
516 AND U.LAST_ACTIVITY_DATE > " . $helper->addDaysToDateTime(-14) .
"
517 AND CASE WHEN U.EXTERNAL_AUTH_ID IN ('".implode(
"','", static::$userTableClass::getExternalUserTypes()).
"') THEN 'N' ELSE 'Y' END = 'Y'