Lines 100.00% 34 / 34
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
Counter 100.00% 34 / 34 100.00% 2 / 2 7 100.00% 1 / 1
 readResponse 100.00% 28 / 28 100.00% 1 / 1 4
 getSelectedDate 100.00% 6 / 6 100.00% 1 / 1 3
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10class Counter extends BaseController
11{
12    /**
13     * @SuppressWarnings(Param)
14     * @return \Psr\Http\Message\ResponseInterface
15     */
16    #[\Override]
17    public function readResponse(
18        \Psr\Http\Message\RequestInterface $request,
19        \Psr\Http\Message\ResponseInterface $response,
20        array $args
21    ): \Psr\Http\Message\ResponseInterface {
22        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity();
23        $validator = $request->getAttribute('validator');
24        $selectedTime = $validator->getParameter('time')->isString()->getValue();
25        $selectedTime = ($selectedTime) ? $selectedTime : null;
26        $selectedProcess = $validator->getParameter('selectedprocess')->isNumber()->getValue();
27        $selectedScope = $validator->getParameter('selectedscope')->isNumber()->getValue();
28
29        if (!$workstation->hasId()) {
30            return \BO\Slim\Render::redirect(
31                'index',
32                array(
33                    'error' => 'login_failed'
34                )
35            );
36        }
37
38        if (!$workstation->getScope()->hasId()) {
39            return \BO\Slim\Render::redirect('workstationSelect', [], []);
40        }
41
42        $workstation->getUseraccount()->testPermissions(['counter']);
43
44        return \BO\Slim\Render::withHtml(
45            $response,
46            'page/counter.twig',
47            array(
48                'title' => 'Tresen',
49                'menuActive' => 'counter',
50                'selectedDate' => $this->getSelectedDate($validator),
51                'selectedTime' => $selectedTime,
52                'selectedProcess' => $selectedProcess,
53                'selectedScope' => $selectedScope,
54                'workstation' => $workstation->getArrayCopy()            )
55        );
56    }
57
58    protected function getSelectedDate(\BO\Mellon\Validator $validator)
59    {
60        $selectedDate = $validator->getParameter('date')->isString()->getValue();
61        $selectedDateTime = $selectedDate ?
62            (new \DateTimeImmutable($selectedDate))->setTime(\App::$now->format('H'), \App::$now->format('i')) :
63            \App::$now;
64        $selectedDate = ($selectedDateTime < \App::$now) ? \App::$now : $selectedDateTime;
65        return $selectedDate->format('Y-m-d');
66    }
67}