Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AppointmentUpdate
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
1 / 1
9
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
1 / 1
9
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsapi;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsdb\Process;
13
14/**
15 * @SuppressWarnings(Coupling)
16 */
17class AppointmentUpdate extends 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\Zmsdb\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 = Process::init()->readEntity($args['id'], $args['authKey'], 1);
42        if (! $process->hasId()) {
43            throw new Exception\Process\ProcessNotFound();
44        }
45        if ($slotType || $slotsRequired) {
46            (new Helper\User($request))->checkPermissions('appointment');
47            Helper\Matching::testCurrentScopeHasRequest($process);
48        } elseif ($clientKey) {
49            $apiClient = (new \BO\Zmsdb\Apiclient())->readEntity($clientKey);
50            if (!$apiClient || !isset($apiClient->accesslevel) || $apiClient->accesslevel == 'blocked') {
51                throw new Exception\Process\ApiclientInvalid();
52            }
53            $slotType = $apiClient->accesslevel;
54            if ($apiClient->accesslevel != 'intern') {
55                $slotsRequired = 0;
56                $slotType = $apiClient->accesslevel;
57                $process = (new Process())->readSlotCount($process);
58            }
59            $process->apiclient = $apiClient;
60        } else {
61            $slotsRequired = 0;
62            $slotType = 'public';
63            $process = (new Process())->readSlotCount($process);
64        }
65
66        $process = Process::init()->writeEntityWithNewAppointment(
67            $process,
68            $appointment,
69            \App::$now,
70            $slotType,
71            $slotsRequired,
72            $resolveReferences,
73            ($keepReserved == 1)
74        );
75
76        $message = 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}