function template_preprocess_calendar_day in Calendar 6.2
Same name in this branch
- 6.2 theme/theme.inc \template_preprocess_calendar_day()
- 6.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_day()
Same name and namespace in other branches
- 8 calendar.theme.inc \template_preprocess_calendar_day()
- 7.3 theme/theme.inc \template_preprocess_calendar_day()
- 7 theme/theme.inc \template_preprocess_calendar_day()
- 7 calendar_multiday/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
- calendar_multiday/
theme/ theme.inc, line 296
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;
$display_overlap = $view->date_info->style_theme_style == '1';
// Add optional css
if ($display_overlap) {
drupal_add_css(drupal_get_path('module', 'calendar_multiday') . '/calendar-overlap.css');
drupal_add_js(drupal_get_path('module', 'calendar_multiday') . '/calendar_overlap.js');
$overlapped_items = array();
}
// 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, $item, $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 &$items) {
foreach ($items as &$item) {
$time = date_format($item->date_start, 'H:i:s');
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) || $display_overlap) && !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;
}
$grouped_items[$start_time]['values'][$column][] = $item;
if ($display_overlap) {
$time_end = date_format($item->date_end, 'H:i:s');
$item->time_start = $time;
$item->time_end = $time_end;
_calc_indents($overlapped_items, $time, $time_end, $item);
}
$item_count++;
$by_hour_count++;
}
}
// Finish out the day's time values if we want to see empty times.
if (!empty($show_empty_times) || $display_overlap) {
while ($start_time < $end_start_time && ($start_time != NULL || $display_overlap)) {
if ($start_time == NULL) {
$start_times = $view->date_info->style_groupby_times;
$start_time = array_shift($start_times);
$next_start_time = array_shift($start_times);
}
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;
$overlap_unit = 15;
$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';
$heading = theme('calendar_time_row_heading', $start_time, $next_start_time, $rows['date']);
$grouped_items[$start_time]['hour'] = $heading['hour'];
$grouped_items[$start_time]['ampm'] = $heading['ampm'];
foreach ($grouped_items[$start_time]['values'] as $column => &$items) {
foreach ($items as $index => &$item) {
if ($display_overlap) {
$offset = round(date_format($item->date_start, 'i') / $overlap_unit);
$duration = date_convert('1970-01-01 ' . $item->time_end, DATE_DATETIME, DATE_UNIX) - date_convert('1970-01-01 ' . $item->time_start, DATE_DATETIME, DATE_UNIX);
$duration = round($duration / ($overlap_unit * 60));
$item->class = 'd_' . $duration . ' o_' . $offset . ' i_' . $item->indent . ' md_' . min($item->max_depth, 5);
}
$theme = isset($item->calendar_node_theme) ? $item->calendar_node_theme : 'calendar_' . $view->date_info->granularity . '_node';
$grouped_items[$start_time]['values'][$column][$index] = theme($theme, $item, $view);
}
}
$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;
$vars['start_times'] = $view->date_info->style_groupby_times;
return;
}