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