You are here

function calendar_build_mini_week in Calendar 7

Same name and namespace in other branches
  1. 6.2 calendar_multiday/includes/calendar.inc \calendar_build_mini_week()
  2. 7.2 calendar_multiday/includes/calendar.inc \calendar_build_mini_week()

Build one week row.

1 call to calendar_build_mini_week()
calendar_build_mini_month in calendar_multiday/includes/calendar.inc
Build one month.

File

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

Code

function calendar_build_mini_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', 0);

  // 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] . ' 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' : '') . (empty($items[$curday_date]) ? ' has-no-events' : ' has-events');
    }
    $rows[$week][] = array(
      'data' => $content,
      'class' => $class,
      'id' => $view->name . '-' . $curday_date,
    );
    date_modify($curday, '+1 day');
  }
  return $rows;
}