Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
47 / 47 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
WorkstationProcessFinished | |
100.00% |
47 / 47 |
|
100.00% |
3 / 3 |
13 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
37 / 37 |
|
100.00% |
1 / 1 |
8 | |||
getFinishedResponse | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
testProcess | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * @package Zmsadmin |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsadmin; |
9 | |
10 | use Psr\Http\Message\RequestInterface; |
11 | use BO\Zmsadmin\Helper\ProcessFinishedHelper; |
12 | use BO\Zmsentities\Process as Entity; |
13 | use BO\Zmsentities\Collection\RequestList; |
14 | |
15 | class 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 | $department = \App::$http |
28 | ->readGetResult( |
29 | '/scope/' . $workstation->scope['id'] . '/department/', |
30 | ['resolveReferences' => 2] |
31 | )->getEntity(); |
32 | $this->testProcess($workstation); |
33 | $input = $request->getParsedBody(); |
34 | $statisticEnabled = $workstation->getScope()->getPreference('queue', 'statisticsEnabled'); |
35 | $isDefaultPickup = $workstation->getScope()->getPreference('pickup', 'isDefault'); |
36 | |
37 | if (! $statisticEnabled && ! $isDefaultPickup) { |
38 | $workstation->process['status'] = 'finished'; |
39 | return $this->getFinishedResponse($workstation); |
40 | } |
41 | |
42 | $scopeId = $workstation->scope['id']; |
43 | if (! empty($workstation->process)) { |
44 | $scopeId = $workstation->process->scope->id; |
45 | } |
46 | |
47 | $requestList = \App::$http |
48 | ->readGetResult('/scope/' . $scopeId . '/request/') |
49 | ->getCollection(); |
50 | $requestList = $requestList ? $requestList : new RequestList(); |
51 | |
52 | if (is_array($input) && isset($input['process']) && array_key_exists('id', $input['process'])) { |
53 | $source = $workstation->getScope()->getSource(); |
54 | $process = new ProcessFinishedHelper(clone $workstation->process, $input, $requestList, $source); |
55 | return $this->getFinishedResponse($workstation, $process); |
56 | } |
57 | |
58 | return \BO\Slim\Render::withHtml( |
59 | $response, |
60 | 'page/workstationProcessFinished.twig', |
61 | array( |
62 | 'title' => 'Kundendaten', |
63 | 'workstation' => $workstation, |
64 | 'pickupList' => $department->getScopeList(), |
65 | 'requestList' => $requestList->toSortedByGroup(), |
66 | 'menuActive' => 'workstation', |
67 | 'statisticEnabled' => $statisticEnabled, |
68 | 'isDefaultPickup' => $isDefaultPickup |
69 | ) |
70 | ); |
71 | } |
72 | |
73 | protected function getFinishedResponse( |
74 | \BO\Zmsentities\Workstation $workstation, |
75 | Entity $process = null |
76 | ) { |
77 | $process = ($process) ? $process : clone $workstation->process; |
78 | $process->status = ('pending' != $process->status) ? 'finished' : $process->status; |
79 | \App::$http->readPostResult('/process/status/finished/', new Entity($process))->getEntity(); |
80 | return \BO\Slim\Render::redirect( |
81 | $workstation->getVariantName(), |
82 | array(), |
83 | array() |
84 | ); |
85 | } |
86 | |
87 | |
88 | protected function testProcess(\BO\Zmsentities\Workstation $workstation) |
89 | { |
90 | if (! $workstation->process->hasId()) { |
91 | throw new \BO\Zmsentities\Exception\WorkstationMissingAssignedProcess(); |
92 | } |
93 | } |
94 | } |