diff --git a/CLAUDE.md b/CLAUDE.md index 44e87f2..1c8d04e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -68,5 +68,5 @@ ## Verwaltungsoberfläche - Formatierte Texte (ADR-50): gespeichert wird bereinigtes HTML aus fester Auswahl, bearbeitet mit dem einen Editor `App\Filament\Support\RichField`, in den Arbeitsplätzen über `ManagesRichFields` (`richFelder()`, `kind => 'rich'`). Ausgabe nur über `App\Domain\Catalog\FormattedText` (`html()`, `display()`, `plain()`, `blocks()` fürs PDF), nie ungeprüft; verglichen wird nur `FormattedText::same()`/`canonical()`. Klartext des Altbestands bleibt in der Datenbank, bis jemand ihn ändert. Keine eigenen Textfelder mit `textarea` für Texte, die formatiert sein sollen. - Filter mit Mehrfachauswahl in Bestandslisten (z. B. Medienmanager): Baustein `verwaltung/bestand-filterdialog` über den Eintrag `filterdialog` in `bestand()` (Filterknopf neben der Suche, Pillen je wirksamem Feld, Dialog mit Entwurf der Auswahl: „Anwenden“ übernimmt, „Abbrechen“ verwirft). Mehrere Werte eines Felds gelten als ODER, verschiedene Felder als UND. Die Häkchen sind per `wire:model` an eine Liste im Entwurf gebunden (nie `wire:click` mit `@checked`: nach einer Serverantwort stimmt sonst die Anzeige nicht). Persönliche Standardfilter je Konto liegen in `user_view_defaults` (`UserViewDefault`). Texte, die für eine Übung angelegt werden, erhalten über `ExerciseSections::mark` die Materialart „Übungsabschnitt“ und den Verweis auf ihre Übung. - Die Redaktion ist ein Arbeitsstand: nur „Redaktion speichern“ schreibt Texte, Einordnung, Präsentationsmedien und Abweichungen. Kein verdecktes Mitspeichern aus anderen Dialogen, offene Eingaben bleiben beim Wechsel erhalten. -- Dokumente (ADR-51): Kapitel sind Texte, die Dokumentfassung ist eine Komposition (`CompositionKind::Document`); bearbeitet wird im Aufbaueditor über den Kapitelarbeitsplatz (`ManagesDocumentChapters`, `verwaltung/dokument`), ausgegeben über `DocumentGuide` (Seite) und `DocumentPdf`. Formatierte Texte mit Tabellen und Bildern laufen nur über `FormattedText`, `RichField` und `EmbeddedImages` (ein Bild ist ein Verweis auf eine Bildfassung, nie eine Adresse); PDF-Satz nur über `PdfFlow`. Änderungen an `PdfDocument` müssen die Prüfsummen in `tests/Unit/PdfDocumentTest.php` einhalten (Belege byte-gleich). +- Dokumente (ADR-51): Kapitel sind Texte, die Dokumentfassung ist eine Komposition (`CompositionKind::Document`); bearbeitet wird im Aufbaueditor über den Kapitelarbeitsplatz (`ManagesDocumentChapters`, `verwaltung/dokument`), ausgegeben über `DocumentGuide` (Seite) und `DocumentPdf`. Formatierte Texte mit Tabellen und Bildern laufen nur über `FormattedText`, `RichField` und `EmbeddedImages` (ein Bild ist ein Verweis auf eine Bildfassung, nie eine Adresse); PDF-Satz nur über `PdfFlow`. Änderungen an `PdfDocument` müssen die Prüfsummen in `tests/Unit/PdfDocumentTest.php` einhalten (Belege byte-gleich). Das Aussehen des Dokument-PDF (Titelseite, Kopf, Fuß) kommt aus der `PdfTemplate` (Seite `PdfVorlagen`); Inhalt wie Ausgabe, Datum und Vermerk gehört in `document_meta` der Dokumentfassung, nicht in die Vorlage. - Jede UI-Änderung in der echten Anwendung prüfen (luf-test, breite und schmale Fenster, Tastatur) und mit Screenshots in `docs/ux/verwaltung/abnahme/` belegen. Stand der Abnahme: `abnahme/teil-a.md`, `abnahme/teil-b.md`, `abnahme/teil-c.md`, `abnahme/stammdaten.md`. diff --git a/app/Domain/Catalog/Composition.php b/app/Domain/Catalog/Composition.php index 4bd54c1..2d7e351 100644 --- a/app/Domain/Catalog/Composition.php +++ b/app/Domain/Catalog/Composition.php @@ -25,6 +25,7 @@ class Composition extends Model 'editorial_content_kind_id', 'archived_at', 'working_draft', + 'pdf_template_id', ]; protected function casts(): array @@ -46,6 +47,12 @@ public function editorialContentKind(): BelongsTo return $this->belongsTo(EditorialContentKind::class); } + /** Die PDF-Vorlage eines Dokuments; leer = bisheriges Layout (ADR-51). */ + public function pdfTemplate(): BelongsTo + { + return $this->belongsTo(PdfTemplate::class); + } + public function versions(): HasMany { return $this->hasMany(CompositionVersion::class); diff --git a/app/Domain/Catalog/CompositionRelease.php b/app/Domain/Catalog/CompositionRelease.php index 2edc9c0..b24fc7e 100644 --- a/app/Domain/Catalog/CompositionRelease.php +++ b/app/Domain/Catalog/CompositionRelease.php @@ -367,6 +367,7 @@ private function materialize( 'duration_max' => $didactic['duration_max'] ?? null, 'material_note' => $didactic['material_note'] ?? null, 'prerequisites' => $didactic['prerequisites'] ?? null, + 'document_meta' => $didactic['document_meta'] ?? null, ], $variants, ); @@ -432,6 +433,7 @@ private function resolveTarget(string $target, ?User $actor, array $stack): Cont 'duration_max' => $draft['duration_max'] ?? null, 'material_note' => $draft['material_note'] ?? null, 'prerequisites' => $draft['prerequisites'] ?? null, + 'document_meta' => $draft['document_meta'] ?? null, ], $actor, is_string($draft['revision_note'] ?? null) ? $draft['revision_note'] : null, diff --git a/app/Domain/Catalog/CompositionVersion.php b/app/Domain/Catalog/CompositionVersion.php index 6675c5c..2dd3deb 100644 --- a/app/Domain/Catalog/CompositionVersion.php +++ b/app/Domain/Catalog/CompositionVersion.php @@ -21,12 +21,14 @@ class CompositionVersion extends Model 'prerequisites', 'structure_hash', 'source_snapshot_id', + 'document_meta', ]; protected function casts(): array { return [ 'status' => ContentVersionStatus::class, + 'document_meta' => 'array', ]; } diff --git a/app/Domain/Catalog/ContentService.php b/app/Domain/Catalog/ContentService.php index 38545c5..e81f3aa 100644 --- a/app/Domain/Catalog/ContentService.php +++ b/app/Domain/Catalog/ContentService.php @@ -335,6 +335,7 @@ public function publishComposition( 'duration_max' => isset($didactic['duration_max']) ? (int) $didactic['duration_max'] : null, 'material_note' => $this->optionalText($didactic['material_note'] ?? null), 'prerequisites' => $this->optionalText($didactic['prerequisites'] ?? null), + 'document_meta' => DocumentMeta::normalize($didactic['document_meta'] ?? null), 'source_snapshot_id' => isset($didactic['source_snapshot_id']) ? (int) $didactic['source_snapshot_id'] : null, ]); @@ -394,6 +395,8 @@ public function structureHash(CompositionVersion $version): string { $version->loadMissing('members.variant', 'variants'); + $meta = DocumentMeta::normalize($version->document_meta); + return hash('sha256', json_encode([ 'fields' => [ $version->learning_goal, @@ -402,6 +405,8 @@ public function structureHash(CompositionVersion $version): string $version->material_note, $version->prerequisites, ], + // Nur wenn gesetzt: Der Nachweis älterer Fassungen ohne Dokumentangaben bleibt unverändert. + ...($meta === null ? [] : ['document' => $meta]), 'variants' => $version->variants->map(fn (CompositionVersionVariant $variant): array => [ $variant->key, $variant->position, $variant->name, $variant->description, $variant->origin, ])->all(), diff --git a/app/Domain/Catalog/DocumentGuide.php b/app/Domain/Catalog/DocumentGuide.php index 9eff4d0..48a3803 100644 --- a/app/Domain/Catalog/DocumentGuide.php +++ b/app/Domain/Catalog/DocumentGuide.php @@ -34,7 +34,7 @@ public function build(User $user, LicenseArticle $article, ArticleRelease $relea $view = ($this->access)($user, $article, $release, $version, 'ansehen'); $download = ($this->access)($user, $article, $release, $version, 'laden'); - $chapters[] = [ + $entry = [ 'number' => $chapter['number'], 'level' => $chapter['level'], 'anchor' => $chapter['anchor'], @@ -45,9 +45,11 @@ public function build(User $user, LicenseArticle $article, ArticleRelease $relea 'may_download' => $download->allowed, 'download_grant' => $download->grant, 'state' => $view->allowed ? 'ok' : ($version->status === ContentVersionStatus::Gesperrt ? 'gesperrt' : 'nicht_lizenziert'), - 'html' => $view->allowed ? $this->shiftHeadings(FormattedText::html($version->body, $embedded->forView($user, $article, $release, $version))) : null, + 'html' => null, 'blocks' => $view->allowed ? FormattedText::blocks($version->body) : null, ]; + $entry['html'] = $view->allowed ? self::anchoredHtml($entry, FormattedText::html($version->body, $embedded->forView($user, $article, $release, $version))) : null; + $chapters[] = self::withHeadings($entry); } $text = $library->text($document->composition); @@ -56,17 +58,61 @@ public function build(User $user, LicenseArticle $article, ArticleRelease $relea 'document' => $document, 'title' => $text['title'], 'summary_html' => $text['summary_html'], + 'pdf_template' => $document->composition->pdfTemplate, + 'meta' => DocumentMeta::normalize($document->document_meta), 'chapters' => $chapters, ]; } /** - * Zwischenüberschriften im Kapiteltext stehen eine Ebene unter dem Kapiteltitel (h3 wird h4), damit die - * Überschriftenfolge der Seite stimmt: Dokument h1, Kapitel h2, Unterkapitel h3, Zwischenüberschrift h4. + * Um wie viele Stufen die Zwischenüberschriften eines Kapitels nach unten rücken: Im Kapitel (h2) bleiben h3 bis h6 wie + * geschrieben, unter einem Unterkapitel (h3) rücken sie eine Stufe tiefer (höchstens h6). So steht nie eine Überschrift + * des Texts auf der Stufe des Kapitels oder Unterkapitels, zu dem sie gehört. */ - public static function shiftHeadings(string $html): string + public static function headingShift(int $chapterLevel): int { - return (string) preg_replace('/<(\/?)h3(?=[\s>])/i', '<$1h4', $html); + return $chapterLevel >= 2 ? 1 : 0; + } + + /** + * Das HTML eines Kapitels mit Sprungmarken an den Zwischenüberschriften und der Stufe, die zum Kapitel passt. + * + * @param array $chapter + */ + public static function anchoredHtml(array $chapter, string $html): string + { + return FormattedText::anchorHeadings($html, (string) $chapter['anchor'], self::headingShift((int) $chapter['level']))['html']; + } + + /** + * Ergänzt ein Kapitel um seine Zwischenüberschriften (`headings`: Stufe, Text, Sprungmarke) für das Inhaltsverzeichnis und + * legt Stufe und Sprungmarke in die Überschriftenblöcke des PDF. Ansicht und PDF zählen gleich; sie lesen beide diese Liste. + * + * @param array $chapter + * @return array + */ + public static function withHeadings(array $chapter): array + { + $shift = self::headingShift((int) $chapter['level']); + $headings = []; + $blocks = $chapter['blocks'] ?? null; + + foreach (is_array($blocks) ? $blocks : [] as $index => $block) { + if ($block['type'] !== 'heading' || trim((string) ($block['text'] ?? '')) === '') { + continue; + } + + $level = min(6, (int) $block['level'] + $shift); + $anchor = $chapter['anchor'].'-u'.(count($headings) + 1); + $blocks[$index]['level'] = $level; + $blocks[$index]['anchor'] = $anchor; + $headings[] = ['level' => $level, 'text' => (string) $block['text'], 'anchor' => $anchor]; + } + + $chapter['blocks'] = is_array($blocks) ? $blocks : null; + $chapter['headings'] = $headings; + + return $chapter; } /** diff --git a/app/Domain/Catalog/DocumentMeta.php b/app/Domain/Catalog/DocumentMeta.php new file mode 100644 index 0000000..55a8f0a --- /dev/null +++ b/app/Domain/Catalog/DocumentMeta.php @@ -0,0 +1,51 @@ +|null + */ + public static function normalize(mixed $value): ?array + { + if (! is_array($value)) { + return null; + } + + $clean = []; + + foreach (self::FIELDS as $field) { + $text = trim((string) ($value[$field] ?? '')); + + if ($field === 'published_on') { + $text = preg_match('/^\d{4}-\d{2}-\d{2}$/', $text) === 1 ? $text : ''; + } + + if ($text !== '') { + $clean[$field] = mb_substr($text, 0, $field === 'copyright' ? 600 : 200); + } + } + + return $clean === [] ? null : $clean; + } + + /** Das Veröffentlichungsdatum in deutscher Schreibweise, oder leer. */ + public static function publishedLabel(?array $meta): string + { + $date = $meta['published_on'] ?? ''; + + return $date === '' ? '' : CarbonImmutable::parse($date)->format('d.m.Y'); + } +} diff --git a/app/Domain/Catalog/DocumentPdf.php b/app/Domain/Catalog/DocumentPdf.php index ddb3a5a..f579ee1 100644 --- a/app/Domain/Catalog/DocumentPdf.php +++ b/app/Domain/Catalog/DocumentPdf.php @@ -3,14 +3,20 @@ namespace App\Domain\Catalog; use App\Domain\Commerce\Receipt\PdfDocument; +use App\Domain\Media\PdfImage; use Closure; use Transliterator; /** - * Druckbare Ausgabe eines Dokuments (DIN A4) aus demselben Ergebnis wie die Ansicht ({@see DocumentGuide}): Titelseite mit - * anklickbarem Inhaltsverzeichnis samt Seitenzahlen, jedes Kapitel der ersten Ebene beginnt auf einer neuen Seite, - * Lesezeichen für die Gliederung des PDF-Betrachters. Fußzeile mit Lizenznehmer, Lizenzkopie und „Seite n von m“ auf jeder - * Seite (K2), die Kennung in den Metadaten (K1). Die Datei wird bei jedem Abruf neu erzeugt und nie abgelegt. + * Druckbare Ausgabe eines Dokuments (DIN A4) aus demselben Ergebnis wie die Ansicht ({@see DocumentGuide}): anklickbares + * Inhaltsverzeichnis samt Seitenzahlen, jedes Kapitel der ersten Ebene beginnt auf einer neuen Seite, Lesezeichen für die + * Gliederung des PDF-Betrachters. Fußzeile mit Lizenznehmer, Lizenzkopie und „Seite n von m“ auf jeder Seite (K2), die Kennung + * in den Metadaten (K1). Die Datei wird bei jedem Abruf neu erzeugt und nie abgelegt. + * + * Vorlage (ADR-51, Nachtrag): Ist dem Dokument eine {@see PdfTemplate} zugeordnet, steht der Titel allein auf einer eigenen + * Titelseite (mit Untertitel, Ausgabe, Veröffentlichungsdatum, Herausgeber und Copyright-Vermerk), und Kopf und Fuß aller + * weiteren Seiten tragen die gewählten Grafiken. Die Angaben kommen aus der Dokumentfassung ({@see DocumentMeta}). Ohne Vorlage + * beginnt das Inhaltsverzeichnis wie bisher unter dem Titel auf der ersten Seite. * * Seitenzahlen stehen erst nach dem Satz fest. Der Satz läuft deshalb so oft, bis Inhaltsverzeichnis, Kapitelanfänge und * Seitenzahl sich nicht mehr ändern (in der Regel zweimal). @@ -21,9 +27,7 @@ class DocumentPdf private const RIGHT = 539.0; - private const TOP = 790.0; - - private const BOTTOM = 72.0; + private const PAGE_HEIGHT = 842.0; private PdfDocument $pdf; @@ -35,20 +39,38 @@ class DocumentPdf private int $total = 0; + private bool $onCover = false; + + /** Das erste Kapitel setzt die Seite fort, statt eine neue zu beginnen (ohne Inhaltsverzeichnis). */ + private bool $continueFirst = false; + + /** Obere und untere Grenze des Textes, abhängig von den Grafiken der Vorlage. */ + private float $top = 790.0; + + private float $bottom = 72.0; + + /** Höhe der Fußlinie über dem Seitenrand. */ + private float $footerLine = 54.0; + + /** @var array{header: ?array, footer: ?array, cover: ?array} Grafiken samt Maßen, siehe {@see self::band()} */ + private array $bands = ['header' => null, 'footer' => null, 'cover' => null]; + /** @var array */ private array $starts = []; /** - * @param array $guide Ergebnis von {@see DocumentGuide::build} + * @param array $guide Ergebnis von {@see DocumentGuide::build}; `pdf_template` und `meta` sind optional */ public function render(array $guide, string $licensee, string $copyId, ?PdfImages $images = null): string { + $template = ($guide['pdf_template'] ?? null) instanceof PdfTemplate ? $guide['pdf_template'] : null; + $this->prepareLayout($template); $starts = []; $total = 0; $bytes = ''; for ($pass = 0; $pass < 5; $pass++) { - $bytes = $this->pass($guide, $licensee, $copyId, $images, $starts, $total); + $bytes = $this->pass($guide, $template, $licensee, $copyId, $images, $starts, $total); if ($this->starts === $starts && $this->total === $total) { break; @@ -61,30 +83,131 @@ public function render(array $guide, string $licensee, string $copyId, ?PdfImage return $bytes; } + /** + * Bereitet die Grafiken der Vorlage auf und legt Ränder fest: Kopf und Fuß in voller Seitenbreite (höchstens 140 Punkt hoch), + * der Text beginnt unter dem Kopf und endet über dem Fuß. + */ + private function prepareLayout(?PdfTemplate $template): void + { + $this->bands = [ + 'header' => $this->band($template?->target('header'), 140.0, 'header', $template?->layout('header')), + 'footer' => $this->band($template?->target('footer'), 140.0, 'footer', $template?->layout('footer')), + 'cover' => $template !== null && $template->show_cover ? $this->band($template->target('cover'), self::PAGE_HEIGHT * 0.4, 'cover') : null, + ]; + $header = (float) ($this->bands['header']['occupied'] ?? 0); + $footer = (float) ($this->bands['footer']['occupied'] ?? 0); + $this->top = $header > 0 ? min(790.0, self::PAGE_HEIGHT - $header - 26.0) : 790.0; + $this->footerLine = max(54.0, $footer + 24.0); + $this->bottom = $this->footerLine + 18.0; + } + + /** + * Eine Grafik für Kopf, Fuß oder Titelseite. Als Band steht sie in Seitenbreite (bei zu großer Höhe verkleinert und zentriert), + * als Logo hat sie die gewählte Höhe und steht am linken oder rechten Textrand, höchstens halb so breit wie der Text. + * `occupied` ist die Höhe, die sie am Seitenrand belegt; `y` die Unterkante. + * + * @param array{align: string, height: int}|null $layout nur für Kopf und Fuß + * @return array{jpeg: string, pixelWidth: int, pixelHeight: int, width: float, height: float, x: float, y: float, occupied: float}|null + */ + private function band(?string $target, float $maxHeight, string $edge, ?array $layout = null): ?array + { + $bytes = TemplateImage::bytes($target); + $image = $bytes === null ? null : PdfImage::fromBytes($bytes); + + if ($image === null) { + return null; + } + + $ratio = $image['width'] / max(1, $image['height']); + $align = $layout['align'] ?? 'full'; + $common = ['jpeg' => $image['jpeg'], 'pixelWidth' => $image['width'], 'pixelHeight' => $image['height']]; + + if ($edge !== 'cover' && $align !== 'full') { + $height = (float) ($layout['height'] ?? PdfTemplate::LOGO_DEFAULT); + $width = $height * $ratio; + + if ($width > (self::RIGHT - self::LEFT) / 2) { + $width = (self::RIGHT - self::LEFT) / 2; + $height = $width / $ratio; + } + + $padding = $edge === 'header' ? 24.0 : 14.0; + + return $common + [ + 'width' => $width, + 'height' => $height, + 'x' => $align === 'left' ? self::LEFT : self::RIGHT - $width, + 'y' => $edge === 'header' ? self::PAGE_HEIGHT - $padding - $height : $padding, + 'occupied' => $height + $padding, + ]; + } + + $width = (float) PdfDocument::WIDTH; + $height = $width / $ratio; + + if ($height > $maxHeight) { + $height = $maxHeight; + $width = $height * $ratio; + } + + return $common + [ + 'width' => $width, + 'height' => $height, + 'x' => (PdfDocument::WIDTH - $width) / 2, + 'y' => $edge === 'header' ? self::PAGE_HEIGHT - $height : 0.0, + 'occupied' => $height, + ]; + } + /** * @param array $guide * @param array $known Kapitelanfänge aus dem vorigen Durchgang */ - private function pass(array $guide, string $licensee, string $copyId, ?PdfImages $images, array $known, int $total): string + private function pass(array $guide, ?PdfTemplate $template, string $licensee, string $copyId, ?PdfImages $images, array $known, int $total): string { $this->pdf = new PdfDocument; $this->page = 0; - $this->total = 0; $this->starts = []; + $this->onCover = false; $this->footer = PdfFlow::printable('Lizenziert für '.$licensee.' · Lizenzkopie '.$copyId); - $this->flow = new PdfFlow($this->pdf, self::LEFT, self::RIGHT, self::TOP, self::BOTTOM, function (): void { + $this->flow = new PdfFlow($this->pdf, self::LEFT, self::RIGHT, $this->top, $this->bottom, function (): void { $this->closePage(); $this->newPage(); }, $images === null ? null : Closure::fromCallable($images)); - $knownTotal = $total; - $this->total = $knownTotal; - $this->newPage(); + $this->flow->onHeading = function (array $block, float $top): void { + $this->starts[$block['anchor']] = ['page' => $this->page, 'top' => $top]; + $this->pdf->bookmark((string) $block['text'], $this->page - 1, $top, (int) $block['level'] - 1); + }; + $this->total = $total; + $withCover = $template !== null && $template->show_cover; - $this->flow->write(PdfFlow::printable((string) $guide['title']), 24, true, 10); - $this->flow->write('Inhaltsverzeichnis', 14, true, 8, keep: 40); + if ($withCover) { + $this->onCover = true; + $this->newPage(); + $this->cover($guide, $template); + $this->closePage(); + $this->onCover = false; + $this->newPage(); + } else { + $this->newPage(); + $this->flow->write(PdfFlow::printable((string) $guide['title']), 24, true, 10); + } - foreach ($guide['chapters'] as $chapter) { - $this->contentsLine($chapter, $known[$chapter['anchor']] ?? ['page' => 1, 'top' => self::TOP]); + $setting = PdfTemplate::normalizeToc($template?->toc_mode, $template?->toc_depth); + $entries = $this->contents($guide, $setting['depth']); + $withContents = match ($setting['mode']) { + 'never' => false, + 'always' => true, + default => count($entries) > 1, + }; + $this->continueFirst = ! $withContents; + + if ($withContents) { + $this->flow->write('Inhaltsverzeichnis', 14, true, 8, keep: 40); + + foreach ($entries as $entry) { + $this->contentsLine($entry, $known[$entry['anchor']] ?? ['page' => 1, 'top' => $this->top]); + } } foreach ($guide['chapters'] as $chapter) { @@ -102,29 +225,120 @@ private function pass(array $guide, string $licensee, string $copyId, ?PdfImages } /** - * Eine Zeile des Inhaltsverzeichnisses: Nummer und Titel, Punktlinie, Seitenzahl; die ganze Zeile springt zum Kapitel. + * Titelseite: Bild (falls gewählt), Titel allein, Untertitel, dann Ausgabe, Veröffentlichung und Herausgeber, unten der + * Copyright-Vermerk. Die Vermerke der Fassung gehen dem Standard der Vorlage vor. * - * @param array $chapter + * @param array $guide + */ + private function cover(array $guide, PdfTemplate $template): void + { + $meta = is_array($guide['meta'] ?? null) ? $guide['meta'] : []; + $y = self::PAGE_HEIGHT - 150.0; + + if ($this->bands['cover'] !== null) { + $cover = $this->bands['cover']; + $this->pdf->image($cover['x'], self::PAGE_HEIGHT - $cover['height'], $cover['width'], $cover['height'], $cover['jpeg'], $cover['pixelWidth'], $cover['pixelHeight']); + $y = self::PAGE_HEIGHT - $cover['height'] - 90.0; + } + + $this->coverText(PdfFlow::printable((string) $guide['title']), 30.0, true, $y, 12.0); + + if (filled($meta['subtitle'] ?? null)) { + $this->coverText(PdfFlow::printable((string) $meta['subtitle']), 15.0, false, $y, 8.0); + } + + $y -= 26.0; + $facts = array_filter([ + filled($meta['edition'] ?? null) ? $meta['edition'] : null, + DocumentMeta::publishedLabel($meta) !== '' ? 'Veröffentlicht am '.DocumentMeta::publishedLabel($meta) : null, + filled($template->publisher) ? 'Herausgeber: '.$template->publisher : null, + ]); + + foreach ($facts as $fact) { + $this->coverText(PdfFlow::printable((string) $fact), 11.0, false, $y, 4.0); + } + + $copyright = trim((string) ($meta['copyright'] ?? '')) !== '' ? (string) $meta['copyright'] : (string) $template->copyright; + + if (trim($copyright) !== '') { + $lines = PdfDocument::wrap(PdfFlow::printable($copyright), self::RIGHT - self::LEFT, 8.5, false); + $at = $this->footerLine + 24.0 + (count($lines) - 1) * 12.0; + + foreach ($lines as $line) { + $this->pdf->text(self::LEFT, $at, $line, 8.5); + $at -= 12.0; + } + } + } + + private function coverText(string $text, float $size, bool $bold, float &$y, float $after): void + { + foreach (PdfDocument::wrap($text, self::RIGHT - self::LEFT, $size, $bold) as $line) { + $this->pdf->text(self::LEFT, $y, $line, $size, $bold); + $y -= $size + 6.0; + } + + $y -= $after; + } + + /** + * Die Einträge des Inhaltsverzeichnisses in der Reihenfolge des Dokuments: Kapitel und Unterkapitel mit Nummer, darunter + * ihre Zwischenüberschriften (h3 bis h6) bis zur gewählten Tiefe, eingerückt nach Stufe. Die Lesezeichen im PDF zeigen + * unabhängig davon alle Ebenen. + * + * @param array $guide + * @param int $depth höchste Überschriftenstufe im Verzeichnis (2 = nur Kapitel) + * @return list + */ + private function contents(array $guide, int $depth = 6): array + { + $entries = []; + + foreach ($guide['chapters'] as $chapter) { + $entries[] = [ + 'anchor' => $chapter['anchor'], + 'label' => $chapter['number'].' '.$chapter['title'], + 'size' => $chapter['level'] === 1 ? 11.0 : 10.0, + 'indent' => $chapter['level'] === 1 ? 0.0 : 18.0, + 'bold' => $chapter['level'] === 1, + ]; + + foreach ($chapter['headings'] ?? [] as $heading) { + if ($heading['level'] > $depth) { + continue; + } + + $entries[] = ['anchor' => $heading['anchor'], 'label' => $heading['text'], 'size' => 9.5, 'indent' => 18.0 + ($heading['level'] - 3) * 12.0, 'bold' => false]; + } + } + + return $entries; + } + + /** + * Eine Zeile des Inhaltsverzeichnisses: Titel, Punktlinie, Seitenzahl; die ganze Zeile springt zum Eintrag. + * + * @param array{anchor: string, label: string, size: float, indent: float, bold: bool} $entry * @param array{page: int, top: float} $target */ - private function contentsLine(array $chapter, array $target): void + private function contentsLine(array $entry, array $target): void { - $level = $chapter['level']; - $size = $level === 1 ? 11.0 : 10.0; - $indent = $level === 1 ? 0.0 : 18.0; - $label = PdfFlow::printable($chapter['number'].' '.$chapter['title']); + $size = $entry['size']; + $indent = $entry['indent']; + $bold = $entry['bold']; + $label = PdfFlow::printable($entry['label']); $pageText = (string) $target['page']; $numberWidth = PdfDocument::exactWidth($pageText, $size, false); - $lines = PdfDocument::wrap($label, self::RIGHT - self::LEFT - $indent - $numberWidth - 14, $size, $level === 1); + $lines = PdfDocument::wrap($label, self::RIGHT - self::LEFT - $indent - $numberWidth - 14, $size, $bold); $x = self::LEFT + $indent; $this->flow->room(count($lines) * ($size + 4) + 2); $top = $this->flow->y; foreach ($lines as $index => $line) { - $this->pdf->text($x, $this->flow->y, $line, $size, $level === 1); + $this->pdf->text($x, $this->flow->y, $line, $size, $bold); if ($index === count($lines) - 1) { - $used = PdfDocument::exactWidth($line, $size, $level === 1) + 4; + $used = PdfDocument::exactWidth($line, $size, $bold) + 4; $room = self::RIGHT - $numberWidth - 4 - ($x + $used); $dots = (int) floor($room / PdfDocument::exactWidth('.', 8, false)); @@ -149,11 +363,12 @@ private function chapter(array $chapter): void { $level = $chapter['level']; - if ($level === 1) { + if ($level === 1 && ! $this->continueFirst) { $this->closePage(); $this->newPage(); } + $this->continueFirst = false; $size = $level === 1 ? 18.0 : 13.5; $title = PdfFlow::printable($chapter['number'].' '.$chapter['title']); $this->flow->room(($size + 4) + 60); @@ -178,13 +393,23 @@ private function newPage(): void $this->pdf->addPage(); $this->page++; $this->flow->restart(); + + if (! $this->onCover && $this->bands['header'] !== null) { + $band = $this->bands['header']; + $this->pdf->image($band['x'], $band['y'], $band['width'], $band['height'], $band['jpeg'], $band['pixelWidth'], $band['pixelHeight']); + } } private function closePage(): void { - $this->pdf->line(self::LEFT, 54, self::RIGHT, 54, 0.4); - $this->pdf->text(self::LEFT, 40, $this->footer, 8); - $this->pdf->textRight(self::RIGHT, 40, 'Seite '.$this->page.($this->total > 0 ? ' von '.$this->total : ''), 8); + if (! $this->onCover && $this->bands['footer'] !== null) { + $band = $this->bands['footer']; + $this->pdf->image($band['x'], $band['y'], $band['width'], $band['height'], $band['jpeg'], $band['pixelWidth'], $band['pixelHeight']); + } + + $this->pdf->line(self::LEFT, $this->footerLine, self::RIGHT, $this->footerLine, 0.4); + $this->pdf->text(self::LEFT, $this->footerLine - 14.0, $this->footer, 8); + $this->pdf->textRight(self::RIGHT, $this->footerLine - 14.0, 'Seite '.$this->page.($this->total > 0 ? ' von '.$this->total : ''), 8); } private function asciiTitle(string $title): string diff --git a/app/Domain/Catalog/FormattedText.php b/app/Domain/Catalog/FormattedText.php index 11fb890..4841073 100644 --- a/app/Domain/Catalog/FormattedText.php +++ b/app/Domain/Catalog/FormattedText.php @@ -10,7 +10,7 @@ /** * Formatierter Text in der Verwaltung und im Mitgliederbereich (ADR-50, ADR-51). * - * Gespeichert wird bereinigtes HTML aus einer festen Auswahl: Absatz, Zwischenüberschrift (h3), fett, kursiv, Aufzählung, + * Gespeichert wird bereinigtes HTML aus einer festen Auswahl: Absatz, Zwischenüberschriften (h3 bis h6), fett, kursiv, Aufzählung, * nummerierte Liste, Zitat, Link, Zeilenumbruch, Tabelle und Bild. Alles andere fällt beim Speichern weg, auch Skripte, * Ereignis­attribute und Links auf andere Schemata als http, https und mailto. * @@ -29,7 +29,7 @@ final class FormattedText { /** Blockelemente, mit denen gespeichertes HTML beginnt. */ - private const BLOCKS = ['p', 'h3', 'ul', 'ol', 'blockquote', 'table', 'img']; + private const BLOCKS = ['p', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'blockquote', 'table', 'img']; /** Angaben der Redaktion, die formatiert gespeichert werden. Suchbegriffe, Titel und Teaser bleiben Klartext. */ public const FIELDS = ['summary', 'description']; @@ -39,7 +39,7 @@ final class FormattedText /** Symbolleiste der Editoren; muss zur Auswahl oben passen. */ public const TOOLBAR = [ ['bold', 'italic', 'link'], - ['h3'], + ['h3', 'h4', 'h5', 'h6'], ['bulletList', 'orderedList', 'blockquote'], ['table', 'tableAddRowAfter', 'tableAddColumnAfter', 'tableDeleteRow', 'tableDeleteColumn', 'tableToggleHeaderRow', 'tableDelete'], ['undo', 'redo'], @@ -130,6 +130,49 @@ public static function imageIds(?string $value): array return $ids; } + /** + * Versieht die Zwischenüberschriften (h3 bis h6, auf oberster Ebene des Texts) mit Sprungmarken `-u` und + * verschiebt ihre Stufe um `$shift` (höchstens h6). Die Marken zählen die nicht leeren Überschriften in ihrer Reihenfolge; + * {@see self::blocks()} zählt dieselben. + * + * @return array{html: string, headings: list} + */ + public static function anchorHeadings(string $html, string $prefix, int $shift = 0): array + { + if (preg_match('/]/i', $html) !== 1) { + return ['html' => $html, 'headings' => []]; + } + + $document = HTMLDocument::createFromString(''.$html.'', LIBXML_NOERROR); + $headings = []; + + foreach (iterator_to_array($document->body->childNodes) as $node) { + if ($node->nodeType !== XML_ELEMENT_NODE || preg_match('/^h([3-6])$/', strtolower($node->nodeName), $match) !== 1) { + continue; + } + + $text = trim((string) preg_replace('/\s+/u', ' ', (string) $node->textContent)); + + if ($text === '') { + continue; + } + + $level = min(6, (int) $match[1] + $shift); + $anchor = $prefix.'-u'.(count($headings) + 1); + $replacement = $document->createElement('h'.$level); + $replacement->setAttribute('id', $anchor); + + while ($node->firstChild !== null) { + $replacement->appendChild($node->firstChild); + } + + $node->replaceWith($replacement); + $headings[] = ['level' => $level, 'text' => $text, 'anchor' => $anchor]; + } + + return ['html' => trim($document->body->innerHTML), 'headings' => $headings]; + } + /** * Fügt die Adresse an jedes Bild, damit der Editor es zeigt. Die Adresse gehört nicht zum gespeicherten Wert: Die * Bereinigung entfernt sie beim Übernehmen aus dem Editor wieder. @@ -335,9 +378,10 @@ private static function extractBlocks(Node $parent): array continue; } - $type = match ($name) { - 'h3' => 'heading', - 'blockquote' => 'quote', + $level = preg_match('/^h([3-6])$/', $name, $heading) === 1 ? (int) $heading[1] : 0; + $type = match (true) { + $level > 0 => 'heading', + $name === 'blockquote' => 'quote', default => 'paragraph', }; @@ -345,7 +389,7 @@ private static function extractBlocks(Node $parent): array $images = $node->querySelectorAll('img'); if (count($images) === 0) { - $blocks[] = ['type' => $type, 'runs' => self::runs($node)]; + $blocks[] = self::textBlock($type, $level, self::runs($node)); continue; } @@ -355,7 +399,7 @@ private static function extractBlocks(Node $parent): array foreach ($node->childNodes as $child) { if ($child->nodeType === XML_ELEMENT_NODE && strtolower($child->nodeName) === 'img') { if (trim(self::runsText($pending)) !== '') { - $blocks[] = ['type' => $type, 'runs' => $pending]; + $blocks[] = self::textBlock($type, $level, $pending); } $pending = []; @@ -370,13 +414,26 @@ private static function extractBlocks(Node $parent): array } if (trim(self::runsText($pending)) !== '') { - $blocks[] = ['type' => $type, 'runs' => $pending]; + $blocks[] = self::textBlock($type, $level, $pending); } } return $blocks; } + /** + * Ein Textblock; eine Überschrift trägt zusätzlich ihre Stufe (3 bis 6) und ihren Text ohne Auszeichnung. + * + * @param list $runs + * @return array + */ + private static function textBlock(string $type, int $level, array $runs): array + { + return $type === 'heading' + ? ['type' => $type, 'level' => $level, 'text' => self::runsText($runs), 'runs' => $runs] + : ['type' => $type, 'runs' => $runs]; + } + /** * Klartext des Altbestands als HTML: Absätze an Leerzeilen, Listen mit „- “, „• “ oder „1. “, Zwischenüberschriften * mit „## “. Dieselben Konventionen wie {@see GuideText}. @@ -520,7 +577,7 @@ private static function table(Node $table): string } $inner = self::inner($cell); - $cells .= '<'.$name.$attributes.'>'.($inner === '' ? '

