I like the feature of jquerymenu for books, but i don't mind to use ALL BOOKS.... great plugin, but just for the browse of the current book is not effective. some way to display only the current book i'm reading??? thanks

Comments

nw’s picture

This feature has come up in several issue threads. I reply here only and leave it for the maintainers to deal with house keeping.

It is possible to have a jQuery menu for the current book by preprocessing the block output by the books module. I have done this in my dev environment in the template.php file. Anyone with basic theming knowledge and experience should be able to follow my code hint:

<?php

function template_preprocess_block(&$variables) {

    $block = &$variables['block'];

    if ($block->module == 'book') {
        $node = menu_get_object();
        $toplevel[] = $node->book['bid'];
        if (!empty($toplevel)) {
            $tree = recursive_book_array_builder($toplevel);
            $trail = book_trail_builder();
            if (empty($trail)) $trail = array();
            $block->content = theme('menu_creation_by_array', $tree, $trail);
        }
    }

}

?>

IMHO this solution should be added to the documentation for Advanced Book Blocks.

tlaurent’s picture

Hi nw,

Thanks for posting this solution, it was very helpful !
I had to make a slight change though to make it working: I had to replace
if ($block->module == 'book')
with
if ($block->module == 'advancedbookblocks')

HansKuiters’s picture

Works for me too, with the addition from tlaurent.

Additional workflow: you need to put all your books in one ABB, not an ABB for every book.

HansKuiters’s picture

Version: 6.x-1.9 » 6.x-2.5
Status: Active » Closed (fixed)
rootwork’s picture

georgemastro’s picture

This didn't work for me so I made a little hacking. If it works for other please tell me so I can make a patch.
One note is that I use it only to display the tree and not navigate through it. So this worked like a charm.

function books_get_top_level($d = NULL, $context = NULL) {
  $books = array();
  $result = '';
  if ($d == NULL && $context == NULL) {
    $query = db_select('book', 'b');
    $query->join('menu_links', 'm',  'm.mlid = b.mlid');
    $result = $query
      ->fields('b', array('bid'))
      ->fields('m', array('weight'))
      ->orderBy('m.weight', 'ASC')
      ->addTag('node_access')
      ->execute();
  }
  if ($d != NULL && $context == NULL) {
    $result = db_query("SELECT bid, weight FROM {adv_book_custom} WHERE delta = :delta ORDER BY weight ASC", array(':delta' => $d));
  }
  if ($d != NULL && $context == 'display') {
    if ($node = menu_get_object()) {
      $nid = $node->nid;
    }
    // We hack here because we only want the current book.
    // $result = db_query("SELECT bid, weight FROM {adv_book_custom} WHERE delta = :delta AND enabled = 1 ORDER BY weight ASC", array(':delta' => $d));
  }
  // foreach ($result as $book) {
    if (!in_array($nid, $books)) {
      $books[] = $nid;
    // }
  }
  return $books;
}