function bat_api_services_availability_index in Booking and Availability Management API 7
Retrieves data in for each unit in a order list of unit ids.
Parameters
$unit_ids:
$start_date:
$duration:
1 string reference to 'bat_api_services_availability_index'
- bat_api_services_resources in ./
bat_api.module - Implements hook_services_resources().
File
- ./
bat_api.module, line 497
Code
function bat_api_services_availability_index($unit_ids, $start_date, $duration) {
$return = new stdClass();
$return->sessid = session_id();
$start_date_object = new DateTime($start_date);
$end_date_object = clone $start_date_object;
$end_date_object
->add(new DateInterval('P' . $duration));
$today = new DateTime();
if (!user_access('view past availability information') && $today > $start_date_object) {
if ($today > $end_date_object) {
$return->events = array();
return $return;
}
$start_date_object = $today;
}
$ids = explode(',', $unit_ids);
$events_json = array();
foreach ($ids as $id) {
$unit = rooms_unit_load($id);
$event_style = rooms_availability_get_style(ROOMS_AVAILABILITY_ADMIN_STYLE, $unit);
$rc = new UnitCalendar($unit->unit_id, $unit->default_state);
$events = $rc
->getEvents($start_date_object, $end_date_object);
foreach ($events as $event) {
if (variable_get('rooms_calendar_events_view', '0') == '0') {
$event->end_date
->add(new DateInterval('P1D'));
}
$events_json[$id][] = $event
->formatJson($event_style, $unit->name);
}
}
$return->events = $events_json;
return $return;
}