[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/calendar/includes/ -> calendar.inc (source)

   1  <?php
   2  //$Id: calendar.inc,v 1.1.2.46 2010/11/28 23:31:28 karens Exp $
   3  /**
   4   * Build calendar
   5   *
   6   * @param unknown_type $view
   7   * @param unknown_type $items
   8   * @return themed table
   9   */
  10  function calendar_build_calendar($view, $items) {
  11    // Remove nodes outside the selected date range.
  12    $values = array();
  13    foreach ($items as $delta => $item) {
  14      if (empty($item->calendar_start_date) || empty($item->calendar_end_date)) {
  15        continue;
  16      }
  17      $item_start = date_format($item->calendar_start_date, DATE_FORMAT_DATE);
  18      $item_end = date_format($item->calendar_end_date, DATE_FORMAT_DATE);
  19      if (($item_start >= $view->date_info->min_date_date && $item_start <= $view->date_info->max_date_date)
  20       || ($item_end >= $view->date_info->min_date_date && $item_end <= $view->date_info->max_date_date)) {
  21         $values[$item_start][date_format($item->calendar_start_date, 'H:i:s')][] = $item;
  22      }
  23    }
  24    $items = $values;
  25    ksort($items);
  26    
  27    $rows = array();
  28    $curday = drupal_clone($view->date_info->min_date);
  29    
  30    switch ($view->date_info->granularity) {
  31      case 'year':
  32        $rows = array();
  33        $view->date_info->mini = TRUE;
  34        for ($i = 1; $i <= 12; $i++) {
  35          $rows[$i] = calendar_build_month($curday, $view, $items);
  36        }
  37        $view->date_info->mini = FALSE;
  38        break;
  39  
  40      case 'month':
  41        $rows = calendar_build_month($curday, $view, $items);
  42        break;
  43  
  44      case 'day':
  45        $rows = calendar_build_day($curday, $view, $items);
  46        break;
  47  
  48      case 'week':
  49        $rows = calendar_build_week($curday, $view, $items);
  50  
  51        // Merge the day names in as the first row.
  52        $rows = array_merge(array(calendar_week_header($view)), $rows);
  53        break;
  54    }
  55    return $rows;
  56    
  57  }
  58  
  59  /**
  60   * Build one month.
  61   */
  62  function calendar_build_month(&$curday, $view, $items) {
  63    $month = date_format($curday, 'n');
  64    date_modify($curday, '-' . strval(date_format($curday, 'j')-1) . ' days');
  65  
  66    $rows = array();
  67    do {
  68      $rows = array_merge($rows, calendar_build_week($curday, $view, $items, TRUE));
  69      $curday_date = date_format($curday, DATE_FORMAT_DATE);
  70      $curday_month = date_format($curday, 'n');
  71    } while ($curday_month == $month && $curday_date <= $view->date_info->max_date_date);
  72  
  73    // Merge the day names in as the first row.
  74    $rows = array_merge(array(calendar_week_header($view)), $rows);
  75    return $rows;
  76  }
  77  
  78  /**
  79   * Build one week row.
  80   */
  81  function calendar_build_week(&$curday, $view, $items, $check_month = FALSE) {
  82    $curday_date = date_format($curday, DATE_FORMAT_DATE);
  83    $weekdays = calendar_untranslated_days($items, $view);
  84    $today = date_format(date_now(date_default_timezone_name()), DATE_FORMAT_DATE);
  85    $month = date_format($curday, 'n');
  86    $week = date_week($curday_date);
  87    $first_day = variable_get('date_first_day', 0);
  88  
  89    // move backwards to the first day of the week
  90    $day_wday = date_format($curday, 'w');
  91    date_modify($curday, '-' . strval((7 + $day_wday - $first_day) % 7) . ' days');
  92    $curday_date = date_format($curday, DATE_FORMAT_DATE);
  93      
  94    // If we're displaying the week number, add it as the
  95    // first cell in the week.
  96    if (!empty($view->date_info->style_with_weekno) && !in_array($view->date_info->granularity, array('day', 'week'))) {
  97      $url = date_real_url($view, NULL, $view->date_info->year .'-W'. $week);
  98      if (!empty($view->date_info->display_types['week'])) {
  99        $weekno = l($week, $url, array('query' => !empty($view->date_info->append) ? $view->date_info->append : ''));
 100      }
 101      else { 
 102        // Do not link week numbers, if Week views are disabled.
 103        $weekno = $week;
 104      }
 105      $rows[$week][] = array(
 106        'data' => $weekno,
 107        'id' => $view->name . '-weekno-' . $curday_date,  
 108        'class' => 'week');
 109    }
 110    for ($i = 0; $i < 7; $i++) {
 111      $curday_date = date_format($curday, DATE_FORMAT_DATE); 
 112      $class = strtolower($weekdays[$i] .
 113      ($view->date_info->mini ? ' mini' : ''));
 114      if ($check_month && ($curday_date < $view->date_info->min_date_date || $curday_date > $view->date_info->max_date_date || date_format($curday, 'n') != $month)) {
 115        $class .= ' empty';
 116        $content = array(
 117          'date' => '', 
 118          'datebox' => '', 
 119          'empty' => theme('calendar_empty_day', $curday_date, $view), 
 120          'link' => '',
 121          'all_day' => array(), 
 122          'items' => array(),
 123          );
 124      }
 125      else {
 126        $content = calendar_build_day($curday, $view, $items);
 127        $class .= ($curday_date == $today ? ' today' : '') .
 128          ($curday_date < $today ? ' past' : '') .
 129          ($curday_date > $today ? ' future' : '') .
 130          (empty($items[$curday_date]) ? ' has-no-events' : ' has-events');
 131      }
 132      
 133      $rows[$week][] = array(
 134        'data' => $content,
 135        'class' => $class, 'id' => $view->name . '-' . $curday_date);
 136      date_modify($curday, '+1 day');
 137    }
 138    return $rows;
 139  }
 140  
 141  /**
 142   * Build the contents of a single day for the $rows results.
 143   */
 144  function calendar_build_day($curday, $view, $items) {
 145    $curday_date = date_format($curday, DATE_FORMAT_DATE);
 146    $selected = FALSE;
 147    $max_events = !empty($view->date_info->style_max_items) ? $view->date_info->style_max_items : 0;
 148    $types = array();
 149    $inner = array();
 150    $all_day = array();
 151    $empty = '';
 152    $link = '';
 153    $count = 0;
 154    foreach ($items as $date => $day) {
 155      if ($date == $curday_date) {
 156        $count = 0;
 157        $selected = TRUE;
 158        ksort($day);
 159        foreach ($day as $time => $hour) {
 160          foreach ($hour as $key => $item) {
 161            $count++;
 162            $types[$item->type] = $item;
 163            if (!$view->date_info->mini && ($max_events == CALENDAR_SHOW_ALL || $count <= $max_events || ($count > 0 && $max_events == CALENDAR_HIDE_ALL))) {
 164              // Theme the item here unless this is a 'Day' or 'Week' view.
 165              // Day and week views need to do more processing before rendering
 166              // the item, so just past them the unrendered item.
 167              $theme = isset($item->calendar_node_theme) ? $item->calendar_node_theme : 'calendar_'. $view->date_info->granularity .'_node';
 168              if ($item->calendar_all_day) {
 169                $all_day[] = in_array($view->date_info->calendar_type, array('day', 'week')) ? $item : theme($theme, $item, $view);
 170              }
 171              else {
 172                $key = date_format($item->calendar_start_date, 'H:i:s');
 173                $inner[$key][] = in_array($view->date_info->calendar_type, array('day', 'week')) ? $item : theme($theme, $item, $view);
 174              }
 175            }
 176          }
 177        }
 178      }
 179    }
 180    ksort($inner);
 181    if (empty($inner) && empty($all_day)) {
 182      $empty = theme('calendar_empty_day', $curday_date, $view);
 183    }
 184    // We have hidden events on this day, use the theme('calendar_multiple_') to show a link.
 185    if ($max_events != CALENDAR_SHOW_ALL && $count > 0 && $count > $max_events && $view->date_info->calendar_type != 'day' && !$view->date_info->mini) {
 186      if ($view->date_info->style_max_items_behavior == 'hide' || $max_events == CALENDAR_HIDE_ALL) {
 187        $all_day = array();
 188        $inner = array();
 189      }
 190      $link = theme('calendar_'. $view->date_info->calendar_type .'_multiple_node', $curday_date, $count, $view, $types);
 191    }
 192      
 193    $content = array(
 194      'date' => $curday_date, 
 195      'datebox' => theme('calendar_datebox', $curday_date, $view, $items, $selected), 
 196      'empty' => $empty,
 197      'link' => $link,
 198      'all_day' => $all_day,
 199      'items' => $inner,
 200      );
 201    return $content;
 202  }
 203  


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7