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 String
19     */
20    public function readResponse(
21        \Psr\Http\Message\RequestInterface $request,
22        \Psr\Http\Message\ResponseInterface $response,
23        array $args
24    ) {
25        $validator = $request->getAttribute('validator');
26        $workstation = \App::$http->readGetResult('/workstation/', [
27            'resolveReferences' => 2,
28            'gql' => Helper\GraphDefaults::getWorkstationWithProvider(),
29        ])->getEntity();
30        $selectedProcess = Helper\AppointmentFormHelper::readSelectedProcess($request);
31        if ($selectedProcess && ! $workstation->hasSuperUseraccount()) {
32            $workstation
33                ->validateProcessScopeAccess((new Helper\ClusterHelper($workstation))->getScopeList(), $selectedProcess);
34        }
35
36        $selectedDate = ($selectedProcess && $selectedProcess->hasId())
37            ? $selectedProcess->getFirstAppointment()->toDateTime()->format('Y-m-d')
38            : $validator->getParameter('selecteddate')->isString()->getValue();
39
40        $selectedTime = ($selectedProcess && $selectedProcess->hasId())
41            ? $selectedProcess->getFirstAppointment()->getStartTime()->format('H-i')
42            : $validator->getParameter('selectedtime')->isString()->getValue();
43
44        $selectedScope = Helper\AppointmentFormHelper::readSelectedScope($request, $workstation, $selectedProcess, 2);
45        $requestList = ($selectedScope && $selectedScope->hasId())
46            ? Helper\AppointmentFormHelper::readRequestList($request, $workstation, $selectedScope)
47            : null;
48
49        $freeProcessList = ($selectedScope)
50            ? Helper\AppointmentFormHelper::readFreeProcessList($request, $workstation, 2)
51            : null;
52
53        $slotTimeInMinutes = null;
54        if ($selectedProcess && $selectedProcess->hasId()) {
55            $slotTimeInMinutes = $selectedProcess->getAppointments()->getFirst()->getAvailability()['slotTimeInMinutes'];
56        } elseif ($selectedScope) {
57            $provider = $selectedScope->getProvider();
58            $slotTimeInMinutes = $provider->getSlotTimeInMinutes();
59        }
60
61        $selectedRequestCounts = [];
62
63        if ($selectedProcess && $selectedProcess->requests) {
64            foreach ($selectedProcess->requests as $request) {
65                if (! isset($selectedRequestCounts[$request->id])) {
66                    $selectedRequestCounts[$request->id] = 0;
67                }
68
69                $selectedRequestCounts[$request->id]++;
70            }
71        }
72
73        $requestsByCount = [];
74        if ($requestList) {
75            foreach ($requestList as $request) {
76                if (! isset($requestsByCount[$request->id])) {
77                    $requestsByCount[$request->id] = [
78                        'count' => $selectedRequestCounts[$request->id] ?? 1,
79                        'request' => $request
80                    ];
81                }
82            }
83        }
84
85        return \BO\Slim\Render::withHtml(
86            $response,
87            'block/appointment/form.twig',
88            array(
89                'workstation' => $workstation,
90                'scope' => $selectedScope,
91                'cluster' => (new Helper\ClusterHelper($workstation, $selectedScope))->getEntity(),
92                'department' =>
93                    \App::$http->readGetResult('/scope/' . $workstation->scope['id'] . '/department/', [
94                        'gql' => Helper\GraphDefaults::getDepartment()
95                    ])->getEntity(),
96                'selectedProcess' => $selectedProcess,
97                'selectedDate' => ($selectedDate) ? $selectedDate : \App::$now->format('Y-m-d'),
98                'selectedTime' => $selectedTime,
99                'freeProcessList' => $freeProcessList,
100                'requestList' => $requestList,
101                'requestsByCount' => $requestsByCount,
102                'slotTimeInMinutes' => $slotTimeInMinutes,
103            )
104        );
105    }
106}