Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
70.21% |
33 / 47 |
|
33.33% |
2 / 6 |
CRAP | |
0.00% |
0 / 1 |
CalldisplayQueue | |
70.21% |
33 / 47 |
|
33.33% |
2 / 6 |
24.64 | |
0.00% |
0 / 1 |
readResponse | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
2.00 | |||
testScopeAndCluster | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
7 | |||
readCalculatedQueueListFromScope | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
2.01 | |||
readFullQueueList | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
readQueueListFromScopeAndStatus | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
readQueueListByStatus | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | /** |
4 | * @package ZMS API |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsapi; |
9 | |
10 | use BO\Slim\Render; |
11 | use BO\Mellon\Validator; |
12 | |
13 | /** |
14 | * @SuppressWarnings(Coupling) |
15 | * @return String |
16 | */ |
17 | class CalldisplayQueue extends BaseController |
18 | { |
19 | /** |
20 | * @SuppressWarnings(Param) |
21 | * @return String |
22 | */ |
23 | public function readResponse( |
24 | \Psr\Http\Message\RequestInterface $request, |
25 | \Psr\Http\Message\ResponseInterface $response, |
26 | array $args |
27 | ) { |
28 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue(); |
29 | $statusList = Validator::param('statusList')->isArray()->setDefault([])->getValue(); |
30 | |
31 | $input = Validator::input()->isJson()->assertValid()->getValue(); |
32 | $calldisplay = (new \BO\Zmsentities\Calldisplay($input))->withOutClusterDuplicates(); |
33 | $this->testScopeAndCluster($calldisplay, $resolveReferences); |
34 | |
35 | //read full list if no statusList exists |
36 | $queueList = (count($statusList)) ? |
37 | $this->readQueueListByStatus($calldisplay, $statusList, $resolveReferences) : |
38 | $this->readFullQueueList($calldisplay, $resolveReferences); |
39 | |
40 | |
41 | |
42 | $message = Response\Message::create($request); |
43 | $message->data = $queueList->withoutDublicates(); |
44 | |
45 | $response = Render::withLastModified($response, time(), '0'); |
46 | $response = Render::withJson($response, $message, 200); |
47 | return $response; |
48 | } |
49 | |
50 | protected $scopeCache = []; |
51 | |
52 | protected function testScopeAndCluster($calldisplay, $resolveReferences) |
53 | { |
54 | if (! $calldisplay->hasScopeList() && ! $calldisplay->hasClusterList()) { |
55 | throw new Exception\Calldisplay\ScopeAndClusterNotFound(); |
56 | } |
57 | foreach ($calldisplay->getClusterList() as $cluster) { |
58 | $cluster = (new \BO\Zmsdb\Cluster())->readEntity($cluster->getId()); |
59 | if (! $cluster) { |
60 | throw new Exception\Cluster\ClusterNotFound(); |
61 | } |
62 | } |
63 | foreach ($calldisplay->getScopeList() as $scope) { |
64 | $scope = (new \BO\Zmsdb\Scope())->readWithWorkstationCount($scope->getId(), \App::$now, $resolveReferences); |
65 | if (! $scope) { |
66 | throw new Exception\Scope\ScopeNotFound(); |
67 | } |
68 | $this->scopeCache[$scope->getId()] = $scope; |
69 | } |
70 | } |
71 | |
72 | protected function readCalculatedQueueListFromScope($scope, $resolveReferences) |
73 | { |
74 | $query = new \BO\Zmsdb\Scope(); |
75 | $scope = (isset($this->scopeCache[$scope->id])) ? |
76 | $this->scopeCache[$scope->id] : |
77 | $query->readWithWorkstationCount($scope->id, \App::$now, $resolveReferences); |
78 | |
79 | return $query |
80 | ->readQueueListWithWaitingTime($scope, \App::$now, $resolveReferences) |
81 | ->withPickupDestination($scope); |
82 | } |
83 | |
84 | // full queueList for calculation optimistic and estimated waiting Time and number of waiting clients |
85 | protected function readFullQueueList($calldisplay, $resolveReferences) |
86 | { |
87 | $queueList = new \BO\Zmsentities\Collection\QueueList(); |
88 | foreach ($calldisplay->getFullScopeList() as $scope) { |
89 | $queueList->addList($this->readCalculatedQueueListFromScope($scope, $resolveReferences)); |
90 | } |
91 | return $queueList; |
92 | } |
93 | |
94 | protected function readQueueListFromScopeAndStatus($scope, $status, $resolveReferences) |
95 | { |
96 | $query = new \BO\Zmsdb\Process(); |
97 | return $query |
98 | ->readProcessListByScopeAndStatus($scope->getId(), $status, $resolveReferences) |
99 | ->withinExactDate(\App::$now) |
100 | ->toQueueList(\App::$now) |
101 | ->withPickupDestination($scope); |
102 | } |
103 | |
104 | // short queueList only with status called, pickup and processing |
105 | protected function readQueueListByStatus($calldisplay, $statusList, $resolveReferences) |
106 | { |
107 | $queueList = new \BO\Zmsentities\Collection\QueueList(); |
108 | foreach ($calldisplay->getFullScopeList() as $scope) { |
109 | foreach ($statusList as $status) { |
110 | $queueList |
111 | ->addList($this->readQueueListFromScopeAndStatus($scope, $status, $resolveReferences)); |
112 | } |
113 | } |
114 | return $queueList; |
115 | } |
116 | } |