function template_preprocess_calendar_day in Calendar 7
Same name in this branch
- 7 theme/theme.inc \template_preprocess_calendar_day()
- 7 calendar_multiday/theme/theme.inc \template_preprocess_calendar_day()
Same name and namespace in other branches
- 8 calendar.theme.inc \template_preprocess_calendar_day()
- 6.2 theme/theme.inc \template_preprocess_calendar_day()
- 6.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_day()
- 7.3 theme/theme.inc \template_preprocess_calendar_day()
- 7.2 theme/theme.inc \template_preprocess_calendar_day()
- 7.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_day()
Display a day view.
1 call to template_preprocess_calendar_day()
- template_preprocess_calendar_day_overlap in calendar_multiday/
theme/ theme.inc - Display a day overlap view.
File
- theme/
theme.inc, line 322 - Theme functions for the Calendar module.
Code
function template_preprocess_calendar_day(&$vars) {
// Add in all the $vars added by the main calendar preprocessor.
$vars['view']->style_with_weekno = FALSE;
template_preprocess_calendar($vars);
$view = $vars['view'];
$rows = $vars['rows'];
$item_count = 0;
$by_hour_count = 0;
$grouping_field = $view->date_info->style_groupby_field;
// If we're not grouping by time, move all items into the 'all day' array.
if (empty($view->date_info->style_groupby_times)) {
// Items are already grouped into times, so we need to process each time-group.
foreach ($rows['items'] as $time => $items) {
foreach ($items as $item) {
$rows['all_day'][] = $item;
}
}
$rows['items'] = array();
}
$columns = array();
// Move all_day items into the right columns and render them.
$grouped_items = array();
foreach ($rows['all_day'] as $item) {
if (isset($item->{$grouping_field})) {
$column = $item->{$grouping_field};
$item->{$grouping_field} = '';
// Remove the grouping field from the results.
if (!in_array($column, $columns)) {
$columns[] = $column;
}
}
else {
$column = t('Items');
}
$theme = isset($item->calendar_node_theme) ? $item->calendar_node_theme : 'calendar_' . $view->date_info->granularity . '_node';
$grouped_items[$column][] = theme($theme, array(
'node' => $item,
'view' => $view,
));
$item_count++;
}
$vars['rows']['all_day'] = $grouped_items;
// Moved timed items into the right columns and render them.
$start_times = $view->date_info->style_groupby_times;
$show_empty_times = $view->date_info->style_show_empty_times;
$end_start_time = '23:59:59';
$start_time = array_shift($start_times);
$next_start_time = count($start_times) ? array_shift($start_times) : $end_start_time;
$grouped_items = array();
foreach ($rows['items'] as $time => $items) {
foreach ($items as $item) {
if (isset($item->{$grouping_field})) {
$column = $item->{$grouping_field};
$item->{$grouping_field} = '';
// Remove the grouping field from the results.
if (!in_array($column, $columns)) {
$columns[] = $column;
}
}
else {
$column = t('Items');
}
// Find the next time slot and fill it. Populate the skipped
// slots if the option to show empty times was chosen.
while ($time >= $next_start_time && $time < $end_start_time) {
if (!empty($show_empty_times) && !array_key_exists($start_time, $grouped_items)) {
$grouped_items[$start_time]['values'] = array();
}
$start_time = $next_start_time;
$next_start_time = count($start_times) ? array_shift($start_times) : $end_start_time;
}
$theme = isset($item->calendar_node_theme) ? $item->calendar_node_theme : 'calendar_' . $view->date_info->granularity . '_node';
$variables = array(
'node' => $item,
'view' => $view,
);
$grouped_items[$start_time]['values'][$column][] = theme($theme, $variables);
$item_count++;
$by_hour_count++;
}
}
// Finish out the day's time values if we want to see empty times.
if (!empty($show_empty_times)) {
while ($start_time < $end_start_time) {
if (!array_key_exists($start_time, $grouped_items)) {
$grouped_items[$start_time]['values'] = array();
}
$start_time = $next_start_time;
$next_start_time = count($start_times) ? array_shift($start_times) : $end_start_time;
}
}
// Do the headers last, once we know what the actual values are.
$i = 0;
$start_times = array_keys($grouped_items);
foreach ($start_times as $start_time) {
$next_start_time = array_key_exists($i + 1, $start_times) ? $start_times[$i + 1] : '23:59:59';
$variables = array(
'start_time' => $start_time,
'next_start_time' => $next_start_time,
'curday_date' => $rows['date'],
);
$heading = theme('calendar_time_row_heading', $variables);
$grouped_items[$start_time]['hour'] = $heading['hour'];
$grouped_items[$start_time]['ampm'] = $heading['ampm'];
$i++;
}
ksort($grouped_items);
$vars['rows']['items'] = $grouped_items;
if (empty($columns)) {
$columns = array(
t('Items'),
);
}
$vars['columns'] = $columns;
$vars['agenda_hour_class'] = 'calendar-agenda-hour';
$first_column_width = 10;
if (empty($view->date_info->style_groupby_times)) {
$vars['agenda_hour_class'] .= ' calendar-agenda-no-hours';
$first_column_width = 1;
}
$vars['first_column_width'] = $first_column_width;
if (count($columns)) {
$vars['column_width'] = round((100 - $first_column_width) / count($columns));
}
else {
$vars['column_width'] = 100 - $first_column_width;
}
$vars['item_count'] = $item_count;
$vars['by_hour_count'] = $by_hour_count;
return;
}