Lines 100.00% 30 / 30
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
AppointmentFormButtons 100.00% 30 / 30 100.00% 2 / 2 7 100.00% 1 / 1
 readResponse 100.00% 27 / 27 100.00% 1 / 1 5
 isNewAppointment 100.00% 3 / 3 100.00% 1 / 1 2
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Slim\Render;
11use BO\Zmsentities\Appointment;
12
13class AppointmentFormButtons extends BaseController
14{
15    /**
16     * @SuppressWarnings(Param)
17     * @return \Psr\Http\Message\ResponseInterface
18     */
19    #[\Override]
20    public function readResponse(
21        \Psr\Http\Message\RequestInterface $request,
22        \Psr\Http\Message\ResponseInterface $response,
23        array $args
24    ): \Psr\Http\Message\ResponseInterface {
25        $workstation = \App::$http->readGetResult('/workstation/', [
26            'resolveReferences' => 2,
27            'gql' => Helper\GraphDefaults::getWorkstation()
28        ])->getEntity();
29        $validator = $request->getAttribute('validator');
30        $selectedDate = $validator->getParameter('selecteddate')->isString()->getValue();
31        $selectedDate = $selectedDate ?: \App::$now->format('Y-m-d');
32        $selectedTime = $validator->getParameter('selectedtime')->isString()->getValue();
33        $selectedProcessId = $validator->getParameter('selectedprocess')->isNumber()->getValue();
34        $selectedProcess = ($selectedProcessId) ?
35            \App::$http->readGetResult('/process/' . $selectedProcessId . '/')->getEntity() : null;
36
37        $isNewAppointment = $this->isNewAppointment(
38            $selectedProcess,
39            $selectedDate,
40            str_replace('-', ':', $selectedTime === null ? '' : $selectedTime)
41        );
42
43        return Render::withHtml(
44            $response,
45            'block/appointment/formButtons.twig',
46            array(
47                'workstation' => $workstation,
48                'selectedProcess' => $selectedProcess,
49                'selectedTime' => $selectedTime = ($selectedTime) ? $selectedTime : '00-00',
50                'selectedDate' => $selectedDate,
51                'isNewAppointment' => $isNewAppointment
52            )
53        );
54    }
55
56    protected function isNewAppointment(?\BO\Zmsentities\Process $process, string $selectedDate, string $selectedTime): bool
57    {
58        $selectedAppointment = new Appointment();
59        $selectedAppointment->setTime($selectedDate . ' ' . $selectedTime);
60        return ($process) ? ($process->getFirstAppointment()->date != $selectedAppointment->date) : false;
61    }
62}