Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.24% covered (success)
95.24%
40 / 42
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
TicketprinterConfig
95.24% covered (success)
95.24%
40 / 42
0.00% covered (danger)
0.00%
0 / 1
7
0.00% covered (danger)
0.00%
0 / 1
 readResponse
95.24% covered (success)
95.24%
40 / 42
0.00% covered (danger)
0.00%
0 / 1
7
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Mellon\Validator;
11use BO\Zmsdb\Request;
12use BO\Zmsentities\Collection\RequestList;
13use BO\Zmsentities\Department as DepartmentEntity;
14use BO\Zmsentities\Collection\DepartmentList;
15
16class TicketprinterConfig extends BaseController
17{
18    /**
19     * @SuppressWarnings(Param)
20     * @return \Psr\Http\Message\ResponseInterface
21     */
22    #[\Override]
23    public function readResponse(
24        \Psr\Http\Message\RequestInterface $request,
25        \Psr\Http\Message\ResponseInterface $response,
26        array $args
27    ): \Psr\Http\Message\ResponseInterface {
28        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity();
29        if (!$workstation->getUseraccount()->hasPermissions(['ticketprinter'])) {
30            throw new \BO\Zmsentities\Exception\UserAccountMissingRights();
31        }
32        $scopeId = Validator::value($workstation['scope']['id'])->isNumber()->getValue();
33        $config = \App::$http->readGetResult('/config/')->getEntity();
34        $organisation = \App::$http->readGetResult(
35            '/scope/' . $scopeId . '/organisation/',
36            ['resolveReferences' => 5]
37        )->getEntity();
38
39        $source = \App::$http->readGetResult(
40            '/source/',
41            ['resolveReferences' => 2]
42        )->getEntity();
43        $requestList = (new RequestList())->addData($source->requests);
44
45        $departments = new DepartmentList();
46
47        foreach ($organisation->departments as $departmentData) {
48            $department = (new DepartmentEntity($departmentData))->withCompleteScopeList();
49            foreach ($department->scopes as $scope) {
50                $scope->services = [];
51
52                if (! isset($scope->provider->data)) {
53                    continue;
54                }
55
56                foreach ($scope->provider->data['services'] as $serviceArray) {
57                    $service = $requestList->getEntity($serviceArray['service']);
58
59                    if (! $service) {
60                        continue;
61                    }
62
63                    $scope->services[] = [
64                        'id' => $scope->id . '-' . $service->id,
65                        'name' => $service->name
66                    ];
67                }
68            }
69            $departments->addEntity($department);
70        }
71        return \BO\Slim\Render::withHtml(
72            $response,
73            'page/ticketprinterConfig.twig',
74            array(
75                'title' => 'Anmeldung an Warteschlange',
76                'config' => $config->getArrayCopy(),
77                'organisation' => $organisation->getArrayCopy(),
78                'departments' => $departments->getArrayCopy(),
79                'workstation' => $workstation,
80                'menuActive' => 'ticketprinter'
81            )
82        );
83    }
84}