3 namespace BookStack\Entities\Tools;
5 use BookStack\Entities\Models\Book;
6 use BookStack\Entities\Models\Bookshelf;
10 protected $KEY_SHELF_CONTEXT_ID = 'context_bookshelf_id';
13 * Get the current bookshelf context for the given book.
15 public function getContextualShelfForBook(Book $book): ?Bookshelf
17 $contextBookshelfId = session()->get($this->KEY_SHELF_CONTEXT_ID, null);
19 if (!is_int($contextBookshelfId)) {
23 /** @var Bookshelf $shelf */
24 $shelf = Bookshelf::visible()->find($contextBookshelfId);
25 $shelfContainsBook = $shelf && $shelf->contains($book);
27 return $shelfContainsBook ? $shelf : null;
31 * Store the current contextual shelf ID.
33 public function setShelfContext(int $shelfId)
35 session()->put($this->KEY_SHELF_CONTEXT_ID, $shelfId);
39 * Clear the session stored shelf context id.
41 public function clearShelfContext()
43 session()->forget($this->KEY_SHELF_CONTEXT_ID);