You are here

function book_prev in Drupal 5

Same name and namespace in other branches
  1. 4 modules/book.module \book_prev()
  2. 6 modules/book/book.module \book_prev()
  3. 7 modules/book/book.module \book_prev()

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

1 call to book_prev()
theme_book_navigation in modules/book/book.module
Prepares the links to children (TOC) and forward/backward navigation for a node presented as a book page.

File

modules/book/book.module, line 368
Allows users to collaboratively author a book.

Code

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.vid = b.vid WHERE b.parent = %d AND n.status = 1 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.vid = b.vid WHERE n.nid = %d AND n.status = 1'), $node->parent));
    return $prev;
  }
}