Lines 100.00% 20 / 20
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 readResponse 100.00% 17 / 17 100.00% 1 / 1 3
 [BO\Zmsbackend\Api\BaseController] __invoke 100.00% 3 / 3 100.00% 1 / 1 1
16class UseraccountListByDepartments extends \BO\Zmsbackend\Api\BaseController
17{
18    /**
19     * @SuppressWarnings(Param)
20     * @return \Psr\Http\Message\ResponseInterface
21     */
22    #[\Override]
23    public function readResponse(
24        RequestInterface $request,
25        ResponseInterface $response,
26        array $args
27    ) {
28        $workstation = (new \BO\Zmsbackend\Helper\User($request, 1))->checkPermissions('useraccount');
29        $parameters = $request->getParams();
30
31        $rawIds = array_map('trim', explode(',', $args['ids']));
32        $rawIds = array_filter($rawIds, 'strlen');
33        $requestedDepartmentIds = \BO\Zmsbackend\Helper\User::normalizeDepartmentIds($rawIds);
34
35        $departmentIds = [];
36        if ($workstation->getUseraccount()->isSuperUser()) {
37            // Superusers can access all departments; no need to validate via DB here
38            $departmentIds = $requestedDepartmentIds;
39        } else {
40            // Non-superusers must go through \BO\Zmsbackend\Helper\User::checkDepartments for access checks
41            $departments = \BO\Zmsbackend\Helper\User::checkDepartments($requestedDepartmentIds);
42            foreach ($departments as $department) {
43                $departmentIds[] = $department->id;
44            }
45        }
46
47        $useraccountList = (new \BO\Zmsbackend\Useraccount\Service\Useraccount())->readSearchByDepartmentIds($departmentIds, $parameters, 0, $workstation);
48
49        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
50        $message->data = $useraccountList;
51
52        $response = Render::withLastModified($response, time(), '0');
53        $response = Render::withJson($response, $message, 200);
54
55        return $response;
56    }
57}

Inherited from BO\Zmsbackend\Api\BaseController

20    public function __invoke(RequestInterface $request, ResponseInterface $response, array $args)
21    {
22        $request = $this->initRequest($request);
23        $noCacheResponse = \BO\Slim\Render::withLastModified($response, time(), '0');
24        return $this->readResponse($request, $noCacheResponse, $args);
25    }