Wähle das Vorschaubild am Medium und nutze es als Standard in der Anzeige und in Modulen.
Deploy Test / test (push) Successful in 28s
Deploy Test / deploy (push) Successful in 39s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-16 21:34:11 +01:00
1 parent f86032cb5f
commit 8e77defaca
18 files changed
+664 -26

No files matched your search

+1
View File
@@ -20,6 +20,7 @@ class ContentElement extends Model
'summary',
'thumbnail_path',
'thumbnail_alt',
'thumbnail_source',
'thumbnail_error',
'editorial_content_kind_id',
'archived_at',
+57 -4
View File
@@ -24,12 +24,48 @@ public function forElement(ContentElement $element): void
}
if (in_array($element->output_class, ['film', 'audio'], true)) {
$this->frame($element, $file);
$this->frame($element, $version, $file);
return;
}
$this->still($element, Storage::disk('media_derived'), $file, 'element-'.$element->id);
$this->rememberElement($element, 'datei');
}
public function forElementUpload(ContentElement $element, string $incoming): void
{
if (! str_starts_with($incoming, 'vorschau/') || str_contains($incoming, '..')) {
$this->fail($element, 'Das Vorschaubild wurde nicht übernommen.');
return;
}
$this->still($element, Storage::disk('cms_incoming'), $incoming, 'element-'.$element->id);
$this->rememberElement($element, 'eigen');
}
public function forElementFrame(ContentElement $element, ContentElementVersion $version, float $seconds): void
{
if ($version->content_element_id !== $element->id || $element->output_class !== 'film') {
$this->fail($element, 'Aus dieser Filmstelle ließ sich kein Vorschaubild erzeugen.');
return;
}
$bytes = $this->jpegAtVersion($version, $seconds);
if (! is_string($bytes)) {
$this->fail($element, 'Aus dieser Filmstelle ließ sich kein Vorschaubild erzeugen.');
return;
}
$name = 'element-'.$element->id;
$path = 'vorschau/'.$name.'.jpg';
Storage::disk('media_derived')->put($path, $bytes);
$this->still($element, Storage::disk('media_derived'), $path, $name);
$this->rememberElement($element, 'frame:'.$version->id.'@'.$this->secondText($seconds));
}
public function forCompositionUpload(Composition $composition, string $incoming): void
@@ -166,7 +202,7 @@ private function secondText(float $seconds): string
return rtrim(rtrim($text, '0'), '.') ?: '0';
}
private function frame(ContentElement $element, string $file): void
private function frame(ContentElement $element, ContentElementVersion $version, string $file): void
{
$binary = (new ExecutableFinder)->find('ffmpeg');
$disk = Storage::disk('media_derived');
@@ -200,8 +236,13 @@ private function frame(ContentElement $element, string $file): void
}
$element->thumbnail_path = $target;
$element->thumbnail_alt = $element->working_title;
if (! filled($element->thumbnail_alt)) {
$element->thumbnail_alt = $element->working_title;
}
$element->thumbnail_error = null;
if ($element->output_class === 'film') {
$element->thumbnail_source = 'frame:'.$version->id.'@0';
}
$element->save();
}
@@ -243,7 +284,7 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st
Storage::disk('media_derived')->put($path, $bytes);
$subject->thumbnail_path = $path;
if (! ($subject instanceof Composition && filled($subject->thumbnail_alt))) {
if (! filled($subject->thumbnail_alt)) {
$subject->thumbnail_alt = $subject instanceof Composition ? $subject->designation : $subject->working_title;
}
@@ -251,6 +292,18 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st
$subject->save();
}
private function rememberElement(ContentElement $element, string $source): void
{
$element->refresh();
if ($element->thumbnail_error !== null || ! filled($element->thumbnail_path)) {
return;
}
$element->thumbnail_source = $source;
$element->save();
}
private function rememberChoice(Composition $composition, string $source): void
{
$composition->refresh();
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Domain\Media;
class ThumbnailRef
{
public static function url(string $route, string $kind, int $id, mixed $path): ?string
{
if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
return null;
}
return route($route, ['kind' => $kind, 'subject' => $id]);
}
}
@@ -15,10 +15,12 @@
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PillarService;
use App\Domain\Catalog\ReleaseContent;
use App\Domain\Media\ThumbnailRef;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\ElementRevision;
use App\Filament\Support\MediaUploadLimit;
use App\Filament\Support\ReportsDomainRules;
use App\Jobs\DeriveThumbnail;
use Filament\Actions\Action;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\FileUpload;
@@ -102,9 +104,27 @@ public function form(Schema $schema): Schema
return $options;
})
->helperText('Wirkt auf die Suche und legt keine neue Fassung an.'),
FileUpload::make('thumbnail_upload')->label('Vorschaubild')
Placeholder::make('thumbnail_current')->label('Aktuelles Vorschaubild')->content(function (): HtmlString {
/** @var ContentElement $element */
$element = $this->getRecord();
$url = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
$caption = match ($element->thumbnail_source) {
'eigen' => 'Eigenes Vorschaubild.',
'datei' => 'Vorschaubild aus der Datei des Mediums.',
default => '',
};
if (is_string($element->thumbnail_source) && preg_match('/^frame:\d+@([\d.]+)$/', $element->thumbnail_source, $match) === 1) {
$caption = 'Vorschaubild aus dem Film bei '.$match[1].' Sekunden.';
}
if ($url === null) {
return new HtmlString('Noch kein Vorschaubild. Eine Filmstelle wählst du beim Ansehen des Mediums.');
}
return new HtmlString('<img src="'.e($url).'" alt="" style="width: 16rem; height: auto;">'.($caption !== '' ? '<p>'.e($caption).'</p>' : ''));
}),
FileUpload::make('thumbnail_upload')->label('Eigenes Vorschaubild')
->disk('cms_incoming')->directory('vorschau')->visibility('private')->image()
->helperText('Nur die Karte. Die Inhaltsfassung bleibt unverändert.'),
->helperText('Gilt für die Anzeige und als Vorschlag in Modulen und Programmen. Eine Filmstelle wählst du beim Ansehen. Speichern legt keine Fassung an.'),
CheckboxList::make('pillars')
->label('Fachliche Säulen')
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all())
@@ -209,10 +229,9 @@ protected function handleRecordUpdate(Model $record, array $data): Model
$record->save();
}
if (is_string($data['thumbnail_upload'] ?? null) && $data['thumbnail_upload'] !== '') {
$record->thumbnail_path = $data['thumbnail_upload'];
$record->thumbnail_error = null;
$record->thumbnail_alt = $record->working_title;
$record->save();
DeriveThumbnail::dispatch('element', $record->id, $data['thumbnail_upload']);
}
if (array_key_exists('dimension_ids', $data)) {
$ids = array_map(intval(...), $data['dimension_ids'] ?? []);
@@ -9,11 +9,13 @@
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PillarService;
use App\Domain\Media\ThumbnailRef;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\CatalogReading;
use App\Filament\Support\ElementRevision;
use App\Filament\Support\ReportsDomainRules;
use App\Http\Controllers\ContentPreviewController;
use App\Jobs\DeriveThumbnail;
use Filament\Actions\Action;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Textarea;
@@ -23,15 +25,26 @@
use Filament\Schemas\Schema;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Collection;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Livewire\WithFileUploads;
class ViewContentElement extends ViewRecord
{
use ReportsDomainRules;
use WithFileUploads;
protected static string $resource = ContentElementResource::class;
public ?int $fassung = null;
public string $frameSecond = '';
public string $thumbnailAlt = '';
public string $pictureFeedback = '';
public mixed $previewUpload = null;
public function mount(int|string $record): void
{
parent::mount($record);
@@ -41,6 +54,8 @@ public function mount(int|string $record): void
if ($requested > 0) {
$this->fassung = $requested;
}
$this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? '');
}
public function getSubheading(): string|Htmlable|null
@@ -61,6 +76,125 @@ public function showVersion(int $version): void
$this->fassung = $version;
}
public function adoptFrame(): void
{
abort_unless(ContentElementResource::editor(), 403);
/** @var ContentElement $element */
$element = $this->getRecord();
$shown = $this->shownVersion();
if (! $shown instanceof ContentElementVersion || $element->output_class !== 'film') {
$this->pictureFeedback = 'Für dieses Medium gibt es keine Filmstelle.';
return;
}
if (! is_numeric($this->frameSecond) || trim($this->frameSecond) === '') {
$this->pictureFeedback = 'Wähle zuerst eine Zeitposition.';
return;
}
$seconds = (float) $this->frameSecond;
if ($seconds < 0 || $seconds > 7200) {
$this->pictureFeedback = 'Die Zeitposition liegt außerhalb des Films.';
return;
}
$this->keepAlt($element);
$element->thumbnail_error = null;
$element->save();
DeriveThumbnail::dispatch('element', $element->id, null, null, $shown->id, $seconds);
$element->refresh();
$this->pictureFeedback = $element->thumbnail_error
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
}
public function storePreview(): void
{
abort_unless(ContentElementResource::editor(), 403);
if (! $this->previewUpload instanceof TemporaryUploadedFile) {
$this->pictureFeedback = 'Wähle zuerst eine Bilddatei.';
return;
}
$extension = strtolower($this->previewUpload->getClientOriginalExtension());
if (! in_array($extension, ['png', 'jpg', 'jpeg', 'webp'], true)) {
$this->pictureFeedback = 'Das Vorschaubild muss eine Bilddatei sein.';
return;
}
$path = $this->previewUpload->storeAs(
'vorschau',
'karte-'.bin2hex(random_bytes(4)).'.'.$extension,
'cms_incoming',
);
$this->previewUpload = null;
if (! is_string($path)) {
$this->pictureFeedback = 'Das Vorschaubild wurde nicht übernommen.';
return;
}
$this->savePreviewImage($path);
}
public function savePreviewImage(string $path): void
{
abort_unless(ContentElementResource::editor(), 403);
/** @var ContentElement $element */
$element = $this->getRecord();
$this->keepAlt($element);
$element->thumbnail_error = null;
$element->save();
DeriveThumbnail::dispatch('element', $element->id, $path);
$element->refresh();
$this->pictureFeedback = $element->thumbnail_error
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
}
public function useOwnImage(): void
{
abort_unless(ContentElementResource::editor(), 403);
/** @var ContentElement $element */
$element = $this->getRecord();
if ($element->output_class !== 'bild') {
$this->pictureFeedback = 'Die Datei dieses Mediums ist kein Bild. Lade ein Vorschaubild hoch.';
return;
}
$this->keepAlt($element);
$element->thumbnail_error = null;
$element->save();
DeriveThumbnail::dispatch('element', $element->id);
$element->refresh();
$this->pictureFeedback = $element->thumbnail_error
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
}
public function framePreviewUrl(): ?string
{
$shown = $this->shownVersion();
if (! $shown instanceof ContentElementVersion || ! is_numeric($this->frameSecond) || trim($this->frameSecond) === '') {
return null;
}
return route('editorial.frame', [
'version' => $shown->id,
'sekunde' => $this->frameSecond,
]);
}
public function deactivateAction(): Action
{
return Action::make('deactivate')
@@ -158,9 +292,52 @@ private function viewerData(): array
'pillars' => $element->pillars->pluck('name')->all(),
'usage' => app(CatalogReading::class)->elementUsage($element),
'canRevise' => ContentElementResource::editor(),
'pictureUrl' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
'pictureCaption' => $this->pictureCaption($element),
];
}
private function shownVersion(): ?ContentElementVersion
{
/** @var ContentElement $element */
$element = $this->getRecord();
$versions = $element->versions()->orderByDesc('number')->get();
return $versions->firstWhere('id', $this->fassung)
?? $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Bereit)
?? $versions->first();
}
private function keepAlt(ContentElement $element): void
{
$alt = trim($this->thumbnailAlt);
if ($alt === '') {
return;
}
$element->thumbnail_alt = $alt;
}
private function pictureCaption(ContentElement $element): string
{
$source = $element->thumbnail_source;
if (! is_string($source) || $source === '') {
return '';
}
if (preg_match('/^frame:\d+@([\d.]+)$/', $source, $match) === 1) {
return 'Vorschaubild aus dem Film bei '.$match[1].' Sekunden.';
}
return match ($source) {
'eigen' => 'Eigenes Vorschaubild.',
'datei' => 'Vorschaubild aus der Datei des Mediums.',
default => '',
};
}
private function ownedVersion(int $id): ?ContentElementVersion
{
/** @var ContentElement $element */
+111 -6
View File
@@ -645,17 +645,122 @@ public function cover(Composition $composition, array $members): array
return ['url' => $own, 'note' => null, 'own' => true];
}
$films = $this->filmPictures($members);
$picture = $this->suggestPicture($members);
if (count($films) === 1) {
if ($picture === null) {
return ['url' => null, 'note' => null, 'own' => false];
}
return [
'url' => $this->cardUrl($picture['kind'], $picture['subject'], 'vorschau/gesetzt'),
'note' => $picture['note'],
'own' => false,
];
}
/**
* Das eigene Titelbild, sonst das erste Vorschaubild aus dem freigegebenen Aufbau.
*
* @return array{kind: string, subject: int, alt: string, note: string}|null
*/
public function visiblePicture(Composition $composition, ?CompositionVersion $version): ?array
{
if ($this->cardUrl('komposition', $composition->id, $composition->thumbnail_path) !== null) {
return [
'url' => $films[0]['image'],
'note' => 'Vorschlag aus dem Film '.$films[0]['title'],
'own' => false,
'kind' => 'komposition',
'subject' => $composition->id,
'alt' => filled($composition->thumbnail_alt) ? (string) $composition->thumbnail_alt : $this->compositionTitle($composition),
'note' => '',
];
}
return ['url' => null, 'note' => null, 'own' => false];
if ($version === null) {
return null;
}
$version->loadMissing('members');
$members = [];
foreach ($version->members as $member) {
$members[] = [
'target' => $member->content_element_version_id
? 'element:'.$member->content_element_version_id
: 'composition:'.$member->nested_composition_version_id,
];
}
return $this->suggestPicture($members);
}
/**
* @param list<array<string, mixed>> $members
* @param list<int> $seen
* @return array{kind: string, subject: int, alt: string, note: string}|null
*/
private function suggestPicture(array $members, array $seen = []): ?array
{
foreach ($members as $member) {
$target = (string) ($member['target'] ?? '');
if (preg_match('/^element:(\d+)$/', $target, $match) === 1) {
$version = ContentElementVersion::query()->with('element')->find((int) $match[1]);
$element = $version?->element;
if (! $element instanceof ContentElement || $this->cardUrl('element', $element->id, $element->thumbnail_path) === null) {
continue;
}
$title = filled($element->display_title) ? $element->display_title : $element->working_title;
return [
'kind' => 'element',
'subject' => $element->id,
'alt' => filled($element->thumbnail_alt) ? (string) $element->thumbnail_alt : $title,
'note' => $element->output_class === 'film'
? 'Vorschlag aus dem Film '.$title
: 'Vorschlag aus '.$title,
];
}
if (preg_match('/^composition:(\d+)$/', $target, $match) !== 1 || in_array((int) $match[1], $seen, true)) {
continue;
}
$version = CompositionVersion::query()->with('composition', 'members')->find((int) $match[1]);
if (! $version instanceof CompositionVersion) {
continue;
}
$nested = $version->composition;
if ($this->cardUrl('komposition', $nested->id, $nested->thumbnail_path) !== null) {
return [
'kind' => 'komposition',
'subject' => $nested->id,
'alt' => filled($nested->thumbnail_alt) ? (string) $nested->thumbnail_alt : $this->compositionTitle($nested),
'note' => 'Vorschlag aus '.$this->compositionTitle($nested),
];
}
$children = [];
foreach ($version->members as $child) {
$children[] = [
'target' => $child->content_element_version_id
? 'element:'.$child->content_element_version_id
: 'composition:'.$child->nested_composition_version_id,
];
}
$picture = $this->suggestPicture($children, [...$seen, $version->id]);
if ($picture !== null) {
return $picture;
}
}
return null;
}
public function create(string $designation, CompositionKind $kind): Composition
+20
View File
@@ -7,6 +7,7 @@
use App\Domain\Catalog\CompositionDisplayRelease;
use App\Domain\Catalog\CompositionStructureReader;
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\ReleaseStatus;
use App\Domain\Catalog\StructureNode;
@@ -14,6 +15,8 @@
use App\Domain\Entitlement\Grant;
use App\Domain\Entitlement\GrantStatus;
use App\Domain\Media\MediaRendition;
use App\Domain\Media\ThumbnailRef;
use App\Filament\Support\EditorialCatalog;
use App\Models\User;
use Illuminate\Support\Collection;
@@ -41,6 +44,7 @@ public function index(User $user): array
$version = $release?->rootCompositionVersion;
if ($composition !== null && $version !== null && $this->display->isReleased($version)) {
$picture = app(EditorialCatalog::class)->visiblePicture($composition, $version);
$card = [
'composition' => $composition,
'version' => $version,
@@ -49,6 +53,11 @@ public function index(User $user): array
'kind' => $composition->editorialContentKind?->label
?? ($composition->kind?->label()),
'coverage' => $this->coverageLabel($user, $composition),
'image' => $picture['alt'] ?? null,
'image_url' => $picture === null ? null : route('member.thumbnail', [
'kind' => $picture['kind'],
'subject' => $picture['subject'],
]),
];
$shelf = $composition->editorialContentKind?->slug === 'modul' ? 'modules' : 'programs';
if ($shelf === 'modules') {
@@ -65,12 +74,15 @@ public function index(User $user): array
$key = $composition !== null
? 'komposition-'.$composition->id
: ($elementId !== null ? 'element-'.$elementId : 'artikel-'.$article->id);
$imageUrl = $element === null ? null : ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path);
$materials[$key] = [
'article' => $article,
'title' => app(CourseOutline::class)->title($article),
'summary' => $element?->summary ?? $composition?->summary,
'kind' => app(CourseOutline::class)->kindLabel($article),
'coverage' => 'nutzbar',
'image' => $imageUrl === null ? null : ($element->thumbnail_alt ?: $element->working_title),
'image_url' => $imageUrl,
];
}
@@ -98,6 +110,7 @@ public function program(User $user, Composition $composition): array
return [
'composition' => $composition,
'picture' => app(EditorialCatalog::class)->visiblePicture($composition, $version),
'title' => filled($composition->display_title) ? $composition->display_title : $composition->designation,
'summary' => $composition->summary,
'kind' => $composition->editorialContentKind?->label
@@ -120,10 +133,16 @@ private function present(User $user, StructureNode $node): array
$playback = 'file';
$poster = null;
if ($node->contentElementVersionId !== null) {
$view = $this->open($user, $node->contentElementVersionId, $this->viewAction($node->outputClass));
$download = $this->open($user, $node->contentElementVersionId, 'laden');
$playback = MediaRendition::masterPath($node->contentElementVersionId) !== null ? 'hls' : 'file';
if ($view !== null && $node->contentElementId !== null) {
$path = ContentElement::query()->whereKey($node->contentElementId)->value('thumbnail_path');
$poster = ThumbnailRef::url('member.thumbnail', 'element', $node->contentElementId, $path);
}
}
return [
@@ -133,6 +152,7 @@ private function present(User $user, StructureNode $node): array
'output_class' => $node->outputClass,
'playback' => $playback,
'view_url' => $view,
'poster_url' => $poster,
'download_url' => $download,
'program_url' => $this->programUrl($node),
'children' => array_map(
+23 -2
View File
@@ -4,6 +4,7 @@
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Media\ThumbnailDeriver;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
@@ -17,6 +18,8 @@ public function __construct(
public readonly int $subjectId,
public readonly ?string $incoming = null,
public readonly ?int $fromElement = null,
public readonly ?int $versionId = null,
public readonly ?float $atSecond = null,
) {}
public function handle(ThumbnailDeriver $deriver): void
@@ -47,8 +50,26 @@ public function handle(ThumbnailDeriver $deriver): void
$element = ContentElement::query()->find($this->subjectId);
if ($element !== null) {
$deriver->forElement($element);
if ($element === null) {
return;
}
if ($this->versionId !== null && $this->atSecond !== null) {
$version = ContentElementVersion::query()->find($this->versionId);
if ($version instanceof ContentElementVersion) {
$deriver->forElementFrame($element, $version, $this->atSecond);
}
return;
}
if (is_string($this->incoming)) {
$deriver->forElementUpload($element, $this->incoming);
return;
}
$deriver->forElement($element);
}
}
@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('content_elements', function (Blueprint $table) {
$table->string('thumbnail_source')->nullable()->after('thumbnail_alt');
});
}
public function down(): void
{
Schema::table('content_elements', function (Blueprint $table) {
$table->dropColumn('thumbnail_source');
});
}
};
+2 -1
View File
@@ -1,11 +1,12 @@
@php
$metadata = is_array($version->metadata) ? $version->metadata : [];
$class = $version->element->output_class;
$poster = \App\Domain\Media\ThumbnailRef::url('editorial.card', 'element', $version->element->id, $version->element->thumbnail_path);
@endphp
@if ($fileUrl)
@if ($class === 'film')
<video controls preload="metadata" playsinline src="{{ $fileUrl }}" style="width: 100%; max-height: 70vh; background: #111;"></video>
<video controls preload="metadata" playsinline @if ($poster) poster="{{ $poster }}" @endif src="{{ $fileUrl }}" style="width: 100%; max-height: 70vh; background: #111;"></video>
@elseif ($class === 'audio')
<audio controls preload="metadata" src="{{ $fileUrl }}" style="width: 100%;"></audio>
@elseif ($class === 'bild')
@@ -21,6 +21,46 @@
<p>{{ $pillars === [] ? 'Keiner Säule zugeordnet.' : implode(' · ', $pillars) }}</p>
</section>
@if ($canRevise || $pictureUrl)
<section style="display: grid; gap: 0.75rem; max-width: 40rem;">
<h2 style="font-size: 1.125rem; font-weight: 600;">Vorschaubild</h2>
<p>Gilt für die Anzeige dieses Mediums und als Vorschlag in Modulen und Programmen, solange die dort kein eigenes Titelbild haben. Eine Inhaltsfassung entsteht dabei nicht.</p>
@if ($pictureUrl)
<img src="{{ $pictureUrl }}" alt="{{ $element->thumbnail_alt ?: $element->working_title }}" style="width: 100%; max-width: 28rem; height: auto; background: #111;">
@else
<p>Noch kein Vorschaubild.</p>
@endif
@if ($pictureCaption !== '')
<p>{{ $pictureCaption }}</p>
@endif
@if ($this->pictureFeedback !== '')
<p role="status">{{ $this->pictureFeedback }}</p>
@endif
@if ($canRevise)
<label for="bild-alternativ">Alternativtext</label>
<input id="bild-alternativ" type="text" wire:model="thumbnailAlt" placeholder="Was das Bild zeigt">
@if ($element->output_class === 'film' && $shown)
<div x-data="{ second: {{ json_encode($this->frameSecond) }} }">
<label for="filmstelle">Zeitposition in Sekunden</label>
<input id="filmstelle" type="range" min="0" max="120" step="0.5" x-model="second" @change="$wire.set('frameSecond', second)">
<input type="number" min="0" max="7200" step="0.1" x-model="second" @change="$wire.set('frameSecond', second)" aria-label="Zeitposition als Zahl">
</div>
<p>Die Vorschau nimmt die kleine Filmstufe, sofern sie vorliegt. Die Filmdatei selbst bleibt unverändert.</p>
@if ($frameUrl = $this->framePreviewUrl())
<img src="{{ $frameUrl }}" alt="Vorschau der gewählten Filmstelle" style="width: 100%; max-width: 28rem; height: auto;">
@endif
<button type="button" wire:click="adoptFrame">Diese Stelle übernehmen</button>
@endif
@if ($element->output_class === 'bild')
<button type="button" wire:click="useOwnImage">Die Bilddatei verwenden</button>
@endif
<label for="vorschau-bild">Eigenes Vorschaubild</label>
<input id="vorschau-bild" type="file" accept="image/png,image/jpeg,image/webp" wire:model="previewUpload">
<button type="button" wire:click="storePreview">Bild übernehmen</button>
@endif
</section>
@endif
<section style="display: grid; gap: 0.75rem;">
@if ($shown === null)
<p>Noch keine Fassung.</p>
+1 -1
View File
@@ -28,7 +28,7 @@
@endif
@if ($entry['playable'])
<div class="player">
<video controls preload="metadata" playsinline @if (($entry['playback'] ?? 'file') === 'hls') data-hls="{{ $entry['url'] }}" @else src="{{ $entry['url'] }}" @endif></video>
<video controls preload="metadata" playsinline @if ($poster = \App\Domain\Media\ThumbnailRef::url('member.thumbnail', 'element', $entry['version']->element->id, $entry['version']->element->thumbnail_path)) poster="{{ $poster }}" @endif @if (($entry['playback'] ?? 'file') === 'hls') data-hls="{{ $entry['url'] }}" @else src="{{ $entry['url'] }}" @endif></video>
<button class="button button-quiet" type="button" data-fullscreen>Vollbild</button>
</div>
@elseif ($entry['allowed'] && $entry['url'])
-4
View File
@@ -74,10 +74,6 @@
'href' => route('member.program', $program['composition']),
'card' => $program + [
'error' => $program['composition']->thumbnail_error,
'image' => filled($program['composition']->thumbnail_path) ? ($program['composition']->thumbnail_alt ?: 'Vorschaubild') : null,
'image_url' => str_starts_with((string) $program['composition']->thumbnail_path, 'vorschau/')
? route('member.thumbnail', ['kind' => 'komposition', 'subject' => $program['composition']->id])
: null,
],
])
@endforeach
@@ -20,7 +20,7 @@
@if ($node['output_class'] === 'audio')
<audio controls preload="metadata" src="{{ $node['view_url'] }}"></audio>
@else
<video controls preload="metadata" playsinline @if (($node['playback'] ?? 'file') === 'hls') data-hls="{{ $node['view_url'] }}" @else src="{{ $node['view_url'] }}" @endif></video>
<video controls preload="metadata" playsinline @if ($node['poster_url'] ?? null) poster="{{ $node['poster_url'] }}" @endif @if (($node['playback'] ?? 'file') === 'hls') data-hls="{{ $node['view_url'] }}" @else src="{{ $node['view_url'] }}" @endif></video>
<button class="button button-quiet" type="button" data-fullscreen>Vollbild</button>
@endif
</div>
+2 -2
View File
@@ -34,8 +34,8 @@
<div>
<dt>Vorschaubild</dt>
<dd>
@if (str_starts_with((string) $composition->thumbnail_path, 'vorschau/'))
<img src="{{ route('member.thumbnail', ['kind' => 'komposition', 'subject' => $composition->id]) }}" alt="{{ $composition->thumbnail_alt ?: 'Vorschaubild' }}">
@if ($picture)
<img src="{{ route('member.thumbnail', ['kind' => $picture['kind'], 'subject' => $picture['subject']]) }}" alt="{{ $picture['alt'] ?: 'Vorschaubild' }}">
@else
Platzhalter
@endif
+2 -1
View File
@@ -369,8 +369,9 @@ public function test_a_chosen_picture_and_description_do_not_create_a_version():
->assertSee('Lara im Hof')
->assertDontSee('Anzeige speichern')
->assertDontSee('Titelbild speichern')
->assertDontSee('Vorschlag aus dem Film')
->assertSee('Vorschlag aus dem Film Lara im Park')
->call('adoptPicture', $first->element->id)
->assertDontSee('Vorschlag aus dem Film')
->assertSet('feedback', 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.')
->set('description', 'Eine fachliche Beschreibung für die Bibliothek.')
->set('summary', 'Kurzer Kartentext')
+67
View File
@@ -10,6 +10,7 @@
use App\Domain\Entitlement\GrantIssuer;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class LibraryProgramTest extends TestCase
@@ -67,4 +68,70 @@ public function test_a_released_program_shows_its_structure_and_an_unreleased_on
->assertSee('Laden')
->assertSee('<video', false);
}
public function test_a_medium_preview_fills_the_program_until_the_program_has_its_own(): void
{
Storage::fake('media_derived');
$content = app(ContentService::class);
$film = $content->publishElementVersion(
$content->createElement('film', 'film', 'Hofszene'),
null,
['file' => 'inhalte/hof.mp4'],
);
$film->element->thumbnail_path = 'vorschau/element-'.$film->element->id.'.jpg';
$film->element->thumbnail_alt = 'Hofbild';
$film->element->save();
$image = imagecreatetruecolor(4, 4);
ob_start();
imagejpeg($image);
Storage::disk('media_derived')->put($film->element->thumbnail_path, ob_get_clean());
imagedestroy($image);
$programm = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
$released = $content->publishComposition(
tap($content->createComposition('Sicher auf dem Schulweg'), function ($item) use ($programm): void {
$item->editorial_content_kind_id = $programm->id;
$item->save();
}),
[['role' => 'Film', 'target' => $film]],
);
$articles = app(ArticleService::class);
$article = $articles->create('sichtbar-bild');
$articles->publishRelease($article, $released, 'Programmartikel.');
$offers = app(OfferService::class);
$rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen', 'laden']]);
$offer = $offers->create('Programmzugang Bild');
$offers->activate($offer, [
['target' => $article->fresh(), 'rights' => $rights],
], ['grant_kind' => 'auf_abruf']);
$member = User::factory()->create();
app(GrantIssuer::class)->claim($member, $offer);
app(CompositionDisplayRelease::class)->release($released, $member);
$elementUrl = route('member.thumbnail', ['kind' => 'element', 'subject' => $film->element->id]);
$this->actingAs($member)
->get(route('member.program', $released->composition))
->assertOk()
->assertSee($elementUrl, false)
->assertSee('poster="'.$elementUrl.'"', false)
->assertDontSee('Platzhalter');
$this->actingAs($member)
->get(route('member.library'))
->assertSee($elementUrl, false);
$this->actingAs($member)->get($elementUrl)->assertOk();
$composition = $released->composition;
$composition->thumbnail_path = 'vorschau/komposition-'.$composition->id.'.jpg';
$composition->thumbnail_alt = 'Programmbild';
$composition->save();
Storage::disk('media_derived')->put($composition->thumbnail_path, Storage::disk('media_derived')->get($film->element->thumbnail_path));
$programUrl = route('member.thumbnail', ['kind' => 'komposition', 'subject' => $composition->id]);
$this->actingAs($member)
->get(route('member.library'))
->assertSee($programUrl, false)
->assertDontSee($elementUrl, false);
}
}
+100
View File
@@ -3,6 +3,7 @@
namespace Tests\Feature;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Media\MediaRendition;
@@ -312,4 +313,103 @@ public function test_a_frame_uses_the_small_film_rendition_when_it_exists(): voi
app(ThumbnailDeriver::class)->frameInput($version),
);
}
public function test_a_chosen_film_frame_becomes_the_medium_preview_without_a_new_version(): void
{
Storage::fake('media_derived');
Storage::fake('cms_incoming');
$image = imagecreatetruecolor(4, 4);
ob_start();
imagejpeg($image);
$jpeg = ob_get_clean();
imagedestroy($image);
$this->app->bind(ThumbnailDeriver::class, fn () => new class($jpeg) extends ThumbnailDeriver
{
public function __construct(private string $jpeg) {}
public function jpegAtVersion(ContentElementVersion $version, float $seconds): ?string
{
return $this->jpeg;
}
});
$content = app(ContentService::class);
$element = $content->createElement('film', 'film', 'Hofszene');
$version = $content->publishElementVersion($element, 'Film', ['file' => 'inhalte/hof.mp4']);
$hash = $version->content_hash;
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
Livewire::actingAs($editor, 'staff')
->test(ViewContentElement::class, ['record' => $element->getKey()])
->assertSee('Diese Stelle übernehmen')
->call('adoptFrame')
->assertSet('pictureFeedback', 'Wähle zuerst eine Zeitposition.')
->set('frameSecond', '12.5')
->call('adoptFrame')
->assertSet('pictureFeedback', 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.');
$element->refresh();
$version->refresh();
$this->assertSame(1, $element->versions()->count());
$this->assertSame($hash, $version->content_hash);
$this->assertSame('vorschau/element-'.$element->id.'.jpg', $element->thumbnail_path);
$this->assertSame('frame:'.$version->id.'@12.5', $element->thumbnail_source);
Storage::disk('media_derived')->assertExists($element->thumbnail_path);
$this->get('/medien/'.$element->thumbnail_path)->assertNotFound();
$this->actingAs($editor, 'staff')
->get(route('editorial.card', ['kind' => 'element', 'subject' => $element->id]))
->assertOk();
$module = $content->publishComposition(
$content->createComposition('Modul mit Hofszene', CompositionKind::Uebung),
[['role' => 'Film', 'target' => $version]],
);
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->composition_id])
->assertSee('Vorschlag aus dem Film Hofszene');
}
public function test_an_uploaded_preview_and_an_image_file_stay_on_the_medium(): void
{
Storage::fake('media_derived');
Storage::fake('cms_incoming');
$image = imagecreatetruecolor(8, 8);
ob_start();
imagepng($image);
$png = ob_get_clean();
imagedestroy($image);
Storage::disk('cms_incoming')->put('vorschau/karte.png', $png);
Storage::disk('media_derived')->put('inhalte/bild.png', $png);
$content = app(ContentService::class);
$text = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$picture = $content->publishElementVersion(
$content->createElement('bild', 'bild', 'Kartenbild'),
null,
['file' => 'inhalte/bild.png'],
);
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
$this->actingAs($editor, 'staff');
Livewire::test(ViewContentElement::class, ['record' => $text->element->getKey()])
->call('savePreviewImage', 'vorschau/karte.png')
->assertSet('pictureFeedback', 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.');
$text->element->refresh();
$this->assertSame(1, $text->element->versions()->count());
$this->assertSame('eigen', $text->element->thumbnail_source);
$this->assertSame('vorschau/element-'.$text->element->id.'.jpg', $text->element->thumbnail_path);
Livewire::test(ViewContentElement::class, ['record' => $picture->element->getKey()])
->call('useOwnImage')
->assertSet('pictureFeedback', 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.');
$picture->element->refresh();
$this->assertSame(1, $picture->element->versions()->count());
$this->assertSame('datei', $picture->element->thumbnail_source);
Storage::disk('media_derived')->assertExists($picture->element->thumbnail_path);
}
}