' : (preg_match('/^<(?:p|ul|ol|blockquote|h3|img)[\s>]/', $inner) === 1 ? $inner : '

'.$inner.'

')).''; + $cells .= '<'.$name.$attributes.'>'.($inner === '' ? '

' : (preg_match('/^<(?:p|ul|ol|blockquote|h[3-6]|img)[\s>]/', $inner) === 1 ? $inner : '

'.$inner.'

')).''; } if ($cells !== '') { @@ -575,12 +632,12 @@ private static function hasText(string $html): bool return trim(html_entity_decode(strip_tags($html), ENT_QUOTES | ENT_HTML5, 'UTF-8')) !== ''; } - /** b, i und andere Überschriftsstufen der Quelle werden auf die feste Auswahl abgebildet; der Rest fällt in der Bereinigung weg. */ + /** b, i und die Überschriftsstufen 1 und 2 der Quelle werden auf die feste Auswahl abgebildet (h1 und h2 gehören dem Dokument und dem Kapitel); der Rest fällt in der Bereinigung weg. */ private static function mapLegacyTags(string $html): string { $html = (string) preg_replace('/<(\/?)b(?=[\s>\/])/i', '<$1strong', $html); $html = (string) preg_replace('/<(\/?)i(?=[\s>\/])/i', '<$1em', $html); - $html = (string) preg_replace('/<(\/?)h[1-6](?=[\s>\/])/i', '<$1h3', $html); + $html = (string) preg_replace('/<(\/?)h[12](?=[\s>\/])/i', '<$1h3', $html); return (string) preg_replace('/<(\/?)div(?=[\s>\/])/i', '<$1p', $html); } @@ -644,6 +701,9 @@ private static function sanitizer(): HtmlSanitizer ->allowElement('p') ->allowElement('br') ->allowElement('h3') + ->allowElement('h4') + ->allowElement('h5') + ->allowElement('h6') ->allowElement('strong') ->allowElement('em') ->allowElement('ul') diff --git a/app/Domain/Catalog/PdfFlow.php b/app/Domain/Catalog/PdfFlow.php index 7efaab3..26fa715 100644 --- a/app/Domain/Catalog/PdfFlow.php +++ b/app/Domain/Catalog/PdfFlow.php @@ -18,6 +18,13 @@ final class PdfFlow { public float $y; + /** + * Wird für jede Zwischenüberschrift mit Sprungmarke aufgerufen, bevor sie gesetzt wird: Block und obere Kante. + * + * @var (Closure(array, float): void)|null + */ + public ?Closure $onHeading = null; + /** Schachtelungstiefe beim Setzen einer Tabelle (Zelleninhalt setzt nie wieder eine Tabelle). */ private int $depth = 0; @@ -116,9 +123,20 @@ public function formatted(array $blocks, ?float $x = null, float $size = 10.5): */ private function headingBlock(array $block, float $x, float $size): void { + // Stufe 3 ist die größte Zwischenüberschrift, Stufe 6 hat Textgröße (und steht kursiv). + $level = max(3, min(6, (int) ($block['level'] ?? 3))); + $heading = $size + [3 => 2.0, 4 => 1.0, 5 => 0.5, 6 => 0.0][$level]; + $gap = [3 => 6.0, 4 => 4.0, 5 => 3.0, 6 => 2.0][$level]; + // Eine Zwischenüberschrift bleibt bei ihrem Text: mindestens zwei Zeilen müssen mit auf die Seite. - $this->room(($size + 0.5) + 4 + 2 * ($size + 4)); - $this->runs($block['runs'], $x, $size + 0.5, bold: true, after: 4); + $this->room($gap + $heading + 4 + 2 * ($size + 4)); + $this->y -= $gap; + + if ($this->onHeading !== null && isset($block['anchor'])) { + ($this->onHeading)($block, $this->y + $heading); + } + + $this->runs($block['runs'], $x, $heading, bold: true, italic: $level === 6, after: 4); } /** diff --git a/app/Domain/Catalog/PdfTemplate.php b/app/Domain/Catalog/PdfTemplate.php new file mode 100644 index 0000000..8d58475 --- /dev/null +++ b/app/Domain/Catalog/PdfTemplate.php @@ -0,0 +1,153 @@ + 'boolean']; + } + + public const SLOTS = ['header', 'footer', 'cover']; + + /** Anordnung von Kopf- und Fußgrafik: Band in voller Seitenbreite oder Logo links oder rechts. */ + public const ALIGNMENTS = ['full', 'left', 'right']; + + public const LOGO_MIN = 16; + + public const LOGO_MAX = 100; + + public const LOGO_DEFAULT = 40; + + /** Inhaltsverzeichnis: nur bei mehr als einem Eintrag, immer oder nie. */ + public const TOC_MODES = ['auto', 'always', 'never']; + + /** Tiefe des Verzeichnisses: 2 = nur Kapitel und Unterkapitel, 3 bis 6 = zusätzlich die Überschriften bis zu dieser Stufe. */ + public const TOC_DEPTH_MIN = 2; + + public const TOC_DEPTH_MAX = 6; + + /** + * Darstellung des gedruckten Inhaltsverzeichnisses. + * + * @return array{mode: string, depth: int} + */ + public function toc(): array + { + return self::normalizeToc((string) $this->getAttribute('toc_mode'), (int) $this->getAttribute('toc_depth')); + } + + /** + * @return array{mode: string, depth: int} + */ + public static function normalizeToc(?string $mode, int|string|null $depth): array + { + $depth = (int) $depth; + + return [ + 'mode' => in_array($mode, self::TOC_MODES, true) ? (string) $mode : 'auto', + 'depth' => $depth < 1 ? self::TOC_DEPTH_MAX : max(self::TOC_DEPTH_MIN, min(self::TOC_DEPTH_MAX, $depth)), + ]; + } + + /** + * Anordnung und Logohöhe (Punkt) von Kopf oder Fuß; ungültige Werte fallen auf die Vorgabe zurück. + * + * @return array{align: string, height: int} + */ + public function layout(string $slot): array + { + return self::normalizeLayout((string) $this->getAttribute($slot.'_align'), (int) $this->getAttribute($slot.'_logo_height')); + } + + /** + * @return array{align: string, height: int} + */ + public static function normalizeLayout(?string $align, int|string|null $height): array + { + $height = (int) $height; + + return [ + 'align' => in_array($align, self::ALIGNMENTS, true) ? (string) $align : 'full', + 'height' => $height < 1 ? self::LOGO_DEFAULT : max(self::LOGO_MIN, min(self::LOGO_MAX, $height)), + ]; + } + + /** + * Das Bild eines Bildfelds als Ziel des Pickers: `element:`, `medium:` oder null. + */ + public function target(string $slot): ?string + { + $version = $this->getAttribute($slot.'_version_id'); + $element = $this->getAttribute($slot.'_element_id'); + + return $version !== null ? 'element:'.$version : ($element !== null ? 'medium:'.$element : null); + } + + /** + * Die Spaltenwerte eines Bildfelds für ein Ziel des Pickers. + * + * @return array + */ + public static function columns(string $slot, ?string $target): array + { + $ref = TemplateImage::parse($target); + + return [ + $slot.'_version_id' => ($ref['type'] ?? null) === 'version' ? $ref['id'] : null, + $slot.'_element_id' => ($ref['type'] ?? null) === 'medium' ? $ref['id'] : null, + ]; + } + + public function headerVersion(): BelongsTo + { + return $this->belongsTo(ContentElementVersion::class, 'header_version_id'); + } + + public function footerVersion(): BelongsTo + { + return $this->belongsTo(ContentElementVersion::class, 'footer_version_id'); + } + + public function coverVersion(): BelongsTo + { + return $this->belongsTo(ContentElementVersion::class, 'cover_version_id'); + } + + public function compositions(): HasMany + { + return $this->hasMany(Composition::class); + } +} diff --git a/app/Domain/Catalog/TemplateImage.php b/app/Domain/Catalog/TemplateImage.php new file mode 100644 index 0000000..348c5ac --- /dev/null +++ b/app/Domain/Catalog/TemplateImage.php @@ -0,0 +1,148 @@ +`: ein Bild mit Inhaltsfassung (Datei im abgeleiteten Bestand), gleich in welchem Stand; nur ein gesperrtes Bild nicht, + * - `medium:`: ein Bild ohne Inhaltsfassung, also ein Präsentationsmedium oder ein für die Website freigegebenes Bild. Gedruckt wird + * die für die Website freigegebene Datei, sonst die Präsentationsdatei. + * + * Jedes Bild mit vorhandener Datei lässt sich verwenden. Das Bild ist Gestaltung der Vorlage und kein lizenzierter Inhalt; es geht nicht über + * die Rechteprüfung der Mitglieder und braucht keine Inhaltsfassung. + */ +final class TemplateImage +{ + /** + * @return array{type: 'version'|'medium', id: int}|null + */ + public static function parse(?string $target): ?array + { + if ($target !== null && preg_match('/^(element|medium):(\d+)$/', $target, $match) === 1) { + return ['type' => $match[1] === 'element' ? 'version' : 'medium', 'id' => (int) $match[2]]; + } + + return null; + } + + /** Die Bilddatei als Bytes, oder null, wenn sie nicht vorliegt. */ + public static function bytes(?string $target): ?string + { + $source = self::source($target); + + return $source === null ? null : (string) Storage::disk($source['disk'])->get($source['path']); + } + + /** Warum sich das Bild nicht verwenden lässt; null, wenn es geht. */ + public static function problem(?string $target): ?string + { + $ref = self::parse($target); + + if ($ref === null) { + return 'Das ist kein Bild des Medienmanagers.'; + } + + if ($ref['type'] === 'version') { + $version = ContentElementVersion::query()->with('element')->find($ref['id']); + + if (! $version instanceof ContentElementVersion || $version->element === null || $version->element->output_class !== 'bild') { + return 'Das ist kein Bild des Medienmanagers.'; + } + + // Gestaltung braucht keine Freigabe der Fassung; nur ein bewusst gesperrtes Bild bleibt außen vor. + if ($version->status === ContentVersionStatus::Gesperrt) { + return 'Dieses Bild ist deaktiviert.'; + } + } else { + $element = ContentElement::query()->find($ref['id']); + + if (! $element instanceof ContentElement || $element->output_class !== 'bild' || $element->archived_at !== null) { + return 'Das ist kein Bild des Medienmanagers.'; + } + } + + return self::source($target) === null ? 'Die Bilddatei liegt nicht vor.' : null; + } + + public static function title(?string $target): string + { + $ref = self::parse($target); + $element = match ($ref['type'] ?? null) { + 'version' => ContentElementVersion::query()->with('element')->find($ref['id'])?->element, + 'medium' => ContentElement::query()->find($ref['id']), + default => null, + }; + + return $element === null ? '' : (string) ($element->display_title ?: $element->working_title); + } + + /** Adresse zur Ansicht in der Verwaltung (Vorschau im Formular). */ + public static function previewUrl(?string $target): ?string + { + $ref = self::parse($target); + + if ($ref === null) { + return null; + } + + if ($ref['type'] === 'version') { + return EmbeddedImages::staffSource($ref['id']); + } + + $element = ContentElement::query()->find($ref['id']); + + if (! $element instanceof ContentElement) { + return null; + } + + if ($element->website_released_at !== null && $element->website_public_path !== null) { + return route('website.media', $element); + } + + return app(EditorialCatalog::class)->cardUrl('element', $element->id, $element->thumbnail_path); + } + + /** + * @return array{disk: string, path: string}|null + */ + private static function source(?string $target): ?array + { + $ref = self::parse($target); + + if ($ref === null) { + return null; + } + + if ($ref['type'] === 'version') { + $version = ContentElementVersion::query()->find($ref['id']); + $file = $version instanceof ContentElementVersion ? EmbeddedImages::file($version) : null; + + return $file === null ? null : ['disk' => 'media_derived', 'path' => $file]; + } + + $element = ContentElement::query()->find($ref['id']); + + if (! $element instanceof ContentElement) { + return null; + } + + $public = (string) $element->website_public_path; + + if ($element->website_released_at !== null && preg_match('#^website/'.$element->id.'/datei\.[a-z0-9]+$#', $public) === 1 && Storage::disk('media_public')->exists($public)) { + return ['disk' => 'media_public', 'path' => $public]; + } + + $preview = (string) $element->thumbnail_path; + + if (str_starts_with($preview, 'vorschau/') && ! str_contains($preview, '..') && Storage::disk('media_derived')->exists($preview)) { + return ['disk' => 'media_derived', 'path' => $preview]; + } + + return null; + } +} diff --git a/app/Domain/Commerce/Receipt/PdfDocument.php b/app/Domain/Commerce/Receipt/PdfDocument.php index ba4e4c4..c70bbe5 100644 --- a/app/Domain/Commerce/Receipt/PdfDocument.php +++ b/app/Domain/Commerce/Receipt/PdfDocument.php @@ -98,10 +98,10 @@ public function link(float $x, float $y, float $w, float $h, int $page, float $t $this->links[array_key_last($this->pages)][] = ['x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'page' => $page, 'top' => $top]; } - /** Lesezeichen (Ebene 1 oder 2) für die Gliederung in PDF-Betrachtern. */ + /** Lesezeichen (Ebene 1 bis 6) für die Gliederung in PDF-Betrachtern. */ public function bookmark(string $title, int $page, float $top, int $level = 1): void { - $this->outline[] = ['title' => $title, 'page' => $page, 'top' => $top, 'level' => $level >= 2 ? 2 : 1]; + $this->outline[] = ['title' => $title, 'page' => $page, 'top' => $top, 'level' => max(1, min(6, $level))]; } public function text(float $x, float $y, string $text, float $size = 10, bool $bold = false, bool $italic = false): void @@ -325,17 +325,23 @@ private function outlineObjects(int $root, array $numbers, int $pageCount): arra { $parentOf = []; $childrenOf = []; - $lastTop = null; + $descendants = []; + $path = []; + // Ein Eintrag gehört zum nächsten davor mit kleinerer Ebene; ohne einen solchen steht er oben. foreach ($this->outline as $index => $item) { - if ($item['level'] === 1 || $lastTop === null) { - $parentOf[$index] = null; - $lastTop = $index; - } else { - $parentOf[$index] = $lastTop; + while ($path !== [] && $this->outline[$path[array_key_last($path)]]['level'] >= $item['level']) { + array_pop($path); } + $parentOf[$index] = $path === [] ? null : $path[array_key_last($path)]; $childrenOf[$parentOf[$index] ?? -1][] = $index; + + foreach ($path as $ancestor) { + $descendants[$ancestor] = ($descendants[$ancestor] ?? 0) + 1; + } + + $path[] = $index; } $top = $childrenOf[-1]; @@ -348,7 +354,7 @@ private function outlineObjects(int $root, array $numbers, int $pageCount): arra $objects[$numbers[$index]] = '<< /Title ('.self::escape($item['title']).') /Parent '.($parentOf[$index] === null ? $root : $numbers[$parentOf[$index]]).' 0 R' .($position > 0 ? ' /Prev '.$numbers[$siblings[$position - 1]].' 0 R' : '') .($position < count($siblings) - 1 ? ' /Next '.$numbers[$siblings[$position + 1]].' 0 R' : '') - .($kids === [] ? '' : ' /First '.$numbers[$kids[0]].' 0 R /Last '.$numbers[$kids[array_key_last($kids)]].' 0 R /Count '.count($kids)) + .($kids === [] ? '' : ' /First '.$numbers[$kids[0]].' 0 R /Last '.$numbers[$kids[array_key_last($kids)]].' 0 R /Count '.($descendants[$index] ?? 0)) .' /Dest ['.(6 + 2 * min($item['page'], $pageCount - 1)).' 0 R /XYZ 0 '.$this->n($item['top']).' null] >>'; } diff --git a/app/Filament/Pages/PdfVorlagen.php b/app/Filament/Pages/PdfVorlagen.php new file mode 100644 index 0000000..e36d70d --- /dev/null +++ b/app/Filament/Pages/PdfVorlagen.php @@ -0,0 +1,387 @@ + + */ + public array $anordnung = ['header' => 'full', 'footer' => 'full']; + + /** + * Höhe des Logos in Punkt, wenn Kopf oder Fuß ein Logo tragen. + * + * @var array + */ + public array $logohoehe = ['header' => PdfTemplate::LOGO_DEFAULT, 'footer' => PdfTemplate::LOGO_DEFAULT]; + + /** + * Die Bilder je Bildfeld (header, footer, cover) als Ziel des Pickers: `element:` oder `medium:`. + * + * @var array + */ + public array $bilder = ['header' => null, 'footer' => null, 'cover' => null]; + + /** Das Bildfeld, in das die Auswahl übernommen wird: header, footer oder cover. */ + public ?string $bildFeld = null; + + /** @var array{aktion: string, argument: int|string|null, titel: string, text: string, label: string, gefahr: bool}|null */ + public ?array $bestaetigung = null; + + public static function canAccess(): bool + { + return ContentElementResource::editor(); + } + + public function mount(): void + { + $first = PdfTemplate::query()->where('kind', PdfTemplate::KIND_DOCUMENT)->orderBy('name')->first(); + $first instanceof PdfTemplate ? $this->loadTemplate($first) : $this->clearForm(); + } + + public function getHeading(): string|Htmlable|null + { + return null; + } + + public function getMaxContentWidth(): Width|string|null + { + return Width::Full; + } + + /** + * @return list + */ + public function templates(): array + { + return PdfTemplate::query()->where('kind', PdfTemplate::KIND_DOCUMENT)->withCount('compositions')->orderBy('name')->get() + ->map(fn (PdfTemplate $template): array => ['id' => $template->id, 'name' => $template->name, 'documents' => (int) $template->compositions_count])->all(); + } + + public function select(int $id): void + { + $template = PdfTemplate::query()->where('kind', PdfTemplate::KIND_DOCUMENT)->find($id); + + if ($template instanceof PdfTemplate) { + $this->loadTemplate($template); + } + } + + public function newTemplate(): void + { + $this->clearForm(); + } + + /** Ob die Eingaben vom gespeicherten Stand abweichen. */ + public function changed(): bool + { + $template = $this->templateId > 0 ? PdfTemplate::query()->find($this->templateId) : null; + + if (! $template instanceof PdfTemplate) { + return $this->name !== '' || $this->publisher !== '' || $this->copyright !== '' || array_filter($this->bilder) !== [] || $this->layouts() !== [PdfTemplate::normalizeLayout(null, null), PdfTemplate::normalizeLayout(null, null)] || $this->tocSetting() !== PdfTemplate::normalizeToc(null, null); + } + + return $this->name !== $template->name + || $this->publisher !== (string) $template->publisher + || $this->copyright !== (string) $template->copyright + || $this->showCover !== (bool) $template->show_cover + || $this->bilder !== $this->templateSlots($template) + || $this->layouts() !== [$template->layout('header'), $template->layout('footer')] + || $this->tocSetting() !== $template->toc(); + } + + public function save(): void + { + abort_unless(ContentElementResource::editor(), 403); + + if (trim($this->name) === '') { + Notification::make()->danger()->title('Der Name fehlt.')->body('Er bezeichnet die Vorlage bei der Auswahl am Dokument.')->send(); + + return; + } + + foreach (PdfTemplate::SLOTS as $slot) { + $problem = $this->bilder[$slot] === null ? null : TemplateImage::problem($this->bilder[$slot]); + + if ($problem !== null) { + Notification::make()->danger()->title('Das Bild für '.$this->slotLabel($slot).' lässt sich nicht verwenden.')->body($problem)->send(); + + return; + } + } + + $values = [ + 'name' => trim($this->name), + 'kind' => PdfTemplate::KIND_DOCUMENT, + 'show_cover' => $this->showCover, + ...PdfTemplate::columns('header', $this->bilder['header']), + ...PdfTemplate::columns('footer', $this->bilder['footer']), + ...PdfTemplate::columns('cover', $this->bilder['cover']), + 'header_align' => $this->layouts()[0]['align'], + 'header_logo_height' => $this->layouts()[0]['height'], + 'footer_align' => $this->layouts()[1]['align'], + 'footer_logo_height' => $this->layouts()[1]['height'], + 'toc_mode' => $this->tocSetting()['mode'], + 'toc_depth' => $this->tocSetting()['depth'], + 'publisher' => trim($this->publisher) === '' ? null : trim($this->publisher), + 'copyright' => trim($this->copyright) === '' ? null : trim($this->copyright), + ]; + $template = $this->templateId > 0 ? PdfTemplate::query()->find($this->templateId) : null; + $template instanceof PdfTemplate ? $template->update($values) : $template = PdfTemplate::query()->create($values); + $this->loadTemplate($template); + Notification::make()->success()->title('Vorlage gespeichert')->body('Sie gilt sofort für jedes Dokument, das sie verwendet, auch für ältere Fassungen.')->send(); + } + + public function askConfirmation(string $aktion): void + { + if ($aktion === 'delete' && $this->templateId > 0) { + $uses = PdfTemplate::query()->withCount('compositions')->find($this->templateId)?->compositions_count ?? 0; + $this->bestaetigung = [ + 'aktion' => 'delete', + 'argument' => null, + 'titel' => '„'.$this->name.'“ löschen?', + 'text' => $uses > 0 + ? $uses.' '.($uses === 1 ? 'Dokument verwendet' : 'Dokumente verwenden').' diese Vorlage und '.($uses === 1 ? 'erzeugt' : 'erzeugen').' danach wieder das einfache PDF ohne Titelseite. Die Bilder bleiben im Medienbestand.' + : 'Die Vorlage wird entfernt. Die Bilder bleiben im Medienbestand.', + 'label' => 'Vorlage löschen', + 'gefahr' => true, + ]; + } + } + + public function confirmConfirmation(): void + { + $frage = $this->bestaetigung; + $this->bestaetigung = null; + + if (($frage['aktion'] ?? null) === 'delete' && $this->templateId > 0) { + abort_unless(ContentElementResource::editor(), 403); + PdfTemplate::query()->whereKey($this->templateId)->delete(); + $this->mount(); + Notification::make()->success()->title('Vorlage gelöscht')->send(); + } + } + + public function cancelConfirmation(): void + { + $this->bestaetigung = null; + } + + public function openImagePicker(string $slot): void + { + if (! in_array($slot, ['header', 'footer', 'cover'], true)) { + return; + } + + $this->bildFeld = $slot; + $this->resetPicker('vorlagenbild'); + $this->pickerKind = 'bild'; + } + + public function clearImage(string $slot): void + { + if (in_array($slot, PdfTemplate::SLOTS, true)) { + $this->bilder[$slot] = null; + } + } + + public function pickerAllowsMany(): bool + { + return false; + } + + public function closePicker(): void + { + $this->pickerOpen = false; + $this->pickerSelected = ''; + $this->pickerInspected = ''; + $this->pickerMarked = []; + $this->bildFeld = null; + } + + public function confirmPicker(): void + { + $target = array_key_first($this->pickerMarked); + $slot = $this->bildFeld; + + if ($target === null || $slot === null || ! in_array($slot, PdfTemplate::SLOTS, true)) { + return; + } + + $problem = TemplateImage::problem((string) $target); + + if ($problem !== null) { + Notification::make()->danger()->title('Dieses Bild lässt sich nicht verwenden.')->body($problem)->send(); + + return; + } + + $this->bilder[$slot] = (string) $target; + $this->closePicker(); + } + + /** @return array */ + public function pickerKinds(): array + { + return ['bild' => 'Bilder']; + } + + public function pickerTitle(): string + { + return 'Bild für '.$this->slotLabel((string) $this->bildFeld); + } + + public function pickerConfirmLabel(): string + { + return 'Bild übernehmen'; + } + + /** @return array{art: string, titel: string} */ + public function pickerKontext(): array + { + return ['art' => 'die PDF-Vorlage', 'titel' => trim($this->name) !== '' ? $this->name : 'neue Vorlage']; + } + + /** @return array */ + public function presentationRoleOptions(): array + { + return []; + } + + /** @return array|null */ + public function pickerReplacing(): ?array + { + return null; + } + + public function imageUrl(?string $target): ?string + { + return TemplateImage::previewUrl($target); + } + + public function imageTitle(?string $target): string + { + return TemplateImage::title($target); + } + + public function slotLabel(string $slot): string + { + return match ($slot) { + 'header' => 'den Kopf der Seiten', + 'footer' => 'den Fuß der Seiten', + 'cover' => 'die Titelseite', + default => 'die Vorlage', + }; + } + + private function loadTemplate(PdfTemplate $template): void + { + $this->templateId = $template->id; + $this->name = $template->name; + $this->publisher = (string) $template->publisher; + $this->copyright = (string) $template->copyright; + $this->showCover = (bool) $template->show_cover; + $this->bilder = $this->templateSlots($template); + $this->anordnung = ['header' => $template->layout('header')['align'], 'footer' => $template->layout('footer')['align']]; + $this->logohoehe = ['header' => $template->layout('header')['height'], 'footer' => $template->layout('footer')['height']]; + $this->tocModus = $template->toc()['mode']; + $this->tocTiefe = $template->toc()['depth']; + } + + /** + * @return array{mode: string, depth: int} + */ + private function tocSetting(): array + { + return PdfTemplate::normalizeToc($this->tocModus, $this->tocTiefe); + } + + /** + * Anordnung und Logohöhe von Kopf und Fuß, ungültige Eingaben auf gültige Werte gebracht. + * + * @return list + */ + private function layouts(): array + { + return [ + PdfTemplate::normalizeLayout($this->anordnung['header'] ?? null, $this->logohoehe['header'] ?? null), + PdfTemplate::normalizeLayout($this->anordnung['footer'] ?? null, $this->logohoehe['footer'] ?? null), + ]; + } + + /** + * @return array + */ + private function templateSlots(PdfTemplate $template): array + { + return ['header' => $template->target('header'), 'footer' => $template->target('footer'), 'cover' => $template->target('cover')]; + } + + private function clearForm(): void + { + $this->templateId = 0; + $this->name = ''; + $this->publisher = ''; + $this->copyright = ''; + $this->showCover = true; + $this->bilder = ['header' => null, 'footer' => null, 'cover' => null]; + $this->anordnung = ['header' => 'full', 'footer' => 'full']; + $this->logohoehe = ['header' => PdfTemplate::LOGO_DEFAULT, 'footer' => PdfTemplate::LOGO_DEFAULT]; + $this->tocModus = 'auto'; + $this->tocTiefe = PdfTemplate::TOC_DEPTH_MAX; + } + + protected function pickerExceptId(): int + { + return 0; + } +} diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index 6b6d016..48a050f 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -12,6 +12,7 @@ use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; use App\Domain\Catalog\ContentVersionStatus; +use App\Domain\Catalog\DocumentMeta; use App\Domain\Catalog\DomainRuleException; use App\Domain\Catalog\EditorialVocabulary; use App\Domain\Catalog\EditorialWorkingDraft; @@ -21,6 +22,7 @@ use App\Domain\Catalog\IdentityDimension; use App\Domain\Catalog\IdentityDimensionValue; use App\Domain\Catalog\IdentityProfile; +use App\Domain\Catalog\PdfTemplate; use App\Domain\Catalog\StructureNode; use App\Domain\Cms\Catalog\PublicCatalogReader; use App\Domain\Cms\Widgets\RenderContext; @@ -81,6 +83,18 @@ abstract class EditComposition extends EditRecord public string $durationMax = ''; + /** Dokumentfassung (ADR-51): Angaben für Titelseite und Impressum des PDF. Sie gehören zur Fassung. */ + public string $docSubtitle = ''; + + public string $docEdition = ''; + + public string $docPublished = ''; + + public string $docCopyright = ''; + + /** Die PDF-Vorlage des Dokuments („“ = bisheriges Layout). Wirkt sofort, ohne Fassung. */ + public string $pdfTemplateId = ''; + public string $prerequisites = ''; public string $newVariantName = ''; @@ -1856,6 +1870,7 @@ public function publishRevision(): bool 'duration_max' => $this->blank($this->durationMax), 'material_note' => $this->richBlank('materialNote'), 'prerequisites' => $this->blank($this->prerequisites), + 'document_meta' => $this->documentMetaNow(), ], $this->releaseConsent, $this->normalizeVariants($this->variants), @@ -1975,6 +1990,7 @@ protected function loadAufbau(): void $this->thumbnailError = $composition->thumbnail_error; $this->thumbnailSource = $composition->thumbnail_source; $this->imageCaptionText = $this->captionFor($composition->thumbnail_source); + $this->pdfTemplateId = $composition->pdf_template_id === null ? '' : (string) $composition->pdf_template_id; $this->catalogScope = match ($this->hostKind()) { CompositionKind::Kurs => 'module', CompositionKind::Uebung => 'uebungen', @@ -1998,6 +2014,7 @@ protected function loadAufbau(): void $this->learningGoal = ''; $this->durationMinutes = ''; $this->materialNote = ''; + $this->fillDocumentMeta(null); return; } @@ -2040,6 +2057,7 @@ protected function applyDraft(array $draft): void $this->learningGoal = (string) ($draft['learning_goal'] ?? ''); $this->durationMinutes = ($draft['duration_minutes'] ?? null) === null ? '' : (string) $draft['duration_minutes']; $this->materialNote = (string) ($draft['material_note'] ?? ''); + $this->fillDocumentMeta($draft['document_meta'] ?? null); $this->revisionNote = (string) ($draft['revision_note'] ?? ''); $this->selected = null; $this->roleDraft = ''; @@ -2063,6 +2081,7 @@ protected function applyVersion(CompositionVersion $version): void $this->learningGoal = (string) ($version->learning_goal ?? ''); $this->durationMinutes = $version->duration_minutes === null ? '' : (string) $version->duration_minutes; $this->materialNote = (string) ($version->material_note ?? ''); + $this->fillDocumentMeta($version->document_meta); $this->selected = null; $this->roleDraft = ''; $this->noteDraft = ''; @@ -2179,6 +2198,66 @@ protected function sameMembers(CompositionVersion $version): bool return $current === $next; } + /** + * Die Angaben der Dokumentfassung im Arbeitsstand; nur bei einem Dokument, sonst null. + * + * @return array|null + */ + protected function documentMetaNow(): ?array + { + if (! $this->isDocument()) { + return null; + } + + return DocumentMeta::normalize([ + 'subtitle' => $this->docSubtitle, + 'edition' => $this->docEdition, + 'published_on' => $this->docPublished, + 'copyright' => $this->docCopyright, + ]); + } + + protected function fillDocumentMeta(mixed $meta): void + { + $meta = DocumentMeta::normalize($meta) ?? []; + $this->docSubtitle = $meta['subtitle'] ?? ''; + $this->docEdition = $meta['edition'] ?? ''; + $this->docPublished = $meta['published_on'] ?? ''; + $this->docCopyright = $meta['copyright'] ?? ''; + } + + /** + * Die wählbaren PDF-Vorlagen für Dokumente. + * + * @return array + */ + public function pdfTemplateOptions(): array + { + return PdfTemplate::query()->where('kind', PdfTemplate::KIND_DOCUMENT)->orderBy('name')->pluck('name', 'id') + ->mapWithKeys(fn (string $name, int|string $id): array => [(string) $id => $name])->all(); + } + + /** Ordnet dem Dokument eine PDF-Vorlage zu. Das gilt sofort für jedes PDF dieses Dokuments, auch für ältere Fassungen. */ + public function savePdfTemplate(): void + { + $this->guardEditorial(); + $id = ctype_digit($this->pdfTemplateId) ? (int) $this->pdfTemplateId : null; + + if ($id !== null && ! PdfTemplate::query()->where('kind', PdfTemplate::KIND_DOCUMENT)->whereKey($id)->exists()) { + $this->feedback = 'Diese PDF-Vorlage gibt es nicht mehr.'; + + return; + } + + /** @var Composition $composition */ + $composition = $this->getRecord(); + $composition->pdf_template_id = $id; + $composition->save(); + $this->feedback = $id === null + ? 'Das Dokument verwendet wieder das einfache PDF-Layout ohne Titelseite.' + : 'Die PDF-Vorlage ist zugeordnet. Sie gilt sofort für jedes PDF dieses Dokuments, auch für ältere Fassungen; Ausgabe, Datum und Vermerk bleiben je Fassung.'; + } + protected function didacticChanged(CompositionVersion $version): bool { $minutes = $this->minutes($this->durationMinutes); @@ -2198,6 +2277,7 @@ protected function didacticChanged(CompositionVersion $version): bool || $version->prerequisites !== $this->blank($this->prerequisites) || ($version->duration_max === null ? null : (string) $version->duration_max) !== $this->blank($this->durationMax) || $storedVariants !== $this->normalizeVariants($this->variants) + || DocumentMeta::normalize($version->document_meta) !== $this->documentMetaNow() || $storedMinutes !== $minutes; } @@ -2420,6 +2500,7 @@ protected function payload(): array 'prerequisites' => $this->blank($this->prerequisites), 'variants' => $this->normalizeVariants($this->variants), 'revision_note' => $this->blank($this->revisionNote), + 'document_meta' => $this->documentMetaNow(), // Ungespeicherte Texte der Kapitel gelten als Änderung des Entwurfs; nach dem Speichern sind sie leer. 'chapters' => $this->chapterEditsNow(), 'members' => array_values(array_map( @@ -2466,6 +2547,7 @@ protected function readyPayload(): array 'prerequisites' => null, 'variants' => [], 'revision_note' => null, + 'document_meta' => null, 'members' => [], ]; } @@ -2482,6 +2564,7 @@ protected function readyPayload(): array 'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description, 'origin' => $variant->origin, ])->all()), 'revision_note' => null, + 'document_meta' => DocumentMeta::normalize($version->document_meta), 'members' => array_values(array_map( fn (array $row): array => [ 'role' => trim((string) ($row['role'] ?? '')), @@ -2524,6 +2607,7 @@ protected function normalizePayload(array $payload): array 'prerequisites' => $payload['prerequisites'] ?? null, 'variants' => $this->normalizeVariants($payload['variants'] ?? []), 'revision_note' => $payload['revision_note'] ?? null, + 'document_meta' => DocumentMeta::normalize($payload['document_meta'] ?? null), 'chapters' => is_array($payload['chapters'] ?? null) ? $payload['chapters'] : [], 'members' => $members, ]; diff --git a/app/Filament/Support/ChoosesMedia.php b/app/Filament/Support/ChoosesMedia.php index f3f5daf..5761daf 100644 --- a/app/Filament/Support/ChoosesMedia.php +++ b/app/Filament/Support/ChoosesMedia.php @@ -106,6 +106,11 @@ public function pickerResult(): array return ['items' => [], 'more' => false]; } + // Eine PDF-Vorlage nimmt auch Bilder ohne Inhaltsfassung (Präsentationsmedien, Website-Bilder) auf. + if ($this->pickerPurpose === 'vorlagenbild') { + return $this->filterByMaterialart(app(EditorialCatalog::class)->presentationBrowse($this->pickerQuery, 'bild')); + } + if (in_array($this->pickerPurpose, ['aufbau', 'textbild'], true)) { $image = $this->pickerPurpose === 'textbild'; diff --git a/app/Http/Controllers/DocumentPreviewController.php b/app/Http/Controllers/DocumentPreviewController.php index fc8fbdb..ab56884 100644 --- a/app/Http/Controllers/DocumentPreviewController.php +++ b/app/Http/Controllers/DocumentPreviewController.php @@ -4,11 +4,15 @@ use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionKind; +use App\Domain\Catalog\ContentVersionStatus; use App\Domain\Catalog\DocumentGuide; +use App\Domain\Catalog\DocumentMeta; use App\Domain\Catalog\DocumentPdf; use App\Domain\Catalog\DocumentReader; +use App\Domain\Catalog\EditorialWorkingDraft; use App\Domain\Catalog\EmbeddedImages; use App\Domain\Catalog\FormattedText; +use App\Domain\Catalog\PdfTemplate; use App\Domain\Identity\StaffRole; use App\Filament\Support\EditorialCatalog; use App\Models\User; @@ -29,7 +33,7 @@ public function show(Composition $composition): View $images = EmbeddedImages::staff(); foreach ($guide['chapters'] as $index => $chapter) { - $guide['chapters'][$index]['html'] = DocumentGuide::shiftHeadings(FormattedText::html($chapter['version']->body, $images)); + $guide['chapters'][$index]['html'] = DocumentGuide::anchoredHtml($chapter, FormattedText::html($chapter['version']->body, $images)); } return view('document.preview', ['guide' => $guide, 'composition' => $composition, 'pdfUrl' => route('editorial.document-preview.pdf', $composition)]); @@ -56,7 +60,7 @@ private function guide(Composition $composition): array abort_if($chapters === null, 404); foreach ($chapters as $index => $chapter) { - $chapters[$index] += [ + $chapters[$index] = DocumentGuide::withHeadings($chapters[$index] + [ 'allowed' => true, 'grant' => null, 'may_download' => true, @@ -64,23 +68,69 @@ private function guide(Composition $composition): array '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, ]; } - private function authorizeStaff(Composition $composition): void + /** + * 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[] = DocumentGuide::withHeadings([ + '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); } } diff --git a/database/migrations/2026_11_29_100000_add_pdf_templates.php b/database/migrations/2026_11_29_100000_add_pdf_templates.php new file mode 100644 index 0000000..3646fec --- /dev/null +++ b/database/migrations/2026_11_29_100000_add_pdf_templates.php @@ -0,0 +1,55 @@ +id(); + $table->string('name'); + $table->string('kind')->default('dokument'); + $table->boolean('show_cover')->default(true); + $table->foreignId('header_version_id')->nullable()->constrained('content_element_versions')->nullOnDelete(); + $table->foreignId('footer_version_id')->nullable()->constrained('content_element_versions')->nullOnDelete(); + $table->foreignId('cover_version_id')->nullable()->constrained('content_element_versions')->nullOnDelete(); + $table->string('publisher')->nullable(); + $table->text('copyright')->nullable(); + $table->timestamps(); + }); + + Schema::table('compositions', function (Blueprint $table) { + $table->foreignId('pdf_template_id')->nullable()->constrained('pdf_templates')->nullOnDelete(); + }); + + Schema::table('composition_versions', function (Blueprint $table) { + $table->json('document_meta')->nullable(); + }); + } + + public function down(): void + { + Schema::table('composition_versions', function (Blueprint $table) { + $table->dropColumn('document_meta'); + }); + Schema::table('compositions', function (Blueprint $table) { + $table->dropConstrainedForeignId('pdf_template_id'); + }); + Schema::dropIfExists('pdf_templates'); + } +}; diff --git a/database/migrations/2026_11_29_110000_add_element_images_to_pdf_templates.php b/database/migrations/2026_11_29_110000_add_element_images_to_pdf_templates.php new file mode 100644 index 0000000..8f86e97 --- /dev/null +++ b/database/migrations/2026_11_29_110000_add_element_images_to_pdf_templates.php @@ -0,0 +1,31 @@ +foreignId('header_element_id')->nullable()->constrained('content_elements')->nullOnDelete(); + $table->foreignId('footer_element_id')->nullable()->constrained('content_elements')->nullOnDelete(); + $table->foreignId('cover_element_id')->nullable()->constrained('content_elements')->nullOnDelete(); + }); + } + + public function down(): void + { + Schema::table('pdf_templates', function (Blueprint $table) { + $table->dropConstrainedForeignId('header_element_id'); + $table->dropConstrainedForeignId('footer_element_id'); + $table->dropConstrainedForeignId('cover_element_id'); + }); + } +}; diff --git a/database/migrations/2026_11_30_100000_add_logo_layout_to_pdf_templates.php b/database/migrations/2026_11_30_100000_add_logo_layout_to_pdf_templates.php new file mode 100644 index 0000000..4a15c9f --- /dev/null +++ b/database/migrations/2026_11_30_100000_add_logo_layout_to_pdf_templates.php @@ -0,0 +1,30 @@ +string('header_align', 10)->default('full'); + $table->string('footer_align', 10)->default('full'); + $table->unsignedSmallInteger('header_logo_height')->default(40); + $table->unsignedSmallInteger('footer_logo_height')->default(40); + }); + } + + public function down(): void + { + Schema::table('pdf_templates', function (Blueprint $table) { + $table->dropColumn(['header_align', 'footer_align', 'header_logo_height', 'footer_logo_height']); + }); + } +}; diff --git a/database/migrations/2026_11_30_110000_add_contents_settings_to_pdf_templates.php b/database/migrations/2026_11_30_110000_add_contents_settings_to_pdf_templates.php new file mode 100644 index 0000000..9337768 --- /dev/null +++ b/database/migrations/2026_11_30_110000_add_contents_settings_to_pdf_templates.php @@ -0,0 +1,28 @@ +string('toc_mode', 10)->default('auto'); + $table->unsignedTinyInteger('toc_depth')->default(6); + }); + } + + public function down(): void + { + Schema::table('pdf_templates', function (Blueprint $table) { + $table->dropColumn(['toc_mode', 'toc_depth']); + }); + } +}; diff --git a/docs/architektur/12_Entscheidungsprotokoll_ADR.md b/docs/architektur/12_Entscheidungsprotokoll_ADR.md index c6afb9e..0f2b135 100644 --- a/docs/architektur/12_Entscheidungsprotokoll_ADR.md +++ b/docs/architektur/12_Entscheidungsprotokoll_ADR.md @@ -712,7 +712,7 @@ ## ADR-50 – Formatierte Texte: bereinigtes HTML als einziges Format, ein Edito **Status:** umgesetzt, fachlich zu bestätigen. **Datum:** 23.11.2026. **Anlass:** Shinkan liefert Übungstexte jetzt als HTML (`text_format: html`); Lars verlangt für alle Textfelder Editoren mit Symbolleiste und visueller Darstellung. **Entscheidung.** -- **Format.** Formatierte Texte werden als **bereinigtes HTML** aus einer festen Auswahl gespeichert: Absatz, Zwischenüberschrift (`h3`), fett, kursiv, Aufzählung, nummerierte Liste, Zitat, Link (http, https, mailto) und Zeilenumbruch. Alles andere fällt beim Speichern weg (Skripte, Ereignisattribute, andere Schemata, Bilder, Tabellen, Unterstreichung). Markdown wurde verworfen: Die Editoren arbeiten mit einem Dokumentmodell, das HTML-nah ist, die Quelle liefert HTML und das CMS speichert HTML bereits. Eine Umwandlung in beide Richtungen wäre verlustbehaftet. +- **Format.** Formatierte Texte werden als **bereinigtes HTML** aus einer festen Auswahl gespeichert: Absatz, Zwischenüberschriften (`h3` bis `h6`), fett, kursiv, Aufzählung, nummerierte Liste, Zitat, Link (http, https, mailto) und Zeilenumbruch. Alles andere fällt beim Speichern weg (Skripte, Ereignisattribute, andere Schemata, Bilder, Tabellen, Unterstreichung). Markdown wurde verworfen: Die Editoren arbeiten mit einem Dokumentmodell, das HTML-nah ist, die Quelle liefert HTML und das CMS speichert HTML bereits. Eine Umwandlung in beide Richtungen wäre verlustbehaftet. - **Ein Baustein.** `App\Domain\Catalog\FormattedText` bereinigt, bringt Werte in die **kanonische Form**, wandelt Klartext des Altbestands und liefert Klartext, Auszug und Blöcke mit Auszeichnung (für das PDF). `App\Filament\Support\RichField` ist der eine Editor (Filament `RichEditor`, immer dieselbe Symbolleiste). Neue formatierte Felder nutzen ihn. - **Kanonische Form.** Es wird nur in kanonischer Form verglichen, gehasht und gespeichert: Das Öffnen eines Felds im Editor, andere Schreibweise desselben Inhalts (`b`/`strong`, Zeilenumbrüche zwischen Blöcken, Listenpunkte mit oder ohne Absatz) und Klartext gegen HTML erzeugen weder „Geändert“-Markierungen noch neue Fassungen noch Scheinkonflikte beim Abgleich mit Shinkan. Lesbar und prüfbar ist das mit `FormattedText::same()`. - **Erkennung statt Spalte.** Es gibt keine Formatspalte und keine Datenmigration. Ein Wert ist HTML, wenn er (nach Leerraum) mit einem Blockelement der Auswahl beginnt (`p`, `h3`, `ul`, `ol`, `blockquote`); gespeichertes HTML ist kanonisch und beginnt immer so. Klartext des Altbestands bleibt unverändert, bis jemand ihn ändert. Beim Anzeigen und Bearbeiten wird er nach den bekannten Konventionen (Leerzeile, „- “, „1. “, „## “) umgewandelt; Zeilenumbrüche an Stellen, die sie bisher zeigten, bleiben dort erhalten (`FormattedText::display`). @@ -741,7 +741,7 @@ ## ADR-51 – Dokumente: Kapitel als Texte, Dokumentfassung als Komposition, Tab - **Ein Texteditor.** `FormattedText` und `RichField` (ADR-50) bekommen Tabellen und Bilder. Alle Texteditoren (Kapitel, Übungstexte, Medientexte) haben dieselbe Symbolleiste; das Bildwerkzeug erscheint dort, wo die Seite den gemeinsamen Picker hat (Aufbaueditor, Medienansicht). Kurzangaben (Beschreibung, Lernziel) bekommen die Tabelle, aber kein Bild. Die kanonische Form kennt `table`/`tr`/`th`/`td` (nur `colspan` und `rowspan` über 1, Zellen mit Absätzen) und `img`. - **Bilder.** Ein Bild ist ein Verweis auf eine freigegebene Bildfassung des Medienbestands (`…`), nie eine Adresse und kein Upload. Der Editor bekommt eine Adresse der Verwaltung nur zur Anzeige; die Bereinigung entfernt sie wieder. Der Editor setzt ein Bild inline in einen Absatz oder als Block in eine Tabellenzelle; beides bleibt erhalten, in Überschrift, Liste und Zitat entfällt ein Bild. Im PDF teilt ein Bild im Absatz den Absatz, in einer Zelle steht es verkleinert in der Zelle. Ohne Auflösung gibt jede Ausgabe kein Bild aus (sichere Voreinstellung). Ein Text mit einem nicht freigegebenen oder gesperrten Bild lässt sich nicht festschreiben (`ContentService::imageProblem`). - **Rechte für Bilder.** Ein Bild im Text gehört zum Text: Wer den Text ansehen darf, sieht die Bilder darin; wer ihn laden darf, bekommt sie im PDF. Es braucht kein eigenes Recht für Bilder. Bestehende Berechtigungen nennen nur Texte; ein eigenes Bildrecht hätte allen bisherigen Käufern die Bilder in Handbuch und Trainerhinweisen genommen. **Das ist eine fachliche Entscheidung, die Lars bestätigt oder ändert.** `ContentResolver::expand` führt die Bildfassungen eines Textes als ergänzende Zeilen im Stand (`release_contents`); die Auslieferung prüft, dass das Bild im Text vorkommt, zum Stand gehört, nicht gesperrt ist und der Text zulässig ist (`EmbeddedImages`, `StandImageController`). Die Adresse eines Bildes (`/bereich/stand/{Artikel}/{Stand}/bild/{Text}/{Bild}`) läuft nicht ab und entscheidet bei jedem Abruf neu, weil eine Seite lange offen bleibt; die Datei liegt nie unter einem öffentlichen Pfad. Eine Sperre der Bildfassung wirkt: Das Bild entfällt mit Hinweis, der Text bleibt lesbar. Das PDF des Dokuments liegt ebenfalls unter einer Adresse ohne Ablauf (angemeldetes Konto, Entscheidung je Abruf), damit der Knopf auf einer langen offenen Seite nicht ins Leere läuft; das Übungs-PDF bleibt signiert. Ausgabenachweis je gedrucktem Bild im PDF. Für das PDF braucht der Text `laden`; die Auswahl der Fähigkeiten im Rechteprofil bietet dafür jetzt „Text als PDF herunterladen“ (`text:laden`) an. -- **Ausgabe.** `DocumentGuide` liefert Kapitel mit Rechteentscheidung für Seite (`member.document`) und PDF (`member.document.pdf`); Zwischenüberschriften im Kapitel stehen eine Ebene unter dem Kapiteltitel. Ein Dokument in einem Modul erscheint als ein Eintrag, der zur gebundenen Fassung führt. Das PDF verlangt `laden` für jedes Kapitel, sonst fehlte ein Teil. +- **Ausgabe.** `DocumentGuide` liefert Kapitel mit Rechteentscheidung für Seite (`member.document`) und PDF (`member.document.pdf`); Zwischenüberschriften im Kapitel (h3 bis h6) stehen mit im Inhaltsverzeichnis (siehe Nachtrag „Überschriftenebenen“). Ein Dokument in einem Modul erscheint als ein Eintrag, der zur gebundenen Fassung führt. Das PDF verlangt `laden` für jedes Kapitel, sonst fehlte ein Teil. - **PDF ohne Bibliothek.** `PdfDocument` kann jetzt Flächen, JPEG-Bilder (aus GD neu kodiert, höchstens 1400 Pixel, auf Weiß), Verweise innerhalb des Dokuments und Lesezeichen; zusätzliche Objekte entstehen nur bei Bedarf und nach allen bisherigen, Belege und Übungs-PDFs bleiben byte-gleich (Test mit Prüfsummen). `PdfFlow` ist der gemeinsame Satz für Übung und Dokument (Absatz, Listen, Tabellen mit Spaltenbreiten nach Inhalt, Kopfzeile je Folgeseite, Zeilen zusammenhaltend, Bilder ungeteilt, Überschrift bleibt bei ihrem Text). `DocumentPdf` setzt Titelseite mit anklickbarem Inhaltsverzeichnis und Seitenzahlen, jedes Kapitel der ersten Ebene beginnt auf einer neuen Seite, Fußzeile „Seite n von m“, Lesezeichen. Seitenzahlen stehen erst nach dem Satz fest; der Satz läuft bis zur Stabilität (in der Regel zweimal). - **Bildformate.** Im Image ist GD mit JPEG, PNG und GIF gebaut, nicht mit WebP (`Dockerfile` unverändert). Ein Bild, das GD nicht liest, erscheint im PDF als Hinweis „Bild kann nicht gedruckt werden“. @@ -750,3 +750,11 @@ ## ADR-51 – Dokumente: Kapitel als Texte, Dokumentfassung als Komposition, Tab **Folgen.** Eine Migration, additiv. **Rückfall:** Der vorherige Stand kennt die Art `document` nicht und blendet Dokumente über den Bereichsfilter aus (`SupportedKindScope`); Kapiteltexte bleiben als Texte erhalten. Die Rückfallsperre (ADR-49) muss auf `main` sein, bevor in Prod das erste Dokument entsteht. Nach einem Rückfall zeigt der vorherige Stand Tabellen und Bilder in Texten nicht mehr (sie fallen in der Bereinigung weg) und ein Modul, das eine Dokumentfassung bindet, zeigt das Dokument nicht. Einen Stand, der ein Dokument bindet, ändert der Rückfall nicht in der Datenbank. Offen: Abnahme auf luf-test (Browser, schmale Fenster, Tastatur), Schrift und Layout des Handbuch-PDF nach Marke (nur Helvetica), Silbentrennung im PDF (lange Wörter in schmalen Tabellenspalten werden hart getrennt). **Quelle.** Auftrag „Dokumente“ von Lars vom 24.11.2026. + +**Nachtrag (24.11.2026): PDF-Vorlagen für Dokumente.** Ein Dokument kann eine PDF-Vorlage verwenden (`pdf_templates`, Zuordnung `compositions.pdf_template_id`, Verwaltung unter Inhalte → PDF-Vorlagen). Die Vorlage ist reines Layout und legt fest: eine Titelseite, auf der der Titel allein steht (mit Untertitel, Ausgabe, Veröffentlichungsdatum, Herausgeber, Copyright-Vermerk und optional einem Titelbild), und eine Kopf- und eine Fußgrafik in voller Seitenbreite auf allen weiteren Seiten. Die Bilder wählt der gemeinsame Picker aus dem Medienbestand: jedes Bild mit vorhandener Datei, auch ohne Inhaltsfassung (Präsentationsmedien, für die Website freigegebene Bilder; Spalten `*_element_id`, Klasse `TemplateImage`); gedruckt wird die Website-Datei, sonst die Präsentationsdatei. Gestaltung ist kein lizenzierter Inhalt und braucht keine Freigabe der Fassung; nur ein gesperrtes oder archiviertes Bild wird abgelehnt. Die Bindung an freigegebene Bildfassungen gilt allein für Bilder im Text eines Dokuments. Untertitel, Ausgabe, Datum und Copyright-Vermerk sind Inhalt und gehören zur Dokumentfassung (`composition_versions.document_meta`, `DocumentMeta`); der Vermerk der Vorlage gilt nur, wenn die Fassung keinen hat. Eine Vorlage wirkt sofort auf jedes PDF der Dokumente, die sie verwenden, auch auf ältere Fassungen: Layout ist nicht Teil der Bindung. Die Angaben ändern den Änderungsnachweis (`structure_hash`) nur, wenn sie gesetzt sind; ältere Fassungen behalten ihren Nachweis. Ohne Vorlage bleibt das bisherige Layout unverändert. Die Kennzeichnung (Lizenzzeile und „Seite n von m“) steht auch auf der Titelseite. Das Muster-PDF einer Vorlage gibt es ohne Dokument. **Grenzen:** nur Helvetica (bewusst, siehe Lizenzfrage von Schriften im Druck), Grafiken als JPEG oder PNG ohne Transparenz, feste Anordnung der Titelseite. **Folgen:** eine additive Migration; der Rückfall zeigt Dokumente im vorherigen Stand nicht (SupportedKindScope) und kennt die Vorlagen nicht. Eine PDF-Bibliothek mit eigenen Schriften bleibt Option B, sobald eine Marke etabliert ist. Die gleiche Vorlagenverwaltung kann später für Übungs-PDFs und Belege genutzt werden; die Rechnung bleibt an OPEN-06 gebunden. + +**Nachtrag (24.11.2026): Inhaltsverzeichnis im PDF einstellbar.** Die PDF-Vorlage bestimmt, ob das gedruckte Verzeichnis erscheint (`toc_mode`: `auto` = nur bei mehr als einem Eintrag, `always`, `never`) und bis zu welcher Stufe es reicht (`toc_depth`: 2 = nur Kapitel und Unterkapitel, 3 bis 6 = bis zu dieser Überschrift; Vorgabe 6). Gezählt wird nach den Einträgen, die im Verzeichnis stünden. Lesezeichen im PDF und das Verzeichnis der Seitenansicht zeigen unverändert alle Ebenen. Ohne Vorlage gilt `auto` mit voller Tiefe, ein Dokument mit einem Eintrag bekommt also kein Verzeichnis mehr. Ohne Verzeichnis beginnt das erste Kapitel auf Seite 1 beziehungsweise nach der Titelseite. **Folgen:** eine additive Migration mit Vorgaben; der vorherige Programmstand zeigt immer das volle Verzeichnis. + +**Nachtrag (24.11.2026): Logo in Kopf und Fuß.** Kopf und Fuß einer PDF-Vorlage können statt eines Bands in voller Seitenbreite ein Logo links oder rechts am Textrand tragen (`header_align`/`footer_align` = `full`, `left`, `right`; `header_logo_height`/`footer_logo_height` in Punkt, 16 bis 100, Vorgabe 40; höchstens halbe Textbreite). Dasselbe Bild kommt aus dem Medienmanager wie bisher. Die Titelseite bleibt unberührt. **Folgen:** eine additive Migration mit Vorgaben; der vorherige Programmstand kennt die Spalten nicht und zeigt jede Grafik als Band. + +**Nachtrag (24.11.2026): Überschriftenebenen im Kapiteltext.** Ein Dokument gliedert sich vor allem durch Kapitel der ersten Ebene und Überschriften im Text. Der Editor bietet dafür `h3` bis `h6` an (Dokumenttitel `h1`, Kapitel `h2`; `h1` und `h2` aus eingefügtem Text werden `h3`). Alle Überschriften des Kapiteltexts stehen automatisch im Inhaltsverzeichnis von Seite und PDF, eingerückt nach Stufe und ohne Nummer, mit Sprungmarken `kapitel--u` (gezählt werden die nicht leeren Überschriften auf oberster Ebene des Texts, nicht die in Tabellen) und, im PDF, mit Seitenzahl, Verweis und verschachtelten Lesezeichen (`PdfDocument::bookmark` kennt jetzt bis zu sechs Ebenen). Die Stufen sind im PDF nach Größe gestaffelt (h6 kursiv). Unter einem Unterkapitel rücken die Überschriften eine Stufe tiefer (höchstens `h6`), damit sie nie auf der Stufe des Unterkapitels stehen; ein Unterkapitel braucht man dafür nicht. **Bewusst offen:** Innerhalb eines Kapitels wird nicht geprüft, ob eine Überschrift im Text eine höhere oder gleiche Stufe wie die vorherige hat (Einzelbearbeitung). Ältere Fassungen behalten ihren Text; die gespeicherten `h3` erscheinen jetzt als `h3` statt `h4` und neu im Verzeichnis. **Folgen:** keine Migration; der Änderungsnachweis (Hash) bleibt unverändert, weil sich der gespeicherte Text nicht ändert. diff --git a/docs/ux/verwaltung/abnahme/dokumente.md b/docs/ux/verwaltung/abnahme/dokumente.md index f2bfdff..380d584 100644 --- a/docs/ux/verwaltung/abnahme/dokumente.md +++ b/docs/ux/verwaltung/abnahme/dokumente.md @@ -48,6 +48,19 @@ ## 3. Trainerhinweis einer Übung mit demselben Editor | Übungsansicht und Übungs-PDF, Stand-Kennung 8 | Überschrift, Liste, Tabelle und Bild erscheinen in Ansicht und PDF | `44-uebung-neu.png`, `53-pdf-uebung-neu.png` | | Dieselben Ausgaben, Stand-Kennung 6 | Unverändert: nur die Liste, keine Tabelle, kein Bild | `44-uebung-alt.png`, `53-pdf-uebung-alt.png` | +## 4. Überschriftenebenen im Kapiteltext (h3 bis h6) + +Lokal geprüft (nicht auf luf-test): Ein neues Dokument mit einem Kapitel; im Editor stehen die Werkzeuge „Unterüberschrift“ (h3) sowie „Überschrift 4“ bis +„Überschrift 6“. Je Stufe eine Überschrift gesetzt, Entwurf gespeichert. Die Ansicht der Redaktion zeigt alle vier Überschriften im Inhaltsverzeichnis, eingerückt, +ohne Nummer; ein Klick springt zur Überschrift (`#kapitel-1-u3`), im schmalen Fenster kein seitliches Scrollen. Das PDF führt sie im Verzeichnis mit Seitenzahl +und Verweis und hat verschachtelte Lesezeichen (Kapitel › h3 › h4 › h5 › h6). + +| Schritt | Beleg | +|---|---| +| Editor mit allen vier Stufen | `dokumente/10-editor-ueberschriften-h3-bis-h6.png` | +| Ansicht mit Verzeichnis und gestaffelten Überschriften | `dokumente/11-ansicht-verzeichnis-mit-ueberschriften.png` | +| Schmales Fenster | `dokumente/12-ansicht-schmales-fenster.png` | + ## Automatisierte Prüfungen (in der Suite) - `TextEditorWerkzeugeTest`: Tabelle und Bild durch die echte Filament-Komponente und zurück ohne Verlust; Bildwerkzeug nur dort, wo der Picker @@ -59,6 +72,8 @@ ## Automatisierte Prüfungen (in der Suite) Bilder folgen den Rechten des Textes (Berechtigung nur für Texte zeigt die Bilder), ohne Recht am Text keine Seite, kein Bild und kein PDF, Bildadresse gibt nur das Bild dieses Textes und Stands frei, Adresse und PDF-Knopf nach 45 Minuten noch gültig, PDF nur mit Download-Recht, gesperrtes Bild, fremdes Konto, gleiche Kapitel in Seite und PDF. +- `DokumentUeberschriftenTest`: Werkzeuge h3 bis h6 und genaue Stufen im Text (h1/h2 werden h3), Sprungmarken und Stufenverschiebung, Verzeichnis und Anker in der + Ansicht (auch unter Unterkapitel), PDF-Verzeichnis mit stimmenden Seitenzahlen und Lesezeichen; `PdfDocumentTest`: Gliederung beliebig tief mit allen Nachkommen gezählt. - `UebungFormatierungTest`: Trainerhinweis mit Überschrift, Liste, Tabelle und Bild bleibt beim Öffnen und Speichern erhalten und erscheint in Ansicht und PDF. - `PdfDocumentTest`: Prüfsummen für Belege und Übungs-PDF (byte-gleich), Verweise, Lesezeichen, Bilder, Kreuzverweistabelle, Nummerierung. - `RueckfallschutzTest`: die Art `document` ist bewusst ergänzt. diff --git a/docs/ux/verwaltung/abnahme/dokumente/10-editor-ueberschriften-h3-bis-h6.png b/docs/ux/verwaltung/abnahme/dokumente/10-editor-ueberschriften-h3-bis-h6.png new file mode 100644 index 0000000..99c407b Binary files /dev/null and b/docs/ux/verwaltung/abnahme/dokumente/10-editor-ueberschriften-h3-bis-h6.png differ diff --git a/docs/ux/verwaltung/abnahme/dokumente/11-ansicht-verzeichnis-mit-ueberschriften.png b/docs/ux/verwaltung/abnahme/dokumente/11-ansicht-verzeichnis-mit-ueberschriften.png new file mode 100644 index 0000000..c9908c3 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/dokumente/11-ansicht-verzeichnis-mit-ueberschriften.png differ diff --git a/docs/ux/verwaltung/abnahme/dokumente/12-ansicht-schmales-fenster.png b/docs/ux/verwaltung/abnahme/dokumente/12-ansicht-schmales-fenster.png new file mode 100644 index 0000000..44803e2 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/dokumente/12-ansicht-schmales-fenster.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen.md b/docs/ux/verwaltung/abnahme/pdf-vorlagen.md new file mode 100644 index 0000000..bad678a --- /dev/null +++ b/docs/ux/verwaltung/abnahme/pdf-vorlagen.md @@ -0,0 +1,72 @@ +# Abnahme PDF-Vorlagen für Dokumente (Stand 24.11.2026) + +Entscheidung: ADR-51, Nachtrag. Dieser Stand belegt die **lokale** Abnahme in der laufenden Anwendung (Arbeitsbaum `feature/pdf-vorlagen`, +lokaler Server, SQLite, Demo-Konten aus `ShopDemoSeeder`) und die automatisierten Prüfungen. Auf `luf-test` ist nichts geprüft. Die +Grafiken der Abnahme (Kopf, Fuß, Titelbild) sind Platzhalter, keine Gestaltung der Marke. + +## Geprüft in der Anwendung + +| Schritt | Ergebnis | Beleg | +|---|---|---| +| Inhalte → PDF-Vorlagen (leer) | Hinweis, wie man die erste Vorlage anlegt | `pdf-vorlagen/01-vorlagen-leer.png` | +| Vorlage „Handbuch“ anlegen: Herausgeber, Standard-Vermerk, Kopf-, Fuß- und Titelbild über den gemeinsamen Picker | Bilder erscheinen als Vorschau; „Vorlage speichern“ erst nach Änderung aktiv | `02-bildauswahl.png`, `03-vorlage-ausgefuellt.png`, `04-vorlage-gespeichert.png` | +| Schmales Fenster (390 px) | Kein waagerechtes Scrollen | `06-schmales-fenster.png` | +| Dokument → „PDF und Katalogbild“: Untertitel, Ausgabe, Veröffentlichungsdatum, Vorlage wählen und übernehmen | Hinweis, dass die Vorlage sofort für jedes PDF gilt, die Angaben aber je Fassung | `05-dokument-pdf-angaben.png` | +| Entwurf speichern, Dokumentfassung 2 bereitstellen, im Modul auf Fassung 2 umstellen, Modulfassung freigeben, Stand veröffentlichen | Fassung 2 trägt die Angaben | im Lauf geprüft | +| Mitglied lädt das PDF (6 Seiten, 4 Lesezeichen) | Seite 1: Titelbild, Titel allein, Untertitel, Ausgabe, Veröffentlichungsdatum, Herausgeber, Vermerk unten, Lizenzzeile; Seite 2: Inhaltsverzeichnis; ab Seite 2 Kopf- und Fußgrafik | `07-pdf-titelseite.png`, `08-pdf-inhaltsverzeichnis.png`, `09-pdf-kapitelseite.png` | +| Muster-PDF der Vorlage | PDF ohne Dokument | im Lauf geprüft (HTTP 200, PDF) | + +## Bilder ohne Inhaltsfassung + +Der Picker der Vorlagenseite bietet jedes Bild des Medienmanagers an, auch Bilder ohne Inhaltsfassung (Zeile „Bild · Ohne Inhaltsfassung“). Lokal geprüft: ein für die +Website freigegebenes Bild als Kopfgrafik und ein reines Präsentationsbild als Fußgrafik gewählt, Vorlage gespeichert, Vorschau zeigt beide Bilder, im Muster-PDF +tragen die Seiten 2 bis 4 je zwei Bilder, die Titelseite keines. + +| Schritt | Beleg | +|---|---| +| Bildauswahl mit Bildern ohne Inhaltsfassung | `07-bildauswahl-ohne-fassung.png` | +| Vorlage mit beiden Bildern ausgefüllt | `08-vorlage-mit-webbildern.png` | +| Vorlage gespeichert | `09-webbilder-gespeichert.png` | + +## Logo links oder rechts in Kopf und Fuß + +Kopf und Fuß haben je eine **Anordnung**: „Band in voller Seitenbreite“ (Vorgabe, wie bisher), „Logo links“ oder „Logo rechts“. Bei einem Logo erscheint das Feld +„Höhe des Logos (Punkt)“ (16 bis 100, Vorgabe 40). Das Logo steht am Textrand (links 56, rechts 539 Punkt), im Kopf 24 Punkt unter dem oberen Rand, im Fuß 14 Punkt +über dem unteren; es ist höchstens halb so breit wie der Text. Der Text beginnt darunter beziehungsweise endet darüber. Die Titelseite trägt weiterhin nur ihr eigenes Bild. +Lokal geprüft (nicht auf luf-test): neue Vorlage, Kopf „Logo links“ mit Höhe 36, Fuß „Logo rechts“ mit 40, gespeichert, Muster-PDF zeigt beide Logos am Rand. + +| Schritt | Beleg | +|---|---| +| Anordnung und Logohöhe für Kopf und Fuß | `10-logo-anordnung.png` | +| Vorlage gespeichert | `11-logo-gespeichert.png` | + +## Inhaltsverzeichnis im PDF: Anzeige und Tiefe + +Die Vorlage hat den Abschnitt „Inhaltsverzeichnis im PDF“ mit zwei Einstellungen. **Anzeige:** „Automatisch (ab 2 Einträgen)“ (Vorgabe), „Immer“ oder „Nie“. **Tiefe:** +„Nur Kapitel und Unterkapitel“ oder „Bis Überschrift 3“ bis „Bis Überschrift 6 (alle)“ (Vorgabe); bei „Nie“ entfällt das Feld. Gezählt wird nach den Einträgen, die im +Verzeichnis stünden: ein Dokument mit einem Kapitel und ohne Überschriften bekommt in „Automatisch“ keins. Ohne Verzeichnis beginnt das erste Kapitel auf Seite 1 (ohne +Titelseite unter dem Titel, mit Titelseite auf Seite 2); es entsteht keine leere Seite. Die Lesezeichen im PDF-Betrachter und das Verzeichnis auf der Seite zeigen immer alle +Ebenen; die Einstellungen betreffen nur das gedruckte Verzeichnis und gelten sofort für alle Dokumente der Vorlage, auch für ältere Fassungen. Dokumente ohne Vorlage +nutzen „Automatisch“ mit voller Tiefe. +Lokal geprüft (nicht auf luf-test): Tiefe „Nur Kapitel und Unterkapitel“ gespeichert, das Muster-PDF zeigt im Verzeichnis keine Zwischenüberschriften; „Nie“ lässt das Verzeichnis weg +(3 statt 4 Seiten) und blendet das Feld „Tiefe“ aus. + +| Schritt | Beleg | +|---|---| +| Einstellungen „Anzeige“ und „Tiefe“ | `12-verzeichnis-einstellung.png` | +| Anzeige „Nie“ | `13-verzeichnis-nie.png` | + +## Automatisierte Prüfungen (`DokumentVorlageTest`, `DokumentAusgabeTest`, `PdfDocumentTest`) + +Titelseite mit allen Angaben und ohne Kapitel; Verzeichnis ab Seite 2 mit stimmenden Seitenzahlen; Titelbild nur auf Seite 1, Kopf und Fuß auf allen +weiteren; Lizenzzeile auch auf der Titelseite; ohne Vorlage das bisherige Layout; Titelseite abschaltbar; Standard-Vermerk der Vorlage; +Angaben je Fassung und Änderungsnachweis; Editor speichert Angaben im Entwurf und bindet sie mit der Fassung; Vorlagenseite (anlegen, ändern, Bilder +über den Picker auch ohne Inhaltsfassung (Präsentations- und Website-Bild), Bild im Entwurf wählbar, gesperrtes Bild, fehlende Datei und Nicht-Bild abgelehnt, löschen); Logo links und rechts mit Höhe und Maßen im PDF, breites Logo höchstens halbe Textbreite, Grenzen der Werte, Speichern der Anordnung auf der Seite; `DokumentVerzeichnisTest`: Grenzen der Werte, Verzeichnis nur ab zwei Einträgen (ohne leere Seite), „Immer“ und „Nie“, Tiefe mit allen Lesezeichen, Seitenansicht unberührt, Speichern auf der Seite; Löschen gibt Dokumente an das einfache Layout zurück; Redaktionsvorschau nutzt Vorlage und Entwurfsangaben. + +## Abweichungen und offene Punkte + +- **Nicht auf luf-test geprüft.** Verkauf und Berechtigung der Abnahme wurden lokal per Skript angelegt. +- **Nur Helvetica.** Eine Markenschrift braucht eine PDF-Bibliothek (Option B im ADR); die Schriftlizenz für gedruckte Werke bleibt zu klären. +- **Grafiken** als JPEG oder PNG ohne Transparenz (Transparenz wird auf Weiß gesetzt). Kopf und Fuß als Band höchstens 140 Punkt hoch (als Logo 16 bis 100 Punkt), das Titelbild höchstens 40 % der Seite. +- **Übungs-PDF und Beleg** nutzen noch keine Vorlage. Die Verwaltung ist so angelegt, dass weitere Arten folgen können (Spalte `kind`). +- **Im Bild der Dokumentseite** bleibt das Feld „Herausgeber“ der Vorlagenseite gegenüber dem Vermerkfeld leicht tiefer ausgerichtet (Darstellung der gemeinsamen Raster). diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/01-vorlagen-leer.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/01-vorlagen-leer.png new file mode 100644 index 0000000..74c908c Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/01-vorlagen-leer.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/02-bildauswahl.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/02-bildauswahl.png new file mode 100644 index 0000000..a74b58d Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/02-bildauswahl.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/03-vorlage-ausgefuellt.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/03-vorlage-ausgefuellt.png new file mode 100644 index 0000000..354380f Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/03-vorlage-ausgefuellt.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/04-vorlage-gespeichert.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/04-vorlage-gespeichert.png new file mode 100644 index 0000000..8ffcdc2 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/04-vorlage-gespeichert.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/05-dokument-pdf-angaben.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/05-dokument-pdf-angaben.png new file mode 100644 index 0000000..f9718d9 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/05-dokument-pdf-angaben.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/06-schmales-fenster.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/06-schmales-fenster.png new file mode 100644 index 0000000..b705dc9 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/06-schmales-fenster.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/07-bildauswahl-ohne-fassung.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/07-bildauswahl-ohne-fassung.png new file mode 100644 index 0000000..65b4049 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/07-bildauswahl-ohne-fassung.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/07-pdf-titelseite.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/07-pdf-titelseite.png new file mode 100644 index 0000000..ed5e61c Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/07-pdf-titelseite.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/08-pdf-inhaltsverzeichnis.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/08-pdf-inhaltsverzeichnis.png new file mode 100644 index 0000000..ea62715 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/08-pdf-inhaltsverzeichnis.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/08-vorlage-mit-webbildern.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/08-vorlage-mit-webbildern.png new file mode 100644 index 0000000..2e84277 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/08-vorlage-mit-webbildern.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/09-pdf-kapitelseite.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/09-pdf-kapitelseite.png new file mode 100644 index 0000000..e0a86af Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/09-pdf-kapitelseite.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/09-webbilder-gespeichert.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/09-webbilder-gespeichert.png new file mode 100644 index 0000000..7e8c9aa Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/09-webbilder-gespeichert.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/10-logo-anordnung.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/10-logo-anordnung.png new file mode 100644 index 0000000..3a7703e Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/10-logo-anordnung.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/11-logo-gespeichert.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/11-logo-gespeichert.png new file mode 100644 index 0000000..9225c09 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/11-logo-gespeichert.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/12-verzeichnis-einstellung.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/12-verzeichnis-einstellung.png new file mode 100644 index 0000000..dd716b7 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/12-verzeichnis-einstellung.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/13-verzeichnis-nie.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/13-verzeichnis-nie.png new file mode 100644 index 0000000..ecbf8b5 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/13-verzeichnis-nie.png differ diff --git a/resources/css/components/lf-member.css b/resources/css/components/lf-member.css index 4e865dc..60da2f5 100644 --- a/resources/css/components/lf-member.css +++ b/resources/css/components/lf-member.css @@ -1137,10 +1137,25 @@ .mb-prose p { } .mb-prose h3, -.mb-prose h4 { +.mb-prose h4, +.mb-prose h5, +.mb-prose h6 { margin: var(--space-4) 0 var(--space-2); font-size: var(--text-body); font-weight: 700; + scroll-margin-top: var(--space-5); +} + +.mb-prose h3 { + font-size: 1.15em; +} + +.mb-prose h4 { + font-size: 1.07em; +} + +.mb-prose h6 { + font-style: italic; } .mb-prose ul, @@ -1894,6 +1909,30 @@ .mb-doc-toc-2 { font-size: 0.95em; } +/* Zwischenüberschriften (h3 bis h6) im Verzeichnis: eingerückt nach Stufe, ohne Nummer. */ +.mb-doc-toc-h3, +.mb-doc-toc-h4, +.mb-doc-toc-h5, +.mb-doc-toc-h6 { + font-size: 0.9em; +} + +.mb-doc-toc-h3 { + padding-left: var(--space-4); +} + +.mb-doc-toc-h4 { + padding-left: calc(var(--space-4) + var(--space-3)); +} + +.mb-doc-toc-h5 { + padding-left: calc(var(--space-4) + 2 * var(--space-3)); +} + +.mb-doc-toc-h6 { + padding-left: calc(var(--space-4) + 3 * var(--space-3)); +} + .mb-doc-nr { display: inline-block; min-width: 2.2ch; diff --git a/resources/views/filament/editorial/editor.blade.php b/resources/views/filament/editorial/editor.blade.php index f1de4a4..6df4f13 100644 --- a/resources/views/filament/editorial/editor.blade.php +++ b/resources/views/filament/editorial/editor.blade.php @@ -65,7 +65,7 @@
- @foreach (['aufbau' => $dokument ? 'Kapitel' : 'Aufbau', 'angaben' => $dokument ? 'Katalogbild' : 'Didaktik und Katalogbild', 'verlauf' => 'Fassungen und Verwendung'] as $wert => $label) + @foreach (['aufbau' => $dokument ? 'Kapitel' : 'Aufbau', 'angaben' => $dokument ? 'PDF und Katalogbild' : 'Didaktik und Katalogbild', 'verlauf' => 'Fassungen und Verwendung'] as $wert => $label) +
+ @if ($liste === []) +
Noch keine Vorlage

