book_get_books

Versions
6 – 7
book_get_books()

Returns an array of all books.

This list may be used for generating a list of all the books, or for building the options for a form select.

▾ 4 functions call book_get_books()

book_admin_overview in modules/book/book.admin.inc
Returns an administrative overview of all books.
book_block_view in modules/book/book.module
Implement hook_block_view().
book_render in modules/book/book.pages.inc
Menu callback; prints a listing of all books.
_book_add_form_elements in modules/book/book.module
Build the common elements of the book form for the node and outline forms.

Code

modules/book/book.module, line 349

<?php
function book_get_books() {
  $all_books = &drupal_static(__FUNCTION__);

  if (!isset($all_books)) {
    $all_books = array();
    $nids = db_query("SELECT DISTINCT(bid) FROM {book}")->fetchCol();

    if ($nids) {
      $query = db_select('book', 'b', array('fetch' => PDO::FETCH_ASSOC));
      $node_alias = $query->join('node', 'n', 'b.nid = n.nid');
      $menu_links_alias = $query->join('menu_links', 'ml', 'b.mlid = ml.mlid');
      $query->addField('n', 'type', 'type');
      $query->addField('n', 'title', 'title');
      $query->fields('b');
      $query->fields($menu_links_alias);
      $query->condition('n.nid', $nids, 'IN');
      $query->condition('n.status', 1);
      $query->orderBy('ml.weight');
      $query->orderBy('ml.link_title');
      $query->addTag('node_access');
      $result2 = $query->execute();
      foreach ($result2 as $link) {
        $link['href'] = $link['link_path'];
        $link['options'] = unserialize($link['options']);
        $all_books[$link['bid']] = $link;
      }
    }
  }

  return $all_books;
}
?>
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.