Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
62 / 62
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AppointmentForm
100.00% covered (success)
100.00%
62 / 62
100.00% covered (success)
100.00%
1 / 1
21
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
62 / 62
100.00% covered (success)
100.00%
1 / 1
21
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Zmsentities\Scope;
11
12class AppointmentForm extends BaseController
13{
14    /**
15     * @SuppressWarnings(Param)
16     * @SuppressWarnings(Cyclomatic)
17     * @SuppressWarnings(Complexity)
18     * @return \Psr\Http\Message\ResponseInterface
19     */
20    #[\Override]
21    public function readResponse(
22        \Psr\Http\Message\RequestInterface $request,
23        \Psr\Http\Message\ResponseInterface $response,
24        array $args
25    ): \Psr\Http\Message\ResponseInterface {
26        $validator = $request->getAttribute('validator');
27        $workstation = \App::$http->readGetResult('/workstation/', [
28            'resolveReferences' => 2,
29            'gql' => Helper\GraphDefaults::getWorkstationWithProvider(),
30        ])->getEntity();
31        $selectedProcess = Helper\AppointmentFormHelper::readSelectedProcess($request);
32        if ($selectedProcess && ! $workstation->hasSuperUseraccount()) {
33            $workstation
34                ->validateProcessScopeAccess((new Helper\ClusterHelper($workstation))->getScopeList(), $selectedProcess);
35        }
36
37        $selectedDate = ($selectedProcess && $selectedProcess->hasId())
38            ? $selectedProcess->getFirstAppointment()->toDateTime()->format('Y-m-d')
39            : $validator->getParameter('selecteddate')->isString()->getValue();
40
41        $selectedTime = ($selectedProcess && $selectedProcess->hasId())
42            ? $selectedProcess->getFirstAppointment()->getStartTime()->format('H-i')
43            : $validator->getParameter('selectedtime')->isString()->getValue();
44
45        $selectedScope = Helper\AppointmentFormHelper::readSelectedScope($request, $workstation, $selectedProcess, 2);
46        $requestList = ($selectedScope && $selectedScope->hasId())
47            ? Helper\AppointmentFormHelper::readRequestList($request, $workstation, $selectedScope)
48            : null;
49
50        $freeProcessList = ($selectedScope)
51            ? Helper\AppointmentFormHelper::readFreeProcessList($request, $workstation, 2)
52            : null;
53
54        $slotTimeInMinutes = null;
55        if ($selectedProcess && $selectedProcess->hasId()) {
56            $slotTimeInMinutes = $selectedProcess->getAppointments()->getFirst()->getAvailability()['slotTimeInMinutes'];
57        } elseif ($selectedScope) {
58            $provider = $selectedScope->getProvider();
59            $slotTimeInMinutes = $provider->getSlotTimeInMinutes();
60        }
61
62        $selectedRequestCounts = [];
63
64        if ($selectedProcess && $selectedProcess->requests) {
65            foreach ($selectedProcess->requests as $request) {
66                if (! isset($selectedRequestCounts[$request->id])) {
67                    $selectedRequestCounts[$request->id] = 0;
68                }
69
70                $selectedRequestCounts[$request->id]++;
71            }
72        }
73
74        $requestsByCount = [];
75        if ($requestList) {
76            foreach ($requestList as $request) {
77                if (! isset($requestsByCount[$request->id])) {
78                    $requestsByCount[$request->id] = [
79                        'count' => $selectedRequestCounts[$request->id] ?? 1,
80                        'request' => $request
81                    ];
82                }
83            }
84        }
85
86        return \BO\Slim\Render::withHtml(
87            $response,
88            'block/appointment/form.twig',
89            array(
90                'workstation' => $workstation,
91                'scope' => $selectedScope,
92                'cluster' => (new Helper\ClusterHelper($workstation, $selectedScope))->getEntity(),
93                'department' =>
94                    \App::$http->readGetResult('/scope/' . $workstation->scope['id'] . '/department/', [
95                        'gql' => Helper\GraphDefaults::getDepartment()
96                    ])->getEntity(),
97                'selectedProcess' => $selectedProcess,
98                'selectedDate' => ($selectedDate) ? $selectedDate : \App::$now->format('Y-m-d'),
99                'selectedTime' => $selectedTime,
100                'freeProcessList' => $freeProcessList,
101                'requestList' => $requestList,
102                'requestsByCount' => $requestsByCount,
103                'slotTimeInMinutes' => $slotTimeInMinutes,
104            )
105        );
106    }
107}