Lines
100.00%
30 / 30
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| CalendarGet | 100.00% | 30 / 30 | 100.00% | 1 / 1 | 7 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 30 / 30 | 100.00% | 1 / 1 | 7 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ZMS API | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsbackend\Calendar\Api; | |
| 9 | ||
| 10 | use BO\Slim\Render; | |
| 11 | use BO\Mellon\Validator; | |
| 12 | use BO\Zmsbackend\Calendar\Service\Calendar as Query; | |
| 13 | ||
| 14 | class CalendarGet extends \BO\Zmsbackend\Api\BaseController | |
| 15 | { | |
| 16 | /** | |
| 17 | * @SuppressWarnings(Param) | |
| 18 | * @return \Psr\Http\Message\ResponseInterface | |
| 19 | */ | |
| 20 | #[\Override] | |
| 21 | public function readResponse( | |
| 22 | \Psr\Http\Message\RequestInterface $request, | |
| 23 | \Psr\Http\Message\ResponseInterface $response, | |
| 24 | array $args | |
| 25 | ) { | |
| 26 | $hasGQL = Validator::param('gql')->isString()->getValue(); | |
| 27 | $slotsRequired = Validator::param('slotsRequired')->isNumber()->getValue(); | |
| 28 | $slotType = Validator::param('slotType')->isString()->getValue(); | |
| 29 | if ($slotType || $slotsRequired) { | |
| 30 | (new \BO\Zmsbackend\Helper\User($request))->checkPermissions(); | |
| 31 | } else { | |
| 32 | $slotsRequired = 0; | |
| 33 | $slotType = 'public'; | |
| 34 | } | |
| 35 | $slotType = $slotType ?? 'public'; | |
| 36 | $slotsRequired = $slotsRequired ?? 0; | |
| 37 | ||
| 38 | $query = new Query(); | |
| 39 | $fillWithEmptyDays = Validator::param('fillWithEmptyDays')->isNumber()->setDefault(0)->getValue(); | |
| 40 | $input = Validator::input()->isJson()->assertValid()->getValue(); | |
| 41 | $calendar = new \BO\Zmsentities\Calendar($input); | |
| 42 | ||
| 43 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 44 | ||
| 45 | if (!$calendar->hasFirstAndLastDay()) { | |
| 46 | throw new \BO\Zmsbackend\Calendar\Exception\InvalidFirstDay('First and last day are required'); | |
| 47 | } else { | |
| 48 | $calendar = $query | |
| 49 | ->readResolvedEntity($calendar, \App::getNow(), false, $slotType, $slotsRequired); | |
| 50 | $calendar = ($hasGQL) ? $calendar : $calendar->withLessData(); | |
| 51 | if ($fillWithEmptyDays) { | |
| 52 | $calendar = $calendar->withFilledEmptyDays(); | |
| 53 | } | |
| 54 | $calendar->days = $calendar->days->withDaysInDateRange($calendar->getFirstDay(), $calendar->getLastDay()); | |
| 55 | $message->data = $calendar; | |
| 56 | } | |
| 57 | if (0 == count($message->data['days'])) { | |
| 58 | $exception = new \BO\Zmsbackend\Calendar\Exception\AppointmentsMissed(); | |
| 59 | $exception->data = $message->data; | |
| 60 | throw $exception; | |
| 61 | } | |
| 62 | $response = Render::withLastModified($response, time(), '0'); | |
| 63 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 64 | return $response; | |
| 65 | } | |
| 66 | } |