Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ProcessNextByCluster
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
23 / 23
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 \Psr\Http\Message\ResponseInterface
20     */
21    #[\Override]
22    public function readResponse(
23        \Psr\Http\Message\RequestInterface $request,
24        \Psr\Http\Message\ResponseInterface $response,
25        array $args
26    ) {
27        $workstation = (new Helper\User($request, 1))->checkPermissions('appointment');
28        $query = new Query();
29        $selectedDate = Validator::param('date')->isString()->getValue();
30        $exclude = Validator::param('exclude')->isString()->getValue();
31        $allowClusterWideCall = Validator::param('allowClusterWideCall')->isBool()->setDefault(true)->getValue();
32        $dateTime = ($selectedDate) ? new DateTime($selectedDate) : \App::$now;
33        $cluster = $query->readEntity($args['id']);
34        if (! $cluster) {
35            throw new Exception\Cluster\ClusterNotFound();
36        }
37
38        (new Helper\User($request, 2))->checkPermissions(
39            new \BO\Zmsentities\Useraccount\EntityAccess($cluster)
40        );
41
42        $queueList = $query->readQueueList($cluster->id, $dateTime, 1);
43        if (! $allowClusterWideCall) {
44            $queueList = $queueList
45            ->toProcessList()
46            ->withScopeId($workstation->getScope()->getId())
47            ->toQueueList($dateTime);
48        }
49
50        $message = Response\Message::create($request);
51        $message->data = ProcessNextByScope::getProcess($queueList, $dateTime, $exclude);
52
53        $response = Render::withLastModified($response, time(), '0');
54        $response = Render::withJson($response, $message, 200);
55        return $response;
56    }
57}