9class User
extends \IRestService
11 public static function getHistoryList($query, $nav = 0, \CRestServer $server)
15 $query = array_change_key_case($query, CASE_LOWER);
17 $filter = ($query[
'filter'] ?? array());
18 $order = ($query[
'order'] ?? array(
'ID' =>
'DESC'));
20 static $filterFields = array(
"USER_ID",
"DATE_INSERT",
"EVENT_TYPE",
"REMOTE_ADDR",
"USER_AGENT",
"REQUEST_URI",
"FIELD");
21 static $orderFields = array(
"ID");
23 $queryFilter = static::sanitizeFilter(
26 function($field, $value, $operation)
31 return Main\Type\DateTime::createFromUserTime(\CRestUtil::unConvertDateTime($value));
37 throw new Rest\RestException(
"Only '=' operation is allowed for the filter field {$field}.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
46 if(!isset($queryFilter[
"=USER_ID"]))
48 throw new Rest\RestException(
"USER_ID filter field is required.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
51 if(!$USER->CanDoOperation(
'edit_all_users') && $queryFilter[
"=USER_ID"] <> $USER->GetID())
53 throw new Rest\AccessException();
56 if(isset($queryFilter[
"=FIELD"]))
58 $queryFilter[
'=\Bitrix\Main\UserProfileRecordTable:HISTORY.FIELD'] = $queryFilter[
"=FIELD"];
59 unset($queryFilter[
"=FIELD"]);
62 $order = static::sanitizeOrder($order, $orderFields);
64 $navParams = static::getNavData($nav,
true);
66 $dbRes = Main\UserProfileHistoryTable::getList(array(
67 'filter' => $queryFilter,
68 'limit' => $navParams[
'limit'],
69 'offset' => $navParams[
'offset'],
70 'count_total' =>
true,
75 while($event = $dbRes->fetch())
78 $ts = $event[
'DATE_INSERT'];
79 $event[
'DATE_INSERT'] = \CRestUtil::convertDateTime($ts->toString());
84 return static::setNavData($result, array(
85 "count" => $dbRes->getCount(),
86 "offset" => $navParams[
'offset']
90 public static function getHistoryFieldsList($query, $nav = 0, \CRestServer $server)
94 $query = array_change_key_case($query, CASE_LOWER);
96 $filter = ($query[
'filter'] ?? array());
97 $order = ($query[
'order'] ?? array(
'ID' =>
'ASC'));
99 static $filterFields = array(
"HISTORY_ID",
"FIELD");
100 static $orderFields = array(
"ID");
102 $queryFilter = static::sanitizeFilter(
105 function($field, $value, $operation)
111 if($operation <>
'=')
113 throw new Rest\RestException(
"Only '=' operation is allowed for the filter field {$field}.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
122 if(!isset($queryFilter[
"=HISTORY_ID"]))
124 throw new Rest\RestException(
"HISTORY_ID filter field is required.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
127 if(!$USER->CanDoOperation(
'edit_all_users'))
129 $queryFilter[
"=HISTORY.USER_ID"] = $USER->GetID();
132 $order = static::sanitizeOrder($order, $orderFields);
134 $dbRes = Main\UserProfileRecordTable::getList(array(
135 'filter' => $queryFilter,
139 $result = $dbRes->fetchAll();
static includeModule($moduleName)
if(Main\Loader::includeModule("rest")) endif