Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.94% covered (success)
93.94%
31 / 33
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
WorkstationSelect
93.94% covered (success)
93.94%
31 / 33
0.00% covered (danger)
0.00%
0 / 1
10.02
0.00% covered (danger)
0.00%
0 / 1
 readResponse
93.94% covered (success)
93.94%
31 / 33
0.00% covered (danger)
0.00%
0 / 1
10.02
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Zmsclient\ModuleAccess;
11use BO\Zmsadmin\Helper\LoginForm;
12use BO\Zmsadmin\Helper\RestrictedRoleRedirect;
13use BO\Mellon\Validator;
14
15class WorkstationSelect extends BaseController
16{
17    /**
18     * @SuppressWarnings(Parameter)
19     * @return \Psr\Http\Message\ResponseInterface
20     */
21    #[\Override]
22    public function readResponse(
23        \Psr\Http\Message\RequestInterface $request,
24        \Psr\Http\Message\ResponseInterface $response,
25        array $args
26    ): \Psr\Http\Message\ResponseInterface {
27        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity();
28        if (!$workstation->hasId()) {
29            return \BO\Slim\Render::redirect('index', array('error' => 'login_failed'));
30        }
31        if ($wrongModuleResponse = ModuleAccess::rejectWrongModuleAccess(ModuleAccess::MODULE_ADMIN, $workstation, $response)) {
32            return $wrongModuleResponse;
33        }
34
35        if ($restrictedRoleRedirect = RestrictedRoleRedirect::create($workstation->getUseraccount())) {
36            return $restrictedRoleRedirect;
37        }
38
39        $input = $request->getParsedBody();
40        $formData = [];
41        if (is_array($input) && (array_key_exists('scope', $input))) {
42            $form = LoginForm::fromAdditionalParameters();
43            $formData = $form->getStatus();
44            $selectedDate = Validator::param('selectedDate')->isString()->getValue();
45            $queryParams = ($selectedDate) ? array('date' => $selectedDate) : array();
46            $redirect = (array_key_exists('redirect', $input)) ? $input['redirect'] : null;
47            if (! $form->hasFailed()) {
48                LoginForm::writeWorkstationUpdate($form, $workstation);
49                return \BO\Slim\Render::redirect(
50                    ($redirect) ? $redirect : $workstation->getVariantName(),
51                    array(),
52                    $queryParams
53                );
54            }
55        }
56
57        return \BO\Slim\Render::withHtml(
58            $response,
59            'page/workstationSelect.twig',
60            array(
61                'title' => 'Standort und Arbeitsplatz auswählen',
62                'advancedData' => $formData,
63                'workstation' => $workstation,
64                'menuActive' => 'select',
65                'today' => \App::$now->format('Y-m-d')
66            )
67        );
68    }
69}