Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
OrganisationByCluster
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
16 / 16
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\Organisation as Query;
13use BO\Zmsdb\Cluster;
14
15class OrganisationByCluster 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        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(1)->getValue();
27        $cluster = (new Cluster())->readEntity($args['id']);
28        if (! $cluster) {
29            throw new Exception\Cluster\ClusterNotFound();
30        }
31        $organisation = (new Query())->readByClusterId($cluster->id, $resolveReferences);
32        if (! $organisation->hasId()) {
33            throw new Exception\Organisation\OrganisationNotFound();
34        }
35
36        $message = Response\Message::create($request);
37        if ((new Helper\User($request))->hasRights()) {
38            (new Helper\User($request))->checkRights('basic');
39        } else {
40            $organisation = $organisation->withLessData();
41            $message->meta->reducedData = true;
42        }
43        $message->data = $organisation;
44
45        $response = Render::withLastModified($response, time(), '0');
46        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
47        return $response;
48    }
49}