Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
ScopeGet | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
5 |
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\Scope; |
13 | |
14 | class ScopeGet extends BaseController |
15 | { |
16 | /** |
17 | * @SuppressWarnings(Param) |
18 | * @return String |
19 | */ |
20 | public function readResponse( |
21 | \Psr\Http\Message\RequestInterface $request, |
22 | \Psr\Http\Message\ResponseInterface $response, |
23 | array $args |
24 | ) { |
25 | $message = Response\Message::create($request); |
26 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue(); |
27 | $keepLessData = Validator::param('keepLessData')->isArray()->setDefault([])->getValue(); |
28 | $hasGQL = Validator::param('gql')->isString()->getValue(); |
29 | $accessRights = Validator::param('accessRights')->isString()->isBiggerThan(4)->setDefault('basic')->getValue(); |
30 | $getIsOpened = Validator::param('getIsOpened')->isNumber()->setDefault(0)->getValue(); |
31 | $scope = (new Scope())->readEntity($args['id'], $resolveReferences); |
32 | if (! $scope) { |
33 | throw new Exception\Scope\ScopeNotFound(); |
34 | } |
35 | |
36 | $userAccess = new Helper\User($request, 2); |
37 | if ($userAccess->hasRights()) { |
38 | $userAccess->checkRights( |
39 | $accessRights, |
40 | new \BO\Zmsentities\Useraccount\EntityAccess($scope) |
41 | ); |
42 | } else { |
43 | $scope = ($hasGQL) ? $scope : $scope->withLessData($keepLessData); |
44 | $message->meta->reducedData = true; |
45 | } |
46 | |
47 | if ($getIsOpened) { |
48 | $scope->setStatusAvailability('isOpened', (new Scope())->readIsOpened($scope->getId(), \App::$now)); |
49 | } |
50 | $message->data = $scope; |
51 | |
52 | $response = Render::withLastModified($response, time(), '0'); |
53 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); |
54 | return $response; |
55 | } |
56 | } |