Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
78.95% covered (warning)
78.95%
30 / 38
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
WorkstationProcessCalled
78.95% covered (warning)
78.95%
30 / 38
0.00% covered (danger)
0.00%
0 / 1
9.76
0.00% covered (danger)
0.00%
0 / 1
 readResponse
78.95% covered (warning)
78.95%
30 / 38
0.00% covered (danger)
0.00%
0 / 1
9.76
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Mellon\Validator;
11use BO\Zmsadmin\Helper\ExcludeIds;
12
13class WorkstationProcessCalled extends BaseController
14{
15    /**
16     * @return \Psr\Http\Message\ResponseInterface
17     */
18    #[\Override]
19    public function readResponse(
20        \Psr\Http\Message\RequestInterface $request,
21        \Psr\Http\Message\ResponseInterface $response,
22        array $args
23    ): \Psr\Http\Message\ResponseInterface {
24        $validator = $request->getAttribute('validator');
25        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity();
26        $processId = Validator::value($args['id'])->isNumber()->getValue();
27        if (! $workstation->process->hasId() && ! $workstation->process->queue->callTime) {
28            $process = \App::$http->readGetResult('/process/' . $args['id'] . '/')->getEntity();
29            try {
30                $workstation = \App::$http->readPostResult('/workstation/process/called/', $process, [
31                    'allowClusterWideCall' => \App::$allowClusterWideCall
32                ])->getEntity();
33            } catch (\BO\Zmsclient\Exception $e) {
34                if ($e->template === 'BO\\Zmsbackend\\Process\\Exception\\ProcessAlreadyCalled') {
35                    return \BO\Slim\Render::redirect(
36                        'workstationProcessCalled',
37                        ['id' => $processId],
38                        ['error' => 'has_called_process']
39                    );
40                }
41
42                throw $e;
43            }
44        }
45
46        $excludedIds = ExcludeIds::fromQuery(
47            $validator->getParameter('exclude')->isString()->setDefault('')->getValue()
48        );
49        $excludedIds[] = $workstation->process->toQueue(\App::$now)->number;
50
51        $error = $validator->getParameter('error')->isString()->getValue();
52        if (isset($processId) && $workstation->process->getId() != $processId) {
53            $error = 'has_called_process';
54        }
55
56        if ($workstation->process->getStatus() == 'processing') {
57            return \BO\Slim\Render::redirect('workstationProcessProcessing', [], ['error' => $error]);
58        }
59
60        // Check if $process is set or assign a default value (like null)
61        $process = isset($process) ? $process : null;
62
63        return \BO\Slim\Render::withHtml(
64            $response,
65            'block/process/called.twig',
66            array(
67                'title' => 'Sachbearbeiter',
68                'workstation' => $workstation,
69                'menuActive' => 'workstation',
70                'process' => $process,
71                'exclude' => ExcludeIds::toQuery($excludedIds),
72                'error' => $error
73            )
74        );
75    }
76}