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

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

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;
  }
}