Lines
100.00%
33 / 33
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ProcessReserve | 100.00% | 33 / 33 | 100.00% | 1 / 1 | 10 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 33 / 33 | 100.00% | 1 / 1 | 10 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ZMS API | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsbackend\Process\Api; | |
| 9 | ||
| 10 | use BO\Slim\Render; | |
| 11 | use BO\Mellon\Validator; | |
| 12 | use BO\Zmsbackend\Process\Service\Process; | |
| 13 | use BO\Zmsbackend\Process\Service\ProcessStatusFree; | |
| 14 | ||
| 15 | /** | |
| 16 | * @SuppressWarnings(Coupling) | |
| 17 | */ | |
| 18 | class ProcessReserve extends \BO\Zmsbackend\Api\BaseController | |
| 19 | { | |
| 20 | /** | |
| 21 | * @SuppressWarnings(Param) | |
| 22 | * @SuppressWarnings(Complexity) | |
| 23 | * @return \Psr\Http\Message\ResponseInterface | |
| 24 | */ | |
| 25 | #[\Override] | |
| 26 | public function readResponse( | |
| 27 | \Psr\Http\Message\RequestInterface $request, | |
| 28 | \Psr\Http\Message\ResponseInterface $response, | |
| 29 | array $args | |
| 30 | ) { | |
| 31 | $slotsRequired = Validator::param('slotsRequired')->isNumber()->getValue(); | |
| 32 | $slotType = Validator::param('slotType')->isString()->getValue(); | |
| 33 | $clientKey = Validator::param('clientkey')->isString()->getValue(); | |
| 34 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue(); | |
| 35 | $input = Validator::input()->isJson()->assertValid()->getValue(); | |
| 36 | $process = new \BO\Zmsentities\Process($input); | |
| 37 | if ($process->hasId()) { | |
| 38 | throw new \BO\Zmsbackend\Process\Exception\ProcessAlreadyExists(); | |
| 39 | } | |
| 40 | ||
| 41 | \BO\Zmsbackend\Connection\Select::setCriticalReadSession(); | |
| 42 | ||
| 43 | if ($slotType || $slotsRequired) { | |
| 44 | $workstation = (new \BO\Zmsbackend\Helper\User($request))->checkPermissions(); | |
| 45 | \BO\Zmsbackend\Helper\Matching::testCurrentScopeHasRequest($process); | |
| 46 | } elseif ($clientKey) { | |
| 47 | $apiClient = (new \BO\Zmsbackend\Apikey\Service\Apiclient())->readEntity($clientKey); | |
| 48 | if (!$apiClient || !isset($apiClient->accesslevel) || $apiClient->accesslevel == 'blocked') { | |
| 49 | throw new \BO\Zmsbackend\Process\Exception\ApiclientInvalid(); | |
| 50 | } | |
| 51 | $slotType = $apiClient->accesslevel; | |
| 52 | if ($apiClient->accesslevel != 'intern') { | |
| 53 | $slotsRequired = 0; | |
| 54 | $slotType = $apiClient->accesslevel; | |
| 55 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readSlotCount($process); | |
| 56 | } | |
| 57 | $process->apiclient = $apiClient; | |
| 58 | } else { | |
| 59 | $slotsRequired = 0; | |
| 60 | $slotType = 'public'; | |
| 61 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readSlotCount($process); | |
| 62 | } | |
| 63 | ||
| 64 | $userAccount = (isset($workstation)) ? $workstation->getUseraccount() : null; | |
| 65 | $process = (new \BO\Zmsbackend\Process\Service\ProcessStatusFree()) | |
| 66 | ->writeEntityReserved($process, \App::$now, $slotType, $slotsRequired, $resolveReferences, $userAccount); | |
| 67 | ||
| 68 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 69 | $message->data = $process; | |
| 70 | ||
| 71 | $response = Render::withLastModified($response, time(), '0'); | |
| 72 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 73 | return $response; | |
| 74 | } | |
| 75 | } |