Lege rechts die erste Vorlage an. Ein Dokument verwendet sie, wenn du sie im Dokument unter „PDF und Katalogbild“ zuordnest.

+ @else +
    + @foreach ($liste as $zeile) +
  • + +
  • + @endforeach +
+ @endif + + +
+
+ + +
+ + +
+ +
+

Inhaltsverzeichnis im PDF

+

Gilt für das gedruckte Verzeichnis. „Automatisch“ lässt es weg, wenn es nur einen Eintrag hätte. Die Lesezeichen im PDF-Betrachter und das Verzeichnis auf der Seite zeigen immer alle Ebenen.

+
+ + @if ($this->tocModus !== 'never') + + @endif +
+
+ + @foreach ($felder as $feld => [$label, $hilfe, $ziel]) +
+

{{ $label }}

+

{{ $hilfe }}

+ @if ($ziel !== null) +
{{ $this->imageTitle($ziel) }}
+

{{ $this->imageTitle($ziel) }}

+ @else +

Kein Bild gewählt.

+ @endif + @if ($feld !== 'cover') +
+ + @if (($this->anordnung[$feld] ?? 'full') !== 'full') + + @endif +
+ @endif +
+ + @if ($ziel !== null) + + @endif +
+
+ @endforeach +
+
+ + + @if ($this->pickerOpen) + @include('filament.verwaltung.picker') + @endif + +@include('filament.verwaltung.bestaetigung') + diff --git a/resources/views/filament/verwaltung/aufbau-angaben.blade.php b/resources/views/filament/verwaltung/aufbau-angaben.blade.php index cecc69c..e36e997 100644 --- a/resources/views/filament/verwaltung/aufbau-angaben.blade.php +++ b/resources/views/filament/verwaltung/aufbau-angaben.blade.php @@ -7,12 +7,43 @@
@if ($this->isDocument()) -

Dokument

-

Ein Dokument hat keine Didaktikangaben. Die Kapitel schreibst du im Register „Kapitel“. Name, Beschreibung und Einordnung des Dokuments bearbeitest du in der Redaktion. +

Titelseite und Impressum des PDF

+

Diese Angaben gehören zur Dokumentfassung. Sie werden mit „Entwurf speichern“ gesichert und erst mit „Dokumentfassung bereitstellen“ Teil einer neuen Fassung. Eine leere Angabe entfällt auf der Titelseite. Titel, Beschreibung und Einordnung des Dokuments bearbeitest du in der Redaktion.

-