You are here

function calendar_build_week in Calendar 7.2

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

Build one week row.

4 calls to calendar_build_week()
calendar_build_calendar in includes/calendar.inc
Build calendar
calendar_build_calendar in calendar_multiday/includes/calendar.inc
Build calendar
calendar_build_month in includes/calendar.inc
Build one month.
calendar_build_month in calendar_multiday/includes/calendar.inc
Build one month.

File

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

Code

function calendar_build_week(&$curday, $view, $items, $check_month = FALSE) {
  $curday_date = date_format($curday, DATE_FORMAT_DATE);
  $weekdays = calendar_untranslated_days($items, $view);
  $today = date_format(date_now(date_default_timezone()), DATE_FORMAT_DATE);
  $month = date_format($curday, 'n');
  $week = date_week($curday_date);
  $first_day = variable_get('date_first_day', 1);

  // move backwards to the first day of the week
  $day_wday = date_format($curday, 'w');
  date_modify($curday, '-' . strval((7 + $day_wday - $first_day) % 7) . ' days');
  $curday_date = date_format($curday, DATE_FORMAT_DATE);

  // If we're displaying the week number, add it as the
  // first cell in the week.
  if (!empty($view->date_info->style_with_weekno) && !in_array($view->date_info->granularity, array(
    'day',
    'week',
  ))) {
    $url = date_real_url($view, NULL, $view->date_info->year . '-W' . $week);
    if (!empty($view->date_info->display_types['week'])) {
      $weekno = l($week, $url, array(
        'query' => !empty($view->date_info->append) ? $view->date_info->append : '',
      ));
    }
    else {

      // Do not link week numbers, if Week views are disabled.
      $weekno = $week;
    }
    $rows[$week][] = array(
      'data' => $weekno,
      'id' => $view->name . '-weekno-' . $curday_date,
      'class' => 'week',
    );
  }
  for ($i = 0; $i < 7; $i++) {
    $curday_date = date_format($curday, DATE_FORMAT_DATE);
    $class = strtolower($weekdays[$i] . ($view->date_info->mini ? ' mini' : ''));
    if ($check_month && ($curday_date < $view->date_info->min_date_date || $curday_date > $view->date_info->max_date_date || date_format($curday, 'n') != $month)) {
      $class .= ' empty';
      $variables = array(
        'curday' => $curday_date,
        'view' => $view,
      );
      $content = array(
        'date' => '',
        'datebox' => '',
        'empty' => theme('calendar_empty_day', $variables),
        'link' => '',
        'all_day' => array(),
        'items' => array(),
      );
    }
    else {
      $content = calendar_build_day($curday, $view, $items);
      $class .= ($curday_date == $today ? ' today' : '') . ($curday_date < $today ? ' past' : '') . ($curday_date > $today ? ' future' : '');
    }
    $rows[$week][] = array(
      'data' => $content,
      'class' => $class,
      'id' => $view->name . '-' . $curday_date,
    );
    date_modify($curday, '+1 day');
  }
  return $rows;
}