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