]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/BookshelfController.php
Merge branch 'feature/sort-shelf-books' of git://github.com/guillaumehanotel/BookStac...
[bookstack] / app / Http / Controllers / BookshelfController.php
index 8574c1b48589970039ccf36aee51a4c85b0d3aaa..14bc9d94efc61e8704f8691b368b7d56799d1f50 100644 (file)
@@ -101,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');
@@ -108,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
         ]);
     }