function book_prev in Drupal 4
Same name and namespace in other branches
- 5 modules/book/book.module \book_prev()
- 6 modules/book/book.module \book_prev()
- 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.module - Prepares the links to children (TOC) and forward/backward navigation for a node presented as a book page.
File
- modules/
book.module, line 390 - 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 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.vid = b.vid WHERE n.nid = %d AND n.status = 1 AND n.moderate = 0'), $node->parent));
return $prev;
}
}