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>
This commit is contained in:
1 parent
cca069be48
commit
127ea86817
16 files changed
+1579
-3
No files matched your search
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Catalog;
|
||||
|
||||
use App\Domain\Catalog\CompositionStructureReader;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
|
||||
/**
|
||||
* Lesesicht „Medien und Materialien“ für Premium-Karten (Website-CMS-Zielarchitektur 6.2).
|
||||
*
|
||||
* Übergangsregel, solange öffentliche Fachobjektprofile (ADR-29) fehlen:
|
||||
* Ein Medium oder Material hat keine eigene öffentliche Seite. Öffentlich genannt wird es heute nur als Bestandteil
|
||||
* der gezeigten Fassung eines öffentlichen Programms (Programmseite /programme/{id}). Genau dann erscheint auch die
|
||||
* Karte öffentlich, mit Verweis auf diese Programmseite. Sonst ist die Karte nur in der Redaktionsvorschau sichtbar.
|
||||
*
|
||||
* Gelesen werden nur Anzeigetitel, Kurzbeschreibung, Inhaltsart und Ausgabeart, nie Dateien, Lehrtexte,
|
||||
* Vorschaubilder der Bibliothek oder Ausgabeadressen. Eine Karte gibt kein Medium frei.
|
||||
*/
|
||||
class PublicMaterialReader
|
||||
{
|
||||
/** @var array<int, array{id: int, title: string}>|null Element-ID => erstes öffentliches Programm */
|
||||
private ?array $publicIndex = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly PublicCatalogReader $catalog,
|
||||
private readonly CompositionStructureReader $structure,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Wählbar ist ein nicht archiviertes Element mit mindestens einer bereitgestellten (nicht gesperrten) Fassung.
|
||||
*/
|
||||
public function isSelectable(ContentElement $element): bool
|
||||
{
|
||||
return $element->archived_at === null
|
||||
&& $element->versions()->where('status', ContentVersionStatus::Bereit->value)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffentliches Programm, in dessen gezeigter Fassung das Element vorkommt, sonst null.
|
||||
*
|
||||
* @return array{id: int, title: string}|null
|
||||
*/
|
||||
public function publicProgramFor(ContentElement $element): ?array
|
||||
{
|
||||
return $this->publicIndex()[$element->id] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function search(?string $term, int $limit = 25): array
|
||||
{
|
||||
$term = trim((string) $term);
|
||||
|
||||
$candidates = ContentElement::query()
|
||||
->with('editorialContentKind')
|
||||
->whereNull('archived_at')
|
||||
->whereHas('versions', fn ($query) => $query->where('status', ContentVersionStatus::Bereit->value))
|
||||
->when($term !== '', function ($query) use ($term): void {
|
||||
$like = '%'.mb_strtolower($term).'%';
|
||||
$query->where(fn ($inner) => $inner
|
||||
->whereRaw('LOWER(working_title) LIKE ?', [$like])
|
||||
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like]));
|
||||
})
|
||||
->orderBy('working_title')
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
||||
$options = [];
|
||||
foreach ($candidates as $element) {
|
||||
$options[$element->id] = $this->optionLabel($element);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function labelFor(mixed $id): ?string
|
||||
{
|
||||
$element = is_numeric($id) ? ContentElement::query()->with('editorialContentKind')->find((int) $id) : null;
|
||||
|
||||
return $element === null ? null : $this->optionLabel($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Anzeigedaten für eine Karte. Öffentlich null, wenn das Element nicht öffentlich genannt wird.
|
||||
*/
|
||||
public function subject(mixed $id, bool $includeNonPublic): ?CardSubject
|
||||
{
|
||||
$element = is_numeric($id) ? ContentElement::query()->with('editorialContentKind')->find((int) $id) : null;
|
||||
|
||||
if ($element === null || ! $this->isSelectable($element)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$program = $this->publicProgramFor($element);
|
||||
|
||||
if ($program === null && ! $includeNonPublic) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$output = self::outputLabel((string) $element->output_class);
|
||||
$editorialKind = $element->editorialContentKind?->label;
|
||||
|
||||
return new CardSubject(
|
||||
title: $this->title($element),
|
||||
summary: filled($element->summary) ? (string) $element->summary : null,
|
||||
kind: filled($editorialKind) ? (string) $editorialKind : $output,
|
||||
badge: $output,
|
||||
meta: array_values(array_filter([
|
||||
$output,
|
||||
$program !== null ? 'Im Programm „'.$program['title'].'“' : null,
|
||||
])),
|
||||
url: $program !== null ? route('public.program', $program['id']) : null,
|
||||
public: $program !== null,
|
||||
notice: $program === null
|
||||
? 'Nur in der Redaktionsvorschau sichtbar: Dieses Medium gehört zu keinem öffentlich gezeigten Programm. Medien haben noch keine eigene öffentliche Freigabe (öffentliches Profil, ADR-29).'
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
/** Bezeichnung der Ausgabeart, wie in der Redaktionsstruktur (CompositionRelease::outputLabel). */
|
||||
public static function outputLabel(string $outputClass): string
|
||||
{
|
||||
return match ($outputClass) {
|
||||
'film' => 'Film',
|
||||
'audio' => 'Hörstück',
|
||||
'bild' => 'Bild',
|
||||
'document', 'pdf' => 'Dokument',
|
||||
default => 'Text',
|
||||
};
|
||||
}
|
||||
|
||||
private function title(ContentElement $element): string
|
||||
{
|
||||
return (string) ($element->display_title ?: $element->working_title);
|
||||
}
|
||||
|
||||
private function optionLabel(ContentElement $element): string
|
||||
{
|
||||
$visibility = $this->publicProgramFor($element) !== null ? 'öffentlich über Programmseite' : 'nur Redaktionsvorschau';
|
||||
$kind = $element->editorialContentKind?->label ?: self::outputLabel((string) $element->output_class);
|
||||
|
||||
return $this->title($element).' · '.$kind.' · '.$visibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Index aller Elemente, die in der gezeigten Fassung eines öffentlichen Programms vorkommen (auch verschachtelt).
|
||||
*
|
||||
* @return array<int, array{id: int, title: string}>
|
||||
*/
|
||||
private function publicIndex(): array
|
||||
{
|
||||
if ($this->publicIndex !== null) {
|
||||
return $this->publicIndex;
|
||||
}
|
||||
|
||||
$index = [];
|
||||
|
||||
foreach ($this->catalog->publicPrograms() as $program) {
|
||||
$version = $this->catalog->shownVersion($program);
|
||||
|
||||
if ($version === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entry = ['id' => (int) $program->id, 'title' => (string) ($program->display_title ?: $program->designation)];
|
||||
|
||||
foreach ($this->elementIds($this->structure->tree($version)) as $elementId) {
|
||||
$index[$elementId] ??= $entry;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->publicIndex = $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<StructureNode> $nodes
|
||||
* @return list<int>
|
||||
*/
|
||||
private function elementIds(array $nodes): array
|
||||
{
|
||||
$ids = [];
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
if ($node->contentElementId !== null) {
|
||||
$ids[] = (int) $node->contentElementId;
|
||||
}
|
||||
|
||||
array_push($ids, ...$this->elementIds($node->children));
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user