Lines
100.00%
42 / 42
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AppointmentUpdate | 100.00% | 42 / 42 | 100.00% | 1 / 1 | 9 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 42 / 42 | 100.00% | 1 / 1 | 9 | |||||
| 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 | ||
| 14 | /** | |
| 15 | * @SuppressWarnings(Coupling) | |
| 16 | */ | |
| 17 | class AppointmentUpdate extends \BO\Zmsbackend\Api\BaseController | |
| 18 | { | |
| 19 | /** | |
| 20 | * @SuppressWarnings(Param) | |
| 21 | * @return \Psr\Http\Message\ResponseInterface | |
| 22 | */ | |
| 23 | #[\Override] | |
| 24 | public function readResponse( | |
| 25 | \Psr\Http\Message\RequestInterface $request, | |
| 26 | \Psr\Http\Message\ResponseInterface $response, | |
| 27 | array $args | |
| 28 | ) { | |
| 29 | \BO\Zmsbackend\Connection\Select::setCriticalReadSession(); | |
| 30 | ||
| 31 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue(); | |
| 32 | $slotsRequired = Validator::param('slotsRequired')->isNumber()->getValue(); | |
| 33 | $slotType = Validator::param('slotType')->isString()->getValue(); | |
| 34 | $clientKey = Validator::param('clientkey')->isString()->getValue(); | |
| 35 | $keepReserved = Validator::param('keepReserved')->isNumber()->setDefault(0)->getValue(); | |
| 36 | $input = Validator::input()->isJson()->assertValid()->getValue(); | |
| 37 | $appointment = new \BO\Zmsentities\Appointment($input); | |
| 38 | $appointment->testValid(); | |
| 39 | ||
| 40 | // get old process and check user rights if slottype or slotrequired is set | |
| 41 | $process = \BO\Zmsbackend\Process\Service\Process::init()->readEntity($args['id'], $args['authKey'], 1); | |
| 42 | if (! $process->hasId()) { | |
| 43 | throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound(); | |
| 44 | } | |
| 45 | if ($slotType || $slotsRequired) { | |
| 46 | (new \BO\Zmsbackend\Helper\User($request))->checkPermissions('appointment'); | |
| 47 | \BO\Zmsbackend\Helper\Matching::testCurrentScopeHasRequest($process); | |
| 48 | } elseif ($clientKey) { | |
| 49 | $apiClient = (new \BO\Zmsbackend\Apikey\Service\Apiclient())->readEntity($clientKey); | |
| 50 | if (!$apiClient || !isset($apiClient->accesslevel) || $apiClient->accesslevel == 'blocked') { | |
| 51 | throw new \BO\Zmsbackend\Process\Exception\ApiclientInvalid(); | |
| 52 | } | |
| 53 | $slotType = $apiClient->accesslevel; | |
| 54 | if ($apiClient->accesslevel != 'intern') { | |
| 55 | $slotsRequired = 0; | |
| 56 | $slotType = $apiClient->accesslevel; | |
| 57 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readSlotCount($process); | |
| 58 | } | |
| 59 | $process->apiclient = $apiClient; | |
| 60 | } else { | |
| 61 | $slotsRequired = 0; | |
| 62 | $slotType = 'public'; | |
| 63 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readSlotCount($process); | |
| 64 | } | |
| 65 | ||
| 66 | $process = \BO\Zmsbackend\Process\Service\Process::init()->writeEntityWithNewAppointment( | |
| 67 | $process, | |
| 68 | $appointment, | |
| 69 | \App::$now, | |
| 70 | $slotType, | |
| 71 | $slotsRequired, | |
| 72 | $resolveReferences, | |
| 73 | ($keepReserved == 1) | |
| 74 | ); | |
| 75 | ||
| 76 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 77 | $message->data = $process; | |
| 78 | ||
| 79 | $response = Render::withLastModified($response, time(), '0'); | |
| 80 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 81 | return $response; | |
| 82 | } | |
| 83 | } |