<?php namespace BookStack\Http\Controllers;
use Activity;
+use BookStack\Book;
use BookStack\Repos\EntityRepo;
use BookStack\Repos\UserRepo;
+use BookStack\Services\ExportService;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Views;
protected $entityRepo;
protected $userRepo;
+ protected $exportService;
/**
* BookController constructor.
* @param EntityRepo $entityRepo
* @param UserRepo $userRepo
+ * @param ExportService $exportService
*/
- public function __construct(EntityRepo $entityRepo, UserRepo $userRepo)
+ public function __construct(EntityRepo $entityRepo, UserRepo $userRepo, ExportService $exportService)
{
$this->entityRepo = $entityRepo;
$this->userRepo = $userRepo;
+ $this->exportService = $exportService;
parent::__construct();
}
*/
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
+ ]);
}
/**
$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)
+ ]);
}
/**
// 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());
}
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'
+ ]);
+ }
}