• Модуль: voximplant
  • Путь к файлу: ~/bitrix/modules/voximplant/classes/general/vi_config.php
  • Класс: CVoxImplantConfig
  • Вызов: CVoxImplantConfig::GetConfig
static function GetConfig($id, $type = self::GET_BY_ID)
{
	if ($id == '')
	{
		return Array('ERROR' => 'Config is`t found for undefined id/number');
	}

	$filter = array();
	if($type === self::GET_BY_SEARCH_ID)
	{
		$filter = [
			'LOGIC' => 'OR',
			'=SEARCH_ID' => (string)$id,
			'=NUMBER.NUMBER' => (string)$id,
			'=GROUP_NUMBER.NUMBER' => (string)$id,
			'=CALLER_ID.NUMBER' => (string)$id,
		];

	}
	else
	{
		$filter['=ID'] = (int)$id;
	}

	$orm = VIConfigTable::getList(array(
		'select' => array(
			'*',
			'NO_ANSWER_RULE' => 'QUEUE.NO_ANSWER_RULE',
			'QUEUE_TYPE' => 'QUEUE.TYPE',
			'QUEUE_TIME' => 'QUEUE.WAIT_TIME', // compatibility fix
			'FORWARD_NUMBER' => 'QUEUE.FORWARD_NUMBER',
			'NUMBER_COUNTRY_CODE' => 'NUMBER.COUNTRY_CODE'
		),
		'filter' => $filter
	));

	$config = $orm->fetch();
	if (!$config)
	{
		return array(
			'ERROR' => $type == self::GET_BY_SEARCH_ID? 'Config is`t found for number: '.$id: 'Config is`t found for id: '.$id
		);
	}

	$result = $config;

	$result['PHONE_TITLE'] = $result['PHONE_NAME'];
	if ($result['PORTAL_MODE'] == self::MODE_LINK)
	{
		$row = VIModelCallerIdTable::getRow([
			'filter' => [
				'=CONFIG_ID' => $config['ID']
			]
		]);
		$result['SEARCH_ID'] = $result['PHONE_TITLE'] = $result['PHONE_NAME'] = $row['NUMBER'];
	}
	else if($result['PORTAL_MODE'] == self::MODE_RENT)
	{
		$row = VIModelNumberTable::getRow([
			'filter' => [
				'=CONFIG_ID' => $config['ID']
			]
		]);
		$result['SEARCH_ID'] = $result['PHONE_TITLE'] = $result['PHONE_NAME'] = $row['NUMBER'];
	}
	else if($result['PORTAL_MODE'] == self::MODE_GROUP)
	{
		if($type == self::GET_BY_SEARCH_ID)
		{
			$result['SEARCH_ID'] = $result['PHONE_TITLE'] = $result['PHONE_NAME'] = $id;
		}
	}
	else if ($result['PORTAL_MODE'] == self::MODE_SIP)
	{
		$viSip = new CVoxImplantSip();
		$sipResult = $viSip->Get($config["ID"]);

		$result['PHONE_NAME'] = preg_replace("/[^0-9#*]/i", "", $result['PHONE_NAME']);
		$result['PHONE_NAME'] = mb_strlen($result['PHONE_NAME']) >= 4? $result['PHONE_NAME']: '';

		if($sipResult)
		{
			$result['SIP_ID'] = $sipResult['ID'];
			$result['SIP_SERVER'] = $sipResult['SERVER'];
			$result['SIP_LOGIN'] = $sipResult['LOGIN'];
			$result['SIP_PASSWORD'] = $sipResult['PASSWORD'];
			$result['SIP_TYPE'] = $sipResult['TYPE'];
			$result['SIP_REG_ID'] = $sipResult['REG_ID'];
			$result['SIP_DETECT_LINE_NUMBER'] = $sipResult['DETECT_LINE_NUMBER'];
			$result['SIP_LINE_DETECT_HEADER_ORDER'] = $sipResult['LINE_DETECT_HEADER_ORDER'];
		}
		else
		{
			$result['SIP_SERVER'] = '';
			$result['SIP_LOGIN'] = '';
			$result['SIP_PASSWORD'] = '';
			$result['SIP_TYPE'] = '';
			$result['SIP_REG_ID'] = '';
			$result['SIP_DETECT_LINE_NUMBER'] = '';
			$result['SIP_LINE_DETECT_HEADER_ORDER'] = '';
		}
	}

	if ($result['FORWARD_LINE'] != '' && $result['FORWARD_LINE'] != self::FORWARD_LINE_DEFAULT)
	{
		$result['FORWARD_LINE'] = self::GetBriefConfig(array(
			'SEARCH_ID' => $result['FORWARD_LINE']
		));
	}

	if ($result['BACKUP_NUMBER'] == '')
	{
		$result['BACKUP_NUMBER'] = static::getCommonBackupNumber();
		$result['BACKUP_LINE'] = static::getCommonBackupLine();
	}

	if ($result['BACKUP_NUMBER'] != '' && $result['BACKUP_LINE'] != '')
	{
		$result['BACKUP_LINE'] = self::GetBriefConfig(['SEARCH_ID' => $result['BACKUP_LINE']]);
	}

	if ($result['FORWARD_NUMBER'] <> '')
	{
		$result["FORWARD_NUMBER"] = NormalizePhone($result['FORWARD_NUMBER'], 1);
	}

	if ($result['WORKTIME_DAYOFF_NUMBER'] <> '')
	{
		$result["WORKTIME_DAYOFF_NUMBER"] = NormalizePhone($result['WORKTIME_DAYOFF_NUMBER'], 1);
	}
	// check work time
	$result['WORKTIME_SKIP_CALL'] = 'N';
	if ($config['WORKTIME_ENABLE'] == 'Y')
	{
		$timezone = (!empty($config["WORKTIME_TIMEZONE"])) ? new DateTimeZone($config["WORKTIME_TIMEZONE"]) : null;
		$numberDate = new BitrixMainTypeDateTime(null, null, $timezone);

		if (!empty($config['WORKTIME_DAYOFF']))
		{
			$daysOff = explode(",", $config['WORKTIME_DAYOFF']);

			$allWeekDays = array('MO' => 1, 'TU' => 2, 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6, 'SU' => 7);
			$currentWeekDay = $numberDate->format('N');
			foreach($daysOff as $day)
			{
				if ($currentWeekDay == $allWeekDays[$day])
				{
					$result['WORKTIME_SKIP_CALL'] = "Y";
				}
			}
		}
		if ($result['WORKTIME_SKIP_CALL'] !== "Y" && !empty($config['WORKTIME_HOLIDAYS']))
		{
			$holidays = explode(",", $config['WORKTIME_HOLIDAYS']);
			$currentDay = $numberDate->format('d.m');

			foreach($holidays as $holiday)
			{
				if ($currentDay == $holiday)
				{
					$result['WORKTIME_SKIP_CALL'] = "Y";
				}
			}
		}
		if ($result['WORKTIME_SKIP_CALL'] !== "Y" && isset($config['WORKTIME_FROM']) && isset($config['WORKTIME_TO']))
		{
			$currentTime = $numberDate->format('G.i');

			if (!($currentTime >= $config['WORKTIME_FROM'] && $currentTime <= $config['WORKTIME_TO']))
			{
				$result['WORKTIME_SKIP_CALL'] = "Y";
			}
		}

		if ($result['WORKTIME_SKIP_CALL'] === "Y")
		{
			$result['WORKTIME_DAYOFF_MELODY'] =  CVoxImplantConfig::GetMelody('WORKTIME_DAYOFF_MELODY', $config['MELODY_LANG'], $config['WORKTIME_DAYOFF_MELODY']);
		}
	}

	if ($result['IVR'] == 'Y' && !VIIvrIvr::isEnabled())
		$result['IVR'] = 'N';

	if($result['RECORDING'] == 'Y')
	{
		$recordLimit = VILimits::getRecordLimit($result['PORTAL_MODE']);
		$recordRemain = VILimits::getRemainingRecordsCount();

		$result['RECORDING_ALLOWED'] = ($recordLimit == 0 || $recordRemain > 0) ? 'Y' : 'N';
	}

	if($result['TRANSCRIBE'] == 'Y' && !VITranscript::isEnabled())
		$result['TRANSCRIBE'] = 'N';

	$result['PORTAL_URL'] = CVoxImplantHttp::GetPortalUrl();
	$result['PORTAL_SIGN'] = CVoxImplantHttp::GetPortalSign();
	$result['MELODY_WELCOME'] = CVoxImplantConfig::GetMelody('MELODY_WELCOME', $config['MELODY_LANG'], $config['MELODY_WELCOME']);
	$result['MELODY_VOICEMAIL'] =  CVoxImplantConfig::GetMelody('MELODY_VOICEMAIL', $config['MELODY_LANG'], $config['MELODY_VOICEMAIL']);
	$result['MELODY_HOLD'] =  CVoxImplantConfig::GetMelody('MELODY_HOLD', $config['MELODY_LANG'], $config['MELODY_HOLD']);
	$result['MELODY_WAIT'] =  CVoxImplantConfig::GetMelody('MELODY_WAIT', $config['MELODY_LANG'], $config['MELODY_WAIT']);
	$result['MELODY_ENQUEUE'] =  CVoxImplantConfig::GetMelody('MELODY_ENQUEUE', $config['MELODY_LANG'], $config['MELODY_ENQUEUE']);
	$result['MELODY_RECORDING'] =  CVoxImplantConfig::GetMelody('MELODY_RECORDING', $config['MELODY_LANG'], $config['MELODY_RECORDING']);
	$result['MELODY_VOTE'] =  CVoxImplantConfig::GetMelody('MELODY_VOTE', $config['MELODY_LANG'], $config['MELODY_VOTE']);
	$result['MELODY_VOTE_END'] =  CVoxImplantConfig::GetMelody('MELODY_VOTE_END', $config['MELODY_LANG'], $config['MELODY_VOTE_END']);
	$result['MODULE_VERSION'] = CVoxImplantHttp::VERSION;

	return $result;
}