- Medienkarten nennen öffentlich nur Titel, Art und Programmzugehörigkeit; die Kurzbeschreibung eines Elements ist heute nirgends öffentlich (offene Entscheidung, ADR-39). - PublicMaterialReader je Anfrage einmal (scoped), nicht je Karte. - Kartenbild höchstens min(70vh, 640 px), damit breite gestapelte Karten nicht übermäßig hoch werden. - Bericht mit Prüfungen, Grenzen und dem offenen Bedarf einer kaufbaren Angebotskarte. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
200 lines
7.1 KiB
PHP
200 lines
7.1 KiB
PHP
<?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, Inhaltsart und Ausgabeart, nie Kurzbeschreibung, Dateien, Lehrtexte,
|
|
* Vorschaubilder der Bibliothek oder Ausgabeadressen. Eine Karte gibt kein Medium frei.
|
|
*
|
|
* Die Kurzbeschreibung eines Elements ist heute nirgends öffentlich (die Programmseite nennt nur den Titel). Sie bleibt
|
|
* deshalb auch auf der Karte aus, bis über öffentliche Profile (ADR-29) entschieden ist (offene Entscheidung, ADR-39).
|
|
*/
|
|
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: 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;
|
|
}
|
|
}
|