Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
81.25% |
26 / 32 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ProcessListByScopeAndDate | |
81.25% |
26 / 32 |
|
0.00% |
0 / 1 |
7.32 | |
0.00% |
0 / 1 |
readResponse | |
81.25% |
26 / 32 |
|
0.00% |
0 / 1 |
7.32 |
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 | use BO\Zmsdb\Scope as Query; |
13 | use BO\Zmsdb\ProcessStatusArchived; |
14 | use BO\Zmsentities\Collection\QueueList; |
15 | |
16 | class ProcessListByScopeAndDate extends BaseController |
17 | { |
18 | /** |
19 | * @SuppressWarnings(Param) |
20 | * @return String |
21 | */ |
22 | public function readResponse( |
23 | \Psr\Http\Message\RequestInterface $request, |
24 | \Psr\Http\Message\ResponseInterface $response, |
25 | array $args |
26 | ) { |
27 | (new Helper\User($request))->checkRights('basic'); |
28 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue(); |
29 | $showWeek = Validator::param('showWeek')->isNumber()->setDefault(0)->getValue(); |
30 | $dateTime = new \BO\Zmsentities\Helper\DateTime($args['date']); |
31 | $dateTime = $dateTime->modify(\App::$now->format('H:i')); |
32 | $dates = [$dateTime]; |
33 | |
34 | if ($showWeek) { |
35 | $dates = []; |
36 | $startDate = clone $dateTime->modify('Monday this week'); |
37 | $endDate = clone $dateTime->modify('Sunday this week'); |
38 | |
39 | while ($startDate <= $endDate) { |
40 | $dates[] = $startDate; |
41 | $startDate = $startDate->modify('+1 day'); |
42 | } |
43 | } |
44 | |
45 | $query = new Query(); |
46 | $scope = $query->readWithWorkstationCount($args['id'], \App::$now, 0); |
47 | if (! $scope || ! $scope->getId()) { |
48 | throw new Exception\Scope\ScopeNotFound(); |
49 | } |
50 | |
51 | $queueList = new QueueList(); |
52 | foreach ($dates as $date) { |
53 | $queueList->addList($query->readQueueListWithWaitingTime( |
54 | $scope, |
55 | $date, |
56 | $resolveReferences ? $resolveReferences + 1 : 1 // resolveReferences is for process, for queue we have to +1 |
57 | )); |
58 | } |
59 | |
60 | $archivedProcesses = |
61 | (new ProcessStatusArchived())->readListByScopesAndDates([$scope->getId()], $dates); |
62 | |
63 | $message = Response\Message::create($request); |
64 | $message->data = $queueList->toProcessList()->withResolveLevel($resolveReferences); |
65 | $message->data->addData($archivedProcesses); |
66 | |
67 | $response = Render::withLastModified($response, time(), '0'); |
68 | $response = Render::withJson($response, $message, 200); |
69 | return $response; |
70 | } |
71 | } |