- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::searchChat
static function searchChat($arParams, $offset, CRestServer $server)
{
$arParams = array_change_key_case($arParams, CASE_UPPER);
if (!isset($arParams['FIND']))
{
throw new BitrixRestRestException("Too short a search phrase.", "FIND_SHORT", CRestServer::STATUS_WRONG_REQUEST);
}
$params = Array(
'FILTER' => Array('SEARCH' => $arParams['FIND']),
'JSON' => 'Y'
);
$ormParams = BitrixImChat::getListParams($params);
if (is_null($ormParams))
{
throw new BitrixRestRestException("Too short a search phrase.", "FIND_SHORT", CRestServer::STATUS_WRONG_REQUEST);
}
$ormParams['select'] = array("CNT" => new BitrixMainEntityExpressionField('CNT', 'COUNT(1)'));
$counter = BitrixImModelChatTable::getList($ormParams)->fetch();
$result = Array();
if ($counter && $counter["CNT"] > 0)
{
$params['OFFSET'] = intval($offset) > 0? intval($offset): (isset($arParams['OFFSET']) && intval($arParams['OFFSET']) > 0? intval($arParams['OFFSET']): 0);
$params['LIMIT'] = isset($arParams['LIMIT'])? (intval($arParams['LIMIT']) > 50? 50: intval($arParams['LIMIT'])): 10;
$params['ORDER'] = Array('ID' => 'DESC');
$params['JSON'] = 'Y';
$result = BitrixImChat::getList($params);
}
return self::setNavData(
$result,
array(
"count" => $counter['CNT'],
"offset" => $params['OFFSET']
)
);
return $result;
}