1 <?php namespace BookStack\Entities\Tools;
3 use BookStack\Entities\EntityProvider;
4 use BookStack\Entities\Models\Book;
5 use BookStack\Entities\Models\Bookshelf;
6 use Illuminate\Support\Collection;
12 * Search among the siblings of the entity of given type and id.
14 public function fetch(string $entityType, int $entityId): Collection
16 $entity = (new EntityProvider)->get($entityType)->visible()->findOrFail($entityId);
20 if ($entity->isA('page') && $entity->chapter) {
21 $entities = $entity->chapter->getVisiblePages();
24 // Page in book or chapter
25 if (($entity->isA('page') && !$entity->chapter) || $entity->isA('chapter')) {
26 $entities = $entity->book->getDirectChildren();
30 // Gets just the books in a shelf if shelf is in context
31 if ($entity->isA('book')) {
32 $contextShelf = (new ShelfContext)->getContextualShelfForBook($entity);
34 $entities = $contextShelf->visibleBooks()->get();
36 $entities = Book::visible()->get();
41 if ($entity->isA('bookshelf')) {
42 $entities = Bookshelf::visible()->get();