function bat_event_get_calendar in Booking and Availability Management Tools for Drupal 8
Same name and namespace in other branches
- 7 modules/bat_event/bat_event.module \bat_event_get_calendar()
Retrieves relevant units and instantiates a BAT calendar object than can be reused. It is preferred to use this function to reduce the cost of setting up a calendar (i.e. loading units).
Parameters
$type_id:
$event_type:
Return value
\Roomify\Bat\Calendar\Calendar
2 calls to bat_event_get_calendar()
- bat_event_get_calendar_response in modules/
bat_event/ bat_event.module - Given a date range and a set of valid states it will return all units within the set of valid states.
- bat_event_get_matching_units in modules/
bat_event/ bat_event.module - Given a date range and a set of valid states it will return all units within the set of valid states.
File
- modules/
bat_event/ bat_event.module, line 901 - Manage Events - Events store the EventValue of a Unit over a period of time.
Code
function bat_event_get_calendar($type_id, $event_type, $drupal_units = []) {
$database = Database::getConnectionInfo('default');
$prefix = isset($database['default']['prefix']['default']) ? $database['default']['prefix']['default'] : '';
$state_store = new DrupalDBStore($event_type, DrupalDBStore::BAT_STATE, $prefix);
if (empty($drupal_units)) {
$drupal_units = bat_unit_load_multiple(FALSE, [
'unit_type_id' => $type_id,
]);
}
$bat_units = [];
foreach ($drupal_units as $unit_id => $unit) {
$bat_units[] = new Unit($unit_id, $unit
->getEventDefaultValue($event_type));
}
$calendar = new Calendar($bat_units, $state_store);
return $calendar;
}