You are here

function calendar_nav in Calendar 5

Function to construct back and next navigation from views arguments

1 call to calendar_nav()
theme_calendar_show_nav in ./calendar.theme
Format the calendar navigation

File

./calendar.module, line 331
Adds calendar filtering and displays to Views.

Code

function calendar_nav($view, $mini = FALSE) {
  if (!calendar_part_is_valid($view->year, 'year')) {
    return array(
      $view->subtitle,
    );
  }
  calendar_load_date_api();
  if ($view->calendar_type == 'week' && calendar_part_is_valid($view->week, 'week')) {
    $range = calendar_week_range($view->year, $view->week + 1);
    $cur_stamp = $range[0];
  }
  else {
    $cur_stamp = date_gmmktime(array(
      'mon' => $view->month ? $view->month : 1,
      'mday' => $view->day ? $view->day : 1,
      'year' => $view->year ? $view->year : date_format_date("Y", date_time()),
    ));
  }

  // make the navigation into a header, with prev and next links
  // use the calendar_nav themes to mimic standard calendar navigation
  $paths = calendar_get_paths($cur_stamp, $view);
  $prev_path = implode('/', array_reverse($paths[0]));
  $next_path = implode('/', array_reverse($paths[1]));
  $prev_query = $next_query = array();
  if ($_GET['view']) {
    $prev_query[] = 'view=' . $_GET['view'];
    $next_query[] = 'view=' . $_GET['view'];
  }

  // for the mini calendar in a block, treat the url as a querystring to avoid actually changing the page
  if ($mini && $view->calendar_type == 'month') {
    $prev_query[] = 'mini=' . $prev_path;
    $prev_path = $_GET['q'];
    $next_query[] = 'mini=' . $next_path;
    $next_path = $_GET['q'];
  }
  $prev_query[] = calendar_url_append($view);
  $next_query[] = calendar_url_append($view);
  $header = array();
  $header[] = array(
    'data' => theme('calendar_nav_prev', $prev_path, $mini ? FALSE : TRUE, implode('&', $prev_query)),
    'class' => 'prev',
  );
  $header[] = array(
    'data' => $view->subtitle,
    'class' => 'heading',
    'colspan' => 5,
  );
  $header[] = array(
    'data' => theme('calendar_nav_next', $next_path, $mini ? FALSE : TRUE, implode('&', $next_query)),
    'class' => 'next',
  );
  return $header;
}