Führe PDF-Vorlagen für Dokumente ein: Titelseite, grafischer Kopf und Fuß, Angaben je Fassung (ADR-51, Nachtrag)
Deploy Test / test (push) Successful in 3m21s
Deploy Test / deploy (push) Successful in 27s

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>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-24 14:28:34 +01:00
1 parent 81037b9868
commit 765b8e779e
31 files changed
+1272 -33

No files matched your search

@@ -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,
];