]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/BookRepo.php
Expanded chapters interface and improved book/page deletion
[bookstack] / app / Repos / BookRepo.php
index c43f449b0cb87648068faecf52f56650ce85021a..b98ed9abad59a60f37f253aa335de0e06bd53307 100644 (file)
@@ -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;
     }
 
 }
\ No newline at end of file