MVP 1.2 (inkl. Shop) #3
No files matched your search
@@ -15,6 +15,8 @@
|
||||
* Redaktionsvorschau (Route editorial.card, nur für angemeldete Redaktion); öffentlich nie ausgegeben, weil es
|
||||
* keine Freigabe für die Website hat.
|
||||
* - missing: was für eine vollständige Karte fehlt, als Hinweis nur in der Redaktionsvorschau.
|
||||
* - texts: die zentralen Texte des Fachobjekts, aus denen die Karte einen wählen kann (teaser, summary, description).
|
||||
* summary bleibt der Text der Vorgabe („Automatisch“); texts wird nur gelesen, wenn die Redaktion einen wählt.
|
||||
*/
|
||||
final readonly class CardSubject
|
||||
{
|
||||
@@ -36,24 +38,39 @@ public function __construct(
|
||||
public ?string $previewImage = null,
|
||||
public array $missing = [],
|
||||
public ?string $style = null,
|
||||
public array $texts = [],
|
||||
) {}
|
||||
|
||||
public function withText(?string $title, ?string $summary): self
|
||||
{
|
||||
return new self(
|
||||
title: $title ?? $this->title,
|
||||
summary: $summary ?? $this->summary,
|
||||
kind: $this->kind,
|
||||
badge: $this->badge,
|
||||
meta: $this->meta,
|
||||
url: $this->url,
|
||||
public: $this->public,
|
||||
notice: $this->notice,
|
||||
visual: $this->visual,
|
||||
visualLabel: $this->visualLabel,
|
||||
previewImage: $this->previewImage,
|
||||
missing: $this->missing,
|
||||
style: $this->style,
|
||||
);
|
||||
return $this->copy(['title' => $title ?? $this->title, 'summary' => $summary ?? $this->summary]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Text der Karte aus einem zentralen Text des Fachobjekts. Ist er nicht gepflegt, bleibt die Karte ohne Text
|
||||
* (kein stiller Ersatz aus einem anderen Feld); in der Redaktionsvorschau steht dann ein Hinweis.
|
||||
*/
|
||||
public function withTextChoice(string $field, string $missingHint): self
|
||||
{
|
||||
if (! array_key_exists($field, $this->texts)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$text = $this->texts[$field];
|
||||
$missing = array_values(array_filter($this->missing, fn (string $hint): bool => ! str_contains($hint, 'Kurzbeschreibung')));
|
||||
|
||||
if ($text === null) {
|
||||
$missing[] = $missingHint;
|
||||
}
|
||||
|
||||
return $this->copy(['summary' => $text, 'missing' => $missing]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $changes
|
||||
*/
|
||||
private function copy(array $changes): self
|
||||
{
|
||||
return new self(...array_merge(get_object_vars($this), $changes));
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,12 @@
|
||||
* öffentlich, mit Verweis auf diese Programmseite, und nur mit bereitgestellter Fassung. Traineranleitungen erscheinen
|
||||
* nie öffentlich (vertraulich für Trainerinnen und Trainer).
|
||||
*
|
||||
* Öffentlich gelesen werden Anzeigetitel (sonst Arbeitstitel), Kurzbeschreibung, Inhaltsart und Ausgabeart. Nie:
|
||||
* Beschreibung, Einsatzhinweis, Lizenzvermerk, Dateien, Lehrtexte, Ausgabeadressen. Das Vorschaubild (Filmstandbild)
|
||||
* der Bibliothek ist nicht für die Website freigegeben; es erscheint nur in der Redaktionsvorschau.
|
||||
* Ö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 nichts ab, bietet keinen Download und gibt kein Medium frei.
|
||||
*/
|
||||
class PublicMaterialReader
|
||||
@@ -124,7 +127,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
|
||||
|
||||
$shown = clone $element;
|
||||
|
||||
foreach (['working_title', 'display_title', 'summary', 'thumbnail_path', 'thumbnail_alt'] as $field) {
|
||||
foreach (['working_title', 'display_title', 'teaser', 'summary', 'description', 'thumbnail_path', 'thumbnail_alt'] as $field) {
|
||||
if (! array_key_exists($field, $draft)) {
|
||||
continue;
|
||||
}
|
||||
@@ -146,6 +149,18 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
|
||||
$summary = trim((string) $shown->teaser);
|
||||
}
|
||||
|
||||
$texts = [];
|
||||
|
||||
foreach (['teaser', 'summary', 'description'] as $field) {
|
||||
$own = filled($shown->getAttribute($field)) ? trim((string) $shown->getAttribute($field)) : null;
|
||||
|
||||
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') {
|
||||
@@ -184,6 +199,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
|
||||
previewImage: $previewImage,
|
||||
missing: $missing,
|
||||
style: $film ? 'media' : 'material',
|
||||
texts: $texts,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
use App\Domain\Cms\Catalog\CardSubject;
|
||||
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Media\FilmStill;
|
||||
use Filament\Forms\Components\ViewField;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
|
||||
/**
|
||||
* Medien- und Materialkarte (Kit v1.7 „media“): ein Inhaltselement mit Anzeigetitel, Kurzbeschreibung, Inhaltsart und
|
||||
@@ -53,7 +56,7 @@ protected function refLabel(): string
|
||||
|
||||
protected function refHelp(): string
|
||||
{
|
||||
return 'Wählbar sind alle nicht archivierten, nicht gesperrten Filme und Materialien. Öffentlich erscheint die Karte nur mit bereitgestellter Fassung und wenn der Inhalt zu einem öffentlich gezeigten Programm gehört; Traineranleitungen nie. Titel und Kurzbeschreibung pflegen Sie im Medium.';
|
||||
return 'Wählbar sind alle nicht archivierten, nicht gesperrten Filme und Materialien. Öffentlich erscheint die Karte nur mit bereitgestellter Fassung und wenn der Inhalt zu einem öffentlich gezeigten Programm gehört; Traineranleitungen nie. Titel, Teaser, Kurzbeschreibung und Beschreibung pflegen Sie im Medium; welcher Text auf der Karte erscheint, wählen Sie unter „Darstellung“.';
|
||||
}
|
||||
|
||||
protected function searchSubjects(?string $term): array
|
||||
@@ -90,6 +93,51 @@ protected function cardStyle(): string
|
||||
return 'media';
|
||||
}
|
||||
|
||||
/**
|
||||
* Bei einem Film: das Vorschaubild des Films oder eine Stelle des Films als Kartenbild übernehmen. Das Bild wird
|
||||
* einmal als Bild-Medium abgelegt (FilmStill) und wie jedes andere Bild ausgewählt; die Karte liest nur diese Datei.
|
||||
*/
|
||||
protected function imageSourceFields(): array
|
||||
{
|
||||
return [
|
||||
ViewField::make('_filmbild')
|
||||
->label('Bild aus dem Film')
|
||||
->view('filament.cms.filmbild-feld')
|
||||
->dehydrated(false)
|
||||
->visible(fn (Get $get): bool => $this->filmFor($get('element')) !== null)
|
||||
->viewData(function (Get $get): array {
|
||||
$film = $this->filmFor($get('element'));
|
||||
$stills = app(FilmStill::class);
|
||||
$version = $film instanceof ContentElement ? $stills->version($film) : null;
|
||||
|
||||
return [
|
||||
'film' => $film,
|
||||
'filmTitle' => $film instanceof ContentElement ? (string) ($film->display_title ?: $film->working_title) : '',
|
||||
'filmVersionId' => $version?->id,
|
||||
'filmHasThumbnail' => $film instanceof ContentElement && is_string($film->thumbnail_path) && $film->thumbnail_path !== '',
|
||||
'filmStartSecond' => $film instanceof ContentElement ? ($stills->thumbnailSecond($film) ?? '0') : '0',
|
||||
];
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
private function filmFor(mixed $id): ?ContentElement
|
||||
{
|
||||
$element = is_numeric($id) ? ContentElement::query()->with('editorialContentKind')->find((int) $id) : null;
|
||||
|
||||
return $element instanceof ContentElement && app(FilmStill::class)->refusal($element) === null ? $element : null;
|
||||
}
|
||||
|
||||
protected function textChoices(): array
|
||||
{
|
||||
return [
|
||||
'auto' => 'Automatisch (Kurzbeschreibung, sonst Teaser)',
|
||||
'teaser' => 'Teaser',
|
||||
'summary' => 'Kurzbeschreibung',
|
||||
'description' => 'Ausführliche Beschreibung (erscheint öffentlich)',
|
||||
];
|
||||
}
|
||||
|
||||
protected function centralCoverId(mixed $id): ?int
|
||||
{
|
||||
$element = is_numeric($id) ? ContentElement::query()->find((int) $id) : null;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||
use App\Domain\Cms\Widgets\WidgetType;
|
||||
use Filament\Forms\Components\Field;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Group;
|
||||
@@ -32,6 +33,13 @@ abstract class PremiumCardWidget extends WidgetType
|
||||
{
|
||||
public const SHOW = ['yes' => 'Anzeigen', 'no' => 'Ausblenden'];
|
||||
|
||||
/** Hinweise der Redaktionsvorschau, wenn der gewählte zentrale Text nicht gepflegt ist. */
|
||||
public const TEXT_MISSING = [
|
||||
'teaser' => 'Kein Teaser gepflegt (Medium bearbeiten → Teaser).',
|
||||
'summary' => 'Keine Kurzbeschreibung gepflegt (Medium bearbeiten → Kurzbeschreibung).',
|
||||
'description' => 'Keine ausführliche Beschreibung gepflegt (Medium bearbeiten → Beschreibung).',
|
||||
];
|
||||
|
||||
/** Schlüssel des Fachobjekts in refs, zum Beispiel 'pillar'. */
|
||||
abstract protected function refKey(): string;
|
||||
|
||||
@@ -56,6 +64,27 @@ abstract protected function defaultActionLabel(): string;
|
||||
/** Gestaltungsvariante des Kits: editorial, media oder catalog. */
|
||||
abstract protected function cardStyle(): string;
|
||||
|
||||
/**
|
||||
* Weitere Wege zum Kartenbild im Reiter „Medien“, zum Beispiel ein Bild aus dem Film. Standard: keine.
|
||||
*
|
||||
* @return list<Field>
|
||||
*/
|
||||
protected function imageSourceFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Zentrale Texte des Fachobjekts, aus denen die Redaktion den Kartentext wählen kann: Wert => Bezeichnung.
|
||||
* Leer: keine Wahl (die Karte nimmt den Text ihrer Vorgabe). Mit Wahl gilt „auto“ als Vorgabe.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function textChoices(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function view(): string
|
||||
{
|
||||
return 'widgets.premium_card';
|
||||
@@ -110,7 +139,9 @@ public function optionIcons(): array
|
||||
|
||||
public function settings(): array
|
||||
{
|
||||
return [
|
||||
$choices = $this->textChoices();
|
||||
|
||||
return ($choices === [] ? [] : ['text_source' => $choices]) + [
|
||||
'format' => ['landscape' => 'Querformat 16:9', 'square' => 'Quadrat 1:1', 'portrait' => 'Hochformat 3:4'],
|
||||
'fit' => ['cover' => 'Ausschnitt füllt die Fläche', 'contain' => 'Ganzes Bild zeigen (Dokument, Poster)'],
|
||||
'heading_level' => ['h3' => 'H3', 'h2' => 'H2', 'h4' => 'H4'],
|
||||
@@ -124,10 +155,11 @@ public function settings(): array
|
||||
public function settingLabels(): array
|
||||
{
|
||||
return [
|
||||
'text_source' => ['Text der Karte', 'Welche Angabe aus der Redaktion die Karte zeigt. Vorgabe: Automatisch. Der gewählte Text erscheint öffentlich, wenn die Karte öffentlich ist; ist er nicht gepflegt, bleibt die Karte ohne Text.'],
|
||||
'format' => ['Bildformat', 'Vorgabe: Querformat 16:9. Gilt auch neben dem Text; das Motiv wird nicht nachträglich hochkant beschnitten.'],
|
||||
'fit' => ['Bilddarstellung', 'Vorgabe: Ausschnitt. „Ganzes Bild“ zeigt Dokumente und Poster vollständig auf ruhiger Fläche.'],
|
||||
'heading_level' => ['Überschriftenebene', 'Vorgabe: H3, passend unter einer Abschnittsüberschrift (H2).'],
|
||||
'show_summary' => ['Kurzbeschreibung', 'Aus den Fachdaten. Vorgabe: anzeigen.'],
|
||||
'show_summary' => ['Text anzeigen', 'Aus den Fachdaten. Vorgabe: anzeigen.'],
|
||||
'show_kind' => ['Art oder Label', 'Zum Beispiel „Thema“ oder „Merkblatt“. Vorgabe: anzeigen.'],
|
||||
'show_meta' => ['Zusatzangaben', 'Aus den Fachdaten, zum Beispiel Ausgabeart oder Programmzugehörigkeit. Vorgabe: anzeigen.'],
|
||||
'show_action' => ['Aktion', 'Verweis auf die öffentliche Seite des Fachobjekts, falls es eine gibt. Vorgabe: anzeigen.'],
|
||||
@@ -195,13 +227,13 @@ public function editorSchema(): array
|
||||
->hintColor(fn (?string $state): string => filled($state) ? 'warning' : 'gray')
|
||||
->helperText('Leer übernimmt den Anzeigenamen des Fachobjekts. Eine Eintragung gilt nur für diese Karte und ändert die Quelle nicht.'),
|
||||
TextInput::make('summary')
|
||||
->label('Teaser nur für diese Karte')
|
||||
->label('Text nur für diese Karte')
|
||||
->maxLength(500)
|
||||
->live(onBlur: true)
|
||||
->placeholder(fn (Get $get): string => $this->centralText($get('../refs.'.$this->refKey()), 'summary') ?? 'Zentraler Teaser oder Kurzbeschreibung')
|
||||
->placeholder(fn (Get $get): string => $this->centralText($get('../refs.'.$this->refKey()), 'summary', $get('../settings.text_source')) ?? 'Zentraler Text aus der Redaktion')
|
||||
->hint(fn (?string $state): string => filled($state) ? 'Eigene Angabe für diese Karte' : 'Aus der Redaktion')
|
||||
->hintColor(fn (?string $state): string => filled($state) ? 'warning' : 'gray')
|
||||
->helperText('Leer übernimmt Teaser oder Kurzbeschreibung. Lehrinhalt, Rechte und Preise bleiben unberührt.'),
|
||||
->helperText('Leer übernimmt den Text, den „Text der Karte“ (Darstellung) wählt. Lehrinhalt, Rechte und Preise bleiben unberührt.'),
|
||||
])->statePath('data'),
|
||||
];
|
||||
}
|
||||
@@ -211,7 +243,7 @@ public function mediaSchema(): array
|
||||
[, , $alt, $focusX, $focusY] = $this->dataFields();
|
||||
|
||||
return [
|
||||
Group::make(ImageRefFields::fields('Kartenbild', live: true))->statePath('refs'),
|
||||
Group::make([...ImageRefFields::fields('Kartenbild', live: true), ...$this->imageSourceFields()])->statePath('refs'),
|
||||
Group::make([$alt, $focusX, $focusY])->statePath('data'),
|
||||
];
|
||||
}
|
||||
@@ -248,6 +280,12 @@ public function resolve(array $widget, RenderContext $context): array
|
||||
$data = $widget['data'];
|
||||
|
||||
$subject = $this->subject($widget['refs'][$this->refKey()] ?? null, $context);
|
||||
$textSource = $option('text_source', 'auto');
|
||||
|
||||
if ($subject instanceof CardSubject && $textSource !== 'auto' && isset($this->textChoices()[$textSource])) {
|
||||
$subject = $subject->withTextChoice($textSource, self::TEXT_MISSING[$textSource] ?? '');
|
||||
}
|
||||
|
||||
$heading = filled($data['heading'] ?? null) ? trim((string) $data['heading']) : null;
|
||||
$lead = filled($data['summary'] ?? null) ? trim((string) $data['summary']) : null;
|
||||
|
||||
@@ -302,7 +340,7 @@ protected function centralCoverId(mixed $id): ?int
|
||||
/**
|
||||
* Zentraler Anzeigename oder Teaser des gewählten Objekts (Redaktionsstand) für Platzhalter im Editor.
|
||||
*/
|
||||
private function centralText(mixed $id, string $field): ?string
|
||||
private function centralText(mixed $id, string $field, mixed $textSource = null): ?string
|
||||
{
|
||||
if (blank($id)) {
|
||||
return null;
|
||||
@@ -314,6 +352,10 @@ private function centralText(mixed $id, string $field): ?string
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($subject instanceof CardSubject && is_string($textSource) && isset($this->textChoices()[$textSource]) && $textSource !== 'auto') {
|
||||
$subject = $subject->withTextChoice($textSource, self::TEXT_MISSING[$textSource] ?? '');
|
||||
}
|
||||
|
||||
$text = $subject?->{$field};
|
||||
|
||||
return is_string($text) && trim($text) !== '' ? Str::limit(trim($text), 120) : null;
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Legt ein Bild aus einem Film als gewöhnliches Bild-Medium im Medienmanager ab (Medien- und Materialkarte).
|
||||
*
|
||||
* - Zwei Wege: das Vorschaubild des Films übernehmen oder eine Stelle (Sekunde) wählen. Beides ist eine
|
||||
* ausdrückliche Handlung der Redaktion; erst dadurch entsteht ein Bild, das für die Website freigegeben werden kann.
|
||||
* - Das Bild wird einmal gezogen und gespeichert (WebsiteIntake legt es an, die Warteschlange leitet es ab und gibt
|
||||
* es frei). Seitenaufrufe lesen nur die gespeicherte Datei und starten nie ffmpeg.
|
||||
* - Dieselbe Stelle (oder dieselbe Vorschaudatei) ergibt dasselbe Medium (film_still_sources).
|
||||
* - Es wird nie der Film selbst, nur ein Einzelbild bis 1600 px Breite abgelegt. Traineranleitungen und
|
||||
* archivierte oder gesperrte Filme sind ausgeschlossen. Eine Rechte- oder Lizenzentscheidung entsteht nicht.
|
||||
*/
|
||||
class FilmStill
|
||||
{
|
||||
/** Breite eines übernommenen Standbilds; die kleine Filmstufe (640 px) wäre auf der Website sichtbar unscharf. */
|
||||
public const WIDTH = 1600;
|
||||
|
||||
public function __construct(
|
||||
private readonly ThumbnailDeriver $deriver,
|
||||
private readonly WebsiteIntake $intake,
|
||||
) {}
|
||||
|
||||
/** Grund, warum aus diesem Medium kein Standbild übernommen wird, sonst null. */
|
||||
public function refusal(ContentElement $film): ?string
|
||||
{
|
||||
if ($film->output_class !== 'film') {
|
||||
return 'Nur aus einem Film lässt sich ein Bild übernehmen.';
|
||||
}
|
||||
|
||||
if ($film->archived_at !== null) {
|
||||
return 'Der Film ist archiviert.';
|
||||
}
|
||||
|
||||
$slug = $film->editorialContentKind?->slug;
|
||||
|
||||
if (in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true)) {
|
||||
return 'Aus Traineranleitungen werden keine Bilder für die Website übernommen.';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Die bereitgestellte Fassung, aus der Stellen gezogen werden (die höchste). */
|
||||
public function version(ContentElement $film): ?ContentElementVersion
|
||||
{
|
||||
return $film->versions()
|
||||
->where('status', ContentVersionStatus::Bereit->value)
|
||||
->orderByDesc('number')
|
||||
->first();
|
||||
}
|
||||
|
||||
/** Sekunde der Stelle, aus der das aktuelle Vorschaubild des Films stammt, sonst null. */
|
||||
public function thumbnailSecond(ContentElement $film): ?string
|
||||
{
|
||||
$source = $film->thumbnail_source;
|
||||
|
||||
return is_string($source) && preg_match('/^frame:\d+@([\d.]+)$/', $source, $match) === 1 ? $match[1] : null;
|
||||
}
|
||||
|
||||
public function fromSecond(ContentElement $film, float $seconds, ?User $actor = null): ContentElement
|
||||
{
|
||||
$this->guard($film);
|
||||
|
||||
if ($seconds < 0 || $seconds > 7200) {
|
||||
throw new DomainRuleException('Die Zeitposition liegt außerhalb des Films.');
|
||||
}
|
||||
|
||||
$version = $this->version($film);
|
||||
|
||||
if (! $version instanceof ContentElementVersion) {
|
||||
throw new DomainRuleException('Der Film hat noch keine bereitgestellte Fassung.');
|
||||
}
|
||||
|
||||
return $this->fromFrame($film, $version, $seconds, $actor);
|
||||
}
|
||||
|
||||
public function fromThumbnail(ContentElement $film, ?User $actor = null): ContentElement
|
||||
{
|
||||
$this->guard($film);
|
||||
|
||||
// Stammt das Vorschaubild aus einer Filmstelle, wird dieselbe Stelle in voller Auflösung gezogen.
|
||||
$second = $this->thumbnailSecond($film);
|
||||
|
||||
if ($second !== null && preg_match('/^frame:(\d+)@/', (string) $film->thumbnail_source, $match) === 1) {
|
||||
$version = ContentElementVersion::query()->find((int) $match[1]);
|
||||
|
||||
if ($version instanceof ContentElementVersion
|
||||
&& (int) $version->content_element_id === (int) $film->id
|
||||
&& $version->status !== ContentVersionStatus::Gesperrt) {
|
||||
try {
|
||||
return $this->fromFrame($film, $version, (float) $second, $actor);
|
||||
} catch (DomainRuleException) {
|
||||
// Die Stelle lässt sich nicht mehr ziehen: das gespeicherte Vorschaubild selbst übernehmen.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$path = $film->thumbnail_path;
|
||||
|
||||
if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..') || ! Storage::disk('media_derived')->exists($path)) {
|
||||
throw new DomainRuleException('Dieser Film hat noch kein Vorschaubild. Setzen Sie es im Medienmanager oder wählen Sie eine Stelle.');
|
||||
}
|
||||
|
||||
$bytes = Storage::disk('media_derived')->get($path);
|
||||
|
||||
if (! is_string($bytes) || $bytes === '') {
|
||||
throw new DomainRuleException('Das Vorschaubild ließ sich nicht lesen.');
|
||||
}
|
||||
|
||||
$key = 'file:'.hash('sha256', $bytes);
|
||||
|
||||
return $this->existing($film, $key) ?? $this->store($film, $key, $bytes, 'Vorschaubild', $actor);
|
||||
}
|
||||
|
||||
private function fromFrame(ContentElement $film, ContentElementVersion $version, float $seconds, ?User $actor): ContentElement
|
||||
{
|
||||
$second = $this->secondText($seconds);
|
||||
$key = 'frame:'.$version->id.'@'.$second;
|
||||
$existing = $this->existing($film, $key);
|
||||
|
||||
if ($existing instanceof ContentElement) {
|
||||
return $existing;
|
||||
}
|
||||
|
||||
$bytes = $this->deriver->frameJpeg($version, (float) $second, self::WIDTH, original: true);
|
||||
|
||||
if (! is_string($bytes)) {
|
||||
throw new DomainRuleException('Aus dieser Filmstelle ließ sich kein Bild erzeugen.');
|
||||
}
|
||||
|
||||
return $this->store($film, $key, $bytes, 'Fassung '.$version->number.', '.str_replace('.', ',', $second).' s', $actor);
|
||||
}
|
||||
|
||||
private function guard(ContentElement $film): void
|
||||
{
|
||||
$refusal = $this->refusal($film);
|
||||
|
||||
if ($refusal !== null) {
|
||||
throw new DomainRuleException($refusal);
|
||||
}
|
||||
}
|
||||
|
||||
private function existing(ContentElement $film, string $key): ?ContentElement
|
||||
{
|
||||
$source = FilmStillSource::query()->with('still')->where('film_element_id', $film->id)->where('source_key', $key)->first();
|
||||
$still = $source?->still;
|
||||
|
||||
return $still instanceof ContentElement && $still->archived_at === null ? $still : null;
|
||||
}
|
||||
|
||||
private function store(ContentElement $film, string $key, string $bytes, string $label, ?User $actor): ContentElement
|
||||
{
|
||||
$title = (string) ($film->display_title ?: $film->working_title);
|
||||
$path = 'cms/standbild-'.$film->id.'-'.Str::lower(Str::random(8)).'.jpg';
|
||||
Storage::disk('cms_incoming')->put($path, $bytes);
|
||||
|
||||
$still = $this->intake->acceptImage(
|
||||
$path,
|
||||
'Standbild: '.$title.' ('.$label.')',
|
||||
filled($film->website_credit) ? (string) $film->website_credit : null,
|
||||
'Szene aus dem Film „'.$title.'“',
|
||||
$actor,
|
||||
);
|
||||
|
||||
try {
|
||||
FilmStillSource::query()->create([
|
||||
'film_element_id' => $film->id,
|
||||
'still_element_id' => $still->id,
|
||||
'source_key' => $key,
|
||||
'actor_id' => $actor?->id,
|
||||
]);
|
||||
} catch (QueryException) {
|
||||
// Gleichzeitige Übernahme derselben Stelle: das zuerst angelegte Bild gilt.
|
||||
return $this->existing($film, $key) ?? $still;
|
||||
}
|
||||
|
||||
return $still;
|
||||
}
|
||||
|
||||
private function secondText(float $seconds): string
|
||||
{
|
||||
$text = number_format(max(0, min(7200, $seconds)), 3, '.', '');
|
||||
|
||||
return rtrim(rtrim($text, '0'), '.') ?: '0';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* Herkunft eines Standbilds: aus welchem Film und welcher Stelle (frame:{Fassung}@{Sekunde}) oder aus welcher Datei
|
||||
* (file:{SHA-256}) das Bild-Medium stammt.
|
||||
*/
|
||||
class FilmStillSource extends Model
|
||||
{
|
||||
protected $fillable = ['film_element_id', 'still_element_id', 'source_key', 'actor_id'];
|
||||
|
||||
public function film(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ContentElement::class, 'film_element_id');
|
||||
}
|
||||
|
||||
public function still(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ContentElement::class, 'still_element_id');
|
||||
}
|
||||
}
|
||||
@@ -138,8 +138,20 @@ public function forCompositionFrame(Composition $composition, ContentElementVers
|
||||
$this->rememberChoice($composition, 'frame:'.$version->id.'@'.$this->secondText($seconds));
|
||||
}
|
||||
|
||||
public function frameInput(ContentElementVersion $version): ?string
|
||||
/**
|
||||
* Datei, aus der ein Bild gezogen wird. Vorgabe: die kleine Filmstufe (schnell, für die Vorschau). Mit $original
|
||||
* zuerst die Mediendatei selbst, damit ein übernommenes Standbild nicht aus der kleinen Stufe hochgerechnet wird.
|
||||
*/
|
||||
public function frameInput(ContentElementVersion $version, bool $original = false): ?string
|
||||
{
|
||||
if ($original) {
|
||||
$master = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
|
||||
|
||||
if ($this->readableDerived($master, 'inhalte/')) {
|
||||
return $master;
|
||||
}
|
||||
}
|
||||
|
||||
$proxy = MediaRendition::query()
|
||||
->where('content_element_version_id', $version->id)
|
||||
->where('role', 'variant')
|
||||
@@ -155,13 +167,25 @@ public function frameInput(ContentElementVersion $version): ?string
|
||||
return $this->readableDerived($file, 'inhalte/') ? $file : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Einzelbild einer Filmstelle als JPEG, 640 px breit aus der kleinen Stufe (Vorschau im Editor und Vorschaubild).
|
||||
*/
|
||||
public function jpegAtVersion(ContentElementVersion $version, float $seconds): ?string
|
||||
{
|
||||
return $this->frameJpeg($version, $seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Einzelbild einer Filmstelle als JPEG. Ein übernommenes Standbild (FilmStill) wird mit $width und $original aus der
|
||||
* Mediendatei gezogen statt aus der kleinen Stufe und dabei nie über die Breite der Quelle hinaus vergrößert.
|
||||
*/
|
||||
public function frameJpeg(ContentElementVersion $version, float $seconds, int $width = 640, bool $original = false): ?string
|
||||
{
|
||||
if ($seconds < 0 || $seconds > 7200) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$file = $this->frameInput($version);
|
||||
$file = $this->frameInput($version, $original);
|
||||
|
||||
if ($file === null) {
|
||||
return null;
|
||||
@@ -186,7 +210,7 @@ public function jpegAtVersion(ContentElementVersion $version, float $seconds): ?
|
||||
'-frames:v',
|
||||
'1',
|
||||
'-vf',
|
||||
'scale=640:-2',
|
||||
$width === 640 ? 'scale=640:-2' : 'scale=min('.max(160, min(2400, $width)).'\,iw):-2',
|
||||
'-f',
|
||||
'image2pipe',
|
||||
'-vcodec',
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||
use App\Domain\Media\FilmStill;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
/**
|
||||
@@ -31,6 +34,62 @@ public function openWebsiteImagePicker(string $pfad): void
|
||||
$this->forceRenderForPicker();
|
||||
}
|
||||
|
||||
/**
|
||||
* Medien- und Materialkarte: das Vorschaubild des Films als Bild für die Website übernehmen. Es entsteht ein Bild
|
||||
* im Medienmanager (einmal gespeichert), das im Bildfeld ausgewählt wird. Die Datei des Films bleibt geschützt.
|
||||
*/
|
||||
public function adoptFilmThumbnail(string $pfad, int $elementId): void
|
||||
{
|
||||
$this->adoptFilmStill($pfad, $elementId, fn (FilmStill $stills, ContentElement $film): ContentElement => $stills->fromThumbnail($film, auth('staff')->user()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Medien- und Materialkarte: eine Stelle des Films wählen und als Bild für die Website übernehmen.
|
||||
*/
|
||||
public function adoptFilmFrame(string $pfad, int $elementId, string $sekunde): void
|
||||
{
|
||||
if (! is_numeric($sekunde)) {
|
||||
Notification::make()->danger()->title('Bitte eine Zeitposition in Sekunden angeben.')->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->adoptFilmStill($pfad, $elementId, fn (FilmStill $stills, ContentElement $film): ContentElement => $stills->fromSecond($film, (float) $sekunde, auth('staff')->user()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(FilmStill, ContentElement): ContentElement $make
|
||||
*/
|
||||
private function adoptFilmStill(string $pfad, int $elementId, callable $make): void
|
||||
{
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
|
||||
if (preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+\.image$/', $pfad) !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$film = ContentElement::query()->with('editorialContentKind')->find($elementId);
|
||||
|
||||
if (! $film instanceof ContentElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$still = $make(app(FilmStill::class), $film);
|
||||
} catch (DomainRuleException $exception) {
|
||||
Notification::make()->danger()->title($exception->getMessage())->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
data_set($this, $pfad, $still->id);
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Im Medienmanager angelegt: „'.($still->display_title ?: $still->working_title).'“')
|
||||
->body('Das Bild ist als Kartenbild ausgewählt. Nach der Verarbeitung wird es für die Website freigegeben; dort lässt sich die Freigabe auch zurücknehmen.')
|
||||
->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filament rendert bei offenen Aktionsdialogen nur den Dialogteil neu; der Picker liegt darüber und braucht die
|
||||
* ganze Seite.
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Herkunft der Standbilder, die aus einem Film als Bild-Medium übernommen wurden (Medien- und Materialkarte).
|
||||
* Additiv. Sie verhindert, dass dieselbe Filmstelle mehrfach als neues Medium entsteht, und hält fest, woher das
|
||||
* Bild kommt. Das Standbild selbst ist ein gewöhnliches Medium (output_class bild) mit eigener Website-Freigabe.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('film_still_sources', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('film_element_id')->constrained('content_elements')->restrictOnDelete();
|
||||
$table->foreignId('still_element_id')->constrained('content_elements')->restrictOnDelete();
|
||||
$table->string('source_key', 120);
|
||||
$table->unsignedBigInteger('actor_id')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['film_element_id', 'source_key']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('film_still_sources');
|
||||
}
|
||||
};
|
||||
@@ -120,6 +120,7 @@ .lf-pc .lf-pc__title {
|
||||
}
|
||||
|
||||
.lf-pc__summary {
|
||||
white-space: pre-line;
|
||||
margin: 0;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
{{--
|
||||
Medien- und Materialkarte, Reiter „Medien“: ein Bild aus dem Film als Kartenbild übernehmen.
|
||||
- „Vorschaubild des Films übernehmen“ und „Dieses Bild übernehmen“ legen das Bild einmal als Bild-Medium im
|
||||
Medienmanager ab (FilmStill) und wählen es im Bildfeld aus. Seitenaufrufe lesen nur diese Datei.
|
||||
- Die Vorschau der gewählten Stelle zieht ein Bild über die Redaktionsroute editorial.frame (nur angemeldete
|
||||
Redaktion) und startet erst nach „Anzeigen“, nicht bei jeder Eingabe.
|
||||
Die Datei des Films bleibt geschützt; übernommen wird nur ein Einzelbild bis 1600 px Breite.
|
||||
--}}
|
||||
@php
|
||||
$pfad = $getStatePath();
|
||||
$ziel = preg_replace('/[^.]+$/', 'image', $pfad);
|
||||
$framePfad = $filmVersionId !== null ? route('editorial.frame', ['version' => $filmVersionId]) : null;
|
||||
@endphp
|
||||
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
|
||||
<div class="luf-filmbild" x-data="{ second: @js((string) $filmStartSecond), shown: null, base: @js($framePfad) }">
|
||||
<p class="luf-filmbild-lead">
|
||||
Aus dem Film „{{ $filmTitle }}“ ein Bild für die Website übernehmen. Das Bild wird einmal gespeichert und im
|
||||
Medienmanager als Bild angelegt. Der Film selbst wird nicht veröffentlicht; die Karte spielt nichts ab.
|
||||
</p>
|
||||
@if ($filmHasThumbnail)
|
||||
<x-filament::button color="gray" size="sm" icon="heroicon-o-photo" wire:loading.attr="disabled"
|
||||
wire:click="adoptFilmThumbnail({{ \Illuminate\Support\Js::from($ziel) }}, {{ (int) $film->id }})">
|
||||
Vorschaubild des Films übernehmen
|
||||
</x-filament::button>
|
||||
@endif
|
||||
@if ($framePfad !== null)
|
||||
<div class="luf-filmbild-frame">
|
||||
<label class="luf-filmbild-label">
|
||||
Zeitposition in Sekunden
|
||||
<input type="number" min="0" max="7200" step="0.5" x-model.lazy="second" class="luf-filmbild-second">
|
||||
</label>
|
||||
<x-filament::button color="gray" size="sm" icon="heroicon-o-eye" type="button" x-on:click="shown = second">
|
||||
Anzeigen
|
||||
</x-filament::button>
|
||||
<template x-if="shown !== null">
|
||||
<div class="luf-filmbild-preview">
|
||||
<img :src="base + '?sekunde=' + encodeURIComponent(shown)" alt="Vorschau der gewählten Filmstelle">
|
||||
<x-filament::button color="primary" size="sm" icon="heroicon-o-check-circle" type="button" wire:loading.attr="disabled"
|
||||
x-on:click="$wire.adoptFilmFrame({{ \Illuminate\Support\Js::from($ziel) }}, {{ (int) $film->id }}, String(shown))">
|
||||
Dieses Bild übernehmen
|
||||
</x-filament::button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
@else
|
||||
<p class="luf-filmbild-lead">Der Film hat noch keine bereitgestellte Fassung; eine Stelle lässt sich erst danach wählen.</p>
|
||||
@endif
|
||||
</div>
|
||||
</x-dynamic-component>
|
||||
@@ -86,6 +86,14 @@
|
||||
.luf-media-badge-warn { background: #fff1c7; color: #6b4b00; }
|
||||
.luf-media-badge-wait { background: #e5eef8; color: #18456f; }
|
||||
.luf-media-badge-quiet { background: #eceff1; color: #3e4c5c; }
|
||||
/* Medien- und Materialkarte: Bild aus dem Film übernehmen. */
|
||||
.luf-filmbild { display: flex; flex-direction: column; gap: .75rem; padding: .75rem; border: 1px solid #d5ddd6; border-radius: .5rem; }
|
||||
.luf-filmbild-lead { margin: 0; font-size: .875rem; }
|
||||
.luf-filmbild-frame { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem; }
|
||||
.luf-filmbild-label { display: flex; flex-direction: column; gap: .25rem; font-size: .875rem; }
|
||||
.luf-filmbild-second { width: 8rem; padding: .35rem .5rem; border: 1px solid #b9c4bd; border-radius: .375rem; }
|
||||
.luf-filmbild-preview { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; width: 100%; }
|
||||
.luf-filmbild-preview img { width: 100%; max-width: 28rem; height: auto; border-radius: .375rem; background: #eef1ee; }
|
||||
.luf-media-status { display: flex; gap: 1rem; align-items: flex-start; padding: .75rem; border: 1px solid #d5ddd6; border-radius: .5rem; }
|
||||
.luf-media-status img { width: 10rem; height: auto; border-radius: .375rem; }
|
||||
.luf-media-status strong { display: block; }
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
$panelName = ['catalog' => 'die Navy-Tafel', 'film' => 'die Filmtafel', 'material' => 'das Materialsymbol'][$subject->visual] ?? 'die Karte ohne Bild';
|
||||
if ($context->preview && $imageUrl === null) {
|
||||
$hints[] = $subject->previewImage !== null
|
||||
? 'Das Vorschaubild der Bibliothek ist nicht für die Website freigegeben; öffentlich erscheint stattdessen '.$panelName.'. Ein freigegebenes Motiv kann im Reiter „Medien“ als Kartenbild gewählt werden.'
|
||||
? 'Das Vorschaubild der Bibliothek ist nicht für die Website freigegeben; öffentlich erscheint stattdessen '.$panelName.'. Ein freigegebenes Motiv kann im Reiter „Medien“ als Kartenbild gewählt werden'.($subject->visual === 'film' ? '; bei einem Film genügt „Vorschaubild des Films übernehmen“.' : '.')
|
||||
: 'Kein Kartenbild gewählt; öffentlich erscheint '.$panelName.' (Kartenbild im Reiter „Medien“).';
|
||||
}
|
||||
@endphp
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageRevision;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\Support\BuildsCatalog;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Medien- und Materialkarte: Die Redaktion wählt, welcher zentrale Text (Teaser, Kurzbeschreibung, ausführliche
|
||||
* Beschreibung) auf der Karte erscheint. Ohne Wahl gilt wie bisher die Kurzbeschreibung, sonst der Teaser.
|
||||
*/
|
||||
class CmsMediaCardTextTest extends TestCase
|
||||
{
|
||||
use BuildsCatalog;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_the_card_shows_the_text_the_editor_chose_and_the_default_stays_unchanged(): void
|
||||
{
|
||||
$film = $this->publicFilm();
|
||||
|
||||
$this->publish('/textwahl', [
|
||||
$this->card($film, []),
|
||||
$this->card($film, ['text_source' => 'auto']),
|
||||
$this->card($film, ['text_source' => 'teaser']),
|
||||
$this->card($film, ['text_source' => 'summary']),
|
||||
$this->card($film, ['text_source' => 'description']),
|
||||
]);
|
||||
|
||||
$cards = $this->cards($this->get('/textwahl')->assertOk()->getContent());
|
||||
$this->assertCount(5, $cards);
|
||||
$this->assertStringContainsString('KURZ-TEXT', $cards[0]);
|
||||
$this->assertStringContainsString('KURZ-TEXT', $cards[1]);
|
||||
$this->assertStringContainsString('TEASER-TEXT', $cards[2]);
|
||||
$this->assertStringNotContainsString('KURZ-TEXT', $cards[2]);
|
||||
$this->assertStringContainsString('KURZ-TEXT', $cards[3]);
|
||||
$this->assertStringContainsString('LANG-TEXT', $cards[4]);
|
||||
$this->assertStringContainsString('zweiter Absatz', $cards[4]);
|
||||
|
||||
foreach ($cards as $index => $card) {
|
||||
foreach (['EINSATZ-INTERN', 'LIZENZ-INTERN'] as $internal) {
|
||||
$this->assertStringNotContainsString($internal, $card, "Karte $index: Einsatzhinweis und Lizenzvermerk bleiben intern.");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ([0, 1, 2, 3] as $index) {
|
||||
$this->assertStringNotContainsString('LANG-TEXT', $cards[$index], 'Die ausführliche Beschreibung erscheint nur auf ausdrückliche Wahl.');
|
||||
}
|
||||
}
|
||||
|
||||
public function test_the_default_falls_back_to_the_teaser_but_an_explicit_choice_does_not(): void
|
||||
{
|
||||
$film = $this->publicFilm(['summary' => null]);
|
||||
|
||||
$revision = $this->publish('/textwahl-ersatz', [
|
||||
$this->card($film, []),
|
||||
$this->card($film, ['text_source' => 'summary']),
|
||||
]);
|
||||
|
||||
$cards = $this->cards($this->get('/textwahl-ersatz')->assertOk()->getContent());
|
||||
$this->assertStringContainsString('TEASER-TEXT', $cards[0], 'Vorgabe: ohne Kurzbeschreibung der Teaser, wie bisher.');
|
||||
$this->assertStringNotContainsString('lf-pc__summary', $cards[1], 'Gewählte, nicht gepflegte Kurzbeschreibung: kein stiller Ersatz.');
|
||||
$this->assertStringNotContainsString('TEASER-TEXT', $cards[1]);
|
||||
|
||||
$this->assertStringNotContainsString('Keine Kurzbeschreibung gepflegt', $this->get('/textwahl-ersatz')->getContent(), 'Hinweise erscheinen öffentlich nie.');
|
||||
$this->assertStringNotContainsString('Für eine vollständige Karte', $this->get('/textwahl-ersatz')->getContent());
|
||||
|
||||
$preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent();
|
||||
$this->assertStringContainsString('Keine Kurzbeschreibung gepflegt (Medium bearbeiten → Kurzbeschreibung).', $preview);
|
||||
}
|
||||
|
||||
public function test_the_own_text_of_the_card_wins_over_the_chosen_central_text(): void
|
||||
{
|
||||
$film = $this->publicFilm();
|
||||
|
||||
$this->publish('/textwahl-eigen', [
|
||||
$this->card($film, ['text_source' => 'description'], ['summary' => 'EIGENER-KARTENTEXT']),
|
||||
]);
|
||||
|
||||
$card = $this->cards($this->get('/textwahl-eigen')->assertOk()->getContent())[0];
|
||||
$this->assertStringContainsString('EIGENER-KARTENTEXT', $card);
|
||||
$this->assertStringNotContainsString('LANG-TEXT', $card);
|
||||
}
|
||||
|
||||
public function test_the_choice_is_limited_to_the_three_central_texts_and_to_the_media_card(): void
|
||||
{
|
||||
$film = $this->publicFilm();
|
||||
$registry = app(WidgetRegistry::class);
|
||||
|
||||
$this->assertSame(['auto', 'teaser', 'summary', 'description'], array_keys($registry->get('media_card')->settingOptions()['text_source']));
|
||||
$this->assertArrayNotHasKey('text_source', $registry->get('program_card')->settingOptions());
|
||||
$this->assertArrayNotHasKey('text_source', $registry->get('topic_card')->settingOptions());
|
||||
|
||||
foreach (['usage_note', 'license_note', 'working_title'] as $internal) {
|
||||
try {
|
||||
$registry->normalize([['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => ['text_source' => $internal], 'data' => [], 'refs' => ['element' => $film->id]]]);
|
||||
$this->fail("Der interne Text $internal wurde als Kartentext angenommen.");
|
||||
} catch (ValidationException $exception) {
|
||||
$this->assertArrayHasKey('blocks.0.settings.text_source', $exception->errors());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $extra
|
||||
*/
|
||||
private function publicFilm(array $extra = []): ContentElement
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$kind = fn (string $slug) => EditorialContentKind::query()->where('slug', $slug)->value('id');
|
||||
$film = $content->createElement('film', 'film', 'Denkpause Rohschnitt');
|
||||
$film->update($extra + [
|
||||
'display_title' => 'Eine Pause, die stark macht',
|
||||
'teaser' => 'TEASER-TEXT',
|
||||
'summary' => 'KURZ-TEXT',
|
||||
'description' => "LANG-TEXT erster Absatz\n\nzweiter Absatz",
|
||||
'usage_note' => 'EINSATZ-INTERN',
|
||||
'license_note' => 'LIZENZ-INTERN',
|
||||
]);
|
||||
$version = $content->publishElementVersion($film, 'Film');
|
||||
$composition = $content->createComposition('Programm Denkpause');
|
||||
$composition->editorial_content_kind_id = $kind('programm');
|
||||
$composition->save();
|
||||
$shown = $content->publishComposition($composition, [['role' => 'Film', 'target' => $version]]);
|
||||
app(CompositionDisplayRelease::class)->release($shown, User::factory()->create());
|
||||
|
||||
return $film->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $settings
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function card(ContentElement $film, array $settings, array $data = []): array
|
||||
{
|
||||
return ['layout' => 'u4', 'style' => [], 'slots' => [
|
||||
['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => $settings, 'data' => $data, 'refs' => ['element' => $film->id]],
|
||||
]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $sections
|
||||
*/
|
||||
private function publish(string $path, array $sections): PageRevision
|
||||
{
|
||||
$page = Page::query()->create(['path' => $path]);
|
||||
$service = app(PageService::class);
|
||||
$revision = $service->saveRevision($page, $sections, null, null, null);
|
||||
$service->publish($page, $revision);
|
||||
|
||||
return $revision;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function cards(string $html): array
|
||||
{
|
||||
preg_match_all('#<article class="lf-pc .*?</article>#s', $html, $matches);
|
||||
|
||||
return $matches[0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Media\FilmStill;
|
||||
use App\Domain\Media\FilmStillSource;
|
||||
use App\Domain\Media\ThumbnailDeriver;
|
||||
use App\Domain\Media\WebsiteRelease;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Bild aus einem Film für die Medien- und Materialkarte: einmal als Bild-Medium ablegen, danach nur lesen.
|
||||
* Die Bildextraktion (ffmpeg) wird durch einen Stub ersetzt und mitgezählt.
|
||||
*/
|
||||
class FilmStillTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @var object{calls: list<array{second: float, width: int, original: bool}>, fail: bool} */
|
||||
private object $extractor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Storage::fake('cms_incoming');
|
||||
Storage::fake('media_derived');
|
||||
Storage::fake('media_public');
|
||||
Storage::fake('media_originals');
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
|
||||
$jpeg = $this->jpeg(1600, 900);
|
||||
$this->extractor = new class($jpeg) extends ThumbnailDeriver
|
||||
{
|
||||
/** @var list<array{second: float, width: int, original: bool}> */
|
||||
public array $calls = [];
|
||||
|
||||
public bool $fail = false;
|
||||
|
||||
public function __construct(private readonly string $jpeg) {}
|
||||
|
||||
public function frameJpeg(ContentElementVersion $version, float $seconds, int $width = 640, bool $original = false): ?string
|
||||
{
|
||||
$this->calls[] = ['second' => $seconds, 'width' => $width, 'original' => $original];
|
||||
|
||||
return $this->fail ? null : $this->jpeg;
|
||||
}
|
||||
};
|
||||
$this->app->instance(ThumbnailDeriver::class, $this->extractor);
|
||||
}
|
||||
|
||||
public function test_a_chosen_frame_becomes_one_image_medium_that_is_released_for_the_website(): void
|
||||
{
|
||||
$film = $this->film();
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
|
||||
$still = app(FilmStill::class)->fromSecond($film, 41.5, $editor)->refresh();
|
||||
|
||||
$this->assertSame('bild', $still->output_class);
|
||||
$this->assertSame('Standbild: Lara im Park (Fassung 1, 41,5 s)', $still->display_title);
|
||||
$this->assertSame('Szene aus dem Film „Lara im Park“', $still->website_alt);
|
||||
$this->assertSame('Foto: Lara und Felix', $still->website_credit, 'Die Quellenzeile des Films wird übernommen.');
|
||||
$this->assertSame(0, $still->versions()->count(), 'Es entsteht keine Inhaltsfassung.');
|
||||
$this->assertSame(0, Grant::query()->count(), 'Es entsteht keine Berechtigung.');
|
||||
$this->assertNotNull($still->website_released_at, 'Die Warteschlange gibt das abgeleitete Bild für die Website frei.');
|
||||
$this->assertSame([['second' => 41.5, 'width' => 1600, 'original' => true]], $this->extractor->calls, 'Aus der Mediendatei in voller Auflösung, nicht aus der kleinen Stufe.');
|
||||
$this->assertSame($still->id, FilmStillSource::query()->where('film_element_id', $film->id)->value('still_element_id'));
|
||||
$this->assertSame($editor->id, FilmStillSource::query()->value('actor_id'));
|
||||
$this->assertSame(1, ContentElement::query()->where('output_class', 'film')->count(), 'Der Film bleibt unverändert.');
|
||||
}
|
||||
|
||||
public function test_the_same_frame_is_never_extracted_or_stored_twice(): void
|
||||
{
|
||||
$film = $this->film();
|
||||
$first = app(FilmStill::class)->fromSecond($film, 12);
|
||||
$second = app(FilmStill::class)->fromSecond($film, 12.0);
|
||||
$other = app(FilmStill::class)->fromSecond($film, 13);
|
||||
|
||||
$this->assertSame($first->id, $second->id);
|
||||
$this->assertNotSame($first->id, $other->id);
|
||||
$this->assertCount(2, $this->extractor->calls, 'Die zweite Anforderung derselben Stelle liest das gespeicherte Bild.');
|
||||
$this->assertSame(2, ContentElement::query()->where('output_class', 'bild')->count());
|
||||
|
||||
$first->update(['archived_at' => now()]);
|
||||
$this->assertNotSame($first->id, app(FilmStill::class)->fromSecond($film, 12)->id, 'Ein archiviertes Bild wird nicht wiederverwendet.');
|
||||
}
|
||||
|
||||
public function test_the_thumbnail_of_the_film_is_taken_over_in_full_resolution_or_as_its_own_file(): void
|
||||
{
|
||||
$film = $this->film();
|
||||
$film->forceFill(['thumbnail_path' => 'vorschau/element-'.$film->id.'.jpg', 'thumbnail_source' => 'frame:'.$film->versions()->value('id').'@41.5'])->save();
|
||||
Storage::disk('media_derived')->put($film->thumbnail_path, $this->jpeg(640, 360));
|
||||
|
||||
$fromFrame = app(FilmStill::class)->fromThumbnail($film);
|
||||
$this->assertSame([['second' => 41.5, 'width' => 1600, 'original' => true]], $this->extractor->calls, 'Eine Filmstelle wird in voller Auflösung neu gezogen.');
|
||||
$this->assertSame($fromFrame->id, app(FilmStill::class)->fromSecond($film, 41.5)->id, 'Dieselbe Stelle ergibt dasselbe Medium, egal auf welchem Weg.');
|
||||
$this->assertCount(1, $this->extractor->calls);
|
||||
|
||||
$own = $this->film('Interview');
|
||||
$own->forceFill(['thumbnail_path' => 'vorschau/element-'.$own->id.'.jpg', 'thumbnail_source' => 'eigen'])->save();
|
||||
Storage::disk('media_derived')->put($own->thumbnail_path, $this->jpeg(800, 450));
|
||||
|
||||
$copied = app(FilmStill::class)->fromThumbnail($own);
|
||||
$this->assertSame($copied->id, app(FilmStill::class)->fromThumbnail($own)->id, 'Dieselbe Vorschaudatei ergibt dasselbe Medium.');
|
||||
$this->assertCount(1, $this->extractor->calls, 'Ein eigenes Vorschaubild wird kopiert, nicht aus dem Film gezogen.');
|
||||
$this->assertStringStartsWith('Standbild: Interview (Vorschaubild)', $copied->refresh()->display_title);
|
||||
}
|
||||
|
||||
public function test_confidential_blocked_or_unusable_films_yield_no_image(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$guide = $this->film('Traineranleitung als Film');
|
||||
$guide->update(['editorial_content_kind_id' => EditorialContentKind::query()->where('slug', 'traineranleitung')->value('id')]);
|
||||
$archived = $this->film('Archiviert');
|
||||
$archived->update(['archived_at' => now()]);
|
||||
$draftOnly = $content->createElement('film', 'film', 'Nur Entwurf');
|
||||
$content->draftElementVersion($draftOnly, 'Entwurf');
|
||||
$text = $content->createElement('text', 'text', 'Ein Text');
|
||||
$noThumbnail = $this->film('Ohne Vorschaubild');
|
||||
|
||||
$cases = [
|
||||
[fn () => app(FilmStill::class)->fromSecond($guide, 5), 'Traineranleitungen'],
|
||||
[fn () => app(FilmStill::class)->fromSecond($archived, 5), 'archiviert'],
|
||||
[fn () => app(FilmStill::class)->fromSecond($draftOnly, 5), 'bereitgestellte Fassung'],
|
||||
[fn () => app(FilmStill::class)->fromSecond($text, 5), 'Nur aus einem Film'],
|
||||
[fn () => app(FilmStill::class)->fromSecond($noThumbnail, -1), 'außerhalb des Films'],
|
||||
[fn () => app(FilmStill::class)->fromSecond($noThumbnail, 7201), 'außerhalb des Films'],
|
||||
[fn () => app(FilmStill::class)->fromThumbnail($noThumbnail), 'noch kein Vorschaubild'],
|
||||
];
|
||||
|
||||
foreach ($cases as [$call, $message]) {
|
||||
try {
|
||||
$call();
|
||||
$this->fail("Erwartete Ablehnung: $message");
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->assertStringContainsString($message, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->extractor->fail = true;
|
||||
|
||||
try {
|
||||
app(FilmStill::class)->fromSecond($noThumbnail, 5);
|
||||
$this->fail('Eine nicht ziehbare Stelle wurde angenommen.');
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->assertStringContainsString('kein Bild erzeugen', $exception->getMessage());
|
||||
}
|
||||
|
||||
$this->assertSame(0, ContentElement::query()->where('output_class', 'bild')->count(), 'Bei einer Ablehnung entsteht kein Medium.');
|
||||
$this->assertSame(0, FilmStillSource::query()->count());
|
||||
}
|
||||
|
||||
public function test_the_card_shows_the_stored_image_and_a_page_view_never_extracts_a_frame(): void
|
||||
{
|
||||
$film = $this->film();
|
||||
$still = app(FilmStill::class)->fromSecond($film, 41.5)->refresh();
|
||||
$this->assertCount(1, $this->extractor->calls);
|
||||
$this->publishInProgram($film);
|
||||
|
||||
$page = Page::query()->create(['path' => '/filmkarte']);
|
||||
$service = app(PageService::class);
|
||||
$service->publish($page, $service->saveRevision($page, [
|
||||
['layout' => 'u4', 'style' => [], 'slots' => [
|
||||
['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => [], 'refs' => ['element' => $film->id, 'image' => $still->id]],
|
||||
]],
|
||||
], null, null, null));
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$html = $this->get('/filmkarte')->assertOk()->getContent();
|
||||
}
|
||||
|
||||
$this->assertStringContainsString('src="'.route('website.media', $still).'"', $html);
|
||||
$this->assertStringContainsString('alt="Szene aus dem Film „Lara im Park“"', htmlspecialchars_decode($html));
|
||||
$this->assertStringNotContainsString('lf-pc__panel--film', $html, 'Mit freigegebenem Bild erscheint keine Filmtafel.');
|
||||
$this->assertStringNotContainsString('/redaktion/', $html);
|
||||
$this->assertCount(1, $this->extractor->calls, 'Seitenaufrufe lesen nur die gespeicherte Datei und starten keine Bildextraktion.');
|
||||
|
||||
app(WebsiteRelease::class)->withdraw($still);
|
||||
$this->app->forgetScopedInstances();
|
||||
$this->assertStringNotContainsString('<img', $this->main($this->get('/filmkarte')->getContent()), 'Zurückgenommen: das Bild entfällt, die Karte bleibt (Filmtafel).');
|
||||
}
|
||||
|
||||
public function test_the_editor_adopts_a_frame_into_the_image_field_and_rejects_foreign_targets(): void
|
||||
{
|
||||
$film = $this->film();
|
||||
$film->forceFill(['thumbnail_path' => 'vorschau/element-'.$film->id.'.jpg', 'thumbnail_source' => 'eigen'])->save();
|
||||
Storage::disk('media_derived')->put($film->thumbnail_path, $this->jpeg(640, 360));
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$page = Page::query()->create(['path' => '/filmbild-editor']);
|
||||
app(PageService::class)->saveRevision($page, [
|
||||
['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => [], 'refs' => ['element' => $film->id]]]],
|
||||
], null, null, null);
|
||||
|
||||
$component = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id]);
|
||||
|
||||
$component->call('adoptFilmFrame', 'data.ziel.image', $film->id, '12.5');
|
||||
$frame = ContentElement::query()->where('output_class', 'bild')->latest('id')->firstOrFail();
|
||||
$this->assertSame($frame->id, $component->get('data.ziel.image'));
|
||||
$this->assertSame('Standbild: Lara im Park (Fassung 1, 12,5 s)', $frame->display_title);
|
||||
|
||||
$component->call('adoptFilmThumbnail', 'data.ziel2.image', $film->id);
|
||||
$this->assertNotNull($component->get('data.ziel2.image'));
|
||||
|
||||
$before = ContentElement::query()->count();
|
||||
$component->call('adoptFilmFrame', 'data.ziel3.image', $film->id, 'abc');
|
||||
$component->call('adoptFilmFrame', 'umgebung.geheim', $film->id, '5');
|
||||
$component->call('adoptFilmFrame', 'data.ziel4.bild', $film->id, '5');
|
||||
$component->call('adoptFilmFrame', 'data.ziel5.image', 999999, '5');
|
||||
$this->assertSame($before, ContentElement::query()->count(), 'Fremde Ziele, falsche Eingaben und fehlende Filme legen nichts an.');
|
||||
$this->assertNull($component->get('data.ziel3.image'));
|
||||
}
|
||||
|
||||
private function film(string $title = 'Lara im Park'): ContentElement
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$film = $content->createElement('film', 'film', $title);
|
||||
$film->update(['website_credit' => 'Foto: Lara und Felix']);
|
||||
$content->publishElementVersion($film, 'Film');
|
||||
|
||||
return $film->refresh();
|
||||
}
|
||||
|
||||
private function publishInProgram(ContentElement $film): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$composition = $content->createComposition('Programm Park');
|
||||
$composition->editorial_content_kind_id = EditorialContentKind::query()->where('slug', 'programm')->value('id');
|
||||
$composition->save();
|
||||
$version = $content->publishComposition($composition, [['role' => 'Film', 'target' => $film->versions()->firstOrFail()]]);
|
||||
app(CompositionDisplayRelease::class)->release($version, User::factory()->create());
|
||||
}
|
||||
|
||||
private function main(string $html): string
|
||||
{
|
||||
preg_match('#<main[^>]*>(.*)</main>#s', $html, $match);
|
||||
|
||||
return $match[1] ?? '';
|
||||
}
|
||||
|
||||
private function jpeg(int $width, int $height): string
|
||||
{
|
||||
$image = imagecreatetruecolor($width, $height);
|
||||
imagefill($image, 0, 0, imagecolorallocate($image, 40, 120, 90));
|
||||
ob_start();
|
||||
imagejpeg($image);
|
||||
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user