Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
UseraccountListByDepartments
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsapi;
9
10use BO\Mellon\Validator;
11use BO\Slim\Render;
12use BO\Zmsdb\Useraccount;
13use Psr\Http\Message\RequestInterface;
14use Psr\Http\Message\ResponseInterface;
15
16class UseraccountListByDepartments extends BaseController
17{
18    /**
19     * @SuppressWarnings(Param)
20     * @return String
21     */
22    public function readResponse(
23        RequestInterface $request,
24        ResponseInterface $response,
25        array $args
26    ) {
27        $workstation = (new Helper\User($request, 1))->checkRights('useraccount');
28        $parameters = $request->getParams();
29
30        $rawIds = array_map('trim', explode(',', $args['ids']));
31        $rawIds = array_filter($rawIds, 'strlen');
32        $requestedDepartmentIds = Helper\User::normalizeDepartmentIds($rawIds);
33
34        $departmentIds = [];
35        if ($workstation->getUseraccount()->isSuperUser()) {
36            // Superusers can access all departments; no need to validate via DB here
37            $departmentIds = $requestedDepartmentIds;
38        } else {
39            // Non-superusers must go through Helper\User::checkDepartments for access checks
40            $departments = Helper\User::checkDepartments($requestedDepartmentIds);
41            foreach ($departments as $department) {
42                $departmentIds[] = $department->id;
43            }
44        }
45
46        $useraccountList = (new Useraccount())->readSearchByDepartmentIds($departmentIds, $parameters, 0, $workstation);
47
48        $message = Response\Message::create($request);
49        $message->data = $useraccountList;
50
51        $response = Render::withLastModified($response, time(), '0');
52        $response = Render::withJson($response, $message, 200);
53
54        return $response;
55    }
56}