Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 48
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
WorkstationProcessRedirect
0.00% covered (danger)
0.00%
0 / 48
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 readResponse
0.00% covered (danger)
0.00%
0 / 48
0.00% covered (danger)
0.00%
0 / 1
12
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\Helper\ProcessPlainText;
12use Psr\Http\Message\RequestInterface;
13
14class WorkstationProcessRedirect extends BaseController
15{
16    /**
17     * @SuppressWarnings(Param)
18     * @return \Psr\Http\Message\ResponseInterface
19     */
20    #[\Override]
21    public function readResponse(
22        RequestInterface $request,
23        \Psr\Http\Message\ResponseInterface $response,
24        array $args
25    ): \Psr\Http\Message\ResponseInterface {
26        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity();
27        $department = \App::$http
28            ->readGetResult(
29                '/scope/' . $workstation->scope['id'] . '/department/',
30                ['resolveReferences' => 2]
31            )->getEntity();
32        $input = $request->getParsedBody();
33
34        if ($request->getMethod() === 'POST') {
35            $validator = $request->getAttribute('validator');
36            $selectedLocation = $validator->getParameter('location')->isNumber()->getValue();
37
38            if (empty($selectedLocation)) {
39                return Render::redirect(
40                    'workstationProcessRedirect',
41                    [],
42                    [
43                        'errors' => [
44                            'location' => 'Bitte wählen Sie einen Standort aus.'
45                        ]
46                    ]
47                );
48            }
49
50            $scope = \App::$http
51                ->readGetResult(
52                    '/scope/' . $selectedLocation . '/',
53                    ['resolveReferences' => 2]
54                )->getEntity();
55
56            $newProcess = clone $workstation->process;
57            $newProcess->scope = $scope;
58            $newProcess->appointments[0]->scope = $scope;
59            $newProcess->amendment = ProcessPlainText::normalize($input['amendment'] ?? '');
60
61            \App::$http->readPostResult('/process/status/redirect/', $newProcess)->getEntity();
62
63            return Render::redirect(
64                $workstation->getVariantName(),
65                array(),
66                array()
67            );
68        }
69
70        return Render::withHtml(
71            $response,
72            'page/workstationProcessRedirect.twig',
73            array(
74                'title' => 'Kundendaten',
75                'workstation' => $workstation,
76                'department' => $department,
77                'scope' => $workstation->scope,
78                'scopes' => $department->getScopeList(),
79                'menuActive' => 'workstation',
80                'errors' => $request->getParam('errors') ?? null
81            )
82        );
83    }
84}