Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ProcessNextByCluster
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsapi;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsdb\Cluster as Query;
13use BO\Zmsentities\Helper\DateTime;
14
15class ProcessNextByCluster extends BaseController
16{
17    /**
18     * @SuppressWarnings(Param)
19     * @return String
20     */
21    public function readResponse(
22        \Psr\Http\Message\RequestInterface $request,
23        \Psr\Http\Message\ResponseInterface $response,
24        array $args
25    ) {
26        $workstation = (new Helper\User($request, 1))->checkRights();
27        $query = new Query();
28        $selectedDate = Validator::param('date')->isString()->getValue();
29        $exclude = Validator::param('exclude')->isString()->getValue();
30        $allowClusterWideCall = Validator::param('allowClusterWideCall')->isBool()->setDefault(true)->getValue();
31        $dateTime = ($selectedDate) ? new DateTime($selectedDate) : \App::$now;
32        $cluster = $query->readEntity($args['id']);
33        if (! $cluster) {
34            throw new Exception\Cluster\ClusterNotFound();
35        }
36        $queueList = $query->readQueueList($cluster->id, $dateTime, 1);
37        if (! $allowClusterWideCall) {
38            $queueList = $queueList
39            ->toProcessList()
40            ->withScopeId($workstation->getScope()->getId())
41            ->toQueueList($dateTime);
42        }
43
44        $message = Response\Message::create($request);
45        $message->data = ProcessNextByScope::getProcess($queueList, $dateTime, $exclude);
46
47        $response = Render::withLastModified($response, time(), '0');
48        $response = Render::withJson($response, $message, 200);
49        return $response;
50    }
51}