Files
LarsandClaude Opus 5.5 127ea86817
CI Feature / test (push) Successful in 46s
Deploy Test / test (push) Successful in 39s
Deploy Test / deploy (push) Successful in 29s
Integriere die Premium-Karten v1.7 als Themen-, Medien- und Programmkarte.
- Drei Widget-Arten (topic_card, media_card, program_card) auf gemeinsamer Basis, eine Karte je Platz im
  bestehenden Abschnittsraster; kein zweites Kartenraster.
- Titel, Kurzbeschreibung, Art, Zusatzangaben und Linkziel kommen zur Laufzeit aus Thema, Inhaltselement
  bzw. Programm/Modul; im CMS stehen nur Kennungen, Bild, Bildausschnitt, Beschriftung und Hinweis.
- Medienkarten sind öffentlich nur als Bestandteil eines öffentlichen Programms (PublicMaterialReader),
  Module nur in der Redaktionsvorschau; keine Bibliotheksbilder, kein Preis, keine Kaufaktion.
- Gleiche Höhe je Zeile über die gemeinsame Höhe „fill“; Raster 1 + 1 + 2 und 2 + 1 + 1 ergänzt.
- Tests zu Raster- und Widgetliste bewusst um die neuen Raster und Arten erweitert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 13:25:06 +01:00

135 lines
4.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Domain\Cms\Sections;
/**
* Freigegebene Abschnittsraster. Ein Raster teilt die Abschnittsbreite in höchstens vier logische Einheiten.
* Die Kennungen sind gespeichert und ändern sich nie; neue Raster werden ergänzt, nicht umbenannt.
*
* Die Einheiten werden nicht als eigenes CSS-Grundraster umgesetzt, sondern als Spaltenverhältnis (fr)
* des Abschnittsrasters. Leere Slots entfallen auf der veröffentlichten Seite; die übrigen Slots teilen
* sich die Breite im Verhältnis ihrer Einheiten.
*/
final class SectionLayouts
{
public const DEFAULT = 'u4';
/** @var array<string, list<int>> */
public const UNITS = [
'u4' => [4],
'u2_2' => [2, 2],
'u1_3' => [1, 3],
'u3_1' => [3, 1],
'u1_2_1' => [1, 2, 1],
'u1_1_1_1' => [1, 1, 1, 1],
'u1_1_2' => [1, 1, 2],
'u2_1_1' => [2, 1, 1],
];
/** @var array<string, string> */
public const LABELS = [
'u4' => 'Volle Breite',
'u2_2' => 'Zwei gleich breit',
'u1_3' => 'Schmal und breit',
'u3_1' => 'Breit und schmal',
'u1_2_1' => 'Mitte betont',
'u1_1_1_1' => 'Vier gleich breit',
'u1_1_2' => 'Zwei schmal, eins breit',
'u2_1_1' => 'Eins breit, zwei schmal',
];
public static function has(mixed $key): bool
{
return is_string($key) && isset(self::UNITS[$key]);
}
/**
* @return list<int>
*/
public static function units(string $key): array
{
return self::UNITS[$key] ?? self::UNITS[self::DEFAULT];
}
public static function slotCount(string $key): int
{
return count(self::units($key));
}
/** Kurzform wie „1 + 3“. */
public static function short(string $key): string
{
return implode(' + ', self::units($key));
}
public static function label(string $key): string
{
return (self::LABELS[$key] ?? self::LABELS[self::DEFAULT]).' ('.self::short($key).')';
}
/**
* @return array<string, string>
*/
public static function options(): array
{
$options = [];
foreach (array_keys(self::UNITS) as $key) {
$options[$key] = self::label($key);
}
return $options;
}
/**
* Spaltenvorlagen für die Slots, die tatsächlich etwas darstellen.
*
* - Desktop (Abschnitt ab 60rem): Verhältnis der Einheiten.
* - Tablet (ab 40rem): gleich breite Slots bleiben nebeneinander (zwei oder drei Spalten, vier Slots als 2 × 2);
* ungleiche Raster stapeln, damit kein Slot unter etwa 13rem fällt.
* - Smartphone: immer eine Spalte. Die Lese- und Fokusreihenfolge bleibt die Reihenfolge der Slots.
*
* @param list<int> $units
* @return array{lg: string, md: string}
*/
public static function columns(array $units): array
{
$units = array_values(array_filter($units, fn ($unit): bool => is_int($unit) && $unit > 0));
$count = count($units);
if ($count <= 1) {
return ['lg' => 'minmax(0, 1fr)', 'md' => 'minmax(0, 1fr)'];
}
$lg = implode(' ', array_map(fn (int $unit): string => "minmax(0, {$unit}fr)", $units));
$equal = count(array_unique($units)) === 1;
$md = match (true) {
! $equal => 'minmax(0, 1fr)',
$count === 3 => 'repeat(3, minmax(0, 1fr))',
default => 'repeat(2, minmax(0, 1fr))',
};
return ['lg' => $lg, 'md' => $md];
}
/**
* Symbolbild des Rasters für die grafische Auswahl im Editor (rein dekorativ).
*/
public static function schematicSvg(string $key): string
{
$units = self::units($key);
$gap = 2;
$width = 56 - $gap * (count($units) - 1);
$x = 2;
$rects = '';
foreach ($units as $unit) {
$w = (int) round($width * $unit / 4);
$rects .= sprintf('<rect x="%d" y="4" width="%d" height="20" rx="1.5"/>', $x, $w);
$x += $w + $gap;
}
return '<svg class="luf-layout-schematic" viewBox="0 0 60 28" width="60" height="28" aria-hidden="true" focusable="false">'.$rects.'</svg>';
}
}