You are here

function bat_event_get_matching_units_from_calendar in Booking and Availability Management Tools for Drupal 7

Same name and namespace in other branches
  1. 8 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:

array $valid_name_states:

bool $intersect:

bool $reset:

bool $use_costraints:

Return value

array|bool

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 2451
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, $use_costraints = TRUE) {
  $valid_states = array();
  foreach ($valid_name_states as $name) {
    $state = bat_event_load_state_by_machine_name($name);
    $valid_states[] = $state['id'];
  }
  $constraints = array();
  if ($use_costraints) {
    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 FALSE;
}