mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-01 05:51:52 +08:00
Expanded chapters interface and improved book/page deletion
This commit is contained in:
@ -70,44 +70,6 @@ class PageRepo
|
||||
return count($tree) > 0 ? array_reverse($tree) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a tree of child pages, Nested by their
|
||||
* set parent pages.
|
||||
* @param $bookId
|
||||
* @param bool $currentPageId
|
||||
* @return array
|
||||
*/
|
||||
public function getTreeByBookId($bookId, $currentPageId = false)
|
||||
{
|
||||
$topLevelPages = $this->getTopLevelPages($bookId);
|
||||
$pageTree = [];
|
||||
|
||||
foreach($topLevelPages as $key => $topPage) {
|
||||
$pageTree[$key] = $this->toArrayTree($topPage, $currentPageId);
|
||||
}
|
||||
|
||||
return $pageTree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a page tree array with the supplied page
|
||||
* as the parent of the tree.
|
||||
* @param $page
|
||||
* @param bool $currentPageId
|
||||
* @return mixed
|
||||
*/
|
||||
private function toArrayTree($page, $currentPageId = false)
|
||||
{
|
||||
$cPage = $page->toSimpleArray();
|
||||
$cPage['current'] = ($currentPageId !== false && $cPage['id'] === $currentPageId);
|
||||
$cPage['pages'] = [];
|
||||
foreach($page->children as $key => $childPage) {
|
||||
$cPage['pages'][$key] = $this->toArrayTree($childPage, $currentPageId);
|
||||
}
|
||||
$cPage['hasChildren'] = count($cPage['pages']) > 0;
|
||||
return $cPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pages at the top of the page hierarchy.
|
||||
* @param $bookId
|
||||
|
Reference in New Issue
Block a user