You are here

function template_preprocess_calendar_week in Calendar 7

Same name in this branch
  1. 7 theme/theme.inc \template_preprocess_calendar_week()
  2. 7 calendar_multiday/theme/theme.inc \template_preprocess_calendar_week()
Same name and namespace in other branches
  1. 8 calendar.theme.inc \template_preprocess_calendar_week()
  2. 6.2 theme/theme.inc \template_preprocess_calendar_week()
  3. 6.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_week()
  4. 7.3 theme/theme.inc \template_preprocess_calendar_week()
  5. 7.2 theme/theme.inc \template_preprocess_calendar_week()
  6. 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

theme/theme.inc, line 467
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;
  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();
  $vars['rows'] = $rows[0];
  foreach ($rows[0] as $weekno => $row) {
    $vars['rows'][$weekno] = $row['data'];

    // If we're not grouping by time, move all items into the 'all day' array.
    if (empty($view->date_info->style_groupby_times)) {
      foreach ($row['data']['items'] as $items) {
        foreach ($items as $item) {
          $rows['all_day'][] = $item;
        }
      }
      $row['data']['items'] = array();
    }
    $columns[] = $weekno;
    $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['data']['all_day'] as $key => $item) {
      $theme = isset($item->calendar_node_theme) ? $item->calendar_node_theme : 'calendar_' . $view->date_info->granularity . '_node';
      $variables = array(
        'node' => $item,
        'view' => $view,
      );
      $vars['rows'][$weekno]['all_day'][$key] = theme($theme, $variables);
      $item_count++;
    }
    foreach ($row['data']['items'] as $time => $items) {
      foreach ($items as $item) {

        // 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 && !array_key_exists($start_time, $grouped_items)) {
            $grouped_items[$start_time]['values'][$weekno] = 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'][$weekno][] = theme($theme, $variables);
        $item_count++;
        $by_hour_count++;
      }
    }

    // Finish out the day's time values if we want to see empty times.
    if ($show_empty_times) {
      while ($start_time < $end_start_time) {
        if (!array_key_exists($start_time, $grouped_items)) {
          $grouped_items[$start_time]['values'][$weekno] = 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' => $row['data']['date'],
    );
    $heading = theme('calendar_time_row_heading', $variables);
    $grouped_items[$start_time]['hour'] = $heading['hour'];
    $grouped_items[$start_time]['ampm'] = $heading['ampm'];
  }
  $vars['items'] = $grouped_items;
  $vars['day_names'] = $day_names;
  $vars['columns'] = $columns;
  $vars['start_times'] = $view->date_info->style_groupby_times;
  $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;
}