- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::searchUser
static function searchUser($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'
);
if (isset($arParams['BUSINESS']) && $arParams['BUSINESS'] == 'Y')
{
$params['FILTER']['BUSINESS'] = 'Y';
}
$ormParams = BitrixImUser::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 = BitrixMainUserTable::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['HR_PHOTO'] = isset($arParams['AVATAR_HR']) && $arParams['AVATAR_HR'] == 'Y';
$params['JSON'] = true;
$result = BitrixImUser::getList($params);
}
return self::setNavData(
$result,
array(
"count" => $counter['CNT'],
"offset" => $params['OFFSET']
)
);
}