You are here

public function BookOutlineStorage::getBookSubtree in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/book/src/BookOutlineStorage.php \Drupal\book\BookOutlineStorage::getBookSubtree()

Get book subtree.

Parameters

array $link: A fully loaded book link.

int $max_depth: The maximum supported depth of the book tree.

Return value

array Array of unordered subtree book items.

Overrides BookOutlineStorageInterface::getBookSubtree

File

core/modules/book/src/BookOutlineStorage.php, line 193
Contains \Drupal\book\BookOutlineStorage.

Class

BookOutlineStorage
Defines a storage class for books outline.

Namespace

Drupal\book

Code

public function getBookSubtree($link, $max_depth) {
  $query = db_select('book', 'b', array(
    'fetch' => \PDO::FETCH_ASSOC,
  ));
  $query
    ->fields('b');
  $query
    ->condition('b.bid', $link['bid']);
  for ($i = 1; $i <= $max_depth && $link["p{$i}"]; ++$i) {
    $query
      ->condition("p{$i}", $link["p{$i}"]);
  }
  for ($i = 1; $i <= $max_depth; ++$i) {
    $query
      ->orderBy("p{$i}");
  }
  return $query
    ->execute();
}