- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/rest.php
- Класс: BitrixImOpenLinesRest
- Вызов: Rest::widgetUserConsentApply
static function widgetUserConsentApply($params, $n, CRestServer $server)
{
if ($server->getAuthType() != WidgetAuth::AUTH_TYPE)
{
throw new RestException('Access for this method allowed only by livechat authorization.', 'WRONG_AUTH_TYPE', CRestServer::STATUS_FORBIDDEN);
}
global $USER;
if (!$USER->IsAuthorized())
{
throw new RestException('Access for this method allowed only for authorized users.', 'WRONG_AUTH_TYPE', CRestServer::STATUS_FORBIDDEN);
}
$params = array_change_key_case($params, CASE_UPPER);
$params['CONFIG_ID'] = (int)$params['CONFIG_ID'];
if ($params['CONFIG_ID'] <= 0)
{
throw new RestException('Config id is not specified.', 'CONFIG_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
}
$config = ModelConfigTable::getById($params['CONFIG_ID'])->fetch();
if (!$config)
{
throw new RestException('Config is not found.', 'CONFIG_NOT_FOUND', CRestServer::STATUS_WRONG_REQUEST);
}
if (!Loader::includeModule('im'))
{
throw new RestException('Messenger is not installed.', 'IM_NOT_INSTALLED', CRestServer::STATUS_WRONG_REQUEST);
}
if ($config['AGREEMENT_MESSAGE'] != 'Y')
{
return false;
}
$chat = ImModelChatTable::getList([
'select' => ['ID'],
'filter' => [
'=ENTITY_TYPE' => 'LIVECHAT',
'=ENTITY_ID' => $config['ID'].'|'.$USER->GetID()
],
'limit' => 1
])->fetch();
if (!$chat)
{
throw new RestException('Chat is not found.', 'CHAT_NOT_FOUND', CRestServer::STATUS_WRONG_REQUEST);
}
Consent::addByContext(
(int)$config['AGREEMENT_ID'],
'imopenlines/livechat',
$chat['ID'],
['URL' => trim($params['CONSENT_URL'])]
);
return true;
}