function bat_api_services_events_index in Booking and Availability Management API 7.2
Retrieve a list of events.
Parameters
string $target_ids:
string $target_types:
string $target_entity_type:
string $start_date:
string $end_date:
string $event_types:
1 string reference to 'bat_api_services_events_index'
- bat_api_services_resources in ./
bat_api.module - Implements hook_services_resources().
File
- ./
bat_api.module, line 875 - API access to booking data for BAT.
Code
function bat_api_services_events_index($target_ids, $target_types, $target_entity_type, $start_date, $end_date, $event_types) {
$return = new stdClass();
$return->sessid = session_id();
$target_types = array_filter(explode(',', $target_types));
$types = array_filter(explode(',', $event_types));
$events_json = array();
foreach ($types as $type) {
$event_store = new DrupalDBStore($type, DrupalDBStore::BAT_EVENT, bat_get_db_prefix());
$start_date_object = new DateTime($start_date);
$end_date_object = new DateTime($end_date);
$today = new DateTime();
if (!user_access('view past event information') && $today > $start_date_object) {
if ($today > $end_date_object) {
$return->events = array();
return $return;
}
$start_date_object = $today;
}
$ids = explode(',', $target_ids);
$units = array();
foreach ($ids as $id) {
if ($target_entity = entity_load_single($target_entity_type, $id)) {
if (in_array($target_entity->type, $target_types) || empty($target_types)) {
// Setting the default value to 0 since we are dealing with the events array
// so getting event IDs.
$units[] = new Unit($id, 0);
}
}
}
if (!empty($units)) {
$event_calendar = new Calendar($units, $event_store);
$event_ids = $event_calendar
->getEvents($start_date_object, $end_date_object);
$bat_event_type = bat_event_type_load($type);
if ($bat_event_type->fixed_event_states) {
$event_formatter = new FullCalendarFixedStateEventFormatter($bat_event_type);
}
else {
$event_formatter = new FullCalendarOpenStateEventFormatter($bat_event_type);
}
foreach ($event_ids as $unit_id => $unit_events) {
foreach ($unit_events as $key => $event) {
$events_json[] = array(
'id' => 'U' . $unit_id . 'E' . $key,
'bat_id' => $event
->getValue(),
'resourceId' => 'S' . $unit_id,
) + $event
->toJson($event_formatter);
}
}
}
}
$return->events = $events_json;
return $return;
}