• Модуль: imopenlines
  • Путь к файлу: ~/bitrix/modules/imopenlines/lib/queue/queue.php
  • Класс: BitrixImOpenLinesQueueQueue
  • Вызов: Queue::createSession
public function createSession($operatorId = 0, $crmManager = null, $isGroupByChat = false)
{
	$defaultQueueTime = $this->getQueueTime();

	$result = [
		'OPERATOR_ID' => 0,
		'QUEUE_HISTORY' => [],
		'OPERATOR_LIST' => [],
		'DATE_OPERATOR' => null,
		'DATE_QUEUE' => null,
		'DATE_NO_ANSWER' => null,
		'JOIN_BOT' => false,
		'UNDISTRIBUTED' => false,
		'OPERATOR_CRM' => false,
	];

	if (empty($operatorId))
	{
		$result['DATE_QUEUE'] = new DateTime();

		// Bot
		if (
			$this->config['ACTIVE'] != 'N' &&
			$this->config['WELCOME_BOT_ENABLE'] == 'Y' &&
			$this->config['WELCOME_BOT_ID'] > 0 &&
			(
				$this->config['WELCOME_BOT_JOIN'] == Config::BOT_JOIN_ALWAYS ||
				$this->chat->isNowCreated()
			)
		)
		{
			$result['JOIN_BOT'] = true;

			$operatorId = $this->config['WELCOME_BOT_ID'];

			if ($this->config['WELCOME_BOT_TIME'] > 0)
			{
				$result['DATE_QUEUE']->add($this->config['WELCOME_BOT_TIME'] . ' SECONDS');
			}
			else
			{
				$result['DATE_QUEUE'] = null;
			}
		}
		//Operator
		else
		{
			$result['DATE_QUEUE']->add($defaultQueueTime . ' SECONDS');

			$result['DATE_NO_ANSWER'] = (new DateTime())->add($this->config['NO_ANSWER_TIME'] . ' SECONDS');

			//CRM
			if (
				$crmManager
				&& $isGroupByChat == false
				&& $this->config['CRM'] == 'Y'
				&& $crmManager->isLoaded()
				&& $this->config['CRM_FORWARD'] == 'Y'
			)
			{
				$crmManager->search();

				$crmOperatorId = $crmManager->getOperatorId();

				if (
					$crmOperatorId !== null &&
					$crmOperatorId > 0 &&
					$this->isActiveCrmUser($crmOperatorId) === true
				)
				{
					$operatorId = $crmOperatorId;

					$result['DATE_QUEUE'] = null;
					$result['OPERATOR_CRM'] = true;
				}
			}

			$undistributedSession = $this->isUndistributedSession();

			// Queue
			if (empty($operatorId) && !$undistributedSession)
			{
				$resultOperatorQueue = $this->getOperatorsQueue();

				if ($resultOperatorQueue['RESULT'])
				{
					$operatorId = $resultOperatorQueue['OPERATOR_ID'];
					$result['OPERATOR_LIST'] = $resultOperatorQueue['OPERATOR_LIST'];
					$result['QUEUE_HISTORY'] = $resultOperatorQueue['QUEUE_HISTORY'];
				}
				else
				{
					$result['UNDISTRIBUTED'] = true;

				}
				$result['DATE_QUEUE'] = $resultOperatorQueue['DATE_QUEUE'];
			}

			if (empty($operatorId) && $undistributedSession)
			{
				$result['UNDISTRIBUTED'] = true;
				$result['DATE_QUEUE'] = new DateTime();
			}

			if (!empty($operatorId))
			{
				$result['DATE_OPERATOR'] = new DateTime();
			}
		}
	}
	else
	{
		$result['DATE_OPERATOR'] = new DateTime();
	}

	if (!empty($operatorId))
	{
		$result['OPERATOR_ID'] = $operatorId;
		if (empty($result['OPERATOR_LIST']))
		{
			$result['OPERATOR_LIST'] = [$operatorId];
		}
		if (empty($result['QUEUE_HISTORY']))
		{
			$result['QUEUE_HISTORY'][$operatorId] = true;
		}
	}

	return $result;
}