3 namespace BookStack\Entities\Tools;
5 use BookStack\Entities\EntityProvider;
6 use BookStack\Entities\Models\Book;
7 use BookStack\Entities\Models\Bookshelf;
8 use Illuminate\Support\Collection;
13 * Search among the siblings of the entity of given type and id.
15 public function fetch(string $entityType, int $entityId): Collection
17 $entity = (new EntityProvider())->get($entityType)->visible()->findOrFail($entityId);
21 if ($entity->isA('page') && $entity->chapter) {
22 $entities = $entity->chapter->getVisiblePages();
25 // Page in book or chapter
26 if (($entity->isA('page') && !$entity->chapter) || $entity->isA('chapter')) {
27 $entities = $entity->book->getDirectChildren();
31 // Gets just the books in a shelf if shelf is in context
32 if ($entity->isA('book')) {
33 $contextShelf = (new ShelfContext())->getContextualShelfForBook($entity);
35 $entities = $contextShelf->visibleBooks()->get();
37 $entities = Book::visible()->get();
42 if ($entity->isA('bookshelf')) {
43 $entities = Bookshelf::visible()->get();