Lines
100.00%
35 / 35
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ProcessQueued | 100.00% | 35 / 35 | 100.00% | 2 / 2 | 6 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 29 / 29 | 100.00% | 1 / 1 | 3 | |||||
| testProcessData | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 3 | |||||
| 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 as Query; | |
| 13 | use BO\Zmsbackend\Process\Service\ProcessStatusQueued; | |
| 14 | ||
| 15 | /** | |
| 16 | * @SuppressWarnings(Coupling) | |
| 17 | */ | |
| 18 | class ProcessQueued extends \BO\Zmsbackend\Api\BaseController | |
| 19 | { | |
| 20 | /** | |
| 21 | * @SuppressWarnings(Param) | |
| 22 | * @return \Psr\Http\Message\ResponseInterface | |
| 23 | */ | |
| 24 | #[\Override] | |
| 25 | public function readResponse( | |
| 26 | \Psr\Http\Message\RequestInterface $request, | |
| 27 | \Psr\Http\Message\ResponseInterface $response, | |
| 28 | array $args | |
| 29 | ) { | |
| 30 | $workstation = (new \BO\Zmsbackend\Helper\User($request))->checkPermissions('appointment'); | |
| 31 | $input = Validator::input()->isJson()->assertValid()->getValue(); | |
| 32 | $entity = new \BO\Zmsentities\Process($input); | |
| 33 | $entity->testValid(); | |
| 34 | $this->testProcessData($entity); | |
| 35 | $process = (new Query())->readEntity($entity['id'], $entity['authKey'], 1); | |
| 36 | $previousStatus = $process->status; | |
| 37 | if (isset($entity->queue['waitingTime'])) { | |
| 38 | $process->queue['waitingTime'] = $entity->queue['waitingTime']; | |
| 39 | } | |
| 40 | if (isset($entity->queue['arrivalTime'])) { | |
| 41 | $process->queue['arrivalTime'] = $entity->queue['arrivalTime']; | |
| 42 | } | |
| 43 | $process->status = 'queued'; | |
| 44 | $process->queue['callCount'] = 0; | |
| 45 | $process->queue['lastCallTime'] = 0; | |
| 46 | $process->queue['priority'] = $entity->getPriority(); | |
| 47 | $cluster = (new \BO\Zmsbackend\Cluster\Service\Cluster())->readByScopeId($workstation->scope['id'], 1); | |
| 48 | $workstation->validateProcessScopeAccess($workstation->getScopeList($cluster), $process); | |
| 49 | $process = (new Query())->updateEntity( | |
| 50 | $process, | |
| 51 | \App::$now, | |
| 52 | 0, | |
| 53 | $previousStatus, | |
| 54 | $workstation->getUseraccount() | |
| 55 | ); | |
| 56 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 57 | $message->data = $process; | |
| 58 | ||
| 59 | $response = Render::withLastModified($response, time(), '0'); | |
| 60 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 61 | return $response; | |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * @return void | |
| 66 | */ | |
| 67 | protected function testProcessData(\BO\Zmsentities\Process $entity) | |
| 68 | { | |
| 69 | $authCheck = (new Query())->readAuthKeyByProcessId($entity->id); | |
| 70 | if (! $authCheck) { | |
| 71 | throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound(); | |
| 72 | } elseif ($authCheck['authKey'] !== $entity->authKey) { | |
| 73 | throw new \BO\Zmsbackend\Process\Exception\AuthKeyMatchFailed(); | |
| 74 | } | |
| 75 | \BO\Zmsbackend\Helper\Matching::testCurrentScopeHasRequest($entity); | |
| 76 | } | |
| 77 | } |