Chris@0: bookManager = $book_manager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Fetches the book link for the previous page of the book. Chris@0: * Chris@0: * @param array $book_link Chris@0: * A fully loaded book link that is part of the book hierarchy. Chris@0: * Chris@0: * @return array Chris@0: * A fully loaded book link for the page before the one represented in Chris@0: * $book_link. Chris@0: */ Chris@0: public function prevLink(array $book_link) { Chris@0: // If the parent is zero, we are at the start of a book. Chris@0: if ($book_link['pid'] == 0) { Chris@0: return NULL; Chris@0: } Chris@0: $flat = $this->bookManager->bookTreeGetFlat($book_link); Chris@14: reset($flat); Chris@0: $curr = NULL; Chris@0: do { Chris@0: $prev = $curr; Chris@14: $key = key($flat); Chris@14: $curr = current($flat); Chris@14: next($flat); Chris@0: } while ($key && $key != $book_link['nid']); Chris@0: Chris@0: if ($key == $book_link['nid']) { Chris@0: // The previous page in the book may be a child of the previous visible link. Chris@0: if ($prev['depth'] == $book_link['depth']) { Chris@0: // The subtree will have only one link at the top level - get its data. Chris@0: $tree = $this->bookManager->bookSubtreeData($prev); Chris@0: $data = array_shift($tree); Chris@0: // The link of interest is the last child - iterate to find the deepest one. Chris@0: while ($data['below']) { Chris@0: $data = end($data['below']); Chris@0: } Chris@0: $this->bookManager->bookLinkTranslate($data['link']); Chris@0: return $data['link']; Chris@0: } Chris@0: else { Chris@0: $this->bookManager->bookLinkTranslate($prev); Chris@0: return $prev; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Fetches the book link for the next page of the book. Chris@0: * Chris@0: * @param array $book_link Chris@0: * A fully loaded book link that is part of the book hierarchy. Chris@0: * Chris@0: * @return array Chris@0: * A fully loaded book link for the page after the one represented in Chris@0: * $book_link. Chris@0: */ Chris@0: public function nextLink(array $book_link) { Chris@0: $flat = $this->bookManager->bookTreeGetFlat($book_link); Chris@14: reset($flat); Chris@0: do { Chris@14: $key = key($flat); Chris@14: next($flat); Chris@0: } while ($key && $key != $book_link['nid']); Chris@0: Chris@0: if ($key == $book_link['nid']) { Chris@0: $next = current($flat); Chris@0: if ($next) { Chris@0: $this->bookManager->bookLinkTranslate($next); Chris@0: } Chris@0: return $next; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Formats the book links for the child pages of the current page. Chris@0: * Chris@0: * @param array $book_link Chris@0: * A fully loaded book link that is part of the book hierarchy. Chris@0: * Chris@0: * @return array Chris@0: * HTML for the links to the child pages of the current page. Chris@0: */ Chris@0: public function childrenLinks(array $book_link) { Chris@0: $flat = $this->bookManager->bookTreeGetFlat($book_link); Chris@0: Chris@0: $children = []; Chris@0: Chris@0: if ($book_link['has_children']) { Chris@0: // Walk through the array until we find the current page. Chris@0: do { Chris@0: $link = array_shift($flat); Chris@0: } while ($link && ($link['nid'] != $book_link['nid'])); Chris@0: // Continue though the array and collect the links whose parent is this page. Chris@0: while (($link = array_shift($flat)) && $link['pid'] == $book_link['nid']) { Chris@0: $data['link'] = $link; Chris@0: $data['below'] = ''; Chris@0: $children[] = $data; Chris@0: } Chris@0: } Chris@0: Chris@0: if ($children) { Chris@0: return $this->bookManager->bookTreeOutput($children); Chris@0: } Chris@0: return ''; Chris@0: } Chris@0: Chris@0: }