diff --git a/app/Domain/Catalog/ContentElement.php b/app/Domain/Catalog/ContentElement.php index f78a422..178dee3 100644 --- a/app/Domain/Catalog/ContentElement.php +++ b/app/Domain/Catalog/ContentElement.php @@ -20,6 +20,7 @@ class ContentElement extends Model 'summary', 'thumbnail_path', 'thumbnail_alt', + 'thumbnail_source', 'thumbnail_error', 'editorial_content_kind_id', 'archived_at', diff --git a/app/Domain/Media/ThumbnailDeriver.php b/app/Domain/Media/ThumbnailDeriver.php index 603f32a..fdd7b1b 100644 --- a/app/Domain/Media/ThumbnailDeriver.php +++ b/app/Domain/Media/ThumbnailDeriver.php @@ -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(); diff --git a/app/Domain/Media/ThumbnailRef.php b/app/Domain/Media/ThumbnailRef.php new file mode 100644 index 0000000..ba80801 --- /dev/null +++ b/app/Domain/Media/ThumbnailRef.php @@ -0,0 +1,15 @@ + $kind, 'subject' => $id]); + } +} diff --git a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php index f643434..0039bdb 100644 --- a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php @@ -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(''.($caption !== '' ? '

'.e($caption).'

' : '')); + }), + 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'] ?? []); diff --git a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php index f23e25d..1124fc5 100644 --- a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php @@ -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 */ diff --git a/app/Filament/Support/EditorialCatalog.php b/app/Filament/Support/EditorialCatalog.php index 5428930..1cb8b73 100644 --- a/app/Filament/Support/EditorialCatalog.php +++ b/app/Filament/Support/EditorialCatalog.php @@ -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> $members + * @param list $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 diff --git a/app/Http/LibraryCatalog.php b/app/Http/LibraryCatalog.php index fc44d0f..48de14a 100644 --- a/app/Http/LibraryCatalog.php +++ b/app/Http/LibraryCatalog.php @@ -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( diff --git a/app/Jobs/DeriveThumbnail.php b/app/Jobs/DeriveThumbnail.php index d90b281..60a3c09 100644 --- a/app/Jobs/DeriveThumbnail.php +++ b/app/Jobs/DeriveThumbnail.php @@ -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); } } diff --git a/database/migrations/2026_11_16_220000_add_thumbnail_source_to_content_elements.php b/database/migrations/2026_11_16_220000_add_thumbnail_source_to_content_elements.php new file mode 100644 index 0000000..1a01299 --- /dev/null +++ b/database/migrations/2026_11_16_220000_add_thumbnail_source_to_content_elements.php @@ -0,0 +1,22 @@ +string('thumbnail_source')->nullable()->after('thumbnail_alt'); + }); + } + + public function down(): void + { + Schema::table('content_elements', function (Blueprint $table) { + $table->dropColumn('thumbnail_source'); + }); + } +}; diff --git a/resources/views/content/player.blade.php b/resources/views/content/player.blade.php index cb3a4e4..d9c3e33 100644 --- a/resources/views/content/player.blade.php +++ b/resources/views/content/player.blade.php @@ -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') - + @elseif ($class === 'audio') @elseif ($class === 'bild') diff --git a/resources/views/filament/media/viewer.blade.php b/resources/views/filament/media/viewer.blade.php index 1b12ca7..0dce912 100644 --- a/resources/views/filament/media/viewer.blade.php +++ b/resources/views/filament/media/viewer.blade.php @@ -21,6 +21,46 @@

{{ $pillars === [] ? 'Keiner Säule zugeordnet.' : implode(' · ', $pillars) }}

+ @if ($canRevise || $pictureUrl) +
+

Vorschaubild

+

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.

+ @if ($pictureUrl) + {{ $element->thumbnail_alt ?: $element->working_title }} + @else +

Noch kein Vorschaubild.

+ @endif + @if ($pictureCaption !== '') +

{{ $pictureCaption }}

+ @endif + @if ($this->pictureFeedback !== '') +

{{ $this->pictureFeedback }}

+ @endif + @if ($canRevise) + + + @if ($element->output_class === 'film' && $shown) +
+ + + +
+

Die Vorschau nimmt die kleine Filmstufe, sofern sie vorliegt. Die Filmdatei selbst bleibt unverändert.

+ @if ($frameUrl = $this->framePreviewUrl()) + Vorschau der gewählten Filmstelle + @endif + + @endif + @if ($element->output_class === 'bild') + + @endif + + + + @endif +
+ @endif +
@if ($shown === null)

Noch keine Fassung.

diff --git a/resources/views/member/article.blade.php b/resources/views/member/article.blade.php index 28f98b1..a4e0c96 100644 --- a/resources/views/member/article.blade.php +++ b/resources/views/member/article.blade.php @@ -28,7 +28,7 @@ @endif @if ($entry['playable'])
- +
@elseif ($entry['allowed'] && $entry['url']) diff --git a/resources/views/member/library.blade.php b/resources/views/member/library.blade.php index 4111176..07117d7 100644 --- a/resources/views/member/library.blade.php +++ b/resources/views/member/library.blade.php @@ -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 diff --git a/resources/views/member/partials/structure.blade.php b/resources/views/member/partials/structure.blade.php index 7af0825..d2490d0 100644 --- a/resources/views/member/partials/structure.blade.php +++ b/resources/views/member/partials/structure.blade.php @@ -20,7 +20,7 @@ @if ($node['output_class'] === 'audio') @else - + @endif diff --git a/resources/views/member/program.blade.php b/resources/views/member/program.blade.php index 7dd0b88..3013ae1 100644 --- a/resources/views/member/program.blade.php +++ b/resources/views/member/program.blade.php @@ -34,8 +34,8 @@
Vorschaubild
- @if (str_starts_with((string) $composition->thumbnail_path, 'vorschau/')) - {{ $composition->thumbnail_alt ?: 'Vorschaubild' }} + @if ($picture) + {{ $picture['alt'] ?: 'Vorschaubild' }} @else Platzhalter @endif diff --git a/tests/Feature/EditorialEditorTest.php b/tests/Feature/EditorialEditorTest.php index ea1221e..7450540 100644 --- a/tests/Feature/EditorialEditorTest.php +++ b/tests/Feature/EditorialEditorTest.php @@ -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') diff --git a/tests/Feature/LibraryProgramTest.php b/tests/Feature/LibraryProgramTest.php index 74f2de8..d590cd1 100644 --- a/tests/Feature/LibraryProgramTest.php +++ b/tests/Feature/LibraryProgramTest.php @@ -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('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); + } } diff --git a/tests/Feature/MediaAdministrationTest.php b/tests/Feature/MediaAdministrationTest.php index c9d2eb2..ca07202 100644 --- a/tests/Feature/MediaAdministrationTest.php +++ b/tests/Feature/MediaAdministrationTest.php @@ -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); + } }