You are here

function prev_next_views_prev_next_nid in Previous/Next API 6

Same name and namespace in other branches
  1. 7.2 prev_next_views.module \prev_next_views_prev_next_nid()
  2. 7 prev_next_views.module \prev_next_views_prev_next_nid()

Implementation of hook_prev_next_nid().

File

./prev_next_views.module, line 6

Code

function prev_next_views_prev_next_nid($nid, $op = 'next') {
  if (isset($_SESSION['prev_next_views'])) {

    // There's a prev_next views list stored for this session
    $index = array_search($nid, $_SESSION['prev_next_views']);
    if ($index !== FALSE) {

      // This node is part of the prev_next list, so return the appropriate node
      $ret = $index;
      if ($op == 'prev') {
        $ret--;
      }
      elseif ($op == 'next') {
        $ret++;
      }
      if ($ret >= 0 && $ret < count($_SESSION['prev_next_views'])) {
        return $_SESSION['prev_next_views'][$ret];
      }
      else {

        // First or last element of the view
        return 0;
      }
    }
  }
  return FALSE;
}