You are here

function template_preprocess_calendar in Calendar 7.2

Same name in this branch
  1. 7.2 theme/theme.inc \template_preprocess_calendar()
  2. 7.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar()
Same name and namespace in other branches
  1. 6.2 theme/theme.inc \template_preprocess_calendar()
  2. 6.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar()
  3. 7 theme/theme.inc \template_preprocess_calendar()
  4. 7 calendar_multiday/theme/theme.inc \template_preprocess_calendar()

Display a view as a calendar.

This preprocessor does all the work needed for all types of calendar views and the template takes care of displaying links to related views.

8 calls to template_preprocess_calendar()
template_preprocess_calendar_day in theme/theme.inc
Display a day view.
template_preprocess_calendar_day in calendar_multiday/theme/theme.inc
Display a day view.
template_preprocess_calendar_month in theme/theme.inc
Display a month view.
template_preprocess_calendar_month in calendar_multiday/theme/theme.inc
Display a month view.
template_preprocess_calendar_week in theme/theme.inc
Display a week view.

... See full list

File

calendar_multiday/theme/theme.inc, line 64
Theme functions for the Calendar module.

Code

function template_preprocess_calendar(&$vars) {
  module_load_include('inc', 'calendar_multiday', 'includes/calendar');

  // Add some basic values to the view.
  calendar_basics($vars);
  $view = $vars['view'];

  // Make sure we only run through this function one time.
  if (!empty($view->date_info->calendar_processed)) {
    return;
  }
  $result = (array) $view->result;
  $view->style_plugin
    ->render_fields($result);
  $rendered_items = !empty($view->style_plugin->rendered_fields) ? $view->style_plugin->rendered_fields : array();
  $items = array();
  $calendar_fields = date_views_fields($view->base_table);
  $calendar_fields = array_keys($calendar_fields['alias']);

  // Try to figure out the 'id' for this collection of items.
  // The id field is often not a field but instead an 'additional field',
  // so this is cludgy.
  foreach ($result as $num => $row) {
    $keys = array_keys((array) $row);
    foreach ($keys as $key) {
      if (strlen($key) == 3 && substr($key, -2) == 'id' && !empty($row->{$key})) {
        $id = $key;
      }
    }
  }
  foreach ($result as $num => $row) {
    $copy = clone $row;
    $items[$num] = new stdClass();
    $items[$num]->id = !empty($row->{$id}) ? $row->{$id} : NULL;
    $items[$num]->rendered = $rendered_items[$num];
    $items[$num]->raw = $copy;
    $items[$num]->calendar_fields = new stdClass();
    foreach ($row as $key => $value) {
      if (in_array($key, $calendar_fields)) {
        $items[$num]->calendar_fields->{$key} = $value;
      }
    }
  }
  $vars['display_type'] = $view->date_info->granularity;
  $vars['min_date_formatted'] = date_format($view->date_info->min_date, DATE_FORMAT_DATETIME);
  $vars['max_date_formatted'] = date_format($view->date_info->max_date, DATE_FORMAT_DATETIME);

  // Massage the resulting items into formatted calendar items.
  $items = calendar_build_nodes($view, $items);

  // Merge in items from other sources.
  foreach (module_implements('calendar_add_items') as $module) {
    $function = $module . '_calendar_add_items';
    if (function_exists($function)) {
      if ($feeds = $function($view)) {
        foreach ($feeds as $feed) {
          $items = $feed;
        }
      }
    }
  }
  $view->date_info->mini = isset($view->date_info->mini) ? $view->date_info->mini : $view->date_info->granularity == 'year';

  // Create the calendar day names and rows.
  $rows = calendar_build_calendar($view, $items);
  $vars['items'] = $items;
  $vars['rows'] = $rows;
  $view->date_info->calendar_processed = TRUE;
  $vars['view'] = $view;
  $vars['mini'] = !empty($view->date_info->mini);
  $vars['block'] = !empty($view->date_info->block);
}