1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Updated shelf sort to allow default sort, added testing

Done during review of #2515
This commit is contained in:
Dan Brown
2021-03-21 23:06:15 +00:00
parent ab4c5a55b8
commit 5c9c1d1a4b
6 changed files with 70 additions and 11 deletions

View File

@ -101,12 +101,11 @@ class BookshelfController extends Controller
$shelf = $this->bookshelfRepo->getBySlug($slug);
$this->checkOwnablePermission('book-view', $shelf);
$sort = setting()->getForCurrentUser('shelf_books_sort', 'name');
$sort = setting()->getForCurrentUser('shelf_books_sort', 'default');
$order = setting()->getForCurrentUser('shelf_books_sort_order', 'asc');
$visibleShelfBooks = $shelf->visibleBooks()->get();
$sortedVisibleShelfBooks = $visibleShelfBooks
->sortBy($sort, SORT_REGULAR, $order === 'desc')
$sortedVisibleShelfBooks = $shelf->visibleBooks()->get()
->sortBy($sort === 'default' ? 'pivot.order' : $sort, SORT_REGULAR, $order === 'desc')
->values()
->all();