Ein Dokument ist eine Komposition der Art document, ein Kapitel ein Text mit der automatischen Materialart Dokumentkapitel; die Ebene steht in der Rolle. Der Aufbaueditor bekommt den Kapitelarbeitsplatz (Übersicht, Ordnen als Block, offene Eingaben bleiben beim Wechsel erhalten, Speichern als Entwurf, Bereitstellen als Dokumentfassung). Module und Programme binden eine Fassung über den gemeinsamen Picker ein. Mitglieder lesen sie mit anklickbarem Inhaltsverzeichnis und laden ein PDF mit Inhaltsverzeichnis, Seitenzahlen, Tabellen und Bildern. Ein älterer Stand liefert die gebundene Fassung weiter. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
352 lines
14 KiB
PHP
352 lines
14 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\EditorialProfileReader;
|
|
use App\Domain\Catalog\FormattedText;
|
|
use App\Domain\Catalog\MaterialTag;
|
|
use App\Domain\Catalog\StructureNode;
|
|
use App\Domain\Media\ThumbnailRef;
|
|
use App\Domain\Media\WebsiteMedia;
|
|
|
|
/**
|
|
* Lesesicht „Medien und Materialien“ für Premium-Karten (Website-CMS-Zielarchitektur 6.2).
|
|
*
|
|
* Auswahl in der Redaktion: jedes nicht archivierte Inhaltselement mit mindestens einer nicht gesperrten Fassung, dazu
|
|
* jeder Film, der nur aus einer Website-Datei besteht (Medium ohne Inhaltsfassung, z. B. ein Teaser).
|
|
*
|
|
* Öffentliche Sichtbarkeit (Übergangsregel, solange öffentliche Fachobjektprofile nach ADR-29 fehlen):
|
|
* Ein Medium 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, und nur mit bereitgestellter Fassung. Traineranleitungen erscheinen
|
|
* nie öffentlich (vertraulich für Trainerinnen und Trainer).
|
|
*
|
|
* Ein Film nur mit Website-Datei hat weder Fassung noch Programm. Er erscheint öffentlich, sobald seine Website-Datei
|
|
* für die Website freigegeben ist (die Freigabe ist die ausdrückliche Entscheidung der Redaktion), ohne Verweis auf
|
|
* eine Programmseite und damit ohne Aktion. Ohne Freigabe bleibt er auf die Redaktionsvorschau beschränkt.
|
|
*
|
|
* Öffentlich gelesen werden Anzeigetitel (sonst Arbeitstitel), Inhaltsart und Ausgabeart sowie einer der Texte
|
|
* Teaser, Kurzbeschreibung oder ausführliche Beschreibung. Welcher Text erscheint, entscheidet die Redaktion je Karte
|
|
* (Einstellung „Text der Karte“); ohne Wahl gilt die Kurzbeschreibung, sonst der Teaser. Die ausführliche Beschreibung
|
|
* erscheint nur, wenn die Redaktion sie ausdrücklich wählt. Nie: Einsatzhinweis, Lizenzvermerk, Dateien, Lehrtexte,
|
|
* Ausgabeadressen. Das Vorschaubild der Bibliothek ist nicht für die Website freigegeben; es erscheint nur in der
|
|
* Redaktionsvorschau und kann in der Karte ausdrücklich als Website-Bild übernommen werden (FilmStill).
|
|
* Eine Karte spielt höchstens den für die Website freigegebenen Trailer ab (CardClip), bietet keinen Download und gibt kein Medium frei.
|
|
*/
|
|
class PublicMaterialReader
|
|
{
|
|
/** Inhaltsarten, die nie öffentlich auf einer Karte erscheinen: Anleitungen für Trainer und die Textabschnitte der Übungen. */
|
|
public const CONFIDENTIAL_KINDS = ['traineranleitung', 'uebungsabschnitt', 'dokumentkapitel'];
|
|
|
|
/** @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,
|
|
) {}
|
|
|
|
public function isSelectable(ContentElement $element): bool
|
|
{
|
|
return $element->archived_at === null
|
|
&& ($element->versions()->where('status', '!=', ContentVersionStatus::Gesperrt->value)->exists()
|
|
|| $this->isWebsiteOnlyFilm($element));
|
|
}
|
|
|
|
/**
|
|
* Ein Film ohne jede Inhaltsfassung, der nur die Website-Datei (`teaser/…`) hat, zum Beispiel ein Teaser. Er kann
|
|
* auf der Medienkarte gewählt werden; was daraus öffentlich wird, bestimmt allein die Freigabe der Datei.
|
|
*/
|
|
public function isWebsiteOnlyFilm(ContentElement $element): bool
|
|
{
|
|
return $element->output_class === 'film'
|
|
&& filled($element->preview_path)
|
|
&& ! $element->versions()->exists();
|
|
}
|
|
|
|
public function isReady(ContentElement $element): bool
|
|
{
|
|
if ($this->isWebsiteOnlyFilm($element)) {
|
|
return $this->isWebsiteReleased($element);
|
|
}
|
|
|
|
return $element->versions()->where('status', ContentVersionStatus::Bereit->value)->exists();
|
|
}
|
|
|
|
/** Die Website-Datei des Films ist freigegeben und wird tatsächlich ausgeliefert (WebsiteMedia). */
|
|
private function isWebsiteReleased(ContentElement $element): bool
|
|
{
|
|
return app(WebsiteMedia::class)->present($element)?->kind === 'film';
|
|
}
|
|
|
|
/**
|
|
* Ö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;
|
|
}
|
|
|
|
public function isPublic(ContentElement $element): bool
|
|
{
|
|
return $this->isSelectable($element)
|
|
&& $this->isReady($element)
|
|
&& ! in_array($element->editorialContentKind?->slug, self::CONFIDENTIAL_KINDS, true)
|
|
&& ($this->publicProgramFor($element) !== null || $this->isWebsiteOnlyFilm($element));
|
|
}
|
|
|
|
/**
|
|
* @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')
|
|
->where(fn ($selectable) => $selectable
|
|
->whereHas('versions', fn ($query) => $query->where('status', '!=', ContentVersionStatus::Gesperrt->value))
|
|
->orWhere(fn ($websiteOnly) => $websiteOnly
|
|
->where('output_class', 'film')
|
|
->whereNotNull('preview_path')
|
|
->where('preview_path', '!=', '')
|
|
->whereDoesntHave('versions')))
|
|
->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.
|
|
*
|
|
* @param array<string, mixed> $draft ungespeicherte Anzeigedaten, nur für die Redaktionsvorschau
|
|
*/
|
|
public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?CardSubject
|
|
{
|
|
$element = is_numeric($id) ? ContentElement::query()->with('editorialContentKind')->find((int) $id) : null;
|
|
|
|
if ($element === null || ! $this->isSelectable($element)) {
|
|
return null;
|
|
}
|
|
|
|
$public = $this->isPublic($element);
|
|
|
|
if (! $public && ! $includeNonPublic) {
|
|
return null;
|
|
}
|
|
|
|
$shown = clone $element;
|
|
|
|
foreach (['working_title', 'display_title', 'teaser', 'summary', 'description', 'thumbnail_path', 'thumbnail_alt'] as $field) {
|
|
if (! array_key_exists($field, $draft)) {
|
|
continue;
|
|
}
|
|
|
|
$value = $draft[$field];
|
|
$shown->setAttribute($field, is_string($value) && trim($value) === '' ? null : $value);
|
|
}
|
|
|
|
$program = $this->publicProgramFor($element);
|
|
$output = self::outputLabel((string) $shown->output_class);
|
|
$film = $shown->output_class === 'film';
|
|
$editorialKind = $element->editorialContentKind?->label;
|
|
$summary = FormattedText::plain($shown->summary) ?: null;
|
|
$profile = app(EditorialProfileReader::class)->read($shown, 'bibliothek');
|
|
|
|
if (! array_key_exists('summary', $draft) && $profile->origin('summary') === 'variante') {
|
|
$summary = $profile->value('summary');
|
|
} elseif ($summary === null && filled($shown->teaser)) {
|
|
$summary = trim((string) $shown->teaser);
|
|
}
|
|
|
|
$texts = [];
|
|
|
|
foreach (['teaser', 'summary', 'description'] as $field) {
|
|
$own = filled($shown->getAttribute($field)) ? trim(in_array($field, FormattedText::FIELDS, true) ? FormattedText::plain((string) $shown->getAttribute($field)) : (string) $shown->getAttribute($field)) : null;
|
|
$own = $own === '' ? null : $own;
|
|
|
|
if (! array_key_exists($field, $draft) && $profile->origin($field) === 'variante') {
|
|
$own = $profile->value($field);
|
|
}
|
|
|
|
$texts[$field] = $own;
|
|
}
|
|
|
|
$title = (string) ($shown->display_title ?: $shown->working_title);
|
|
|
|
if (! array_key_exists('display_title', $draft) && $profile->origin('display_title') === 'variante') {
|
|
$title = (string) $profile->value('display_title');
|
|
}
|
|
|
|
$websiteOnly = $this->isWebsiteOnlyFilm($element);
|
|
$meta = [$output];
|
|
if ($program !== null) {
|
|
$meta[] = 'Im Programm „'.$program['title'].'“';
|
|
}
|
|
if ($film && ! $websiteOnly) {
|
|
$meta[] = 'Vollständiger Film nur mit Lizenz im Mitgliederbereich';
|
|
}
|
|
|
|
$missing = [];
|
|
if ($summary === null) {
|
|
$missing[] = 'Keine Kurzbeschreibung gepflegt (Medium bearbeiten → Kurzbeschreibung).';
|
|
}
|
|
if (! filled($shown->display_title)) {
|
|
$missing[] = 'Kein Anzeigetitel gepflegt; die Karte zeigt den Arbeitstitel.';
|
|
}
|
|
|
|
$previewImage = $includeNonPublic ? ThumbnailRef::url('editorial.card', 'element', (int) $element->id, $shown->thumbnail_path) : null;
|
|
|
|
return new CardSubject(
|
|
title: $title,
|
|
summary: $summary,
|
|
kind: filled($editorialKind) ? (string) $editorialKind : $output,
|
|
badge: $output,
|
|
meta: $meta,
|
|
url: $public && $program !== null ? route('public.program', $program['id']) : null,
|
|
public: $public,
|
|
notice: $public ? null : $this->notice($element, $program),
|
|
visual: $film ? 'film' : 'material',
|
|
visualLabel: $output,
|
|
previewImage: $previewImage,
|
|
missing: $missing,
|
|
style: $film ? 'media' : 'material',
|
|
texts: $texts,
|
|
tag: MaterialTag::fromContent((string) $shown->output_class, $element->editorialContentKind?->slug)?->value,
|
|
);
|
|
}
|
|
|
|
/** 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',
|
|
};
|
|
}
|
|
|
|
public function visibilityNote(ContentElement $element): string
|
|
{
|
|
if ($this->isPublic($element)) {
|
|
$program = $this->publicProgramFor($element);
|
|
|
|
if ($program === null) {
|
|
return 'Öffentlich mit der für die Website freigegebenen Datei, ohne Verweis auf eine Programmseite. Die Originaldatei wird nie ausgeliefert.';
|
|
}
|
|
|
|
return 'Öffentlich nur als Teil der Programmseite „'.$program['title'].'“. Die Mediendatei wird dabei nicht ausgeliefert.';
|
|
}
|
|
|
|
return $this->notice($element, $this->publicProgramFor($element));
|
|
}
|
|
|
|
/**
|
|
* @param array{id: int, title: string}|null $program
|
|
*/
|
|
private function notice(ContentElement $element, ?array $program): string
|
|
{
|
|
$reason = match (true) {
|
|
in_array($element->editorialContentKind?->slug, self::CONFIDENTIAL_KINDS, true) => 'Traineranleitungen erscheinen nie öffentlich.',
|
|
$this->isWebsiteOnlyFilm($element) => 'Die Website-Datei ist nicht für die Website freigegeben (Medium öffnen → Reiter „Website“ → freigeben).',
|
|
! $this->isReady($element) => 'Das Medium hat noch keine bereitgestellte Fassung.',
|
|
$program === null => 'Das Medium gehört zu keinem öffentlich gezeigten Programm. Medien haben noch keine eigene öffentliche Freigabe (öffentliches Profil, ADR-29).',
|
|
default => 'Das Medium ist nicht öffentlich.',
|
|
};
|
|
|
|
return 'Nur in der Redaktionsvorschau sichtbar: '.$reason;
|
|
}
|
|
|
|
private function optionLabel(ContentElement $element): string
|
|
{
|
|
$visibility = match (true) {
|
|
$this->isWebsiteOnlyFilm($element) => $this->isPublic($element)
|
|
? 'öffentlich mit Website-Datei'
|
|
: 'Website-Datei nicht freigegeben, nur Redaktionsvorschau',
|
|
$this->isPublic($element) => 'öffentlich über Programmseite',
|
|
$this->isReady($element) => 'nur Redaktionsvorschau',
|
|
default => 'Entwurf, nur Redaktionsvorschau',
|
|
};
|
|
$kind = $element->editorialContentKind?->label ?: self::outputLabel((string) $element->output_class);
|
|
|
|
return (string) ($element->display_title ?: $element->working_title).' · '.$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;
|
|
}
|
|
}
|