<?php namespace BookStack\Http\Controllers;
use Activity;
-use BookStack\Book;
-use BookStack\Bookshelf;
-use BookStack\Repos\EntityRepo;
-use BookStack\Repos\UserRepo;
-use BookStack\Services\ExportService;
+use BookStack\Auth\UserRepo;
+use BookStack\Entities\Bookshelf;
+use BookStack\Entities\EntityContextManager;
+use BookStack\Entities\Repos\EntityRepo;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Views;
protected $entityRepo;
protected $userRepo;
- protected $exportService;
+ protected $entityContextManager;
/**
* BookController constructor.
* @param EntityRepo $entityRepo
* @param UserRepo $userRepo
- * @param ExportService $exportService
+ * @param EntityContextManager $entityContextManager
*/
- public function __construct(EntityRepo $entityRepo, UserRepo $userRepo, ExportService $exportService)
+ public function __construct(EntityRepo $entityRepo, UserRepo $userRepo, EntityContextManager $entityContextManager)
{
$this->entityRepo = $entityRepo;
$this->userRepo = $userRepo;
- $this->exportService = $exportService;
+ $this->entityContextManager = $entityContextManager;
parent::__construct();
}
*/
public function index()
{
- $shelves = $this->entityRepo->getAllPaginated('bookshelf', 18);
+ $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');
+ $sortOptions = [
+ 'name' => trans('common.sort_name'),
+ 'created_at' => trans('common.sort_created_at'),
+ 'updated_at' => trans('common.sort_updated_at'),
+ ];
+
+ $shelves = $this->entityRepo->getAllPaginated('bookshelf', 18, $sort, $order);
+ foreach ($shelves as $shelf) {
+ $shelf->books = $this->entityRepo->getBookshelfChildren($shelf);
+ }
+
$recents = $this->signedIn ? $this->entityRepo->getRecentlyViewed('bookshelf', 4, 0) : false;
$popular = $this->entityRepo->getPopular('bookshelf', 4, 0);
$new = $this->entityRepo->getRecentlyCreated('bookshelf', 4, 0);
- $shelvesViewType = setting()->getUser($this->currentUser, 'bookshelves_view_type', config('app.views.bookshelves', 'grid'));
+ $this->entityContextManager->clearShelfContext();
$this->setPageTitle(trans('entities.shelves'));
- return view('shelves/index', [
+ return view('shelves.index', [
'shelves' => $shelves,
'recents' => $recents,
'popular' => $popular,
'new' => $new,
- 'shelvesViewType' => $shelvesViewType
+ 'view' => $view,
+ 'sort' => $sort,
+ 'order' => $order,
+ 'sortOptions' => $sortOptions,
]);
}
$this->checkPermission('bookshelf-create-all');
$books = $this->entityRepo->getAll('book', false, 'update');
$this->setPageTitle(trans('entities.shelves_create'));
- return view('shelves/create', ['books' => $books]);
+ return view('shelves.create', ['books' => $books]);
}
/**
*/
public function show(string $slug)
{
- $bookshelf = $this->entityRepo->getBySlug('bookshelf', $slug); /** @var $bookshelf Bookshelf */
+ /** @var Bookshelf $bookshelf */
+ $bookshelf = $this->entityRepo->getBySlug('bookshelf', $slug);
$this->checkOwnablePermission('book-view', $bookshelf);
$books = $this->entityRepo->getBookshelfChildren($bookshelf);
Views::add($bookshelf);
+ $this->entityContextManager->setShelfContext($bookshelf->id);
$this->setPageTitle($bookshelf->getShortName());
- return view('shelves/show', [
+ return view('shelves.show', [
'shelf' => $bookshelf,
'books' => $books,
- 'activity' => Activity::entityActivity($bookshelf, 20, 0)
+ 'activity' => Activity::entityActivity($bookshelf, 20, 1)
]);
}
});
$this->setPageTitle(trans('entities.shelves_edit_named', ['name' => $bookshelf->getShortName()]));
- return view('shelves/edit', [
+ return view('shelves.edit', [
'shelf' => $bookshelf,
'books' => $books,
'shelfBooks' => $shelfBooks,
$this->checkOwnablePermission('bookshelf-delete', $bookshelf);
$this->setPageTitle(trans('entities.shelves_delete_named', ['name' => $bookshelf->getShortName()]));
- return view('shelves/delete', ['shelf' => $bookshelf]);
+ return view('shelves.delete', ['shelf' => $bookshelf]);
}
/**
$this->entityRepo->destroyBookshelf($bookshelf);
return redirect('/shelves');
}
-//
-// /**
-// * Show the Restrictions view.
-// * @param $bookSlug
-// * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
-// */
-// public function showRestrict($bookSlug)
-// {
-// $book = $this->entityRepo->getBySlug('book', $bookSlug);
-// $this->checkOwnablePermission('restrictions-manage', $book);
-// $roles = $this->userRepo->getRestrictableRoles();
-// return view('books/restrictions', [
-// 'book' => $book,
-// 'roles' => $roles
-// ]);
-// }
-//
-// /**
-// * Set the restrictions for this book.
-// * @param $bookSlug
-// * @param $bookSlug
-// * @param Request $request
-// * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
-// */
-// public function restrict($bookSlug, Request $request)
-// {
-// $book = $this->entityRepo->getBySlug('book', $bookSlug);
-// $this->checkOwnablePermission('restrictions-manage', $book);
-// $this->entityRepo->updateEntityPermissionsFromRequest($request, $book);
-// session()->flash('success', trans('entities.books_permissions_updated'));
-// return redirect($book->getUrl());
-// }
+ /**
+ * Show the permissions view.
+ * @param string $slug
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ * @throws \BookStack\Exceptions\NotFoundException
+ */
+ public function showPermissions(string $slug)
+ {
+ $bookshelf = $this->entityRepo->getBySlug('bookshelf', $slug);
+ $this->checkOwnablePermission('restrictions-manage', $bookshelf);
+
+ $roles = $this->userRepo->getRestrictableRoles();
+ return view('shelves.permissions', [
+ 'shelf' => $bookshelf,
+ 'roles' => $roles
+ ]);
+ }
+
+ /**
+ * Set the permissions for this bookshelf.
+ * @param string $slug
+ * @param Request $request
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * @throws \BookStack\Exceptions\NotFoundException
+ * @throws \Throwable
+ */
+ public function permissions(string $slug, Request $request)
+ {
+ $bookshelf = $this->entityRepo->getBySlug('bookshelf', $slug);
+ $this->checkOwnablePermission('restrictions-manage', $bookshelf);
+
+ $this->entityRepo->updateEntityPermissionsFromRequest($request, $bookshelf);
+ session()->flash('success', trans('entities.shelves_permissions_updated'));
+ return redirect($bookshelf->getUrl());
+ }
+
+ /**
+ * Copy the permissions of a bookshelf to the child books.
+ * @param string $slug
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * @throws \BookStack\Exceptions\NotFoundException
+ */
+ public function copyPermissions(string $slug)
+ {
+ $bookshelf = $this->entityRepo->getBySlug('bookshelf', $slug);
+ $this->checkOwnablePermission('restrictions-manage', $bookshelf);
+
+ $updateCount = $this->entityRepo->copyBookshelfPermissions($bookshelf);
+ session()->flash('success', trans('entities.shelves_copy_permission_success', ['count' => $updateCount]));
+ return redirect($bookshelf->getUrl());
+ }
}