3 namespace BookStack\Entities\Tools;
5 use BookStack\Entities\Models\Page;
6 use BookStack\Entities\Repos\PageRepo;
11 protected PageRepo $pageRepo;
13 protected array $viewData;
14 protected array $warnings;
16 public function __construct(Page $page, PageRepo $pageRepo)
19 $this->pageRepo = $pageRepo;
20 $this->viewData = $this->build();
23 public function getViewData(): array
25 return $this->viewData;
28 public function getWarnings(): array
30 return $this->warnings;
33 protected function build(): array
35 $page = clone $this->page;
36 $isDraft = boolval($this->page->draft);
37 $templates = $this->pageRepo->getTemplates(10);
38 $draftsEnabled = auth()->check();
40 $isDraftRevision = false;
42 $editActivity = new PageEditActivity($page);
44 if ($editActivity->hasActiveEditing()) {
45 $this->warnings[] = $editActivity->activeEditingMessage();
48 // Check for a current draft version for this user
49 $userDraft = $this->pageRepo->getUserDraft($page);
50 if ($userDraft !== null) {
51 $page->forceFill($userDraft->only(['name', 'html', 'markdown']));
52 $isDraftRevision = true;
53 $this->warnings[] = $editActivity->getEditingActiveDraftMessage($userDraft);
58 'book' => $page->book,
59 'isDraft' => $isDraft,
60 'isDraftRevision' => $isDraftRevision,
61 'draftsEnabled' => $draftsEnabled,
62 'templates' => $templates,
63 'editor' => setting('app-editor') === 'wysiwyg' ? 'wysiwyg' : 'markdown',