17 import(
'lib.pkp.classes.handler.APIHandler');
18 import(
'classes.core.Services');
26 $this->_handlerPath =
'users';
27 $roles = array(ROLE_ID_SITE_ADMIN, ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR);
28 $this->_endpoints = array(
32 'handler' => array($this,
'getMany'),
37 'handler' => array($this,
'getReviewers'),
42 'handler' => array($this,
'get'),
47 parent::__construct();
53 function authorize($request, &$args, $roleAssignments) {
54 import(
'lib.pkp.classes.security.authorization.ContextAccessPolicy');
56 return parent::authorize($request, $args, $roleAssignments);
67 public function getMany($slimRequest, $response, $args) {
69 $context = $request->getContext();
72 return $response->withStatus(404)->withJsonError(
'api.404.resourceNotFound');
75 $params = $this->_processAllowedParams($slimRequest->getQueryParams(), [
78 'assignedToSubmission',
79 'assignedToSubmissionStage',
89 $params[
'contextId'] = $context->getId();
95 if (count($usersItereator)) {
97 'request' => $request,
98 'slimRequest' => $slimRequest,
100 foreach ($usersItereator as $user) {
101 $items[] =
Services::get(
'user')->getSummaryProperties($user, $propertyArgs);
110 return $response->withJson($data, 200);
121 public function get($slimRequest, $response, $args) {
124 if (!empty($args[
'userId'])) {
129 return $response->withStatus(404)->withJsonError(
'api.404.resourceNotFound');
132 $data =
Services::get(
'user')->getFullProperties($user, array(
133 'request' => $request,
134 'slimRequest' => $slimRequest
137 return $response->withJson($data, 200);
150 $context = $request->getContext();
153 return $response->withStatus(404)->withJsonError(
'api.404.resourceNotFound');
156 $params = $this->_processAllowedParams($slimRequest->getQueryParams(), [
159 'daysSinceLastAssignment',
171 $params[
'contextId'] = $context->getId();
176 $usersIterator =
Services::get(
'user')->getReviewers($params);
177 if (count($usersIterator)) {
179 'request' => $request,
180 'slimRequest' => $slimRequest,
182 foreach ($usersIterator as $user) {
183 $items[] =
Services::get(
'user')->getReviewerSummaryProperties($user, $propertyArgs);
188 'itemsMax' =>
Services::get(
'user')->getReviewersMax($params),
192 return $response->withJson($data, 200);
203 private function _processAllowedparams($params, $allowedKeys) {
211 $requestParams = array_merge($defaultParams, $params);
215 foreach ($requestParams as $param => $val) {
216 if (!in_array($param, $allowedKeys)) {
221 if (in_array($val, [
'id',
'familyName',
'givenName'])) {
222 $returnParams[$param] = $val;
226 case 'orderDirection':
227 $returnParams[$param] = $val ===
'ASC' ? $val :
'DESC';
231 if (in_array($val, [
'all',
'active',
'disabled'])) {
232 $returnParams[$param] = $val;
238 if (is_string($val) && strpos($val,
',') > -1) {
239 $val = explode(
',', $val);
240 } elseif (!is_array($val)) {
243 $returnParams[$param] = array_map(
'intval', $val);
245 case 'assignedToCategory':
246 case 'assignedToSection':
247 case 'assignedToSubmissionStage':
248 case 'assignedToSubmission':
249 case 'reviewerRating':
252 $returnParams[$param] = (int) $val;
256 $returnParams[$param] = trim($val);
259 case 'reviewsCompleted':
260 case 'reviewsActive':
261 case 'daysSinceLastAssignment':
262 case 'averageCompletion':
263 if (is_array($val)) {
264 $val = array_map(
'intval', $val);
265 } elseif (strpos($val,
'-') !==
false) {
266 $val = array_map(
'intval', explode(
'-', $val));
270 $returnParams[$param] = $val;
275 $returnParams[$param] = min(100, (
int) $val);
280 return $returnParams;