Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
WorkstationProcessFinished
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
3 / 3
12
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
7
 getFinishedResponse
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
 testProcess
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
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 Psr\Http\Message\RequestInterface;
12use BO\Zmsadmin\Helper\ProcessFinishedHelper;
13use BO\Zmsentities\Exception\WorkstationMissingAssignedProcess;
14use BO\Zmsentities\Process;
15use BO\Zmsentities\Collection\RequestList;
16use BO\Zmsentities\Workstation;
17
18class WorkstationProcessFinished extends BaseController
19{
20    /**
21     * @SuppressWarnings(Param)
22     * @return \Psr\Http\Message\ResponseInterface
23     */
24    #[\Override]
25    public function readResponse(
26        RequestInterface $request,
27        \Psr\Http\Message\ResponseInterface $response,
28        array $args
29    ): \Psr\Http\Message\ResponseInterface {
30        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity();
31        $this->testProcess($workstation);
32        $input = $request->getParsedBody();
33        $statisticEnabled = $workstation->getScope()->getPreference('queue', 'statisticsEnabled');
34
35        if (! $statisticEnabled) {
36            $workstation->process['status'] = 'finished';
37            return $this->getFinishedResponse($workstation);
38        }
39
40        $scopeId = $workstation->scope['id'];
41        if (! empty($workstation->process)) {
42            $scopeId = $workstation->process->scope->id;
43        }
44
45        $requestList = \App::$http
46            ->readGetResult('/scope/' . $scopeId . '/request/')
47            ->getCollection();
48        $requestList = $requestList ? $requestList : new RequestList();
49
50        if (is_array($input) && isset($input['process']) && array_key_exists('id', $input['process'])) {
51            $source = $workstation->getScope()->getSource();
52            $process = new ProcessFinishedHelper(clone $workstation->process, $input, $requestList, $source);
53            return $this->getFinishedResponse($workstation, $process);
54        }
55
56        return Render::withHtml(
57            $response,
58            'page/workstationProcessFinished.twig',
59            array(
60                'title' => 'Kundendaten',
61                'workstation' => $workstation,
62                'requestList' => $requestList->toSortedByGroup(),
63                'menuActive' => 'workstation',
64                'statisticEnabled' => $statisticEnabled
65            )
66        );
67    }
68
69    protected function getFinishedResponse(
70        Workstation $workstation,
71        Process $process = null
72    ) {
73        $process = ($process) ? $process : clone $workstation->process;
74        $process->status = ('pending' != $process->status) ? 'finished' : $process->status;
75        \App::$http->readPostResult('/process/status/finished/', new Process($process))->getEntity();
76        return Render::redirect(
77            $workstation->getVariantName(),
78            array(),
79            array()
80        );
81    }
82
83
84    protected function testProcess(Workstation $workstation)
85    {
86        if (! $workstation->process->hasId()) {
87            throw new WorkstationMissingAssignedProcess();
88        }
89    }
90}