Commit bd65cbdc authored by nicola85's avatar nicola85

Collapse calendar units childrens

parent aca4691c
......@@ -353,6 +353,14 @@ function bat_api_services_resources() {
'source' => array('param' => 'grouping_entity_type'),
'optional' => TRUE,
),
array(
'name' => 'collapse_childrens',
'type' => 'boolean',
'description' => t('Collapse childrens'),
'source' => array('param' => 'collapse_childrens'),
'optional' => TRUE,
'default value' => FALSE,
),
array(
'name' => 'offset',
'type' => 'string',
......@@ -563,10 +571,11 @@ function bat_api_services_resources() {
* @param bool $return_children
* @param string $grouping_ids
* @param string $grouping_entity_type
* @param bool $collapse_childrens
* @param string $offset
* @param string $limit
*/
function bat_api_services_units_index_calendar($unit_types, $unit_ids, $event_type, $return_children, $grouping_ids, $grouping_entity_type, $offset, $limit) {
function bat_api_services_units_index_calendar($unit_types, $unit_ids, $event_type, $return_children, $grouping_ids, $grouping_entity_type, $collapse_childrens, $offset, $limit) {
$create_event_access = FALSE;
if (bat_event_access('create', bat_event_create(array('type' => $event_type)))) {
......@@ -694,6 +703,27 @@ function bat_api_services_units_index_calendar($unit_types, $unit_ids, $event_ty
}
}
if ($collapse_childrens) {
foreach ($units as $id => $unit1) {
if (count($unit1['children']) == 1) {
foreach ($unit1['children'] as $unit2) {
if (count($unit2['children']) == 1) {
$units[$id] = $unit2['children'][0];
$units[$id]['title'] = $unit1['title'];
}
}
}
else {
foreach ($unit1['children'] as $id2 => $unit2) {
if (count($unit2['children']) == 1) {
$units[$id]['children'][$id2] = $unit2['children'][0];
$units[$id]['children'][$id2]['title'] = $unit2['title'];
}
}
}
}
}
drupal_alter('bat_api_units_index_calendar', $units);
return array_values($units);
......
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