Lines
100.00%
23 / 23
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ScopeGet | 100.00% | 23 / 23 | 100.00% | 1 / 1 | 6 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 23 / 23 | 100.00% | 1 / 1 | 6 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ZMS API | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsbackend\Scope\Api; | |
| 9 | ||
| 10 | use BO\Slim\Render; | |
| 11 | use BO\Mellon\Validator; | |
| 12 | use BO\Zmsbackend\Scope\Service\Scope; | |
| 13 | ||
| 14 | class ScopeGet extends \BO\Zmsbackend\Api\BaseController | |
| 15 | { | |
| 16 | /** | |
| 17 | * @SuppressWarnings(Param) | |
| 18 | * @return \Psr\Http\Message\ResponseInterface | |
| 19 | */ | |
| 20 | #[\Override] | |
| 21 | public function readResponse( | |
| 22 | \Psr\Http\Message\RequestInterface $request, | |
| 23 | \Psr\Http\Message\ResponseInterface $response, | |
| 24 | array $args | |
| 25 | ) { | |
| 26 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 27 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue(); | |
| 28 | $keepLessData = Validator::param('keepLessData')->isArray()->setDefault([])->getValue(); | |
| 29 | $hasGQL = Validator::param('gql')->isString()->getValue(); | |
| 30 | $accessRights = Validator::param('accessRights')->isString()->isBiggerThan(4)->getValue(); | |
| 31 | $getIsOpened = Validator::param('getIsOpened')->isNumber()->setDefault(0)->getValue(); | |
| 32 | $scope = (new \BO\Zmsbackend\Scope\Service\Scope())->readEntity($args['id'], $resolveReferences); | |
| 33 | if (! $scope) { | |
| 34 | throw new \BO\Zmsbackend\Scope\Exception\ScopeNotFound(); | |
| 35 | } | |
| 36 | ||
| 37 | $userAccess = new \BO\Zmsbackend\Helper\User($request, 2); | |
| 38 | if ($userAccess->hasLogin()) { | |
| 39 | $entityAccess = new \BO\Zmsentities\Useraccount\EntityAccess($scope); | |
| 40 | if ($accessRights) { | |
| 41 | $userAccess->checkPermissions($accessRights, $entityAccess); | |
| 42 | } else { | |
| 43 | $userAccess->checkPermissions($entityAccess); | |
| 44 | } | |
| 45 | } else { | |
| 46 | $scope = ($hasGQL) ? $scope : $scope->withLessData($keepLessData); | |
| 47 | $message->meta->reducedData = true; | |
| 48 | } | |
| 49 | ||
| 50 | if ($getIsOpened) { | |
| 51 | $scope->setStatusAvailability('isOpened', (new \BO\Zmsbackend\Scope\Service\Scope())->readIsOpened($scope->getId(), \App::$now)); | |
| 52 | } | |
| 53 | $message->data = $scope; | |
| 54 | ||
| 55 | $response = Render::withLastModified($response, time(), '0'); | |
| 56 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 57 | return $response; | |
| 58 | } | |
| 59 | } |