Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
61.76% covered (warning)
61.76%
21 / 34
20.00% covered (danger)
20.00%
1 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
CalldisplayQueue
61.76% covered (warning)
61.76%
21 / 34
20.00% covered (danger)
20.00%
1 / 5
15.59
0.00% covered (danger)
0.00%
0 / 1
 readResponse
92.31% covered (success)
92.31%
12 / 13
0.00% covered (danger)
0.00%
0 / 1
2.00
 readCalculatedQueueListFromScope
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
2.02
 readFullQueueList
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 readQueueListFromScopeAndStatus
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 readQueueListByStatus
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsbackend\Calldisplay\Api;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsbackend\Calldisplay\Helper\CalldisplayCollections;
13
14/**
15 * @SuppressWarnings(Coupling)
16 * @return \Psr\Http\Message\ResponseInterface
17 */
18class CalldisplayQueue extends \BO\Zmsbackend\Api\BaseController
19{
20    /** @var array<int|string, \BO\Zmsentities\Scope> */
21    protected array $scopeCache = [];
22
23    /**
24     * @SuppressWarnings(Param)
25     * @return \Psr\Http\Message\ResponseInterface
26     */
27    #[\Override]
28    public function readResponse(
29        \Psr\Http\Message\RequestInterface $request,
30        \Psr\Http\Message\ResponseInterface $response,
31        array $args
32    ) {
33        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue();
34        $statusList = Validator::param('statusList')->isArray()->setDefault([])->getValue();
35
36        $input = Validator::input()->isJson()->assertValid()->getValue();
37        $calldisplay = (new \BO\Zmsentities\Calldisplay($input))->withOutClusterDuplicates();
38        $this->scopeCache = CalldisplayCollections::prepareForQueue($calldisplay, $resolveReferences);
39
40        //read full list if no statusList exists
41        $queueList = (count($statusList)) ?
42            $this->readQueueListByStatus($calldisplay, $statusList, $resolveReferences) :
43            $this->readFullQueueList($calldisplay, $resolveReferences);
44
45        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
46        $message->data = $queueList->withoutDublicates();
47
48        $response = Render::withLastModified($response, time(), '0');
49        $response = Render::withJson($response, $message, 200);
50        return $response;
51    }
52
53    protected function readCalculatedQueueListFromScope($scope, $resolveReferences)
54    {
55        $query = new \BO\Zmsbackend\Scope\Service\Scope();
56        $scope = (isset($this->scopeCache[$scope->id])) ?
57            $this->scopeCache[$scope->id] :
58            $query->readWithWorkstationCount($scope->id, \App::$now, $resolveReferences);
59
60        return $query
61            ->readQueueListWithWaitingTime($scope, \App::$now, $resolveReferences);
62    }
63
64    // full queueList for calculation optimistic and estimated waiting Time and number of waiting clients
65    protected function readFullQueueList($calldisplay, $resolveReferences)
66    {
67        $queueList = new \BO\Zmsentities\Collection\QueueList();
68        foreach ($calldisplay->getFullScopeList() as $scope) {
69            $queueList->addList($this->readCalculatedQueueListFromScope($scope, $resolveReferences));
70        }
71        return $queueList;
72    }
73
74    protected function readQueueListFromScopeAndStatus($scope, $status, $resolveReferences)
75    {
76        $query = new \BO\Zmsbackend\Process\Service\Process();
77        return $query
78            ->readProcessListByScopeAndStatus($scope->getId(), $status, $resolveReferences)
79            ->withinExactDate(\App::$now)
80            ->toQueueList(\App::$now);
81    }
82
83    // short queueList only with status called and processing
84    protected function readQueueListByStatus($calldisplay, $statusList, $resolveReferences)
85    {
86        $queueList = new \BO\Zmsentities\Collection\QueueList();
87        foreach ($calldisplay->getFullScopeList() as $scope) {
88            foreach ($statusList as $status) {
89                $queueList
90                    ->addList($this->readQueueListFromScopeAndStatus($scope, $status, $resolveReferences));
91            }
92        }
93        return $queueList;
94    }
95}