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>
52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?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');
|
|
}
|
|
}
|