You are here

function _event_nav in Event 5

Same name and namespace in other branches
  1. 5.2 event.module \_event_nav()

Build the navigation links for the calendar views

Parameters

$date The GMT date we are viewing:

$dir The 'direction' we want (prev or next):

$view The view we are navigating, month, week, day or table:

$types The content types to filter by:

$terms The taxonomy terms to filter by:

$duration The duration of the current view in multiples of view type:

Return value

Themed navigation link.

Related topics

2 calls to _event_nav()
event_calendar_month in ./event.module
Displays a monthly event calendar.
event_page in ./event.module
Displays a page containing event information. The page layout defaults to a graphical calendar.

File

./event.module, line 1588

Code

function _event_nav($date, $dir, $view, $types, $terms, $duration = NULL) {

  // first, retrieve the stored timestamp of the first/last event
  $range = variable_get('event_range_' . $dir, -1);

  // If the variable isn't set, set it and try again
  if ($range == -1) {
    event_set_range();
    $range = variable_get('event_range_' . $dir, $date);
  }

  // if we are beyond the range of the stored events, dont display navigation
  if ($dir == 'prev' && $range < $date || $dir == 'next' && $range > $date) {
    $inc = $dir == 'prev' ? -1 : 1;
    $duration = $duration ? $duration : 1;

    // we have to separeate block navigation from normal month view
    // what happens with $attributes if its not declared? its still passed to theme below
    if ($view == 'block') {
      $view = 'month';
      $attributes = array(
        'class' => 'updateblock',
      );
    }
    switch ($view) {
      case 'day':
      case 'table':

        // Increment by $duration*days
        $date += $inc * ($duration * 86400);
        break;
      case 'week':

        // Increment by $duration*weeks
        $date += $inc * ($duration * (86400 * 7));
        break;
      case 'month':

        // Increment by $duration*months
        $date = gmmktime(0, 0, 0, gmdate('m', $date) + $duration * $inc, 1, gmdate('Y', $date));
        break;
    }
    $url[] = 'event';
    $url[] = gmdate('Y', $date);
    $url[] = gmdate('m', $date);
    $url[] = gmdate('d', $date);
    $url[] = $view;
    $url[] = $types ? implode('+', $types) : 'all';
    $url[] = $terms ? implode('+', $terms) : 'all';
    $url[] = $duration;
    return theme('event_nav_' . $dir, implode('/', $url), $attributes);
  }
}