Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
CalldisplayGet | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
8 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
testScopeAndCluster | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
7 |
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\Calldisplay as Query; |
13 | use BO\Zmsentities\Calldisplay as Entity; |
14 | |
15 | /** |
16 | * @SuppressWarnings(Coupling) |
17 | * @return String |
18 | */ |
19 | class CalldisplayGet extends BaseController |
20 | { |
21 | /** |
22 | * @SuppressWarnings(Param) |
23 | * @return String |
24 | */ |
25 | public function readResponse( |
26 | \Psr\Http\Message\RequestInterface $request, |
27 | \Psr\Http\Message\ResponseInterface $response, |
28 | array $args |
29 | ) { |
30 | $query = new Query(); |
31 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(1)->getValue(); |
32 | $input = Validator::input()->isJson()->assertValid()->getValue(); |
33 | $entity = new Entity($input); |
34 | |
35 | $this->testScopeAndCluster($entity); |
36 | $message = Response\Message::create($request); |
37 | $message->data = $query->readResolvedEntity($entity, \App::getNow(), $resolveReferences); |
38 | |
39 | $response = Render::withLastModified($response, time(), '0'); |
40 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); |
41 | return $response; |
42 | } |
43 | |
44 | protected function testScopeAndCluster($calldisplay) |
45 | { |
46 | if (! $calldisplay->hasScopeList() && ! $calldisplay->hasClusterList()) { |
47 | throw new Exception\Calldisplay\ScopeAndClusterNotFound(); |
48 | } |
49 | foreach ($calldisplay->getClusterList() as $cluster) { |
50 | $cluster = (new \BO\Zmsdb\Cluster())->readEntity($cluster->id); |
51 | if (! $cluster) { |
52 | throw new Exception\Cluster\ClusterNotFound(); |
53 | } |
54 | } |
55 | foreach ($calldisplay->getScopeList() as $scope) { |
56 | $scope = (new \BO\Zmsdb\Scope())->readEntity($scope->id); |
57 | if (! $scope) { |
58 | throw new Exception\Scope\ScopeNotFound(); |
59 | } |
60 | } |
61 | } |
62 | } |