| Server IP : 195.134.90.114 / Your IP : 216.73.216.86 Web Server : Apache/2.4.58 System : Linux nepub 6.8.0-88-generic #89-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 01:02:46 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/public_html/lib/pkp/api/v1/stats/users/ |
Upload File : |
<?php
/**
* @file api/v1/stats/PKPStatsUserHandler.inc.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PKPStatsUserHandler
* @ingroup api_v1_stats
*
* @brief Handle API requests for publication statistics.
*
*/
import('lib.pkp.classes.handler.APIHandler');
import('classes.core.Services');
class PKPStatsUserHandler extends APIHandler {
/**
* Constructor
*/
public function __construct() {
$this->_handlerPath = 'stats/users';
$this->_endpoints = [
'GET' => [
[
'pattern' => $this->getEndpointPattern(),
'handler' => [$this, 'get'],
'roles' => [ROLE_ID_SITE_ADMIN, ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR],
],
],
];
parent::__construct();
}
/**
* @copydoc PKPHandler::authorize()
*/
function authorize($request, &$args, $roleAssignments) {
import('lib.pkp.classes.security.authorization.ContextAccessPolicy');
$this->addPolicy(new ContextAccessPolicy($request, $roleAssignments));
import('lib.pkp.classes.security.authorization.PolicySet');
$rolePolicy = new PolicySet(COMBINING_PERMIT_OVERRIDES);
import('lib.pkp.classes.security.authorization.RoleBasedHandlerOperationPolicy');
foreach ($roleAssignments as $role => $operations) {
$rolePolicy->addPolicy(new RoleBasedHandlerOperationPolicy($request, $role, $operations));
}
$this->addPolicy($rolePolicy);
return parent::authorize($request, $args, $roleAssignments);
}
/**
* Get user stats
*
* Returns the count of users broken down by roles
*
* @param $slimRequest Request Slim request object
* @param $response object Response
* @param $args array
* @return object Response
*/
public function get($slimRequest, $response, $args) {
$request = $this->getRequest();
if (!$request->getContext()) {
return $response->withStatus(404)->withJsonError('api.404.resourceNotFound');
}
$defaultParams = [
'status' => 'active'
];
$params = [];
foreach ($slimRequest->getQueryParams() as $param => $value) {
switch ($param) {
case 'registeredAfter':
case 'registeredBefore':
$params[$param] = $value;
break;
case 'status':
$params[$param] = $value === 'disabled' ? $value : 'active';
break;
}
}
$params = array_merge($defaultParams, $params);
\HookRegistry::call('API::stats::users::params', array(&$params, $slimRequest));
$params['contextId'] = [$request->getContext()->getId()];
$result = $this->_validateStatDates($params, 'registeredAfter', 'registeredBefore');
if ($result !== true) {
return $response->withStatus(400)->withJsonError($result);
}
return $response->withJson(array_map(
function ($item) {
$item['name'] = __($item['name']);
return $item;
},
Services::get('user')->getRolesOverview($params)
));
}
}