+
+ /**
+ * 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->getEntityBySlug('chapter', $chapterSlug, $bookSlug);
+ $this->setPageTitle(trans('entities.chapters_move_named', ['chapterName' => $chapter->getShortName()]));
+ $this->checkOwnablePermission('chapter-update', $chapter);
+ $this->checkOwnablePermission('chapter-delete', $chapter);
+ return view('chapters.move', [
+ 'chapter' => $chapter,
+ 'book' => $chapter->book
+ ]);
+ }
+
+ /**
+ * Perform the move action for a chapter.
+ * @param Request $request
+ * @param string $bookSlug
+ * @param string $chapterSlug
+ * @return mixed
+ * @throws \BookStack\Exceptions\NotFoundException
+ */
+ public function move(Request $request, string $bookSlug, string $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getEntityBySlug('chapter', $chapterSlug, $bookSlug);
+ $this->checkOwnablePermission('chapter-update', $chapter);
+ $this->checkOwnablePermission('chapter-delete', $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) {
+ $this->showErrorNotification( trans('errors.selected_book_not_found'));
+ return redirect()->back();
+ }
+
+ $this->entityRepo->changeBook($chapter, $parent->id);
+ $chapter->rebuildPermissions();
+
+ Activity::add($chapter, 'chapter_move', $chapter->book->id);
+ $this->showSuccessNotification( 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
+ * @throws \BookStack\Exceptions\NotFoundException
+ */
+ public function showPermissions($bookSlug, $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getEntityBySlug('chapter', $chapterSlug, $bookSlug);
+ $this->checkOwnablePermission('restrictions-manage', $chapter);
+ $roles = $this->userRepo->getRestrictableRoles();
+ return view('chapters.permissions', [
+ 'chapter' => $chapter,
+ 'roles' => $roles
+ ]);
+ }
+
+ /**
+ * Set the restrictions for this chapter.
+ * @param Request $request
+ * @param string $bookSlug
+ * @param string $chapterSlug
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * @throws \BookStack\Exceptions\NotFoundException
+ * @throws \Throwable
+ */
+ public function permissions(Request $request, string $bookSlug, string $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getEntityBySlug('chapter', $chapterSlug, $bookSlug);
+ $this->checkOwnablePermission('restrictions-manage', $chapter);
+ $this->entityRepo->updateEntityPermissionsFromRequest($request, $chapter);
+ $this->showSuccessNotification( trans('entities.chapters_permissions_success'));
+ return redirect($chapter->getUrl());
+ }