X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/79f6dc00a366fbb318ac70db7ec1128615482655..refs/pull/1695/head:/app/Http/Controllers/BookshelfController.php diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index dba2503ef..bef96dd01 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -40,9 +40,9 @@ class BookshelfController extends Controller */ public function index() { - $view = setting()->getUser($this->currentUser, 'bookshelves_view_type', config('app.views.bookshelves', 'grid')); - $sort = setting()->getUser($this->currentUser, 'bookshelves_sort', 'name'); - $order = setting()->getUser($this->currentUser, 'bookshelves_sort_order', 'asc'); + $view = setting()->getForCurrentUser('bookshelves_view_type', config('app.views.bookshelves', 'grid')); + $sort = setting()->getForCurrentUser('bookshelves_sort', 'name'); + $order = setting()->getForCurrentUser('bookshelves_sort_order', 'asc'); $sortOptions = [ 'name' => trans('common.sort_name'), 'created_at' => trans('common.sort_created_at'), @@ -54,7 +54,7 @@ class BookshelfController extends Controller $shelf->books = $this->entityRepo->getBookshelfChildren($shelf); } - $recents = $this->signedIn ? $this->entityRepo->getRecentlyViewed('bookshelf', 4, 0) : false; + $recents = $this->isSignedIn() ? $this->entityRepo->getRecentlyViewed('bookshelf', 4, 0) : false; $popular = $this->entityRepo->getPopular('bookshelf', 4, 0); $new = $this->entityRepo->getRecentlyCreated('bookshelf', 4, 0); @@ -116,7 +116,7 @@ class BookshelfController extends Controller public function show(string $slug) { /** @var Bookshelf $shelf */ - $shelf = $this->entityRepo->getBySlug('bookshelf', $slug); + $shelf = $this->entityRepo->getEntityBySlug('bookshelf', $slug); $this->checkOwnablePermission('book-view', $shelf); $books = $this->entityRepo->getBookshelfChildren($shelf); @@ -124,6 +124,7 @@ class BookshelfController extends Controller $this->entityContextManager->setShelfContext($shelf->id); $this->setPageTitle($shelf->getShortName()); + return view('shelves.show', [ 'shelf' => $shelf, 'books' => $books, @@ -139,7 +140,7 @@ class BookshelfController extends Controller */ public function edit(string $slug) { - $shelf = $this->entityRepo->getBySlug('bookshelf', $slug); /** @var $shelf Bookshelf */ + $shelf = $this->entityRepo->getEntityBySlug('bookshelf', $slug); /** @var $shelf Bookshelf */ $this->checkOwnablePermission('bookshelf-update', $shelf); $shelfBooks = $this->entityRepo->getBookshelfChildren($shelf); @@ -168,7 +169,7 @@ class BookshelfController extends Controller */ public function update(Request $request, string $slug) { - $shelf = $this->entityRepo->getBySlug('bookshelf', $slug); /** @var $bookshelf Bookshelf */ + $shelf = $this->entityRepo->getEntityBySlug('bookshelf', $slug); /** @var $bookshelf Bookshelf */ $this->checkOwnablePermission('bookshelf-update', $shelf); $this->validate($request, [ 'name' => 'required|string|max:255', @@ -176,7 +177,7 @@ class BookshelfController extends Controller 'image' => $this->imageRepo->getImageValidationRules(), ]); - $shelf = $this->entityRepo->updateFromInput('bookshelf', $shelf, $request->all()); + $shelf = $this->entityRepo->updateFromInput($shelf, $request->all()); $this->shelfUpdateActions($shelf, $request); Activity::add($shelf, 'bookshelf_update'); @@ -193,7 +194,7 @@ class BookshelfController extends Controller */ public function showDelete(string $slug) { - $shelf = $this->entityRepo->getBySlug('bookshelf', $slug); /** @var $shelf Bookshelf */ + $shelf = $this->entityRepo->getEntityBySlug('bookshelf', $slug); /** @var $shelf Bookshelf */ $this->checkOwnablePermission('bookshelf-delete', $shelf); $this->setPageTitle(trans('entities.shelves_delete_named', ['name' => $shelf->getShortName()])); @@ -209,9 +210,9 @@ class BookshelfController extends Controller */ public function destroy(string $slug) { - $shelf = $this->entityRepo->getBySlug('bookshelf', $slug); /** @var $shelf Bookshelf */ + $shelf = $this->entityRepo->getEntityBySlug('bookshelf', $slug); /** @var $shelf Bookshelf */ $this->checkOwnablePermission('bookshelf-delete', $shelf); - Activity::addMessage('bookshelf_delete', 0, $shelf->name); + Activity::addMessage('bookshelf_delete', $shelf->name); if ($shelf->cover) { $this->imageRepo->destroyImage($shelf->cover); @@ -229,7 +230,7 @@ class BookshelfController extends Controller */ public function showPermissions(string $slug) { - $shelf = $this->entityRepo->getBySlug('bookshelf', $slug); + $shelf = $this->entityRepo->getEntityBySlug('bookshelf', $slug); $this->checkOwnablePermission('restrictions-manage', $shelf); $roles = $this->userRepo->getRestrictableRoles(); @@ -241,19 +242,19 @@ class BookshelfController extends Controller /** * Set the permissions for this bookshelf. - * @param string $slug * @param Request $request + * @param string $slug * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @throws \BookStack\Exceptions\NotFoundException * @throws \Throwable */ - public function permissions(string $slug, Request $request) + public function permissions(Request $request, string $slug) { - $shelf = $this->entityRepo->getBySlug('bookshelf', $slug); + $shelf = $this->entityRepo->getEntityBySlug('bookshelf', $slug); $this->checkOwnablePermission('restrictions-manage', $shelf); $this->entityRepo->updateEntityPermissionsFromRequest($request, $shelf); - session()->flash('success', trans('entities.shelves_permissions_updated')); + $this->showSuccessNotification( trans('entities.shelves_permissions_updated')); return redirect($shelf->getUrl()); } @@ -265,11 +266,11 @@ class BookshelfController extends Controller */ public function copyPermissions(string $slug) { - $shelf = $this->entityRepo->getBySlug('bookshelf', $slug); + $shelf = $this->entityRepo->getEntityBySlug('bookshelf', $slug); $this->checkOwnablePermission('restrictions-manage', $shelf); $updateCount = $this->entityRepo->copyBookshelfPermissions($shelf); - session()->flash('success', trans('entities.shelves_copy_permission_success', ['count' => $updateCount])); + $this->showSuccessNotification( trans('entities.shelves_copy_permission_success', ['count' => $updateCount])); return redirect($shelf->getUrl()); } @@ -287,6 +288,7 @@ class BookshelfController extends Controller // Update the cover image if in request if ($request->has('image')) { $newImage = $request->file('image'); + $this->imageRepo->destroyImage($shelf->cover); $image = $this->imageRepo->saveNew($newImage, 'cover_shelf', $shelf->id, 512, 512, true); $shelf->image_id = $image->id; $shelf->save();