You are here

function calendar_build_day in Calendar 7.2

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

Build the contents of a single day for the $rows results.

4 calls to calendar_build_day()
calendar_build_calendar in includes/calendar.inc
Build calendar
calendar_build_calendar in calendar_multiday/includes/calendar.inc
Build calendar
calendar_build_mini_week in calendar_multiday/includes/calendar.inc
Build one week row.
calendar_build_week in includes/calendar.inc
Build one week row.

File

includes/calendar.inc, line 148
Calendar building functions for the Calendar module.

Code

function calendar_build_day($curday, $view, $items) {
  $curday_date = date_format($curday, DATE_FORMAT_DATE);
  $selected = FALSE;
  $max_events = !empty($view->date_info->style_max_items) ? $view->date_info->style_max_items : 0;
  $types = array();
  $inner = array();
  $all_day = array();
  $empty = '';
  $link = '';
  $count = 0;
  foreach ($items as $date => $day) {
    if ($date == $curday_date) {
      $count = 0;
      $selected = TRUE;
      ksort($day);
      foreach ($day as $time => $hour) {
        foreach ($hour as $key => $item) {
          $count++;

          // @TODO $node->type may or may not exist any more, or be relevant.
          // Dig into the theme code to either remove it or get it working differently.
          if (isset($item->type)) {
            $types[$item->type] = $item;
          }
          if (!$view->date_info->mini && (empty($max_events) || $max_events > 0 && $count <= $max_events)) {

            // Theme the item here unless this is a 'Day' or 'Week' view.
            // Day and week views need to do more processing before rendering
            // the item, so just past them the unrendered item.
            $theme = isset($item->calendar_node_theme) ? $item->calendar_node_theme : 'calendar_' . $view->date_info->granularity . '_node';
            $variables = array(
              'node' => $item,
              'view' => $view,
            );
            if ($item->calendar_all_day) {
              $all_day[] = in_array($view->date_info->calendar_type, array(
                'day',
                'week',
              )) ? $item : theme($theme, $variables);
            }
            else {
              $key = date_format($item->calendar_start_date, 'H:i:s');
              $inner[$key][] = in_array($view->date_info->calendar_type, array(
                'day',
                'week',
              )) ? $item : theme($theme, $variables);
            }
          }
        }
      }
    }
  }
  ksort($inner);
  if (empty($inner) && empty($all_day)) {
    $variables = array(
      'curday' => $curday_date,
      'view' => $view,
    );
    $empty = theme('calendar_empty_day', $variables);
  }

  // we have too many events on this day. use the theme('calendar_multiple_')
  if ($max_events > 0 && $count > $max_events && $view->date_info->calendar_type != 'day' && !$view->date_info->mini) {
    $variables = array(
      'curday' => $curday_date,
      'count' => $count,
      'view' => $view,
      'types' => $types,
    );
    if ($view->date_info->style_max_items_behavior == 'hide') {
      $inner = array();
    }
    $link = theme('calendar_' . $view->date_info->calendar_type . '_multiple_node', $variables);
  }
  $variables = array(
    'date' => $curday_date,
    'view' => $view,
    'items' => $items,
    'selected' => $selected,
  );
  $content = array(
    'date' => $curday_date,
    'datebox' => theme('calendar_datebox', $variables),
    'empty' => $empty,
    'link' => $link,
    'all_day' => $all_day,
    'items' => $inner,
  );
  return $content;
}