Lines 46.00% 23 / 50
Functions and Methods 0.00% 0 / 1
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
WorkstationProcessRedirect 46.00% 23 / 50 0.00% 0 / 1 8.94 0.00% 0 / 1
 readResponse 46.00% 23 / 50 0.00% 0 / 1 8.94
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            if (empty($workstation->process) || !$workstation->process->hasId()) {
36                return Render::redirect('workstation', [], []);
37            }
38
39            $validator = $request->getAttribute('validator');
40            $selectedLocation = $validator->getParameter('location')->isNumber()->getValue();
41
42            if (empty($selectedLocation)) {
43                return Render::redirect(
44                    'workstationProcessRedirect',
45                    [],
46                    [
47                        'errors' => [
48                            'location' => 'Bitte wählen Sie einen Standort aus.'
49                        ]
50                    ]
51                );
52            }
53
54            $scope = \App::$http
55                ->readGetResult(
56                    '/scope/' . $selectedLocation . '/',
57                    ['resolveReferences' => 2]
58                )->getEntity();
59
60            $newProcess = clone $workstation->process;
61            $newProcess->scope = $scope;
62            $newProcess->appointments[0]->scope = $scope;
63            $newProcess->amendment = ProcessPlainText::normalize($input['amendment'] ?? '');
64
65            \App::$http->readPostResult('/process/status/redirect/', $newProcess)->getEntity();
66
67            return Render::redirect(
68                $workstation->getVariantName(),
69                array(),
70                array()
71            );
72        }
73
74        return Render::withHtml(
75            $response,
76            'page/workstationProcessRedirect.twig',
77            array(
78                'title' => 'Kundendaten',
79                'workstation' => $workstation,
80                'department' => $department,
81                'scope' => $workstation->scope,
82                'scopes' => $department->getScopeList(),
83                'menuActive' => 'workstation',
84                'errors' => $request->getParam('errors') ?? null
85            )
86        );
87    }
88}