book_prev

Versions
4.6 – 5
book_prev($node)
6 – 7
book_prev($book_link)

Fetch the node object of the previous page of the book.

▾ 1 function calls book_prev()

theme_book_navigation in modules/book.module
Prepares both the custom breadcrumb trail and the forward/backward navigation for a node presented as a book page.

Code

modules/book.module, line 331

<?php
function book_prev($node) {
  // If the parent is zero, we are at the start of a book so there is no previous.
  if ($node->parent == 0) {
    return NULL;
  }

  // Previous on the same level:
  $direct_above = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND n.moderate = 0 AND (b.weight < %d OR (b.weight = %d AND n.title < '%s')) ORDER BY b.weight DESC, n.title DESC"), $node->parent, $node->weight, $node->weight, $node->title));
  if ($direct_above) {
    // Get last leaf of $above.
    $path = book_location_down($direct_above);

    return $path ? (count($path) > 0 ? array_pop($path) : NULL) : $direct_above;
  }
  else {
    // Direct parent:
    $prev = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d AND n.status = 1 AND n.moderate = 0'), $node->parent));
    return $prev;
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.