Kopf-, Fuß- und Titelbild einer PDF-Vorlage sind Gestaltung und brauchen keine Inhaltsfassung. Der Picker bietet auch Präsentationsmedien und für die Website freigegebene Bilder an (Spalten *_element_id, Klasse TemplateImage); gedruckt wird die Website-Datei, sonst die Präsentationsdatei. Abgelehnt werden nur gesperrte oder archivierte Bilder, fehlende Dateien und Nicht-Bilder. Bilder im Text eines Dokuments bleiben an freigegebene Bildfassungen gebunden. Die öffentliche Eigenschaft heißt bilder, weil slots mit Livewires internem Slot-Mechanismus kollidiert. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
85 lines
2.5 KiB
PHP
85 lines
2.5 KiB
PHP
<?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',
|
|
'header_element_id',
|
|
'footer_element_id',
|
|
'cover_element_id',
|
|
'publisher',
|
|
'copyright',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['show_cover' => 'boolean'];
|
|
}
|
|
|
|
public const SLOTS = ['header', 'footer', 'cover'];
|
|
|
|
/**
|
|
* Das Bild eines Bildfelds als Ziel des Pickers: `element:<Fassung>`, `medium:<Medium>` oder null.
|
|
*/
|
|
public function target(string $slot): ?string
|
|
{
|
|
$version = $this->getAttribute($slot.'_version_id');
|
|
$element = $this->getAttribute($slot.'_element_id');
|
|
|
|
return $version !== null ? 'element:'.$version : ($element !== null ? 'medium:'.$element : null);
|
|
}
|
|
|
|
/**
|
|
* Die Spaltenwerte eines Bildfelds für ein Ziel des Pickers.
|
|
*
|
|
* @return array<string, int|null>
|
|
*/
|
|
public static function columns(string $slot, ?string $target): array
|
|
{
|
|
$ref = TemplateImage::parse($target);
|
|
|
|
return [
|
|
$slot.'_version_id' => ($ref['type'] ?? null) === 'version' ? $ref['id'] : null,
|
|
$slot.'_element_id' => ($ref['type'] ?? null) === 'medium' ? $ref['id'] : null,
|
|
];
|
|
}
|
|
|
|
public function headerVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ContentElementVersion::class, 'header_version_id');
|
|
}
|
|
|
|
public function footerVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ContentElementVersion::class, 'footer_version_id');
|
|
}
|
|
|
|
public function coverVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ContentElementVersion::class, 'cover_version_id');
|
|
}
|
|
|
|
public function compositions(): HasMany
|
|
{
|
|
return $this->hasMany(Composition::class);
|
|
}
|
|
}
|