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
OrganisationByScope
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\Scope;
14
15/**
16  * Handle requests concerning services
17  */
18class OrganisationByScope extends BaseController
19{
20    /**
21     * @SuppressWarnings(Param)
22     * @return String
23     */
24    public function readResponse(
25        \Psr\Http\Message\RequestInterface $request,
26        \Psr\Http\Message\ResponseInterface $response,
27        array $args
28    ) {
29        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(1)->getValue();
30        $scope = (new Scope())->readEntity($args['id'], 0);
31        if (! $scope) {
32            throw new Exception\Scope\ScopeNotFound();
33        }
34        $organisation = (new Query())->readByScopeId($scope->id, $resolveReferences);
35
36        if (! $organisation->hasId()) {
37            throw new Exception\Organisation\OrganisationNotFound();
38        }
39
40        $message = Response\Message::create($request);
41        if ((new Helper\User($request))->hasRights()) {
42            (new Helper\User($request))->checkRights('basic');
43        } else {
44            $organisation = $organisation->withLessData();
45            $message->meta->reducedData = true;
46        }
47        $message->data = $organisation;
48
49        $response = Render::withLastModified($response, time(), '0');
50        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
51        return $response;
52    }
53}