• Модуль: voximplant
  • Путь к файлу: ~/bitrix/modules/voximplant/lib/routing/router.php
  • Класс: BitrixVoximplantRoutingRouter
  • Вызов: Router::buildIncomingExecutionGraph
protected function buildIncomingExecutionGraph(Call $call)
{
	$config = $call->getConfig();
	$rootNode = new Root();
	$lastNode = $rootNode;

	if($config['USE_SIP_TO'] === 'Y')
	{
		$sipTo = $call->getSipHeader('To');

		if(preg_match('/^sip:(d+)@/', $sipTo, $matches))
		{
			$extension = $matches[1];
			$entityInfo = CVoxImplantIncoming::getByInternalPhoneNumber($extension);
			if ($entityInfo)
			{
				if ($entityInfo['ENTITY_TYPE'] === 'user')
				{
					[$sipNode, $nextNode] = static::buildUserGraph($entityInfo['ENTITY_ID'],'sip_to',CVoxImplantIncoming::RULE_QUEUE);
					$lastNode->setNext($sipNode);
					$lastNode = $nextNode;
				}
				else
				{
					$queueNode = static::buildQueueGraph($entityInfo['ENTITY_ID'],$config['TIMEMAN'] === 'Y');
					$lastNode->setNext($queueNode);
					$lastNode = $queueNode;
				}
			}
		}
	}

	if($config['DIRECT_CODE'] === 'Y')
	{
		$gatheredDigits = $call->getGatheredDigits();
		if($gatheredDigits)
		{

			$entityInfo = CVoxImplantIncoming::getByInternalPhoneNumber($gatheredDigits);
			if ($entityInfo)
			{
				if ($entityInfo['ENTITY_TYPE'] === 'user')
				{
					[$directNode, $nextNode] = static::buildUserGraph(
						$entityInfo['ENTITY_ID'],
						'direct',
						$config['DIRECT_CODE_RULE'],
						true
					);
					$lastNode->setNext($directNode);
					$lastNode = $nextNode;
				}
				else
				{
					$queueNode = static::buildQueueGraph(
						$entityInfo['ENTITY_ID'],
						$config['TIMEMAN'] === 'Y'
					);
					$lastNode->setNext($queueNode);
					$lastNode = $queueNode;
				}
			}
			else
			{
				$lastNode->setNext(new Hangup(404, 'Could not find user or queue with extension number ' . $this->call->getGatheredDigits()));
				return $rootNode;
			}
		}
	}

	if($config['IVR'] === 'Y' && $config['IVR_ID'] > 0)
	{
		$ivrNode = new Ivr($config['IVR_ID']);
		$lastNode->setNext($ivrNode);
		$lastNode = $ivrNode;
	}

	if($call->getIvrActionId() > 0)
	{
		$ivrActionNode = $this->buildIvrActionGraph($call->getIvrActionId());
		$lastNode->setNext($ivrActionNode);
		$lastNode = $ivrActionNode;
	}
	else
	{
		if($config['CRM_FORWARD'] === 'Y')
		{
			$responsibleId = CVoxImplantCrmHelper::getResponsibleWithCall($this->call);
			if($responsibleId)
			{
				if($config['TIMEMAN'] != 'Y' || CVoxImplantUser::GetActiveStatusByTimeman($responsibleId))
				{
					list($crmNode, $nextNode) = $this->buildUserGraph($responsibleId, 'crm', $config['CRM_RULE'], true);
					$lastNode->setNext($crmNode);
					$lastNode = $nextNode;
				}
			}
		}

		if($call->getQueueId())
		{
			$queueNode = $this->buildQueueGraph($call->getQueueId(), $config['TIMEMAN'] === 'Y');
			if($queueNode instanceof Node)
			{
				$lastNode->setNext($queueNode);
			}
		}
	}

	return $rootNode;
}