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                ->testMatchingProcessScope((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
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}