1.12.x book.module book_get_books()
1.10.x book.module book_get_books()
1.11.x book.module book_get_books()
1.7.x book.module book_get_books()
1.8.x book.module book_get_books()
1.9.x book.module 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.

Return value

An array of all books.

File

modules/book/book.module, line 345
Allows users to create and organize related content in an outline.

Code

function book_get_books() {
  $all_books = &backdrop_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));
      $query->join('node', 'n', 'b.nid = n.nid');
      $query->join('menu_links', 'ml', 'b.mlid = ml.mlid');
      $query->addField('n', 'type', 'type');
      $query->addField('n', 'title', 'title');
      $query->fields('b');
      $query->fields('ml');
      $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;
}