Commit cbb34a29 authored by Nicolò Caruso's avatar Nicolò Caruso
Browse files

One call to getEvents function

parent 3e620e6e
......@@ -539,8 +539,6 @@ function bat_api_services_events_index($unit_ids, $start_date, $end_date, $type)
$state_store = new DrupalDBStore($type, DrupalDBStore::BAT_STATE);
$event_style = BAT_EVENT_CALENDAR_ADMIN_STYLE;
$start_date_object = new DateTime($start_date);
$end_date_object = new DateTime($end_date);
......@@ -558,17 +556,22 @@ function bat_api_services_events_index($unit_ids, $start_date, $end_date, $type)
$events_json = array();
$units = array();
foreach ($ids as $id) {
$bat_unit = bat_unit_load($id);
$unit = new Unit($id, $bat_unit->getDefaultValue($type));
if ($bat_unit = bat_unit_load($id)) {
$units[] = new Unit($id, $bat_unit->getDefaultValue($type));
}
}
$rc = new Calendar(array($unit), $state_store);
if (!empty($units)) {
$rc = new Calendar($units, $state_store);
$events = $rc->getEvents($start_date_object, $end_date_object);
if (isset($events[$id])) {
foreach ($events[$id] as $event) {
$event_formatter = new FullCalendarEventFormatter();
$events_json[$id][] = $event->toJson($event_formatter);
$event_formatter = new FullCalendarEventFormatter($type);
foreach ($events as $unit_id => $unit_events) {
foreach ($unit_events as $event) {
$events_json[$unit_id][] = $event->toJson($event_formatter);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment