Expanded chapters interface and improved book/page deletion

This commit is contained in:
Dan Brown
2015-07-28 20:57:13 +01:00
parent b9df3c647a
commit fd1a0dceb2
19 changed files with 282 additions and 141 deletions

View File

@ -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