'boolean']; } public const SLOTS = ['header', 'footer', 'cover']; /** Anordnung von Kopf- und Fußgrafik: Band in voller Seitenbreite oder Logo links oder rechts. */ public const ALIGNMENTS = ['full', 'left', 'right']; public const LOGO_MIN = 16; public const LOGO_MAX = 100; public const LOGO_DEFAULT = 40; /** Inhaltsverzeichnis: nur bei mehr als einem Eintrag, immer oder nie. */ public const TOC_MODES = ['auto', 'always', 'never']; /** Tiefe des Verzeichnisses: 2 = nur Kapitel und Unterkapitel, 3 bis 6 = zusätzlich die Überschriften bis zu dieser Stufe. */ public const TOC_DEPTH_MIN = 2; public const TOC_DEPTH_MAX = 6; /** * Darstellung des gedruckten Inhaltsverzeichnisses. * * @return array{mode: string, depth: int} */ public function toc(): array { return self::normalizeToc((string) $this->getAttribute('toc_mode'), (int) $this->getAttribute('toc_depth')); } /** * @return array{mode: string, depth: int} */ public static function normalizeToc(?string $mode, int|string|null $depth): array { $depth = (int) $depth; return [ 'mode' => in_array($mode, self::TOC_MODES, true) ? (string) $mode : 'auto', 'depth' => $depth < 1 ? self::TOC_DEPTH_MAX : max(self::TOC_DEPTH_MIN, min(self::TOC_DEPTH_MAX, $depth)), ]; } /** * Anordnung und Logohöhe (Punkt) von Kopf oder Fuß; ungültige Werte fallen auf die Vorgabe zurück. * * @return array{align: string, height: int} */ public function layout(string $slot): array { return self::normalizeLayout((string) $this->getAttribute($slot.'_align'), (int) $this->getAttribute($slot.'_logo_height')); } /** * @return array{align: string, height: int} */ public static function normalizeLayout(?string $align, int|string|null $height): array { $height = (int) $height; return [ 'align' => in_array($align, self::ALIGNMENTS, true) ? (string) $align : 'full', 'height' => $height < 1 ? self::LOGO_DEFAULT : max(self::LOGO_MIN, min(self::LOGO_MAX, $height)), ]; } /** * Das Bild eines Bildfelds als Ziel des Pickers: `element:`, `medium:` oder null. */ public function target(string $slot): ?string { $version = $this->getAttribute($slot.'_version_id'); $element = $this->getAttribute($slot.'_element_id'); return $version !== null ? 'element:'.$version : ($element !== null ? 'medium:'.$element : null); } /** * Die Spaltenwerte eines Bildfelds für ein Ziel des Pickers. * * @return array */ public static function columns(string $slot, ?string $target): array { $ref = TemplateImage::parse($target); return [ $slot.'_version_id' => ($ref['type'] ?? null) === 'version' ? $ref['id'] : null, $slot.'_element_id' => ($ref['type'] ?? null) === 'medium' ? $ref['id'] : null, ]; } public function headerVersion(): BelongsTo { return $this->belongsTo(ContentElementVersion::class, 'header_version_id'); } public function footerVersion(): BelongsTo { return $this->belongsTo(ContentElementVersion::class, 'footer_version_id'); } public function coverVersion(): BelongsTo { return $this->belongsTo(ContentElementVersion::class, 'cover_version_id'); } public function compositions(): HasMany { return $this->hasMany(Composition::class); } }