function template_preprocess_calendar_week in Calendar 7
Same name in this branch
- 7 theme/theme.inc \template_preprocess_calendar_week()
- 7 calendar_multiday/theme/theme.inc \template_preprocess_calendar_week()
Same name and namespace in other branches
- 8 calendar.theme.inc \template_preprocess_calendar_week()
- 6.2 theme/theme.inc \template_preprocess_calendar_week()
- 6.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_week()
- 7.3 theme/theme.inc \template_preprocess_calendar_week()
- 7.2 theme/theme.inc \template_preprocess_calendar_week()
- 7.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_week()
Display a week view.
1 call to template_preprocess_calendar_week()
- template_preprocess_calendar_week_overlap in calendar_multiday/
theme/ theme.inc - Display a week overlap view.
File
- calendar_multiday/
theme/ theme.inc, line 521 - Theme functions for the Calendar module.
Code
function template_preprocess_calendar_week(&$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;
$start_time = NULL;
if (sizeof($rows) > 1) {
$day_names = array_shift($rows);
}
else {
$day_names = $rows;
$rows = array();
}
// Moved timed items into the right columns and render them.
$show_empty_times = $view->date_info->style_show_empty_times;
$end_start_time = '23:59:59';
$grouped_items = array();
// pass the multiday buckets
$vars['all_day'] = $rows['multiday_buckets'];
// Remove the count for singleday
$vars['multiday_rows'] = max(0, $rows['total_rows'] - 1);
$display_overlap = $view->date_info->style_multiday_theme == '1' && $view->date_info->style_theme_style == '1';
$vars['display_overlap'] = $display_overlap;
// 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(
array(),
array(),
array(),
array(),
array(),
array(),
array(),
);
// Locate the first item
$first_time = '23:59:59';
$first_time_index = -1;
for ($i = 0; $i < 7; $i++) {
if (count($rows['singleday_buckets'][$i]) > 0) {
$time_slot = reset($rows['singleday_buckets'][$i]);
$time = date_format($time_slot[0]['item']->date_start, 'H:i:s');
if ($time < $first_time) {
$first_time = $time;
$first_time_index = $i;
}
}
}
if ($first_time_index > -1) {
$rows['singleday_buckets'][$first_time_index][$first_time][0]['is_first'] = TRUE;
}
}
// If we're not grouping by time, move all items into the 'all day' array.
if (empty($view->date_info->style_groupby_times)) {
$add_row = FALSE;
foreach ($vars['all_day'] as $index => &$day) {
foreach ($rows['singleday_buckets'][$index] as $item) {
foreach ($item as $event) {
$day[] = $event;
$add_row = TRUE;
}
}
}
if ($add_row) {
$vars['multiday_rows']++;
}
}
else {
foreach ($rows['singleday_buckets'] as $wday => $singleday_row) {
$columns[] = $wday;
foreach ($singleday_row as &$row) {
$start_times = $view->date_info->style_groupby_times;
$start_time = array_shift($start_times);
$next_start_time = count($start_times) ? array_shift($start_times) : $end_start_time;
foreach ($row as &$item) {
$time = date_format($item['item']->date_start, 'H:i:s');
if ($item['item']->calendar_all_day || $item['item']->date_start == $item['item']->date_end) {
$vars['all_day'][$item['wday']][] = $item;
if ($vars['multiday_rows'] == 0) {
$vars['multiday_rows']++;
}
}
else {
// 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 (($show_empty_times || $display_overlap) && !array_key_exists($start_time, $grouped_items)) {
$grouped_items[$start_time]['values'][$wday] = array();
}
$start_time = $next_start_time;
$next_start_time = count($start_times) ? array_shift($start_times) : $end_start_time;
}
$grouped_items[$start_time]['values'][$wday][] =& $item;
if ($display_overlap) {
$date_end = date_format($item['item']->date_end, 'H:i:s');
_calc_indents($overlapped_items[$wday], $time, $date_end, $item);
}
$item_count++;
$by_hour_count++;
}
}
}
// Finish out the day's time values if we want to see empty times.
if ($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'][$wday] = array();
}
$start_time = $next_start_time;
$next_start_time = count($start_times) ? array_shift($start_times) : $end_start_time;
}
}
ksort($grouped_items);
}
}
// 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' => isset($row['data']) ? $row['data']['date'] : NULL,
);
$heading = theme('calendar_time_row_heading', $variables);
$grouped_items[$start_time]['hour'] = $heading['hour'];
$grouped_items[$start_time]['ampm'] = $heading['ampm'];
$grouped_items[$start_time]['time'] = $start_time;
if ($display_overlap) {
foreach ($grouped_items[$start_time]['values'] as $wday => &$items) {
foreach ($items as &$item) {
if ($display_overlap) {
$offset = round(date_format($item['item']->date_start, 'i') / 15);
$duration = $item['item']->date_end
->format('U') - $item['item']->date_start
->format('U');
$duration = round($duration / (15 * 60));
$item['class'] = 'd_' . $duration . ' o_' . $offset . ' i_' . $item['indent'] . ' md_' . min($item['max_depth'], 5);
}
}
}
}
}
$vars['items'] = $grouped_items;
$vars['day_names'] = $day_names;
$vars['columns'] = $columns;
$vars['start_times'] = $view->date_info->style_groupby_times;
$vars['first_time'] = $first_time;
$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['item_count'] = $item_count;
$vars['by_hour_count'] = $by_hour_count;
return;
}