You are here

function calendar_build_calendar in Calendar 5.2

Same name and namespace in other branches
  1. 6.2 includes/calendar.inc \calendar_build_calendar()
  2. 6.2 calendar_multiday/includes/calendar.inc \calendar_build_calendar()
  3. 7 includes/calendar.inc \calendar_build_calendar()
  4. 7 calendar_multiday/includes/calendar.inc \calendar_build_calendar()
  5. 7.2 includes/calendar.inc \calendar_build_calendar()
  6. 7.2 calendar_multiday/includes/calendar.inc \calendar_build_calendar()

Build calendar

Parameters

unknown_type $view:

unknown_type $items:

unknown_type $params:

Return value

themed table

1 call to calendar_build_calendar()
theme_calendar_views_calendar in ./calendar.theme
Calendar Views plugin theme, overrides default views theme to create a calendar view.

File

./calendar.inc, line 196
All the code used while processing a calendar is stored in this file and is included only when needed.

Code

function calendar_build_calendar($view, $items, $params) {

  // Remove nodes outside the selected date range.
  $values = array();
  foreach ($items as $delta => $item) {
    if (empty($item->calendar_start_date) || empty($item->calendar_end_date)) {
      continue;
    }
    $item_start = date_format($item->calendar_start_date, DATE_FORMAT_DATE);
    $item_end = date_format($item->calendar_end_date, DATE_FORMAT_DATE);
    if ($item_start >= $view->min_date_date && $item_start <= $view->max_date_date || $item_end >= $view->min_date_date && $item_end <= $view->max_date_date) {
      $values[$item_start][$item_start][] = $item;
    }
  }
  $items = $values;
  ksort($items);
  $rows = array();
  $curday = drupal_clone($view->min_date);
  switch ($view->calendar_type) {
    case 'year':
      $rows = array();
      for ($i = 1; $i <= 12; $i++) {
        $rows[$i] = calendar_build_month($curday, $view, $items, $params);
      }
      break;
    case 'month':
      $rows = calendar_build_month($curday, $view, $items, $params);
      break;
    case 'day':
      $rows = calendar_build_day($curday, $view, $items, $params);
      break;
    case 'week':
      $rows = calendar_build_week($curday, $view, $items, $params);

      // Merge the day names in as the first row.
      if (!empty($view->mini)) {
        $len = variable_get('calendar_day_header_' . $view->name, 1);
      }
      else {
        $len = variable_get('calendar_full_day_header_' . $view->name, 3);
      }
      $rows = array_merge(array(
        calendar_week_header($view->mini, $params['with_weekno'], $len),
      ), $rows);
      break;
  }
  $output = theme('calendar_links', $view, $view->build_type != 'block');
  $output .= theme('calendar_nav', $view);
  $header = in_array($view->calendar_type, array(
    'month',
    'week',
  )) ? array_shift($rows) : array();
  $output .= theme('calendar_' . $view->calendar_type, $view, $header, $rows);
  return $output;
}