Files
LarsandCursor 7b325f0d66
CI Feature / test (push) Successful in 53s
Deploy Test / test (push) Successful in 48s
Deploy Test / deploy (push) Successful in 22s
Lasse Präsentationsmedien ohne Inhaltsfassung zu.
Bilder, Filme und Hörstücke lassen sich zuordnen und für die Website freigeben, ohne eine fachliche Fassung anzulegen. Unterrichtsfilme behalten die Teaserfassung an ihrer bereitgestellten Fassung.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-19 08:20:35 +01:00

77 lines
2.1 KiB
PHP

<?php
namespace App\Domain\Media;
use App\Domain\Catalog\ContentElement;
use Illuminate\Support\Facades\Storage;
/**
* Lesesicht für Hero, Teaser und Slideshow.
* Liefert nur eine freigegebene öffentliche Ableitung, sonst nichts.
*/
class WebsiteMedia
{
public function present(ContentElement|int $element): ?WebsitePresentation
{
$element = $element instanceof ContentElement
? $element
: ContentElement::query()->find($element);
if (! $element instanceof ContentElement || $element->website_released_at === null) {
return null;
}
$path = $element->website_public_path;
$expected = '#^website/'.$element->id.'/datei\.[a-z0-9]+$#';
if (! is_string($path) || preg_match($expected, $path) !== 1) {
return null;
}
if (! Storage::disk('media_public')->exists($path)) {
return null;
}
$title = trim((string) ($element->display_title ?: $element->working_title));
$alt = trim((string) ($element->website_alt ?? ''));
return new WebsitePresentation(
elementId: $element->id,
title: $title,
alt: $alt !== '' ? $alt : $title,
credit: filled($element->website_credit) ? trim((string) $element->website_credit) : null,
kind: match ($element->output_class) {
'film' => 'film',
'audio' => 'audio',
default => 'bild',
},
url: route('website.media', $element),
);
}
/**
* Slideshow: freigegebene Medien in der angegebenen Reihenfolge. Nicht freigegebene Einträge entfallen.
*
* @param list<int|string> $ids
* @return list<WebsitePresentation>
*/
public function presentMany(array $ids): array
{
$presentations = [];
foreach ($ids as $id) {
if (! is_numeric($id)) {
continue;
}
$presentation = $this->present((int) $id);
if ($presentation !== null) {
$presentations[] = $presentation;
}
}
return $presentations;
}
}