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