Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
user.php
1<?php
2namespace Bitrix\Main\Rest;
3
6
7if(Main\Loader::includeModule("rest")):
8
9class User extends \IRestService
10{
11 public static function getHistoryList($query, $nav = 0, \CRestServer $server)
12 {
13 global $USER;
14
15 $query = array_change_key_case($query, CASE_LOWER);
16
17 $filter = ($query['filter'] ?? array());
18 $order = ($query['order'] ?? array('ID' => 'DESC'));
19
20 static $filterFields = array("USER_ID", "DATE_INSERT", "EVENT_TYPE", "REMOTE_ADDR", "USER_AGENT", "REQUEST_URI", "FIELD");
21 static $orderFields = array("ID");
22
23 $queryFilter = static::sanitizeFilter(
24 $filter,
25 $filterFields,
26 function($field, $value, $operation)
27 {
28 switch($field)
29 {
30 case 'DATE_INSERT':
31 return Main\Type\DateTime::createFromUserTime(\CRestUtil::unConvertDateTime($value));
32 break;
33 case 'USER_ID':
34 case 'FIELD':
35 if($operation <> '=')
36 {
37 throw new Rest\RestException("Only '=' operation is allowed for the filter field {$field}.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
38 }
39 break;
40
41 }
42 return $value;
43 }
44 );
45
46 if(!isset($queryFilter["=USER_ID"]))
47 {
48 throw new Rest\RestException("USER_ID filter field is required.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
49 }
50
51 if(!$USER->CanDoOperation('edit_all_users') && $queryFilter["=USER_ID"] <> $USER->GetID())
52 {
53 throw new Rest\AccessException();
54 }
55
56 if(isset($queryFilter["=FIELD"]))
57 {
58 $queryFilter['=\Bitrix\Main\UserProfileRecordTable:HISTORY.FIELD'] = $queryFilter["=FIELD"];
59 unset($queryFilter["=FIELD"]);
60 }
61
62 $order = static::sanitizeOrder($order, $orderFields);
63
64 $navParams = static::getNavData($nav, true);
65
66 $dbRes = Main\UserProfileHistoryTable::getList(array(
67 'filter' => $queryFilter,
68 'limit' => $navParams['limit'],
69 'offset' => $navParams['offset'],
70 'count_total' => true,
71 'order' => $order,
72 ));
73
74 $result = array();
75 while($event = $dbRes->fetch())
76 {
78 $ts = $event['DATE_INSERT'];
79 $event['DATE_INSERT'] = \CRestUtil::convertDateTime($ts->toString());
80
81 $result[] = $event;
82 }
83
84 return static::setNavData($result, array(
85 "count" => $dbRes->getCount(),
86 "offset" => $navParams['offset']
87 ));
88 }
89
90 public static function getHistoryFieldsList($query, $nav = 0, \CRestServer $server)
91 {
92 global $USER;
93
94 $query = array_change_key_case($query, CASE_LOWER);
95
96 $filter = ($query['filter'] ?? array());
97 $order = ($query['order'] ?? array('ID' => 'ASC'));
98
99 static $filterFields = array("HISTORY_ID", "FIELD");
100 static $orderFields = array("ID");
101
102 $queryFilter = static::sanitizeFilter(
103 $filter,
104 $filterFields,
105 function($field, $value, $operation)
106 {
107 switch($field)
108 {
109 case 'HISTORY_ID':
110 case 'FIELD':
111 if($operation <> '=')
112 {
113 throw new Rest\RestException("Only '=' operation is allowed for the filter field {$field}.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
114 }
115 break;
116
117 }
118 return $value;
119 }
120 );
121
122 if(!isset($queryFilter["=HISTORY_ID"]))
123 {
124 throw new Rest\RestException("HISTORY_ID filter field is required.", Rest\RestException::ERROR_ARGUMENT, \CRestServer::STATUS_WRONG_REQUEST);
125 }
126
127 if(!$USER->CanDoOperation('edit_all_users'))
128 {
129 $queryFilter["=HISTORY.USER_ID"] = $USER->GetID();
130 }
131
132 $order = static::sanitizeOrder($order, $orderFields);
133
134 $dbRes = Main\UserProfileRecordTable::getList(array(
135 'filter' => $queryFilter,
136 'order' => $order,
137 ));
138
139 $result = $dbRes->fetchAll();
140
141 return $result;
142 }
143}
144
145endif;
static includeModule($moduleName)
Definition loader.php:69
if(Main\Loader::includeModule("rest")) endif
Definition rating.php:7