X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/c7a2d568bf693add30c8402d68d1f46f09a44c5b..refs/pull/2515/head:/app/Http/Controllers/BookshelfController.php diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index 52de74b66..6c090a26d 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -1,7 +1,8 @@ bookshelfRepo = $bookshelfRepo; @@ -103,6 +101,15 @@ class BookshelfController extends Controller $shelf = $this->bookshelfRepo->getBySlug($slug); $this->checkOwnablePermission('book-view', $shelf); + $sort = setting()->getForCurrentUser('shelf_books_sort', 'name'); + $order = setting()->getForCurrentUser('shelf_books_sort_order', 'asc'); + + $visibleShelfBooks = $shelf->visibleBooks()->get(); + $sortedVisibleShelfBooks = $visibleShelfBooks + ->sortBy($sort, SORT_REGULAR, $order === 'desc') + ->values() + ->all(); + Views::add($shelf); $this->entityContextManager->setShelfContext($shelf->id); $view = setting()->getForCurrentUser('bookshelf_view_type', config('app.views.books')); @@ -110,8 +117,11 @@ class BookshelfController extends Controller $this->setPageTitle($shelf->getShortName()); return view('shelves.show', [ 'shelf' => $shelf, + 'sortedVisibleShelfBooks' => $sortedVisibleShelfBooks, 'view' => $view, - 'activity' => Activity::entityActivity($shelf, 20, 1) + 'activity' => Activity::entityActivity($shelf, 20, 1), + 'order' => $order, + 'sort' => $sort ]); } @@ -200,14 +210,12 @@ class BookshelfController extends Controller /** * Set the permissions for this bookshelf. */ - public function permissions(Request $request, string $slug) + public function permissions(Request $request, PermissionsUpdater $permissionsUpdater, string $slug) { $shelf = $this->bookshelfRepo->getBySlug($slug); $this->checkOwnablePermission('restrictions-manage', $shelf); - $restricted = $request->get('restricted') === 'true'; - $permissions = $request->filled('restrictions') ? collect($request->get('restrictions')) : null; - $this->bookshelfRepo->updatePermissions($shelf, $restricted, $permissions); + $permissionsUpdater->updateFromPermissionsForm($shelf, $request); $this->showSuccessNotification(trans('entities.shelves_permissions_updated')); return redirect($shelf->getUrl());