You are here

function bat_event_get_calendar_response 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_calendar_response()

Given a date range and a set of valid states it will return all units within the set of valid states.

Parameters

DateTime $start_date:

DateTime $end_date:

array $valid_name_states:

$type_id:

$event_type:

bool $intersect:

bool $use_costraints:

Return value

array

File

modules/bat_event/bat_event.module, line 2490
Manage Events - Events store the EventValue of a Unit over a period of time.

Code

function bat_event_get_calendar_response(DateTime $start_date, DateTime $end_date, $valid_name_states, $type_id, $event_type, $intersect = FALSE, $use_costraints = TRUE) {
  $results = array(
    'included' => array(),
    'excluded' => array(),
  );
  $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'];
    }
  }
  $calendar = bat_event_get_calendar($type_id, $event_type);
  $response = $calendar
    ->getMatchingUnits($start_date, $end_date, $valid_states, $constraints, $intersect);
  $valid_unit_ids = array_keys($response
    ->getIncluded());
  $excluded = array();
  foreach ($response
    ->getExcluded() as $unit_id => $ex) {
    if (isset($ex['constraint'])) {
      $p = $ex['constraint']
        ->toString();
      $excluded[$unit_id] = t($p['text'], $p['args']);
    }
    else {
      $excluded[$unit_id] = '';
    }
  }
  $results['excluded'] = $excluded;
  if (count($valid_unit_ids)) {
    $results['included'] = $valid_unit_ids;
  }
  return $results;
}