X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/cd6572b61af2165133468d2562d04dffdca8fca8..refs/pull/261/head:/app/Http/Controllers/BookController.php diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php index 57ac486d5..8996ae64a 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(); } @@ -203,13 +208,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 +262,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' + ]); + } }