You are here

public function BookOutlineStorage::getChildRelativeDepth in Zircon Profile 8

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

Gets child relative depth.

Parameters

array $book_link: The book link.

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

Return value

int The depth of the searched book.

Overrides BookOutlineStorageInterface::getChildRelativeDepth

File

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

Class

BookOutlineStorage
Defines a storage class for books outline.

Namespace

Drupal\book

Code

public function getChildRelativeDepth($book_link, $max_depth) {
  $query = $this->connection
    ->select('book');
  $query
    ->addField('book', 'depth');
  $query
    ->condition('bid', $book_link['bid']);
  $query
    ->orderBy('depth', 'DESC');
  $query
    ->range(0, 1);
  $i = 1;
  $p = 'p1';
  while ($i <= $max_depth && $book_link[$p]) {
    $query
      ->condition($p, $book_link[$p]);
    $p = 'p' . ++$i;
  }
  return $query
    ->execute()
    ->fetchField();
}