]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/ChapterRepo.php
Added restriction tests and fixed any bugs in the process
[bookstack] / app / Repos / ChapterRepo.php
index 90f2f8c543bf26a5c755afc66fa6d237c2f0ddf5..095596a608931f10ac1912e1e017fe403f72de96 100644 (file)
@@ -2,6 +2,7 @@
 
 
 use Activity;
+use BookStack\Exceptions\NotFoundException;
 use BookStack\Services\RestrictionService;
 use Illuminate\Support\Str;
 use BookStack\Chapter;
@@ -66,14 +67,24 @@ class ChapterRepo
      * @param $slug
      * @param $bookId
      * @return mixed
+     * @throws NotFoundException
      */
     public function getBySlug($slug, $bookId)
     {
         $chapter = $this->chapterQuery()->where('slug', '=', $slug)->where('book_id', '=', $bookId)->first();
-        if ($chapter === null) abort(404);
+        if ($chapter === null) throw new NotFoundException('Chapter not found');
         return $chapter;
     }
 
+    /**
+     * Get the child items for a chapter
+     * @param Chapter $chapter
+     */
+    public function getChildren(Chapter $chapter)
+    {
+        return $this->restrictionService->enforcePageRestrictions($chapter->pages())->get();
+    }
+
     /**
      * Create a new chapter from request input.
      * @param $input
@@ -98,6 +109,7 @@ class ChapterRepo
         }
         Activity::removeEntity($chapter);
         $chapter->views()->delete();
+        $chapter->restrictions()->delete();
         $chapter->delete();
     }