Loading bookable_calendar.routing.yml +11 −0 Original line number Diff line number Diff line Loading @@ -130,3 +130,14 @@ bookable_calendar.booking.check_in: parameters: bookable_calendar: type: entity:bookable_calendar bookable_calendar.openings: path: 'bookable-calendar/api/{bookable_calendar}/openings' defaults: _controller: 'Drupal\bookable_calendar\Controller\BookableCalendarApiController::getOpenings' _title: 'Bookable Calendar Openings' requirements: _permission: 'access bookable calendar' options: parameters: bookable_calendar: type: entity:bookable_calendar src/Controller/BookableCalendarApiController.php +41 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\bookable_calendar\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Url; use Drupal\bookable_calendar\Entity\BookableCalendarOpeningInstance; use Drupal\bookable_calendar\Entity\BookableCalendar; use Drupal\bookable_calendar\Entity\BookingContact; Loading Loading @@ -185,4 +186,44 @@ public function checkOut(BookingContact $booking_contact) { 'message' => $booking_contact->id() . ' successfully checked out' ]); } /** * Get Passed in a Calendar and show the opening times * * In format that works with fullcalendar_block * * @param BookableCalendar $bookable_calendar * @return void */ public function getOpenings(BookableCalendar $bookable_calendar){ $opening_storage = \Drupal::entityTypeManager()->getStorage('bookable_calendar_opening'); $instance_storage = \Drupal::entityTypeManager()->getStorage('bookable_calendar_opening_inst'); $openings = $opening_storage->loadByProperties([ 'bookable_calendar' => [ 'target_id' => $bookable_calendar->id() ] ]); $opening_array = []; foreach ($openings as $opening) { $opening_instance = $instance_storage->loadByProperties([ 'booking_opening' => [ 'target_id' => $opening->id() ] ]); foreach ($opening_instance as $instance) { $path = Url::fromRoute('entity.bookable_calendar_opening_inst.canonical', [ 'bookable_calendar_opening_inst' => $instance->id() ])->toString(); $opening_array[] = [ 'title' => $bookable_calendar->title->value, 'start' => date('Y-m-d H:i:s', $instance->date->value), 'end' => date('Y-m-d H:i:s', $instance->date->value), 'url' => $path, ]; } } return new JsonResponse( $opening_array ); } } Loading
bookable_calendar.routing.yml +11 −0 Original line number Diff line number Diff line Loading @@ -130,3 +130,14 @@ bookable_calendar.booking.check_in: parameters: bookable_calendar: type: entity:bookable_calendar bookable_calendar.openings: path: 'bookable-calendar/api/{bookable_calendar}/openings' defaults: _controller: 'Drupal\bookable_calendar\Controller\BookableCalendarApiController::getOpenings' _title: 'Bookable Calendar Openings' requirements: _permission: 'access bookable calendar' options: parameters: bookable_calendar: type: entity:bookable_calendar
src/Controller/BookableCalendarApiController.php +41 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\bookable_calendar\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Url; use Drupal\bookable_calendar\Entity\BookableCalendarOpeningInstance; use Drupal\bookable_calendar\Entity\BookableCalendar; use Drupal\bookable_calendar\Entity\BookingContact; Loading Loading @@ -185,4 +186,44 @@ public function checkOut(BookingContact $booking_contact) { 'message' => $booking_contact->id() . ' successfully checked out' ]); } /** * Get Passed in a Calendar and show the opening times * * In format that works with fullcalendar_block * * @param BookableCalendar $bookable_calendar * @return void */ public function getOpenings(BookableCalendar $bookable_calendar){ $opening_storage = \Drupal::entityTypeManager()->getStorage('bookable_calendar_opening'); $instance_storage = \Drupal::entityTypeManager()->getStorage('bookable_calendar_opening_inst'); $openings = $opening_storage->loadByProperties([ 'bookable_calendar' => [ 'target_id' => $bookable_calendar->id() ] ]); $opening_array = []; foreach ($openings as $opening) { $opening_instance = $instance_storage->loadByProperties([ 'booking_opening' => [ 'target_id' => $opening->id() ] ]); foreach ($opening_instance as $instance) { $path = Url::fromRoute('entity.bookable_calendar_opening_inst.canonical', [ 'bookable_calendar_opening_inst' => $instance->id() ])->toString(); $opening_array[] = [ 'title' => $bookable_calendar->title->value, 'start' => date('Y-m-d H:i:s', $instance->date->value), 'end' => date('Y-m-d H:i:s', $instance->date->value), 'url' => $path, ]; } } return new JsonResponse( $opening_array ); } }