X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/876bc10d4d414c0680ea13e008b764c3ee70060f..refs/pull/5313/head:/app/Entities/Tools/SiblingFetcher.php diff --git a/app/Entities/Tools/SiblingFetcher.php b/app/Entities/Tools/SiblingFetcher.php index 617ef4a62..156209fd2 100644 --- a/app/Entities/Tools/SiblingFetcher.php +++ b/app/Entities/Tools/SiblingFetcher.php @@ -7,10 +7,17 @@ use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Bookshelf; use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Page; +use BookStack\Entities\Queries\EntityQueries; use Illuminate\Support\Collection; class SiblingFetcher { + public function __construct( + protected EntityQueries $queries, + protected ShelfContext $shelfContext, + ) { + } + /** * Search among the siblings of the entity of given type and id. */ @@ -26,23 +33,23 @@ class SiblingFetcher // Page in book or chapter if (($entity instanceof Page && !$entity->chapter) || $entity instanceof Chapter) { - $entities = $entity->book->getDirectChildren(); + $entities = $entity->book->getDirectVisibleChildren(); } // Book // Gets just the books in a shelf if shelf is in context if ($entity instanceof Book) { - $contextShelf = (new ShelfContext())->getContextualShelfForBook($entity); + $contextShelf = $this->shelfContext->getContextualShelfForBook($entity); if ($contextShelf) { $entities = $contextShelf->visibleBooks()->get(); } else { - $entities = Book::visible()->get(); + $entities = $this->queries->books->visibleForList()->orderBy('name', 'asc')->get(); } } // Shelf if ($entity instanceof Bookshelf) { - $entities = Bookshelf::visible()->get(); + $entities = $this->queries->shelves->visibleForList()->orderBy('name', 'asc')->get(); } return $entities;