Files
laraundfelix/app/Domain/Cms/Catalog/PublicCatalogReader.php
LarsandClaude Opus 5.5 9d936bfa4a
CI Feature / test (push) Successful in 31s
Führe eine zentrale Widget-Registry mit visuellem Seiteneditor ein.
- Codebasiertes Widget-Register (config/cms.php) mit Vertrag
  {id, type, v, variant, settings, data, refs}: Typkennung, Schemaversion,
  Prüfregeln, freigegebene Varianten, Editorfelder, Blade-Ansicht,
  Verweisauflösung und Medienliste je Widget-Art.
- Die sechs Bestandsbausteine bleiben als Version 1 lesbar; gespeicherte
  Revisionen werden nicht umgeschrieben, sondern beim Lesen angehoben
  (Bild und Text: Version 2 mit Titel, formatiertem Text, Bild links/rechts).
  Wiederherstellen kopiert eine Revision unverändert.
- Neue Widgets: Einstieg (Hero) und Programm-/Modulkarten. Letztere speichern
  nur Verweise; Titel und Kurzbeschreibung kommen aus den Fachdaten. Öffentlich
  erscheinen nur Programme mit Anzeigefreigabe (gleiche Regel wie /programme,
  jetzt in PublicCatalogReader); Module nur in der Redaktionsvorschau, bis
  öffentliche Profile (ADR-29) bestehen.
- Ein Renderer für öffentliche Seite, Vorschau und Blockvorschau im Editor.
- Seiteneditor als Filament-Builder: Auswahl mit Beschreibung und Schema,
  kompakte Abschnitte mit Vorschau, Bearbeitung im Dialog, Sortieren,
  Duplizieren. Speichern erzeugt nur einen Entwurf.
- Vorschau einer Revision in 390/768/1440 px; Vorschauroute nutzt den
  Personal-Guard (vorher war sie für Redakteure ohne Mitgliedersitzung
  nicht erreichbar).
- Basislayout in Komponenten (Marke, Kopf, Fuß, Seitenvorlage).
- Navigation: bearbeiten, ausblenden, löschen, per Ziehen sortieren;
  unsichere Adressen (javascript:) werden abgewiesen und nicht ausgegeben.
  Ergänzende Migration is_visible (Vorgabe sichtbar).
- Pfadfehler und doppelte Pfade erscheinen am Pfadfeld statt still zu scheitern.

Tests: BlockRegistryTest geht in WidgetRegistryTest auf (gleiche Prüfungen
plus Registrierung, Versionierung, Bereinigung). Bestandsseiten werden gegen
Textfixtures aus dem Stand vor der Umstellung geprüft.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 17:49:30 +01:00

186 lines
6.3 KiB
PHP

