]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/EntityRepo.php
Add Slovak translation
[bookstack] / app / Repos / EntityRepo.php
index f1428735cc340149a3c33d0d3ed76e298cfe7f63..8f4b533ff29fc613bc1d2cd530839729550f87c1 100644 (file)
@@ -86,8 +86,7 @@ class EntityRepo
         $this->entities = [
             'page' => $this->page,
             'chapter' => $this->chapter,
-            'book' => $this->book,
-            'page_revision' => $this->pageRevision
+            'book' => $this->book
         ];
         $this->viewService = $viewService;
         $this->permissionService = $permissionService;
@@ -314,11 +313,12 @@ class EntityRepo
      * Loads the book slug onto child elements to prevent access database access for getting the slug.
      * @param Book $book
      * @param bool $filterDrafts
+     * @param bool $renderPages
      * @return mixed
      */
-    public function getBookChildren(Book $book, $filterDrafts = false)
+    public function getBookChildren(Book $book, $filterDrafts = false, $renderPages = false)
     {
-        $q = $this->permissionService->bookChildrenQuery($book->id, $filterDrafts)->get();
+        $q = $this->permissionService->bookChildrenQuery($book->id, $filterDrafts, $renderPages)->get();
         $entities = [];
         $parents = [];
         $tree = [];
@@ -326,18 +326,22 @@ class EntityRepo
         foreach ($q as $index => $rawEntity) {
             if ($rawEntity->entity_type === 'BookStack\\Page') {
                 $entities[$index] = $this->page->newFromBuilder($rawEntity);
+                if ($renderPages) {
+                    $entities[$index]->html = $rawEntity->description;
+                    $entities[$index]->html = $this->renderPage($entities[$index]);
+                };
             } else if ($rawEntity->entity_type === 'BookStack\\Chapter') {
                 $entities[$index] = $this->chapter->newFromBuilder($rawEntity);
                 $key = $entities[$index]->entity_type . ':' . $entities[$index]->id;
                 $parents[$key] = $entities[$index];
                 $parents[$key]->setAttribute('pages', collect());
             }
-            if ($entities[$index]->chapter_id === 0) $tree[] = $entities[$index];
+            if ($entities[$index]->chapter_id === 0 || $entities[$index]->chapter_id === '0') $tree[] = $entities[$index];
             $entities[$index]->book = $book;
         }
 
         foreach ($entities as $entity) {
-            if ($entity->chapter_id === 0) continue;
+            if ($entity->chapter_id === 0 || $entity->chapter_id === '0') continue;
             $parentKey = 'BookStack\\Chapter:' . $entity->chapter_id;
             $chapter = $parents[$parentKey];
             $chapter->pages->push($entity);
@@ -1054,7 +1058,7 @@ class EntityRepo
     public function restorePageRevision(Page $page, Book $book, $revisionId)
     {
         $this->savePageRevision($page);
-        $revision = $this->getById('page_revision', $revisionId);
+        $revision = $page->revisions()->where('id', '=', $revisionId)->first();
         $page->fill($revision->toArray());
         $page->slug = $this->findSuitableSlug('page', $page->name, $page->id, $book->id);
         $page->text = strip_tags($page->html);