• Модуль: voximplant
  • Путь к файлу: ~/bitrix/modules/voximplant/classes/general/vi_outgoing.php
  • Класс: CVoxImplantOutgoing
  • Вызов: CVoxImplantOutgoing::GetConfig
static function GetConfig($userId, $lineId = '')
{
	if (!VILimits::canCall())
	{
		return [
			'error' => ['code' => 'PAID_PLAN_REQUIRED']
		];
	}

	$userId = intval($userId);

	if($userId === 0)
		return array('error' => array('code' => 'EMPTY_USER_ID', 'msg' => 'userId should be positive'));

	$viUser = new CVoxImplantUser();
	$userInfo = $viUser->GetUserInfo($userId);

	if(!$userInfo)
		return array('error' => array('code' => $viUser->GetError()->code, 'msg' => $viUser->GetError()->msg));

	if($userInfo['user_extranet'])
		return array('error' => array('code' => 'EXTRANAET', 'msg' => 'Extranet user (or user hasnt department) can not use telephony'));

	$isPaid = CVoxImplantAccount::GetPayedFlag() === "Y";
	$portalLines = CVoxImplantConfig::GetLines(true, false);

	$userDefaultLine = $userInfo['user_backphone'];
	if (!isset($portalLines[$userDefaultLine]))
	{
		$defaultPortalLine = COption::GetOptionString("voximplant", "portal_number");
		if(isset($portalLines[$defaultPortalLine]))
		{
			$userDefaultLine = $defaultPortalLine;
		}
		else if(!empty($portalLines))
		{
			reset($portalLines);
			$userDefaultLine = key($portalLines);
		}
		else if(!$isPaid)
		{
			return array(
				'PORTAL_MODE' => CVoxImplantConfig::MODE_FAKE,
				'PORTAL_URL' => CVoxImplantHttp::GetPortalUrl(),
				'PORTAL_SIGN' => CVoxImplantHttp::GetPortalSign(),
				'USER_ID' => $userId,
				'USER_DIRECT_CODE' => $userInfo['user_innerphone'],
			);
		}
		else
		{
			return array('error' => array('code' => 'NEED_RENT_ERROR', 'msg' => 'No available lines found'));
		}
	}

	if($lineId != '')
	{
		if(isset($portalLines[$lineId]))
		{
			if(!CVoxImplantUser::canUseLine($userId, $lineId))
			{
				$lineId = '';
			}
		}
		else
		{
			$lineId = '';
		}
	}

	$result = CVoxImplantConfig::GetConfigBySearchId($lineId ?: $userDefaultLine);
	$result['USER_ID'] = $userId;
	$result['USER_DIRECT_CODE'] = $userInfo['user_innerphone'];

	return $result;
}