1 <?php namespace BookStack\Entities\Tools;
3 use BookStack\Entities\Models\Book;
4 use BookStack\Entities\Models\Bookshelf;
8 protected $KEY_SHELF_CONTEXT_ID = 'context_bookshelf_id';
11 * Get the current bookshelf context for the given book.
13 public function getContextualShelfForBook(Book $book): ?Bookshelf
15 $contextBookshelfId = session()->get($this->KEY_SHELF_CONTEXT_ID, null);
17 if (!is_int($contextBookshelfId)) {
21 $shelf = Bookshelf::visible()->find($contextBookshelfId);
22 $shelfContainsBook = $shelf && $shelf->contains($book);
24 return $shelfContainsBook ? $shelf : null;
28 * Store the current contextual shelf ID.
30 public function setShelfContext(int $shelfId)
32 session()->put($this->KEY_SHELF_CONTEXT_ID, $shelfId);
36 * Clear the session stored shelf context id.
38 public function clearShelfContext()
40 session()->forget($this->KEY_SHELF_CONTEXT_ID);