mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Expanded chapters interface and improved book/page deletion
This commit is contained in:
@ -44,21 +44,19 @@ class BookRepo
|
||||
return $this->book->where('slug', '=', $slug)->count();
|
||||
}
|
||||
|
||||
public function destroyById($id)
|
||||
public function destroyBySlug($bookSlug)
|
||||
{
|
||||
$book = $this->getById($id);
|
||||
foreach($book->pages as $page) {
|
||||
$this->pageRepo->destroyById($page->id);
|
||||
$book = $this->getBySlug($bookSlug);
|
||||
foreach($book->children() as $child) {
|
||||
$child->delete();
|
||||
}
|
||||
$book->delete();
|
||||
}
|
||||
|
||||
public function getTree($book, $currentPageId = false)
|
||||
public function getNewPriority($book)
|
||||
{
|
||||
$tree = $book->toArray();
|
||||
$tree['pages'] = $this->pageRepo->getTreeByBookId($book->id, $currentPageId);
|
||||
$tree['hasChildren'] = count($tree['pages']) > 0;
|
||||
return $tree;
|
||||
$lastElem = $book->children()->pop();
|
||||
return $lastElem ? $lastElem->priority + 1 : 0;
|
||||
}
|
||||
|
||||
}
|
@ -53,10 +53,10 @@ class ChapterRepo
|
||||
return $query->count() > 0;
|
||||
}
|
||||
|
||||
public function findSuitableSlug($name, $bookId)
|
||||
public function findSuitableSlug($name, $bookId, $currentId = false)
|
||||
{
|
||||
$slug = Str::slug($name);
|
||||
while($this->doesSlugExist($slug, $bookId)) {
|
||||
while($this->doesSlugExist($slug, $bookId, $currentId)) {
|
||||
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
|
||||
}
|
||||
return $slug;
|
||||
|
@ -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