X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/257a5a23ecaf7ce779969d575ff8a0b976181d13..7f95b51b00d0d5fa1e7bcf5574f2d58bddcbd504:/app/Http/Controllers/BookController.php diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php index 5a9eadaf8..b5e2a4a85 100644 --- a/app/Http/Controllers/BookController.php +++ b/app/Http/Controllers/BookController.php @@ -3,7 +3,7 @@ use Activity; use BookStack\Auth\UserRepo; use BookStack\Entities\Book; -use BookStack\Entities\EntityRepo; +use BookStack\Entities\Repos\EntityRepo; use BookStack\Entities\ExportService; use Illuminate\Http\Request; use Illuminate\Http\Response; @@ -36,18 +36,30 @@ class BookController extends Controller */ public function index() { - $books = $this->entityRepo->getAllPaginated('book', 18); + $view = setting()->getUser($this->currentUser, 'books_view_type', config('app.views.books')); + $sort = setting()->getUser($this->currentUser, 'books_sort', 'name'); + $order = setting()->getUser($this->currentUser, 'books_sort_order', 'asc'); + $sortOptions = [ + 'name' => trans('common.sort_name'), + 'created_at' => trans('common.sort_created_at'), + 'updated_at' => trans('common.sort_updated_at'), + ]; + + $books = $this->entityRepo->getAllPaginated('book', 18, $sort, $order); $recents = $this->signedIn ? $this->entityRepo->getRecentlyViewed('book', 4, 0) : false; $popular = $this->entityRepo->getPopular('book', 4, 0); $new = $this->entityRepo->getRecentlyCreated('book', 4, 0); - $booksViewType = setting()->getUser($this->currentUser, 'books_view_type', config('app.views.books', 'list')); + $this->setPageTitle(trans('entities.books')); return view('books/index', [ 'books' => $books, 'recents' => $recents, 'popular' => $popular, 'new' => $new, - 'booksViewType' => $booksViewType + 'view' => $view, + 'sort' => $sort, + 'order' => $order, + 'sortOptions' => $sortOptions, ]); } @@ -204,7 +216,7 @@ class BookController extends Controller // Get the books involved in the sort $bookIdsInvolved = $bookIdsInvolved->unique()->toArray(); - $booksInvolved = $this->entityRepo->book->newQuery()->whereIn('id', $bookIdsInvolved)->get(); + $booksInvolved = $this->entityRepo->getManyById('book', $bookIdsInvolved, false, true); // Throw permission error if invalid ids or inaccessible books given. if (count($bookIdsInvolved) !== count($booksInvolved)) { $this->showPermissionError();