• Модуль: imopenlines
  • Путь к файлу: ~/bitrix/modules/imopenlines/lib/queue.php
  • Класс: BitrixImOpenLinesQueue
  • Вызов: Queue::getCountFreeSlotOperator
static function getCountFreeSlotOperator($idUser, $idLine = 0, $maxChat = 0, $typeMaxChat = null)
{
	if(empty($maxChat) || $maxChat > Queue::MAX_CHAT)
	{
		$maxChat = Queue::MAX_CHAT;
	}

	$countNotCloseGlobal = 0;

	if(Loader::includeModule('im'))
	{
		$countNotCloseGlobal = RecentTable::getCount([
			'=USER_ID' => $idUser,
			'=ITEM_TYPE' => IM_MESSAGE_OPEN_LINE
		]);
	}

	$result = Queue::MAX_CHAT - $countNotCloseGlobal;

	if(
		$result > 0 &&
		!empty($idLine) &&
		is_numeric($idLine) &&
		$idLine > 0 &&
		!empty($typeMaxChat) &&
		(
			$typeMaxChat == Config::TYPE_MAX_CHAT_ANSWERED ||
			$typeMaxChat == Config::TYPE_MAX_CHAT_ANSWERED_NEW ||
			$typeMaxChat == Config::TYPE_MAX_CHAT_CLOSED
		)
	)
	{
		if($typeMaxChat == Config::TYPE_MAX_CHAT_ANSWERED_NEW)
		{
			$stopStatus = Session::STATUS_CLIENT_AFTER_OPERATOR;
		}

		if($typeMaxChat == Config::TYPE_MAX_CHAT_ANSWERED)
		{
			$stopStatus = Session::STATUS_OPERATOR;
		}

		if($typeMaxChat == Config::TYPE_MAX_CHAT_CLOSED)
		{
			$stopStatus = Session::STATUS_WAIT_CLIENT;
		}

		if(!empty($stopStatus))
		{
			$countBusy  = SessionCheckTable::getCount([
				'=SESSION.OPERATOR_ID' => $idUser,
				'=SESSION.CONFIG_ID' => $idLine,
				' $stopStatus
			]);

			$freeSlotRestrictions = $maxChat - $countBusy;

			$result = min($freeSlotRestrictions, $result);
		}
	}

	return $result;
}