Führe PDF-Vorlagen für Dokumente ein: Titelseite, grafischer Kopf und Fuß, Angaben je Fassung (ADR-51, Nachtrag)
Eine Vorlage ist reines Layout (Titelseite mit allein stehendem Titel, Kopf- und Fußgrafik aus dem Medienbestand, Herausgeber und Standardvermerk) und wird dem Dokument zugeordnet. Untertitel, Ausgabe, Veröffentlichungsdatum und Copyright-Vermerk gehören zur Dokumentfassung (document_meta). Ohne Vorlage bleibt das PDF unverändert. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
No files matched your search
@@ -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`.
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -56,6 +56,8 @@ 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,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
* Angaben einer Dokumentfassung für Titelseite und Impressum des PDF: Untertitel, Ausgabe (Release), Veröffentlichungsdatum und
|
||||
* Copyright-Vermerk. Sie liegen als Teil der Fassung in `composition_versions.document_meta` und ändern sich nur mit einer neuen
|
||||
* Fassung. Alle Felder sind Klartext; ein leeres Feld entfällt.
|
||||
*/
|
||||
final class DocumentMeta
|
||||
{
|
||||
public const FIELDS = ['subtitle', 'edition', 'published_on', 'copyright'];
|
||||
|
||||
/**
|
||||
* Bereinigte Angaben: nur die bekannten Felder, getrimmt, ohne leere Werte; ein Datum nur als `YYYY-MM-DD`. Null, wenn nichts gesetzt ist.
|
||||
*
|
||||
* @return array<string, string>|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');
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,21 @@
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Domain\Commerce\Receipt\PdfDocument;
|
||||
use App\Domain\Media\PdfImage;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
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 +28,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 +40,35 @@ class DocumentPdf
|
||||
|
||||
private int $total = 0;
|
||||
|
||||
private bool $onCover = 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<string, mixed>, footer: ?array<string, mixed>, cover: ?array<string, mixed>} */
|
||||
private array $bands = ['header' => null, 'footer' => null, 'cover' => null];
|
||||
|
||||
/** @var array<string, array{page: int, top: float}> */
|
||||
private array $starts = [];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $guide Ergebnis von {@see DocumentGuide::build}
|
||||
* @param array<string, mixed> $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 +81,83 @@ 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?->headerVersion, 140.0),
|
||||
'footer' => $this->band($template?->footerVersion, 140.0),
|
||||
'cover' => $template !== null && $template->show_cover ? $this->band($template->coverVersion, self::PAGE_HEIGHT * 0.4) : null,
|
||||
];
|
||||
$header = (float) ($this->bands['header']['height'] ?? 0);
|
||||
$footer = (float) ($this->bands['footer']['height'] ?? 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 in Seitenbreite, bei zu großer Höhe verkleinert und zentriert.
|
||||
*
|
||||
* @return array{jpeg: string, pixelWidth: int, pixelHeight: int, width: float, height: float, x: float}|null
|
||||
*/
|
||||
private function band(?ContentElementVersion $version, float $maxHeight): ?array
|
||||
{
|
||||
$file = $version === null ? null : EmbeddedImages::file($version);
|
||||
$image = $file === null ? null : PdfImage::fromBytes((string) Storage::disk('media_derived')->get($file));
|
||||
|
||||
if ($image === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$width = (float) PdfDocument::WIDTH;
|
||||
$height = $width * $image['height'] / max(1, $image['width']);
|
||||
|
||||
if ($height > $maxHeight) {
|
||||
$height = $maxHeight;
|
||||
$width = $height * $image['width'] / max(1, $image['height']);
|
||||
}
|
||||
|
||||
return ['jpeg' => $image['jpeg'], 'pixelWidth' => $image['width'], 'pixelHeight' => $image['height'], 'width' => $width, 'height' => $height, 'x' => (PdfDocument::WIDTH - $width) / 2];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $guide
|
||||
* @param array<string, array{page: int, top: float}> $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->total = $total;
|
||||
$withCover = $template !== null && $template->show_cover;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
$this->flow->write(PdfFlow::printable((string) $guide['title']), 24, true, 10);
|
||||
$this->flow->write('Inhaltsverzeichnis', 14, true, 8, keep: 40);
|
||||
|
||||
foreach ($guide['chapters'] as $chapter) {
|
||||
$this->contentsLine($chapter, $known[$chapter['anchor']] ?? ['page' => 1, 'top' => self::TOP]);
|
||||
$this->contentsLine($chapter, $known[$chapter['anchor']] ?? ['page' => 1, 'top' => $this->top]);
|
||||
}
|
||||
|
||||
foreach ($guide['chapters'] as $chapter) {
|
||||
@@ -101,6 +174,63 @@ private function pass(array $guide, string $licensee, string $copyId, ?PdfImages
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<string, mixed> $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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Zeile des Inhaltsverzeichnisses: Nummer und Titel, Punktlinie, Seitenzahl; die ganze Zeile springt zum Kapitel.
|
||||
*
|
||||
@@ -178,13 +308,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'], self::PAGE_HEIGHT - $band['height'], $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'], 0, $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
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* Vorlage für das PDF eines Dokuments (ADR-51, Nachtrag): Titelseite, grafische Kopf- und Fußzeile und Standardvermerke.
|
||||
* Die Vorlage bestimmt nur das Aussehen. Der Inhalt, auch Ausgabe, Datum und Copyright-Vermerk der Dokumentfassung, gehört
|
||||
* zur Fassung ({@see DocumentMeta}); die Vorlage liefert nur den Standard-Vermerk, wenn die Fassung keinen eigenen hat.
|
||||
*/
|
||||
class PdfTemplate extends Model
|
||||
{
|
||||
public const KIND_DOCUMENT = 'dokument';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'kind',
|
||||
'show_cover',
|
||||
'header_version_id',
|
||||
'footer_version_id',
|
||||
'cover_version_id',
|
||||
'publisher',
|
||||
'copyright',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['show_cover' => 'boolean'];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EmbeddedImages;
|
||||
use App\Domain\Catalog\PdfTemplate;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\ChoosesMedia;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
/**
|
||||
* PDF-Vorlagen für Dokumente (ADR-51, Nachtrag): Titelseite, grafische Kopf- und Fußzeile und Standardvermerke. Die Bilder
|
||||
* wählt der gemeinsame Picker aus dem Medienbestand (freigegebene Bildfassungen); eine Vorlage ist reines Layout und ändert
|
||||
* keinen Inhalt. Gespeichert wird erst mit „Vorlage speichern“; offene Eingaben bleiben beim Wechsel der Vorlage nicht stehen,
|
||||
* der Wechsel fragt bei offenen Änderungen nach.
|
||||
*/
|
||||
class PdfVorlagen extends Page
|
||||
{
|
||||
use ChoosesMedia;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
|
||||
protected static ?string $navigationLabel = 'PDF-Vorlagen';
|
||||
|
||||
protected static ?int $navigationSort = 60;
|
||||
|
||||
protected static ?string $slug = 'pdf-vorlagen';
|
||||
|
||||
protected static ?string $title = 'PDF-Vorlagen';
|
||||
|
||||
protected string $view = 'filament.pdf.vorlagen';
|
||||
|
||||
/** Gewählte Vorlage; 0 = neue, noch nicht gespeicherte. */
|
||||
public int $templateId = 0;
|
||||
|
||||
public string $name = '';
|
||||
|
||||
public string $publisher = '';
|
||||
|
||||
public string $copyright = '';
|
||||
|
||||
public bool $showCover = true;
|
||||
|
||||
public ?int $headerId = null;
|
||||
|
||||
public ?int $footerId = null;
|
||||
|
||||
public ?int $coverId = 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<array{id: int, name: string, documents: int}>
|
||||
*/
|
||||
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 !== '' || $this->headerId !== null || $this->footerId !== null || $this->coverId !== null;
|
||||
}
|
||||
|
||||
return $this->name !== $template->name
|
||||
|| $this->publisher !== (string) $template->publisher
|
||||
|| $this->copyright !== (string) $template->copyright
|
||||
|| $this->showCover !== (bool) $template->show_cover
|
||||
|| $this->headerId !== $template->header_version_id
|
||||
|| $this->footerId !== $template->footer_version_id
|
||||
|| $this->coverId !== $template->cover_version_id;
|
||||
}
|
||||
|
||||
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 (['header' => $this->headerId, 'footer' => $this->footerId, 'cover' => $this->coverId] as $slot => $id) {
|
||||
if ($id !== null && $this->imageProblem($id) !== null) {
|
||||
Notification::make()->danger()->title('Das Bild für '.$this->slotLabel($slot).' lässt sich nicht verwenden.')->body((string) $this->imageProblem($id))->send();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$values = [
|
||||
'name' => trim($this->name),
|
||||
'kind' => PdfTemplate::KIND_DOCUMENT,
|
||||
'show_cover' => $this->showCover,
|
||||
'header_version_id' => $this->headerId,
|
||||
'footer_version_id' => $this->footerId,
|
||||
'cover_version_id' => $this->coverId,
|
||||
'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
|
||||
{
|
||||
match ($slot) {
|
||||
'header' => $this->headerId = null,
|
||||
'footer' => $this->footerId = null,
|
||||
'cover' => $this->coverId = null,
|
||||
default => 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 || preg_match('/^element:(\d+)$/', (string) $target, $match) !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$problem = $this->imageProblem((int) $match[1]);
|
||||
|
||||
if ($problem !== null) {
|
||||
Notification::make()->danger()->title('Dieses Bild lässt sich nicht verwenden.')->body($problem)->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
match ($slot) {
|
||||
'header' => $this->headerId = (int) $match[1],
|
||||
'footer' => $this->footerId = (int) $match[1],
|
||||
'cover' => $this->coverId = (int) $match[1],
|
||||
default => null,
|
||||
};
|
||||
$this->closePicker();
|
||||
}
|
||||
|
||||
/** @return array<string, string> */
|
||||
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<string, string> */
|
||||
public function presentationRoleOptions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
public function pickerReplacing(): ?array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function imageUrl(?int $versionId): ?string
|
||||
{
|
||||
return $versionId === null ? null : EmbeddedImages::staffSource($versionId);
|
||||
}
|
||||
|
||||
public function imageTitle(?int $versionId): string
|
||||
{
|
||||
$version = $versionId === null ? null : ContentElementVersion::query()->with('element')->find($versionId);
|
||||
|
||||
return $version?->element === null ? '' : (string) ($version->element->display_title ?: $version->element->working_title);
|
||||
}
|
||||
|
||||
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 imageProblem(int $versionId): ?string
|
||||
{
|
||||
$version = ContentElementVersion::query()->with('element')->find($versionId);
|
||||
|
||||
if (! $version instanceof ContentElementVersion || $version->element === null || $version->element->output_class !== 'bild') {
|
||||
return 'Das ist kein Bild des Medienbestands.';
|
||||
}
|
||||
|
||||
if ($version->status !== ContentVersionStatus::Bereit) {
|
||||
return 'Die Bildfassung ist noch nicht freigegeben.';
|
||||
}
|
||||
|
||||
return EmbeddedImages::file($version) === null ? 'Die Bilddatei liegt nicht vor.' : null;
|
||||
}
|
||||
|
||||
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->headerId = $template->header_version_id;
|
||||
$this->footerId = $template->footer_version_id;
|
||||
$this->coverId = $template->cover_version_id;
|
||||
}
|
||||
|
||||
private function clearForm(): void
|
||||
{
|
||||
$this->templateId = 0;
|
||||
$this->name = '';
|
||||
$this->publisher = '';
|
||||
$this->copyright = '';
|
||||
$this->showCover = true;
|
||||
$this->headerId = null;
|
||||
$this->footerId = null;
|
||||
$this->coverId = null;
|
||||
}
|
||||
|
||||
protected function pickerExceptId(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -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<string, string>|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<string, string>
|
||||
*/
|
||||
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,
|
||||
];
|
||||
|
||||
@@ -106,8 +106,8 @@ public function pickerResult(): array
|
||||
return ['items' => [], 'more' => false];
|
||||
}
|
||||
|
||||
if (in_array($this->pickerPurpose, ['aufbau', 'textbild'], true)) {
|
||||
$image = $this->pickerPurpose === 'textbild';
|
||||
if (in_array($this->pickerPurpose, ['aufbau', 'textbild', 'vorlagenbild'], true)) {
|
||||
$image = in_array($this->pickerPurpose, ['textbild', 'vorlagenbild'], true);
|
||||
|
||||
return $this->filterByMaterialart(app(EditorialCatalog::class)->browse(
|
||||
$this->pickerQuery,
|
||||
|
||||
@@ -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;
|
||||
@@ -67,20 +71,66 @@ private function guide(Composition $composition): array
|
||||
];
|
||||
}
|
||||
|
||||
$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 = '<table><tbody><tr><th><p>Zeit</p></th><th><p>Inhalt</p></th></tr><tr><td><p>10 Min.</p></td><td><p>Begrüßung</p></td></tr></tbody></table>';
|
||||
$chapters = [];
|
||||
|
||||
foreach (['Grundlagen' => 1, 'Haltung und Abstand' => 1, 'Vertiefung' => 2] as $title => $level) {
|
||||
$number = count($chapters) + 1;
|
||||
$chapters[] = [
|
||||
'number' => (string) ($level === 1 ? count(array_filter($chapters, fn (array $c): bool => $c['level'] === 1)) + 1 : '2.1'),
|
||||
'level' => $level,
|
||||
'anchor' => 'muster-'.$number,
|
||||
'title' => $title,
|
||||
'allowed' => true,
|
||||
'blocks' => FormattedText::blocks('<p>'.str_repeat('Mustertext für die Vorschau der Vorlage. ', 30).'</p><h3>Zwischenüberschrift</h3>'.$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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* PDF-Vorlagen für Dokumente (ADR-51, Nachtrag), rein additiv:
|
||||
*
|
||||
* - `pdf_templates`: Titelseite, Kopf- und Fußgrafik und Standardvermerke. Die Bilder verweisen auf freigegebene Bildfassungen
|
||||
* des Medienbestands.
|
||||
* - `compositions.pdf_template_id`: welche Vorlage ein Dokument verwendet (leer = bisheriges Layout).
|
||||
* - `composition_versions.document_meta`: Untertitel, Ausgabe (Release), Veröffentlichungsdatum und Copyright-Vermerk einer
|
||||
* Dokumentfassung. Sie sind Teil der Fassung und damit versioniert.
|
||||
*
|
||||
* Der Rückfall auf den vorherigen Programmstand setzt nur den Code zurück. Dieser kennt die Spalten und die Tabelle nicht;
|
||||
* ohne Vorlage und ohne Angaben erzeugt er dasselbe PDF wie bisher.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('pdf_templates', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
@@ -750,3 +750,5 @@ ## 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 (freigegebene Bildfassungen). 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.
|
||||
@@ -0,0 +1,32 @@
|
||||
# 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) |
|
||||
|
||||
## 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, nicht freigegebenes Bild abgelehnt, löschen); 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ß höchstens 140 Punkt hoch, 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).
|
||||
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 137 KiB |
|
After Width: | Height: | Size: 175 KiB |
|
After Width: | Height: | Size: 117 KiB |
|
After Width: | Height: | Size: 218 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 90 KiB |
@@ -65,7 +65,7 @@
|
||||
</div>
|
||||
|
||||
<div class="vw-register" role="tablist" aria-label="Bereiche">
|
||||
@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)
|
||||
<button type="button" role="tab" aria-selected="{{ $this->aufbauTab === $wert ? 'true' : 'false' }}" tabindex="{{ $this->aufbauTab === $wert ? '0' : '-1' }}"
|
||||
wire:click="showAufbauTab('{{ $wert }}')"
|
||||
x-on:keydown.right.prevent="$el.nextElementSibling?.focus()" x-on:keydown.left.prevent="$el.previousElementSibling?.focus()">
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
{{-- PDF-Vorlagen für Dokumente (ADR-51, Nachtrag): Titelseite, Kopf- und Fußgrafik, Standardvermerke. Eine Speicherhandlung. --}}
|
||||
@php
|
||||
$liste = $this->templates();
|
||||
$geaendert = $this->changed();
|
||||
$neu = $this->templateId === 0;
|
||||
$status = [
|
||||
$geaendert ? ['text' => 'Änderungen nicht gespeichert', 'ton' => 'offen'] : ['text' => $neu ? 'Noch keine Vorlage angelegt' : 'Gespeichert', 'ton' => $neu ? 'neutral' : 'gut'],
|
||||
['text' => 'Eine Vorlage ist reines Layout. Sie wirkt sofort auf jedes PDF der Dokumente, die sie verwenden, auch für ältere Fassungen.', 'ton' => 'neutral'],
|
||||
];
|
||||
$aktionen = [
|
||||
! $neu ? ['label' => 'Muster-PDF ansehen', 'href' => route('editorial.pdf-template-preview', $this->templateId), 'neu' => true, 'icon' => 'extern', 'art' => 'line'] : null,
|
||||
['label' => 'Vorlage speichern', 'wire' => 'save', 'art' => 'primary', 'disabled' => ! $geaendert],
|
||||
];
|
||||
$mehr = $neu ? [] : [['label' => 'Vorlage löschen …', 'wire' => "askConfirmation('delete')", 'hinweis' => 'Dokumente mit dieser Vorlage erzeugen danach wieder das einfache PDF.', 'gefahr' => true]];
|
||||
$felder = [
|
||||
'header' => ['Kopfgrafik', 'Steht oben auf jeder Seite außer der Titelseite, in voller Seitenbreite. Empfohlen: A4-breit (2480 Pixel bei 300 dpi), JPEG oder PNG ohne Transparenz.', $this->headerId],
|
||||
'footer' => ['Fußgrafik', 'Steht unten auf jeder Seite außer der Titelseite, in voller Seitenbreite. Die Lizenzzeile und „Seite n von m“ stehen darüber.', $this->footerId],
|
||||
'cover' => ['Bild der Titelseite', 'Steht oben auf der Titelseite in voller Seitenbreite, höchstens 40 % der Seite hoch. Ohne Bild beginnt die Titelseite mit dem Titel.', $this->coverId],
|
||||
];
|
||||
@endphp
|
||||
<x-filament-panels::page>
|
||||
<div class="vw" x-data x-on:keydown.window.ctrl.s.prevent="if (! document.querySelector('.vw-dialog')) $wire.save()">
|
||||
@include('filament.verwaltung.kopf', [
|
||||
'brot' => ['Inhalte', 'PDF-Vorlagen', $neu ? 'Neue Vorlage' : $this->name],
|
||||
'titel' => $neu ? 'Neue PDF-Vorlage' : $this->name,
|
||||
'typ' => 'Titelseite, Kopf- und Fußgrafik und Vermerke für das PDF eines Dokuments',
|
||||
'status' => $status,
|
||||
'aktionen' => array_values(array_filter($aktionen)),
|
||||
'mehr' => $mehr,
|
||||
])
|
||||
|
||||
<div class="vw-aufbau">
|
||||
<section class="vw-struktur" aria-labelledby="vorlagen-titel">
|
||||
<div class="vw-struktur-kopf">
|
||||
<h2 id="vorlagen-titel">Vorlagen <span class="vw-rolle-zahl">· {{ count($liste) }}</span></h2>
|
||||
<button type="button" class="vw-btn is-line is-small" wire:click="newTemplate">@include('filament.verwaltung.icon', ['name' => 'plus'])Neue Vorlage</button>
|
||||
</div>
|
||||
@if ($liste === [])
|
||||
<div class="vw-leer"><strong>Noch keine Vorlage</strong><p>Lege rechts die erste Vorlage an. Ein Dokument verwendet sie, wenn du sie im Dokument unter „PDF und Katalogbild“ zuordnest.</p></div>
|
||||
@else
|
||||
<ul class="vw-liste" aria-label="Vorlagen" style="display: grid; gap: 0.5rem; margin: 0; padding: 0; list-style: none;">
|
||||
@foreach ($liste as $zeile)
|
||||
<li wire:key="vorlage-{{ $zeile['id'] }}">
|
||||
<button type="button" @class(['vw-btn', 'is-primary' => $zeile['id'] === $this->templateId]) style="width: 100%; height: auto; flex-direction: column; align-items: flex-start; gap: 0.1rem; padding: 0.6rem 0.8rem; text-align: left;"
|
||||
wire:click="select({{ $zeile['id'] }})" @if ($zeile['id'] === $this->templateId) aria-current="true" @endif>
|
||||
<strong>{{ $zeile['name'] }}</strong>
|
||||
<span class="vw-feld-hilfe" style="color: inherit;">{{ $zeile['documents'] === 0 ? 'Von keinem Dokument verwendet' : ($zeile['documents'] === 1 ? '1 Dokument' : $zeile['documents'].' Dokumente') }}</span>
|
||||
</button>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
</section>
|
||||
|
||||
<section class="vw-detailbereich" aria-label="Vorlage bearbeiten">
|
||||
<div class="vw-detail-inhalt">
|
||||
<label class="vw-feldlabel">Name der Vorlage
|
||||
<input class="vw-eingabe" type="text" maxlength="255" wire:model.live.blur="name" placeholder="z. B. Handbuch">
|
||||
</label>
|
||||
<label class="vw-feldlabel" style="flex-direction: row; gap: 0.6rem; align-items: center;">
|
||||
<input type="checkbox" wire:model.live="showCover" style="width: 1.1rem; height: 1.1rem; accent-color: var(--vw-pine);">
|
||||
Titelseite: Der Titel steht allein auf der ersten Seite
|
||||
</label>
|
||||
<div class="vw-raster-2">
|
||||
<label class="vw-feldlabel">Herausgeber
|
||||
<input class="vw-eingabe" type="text" maxlength="255" wire:model.live.blur="publisher" placeholder="z. B. Lara & Felix">
|
||||
</label>
|
||||
<label class="vw-feldlabel">Standard-Copyright-Vermerk
|
||||
<textarea class="vw-eingabe" rows="3" wire:model.live.blur="copyright" placeholder="Gilt, wenn die Dokumentfassung keinen eigenen Vermerk hat"></textarea>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@foreach ($felder as $slot => [$label, $hilfe, $id])
|
||||
<div class="vw-karte-box" wire:key="bild-{{ $slot }}">
|
||||
<h3>{{ $label }}</h3>
|
||||
<p class="vw-feld-hilfe">{{ $hilfe }}</p>
|
||||
@if ($id !== null)
|
||||
<div class="vw-vorschaubild" style="height: auto; max-height: 12rem;"><img src="{{ $this->imageUrl($id) }}" alt="{{ $this->imageTitle($id) }}" style="max-height: 12rem; width: auto; max-width: 100%;"></div>
|
||||
<p class="vw-feld-hilfe">{{ $this->imageTitle($id) }}</p>
|
||||
@else
|
||||
<p class="vw-feld-hilfe">Kein Bild gewählt.</p>
|
||||
@endif
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem;">
|
||||
<button type="button" class="vw-btn" wire:click="openImagePicker('{{ $slot }}')">{{ $id === null ? 'Bild aus dem Bestand wählen' : 'Anderes Bild wählen' }}</button>
|
||||
@if ($id !== null)
|
||||
<button type="button" class="vw-link is-quiet" wire:click="clearImage('{{ $slot }}')">Bild entfernen</button>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@if ($this->pickerOpen)
|
||||
@include('filament.verwaltung.picker')
|
||||
@endif
|
||||
</div>
|
||||
@include('filament.verwaltung.bestaetigung')
|
||||
</x-filament-panels::page>
|
||||
@@ -7,12 +7,43 @@
|
||||
<div class="vw-medien-raster">
|
||||
<section class="vw-medien-haupt" aria-labelledby="didaktik-titel">
|
||||
@if ($this->isDocument())
|
||||
<h2 id="didaktik-titel" class="vw-abschnitt-titel">Dokument</h2>
|
||||
<p class="vw-feld-hilfe">Ein Dokument hat keine Didaktikangaben. Die Kapitel schreibst du im Register „Kapitel“. Name, Beschreibung und Einordnung des Dokuments bearbeitest du in der Redaktion.
|
||||
<h2 id="didaktik-titel" class="vw-abschnitt-titel">Titelseite und Impressum des PDF</h2>
|
||||
<p class="vw-feld-hilfe">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.
|
||||
<button type="button" class="vw-link" wire:click="openRedaktion('texte')">Redaktion öffnen</button></p>
|
||||
<label class="vw-feldlabel">Notiz zur nächsten Dokumentfassung
|
||||
<input class="vw-eingabe" type="text" wire:model.live.blur="revisionNote">
|
||||
<div class="vw-raster-2">
|
||||
<label class="vw-feldlabel">Untertitel
|
||||
<input class="vw-eingabe" type="text" maxlength="200" wire:model.live.blur="docSubtitle" placeholder="z. B. Handbuch für Trainerinnen und Trainer">
|
||||
</label>
|
||||
<label class="vw-feldlabel">Ausgabe (Release)
|
||||
<input class="vw-eingabe" type="text" maxlength="200" wire:model.live.blur="docEdition" placeholder="z. B. Ausgabe 2.1 · Stand Dezember 2026">
|
||||
</label>
|
||||
</div>
|
||||
<div class="vw-raster-2">
|
||||
<label class="vw-feldlabel">Veröffentlicht am
|
||||
<input class="vw-eingabe" type="date" wire:model.live.blur="docPublished">
|
||||
</label>
|
||||
<label class="vw-feldlabel">Notiz zur nächsten Dokumentfassung
|
||||
<input class="vw-eingabe" type="text" wire:model.live.blur="revisionNote">
|
||||
</label>
|
||||
</div>
|
||||
<label class="vw-feldlabel">Copyright-Vermerk
|
||||
<textarea class="vw-eingabe" rows="3" maxlength="600" wire:model.live.blur="docCopyright" placeholder="Leer: der Vermerk der PDF-Vorlage"></textarea>
|
||||
</label>
|
||||
|
||||
<h2 id="pdfvorlage-titel" class="vw-abschnitt-titel">PDF-Vorlage</h2>
|
||||
<p class="vw-feld-hilfe">Die Vorlage legt Titelseite sowie Kopf- und Fußgrafik des PDF fest. Sie ist reines Layout und wirkt sofort auf jedes PDF dieses Dokuments, auch auf ältere Fassungen; Ausgabe, Datum und Vermerk bleiben je Fassung. Ohne Vorlage bleibt das einfache Layout.
|
||||
@if (\App\Filament\Pages\PdfVorlagen::canAccess())<a class="vw-link" href="{{ \App\Filament\Pages\PdfVorlagen::getUrl() }}">Vorlagen verwalten</a>@endif</p>
|
||||
<div class="vw-raster-2">
|
||||
<label class="vw-feldlabel">Vorlage
|
||||
<select class="vw-eingabe" wire:model="pdfTemplateId">
|
||||
<option value="">Keine Vorlage (einfaches Layout)</option>
|
||||
@foreach ($this->pdfTemplateOptions() as $id => $name)
|
||||
<option value="{{ $id }}">{{ $name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
<div style="align-self: end;"><button type="button" class="vw-btn" wire:click="savePdfTemplate">Vorlage übernehmen</button></div>
|
||||
</div>
|
||||
@else
|
||||
<h2 id="didaktik-titel" class="vw-abschnitt-titel">Didaktik</h2>
|
||||
<p class="vw-feld-hilfe">Lernziel, Zeit und Material gehören zum fachlichen Stand {{ $ort }}. Sie werden mit „Entwurf speichern“ gesichert und erst mit „Fassung freigeben“ Teil einer neuen Fassung.</p>
|
||||
|
||||
@@ -79,6 +79,10 @@
|
||||
->middleware('auth:staff')
|
||||
->whereNumber('composition')
|
||||
->name('editorial.document-preview');
|
||||
Route::get('/redaktion/pdf-vorlage/{template}', [DocumentPreviewController::class, 'template'])
|
||||
->middleware('auth:staff')
|
||||
->whereNumber('template')
|
||||
->name('editorial.pdf-template-preview');
|
||||
Route::get('/redaktion/dokument/{composition}/pdf', [DocumentPreviewController::class, 'pdf'])
|
||||
->middleware('auth:staff')
|
||||
->whereNumber('composition')
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DocumentMeta;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\PdfTemplate;
|
||||
use App\Filament\Pages\PdfVorlagen;
|
||||
use App\Filament\Resources\Documents\Pages\EditDocument;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\Support\BuildsDocuments;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* PDF-Vorlagen für Dokumente (ADR-51, Nachtrag): Titelseite mit Ausgabe, Datum und Copyright-Vermerk, grafischer Kopf und Fuß,
|
||||
* Angaben als Teil der Dokumentfassung und eine Verwaltungsseite für die Vorlagen.
|
||||
*/
|
||||
class DokumentVorlageTest extends TestCase
|
||||
{
|
||||
use BuildsDocuments;
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Storage::fake('media_derived');
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
}
|
||||
|
||||
public function test_a_template_gives_the_title_its_own_cover_page_and_the_other_pages_header_and_footer_graphics(): void
|
||||
{
|
||||
$template = $this->template();
|
||||
[$article, $release, $member, $document] = $this->sold($template, [
|
||||
'subtitle' => 'Handbuch für Trainerinnen und Trainer',
|
||||
'edition' => 'Ausgabe 2.1 · Stand Dezember 2026',
|
||||
'published_on' => '2026-12-01',
|
||||
'copyright' => 'Alle Rechte beim Herausgeber. Weitergabe nur mit Lizenz.',
|
||||
]);
|
||||
|
||||
$pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->assertOk()->getContent();
|
||||
$pages = $this->pdfPages($pdf);
|
||||
$images = $this->pdfPageImages($pdf);
|
||||
|
||||
// Titelseite: der Titel allein, dann die Angaben der Fassung und der Vorlage, unten der Vermerk.
|
||||
$this->assertStringContainsString('Trainerhandbuch', $pages[0]);
|
||||
$this->assertStringContainsString('Handbuch für Trainerinnen und Trainer', $pages[0]);
|
||||
$this->assertStringContainsString('Ausgabe 2.1 · Stand Dezember 2026', $pages[0]);
|
||||
$this->assertStringContainsString('Veröffentlicht am 01.12.2026', $pages[0]);
|
||||
$this->assertStringContainsString('Herausgeber: Lara & Felix', $pages[0]);
|
||||
$this->assertStringContainsString('Alle Rechte beim Herausgeber.', $pages[0]);
|
||||
$this->assertStringNotContainsString('Inhaltsverzeichnis', $pages[0]);
|
||||
$this->assertStringNotContainsString('Grundlagen', $pages[0], 'Kein Kapitel auf der Titelseite.');
|
||||
$this->assertStringContainsString('Lizenziert für '.$member->name.' · Lizenzkopie LK-', $pages[0], 'Die Kennzeichnung steht auch auf der Titelseite.');
|
||||
|
||||
// Inhaltsverzeichnis folgt auf Seite 2; Kapitel beginnen dahinter und das Verzeichnis nennt ihre Seiten.
|
||||
$this->assertStringContainsString('Inhaltsverzeichnis', $pages[1]);
|
||||
$this->assertStringContainsString('Seite 2 von '.count($pages), $pages[1]);
|
||||
$start = collect($pages)->search(fn (string $page, int $index): bool => $index > 1 && str_contains($page, '1 Grundlagen'));
|
||||
$this->assertMatchesRegularExpression('/1 Grundlagen\\s+\\.{3,}\\s+'.($start + 1).'\\s/', $pages[1]);
|
||||
|
||||
// Bilder: Titelseite nur mit ihrem Bild, alle anderen Seiten mit Kopf und Fuß.
|
||||
$this->assertSame(1, $images[0], 'Die Titelseite trägt nur das Titelbild.');
|
||||
$this->assertSame(array_fill(0, count($pages) - 1, 2), array_slice($images, 1), 'Jede weitere Seite trägt Kopf und Fuß.');
|
||||
$this->assertSame(3, substr_count($pdf, '/Subtype /Image'), 'Drei verschiedene Grafiken, jede einmal im Dokument.');
|
||||
$this->assertStringContainsString($document->composition->display_title ?? 'Trainerhandbuch', $pages[0]);
|
||||
}
|
||||
|
||||
public function test_without_a_template_the_pdf_keeps_its_simple_layout_and_a_cover_can_be_switched_off(): void
|
||||
{
|
||||
[$article, $release, $member] = $this->sold(null, ['subtitle' => 'Wird ohne Vorlage nicht gedruckt']);
|
||||
$plain = $this->pdfPages($this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent());
|
||||
|
||||
$this->assertStringContainsString('Trainerhandbuch', $plain[0]);
|
||||
$this->assertStringContainsString('Inhaltsverzeichnis', $plain[0], 'Ohne Vorlage steht das Verzeichnis wie bisher auf der ersten Seite.');
|
||||
$this->assertStringNotContainsString('Wird ohne Vorlage nicht gedruckt', implode("\n", $plain));
|
||||
|
||||
$template = $this->template(cover: false);
|
||||
[$article, $release, $member] = $this->sold($template, null);
|
||||
$pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent();
|
||||
$pages = $this->pdfPages($pdf);
|
||||
|
||||
$this->assertStringContainsString('Inhaltsverzeichnis', $pages[0], 'Ohne Titelseite beginnt das Verzeichnis auf Seite 1.');
|
||||
$this->assertSame(array_fill(0, count($pages), 2), $this->pdfPageImages($pdf), 'Kopf und Fuß stehen auf jeder Seite.');
|
||||
}
|
||||
|
||||
public function test_the_fallback_copyright_of_the_template_is_used_when_the_version_has_none(): void
|
||||
{
|
||||
$template = $this->template(copyright: 'Standardvermerk der Vorlage.');
|
||||
[$article, $release, $member] = $this->sold($template, ['edition' => 'Ausgabe 1']);
|
||||
|
||||
$first = $this->pdfPages($this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent())[0];
|
||||
|
||||
$this->assertStringContainsString('Standardvermerk der Vorlage.', $first);
|
||||
}
|
||||
|
||||
public function test_the_details_belong_to_the_version_and_a_later_edit_changes_only_the_next_version(): void
|
||||
{
|
||||
$document = $this->documentComposition();
|
||||
$one = $this->document(['Grundlagen' => '<p>Text</p>'], composition: $document, meta: ['edition' => 'Ausgabe 1', 'unbekannt' => 'wird verworfen', 'published_on' => 'kein Datum']);
|
||||
$two = $this->document(['Grundlagen' => '<p>Text</p>'], composition: $document, meta: ['edition' => 'Ausgabe 2']);
|
||||
|
||||
$this->assertSame(['edition' => 'Ausgabe 1'], $one->fresh()->document_meta);
|
||||
$this->assertSame(['edition' => 'Ausgabe 2'], $two->fresh()->document_meta);
|
||||
$this->assertNotSame(app(ContentService::class)->structureHash($one->fresh()), app(ContentService::class)->structureHash($two->fresh()), 'Die Angaben ändern den Änderungsnachweis.');
|
||||
|
||||
$plain = $this->document(['Grundlagen' => '<p>Text</p>']);
|
||||
$this->assertNull($plain->fresh()->document_meta);
|
||||
$this->assertSame($plain->structure_hash, app(ContentService::class)->structureHash($plain->fresh()), 'Ohne Angaben bleibt der Nachweis wie vor den Vorlagen.');
|
||||
$this->assertNull(DocumentMeta::normalize(['subtitle' => ' ']));
|
||||
}
|
||||
|
||||
public function test_the_editor_saves_the_details_in_the_draft_and_binds_them_with_the_document_version(): void
|
||||
{
|
||||
$template = $this->template();
|
||||
$document = app(EditorialCatalog::class)->create('Trainerhandbuch', CompositionKind::Document);
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditDocument::class, ['record' => $document->getKey()])
|
||||
->call('addChapter', 1)->call('selectChapter', 0)->set('partTitle', 'Grundlagen')->set('rich.partBody', ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Text']]]]])
|
||||
->set('docSubtitle', 'Für Trainer')->set('docEdition', 'Ausgabe 1')->set('docPublished', '2026-12-01')->set('docCopyright', 'Vermerk')
|
||||
->call('saveDraft');
|
||||
|
||||
$this->assertSame(['subtitle' => 'Für Trainer', 'edition' => 'Ausgabe 1', 'published_on' => '2026-12-01', 'copyright' => 'Vermerk'], $document->fresh()->working_draft['document_meta']);
|
||||
|
||||
$component->call('armRelease')->set('releaseConsent', true)->call('publishRevision');
|
||||
$version = $document->versions()->firstOrFail();
|
||||
$this->assertSame('Ausgabe 1', $version->document_meta['edition']);
|
||||
|
||||
// Eine Änderung der Ausgabe allein verlangt eine neue Fassung.
|
||||
$component->set('docEdition', 'Ausgabe 2')->call('armRelease')->assertSet('releaseArmed', true);
|
||||
$component->set('releaseConsent', true)->call('publishRevision');
|
||||
$this->assertSame(['Ausgabe 1', 'Ausgabe 2'], $document->versions()->orderBy('number')->get()->map(fn ($v) => $v->document_meta['edition'])->all());
|
||||
|
||||
// Die Vorlage wird sofort zugeordnet und zeigt sich beim erneuten Öffnen.
|
||||
$component->set('pdfTemplateId', (string) $template->id)->call('savePdfTemplate');
|
||||
$this->assertSame($template->id, $document->fresh()->pdf_template_id);
|
||||
$reopened = Livewire::actingAs($this->editor(), 'staff')->test(EditDocument::class, ['record' => $document->getKey()]);
|
||||
$this->assertSame((string) $template->id, $reopened->get('pdfTemplateId'));
|
||||
$this->assertSame('Ausgabe 2', $reopened->get('docEdition'));
|
||||
|
||||
$component->set('pdfTemplateId', '')->call('savePdfTemplate');
|
||||
$this->assertNull($document->fresh()->pdf_template_id);
|
||||
}
|
||||
|
||||
public function test_the_template_page_creates_changes_and_deletes_templates_with_images_from_the_picker(): void
|
||||
{
|
||||
$header = $this->picture('Kopf', 2480, 300, [20, 80, 60]);
|
||||
$draftImage = app(ContentService::class)->draftElementVersion(app(ContentService::class)->createElement('bild', 'bild', 'Entwurf'), null, ['file' => 'inhalte/entwurf.png']);
|
||||
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)->assertOk();
|
||||
$this->assertSame([], $component->instance()->templates());
|
||||
|
||||
$component->set('name', 'Handbuch')->set('publisher', 'Lara & Felix')->set('copyright', '© Lara & Felix')
|
||||
->call('openImagePicker', 'header')->assertSet('pickerPurpose', 'vorlagenbild');
|
||||
$this->assertSame(['bild' => 'Bilder'], $component->instance()->pickerKinds());
|
||||
$this->assertContains('Kopf', array_column($component->instance()->pickerResult()['items'], 'title'));
|
||||
|
||||
// Eine nicht freigegebene Fassung wird abgelehnt.
|
||||
$component->call('markPicker', 'element:'.$draftImage->id, true)->call('confirmPicker')->assertSet('headerId', null);
|
||||
$component->call('markPicker', 'element:'.$header->id, true)->call('confirmPicker')->assertSet('headerId', $header->id)->assertSet('pickerOpen', false);
|
||||
$this->assertTrue($component->instance()->changed());
|
||||
$component->call('save');
|
||||
|
||||
$template = PdfTemplate::query()->firstOrFail();
|
||||
$this->assertSame(['Handbuch', $header->id, true], [$template->name, $template->header_version_id, $template->show_cover]);
|
||||
$this->assertFalse($component->instance()->changed());
|
||||
|
||||
$component->set('showCover', false)->call('clearImage', 'header')->call('save');
|
||||
$this->assertNull($template->fresh()->header_version_id);
|
||||
$this->assertFalse($template->fresh()->show_cover);
|
||||
|
||||
$this->actingAs($this->editor(), 'staff')->get(route('editorial.pdf-template-preview', $template))->assertOk()->assertHeader('Content-Type', 'application/pdf');
|
||||
|
||||
$component->call('askConfirmation', 'delete')->call('confirmConfirmation');
|
||||
$this->assertSame(0, PdfTemplate::query()->count());
|
||||
}
|
||||
|
||||
public function test_deleting_a_template_returns_its_documents_to_the_simple_layout(): void
|
||||
{
|
||||
$template = $this->template();
|
||||
$document = $this->documentComposition();
|
||||
$document->forceFill(['pdf_template_id' => $template->id])->save();
|
||||
|
||||
$template->delete();
|
||||
|
||||
$this->assertNull($document->fresh()->pdf_template_id);
|
||||
}
|
||||
|
||||
public function test_the_staff_preview_of_a_document_uses_its_template_and_the_draft_details(): void
|
||||
{
|
||||
$template = $this->template();
|
||||
$document = $this->documentComposition();
|
||||
$document->forceFill(['pdf_template_id' => $template->id, 'working_draft' => ['members' => [], 'document_meta' => ['edition' => 'Entwurfsausgabe 7']]])->save();
|
||||
$this->document(['Grundlagen' => '<p>Text</p>'], composition: $document);
|
||||
$document->forceFill(['working_draft' => ['members' => [['role' => 'Kapitel', 'target' => 'element:'.ContentElementVersion::query()->firstOrFail()->id, 'note' => '']], 'document_meta' => ['edition' => 'Entwurfsausgabe 7']]])->save();
|
||||
|
||||
$pdf = $this->actingAs($this->editor(), 'staff')->get(route('editorial.document-preview.pdf', $document))->assertOk()->getContent();
|
||||
|
||||
$this->assertStringContainsString('Entwurfsausgabe 7', $this->pdfPages($pdf)[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Vorlage mit Kopf-, Fuß- und Titelbild (drei verschiedene Grafiken).
|
||||
*/
|
||||
private function template(bool $cover = true, ?string $copyright = null): PdfTemplate
|
||||
{
|
||||
return PdfTemplate::query()->create([
|
||||
'name' => 'Handbuch',
|
||||
'kind' => PdfTemplate::KIND_DOCUMENT,
|
||||
'show_cover' => $cover,
|
||||
'header_version_id' => $this->picture('Kopf '.uniqid(), 2480, 300, [20, 80, 60])->id,
|
||||
'footer_version_id' => $this->picture('Fuß '.uniqid(), 2480, 200, [200, 160, 40])->id,
|
||||
'cover_version_id' => $this->picture('Titel '.uniqid(), 1600, 900, [60, 60, 160])->id,
|
||||
'publisher' => 'Lara & Felix',
|
||||
'copyright' => $copyright,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Handbuch in einem verkauften Modul, optional mit Vorlage und Angaben.
|
||||
*
|
||||
* @param array<string, string>|null $meta
|
||||
* @return array{0: LicenseArticle, 1: ArticleRelease, 2: User, 3: CompositionVersion}
|
||||
*/
|
||||
private function sold(?PdfTemplate $template, ?array $meta): array
|
||||
{
|
||||
$composition = $this->documentComposition();
|
||||
$composition->forceFill(['pdf_template_id' => $template?->id])->save();
|
||||
$document = $this->document([
|
||||
'Grundlagen' => '<p>'.str_repeat('Haltung zeigen und Abstand halten. ', 40).'</p>',
|
||||
'Haltung' => '<p>'.str_repeat('Klar sprechen. ', 50).'</p>',
|
||||
], composition: $composition, meta: $meta);
|
||||
$module = $this->moduleWith('Modul Handbuch', $document);
|
||||
[$article, $release] = $this->publishFor('handbuch-'.uniqid(), $module);
|
||||
|
||||
return [$article, $release, $this->memberWith($this->fullRights(), [$article]), $document];
|
||||
}
|
||||
|
||||
private function editor(): User
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
return $editor;
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ protected function chapter(Composition $document, string $title, string $body):
|
||||
*
|
||||
* @param array<string, string> $chapters
|
||||
*/
|
||||
protected function document(array $chapters, string $title = 'Trainerhandbuch', ?Composition $composition = null): CompositionVersion
|
||||
protected function document(array $chapters, string $title = 'Trainerhandbuch', ?Composition $composition = null, ?array $meta = null): CompositionVersion
|
||||
{
|
||||
$composition ??= $this->documentComposition($title);
|
||||
$members = [];
|
||||
@@ -60,16 +60,16 @@ protected function document(array $chapters, string $title = 'Trainerhandbuch',
|
||||
$members[] = ['role' => $sub ? 'Unterkapitel' : 'Kapitel', 'target' => $this->chapter($composition, $name, $body)];
|
||||
}
|
||||
|
||||
return app(ContentService::class)->publishComposition($composition, $members);
|
||||
return app(ContentService::class)->publishComposition($composition, $members, null, null, $meta === null ? [] : ['document_meta' => $meta]);
|
||||
}
|
||||
|
||||
/** Ein Bild im Medienbestand mit echter Datei im abgeleiteten Bestand. */
|
||||
protected function picture(string $title, int $width = 640, int $height = 360): ContentElementVersion
|
||||
protected function picture(string $title, int $width = 640, int $height = 360, array $rgb = [40, 120, 90]): ContentElementVersion
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$file = 'inhalte/'.str($title)->slug().'.png';
|
||||
$image = imagecreatetruecolor($width, $height);
|
||||
imagefill($image, 0, 0, (int) imagecolorallocate($image, 40, 120, 90));
|
||||
imagefill($image, 0, 0, (int) imagecolorallocate($image, ...$rgb));
|
||||
ob_start();
|
||||
imagepng($image);
|
||||
Storage::disk('media_derived')->put($file, (string) ob_get_clean());
|
||||
@@ -124,6 +124,18 @@ protected function pdfText(string $pdf): string
|
||||
return implode("\n", $this->pdfPages($pdf));
|
||||
}
|
||||
|
||||
/**
|
||||
* Anzahl der Bilder je Seite (aus den Betriebsmitteln der Seitenobjekte).
|
||||
*
|
||||
* @return list<int>
|
||||
*/
|
||||
protected function pdfPageImages(string $pdf): array
|
||||
{
|
||||
preg_match_all('/\/Type \/Page \/Parent 2 0 R(.*?)\/Contents \d+ 0 R/s', $pdf, $pages);
|
||||
|
||||
return array_map(fn (string $page): int => preg_match_all('/\/Im\d+ \d+ 0 R/', $page), $pages[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Text je Seite. Die Seiteninhalte stehen in der Reihenfolge der Seiten im Dokument.
|
||||
*
|
||||
|
||||