• Модуль: pull
  • Путь к файлу: ~/bitrix/modules/pull/classes/general/pull_channel.php
  • Класс: CPullChannel
  • Вызов: CPullChannel::CheckOnlineChannel
static function CheckOnlineChannel()
{
	if (!CPullOptions::GetQueueServerStatus())
		return "CPullChannel::CheckOnlineChannel();";

	$users = Array();
	$channels = Array();

	$isImInstalled = CModule::IncludeModule('im');
	if ($isImInstalled)
	{
		$orm = BitrixMainUserTable::getList(array(
			'select' => Array(
				'USER_ID' => 'ID',
				'CHANNEL_ID' =>	'CHANNEL.CHANNEL_ID',
				'STATUS' =>	'ST.STATUS',
				'COLOR' =>	'ST.COLOR',
				'IDLE' => 'ST.IDLE',
				'MOBILE_LAST_DATE' => 'ST.MOBILE_LAST_DATE',
				'DESKTOP_LAST_DATE' => 'ST.DESKTOP_LAST_DATE',
			 ),
			'runtime' => Array(
				new BitrixMainEntityReferenceField(
					'CHANNEL',
					'BitrixPullModelChannelTable',
					array(
						"=ref.USER_ID" => "this.ID",
						"=ref.CHANNEL_TYPE" => new BitrixMainDBSqlExpression('?s', 'private'),
					),
					array("join_type"=>"INNER")
				),
				new BitrixMainEntityReferenceField(
					'ST',
					'BitrixImModelStatusTable',
					array("=ref.USER_ID" => "this.ID"),
					array("join_type"=>"LEFT")
				),
			),
			'filter' => Array(
				'=IS_ONLINE' => 'Y',
				'=IS_REAL_USER' => 'Y'
			)
		));
	}
	else
	{
		$orm = BitrixPullChannelTable::getList([
			'select' => [
				'USER_ID',
				'CHANNEL_ID'
			],
			'filter' => [
				'=CHANNEL_TYPE' => 'private',
				'=USER.IS_ONLINE' => 'Y',
				'=USER.IS_REAL_USER' => 'Y',
			]
		]);
	}

	while ($res = $orm->fetch())
	{
		$channels[$res['CHANNEL_ID']] = $res['USER_ID'];
		$users[$res['USER_ID']] = $isImInstalled? CIMStatus::prepareLastDate($res): $res;
	}

	if (count($users) == 0)
	{
		return "CPullChannel::CheckOnlineChannel();";
	}

	$arOnline = static::getOnlineUsers($channels);

	if (count($arOnline) > 0)
	{
		ksort($arOnline);
		CUser::SetLastActivityDateByArray($arOnline);
	}

		$arSend = Array();
		if ($isImInstalled)
		{
			foreach ($arOnline as $userId)
			{
				$arSend[$userId] = Array(
					'id' => $userId,
					'status' => $users[$userId]['STATUS'],
					'color' => $users[$userId]['COLOR']? BitrixImColor::getColor($users[$userId]['COLOR']): BitrixImColor::getColorByNumber($userId),
					'idle' => $users[$userId]['IDLE'],
					'mobile_last_date' => $users[$userId]['MOBILE_LAST_DATE'],
					'desktop_last_date' => $users[$userId]['DESKTOP_LAST_DATE'],
					'last_activity_date' => new BitrixMainTypeDateTime(),
				);
			}
		}
		else
		{
			foreach ($arOnline as $userId)
			{
				$arSend[$userId] = Array(
					'id' => $userId,
					'status' => 'online',
					'color' => '#556574',
					'idle' => false,
					'mobile_last_date' => false,
					'desktop_last_date' => false,
					'last_activity_date' => new BitrixMainTypeDateTime(),
				);
			}
		}

	CPullStack::AddShared(Array(
		'module_id' => 'online',
		'command' => 'list',
		'expiry' => 240,
		'params' => Array(
			'users' => $arSend
		),
	));

	return "CPullChannel::CheckOnlineChannel();";
}