- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/rest.php
- Класс: BitrixImOpenLinesRest
- Вызов: Rest::widgetOperatorGet
static function widgetOperatorGet($params, $n, CRestServer $server)
{
$params = array_change_key_case($params, CASE_UPPER);
$type = CPullChannel::TYPE_PRIVATE;
if ($params['APPLICATION'] == 'Y')
{
$clientId = $server->getClientId();
if (!$clientId)
{
throw new RestException('Get application public channel available only for application authorization.', 'WRONG_AUTH_TYPE', CRestServer::STATUS_WRONG_REQUEST);
}
$type = $clientId;
}
$users = [];
if (is_string($params['USERS']))
{
$params['USERS'] = CUtil::JsObjectToPhp($params['USERS']);
}
if (is_array($params['USERS']))
{
foreach ($params['USERS'] as $userId)
{
$userId = (int)$userId;
if ($userId > 0)
{
$users[$userId] = $userId;
}
}
}
if (empty($users))
{
throw new RestException('A wrong format for the USERS field is passed', 'INVALID_FORMAT', CRestServer::STATUS_WRONG_REQUEST);
}
global $USER;
$operators = ModelSessionTable::getList([
'select' => ['OPERATOR_ID'],
'filter' => [
'=USER_ID' => $USER->GetID(),
'=CLOSED' => 'N'
]])->fetchAll();
$operators = array_map(function($operator){
return $operator['OPERATOR_ID'];
}, $operators);
foreach ($users as $user)
{
if (!in_array((string)$user, $operators, true))
{
//TODO: Exception details
throw new RestException('Wrong operator ID');
}
}
$configParams = [];
$configParams['TYPE'] = $type;
$configParams['USERS'] = $users;
$configParams['JSON'] = true;
$config = BitrixPullChannel::getPublicIds($configParams);
if (!$config)
{
throw new RestException('Push & Pull server is not configured', 'SERVER_ERROR', CRestServer::STATUS_INTERNAL);
}
return $config;
}