Fasse die Bearbeitung in Dialoge und übernimm eine Filmstelle als Titelbild.
Deploy Test / test (push) Successful in 23s
Deploy Test / deploy (push) Successful in 22s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-16 18:58:26 +01:00
1 parent 9195cdcd15
commit c47c3b9b32
9 files changed
+1052 -228

No files matched your search

+85
View File
@@ -58,6 +58,91 @@ public function forCompositionFromElement(Composition $composition, ContentEleme
$this->rememberChoice($composition, 'element:'.$element->id);
}
public function forCompositionFrame(Composition $composition, ContentElementVersion $version, float $seconds): void
{
$version->loadMissing('element');
if ($version->element?->output_class !== 'film') {
$this->failComposition($composition, 'Aus dieser Filmstelle ließ sich kein Titelbild erzeugen.');
return;
}
$bytes = $this->jpegAtVersion($version, $seconds);
if (! is_string($bytes)) {
$this->failComposition($composition, 'Aus dieser Filmstelle ließ sich kein Titelbild erzeugen.');
return;
}
$name = 'komposition-'.$composition->id;
$path = 'vorschau/'.$name.'.jpg';
Storage::disk('media_derived')->put($path, $bytes);
$this->still($composition, Storage::disk('media_derived'), $path, $name);
$this->rememberChoice($composition, 'frame:'.$version->id.'@'.$this->secondText($seconds));
}
public function jpegAtVersion(ContentElementVersion $version, float $seconds): ?string
{
$file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
if (! is_string($file) || $file === '' || str_contains($file, '..') || ! str_starts_with($file, 'inhalte/')) {
return null;
}
if ($seconds < 0 || $seconds > 7200) {
return null;
}
$disk = Storage::disk('media_derived');
if (! $disk->exists($file)) {
return null;
}
$binary = (new ExecutableFinder)->find('ffmpeg');
if ($binary === null) {
return null;
}
$process = new Process([
$binary,
'-hide_banner',
'-loglevel',
'error',
'-i',
$disk->path($file),
'-ss',
$this->secondText($seconds),
'-frames:v',
'1',
'-f',
'image2pipe',
'-vcodec',
'mjpeg',
'pipe:1',
]);
$process->setTimeout(30);
$process->run();
$bytes = $process->getOutput();
if (! $process->isSuccessful() || ! str_starts_with($bytes, "\xFF\xD8")) {
return null;
}
return $bytes;
}
private function secondText(float $seconds): string
{
$seconds = max(0, min(7200, $seconds));
$text = number_format($seconds, 3, '.', '');
return rtrim(rtrim($text, '0'), '.') ?: '0';
}
private function frame(ContentElement $element, string $file): void
{
$binary = (new ExecutableFinder)->find('ffmpeg');
@@ -20,6 +20,8 @@
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Catalog\StructureNode;
use App\Filament\Support\EditorialCatalog;
use App\Http\Controllers\ContentPreviewController;
use App\Jobs\DeriveCompositionFrame;
use App\Jobs\DeriveThumbnail;
use App\Models\User;
use Filament\Actions\Action;
@@ -101,6 +103,26 @@ abstract class EditComposition extends EditRecord
public string $imageQuery = '';
public bool $moduleOpen = false;
public string $moduleTab = 'beschreibung';
public bool $partOpen = false;
public string $imageMode = 'film';
public string $imagePick = '';
public ?int $frameVersionId = null;
public string $frameSecond = '';
/** @var array<string, mixed> */
public array $moduleSnapshot = [];
/** @var list<array<string, mixed>> */
public array $partSnapshot = [];
/** @var list<array<string, string|null>> */
public array $members = [];
@@ -260,6 +282,14 @@ public function hits(): array
public function openPicker(): void
{
if ($this->moduleOpen) {
$this->closeModule();
}
if ($this->partOpen) {
$this->closePart();
}
$this->pickerOpen = true;
$this->textOpen = false;
$this->pickerSelected = '';
@@ -296,15 +326,67 @@ public function pickerDetail(): ?array
return null;
}
return app(EditorialCatalog::class)->rowForTarget(
$row = app(EditorialCatalog::class)->rowForTarget(
$this->pickerSelected,
(int) $this->getRecord()->getKey(),
);
if ($row === null) {
return null;
}
$row['file_url'] = null;
if (preg_match('/^element:(\d+)$/', (string) $row['target'], $match) === 1) {
$version = ContentElementVersion::query()->find($match[1]);
$row['file_url'] = $version instanceof ContentElementVersion
? app(ContentPreviewController::class)->fileUrl($version)
: null;
}
return $row;
}
/**
* @return list<array{target: string, label: string, current: bool}>
*/
public function pickerVersions(): array
{
$detail = $this->pickerDetail();
if ($detail === null) {
return [];
}
$options = app(EditorialCatalog::class)->alternatives(
(string) ($detail['identity'] ?? ''),
(int) $this->getRecord()->getKey(),
);
if ($options === []) {
return [];
}
$current = $options[array_key_last($options)]['target'];
return array_map(
fn (array $option): array => $option + ['current' => $option['target'] === $current],
$options,
);
}
public function pickerMatches(string $identity): bool
{
$detail = $this->pickerDetail();
return $detail !== null && ($detail['identity'] ?? '') === $identity;
}
public function openText(): void
{
$this->pickerOpen = false;
$this->moduleOpen = false;
$this->partOpen = false;
$this->textOpen = true;
}
@@ -611,7 +693,12 @@ public function addPart(string $target): void
$this->search = '';
$this->pickerOpen = false;
$this->pickerSelected = '';
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die Datei wird nicht kopiert. Gespeichert ist das erst mit „Entwurf speichern“.';
if (! $this->persistDraft()) {
return;
}
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die Datei wird nicht kopiert. Der Entwurf ist gespeichert. Es entsteht keine neue Fassung.';
}
public function removePart(int $index): void
@@ -625,7 +712,9 @@ public function removePart(int $index): void
$this->selected = null;
$this->roleDraft = '';
$this->panel = 'angaben';
$this->feedback = 'Der Bestandteil ist aus dem Arbeitsstand genommen. Gespeichert ist das erst mit einer neuen Fassung.';
$this->partOpen = false;
$this->partSnapshot = [];
$this->feedback = 'Der Bestandteil ist aus dem Arbeitsstand genommen. Entwurf speichern hält das fest. Eine freigegebene Fassung bleibt unverändert.';
}
public function movePart(int $index, int $direction): void
@@ -663,7 +752,7 @@ public function useVersion(int $index, string $target): void
$row['role'] = $this->members[$index]['role'] ?? $row['kind'];
$this->members[$index] = $row;
$this->syncRoleDraft();
$this->feedback = $row['version_label'].' ist für diese Stelle ausgewählt. Übernehmen legt dafür eine neue Fassung an.';
$this->feedback = $row['version_label'].' ist für diese Stelle ausgewählt. Der Entwurf speichert das. Eine freigegebene Fassung bleibt unverändert.';
}
public function loadTemplate(int $versionId): void
@@ -678,7 +767,7 @@ public function loadTemplate(int $versionId): void
$this->applyVersion($version);
$this->templateNumber = $version->number;
$this->feedback = 'Fassung '.$version->number.' ist als Arbeitsstand geladen. Übernehmen legt eine neue Fassung an und lässt die geladene Fassung unverändert.';
$this->feedback = 'Fassung '.$version->number.' ist als Arbeitsstand geladen. Die geladene Fassung bleibt unverändert.';
}
public function addText(): void
@@ -706,7 +795,7 @@ public function addText(): void
$this->newTextBody = '';
$this->textOpen = false;
$this->addPart('element:'.$version->id);
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Derselbe Text kann später woanders wiederverwendet werden. Gespeichert ist das erst mit „Entwurf speichern“.';
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Derselbe Text kann später woanders wiederverwendet werden. Der Entwurf ist gespeichert. Es entsteht keine neue Fassung dieses Eintrags.';
}
public function startModule(): void
@@ -727,27 +816,197 @@ public function startModule(): void
public function saveDisplay(): void
{
/** @var Composition $record */
$record = $this->getRecord();
$name = trim($this->designation);
if (! $this->persistPresentation()) {
return;
}
if ($name === '') {
$this->feedback = 'Der Name fehlt.';
$this->feedback = 'Die Anzeige ist gespeichert. Die Fassung bleibt unverändert.';
}
public function openModule(): void
{
$this->moduleSnapshot = [
'designation' => $this->designation,
'displayTitle' => $this->displayTitle,
'summary' => $this->summary,
'description' => $this->description,
'learningGoal' => $this->learningGoal,
'durationMinutes' => $this->durationMinutes,
'materialNote' => $this->materialNote,
'revisionNote' => $this->revisionNote,
'thumbnailAlt' => $this->thumbnailAlt,
'dimensionIds' => $this->dimensionIds,
'imageMode' => $this->imageMode,
'imagePick' => $this->imagePick,
'frameVersionId' => $this->frameVersionId,
'frameSecond' => $this->frameSecond,
];
$this->pickerOpen = false;
$this->partOpen = false;
$this->textOpen = false;
$this->moduleTab = 'beschreibung';
$films = $this->frameFilms();
$this->imageMode = $films === [] ? 'bestand' : 'film';
if ($films !== [] && $this->frameVersionId === null) {
$this->frameVersionId = $films[0]['version_id'];
}
$this->moduleOpen = true;
}
public function closeModule(): void
{
foreach ($this->moduleSnapshot as $key => $value) {
$this->{$key} = $value;
}
$this->moduleOpen = false;
$this->moduleSnapshot = [];
$this->previewUpload = null;
}
public function saveModule(): void
{
if ($this->minutes($this->durationMinutes) === false) {
$this->feedback = 'Der Zeitbedarf ist eine Zahl von Minuten oder bleibt leer.';
return;
}
$record->designation = $name;
app(IdentityProfile::class)->fill($record, [
'display_title' => $this->displayTitle,
'summary' => $this->summary,
'description' => $this->description,
'thumbnail_alt' => $this->thumbnailAlt,
], $this->actor());
$this->syncDimensions($record, array_map(intval(...), $this->dimensionIds));
$record->refresh();
$this->getRecord()->setRawAttributes($record->getAttributes());
$this->feedback = 'Die Anzeige ist gespeichert. Die Fassung bleibt unverändert.';
if (! $this->persistPresentation()) {
return;
}
$image = $this->applyChosenImage();
if ($image === false) {
return;
}
/** @var Composition $record */
$record = $this->getRecord();
if ($this->needsRevision() || app(EditorialWorkingDraft::class)->read($record) !== null) {
$this->persistDraft();
}
$this->moduleOpen = false;
$this->moduleSnapshot = [];
$this->previewUpload = null;
$this->imagePick = '';
$this->feedback = trim('Die Angaben sind übernommen. Es entsteht keine neue Fassung.'.($image === '' ? '' : ' '.$image));
}
public function openPart(int $index): void
{
$this->selectPart($index);
$this->partSnapshot = $this->members;
$this->moduleOpen = false;
$this->pickerOpen = false;
$this->textOpen = false;
$this->partOpen = true;
}
public function closePart(): void
{
if ($this->partSnapshot !== []) {
$this->members = $this->partSnapshot;
}
$this->partOpen = false;
$this->partSnapshot = [];
$this->syncRoleDraft();
}
public function savePart(): void
{
if (trim($this->roleDraft) === '') {
$this->feedback = 'Die Rolle fehlt.';
return;
}
$this->commitRoleDraft();
if (! $this->persistDraft()) {
return;
}
$this->partOpen = false;
$this->partSnapshot = [];
$this->feedback = 'Die Angaben zum Bestandteil sind im Entwurf. Es entsteht keine neue Fassung.';
}
/**
* @return list<array{version_id: int, title: string, label: string, file_url: ?string}>
*/
public function frameFilms(): array
{
$preview = app(ContentPreviewController::class);
$films = [];
foreach ($this->members as $member) {
if (preg_match('/^element:(\d+)$/', (string) ($member['target'] ?? ''), $match) !== 1) {
continue;
}
$version = ContentElementVersion::query()->with('element')->find($match[1]);
if (! $version instanceof ContentElementVersion || $version->element?->output_class !== 'film') {
continue;
}
$films[] = [
'version_id' => $version->id,
'title' => (string) ($member['title'] ?? $version->element->working_title),
'label' => 'Fassung '.$version->number,
'file_url' => $preview->fileUrl($version),
];
}
return $films;
}
public function framePreviewUrl(): ?string
{
if ($this->frameVersionId === null || ! is_numeric($this->frameSecond) || trim($this->frameSecond) === '') {
return null;
}
return route('editorial.frame', [
'version' => $this->frameVersionId,
'sekunde' => $this->frameSecond,
]);
}
public function imageCaption(): ?string
{
/** @var Composition $composition */
$composition = $this->getRecord();
$composition->refresh();
$source = $composition->thumbnail_source;
if (! is_string($source) || $source === '') {
return null;
}
if (preg_match('/^frame:(\d+)@([\d.]+)$/', $source, $match) === 1) {
$version = ContentElementVersion::query()->with('element')->find($match[1]);
$title = $version?->element?->working_title ?: 'dem Film';
return 'Titelbild aus '.$title.' bei '.$match[2].' Sekunden.';
}
if ($source === 'eigen') {
return 'Eigenes Titelbild.';
}
if (str_starts_with($source, 'element:')) {
return 'Titelbild aus einem vorhandenen Bild.';
}
return null;
}
public function savePreview(): void
@@ -1228,6 +1487,120 @@ protected function syncDimensions(Composition $composition, array $ids): void
}
}
protected function persistPresentation(): bool
{
/** @var Composition $record */
$record = $this->getRecord();
$name = trim($this->designation);
if ($name === '') {
$this->feedback = 'Der Name fehlt.';
return false;
}
$record->designation = $name;
app(IdentityProfile::class)->fill($record, [
'display_title' => $this->displayTitle,
'summary' => $this->summary,
'description' => $this->description,
'thumbnail_alt' => $this->thumbnailAlt,
], $this->actor());
$this->syncDimensions($record, array_map(intval(...), $this->dimensionIds));
$record->refresh();
$this->getRecord()->setRawAttributes($record->getAttributes());
return true;
}
protected function persistDraft(): bool
{
if ($this->minutes($this->durationMinutes) === false) {
$this->feedback = 'Der Zeitbedarf ist eine Zahl von Minuten oder bleibt leer.';
return false;
}
/** @var Composition $record */
$record = $this->getRecord();
app(EditorialWorkingDraft::class)->write($record, $this->payload());
return true;
}
protected function applyChosenImage(): string|false
{
if ($this->imageMode === 'upload' && $this->previewUpload instanceof TemporaryUploadedFile) {
$extension = strtolower($this->previewUpload->getClientOriginalExtension());
if (! in_array($extension, ['png', 'jpg', 'jpeg', 'webp'], true)) {
$this->feedback = 'Das Vorschaubild muss eine Bilddatei sein.';
return false;
}
$path = $this->previewUpload->storeAs(
'vorschau',
'karte-'.bin2hex(random_bytes(4)).'.'.$extension,
'cms_incoming',
);
$this->previewUpload = null;
if (! is_string($path)) {
$this->feedback = 'Das Vorschaubild wurde nicht übernommen.';
return false;
}
$this->storePreview($path);
return str_contains($this->feedback, 'unverändert') ? $this->feedback : false;
}
if ($this->imageMode === 'bestand' && ctype_digit($this->imagePick)) {
$this->adoptPicture((int) $this->imagePick);
return str_contains($this->feedback, 'unverändert') ? $this->feedback : false;
}
if ($this->imageMode === 'film' && $this->frameVersionId !== null && trim($this->frameSecond) !== '') {
if (! is_numeric($this->frameSecond) || (float) $this->frameSecond < 0 || (float) $this->frameSecond > 7200) {
$this->feedback = 'Die Zeitposition muss eine Zahl in Sekunden sein.';
return false;
}
$version = ContentElementVersion::query()->with('element')->find($this->frameVersionId);
$target = 'element:'.(int) $this->frameVersionId;
$known = array_map(fn (array $member): string => (string) ($member['target'] ?? ''), $this->members);
if (! $version instanceof ContentElementVersion || $version->element?->output_class !== 'film' || ! in_array($target, $known, true)) {
$this->feedback = 'Die Filmfassung gehört nicht zu diesem Aufbau.';
return false;
}
/** @var Composition $record */
$record = $this->getRecord();
$before = $record->versions()->count();
DeriveCompositionFrame::dispatch($record->id, $version->id, (float) $this->frameSecond);
$record->refresh();
$this->thumbnailPath = $record->thumbnail_path;
$this->thumbnailError = $record->thumbnail_error;
$note = $this->previewFeedback($record, $before);
if (! str_contains($note, 'unverändert')) {
$this->feedback = $note;
return false;
}
return $note;
}
return '';
}
protected function storePreview(string $path): void
{
if (! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
+12 -4
View File
@@ -205,12 +205,16 @@ public function browse(string $query, string $kind, string $dimension, int $exce
$dimensionId = ctype_digit($dimension) ? (int) $dimension : 0;
if ($kind !== 'modul') {
$elements = ContentElementVersion::query()
$latestElements = ContentElementVersion::query()
->selectRaw('MAX(id)')
->where('status', ContentVersionStatus::Bereit)
->with('element.editorialContentKind')
->whereHas('element', function ($builder) use ($query, $like, $kind, $dimensionId): void {
$this->constrainElement($builder, $query, $like, $kind, $dimensionId);
})
->groupBy('content_element_id');
$elements = ContentElementVersion::query()
->with('element.editorialContentKind')
->whereIn('id', $latestElements)
->orderByDesc('id')
->limit($limit + 1)
->get();
@@ -225,10 +229,10 @@ public function browse(string $query, string $kind, string $dimension, int $exce
}
if (in_array($kind, ['alle', 'modul'], true)) {
$versions = CompositionVersion::query()
$latestCompositions = CompositionVersion::query()
->selectRaw('MAX(id)')
->where('status', ContentVersionStatus::Bereit)
->where('composition_id', '!=', $exceptCompositionId)
->with('composition.editorialContentKind')
->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId): void {
if ($kind === 'modul') {
$builder->where('kind', CompositionKind::Uebung);
@@ -248,6 +252,10 @@ public function browse(string $query, string $kind, string $dimension, int $exce
->orWhere('summary', 'like', $like);
});
})
->groupBy('composition_id');
$versions = CompositionVersion::query()
->with('composition.editorialContentKind')
->whereIn('id', $latestCompositions)
->orderByDesc('id')
->limit($limit + 1)
->get();
@@ -10,8 +10,11 @@
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\StructureNode;
use App\Domain\Identity\StaffRole;
use App\Domain\Media\ThumbnailDeriver;
use App\Filament\Support\EditorialCatalog;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -146,6 +149,23 @@ private function render(
]);
}
public function frame(ContentElementVersion $version, Request $request): Response
{
$this->authorizeStaff();
$version->loadMissing('element');
abort_unless($version->element?->output_class === 'film', 404);
$seconds = $request->query('sekunde');
abort_unless(is_numeric($seconds), 404);
$bytes = app(ThumbnailDeriver::class)->jpegAtVersion($version, (float) $seconds);
abort_unless(is_string($bytes), 404);
return response($bytes, 200, [
'Content-Type' => 'image/jpeg',
'Cache-Control' => 'private, no-store',
]);
}
/**
* @return array<string, mixed>
*/
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace App\Jobs;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Media\ThumbnailDeriver;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
class DeriveCompositionFrame implements ShouldQueue
{
use Queueable;
public function __construct(
public readonly int $compositionId,
public readonly int $versionId,
public readonly float $atSecond,
) {}
public function handle(ThumbnailDeriver $deriver): void
{
$composition = Composition::query()->find($this->compositionId);
$version = ContentElementVersion::query()->find($this->versionId);
if (! $composition instanceof Composition || ! $version instanceof ContentElementVersion) {
return;
}
$deriver->forCompositionFrame($composition, $version, $this->atSecond);
}
}