+
+ /**
+ * Show the page for moving a chapter.
+ * @param $bookSlug
+ * @param $chapterSlug
+ * @return mixed
+ * @throws \BookStack\Exceptions\NotFoundException
+ */
+ public function showMove($bookSlug, $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $this->setPageTitle(trans('entities.chapters_move_named', ['chapterName' => $chapter->getShortName()]));
+ $this->checkOwnablePermission('chapter-update', $chapter);
+ return view('chapters/move', [
+ 'chapter' => $chapter,
+ 'book' => $chapter->book
+ ]);
+ }
+
+ /**
+ * Perform the move action for a chapter.
+ * @param $bookSlug
+ * @param $chapterSlug
+ * @param Request $request
+ * @return mixed
+ * @throws \BookStack\Exceptions\NotFoundException
+ */
+ public function move($bookSlug, $chapterSlug, Request $request)
+ {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $this->checkOwnablePermission('chapter-update', $chapter);
+
+ $entitySelection = $request->get('entity_selection', null);
+ if ($entitySelection === null || $entitySelection === '') {
+ return redirect($chapter->getUrl());
+ }
+
+ $stringExploded = explode(':', $entitySelection);
+ $entityType = $stringExploded[0];
+ $entityId = intval($stringExploded[1]);
+
+ $parent = false;
+
+ if ($entityType == 'book') {
+ $parent = $this->entityRepo->getById('book', $entityId);
+ }
+
+ if ($parent === false || $parent === null) {
+ session()->flash('error', trans('errors.selected_book_not_found'));
+ return redirect()->back();
+ }
+
+ $this->entityRepo->changeBook('chapter', $parent->id, $chapter, true);
+ Activity::add($chapter, 'chapter_move', $chapter->book->id);
+ session()->flash('success', trans('entities.chapter_move_success', ['bookName' => $parent->name]));
+
+ return redirect($chapter->getUrl());
+ }
+
+ /**
+ * Show the Restrictions view.
+ * @param $bookSlug
+ * @param $chapterSlug
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function showRestrict($bookSlug, $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $this->checkOwnablePermission('restrictions-manage', $chapter);
+ $roles = $this->userRepo->getRestrictableRoles();
+ return view('chapters/restrictions', [
+ 'chapter' => $chapter,
+ 'roles' => $roles
+ ]);
+ }
+
+ /**
+ * Set the restrictions for this chapter.
+ * @param $bookSlug
+ * @param $chapterSlug
+ * @param Request $request
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ public function restrict($bookSlug, $chapterSlug, Request $request)
+ {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $this->checkOwnablePermission('restrictions-manage', $chapter);
+ $this->entityRepo->updateEntityPermissionsFromRequest($request, $chapter);
+ session()->flash('success', trans('entities.chapters_permissions_success'));
+ return redirect($chapter->getUrl());
+ }
+
+ /**
+ * Exports a chapter to pdf .
+ * @param string $bookSlug
+ * @param string $chapterSlug
+ * @return \Illuminate\Http\Response
+ */
+ public function exportPdf($bookSlug, $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $pdfContent = $this->exportService->chapterToPdf($chapter);
+ return response()->make($pdfContent, 200, [
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment; filename="' . $chapterSlug . '.pdf'
+ ]);
+ }
+
+ /**
+ * Export a chapter to a self-contained HTML file.
+ * @param string $bookSlug
+ * @param string $chapterSlug
+ * @return \Illuminate\Http\Response
+ */
+ public function exportHtml($bookSlug, $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $containedHtml = $this->exportService->chapterToContainedHtml($chapter);
+ return response()->make($containedHtml, 200, [
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment; filename="' . $chapterSlug . '.html'
+ ]);
+ }
+
+ /**
+ * Export a chapter to a simple plaintext .txt file.
+ * @param string $bookSlug
+ * @param string $chapterSlug
+ * @return \Illuminate\Http\Response
+ */
+ public function exportPlainText($bookSlug, $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $containedHtml = $this->exportService->chapterToPlainText($chapter);
+ return response()->make($containedHtml, 200, [
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment; filename="' . $chapterSlug . '.txt'
+ ]);
+ }