- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/user_counter.php
- Класс: CAllUserCounter
- Вызов: CAllUserCounter::SendPullEvent
static function SendPullEvent($user_id, $code = "", $bMultiple = false)
{
$user_id = (int)$user_id;
if ($user_id < 0)
{
return false;
}
if (self::CheckLiveMode())
{
global $DB;
$arSites = Array();
$by = '';
$order = '';
$res = CSite::GetList($by, $order, Array("ACTIVE" => "Y"));
while ($row = $res->Fetch())
{
$arSites[] = $row['ID'];
}
$helper = BitrixMainApplication::getConnection()->getSqlHelper();
$strSQL = "
SELECT uc.USER_ID as CHANNEL_ID, 'private' as CHANNEL_TYPE, uc.USER_ID, uc.SITE_ID, uc.CODE, uc.CNT
FROM b_user_counter uc
INNER JOIN b_user u ON u.ID = uc.USER_ID AND (CASE WHEN u.EXTERNAL_AUTH_ID IN ('" . implode("', '", BitrixMainUserTable::getExternalUserTypes())."') THEN 'Y' ELSE 'N' END) = 'N' AND u.LAST_ACTIVITY_DATE > ".$helper->addSecondsToDateTime('(-3600)')."
WHERE uc.USER_ID = " . (int)$user_id
.(
$code <> ''
? (
$bMultiple
? " AND uc.CODE LIKE '".$DB->ForSQL($code)."%'"
: " AND uc.CODE = '".$DB->ForSQL($code)."'"
)
: ""
)."
";
$res = $DB->Query($strSQL, false, "FILE: ".__FILE__."
LINE: ".__LINE__);
$pullMessage = Array();
while ($row = $res->Fetch())
{
$key = ($code <> '' ? $code : $row['CODE']);
if (!(
$row['CHANNEL_TYPE'] === 'private'
|| (
$row['CHANNEL_TYPE'] === 'shared'
&& (int)$row['USER_ID'] === 0
)
))
{
continue;
}
if ($row['SITE_ID'] === self::ALL_SITES)
{
foreach ($arSites as $siteId)
{
if (isset($pullMessage[$row['CHANNEL_ID']][$siteId][$key]))
{
$pullMessage[$row['CHANNEL_ID']][$siteId][$key] += (int)$row['CNT'];
}
else
{
$pullMessage[$row['CHANNEL_ID']][$siteId][$key] = (int)$row['CNT'];
}
}
}
elseif (isset($pullMessage[$row['CHANNEL_ID']][$row['SITE_ID']][$key]))
{
$pullMessage[$row['CHANNEL_ID']][$row['SITE_ID']][$key] += (int)$row['CNT'];
}
else
{
$pullMessage[$row['CHANNEL_ID']][$row['SITE_ID']][$key] = (int)$row['CNT'];
}
}
foreach ($pullMessage as $channelId => $arMessage)
{
BitrixPullEvent::add($channelId, Array(
'module_id' => 'main',
'command' => 'user_counter',
'expiry' => 3600,
'params' => $arMessage,
));
}
}
}