function bat_event_get_matching_units_from_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_matching_units_from_calendar()
Returns matching units based on a provided Calendar. A Calendar can be instantiated in a number of ways - bat_event offers bat_event_get_calendar. Using an already setup calendar multiple times reduces overall load.
Parameters
$calendar:
DateTime $start_date:
DateTime $end_date:
$valid_name_states:
$intersect:
$reset:
Return value
array
1 call to bat_event_get_matching_units_from_calendar()
- 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 936 - Manage Events - Events store the EventValue of a Unit over a period of time.
Code
function bat_event_get_matching_units_from_calendar($calendar, DateTime $start_date, DateTime $end_date, $valid_name_states, $intersect = FALSE, $reset = TRUE) {
$valid_states = [];
foreach ($valid_name_states as $name) {
$state = bat_event_load_state_by_machine_name($name);
$valid_states[] = $state
->id();
}
$constraints = [];
foreach (bat_event_constraints_get_info() as $constraint) {
$constraints[] = $constraint['constraint'];
}
$response = $calendar
->getMatchingUnits($start_date, $end_date, $valid_states, $constraints, $intersect, $reset);
$valid_unit_ids = array_keys($response
->getIncluded());
if (count($valid_unit_ids)) {
return $valid_unit_ids;
}
return [];
}