authorizeStaff($composition); $guide = $this->guide($composition); $images = EmbeddedImages::staff(); foreach ($guide['chapters'] as $index => $chapter) { $guide['chapters'][$index]['html'] = DocumentGuide::shiftHeadings(FormattedText::html($chapter['version']->body, $images)); } return view('document.preview', ['guide' => $guide, 'composition' => $composition, 'pdfUrl' => route('editorial.document-preview.pdf', $composition)]); } public function pdf(Composition $composition): Response { $this->authorizeStaff($composition); $content = app(DocumentPdf::class)->render($this->guide($composition), 'Vorschau der Redaktion', 'vorschau', EmbeddedImages::forStaffPdf()); return response($content, 200, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; filename="vorschau.pdf"', 'Cache-Control' => 'private, no-store', ]); } /** * @return array */ private function guide(Composition $composition): array { $chapters = app(DocumentReader::class)->forStaff($composition); abort_if($chapters === null, 404); foreach ($chapters as $index => $chapter) { $chapters[$index] += [ 'allowed' => true, 'grant' => null, 'may_download' => true, 'download_grant' => null, 'state' => 'ok', 'html' => null, 'blocks' => FormattedText::blocks($chapter['version']->body), ]; } $draft = app(EditorialWorkingDraft::class)->read($composition); $ready = $composition->versions()->where('status', ContentVersionStatus::Bereit)->orderByDesc('number')->first(); return [ 'title' => app(EditorialCatalog::class)->compositionTitle($composition), 'summary_html' => FormattedText::html($composition->summary), 'pdf_template' => $composition->pdfTemplate, 'meta' => DocumentMeta::normalize($draft !== null ? ($draft['document_meta'] ?? null) : $ready?->document_meta), 'chapters' => $chapters, ]; } /** * Muster-PDF einer Vorlage: ein kurzes Handbuch mit Beispielangaben, damit Titelseite, Kopf, Fuß und Seitenzahlen zu sehen * sind, ohne ein Dokument zu brauchen. */ public function template(PdfTemplate $template): Response { $this->authorizeUser(); $table = '

Zeit

Inhalt

10 Min.

Begrüßung

'; $chapters = []; foreach (['Grundlagen' => 1, 'Haltung und Abstand' => 1, 'Vertiefung' => 2] as $title => $level) { $number = count($chapters) + 1; $chapters[] = [ 'number' => (string) ($level === 1 ? count(array_filter($chapters, fn (array $c): bool => $c['level'] === 1)) + 1 : '2.1'), 'level' => $level, 'anchor' => 'muster-'.$number, 'title' => $title, 'allowed' => true, 'blocks' => FormattedText::blocks('

'.str_repeat('Mustertext für die Vorschau der Vorlage. ', 30).'

Zwischenüberschrift

'.$table), ]; } $guide = [ 'title' => 'Musterhandbuch', 'pdf_template' => $template, 'meta' => ['subtitle' => 'Beispiel für eine Titelseite', 'edition' => 'Ausgabe 1.0 · Muster', 'published_on' => now()->format('Y-m-d')], 'chapters' => $chapters, ]; return response(app(DocumentPdf::class)->render($guide, 'Vorschau der Redaktion', 'vorschau'), 200, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; filename="muster.pdf"', 'Cache-Control' => 'private, no-store', ]); } private function authorizeUser(): void { $user = auth('staff')->user(); abort_unless( $user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)), 403, ); } private function authorizeStaff(Composition $composition): void { $this->authorizeUser(); abort_unless($composition->kind === CompositionKind::Document, 404); } }