Files
laraundfelix/app/Domain/Media/CompositionStill.php
T
LarsandClaude Sonnet 5.5 3825f53a9b
CI Feature / test (push) Successful in 1m46s
Deploy Test / test (push) Successful in 1m45s
Deploy Test / deploy (push) Successful in 36s
Wähle den Kartentext auch an der Programm- und Modulkarte und führe den Filmbild-Regler nach.
- 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>
2026-11-21 21:19:43 +01:00

101 lines
3.7 KiB
PHP

<?php
namespace App\Domain\Media;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\DomainRuleException;
use App\Models\User;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
/**
* Übernimmt das Vorschaubild eines Programms oder Moduls als gewöhnliches Bild-Medium im Medienmanager
* (Programm- und Modulkarte), nach demselben Prinzip wie FilmStill.
*
* - Ausdrückliche Handlung der Redaktion. Das Vorschaubild ist ein geschütztes Bibliotheksbild; erst die Übernahme
* legt ein Medium an, das für die Website freigegeben werden kann (WebsiteIntake, Warteschlange).
* - Die Datei wird einmal kopiert. Dieselbe Vorschaudatei ergibt dasselbe Medium (composition_still_sources).
* - Es entsteht keine Fassung, keine Berechtigung, kein Lizenzartikel.
*/
class CompositionStill
{
/** Wahr, wenn der letzte Aufruf ein schon vorhandenes Bild geliefert hat. */
public bool $reused = false;
public function __construct(private readonly WebsiteIntake $intake) {}
public function refusal(Composition $composition): ?string
{
if ($composition->archived_at !== null) {
return 'Das Programm oder Modul ist archiviert.';
}
return null;
}
public function hasThumbnail(Composition $composition): bool
{
$path = $composition->thumbnail_path;
return is_string($path) && str_starts_with($path, 'vorschau/') && ! str_contains($path, '..')
&& Storage::disk('media_derived')->exists($path);
}
public function fromThumbnail(Composition $composition, ?User $actor = null): ContentElement
{
$this->reused = false;
$refusal = $this->refusal($composition);
if ($refusal !== null) {
throw new DomainRuleException($refusal);
}
if (! $this->hasThumbnail($composition)) {
throw new DomainRuleException('Dieses Programm oder Modul hat noch kein Vorschaubild. Setzen Sie es im Redaktionsmanager.');
}
$bytes = Storage::disk('media_derived')->get((string) $composition->thumbnail_path);
if (! is_string($bytes) || $bytes === '') {
throw new DomainRuleException('Das Vorschaubild ließ sich nicht lesen.');
}
$key = 'file:'.hash('sha256', $bytes);
$existing = $this->existing($composition, $key);
if ($existing instanceof ContentElement) {
$this->reused = true;
return $existing;
}
$title = (string) ($composition->display_title ?: $composition->designation);
$path = 'cms/titelbild-'.$composition->id.'-'.Str::lower(Str::random(8)).'.jpg';
Storage::disk('cms_incoming')->put($path, $bytes);
$still = $this->intake->acceptImage($path, 'Titelbild: '.$title, null, 'Titelbild zu „'.$title.'“', $actor);
try {
CompositionStillSource::query()->updateOrCreate(
['composition_id' => $composition->id, 'source_key' => $key],
['still_element_id' => $still->id, 'actor_id' => $actor?->id],
);
} catch (QueryException) {
return $this->existing($composition, $key) ?? $still;
}
return $still;
}
private function existing(Composition $composition, string $key): ?ContentElement
{
$source = CompositionStillSource::query()->with('still')->where('composition_id', $composition->id)->where('source_key', $key)->first();
$still = $source?->still;
// Ein archiviertes oder bei der Verarbeitung gescheitertes Bild wird nicht wiederverwendet.
return $still instanceof ContentElement && $still->archived_at === null && ! filled($still->thumbnail_error) ? $still : null;
}
}