Lines
4.00%
1 / 25
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ScopeAvailabilityHistory | 4.00% | 1 / 25 | 50.00% | 1 / 2 | 27.12 | 0.00% | 0 / 1 | |||
| readResponse | 0.00% | 0 / 24 | 0.00% | 0 / 1 | 12 | |||||
| canViewAvailabilityHistory | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package Zmsadmin | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsadmin; | |
| 9 | ||
| 10 | use BO\Mellon\Validator; | |
| 11 | use BO\Slim\Render; | |
| 12 | use BO\Zmsentities\Exception\UserAccountMissingRights; | |
| 13 | use BO\Zmsentities\Useraccount; | |
| 14 | use Psr\Http\Message\RequestInterface; | |
| 15 | use Psr\Http\Message\ResponseInterface; | |
| 16 | ||
| 17 | class ScopeAvailabilityHistory extends BaseController | |
| 18 | { | |
| 19 | /** | |
| 20 | * @SuppressWarnings(Param) | |
| 21 | */ | |
| 22 | #[\Override] | |
| 23 | public function readResponse( | |
| 24 | RequestInterface $request, | |
| 25 | ResponseInterface $response, | |
| 26 | array $args | |
| 27 | ): ResponseInterface { | |
| 28 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity(); | |
| 29 | $useraccount = $workstation->getUseraccount(); | |
| 30 | if (!static::canViewAvailabilityHistory($useraccount)) { | |
| 31 | throw new UserAccountMissingRights(); | |
| 32 | } | |
| 33 | ||
| 34 | $scopeId = Validator::value($args['id'])->isNumber()->getValue(); | |
| 35 | $from = Validator::param('from')->isString()->getValue(); | |
| 36 | $to = Validator::param('to')->isString()->getValue(); | |
| 37 | $availabilityId = Validator::param('availabilityId')->isNumber()->getValue(); | |
| 38 | $action = Validator::param('action')->isString()->getValue(); | |
| 39 | $params = array_filter([ | |
| 40 | 'from' => $from, | |
| 41 | 'to' => $to, | |
| 42 | 'availabilityId' => $availabilityId, | |
| 43 | 'action' => $action, | |
| 44 | ], static function ($value) { | |
| 45 | return $value !== null && $value !== ''; | |
| 46 | }); | |
| 47 | ||
| 48 | $result = \App::$http->readGetResult( | |
| 49 | '/scope/' . $scopeId . '/availability/history/', | |
| 50 | $params | |
| 51 | ); | |
| 52 | ||
| 53 | return Render::withJson($response, [ | |
| 54 | 'data' => $result->getData() ?? [], | |
| 55 | ]); | |
| 56 | } | |
| 57 | ||
| 58 | public static function canViewAvailabilityHistory(Useraccount $useraccount): bool | |
| 59 | { | |
| 60 | return $useraccount->isSuperUser() || $useraccount->hasRole('system_admin'); | |
| 61 | } | |
| 62 | } |