Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
29 / 29 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| AppointmentFormButtons | |
100.00% |
29 / 29 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
| readResponse | |
100.00% |
26 / 26 |
|
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 | |
| 8 | namespace BO\Zmsadmin; |
| 9 | |
| 10 | use BO\Slim\Render; |
| 11 | use BO\Zmsentities\Appointment; |
| 12 | |
| 13 | class 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 | $selectedTime = $validator->getParameter('selectedtime')->isString()->getValue(); |
| 32 | $selectedProcessId = $validator->getParameter('selectedprocess')->isNumber()->getValue(); |
| 33 | $selectedProcess = ($selectedProcessId) ? |
| 34 | \App::$http->readGetResult('/process/' . $selectedProcessId . '/')->getEntity() : null; |
| 35 | |
| 36 | $isNewAppointment = $this->isNewAppointment( |
| 37 | $selectedProcess, |
| 38 | $selectedDate, |
| 39 | str_replace('-', ':', $selectedTime === null ? '' : $selectedTime) |
| 40 | ); |
| 41 | |
| 42 | return Render::withHtml( |
| 43 | $response, |
| 44 | 'block/appointment/formButtons.twig', |
| 45 | array( |
| 46 | 'workstation' => $workstation, |
| 47 | 'selectedProcess' => $selectedProcess, |
| 48 | 'selectedTime' => $selectedTime = ($selectedTime) ? $selectedTime : '00-00', |
| 49 | 'selectedDate' => ($selectedDate) ? $selectedDate : \App::$now->format('Y-m-d'), |
| 50 | 'isNewAppointment' => $isNewAppointment |
| 51 | ) |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | protected function isNewAppointment($process, $selectedDate, $selectedTime) |
| 56 | { |
| 57 | $selectedAppointment = new Appointment(); |
| 58 | $selectedAppointment->setTime($selectedDate . ' ' . $selectedTime); |
| 59 | return ($process) ? ($process->getFirstAppointment()->date != $selectedAppointment->date) : false; |
| 60 | } |
| 61 | } |