- Programm- und Modulkarte: „Text der Karte“ (Automatisch wie bisher: Teaser, sonst Kurzbeschreibung, sonst Lernziel; Teaser, Kurzbeschreibung, Ausführliche Beschreibung, Lernziel der Fassung). Eine ausdrückliche Wahl ersetzt nicht still; die Vorschau nennt, wo der Text zu pflegen ist. Das Vorschaubild des Programms oder Moduls lässt sich als Bild-Medium übernehmen (CompositionStill, additive Tabelle composition_still_sources). - Filmbild im Dialog wie im Medienmanager: Regler und Zahlenfeld zeigen dieselbe Stelle, das Bild folgt dem Regler nach kurzer Pause, „Diese Stelle übernehmen“; das Vorschaubild des Films mit kleiner Ansicht daneben. - Gemeinsame Meldung nach dem tatsächlichen Stand für Film- und Programmbilder. - Test bewusst angepasst: Die Programmkarte hat jetzt eine Textwahl (vorher nur die Medienkarte). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
261 lines
8.7 KiB
PHP
261 lines
8.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Support;
|
|
|
|
use App\Domain\Catalog\Composition;
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Catalog\DomainRuleException;
|
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
|
use App\Domain\Media\CompositionStill;
|
|
use App\Domain\Media\FilmStill;
|
|
use App\Domain\Media\WebsiteMedia;
|
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
|
use Filament\Notifications\Notification;
|
|
|
|
/**
|
|
* Bildauswahl im CMS über den gemeinsamen visuellen Picker (Dokument 14 §9) statt einer eigenen Auswahlliste.
|
|
* Ein Bildfeld (filament.cms.bild-feld) öffnet den Picker mit seinem Formularpfad; „Bild übernehmen“ schreibt die
|
|
* Kennung des Mediums in genau dieses Feld, auch im geöffneten Bausteindialog. Gespeichert wird weiterhin nur mit dem
|
|
* Seitenentwurf. Die Auswahl gibt kein Bild für die Website frei.
|
|
*/
|
|
trait ChoosesWebsiteImages
|
|
{
|
|
use ChoosesMedia;
|
|
|
|
/** Formularpfad des Bildfelds, in das die Auswahl übernommen wird. */
|
|
public ?string $bildZiel = null;
|
|
|
|
public function openWebsiteImagePicker(string $pfad): void
|
|
{
|
|
if (preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+$/', $pfad) !== 1) {
|
|
return;
|
|
}
|
|
|
|
$this->resetPicker('website-bild');
|
|
$this->pickerKind = 'bild';
|
|
$this->bildZiel = $pfad;
|
|
$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()));
|
|
}
|
|
|
|
/**
|
|
* Programm- und Modulkarte: das Vorschaubild des Programms oder Moduls als Bild für die Website übernehmen
|
|
* (Bild-Medium im Medienmanager, einmal kopiert).
|
|
*/
|
|
public function adoptCompositionThumbnail(string $pfad, int $compositionId): void
|
|
{
|
|
abort_unless(ContentElementResource::editor(), 403);
|
|
|
|
if ($this->imageTargetIsInvalid($pfad)) {
|
|
return;
|
|
}
|
|
|
|
$composition = Composition::query()->find($compositionId);
|
|
|
|
if (! $composition instanceof Composition) {
|
|
return;
|
|
}
|
|
|
|
$stills = app(CompositionStill::class);
|
|
|
|
try {
|
|
$still = $stills->fromThumbnail($composition, auth('staff')->user());
|
|
} catch (DomainRuleException $exception) {
|
|
Notification::make()->danger()->title($exception->getMessage())->send();
|
|
|
|
return;
|
|
}
|
|
|
|
data_set($this, $pfad, $still->id);
|
|
$this->announceAdoptedStill($still, $stills->reused, 'Dieses Vorschaubild war schon übernommen.');
|
|
}
|
|
|
|
/**
|
|
* @param callable(FilmStill, ContentElement): ContentElement $make
|
|
*/
|
|
private function adoptFilmStill(string $pfad, int $elementId, callable $make): void
|
|
{
|
|
abort_unless(ContentElementResource::editor(), 403);
|
|
|
|
if ($this->imageTargetIsInvalid($pfad)) {
|
|
return;
|
|
}
|
|
|
|
$film = ContentElement::query()->with('editorialContentKind')->find($elementId);
|
|
|
|
if (! $film instanceof ContentElement) {
|
|
return;
|
|
}
|
|
|
|
$stills = app(FilmStill::class);
|
|
|
|
try {
|
|
$still = $make($stills, $film);
|
|
} catch (DomainRuleException $exception) {
|
|
Notification::make()->danger()->title($exception->getMessage())->send();
|
|
|
|
return;
|
|
}
|
|
|
|
data_set($this, $pfad, $still->id);
|
|
$this->announceAdoptedStill($still, $stills->reused, 'Diese Stelle war schon übernommen.');
|
|
}
|
|
|
|
/** Nur das Bildfeld eines Widgets oder Abschnitts ist ein zulässiges Ziel (…image). */
|
|
private function imageTargetIsInvalid(string $pfad): bool
|
|
{
|
|
return preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+\.image$/', $pfad) !== 1;
|
|
}
|
|
|
|
/**
|
|
* Meldung nach dem tatsächlichen Stand des Bildes: neu angelegt, schon vorhanden und freigegeben, wird verarbeitet
|
|
* oder Website-Freigabe zurückgenommen (bleibt zurückgenommen).
|
|
*/
|
|
private function announceAdoptedStill(ContentElement $still, bool $reused, string $reusedText): void
|
|
{
|
|
$title = ($still->display_title ?: $still->working_title);
|
|
|
|
if (! $reused) {
|
|
Notification::make()
|
|
->success()
|
|
->title('Im Medienmanager angelegt: „'.$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();
|
|
|
|
return;
|
|
}
|
|
|
|
if (app(WebsiteMedia::class)->present($still) !== null) {
|
|
Notification::make()->success()->title('Bereits im Medienmanager: „'.$title.'“')->body($reusedText.' Das Bild ist als Kartenbild ausgewählt.')->send();
|
|
} elseif (blank($still->thumbnail_path) && blank($still->thumbnail_error)) {
|
|
Notification::make()->success()->title('Bereits im Medienmanager: „'.$title.'“')->body('Das Bild wird noch verarbeitet und danach für die Website freigegeben.')->send();
|
|
} else {
|
|
Notification::make()->warning()->title('Bild ausgewählt, aber nicht für die Website freigegeben: „'.$title.'“')
|
|
->body($reusedText.' Die Website-Freigabe wurde zurückgenommen. Das Bild erscheint öffentlich erst wieder, wenn sie im Medienmanager (Reiter „Website“) erneut gegeben wird.')
|
|
->persistent()
|
|
->send();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Filament rendert bei offenen Aktionsdialogen nur den Dialogteil neu; der Picker liegt darüber und braucht die
|
|
* ganze Seite.
|
|
*/
|
|
public function hydrateChoosesWebsiteImages(): void
|
|
{
|
|
if ($this->pickerOpen) {
|
|
$this->forceRenderForPicker();
|
|
}
|
|
}
|
|
|
|
public function pickerAllowsMany(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function closePicker(): void
|
|
{
|
|
$this->pickerOpen = false;
|
|
$this->pickerSelected = '';
|
|
$this->pickerInspected = '';
|
|
$this->pickerMarked = [];
|
|
$this->bildZiel = null;
|
|
$this->forceRenderForPicker();
|
|
}
|
|
|
|
public function confirmPicker(): void
|
|
{
|
|
$target = array_key_first($this->pickerMarked);
|
|
$ziel = $this->bildZiel;
|
|
|
|
if ($target === null || $ziel === null) {
|
|
return;
|
|
}
|
|
|
|
$row = app(EditorialCatalog::class)->rowForTarget((string) $target, 0, allowDraft: true);
|
|
$element = isset($row['element_id']) ? ContentElement::query()->find((int) $row['element_id']) : null;
|
|
|
|
if (! $element instanceof ContentElement || ! WebsiteImage::isSelectable($element)) {
|
|
Notification::make()->danger()->title('Dieses Medium kann nicht als Website-Bild gewählt werden.')->send();
|
|
|
|
return;
|
|
}
|
|
|
|
data_set($this, $ziel, $element->id);
|
|
$this->closePicker();
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function pickerKinds(): array
|
|
{
|
|
return ['bild' => 'Bilder'];
|
|
}
|
|
|
|
public function pickerTitle(): string
|
|
{
|
|
return 'Bild aus dem Medienmanager';
|
|
}
|
|
|
|
public function pickerConfirmLabel(): string
|
|
{
|
|
return 'Bild übernehmen';
|
|
}
|
|
|
|
/**
|
|
* @return array{art: string, titel: string}
|
|
*/
|
|
public function pickerKontext(): array
|
|
{
|
|
$pfad = property_exists($this, 'record') && is_object($this->record ?? null) ? (string) ($this->record->path ?? '') : '';
|
|
|
|
return ['art' => 'die Seite', 'titel' => $pfad !== '' ? $pfad : 'neue Seite'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function presentationRoleOptions(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>|null
|
|
*/
|
|
public function pickerReplacing(): ?array
|
|
{
|
|
return null;
|
|
}
|
|
|
|
private function forceRenderForPicker(): void
|
|
{
|
|
if (method_exists($this, 'forceRender')) {
|
|
$this->forceRender();
|
|
}
|
|
}
|
|
}
|