X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/cd6572b61af2165133468d2562d04dffdca8fca8..refs/pull/524/head:/app/Http/Controllers/BookController.php diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php index 57ac486d5..5342ece6b 100644 --- a/app/Http/Controllers/BookController.php +++ b/app/Http/Controllers/BookController.php @@ -1,8 +1,10 @@ entityRepo = $entityRepo; $this->userRepo = $userRepo; + $this->exportService = $exportService; parent::__construct(); } @@ -31,11 +36,17 @@ class BookController extends Controller */ public function index() { - $books = $this->entityRepo->getAllPaginated('book', 10); + $books = $this->entityRepo->getAllPaginated('book', 20); $recents = $this->signedIn ? $this->entityRepo->getRecentlyViewed('book', 4, 0) : false; $popular = $this->entityRepo->getPopular('book', 4, 0); + $new = $this->entityRepo->getRecentlyCreated('book', 4, 0); $this->setPageTitle('Books'); - return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular]); + return view('books/index', [ + 'books' => $books, + 'recents' => $recents, + 'popular' => $popular, + 'new' => $new + ]); } /** @@ -79,7 +90,12 @@ class BookController extends Controller $bookChildren = $this->entityRepo->getBookChildren($book); Views::add($book); $this->setPageTitle($book->getShortName()); - return view('books/show', ['book' => $book, 'current' => $book, 'bookChildren' => $bookChildren]); + return view('books/show', [ + 'book' => $book, + 'current' => $book, + 'bookChildren' => $bookChildren, + 'activity' => Activity::entityActivity($book, 20, 0) + ]); } /** @@ -203,13 +219,12 @@ class BookController extends Controller // Add activity for books foreach ($sortedBooks as $bookId) { + /** @var Book $updatedBook */ $updatedBook = $this->entityRepo->getById('book', $bookId); + $this->entityRepo->buildJointPermissionsForBook($updatedBook); Activity::add($updatedBook, 'book_sort', $updatedBook->id); } - // Update permissions on changed models - $this->entityRepo->buildJointPermissions($updatedModels); - return redirect($book->getUrl()); } @@ -258,4 +273,49 @@ class BookController extends Controller session()->flash('success', trans('entities.books_permissions_updated')); return redirect($book->getUrl()); } + + /** + * Export a book as a PDF file. + * @param string $bookSlug + * @return mixed + */ + public function exportPdf($bookSlug) + { + $book = $this->entityRepo->getBySlug('book', $bookSlug); + $pdfContent = $this->exportService->bookToPdf($book); + return response()->make($pdfContent, 200, [ + 'Content-Type' => 'application/octet-stream', + 'Content-Disposition' => 'attachment; filename="' . $bookSlug . '.pdf' + ]); + } + + /** + * Export a book as a contained HTML file. + * @param string $bookSlug + * @return mixed + */ + public function exportHtml($bookSlug) + { + $book = $this->entityRepo->getBySlug('book', $bookSlug); + $htmlContent = $this->exportService->bookToContainedHtml($book); + return response()->make($htmlContent, 200, [ + 'Content-Type' => 'application/octet-stream', + 'Content-Disposition' => 'attachment; filename="' . $bookSlug . '.html' + ]); + } + + /** + * Export a book as a plain text file. + * @param $bookSlug + * @return mixed + */ + public function exportPlainText($bookSlug) + { + $book = $this->entityRepo->getBySlug('book', $bookSlug); + $htmlContent = $this->exportService->bookToPlainText($book); + return response()->make($htmlContent, 200, [ + 'Content-Type' => 'application/octet-stream', + 'Content-Disposition' => 'attachment; filename="' . $bookSlug . '.txt' + ]); + } }