<?php
namespace App\Domain\Cms\Catalog;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionDisplayRelease;
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\EditorialContentKind;
use Illuminate\Support\Collection;
/**
* Lesesicht „Öffentlicher Katalog“ für Website und CMS (Website-CMS-Zielarchitektur 5.1, 6.2).
*
* Übergangsregel, solange öffentliche Fachobjektprofile (ADR-29) fehlen:
* Öffentlich gezeigt wird nur, was die Website bereits heute öffentlich zeigt, nämlich Kompositionen
* der Inhaltsart „programm“ mit einer zur Anzeige freigegebenen Fassung (Route /programme).
* Module haben noch keine öffentliche Seitenart; sie sind im Editor wählbar und erscheinen nur in
* der geschützten Redaktionsvorschau, nie auf der öffentlichen Seite.
*
* Gelesen werden nur Anzeigetitel, Kurzbeschreibung und Inhaltsart, nie Dateien, Lehrtexte oder
* Vorschaubilder der Bibliothek (diese sind geschützt, Paket 6).
*/
class PublicCatalogReader
{
/** Inhaltsarten mit öffentlicher Seitenart. */
public const PUBLIC_KINDS = ['programm'];
/** Inhaltsarten, die ein Katalog-Widget referenzieren darf. */
public const SELECTABLE_KINDS = ['programm', 'modul'];
public function __construct(private readonly CompositionDisplayRelease $releases) {}
/**
* @return Collection<int, Composition>
*/
public function publicPrograms(): Collection
{
$kind = EditorialContentKind::query()->where('slug', 'programm')->first();
if ($kind === null) {
return collect();
}
return Composition::query()
->where('editorial_content_kind_id', $kind->id)
->orderBy('designation')
->get()
->filter(fn (Composition $composition): bool => $this->shownVersion($composition) !== null)
->values();
}
/**
* Gezeigte Fassung einer öffentlich gezeigten Komposition, sonst null.
*/
public function shownVersion(Composition $composition): ?CompositionVersion
{
if (! in_array($composition->editorialContentKind?->slug, self::PUBLIC_KINDS, true)) {
return null;
}
return $this->releases->highestReleasedVersion($composition);
}
public function isPublic(Composition $composition): bool
{
return $this->shownVersion($composition) !== null;
}
/**
* Wählbar sind Programme und Module mit zur Anzeige freigegebener Fassung, die nicht archiviert sind.
*/
public function isSelectable(Composition $composition): bool
{
return $composition->archived_at === null
&& in_array($composition->editorialContentKind?->slug, self::SELECTABLE_KINDS, true)
&& $this->releases->highestReleasedVersion($composition) !== null;
}
/**
* Suchtreffer für die Auswahl im Editor: Kennung => Bezeichnung mit Sichtbarkeitshinweis.
*
* @return array<int, string>
*/
public function search(?string $term, int $limit = 25): array
{
$term = trim((string) $term);
$candidates = Composition::query()
->with('editorialContentKind')
->whereNull('archived_at')
->whereHas('editorialContentKind', fn ($query) => $query->whereIn('slug', self::SELECTABLE_KINDS))
->when($term !== '', function ($query) use ($term): void {
$like = '%'.mb_strtolower($term).'%';
$query->where(fn ($inner) => $inner
->whereRaw('LOWER(designation) LIKE ?', [$like])
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like]));
})
->orderBy('designation')
->limit($limit * 3)
->get();
$options = [];
foreach ($candidates as $composition) {
if (! $this->isSelectable($composition)) {
continue;
}
$options[$composition->id] = $this->optionLabel($composition);
if (count($options) >= $limit) {
break;
}
}
return $options;
}
public function labelFor(mixed $id): ?string
{
$composition = is_numeric($id) ? Composition::query()->with('editorialContentKind')->find((int) $id) : null;
return $composition === null ? null : $this->optionLabel($composition);
}
/**
* Löst Verweise in Anzeigeeinträge auf. Öffentlich entfallen nicht öffentliche Objekte stillschweigend.
*
* @param list<array{type?: mixed, id?: mixed}> $refs
* @return list<CatalogEntry>
*/
public function entries(array $refs, bool $includeNonPublic): array
{
$ids = [];
foreach ($refs as $ref) {
if (is_array($ref) && ($ref['type'] ?? null) === 'composition' && is_numeric($ref['id'] ?? null)) {
$ids[] = (int) $ref['id'];
}
}
if ($ids === []) {
return [];
}
$compositions = Composition::query()->with('editorialContentKind')->whereIn('id', $ids)->get()->keyBy('id');
$entries = [];
foreach (array_unique($ids) as $id) {
$composition = $compositions->get($id);
if ($composition === null || ! $this->isSelectable($composition)) {
continue;
}
$public = $this->isPublic($composition);
if (! $public && ! $includeNonPublic) {
continue;
}
$entries[] = new CatalogEntry(
id: $composition->id,
title: $this->title($composition),
summary: filled($composition->summary) ? (string) $composition->summary : null,
kindLabel: (string) ($composition->editorialContentKind?->label ?? ''),
url: $public ? route('public.program', $composition) : null,
public: $public,
);
}
return $entries;
}
private function title(Composition $composition): string
{
return (string) ($composition->display_title ?: $composition->designation);
}
private function optionLabel(Composition $composition): string
{
$visibility = $this->isPublic($composition) ? 'öffentlich sichtbar' : 'nur Redaktionsvorschau';
return $this->title($composition).' · '.($composition->editorialContentKind?->label ?? '').' · '.$visibility;
}
}