You are here

public function BookOutlineStorage::getBookMenuTree in Zircon Profile 8

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

Builds tree data used for the menu tree.

Parameters

int $bid: The ID of the book that we are building the tree for.

array $parameters: An associative array of build parameters. For info about individual parameters see BookManager::bookTreeBuild().

int $min_depth: The minimum depth of book links in the resulting tree.

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

Return value

array Array of loaded book links.

Overrides BookOutlineStorageInterface::getBookMenuTree

File

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

Class

BookOutlineStorage
Defines a storage class for books outline.

Namespace

Drupal\book

Code

public function getBookMenuTree($bid, $parameters, $min_depth, $max_depth) {
  $query = $this->connection
    ->select('book');
  $query
    ->fields('book');
  for ($i = 1; $i <= $max_depth; $i++) {
    $query
      ->orderBy('p' . $i, 'ASC');
  }
  $query
    ->condition('bid', $bid);
  if (!empty($parameters['expanded'])) {
    $query
      ->condition('pid', $parameters['expanded'], 'IN');
  }
  if ($min_depth != 1) {
    $query
      ->condition('depth', $min_depth, '>=');
  }
  if (isset($parameters['max_depth'])) {
    $query
      ->condition('depth', $parameters['max_depth'], '<=');
  }

  // Add custom query conditions, if any were passed.
  if (isset($parameters['conditions'])) {
    foreach ($parameters['conditions'] as $column => $value) {
      $query
        ->condition($column, $value);
    }
  }
  return $query
    ->execute();
}