diff --git a/app/Domain/Catalog/Composition.php b/app/Domain/Catalog/Composition.php index 4911383..196f66d 100644 --- a/app/Domain/Catalog/Composition.php +++ b/app/Domain/Catalog/Composition.php @@ -12,8 +12,10 @@ class Composition extends Model 'designation', 'display_title', 'summary', + 'description', 'thumbnail_path', 'thumbnail_alt', + 'thumbnail_source', 'thumbnail_error', 'public_slug', 'kind', diff --git a/app/Domain/Media/ThumbnailDeriver.php b/app/Domain/Media/ThumbnailDeriver.php index 1f0bb41..6be195c 100644 --- a/app/Domain/Media/ThumbnailDeriver.php +++ b/app/Domain/Media/ThumbnailDeriver.php @@ -41,6 +41,21 @@ public function forCompositionUpload(Composition $composition, string $incoming) } $this->still($composition, Storage::disk('cms_incoming'), $incoming, 'komposition-'.$composition->id); + $this->rememberChoice($composition, 'eigen'); + } + + public function forCompositionFromElement(Composition $composition, ContentElement $element): void + { + $path = $element->thumbnail_path; + + if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) { + $this->failComposition($composition, 'Für dieses Medium liegt noch kein Vorschaubild vor.'); + + return; + } + + $this->still($composition, Storage::disk('media_derived'), $path, 'komposition-'.$composition->id); + $this->rememberChoice($composition, 'element:'.$element->id); } private function frame(ContentElement $element, string $file): void @@ -119,11 +134,27 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st $path = 'vorschau/'.$name.'.jpg'; Storage::disk('media_derived')->put($path, $bytes); $subject->thumbnail_path = $path; - $subject->thumbnail_alt = $subject instanceof Composition ? $subject->designation : $subject->working_title; + + if (! ($subject instanceof Composition && filled($subject->thumbnail_alt))) { + $subject->thumbnail_alt = $subject instanceof Composition ? $subject->designation : $subject->working_title; + } + $subject->thumbnail_error = null; $subject->save(); } + private function rememberChoice(Composition $composition, string $source): void + { + $composition->refresh(); + + if ($composition->thumbnail_error !== null || ! filled($composition->thumbnail_path)) { + return; + } + + $composition->thumbnail_source = $source; + $composition->save(); + } + private function fail(ContentElement $element, string $reason): void { $this->failSubject($element, $reason); diff --git a/app/Filament/Pages/EditorialDesk.php b/app/Filament/Pages/EditorialDesk.php index 51ee0cf..725b789 100644 --- a/app/Filament/Pages/EditorialDesk.php +++ b/app/Filament/Pages/EditorialDesk.php @@ -4,6 +4,9 @@ use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionKind; +use App\Domain\Catalog\ContentVersionStatus; +use App\Domain\Catalog\EditorialDimension; +use App\Domain\Catalog\IdentityDimensionValue; use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Support\EditorialCatalog; use Filament\Pages\Page; @@ -31,6 +34,12 @@ class EditorialDesk extends Page #[Url] public string $kindFilter = 'alle'; + #[Url] + public string $pillar = ''; + + #[Url] + public string $visibility = 'alle'; + public string $programName = ''; public string $moduleName = ''; @@ -58,18 +67,55 @@ public static function canAccess(): bool } /** - * @return list + * @return list}> + */ + public function dimensionFilters(): array + { + $groups = []; + + foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) { + $values = []; + + foreach ($dimension->values as $value) { + $values[] = ['id' => $value->id, 'label' => $value->label]; + } + + if ($values !== []) { + $groups[] = ['label' => $dimension->label, 'values' => $values]; + } + } + + return $groups; + } + + public function resetFilters(): void + { + $this->query = ''; + $this->kindFilter = 'alle'; + $this->pillar = ''; + $this->visibility = 'alle'; + } + + public function hasActiveFilters(): bool + { + return trim($this->query) !== '' || $this->kindFilter !== 'alle' || $this->pillar !== '' || $this->visibility !== 'alle'; + } + + /** + * @return list> */ public function entries(): array { $query = trim($this->query); $needle = mb_strtolower($query); $catalog = app(EditorialCatalog::class); + $offered = $catalog->offeredCompositionIds(); + $pillarIds = $this->pillar === '' ? null : $this->pillarSubjects((int) $this->pillar); $rows = []; $compositions = Composition::query() ->whereIn('kind', [CompositionKind::Kurs, CompositionKind::Uebung]) - ->with(['editorialContentKind', 'versions']) + ->with(['editorialContentKind', 'versions.members.contentElementVersion.element']) ->orderBy('designation') ->get(); @@ -77,7 +123,6 @@ public function entries(): array $kind = $composition->kind instanceof CompositionKind ? $composition->kind : CompositionKind::from((string) $composition->kind); - $label = $kind->deskLabel(); if ($this->kindFilter === 'programm' && $kind !== CompositionKind::Kurs) { continue; @@ -87,26 +132,98 @@ public function entries(): array continue; } + if ($pillarIds !== null && ! in_array($composition->id, $pillarIds, true)) { + continue; + } + + $stand = $catalog->stand($composition); + + if (! $this->matchesVisibility($stand)) { + continue; + } + $title = $catalog->compositionTitle($composition); - $haystack = mb_strtolower($title.' '.$composition->designation.' '.(string) $composition->summary); + $summary = (string) ($composition->summary ?? ''); + $haystack = mb_strtolower($title.' '.$composition->designation.' '.$summary.' '.(string) $composition->description); if ($needle !== '' && ! str_contains($haystack, $needle)) { continue; } + $cover = $catalog->cover($composition, $this->coverMembers($composition)); $rows[] = [ 'title' => $title, - 'kind' => $label, + 'kind' => $kind->deskLabel(), 'tone' => $kind === CompositionKind::Kurs ? 'programm' : 'modul', - 'stand' => $catalog->stand($composition)['text'], + 'summary' => $summary, 'url' => EditorialCatalog::editUrl($composition), - 'summary' => (string) ($composition->summary ?? ''), + 'image' => $cover['url'], + 'image_note' => $cover['note'], + 'chips' => $catalog->statusChips($composition, in_array($composition->id, $offered, true)), ]; } return $rows; } + /** + * @return list + */ + private function coverMembers(Composition $composition): array + { + $draft = $composition->working_draft; + + if (is_array($draft) && is_array($draft['members'] ?? null) && $draft['members'] !== []) { + return $draft['members']; + } + + $version = $composition->versions + ->filter(fn ($item): bool => $item->status === ContentVersionStatus::Bereit) + ->sortByDesc('number') + ->first(); + + if ($version === null) { + return []; + } + + $members = []; + + foreach ($version->members as $member) { + $target = $member->content_element_version_id + ? 'element:'.$member->content_element_version_id + : 'composition:'.$member->nested_composition_version_id; + $members[] = ['target' => $target]; + } + + return $members; + } + + /** + * @return list + */ + private function pillarSubjects(int $valueId): array + { + return IdentityDimensionValue::query() + ->where('subject_type', (new Composition)->getMorphClass()) + ->where('editorial_dimension_value_id', $valueId) + ->pluck('subject_id') + ->map(fn (mixed $id): int => (int) $id) + ->all(); + } + + /** + * @param array{text: string, number: int|null, released_number: int|null} $stand + */ + private function matchesVisibility(array $stand): bool + { + return match ($this->visibility) { + 'bibliothek' => $stand['released_number'] !== null, + 'verborgen' => $stand['number'] !== null && $stand['released_number'] === null, + 'entwurf' => $stand['number'] === null, + default => true, + }; + } + public function createProgram(): void { $this->create(CompositionKind::Kurs, $this->programName); diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index a982164..e626f89 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -7,6 +7,7 @@ use App\Domain\Catalog\CompositionKind; use App\Domain\Catalog\CompositionStructureReader; use App\Domain\Catalog\CompositionVersion; +use App\Domain\Catalog\ContentElement; use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; use App\Domain\Catalog\ContentVersionStatus; @@ -42,6 +43,8 @@ abstract class EditComposition extends EditRecord public string $summary = ''; + public string $description = ''; + public string $learningGoal = ''; public string $durationMinutes = ''; @@ -92,8 +95,12 @@ abstract class EditComposition extends EditRecord public ?string $thumbnailPath = null; + public string $thumbnailAlt = ''; + public ?string $thumbnailError = null; + public string $imageQuery = ''; + /** @var list> */ public array $members = []; @@ -150,10 +157,10 @@ protected function getHeaderActions(): array ->openUrlInNewTab() ->visible(fn (): bool => $this->previewUrl() !== null), Action::make('displayRelease') - ->label('Zur Anzeige freigeben') + ->label('In Mitgliederbibliothek anzeigen') ->requiresConfirmation() - ->modalHeading('Diese Fassung zur Anzeige freigeben') - ->modalDescription('Freigegeben wird die zuletzt übernommene Fassung. Eine frühere Fassung bleibt unverändert. Ungespeicherte Änderungen am Aufbau sind nicht Teil dieser Freigabe.') + ->modalHeading('In der Mitgliederbibliothek anzeigen') + ->modalDescription('Sichtbar wird die zuletzt übernommene Fassung. Das ist keine Website-Veröffentlichung und kein aktives Angebot. Eine frühere Fassung bleibt unverändert. Ungespeicherte Änderungen am Aufbau sind nicht Teil dieser Freigabe.') ->visible(function (): bool { $version = $this->currentReadyVersion(); @@ -163,10 +170,10 @@ protected function getHeaderActions(): array $this->releaseDisplay(); }), Action::make('displayRevoke') - ->label('Anzeige zurücknehmen') + ->label('Aus Mitgliederbibliothek ausblenden') ->color('danger') ->requiresConfirmation() - ->modalDescription('Nur die Anzeige dieser Fassung wird zurückgenommen. Der Inhalt der Fassung bleibt gespeichert.') + ->modalDescription('Die Fassung verschwindet aus der Mitgliederbibliothek. Der fachliche Inhalt bleibt gespeichert. Website und Angebot sind davon unabhängig.') ->visible(function (): bool { $version = $this->currentReadyVersion(); @@ -177,7 +184,7 @@ protected function getHeaderActions(): array $actor = $this->actor(); abort_unless($version !== null && $actor instanceof User, 403); app(CompositionDisplayRelease::class)->revoke($version, $actor); - $this->feedback = 'Die Anzeige dieser Fassung ist zurückgenommen. Der Inhalt bleibt gespeichert.'; + $this->feedback = 'Die Fassung ist aus der Mitgliederbibliothek ausgeblendet. Der Inhalt bleibt gespeichert.'; }), ]; } @@ -370,8 +377,8 @@ public function editorStatus(): string $display = $version === null ? '' : (app(CompositionDisplayRelease::class)->isReleased($version) - ? ' Sie ist zur Anzeige freigegeben.' - : ' Sie ist noch nicht zur Anzeige freigegeben.'); + ? ' Sie ist in der Mitgliederbibliothek sichtbar.' + : ' Sie ist nicht in der Mitgliederbibliothek.'); $unsaved = $stored === null ? $current !== $ready : $current !== $this->fingerprint($stored); @@ -453,7 +460,7 @@ public function versionChoices(): array $rows[] = [ 'id' => $version->id, 'number' => $version->number, - 'text' => 'Fassung '.$version->number.($released ? ', zur Anzeige freigegeben' : ''), + 'text' => 'Fassung '.$version->number.($released ? ', in der Mitgliederbibliothek' : ', nicht in der Mitgliederbibliothek'), 'current' => $latest !== null && $latest->id === $version->id, ]; } @@ -734,6 +741,8 @@ public function saveDisplay(): void 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(); @@ -778,6 +787,82 @@ public function savePreviewImage(string $storedPath): void $this->storePreview($storedPath); } + public function adoptPicture(int $elementId): void + { + $element = ContentElement::query()->find($elementId); + $path = $element?->thumbnail_path; + + if (! $element instanceof ContentElement || ! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) { + $this->feedback = 'Für dieses Medium liegt noch kein Vorschaubild vor.'; + + return; + } + + /** @var Composition $record */ + $record = $this->getRecord(); + $before = $record->versions()->count(); + DeriveThumbnail::dispatch('komposition', $record->id, null, $element->id); + $record->refresh(); + $this->thumbnailPath = $record->thumbnail_path; + $this->thumbnailError = $record->thumbnail_error; + $this->feedback = $this->previewFeedback($record, $before); + } + + /** + * @return array{url: ?string, note: ?string, own: bool} + */ + public function coverPicture(): array + { + /** @var Composition $composition */ + $composition = $this->getRecord(); + + return app(EditorialCatalog::class)->cover($composition, $this->members); + } + + /** + * @return list + */ + public function filmChoices(): array + { + $films = app(EditorialCatalog::class)->filmPictures($this->members); + + return count($films) > 1 ? $films : []; + } + + /** + * @return array{id: int, title: string, image: string}|null + */ + public function suggestedFilm(): ?array + { + if (filled($this->thumbnailPath)) { + return null; + } + + $films = app(EditorialCatalog::class)->filmPictures($this->members); + + return count($films) === 1 ? $films[0] : null; + } + + /** + * @return list + */ + public function mediaChoices(): array + { + return app(EditorialCatalog::class)->mediaPictures($this->imageQuery); + } + + /** + * @return list + */ + public function presentationChips(): array + { + /** @var Composition $composition */ + $composition = $this->getRecord(); + $offered = in_array($composition->id, app(EditorialCatalog::class)->offeredCompositionIds(), true); + + return app(EditorialCatalog::class)->statusChips($composition, $offered); + } + public function publishRevision(): bool { $this->commitRoleDraft(); @@ -910,7 +995,9 @@ protected function loadEditor(): void $this->designation = $composition->designation; $this->displayTitle = (string) ($composition->display_title ?? ''); $this->summary = (string) ($composition->summary ?? ''); + $this->description = (string) ($composition->description ?? ''); $this->thumbnailPath = $composition->thumbnail_path; + $this->thumbnailAlt = (string) ($composition->thumbnail_alt ?? ''); $this->thumbnailError = $composition->thumbnail_error; $this->dimensionIds = IdentityDimensionValue::query() ->where('subject_type', $composition->getMorphClass()) @@ -1034,7 +1121,7 @@ protected function releaseCurrent(): void } app(CompositionDisplayRelease::class)->release($version, $actor); - $this->feedback = 'Fassung '.$version->number.' ist zur Anzeige freigegeben. Frühere Fassungen bleiben erhalten.'; + $this->feedback = 'Fassung '.$version->number.' ist in der Mitgliederbibliothek sichtbar. Frühere Fassungen bleiben erhalten.'; } protected function currentReadyVersion(): ?CompositionVersion @@ -1156,9 +1243,24 @@ protected function storePreview(string $path): void $record->refresh(); $this->thumbnailPath = $record->thumbnail_path; $this->thumbnailError = $record->thumbnail_error; - $this->feedback = $record->versions()->count() === $before && filled($record->thumbnail_path) - ? 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.' - : ($record->thumbnail_error ?: 'Das Vorschaubild wurde nicht übernommen.'); + $this->feedback = $this->previewFeedback($record, $before); + } + + protected function previewFeedback(Composition $record, int $versionsBefore): string + { + if ($record->versions()->count() !== $versionsBefore) { + return 'Das Vorschaubild wurde nicht übernommen.'; + } + + if (filled($record->thumbnail_path) && $record->thumbnail_error === null) { + return 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.'; + } + + if (config('queue.default') !== 'sync') { + return 'Das Titelbild wird vorbereitet. Die Fassung bleibt unverändert.'; + } + + return $record->thumbnail_error ?: 'Das Vorschaubild wurde nicht übernommen.'; } protected function statusSentence(): string diff --git a/app/Filament/Support/EditorialCatalog.php b/app/Filament/Support/EditorialCatalog.php index 278866b..69cb1da 100644 --- a/app/Filament/Support/EditorialCatalog.php +++ b/app/Filament/Support/EditorialCatalog.php @@ -14,11 +14,14 @@ use App\Domain\Catalog\ContentVersionStatus; use App\Domain\Catalog\EditorialContentKind; use App\Domain\Catalog\IdentityDimensionValue; +use App\Domain\Catalog\LicenseArticle; +use App\Domain\Catalog\OfferStatus; use App\Filament\Resources\Combinations\CombinationResource; use App\Filament\Resources\Courses\CourseResource; use App\Filament\Resources\Exercises\ExerciseResource; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\DB; class EditorialCatalog { @@ -447,20 +450,202 @@ public function stand(Composition $composition): array ]; } - $text = 'Fassung '.$latest->number.($release->isReleased($latest) ? ', zur Anzeige freigegeben' : ', noch nicht zur Anzeige freigegeben'); + $visible = $released instanceof CompositionVersion; + $text = 'Fassung '.$latest->number.($visible ? ', in der Mitgliederbibliothek' : ', nicht in der Mitgliederbibliothek'); $text = ($draft ? 'Entwurf gespeichert. ' : '').$text; - if ($released instanceof CompositionVersion && $released->number !== $latest->number) { + if ($visible && $released->number !== $latest->number) { $text .= '. Angezeigt wird Fassung '.$released->number; } return [ 'text' => $text, 'number' => $latest->number, - 'released_number' => $released instanceof CompositionVersion ? $released->number : null, + 'released_number' => $visible ? $released->number : null, ]; } + /** + * @return list + */ + public function statusChips(Composition $composition, bool $offered): array + { + $stand = $this->stand($composition); + $chips = []; + + if ($stand['number'] === null) { + $chips[] = [ + 'label' => str_contains($stand['text'], 'Entwurf') ? 'Entwurf gespeichert' : 'Noch ohne Fassung', + 'tone' => 'yellow', + ]; + } else { + $chips[] = ['label' => 'Fassung '.$stand['number'], 'tone' => 'ink']; + + if (str_starts_with($stand['text'], 'Entwurf gespeichert')) { + $chips[] = ['label' => 'Entwurf offen', 'tone' => 'yellow']; + } + + $chips[] = $stand['released_number'] !== null + ? ['label' => 'In der Mitgliederbibliothek', 'tone' => 'pine'] + : ['label' => 'Nicht in der Mitgliederbibliothek', 'tone' => 'quiet']; + + if ($stand['released_number'] !== null && $stand['released_number'] !== $stand['number']) { + $chips[] = ['label' => 'Bibliothek zeigt Fassung '.$stand['released_number'], 'tone' => 'pine']; + } + } + + $chips[] = ['label' => 'Nicht auf der Website', 'tone' => 'quiet']; + $chips[] = $offered + ? ['label' => 'Angebot aktiv', 'tone' => 'pine'] + : ['label' => 'Kein aktives Angebot', 'tone' => 'quiet']; + + return $chips; + } + + /** + * @return list + */ + public function offeredCompositionIds(): array + { + $articleIds = DB::table('resolved_scopes') + ->join('offer_versions', 'offer_versions.id', '=', 'resolved_scopes.offer_version_id') + ->where('offer_versions.status', OfferStatus::Aktiv->value) + ->pluck('resolved_scopes.license_article_id'); + + if ($articleIds->isEmpty()) { + return []; + } + + $releaseIds = LicenseArticle::query() + ->whereIn('id', $articleIds) + ->whereNotNull('current_release_id') + ->pluck('current_release_id'); + $versionIds = ArticleRelease::query() + ->whereIn('id', $releaseIds) + ->whereNotNull('root_composition_version_id') + ->pluck('root_composition_version_id'); + + return CompositionVersion::query() + ->whereIn('id', $versionIds) + ->pluck('composition_id') + ->map(fn (mixed $id): int => (int) $id) + ->unique() + ->values() + ->all(); + } + + /** + * @param list> $members + * @return list + */ + public function filmPictures(array $members): array + { + $versionIds = []; + + foreach ($members as $member) { + $target = (string) ($member['target'] ?? ''); + + if (preg_match('/^element:(\d+)$/', $target, $match) === 1) { + $versionIds[] = (int) $match[1]; + } + } + + if ($versionIds === []) { + return []; + } + + $pictures = []; + + foreach (ContentElementVersion::query()->with('element')->whereIn('id', $versionIds)->get() as $version) { + $element = $version->element; + + if (! $element instanceof ContentElement || $element->output_class !== 'film') { + continue; + } + + $image = $this->cardUrl('element', $element->id, $element->thumbnail_path); + + if ($image === null || isset($pictures[$element->id])) { + continue; + } + + $pictures[$element->id] = [ + 'id' => $element->id, + 'title' => filled($element->display_title) ? $element->display_title : $element->working_title, + 'image' => $image, + ]; + } + + return array_values($pictures); + } + + /** + * @return list + */ + public function mediaPictures(string $query): array + { + $query = trim($query); + + if (mb_strlen($query) < 2) { + return []; + } + + $like = '%'.str_replace(['%', '_'], ['', ''], $query).'%'; + + return ContentElement::query() + ->where('thumbnail_path', 'like', 'vorschau/%') + ->where(function ($builder) use ($like): void { + $builder->where('working_title', 'like', $like) + ->orWhere('display_title', 'like', $like) + ->orWhere('summary', 'like', $like); + }) + ->orderBy('working_title') + ->limit(12) + ->get() + ->map(function (ContentElement $element): ?array { + $image = $this->cardUrl('element', $element->id, $element->thumbnail_path); + + if ($image === null) { + return null; + } + + return [ + 'id' => $element->id, + 'title' => filled($element->display_title) ? $element->display_title : $element->working_title, + 'image' => $image, + 'kind' => $element->editorialContentKind?->label ?: $this->outputLabel((string) $element->output_class), + ]; + }) + ->filter() + ->values() + ->all(); + } + + /** + * @param list> $members + * @return array{url: ?string, note: ?string, own: bool} + */ + public function cover(Composition $composition, array $members): array + { + $own = $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path); + + if ($own !== null) { + return ['url' => $own, 'note' => null, 'own' => true]; + } + + $films = $this->filmPictures($members); + + if (count($films) === 1) { + return [ + 'url' => $films[0]['image'], + 'note' => 'Vorschlag aus dem Film '.$films[0]['title'], + 'own' => false, + ]; + } + + return ['url' => null, 'note' => null, 'own' => false]; + } + public function create(string $designation, CompositionKind $kind): Composition { $composition = app(ContentService::class)->createComposition($designation, $kind); diff --git a/app/Http/Controllers/EditorialPreviewController.php b/app/Http/Controllers/EditorialPreviewController.php index 3d19592..9273f51 100644 --- a/app/Http/Controllers/EditorialPreviewController.php +++ b/app/Http/Controllers/EditorialPreviewController.php @@ -133,6 +133,7 @@ private function render( return view('filament.editorial.preview', [ 'title' => $catalog->compositionTitle($composition), 'summary' => $composition->summary, + 'description' => $composition->description, 'kind' => $composition->editorialContentKind?->label ?? ($composition->kind?->deskLabel()), 'learningGoal' => $learningGoal, diff --git a/app/Jobs/DeriveThumbnail.php b/app/Jobs/DeriveThumbnail.php index ea7221b..d90b281 100644 --- a/app/Jobs/DeriveThumbnail.php +++ b/app/Jobs/DeriveThumbnail.php @@ -16,6 +16,7 @@ public function __construct( public readonly string $subject, public readonly int $subjectId, public readonly ?string $incoming = null, + public readonly ?int $fromElement = null, ) {} public function handle(ThumbnailDeriver $deriver): void @@ -23,7 +24,21 @@ public function handle(ThumbnailDeriver $deriver): void if ($this->subject === 'komposition') { $composition = Composition::query()->find($this->subjectId); - if ($composition !== null && is_string($this->incoming)) { + if ($composition === null) { + return; + } + + if ($this->fromElement !== null) { + $element = ContentElement::query()->find($this->fromElement); + + if ($element !== null) { + $deriver->forCompositionFromElement($composition, $element); + } + + return; + } + + if (is_string($this->incoming)) { $deriver->forCompositionUpload($composition, $this->incoming); } diff --git a/database/migrations/2026_11_16_190000_add_presentation_text_to_compositions.php b/database/migrations/2026_11_16_190000_add_presentation_text_to_compositions.php new file mode 100644 index 0000000..a207989 --- /dev/null +++ b/database/migrations/2026_11_16_190000_add_presentation_text_to_compositions.php @@ -0,0 +1,23 @@ +text('description')->nullable()->after('summary'); + $table->string('thumbnail_source')->nullable()->after('thumbnail_alt'); + }); + } + + public function down(): void + { + Schema::table('compositions', function (Blueprint $table) { + $table->dropColumn(['description', 'thumbnail_source']); + }); + } +}; diff --git a/resources/views/filament/editorial/catalog-card.blade.php b/resources/views/filament/editorial/catalog-card.blade.php new file mode 100644 index 0000000..8884097 --- /dev/null +++ b/resources/views/filament/editorial/catalog-card.blade.php @@ -0,0 +1,29 @@ +@php + $summary = \Illuminate\Support\Str::limit(trim((string) ($card['summary'] ?? '')), 160); +@endphp + + + @if (! empty($card['image'])) + + @else + + Kein Titelbild + @endif + @if (! empty($card['image_note'])) + {{ $card['image_note'] }} + @endif + + + {{ $card['kind'] }} + {{ $card['title'] }} + {{ $summary !== '' ? $summary : 'Noch keine Kurzbeschreibung' }} + + @foreach ($card['chips'] as $chip) + {{ $chip['label'] }} + @endforeach + + + diff --git a/resources/views/filament/editorial/desk-page.blade.php b/resources/views/filament/editorial/desk-page.blade.php index c421317..57d4a43 100644 --- a/resources/views/filament/editorial/desk-page.blade.php +++ b/resources/views/filament/editorial/desk-page.blade.php @@ -19,32 +19,48 @@
- +
+
+ + + + +
+ @if ($this->dimensionFilters() !== []) +
+ + +
+ @endif
@if ($this->entries() === []) -

{{ trim($this->query) === '' ? 'Noch keine Programme oder Module.' : 'Nichts gefunden. Prüfe die Schreibweise oder lege oben einen neuen Eintrag an.' }}

+
+ @if ($this->hasActiveFilters()) +

Nichts gefunden. Prüfe die Schreibweise oder setze die Filter zurück.

+ + @else +

Noch keine Programme oder Module. Der Name oben genügt, um das erste anzulegen.

+ @endif +
@else -
    + @endif diff --git a/resources/views/filament/editorial/editor.blade.php b/resources/views/filament/editorial/editor.blade.php index 8c4be56..33b3ba6 100644 --- a/resources/views/filament/editorial/editor.blade.php +++ b/resources/views/filament/editorial/editor.blade.php @@ -150,18 +150,48 @@ @else

    {{ $this->hostLabel() }}

    {{ trim($this->displayTitle) !== '' ? $this->displayTitle : $this->designation }}

    -

    Name, Anzeigetitel, Kurzbeschreibung, Einordnung und Vorschaubild gelten für die Karte. Sie legen keine Inhaltsfassung an.

    +

    Titel, Texte, Einordnung und Titelbild beschreiben die Karte. Sie legen keine Inhaltsfassung an. Lernziel, Zeit und Material gehören zum fachlichen Stand darunter.

    +
    + @foreach ($this->presentationChips() as $chip) + {{ $chip['label'] }} + @endforeach +
    + @php($cover = $this->coverPicture()) +

    Katalogvorschau

    +
    + @if ($cover['url']) + {{ $this->thumbnailAlt !== '' ? $this->thumbnailAlt : '' }} + @else + + @endif + @if ($cover['note']) + {{ $cover['note'] }} + @endif +
    +

    + {{ trim($this->displayTitle) !== '' ? $this->displayTitle : ($this->designation !== '' ? $this->designation : 'Ohne Titel') }} + {{ trim($this->summary) !== '' ? \Illuminate\Support\Str::limit(trim($this->summary), 160) : 'Noch keine Kurzbeschreibung' }} +

    - - + +
    - + + Steht auf der Katalogkarte. +
    +
    + + + Ausführlicher Text für die Mitgliederbibliothek und eine spätere öffentliche Produktseite. Preis und Nutzungsrechte bleiben beim Angebot.
    @foreach ($this->dimensionGroups() as $group)
    @@ -174,22 +204,49 @@ @endforeach
    @endforeach -

    - @if ($this->thumbnailError) - {{ $this->thumbnailError }} - @elseif (filled($this->thumbnailPath)) - Ein Vorschaubild ist hinterlegt. - @else - Noch kein Vorschaubild. - @endif -

    +

    Titelbild

    +

    Ein selbst gewähltes Bild hat Vorrang vor einem Vorschlag. Ein Bild aus einem Film bleibt geschützt und wird nicht auf der öffentlichen Website ausgegeben.

    + @if ($this->thumbnailError) +

    {{ $this->thumbnailError }}

    + @endif + @php($films = $this->filmChoices()) + @php($suggestion = $this->suggestedFilm()) + @if ($suggestion) +

    Vorschlag aus dem Film {{ $suggestion['title'] }}.

    + + @endif + @if ($films !== []) +

    Mehrere Filme sind enthalten. Wähle das Titelbild.

    + @foreach ($films as $film) +
    + + {{ $film['title'] }} + +
    + @endforeach + @endif
    - + + +
    +
    +
    +
    + + +
    + @foreach ($this->mediaChoices() as $medium) +
    + + {{ $medium['kind'] }}{{ $medium['title'] }} + +
    + @endforeach
    - +

    Zum fachlichen Stand

    @@ -224,10 +281,10 @@
    Was Speichern und Freigeben bedeuten -

    Anzeigetitel, Kurzbeschreibung, Einordnung und Vorschaubild ändern die sichtbare Karte. Sie erzeugen keine Inhaltsfassung.

    +

    Titel, Kurzbeschreibung, fachliche Beschreibung, Einordnung und Titelbild ändern die sichtbare Karte. Sie erzeugen keine Inhaltsfassung.

    Entwurf speichern hält Aufbau, Rollen, Lernziel, Zeit und Material fest. Das kann beliebig oft geschehen. Eine freigegebene Fassung bleibt dabei unverändert.

    Freigeben erzeugt eine neue unveränderliche Fassung. Die bisherige bleibt für ältere Verweise erhalten.

    -

    Zur Anzeige freigeben, oben in der Leiste, entscheidet zusätzlich, welche freigegebene Fassung Trainer sehen. Das ist ein eigener Schritt.

    +

    In Mitgliederbibliothek anzeigen entscheidet, welche freigegebene Fassung Trainer sehen. Das veröffentlicht weder die Website noch ein Angebot.

    Ein Medium oder Modul, das auch woanders steckt, bleibt dort bei seiner bisherigen Fassung. Hier wird nur darauf verwiesen.

    diff --git a/resources/views/filament/editorial/preview.blade.php b/resources/views/filament/editorial/preview.blade.php index 75e30ac..61b126f 100644 --- a/resources/views/filament/editorial/preview.blade.php +++ b/resources/views/filament/editorial/preview.blade.php @@ -35,6 +35,10 @@ @if (filled($summary))

    {{ $summary }}

    @endif + @if (filled($description ?? null)) +

    Beschreibung

    +

    {{ $description }}

    + @endif @if (filled($learningGoal))

    Lernziel

    {{ $learningGoal }}

    diff --git a/resources/views/filament/editorial/styles.blade.php b/resources/views/filament/editorial/styles.blade.php index 06083c4..b18b089 100644 --- a/resources/views/filament/editorial/styles.blade.php +++ b/resources/views/filament/editorial/styles.blade.php @@ -160,6 +160,62 @@ .luf-block-main strong, .luf-card strong { display: block; font-size: 1.05rem; } .luf-thumb { width: 3.25rem; height: 3.25rem; object-fit: cover; flex: 0 0 auto; background: #e7eee9; } .luf-fallback { display: inline-flex; align-items: center; justify-content: center; font-family: Georgia, serif; font-size: 1.35rem; color: var(--luf-pine); } + .luf-catalogs { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(16.5rem, 1fr)); gap: 0.85rem; } + .luf-catalog { + display: flex; + flex-direction: column; + height: 100%; + background: #fff; + border: 1px solid var(--luf-line); + border-top: 4px solid var(--luf-pine); + color: inherit; + text-decoration: none; + min-width: 0; + } + .luf-catalog:hover { border-color: var(--luf-pine); } + .luf-catalog.luf-tone-programm { border-top-color: var(--luf-pine); } + .luf-catalog.luf-tone-modul { border-top-color: #1b2838; } + .luf-figure { position: relative; display: block; aspect-ratio: 16 / 9; background: #e7eee9; overflow: hidden; } + .luf-figure img, .luf-frame img { width: 100%; height: 100%; object-fit: cover; display: block; } + .luf-mark { width: 100%; height: 100%; color: var(--luf-pine); background: #e7eee9; } + .luf-figure-note, .luf-frame-note { + position: absolute; + left: 0.4rem; + bottom: 0.4rem; + max-width: calc(100% - 0.8rem); + background: rgba(255, 255, 255, 0.92); + padding: 0.15rem 0.4rem; + font-size: 0.78rem; + } + .luf-catalog-body { display: grid; gap: 0.35rem; padding: 0.75rem 0.8rem 0.9rem; } + .luf-catalog-body strong { + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; + min-height: 2.6em; + font-size: 1.08rem; + line-height: 1.3; + } + .luf-summary { + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; + min-height: 2.6em; + color: var(--luf-quiet); + font-size: 0.92rem; + } + .luf-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; } + .luf-chip { border: 1px solid var(--luf-line); padding: 0.05rem 0.4rem; font-size: 0.78rem; line-height: 1.5; background: #fff; } + .luf-chip-pine { color: var(--luf-pine); border-color: var(--luf-pine); } + .luf-chip-yellow { border-color: var(--luf-yellow); background: #fff8e8; } + .luf-chip-quiet { color: var(--luf-quiet); } + .luf-chip-ink { color: var(--luf-ink); } + .luf-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; } + .luf-frame { position: relative; aspect-ratio: 16 / 9; max-width: 22rem; background: #e7eee9; margin: 0 0 0.8rem; } + .luf-choice { display: grid; grid-template-columns: 5.5rem 1fr auto; gap: 0.6rem; align-items: center; background: #fff; border: 1px solid var(--luf-line); padding: 0.35rem; margin: 0 0 0.45rem; } + .luf-choice img { width: 5.5rem; height: 3.1rem; object-fit: cover; } .luf-picker { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(14rem, 0.8fr); gap: 0.8rem; align-items: start; } .luf-detail { background: var(--luf-paper); border: 1px solid var(--luf-line); padding: 0.8rem; } .luf-modal { position: fixed; inset: 0; z-index: 50; background: rgba(27, 40, 56, 0.46); display: grid; place-items: center; padding: 1rem; } @@ -171,6 +227,7 @@ .luf-split, .luf-desk-create, .luf-picker { grid-template-columns: 1fr; } .luf-move { grid-auto-flow: column; } .luf-part-row, .luf-block { grid-template-columns: 1fr; } - .luf-cards { grid-template-columns: 1fr; } + .luf-cards, .luf-catalogs { grid-template-columns: 1fr; } + .luf-choice { grid-template-columns: 5.5rem 1fr; } } diff --git a/resources/views/member/program.blade.php b/resources/views/member/program.blade.php index acb184c..7dd0b88 100644 --- a/resources/views/member/program.blade.php +++ b/resources/views/member/program.blade.php @@ -12,6 +12,9 @@ @if (filled($summary ?? null))

    {{ $summary }}

    @endif + @if (filled($composition->description)) +

    {{ $composition->description }}

    + @endif
    diff --git a/tests/Feature/EditorialEditorTest.php b/tests/Feature/EditorialEditorTest.php index e0c4be9..8759a12 100644 --- a/tests/Feature/EditorialEditorTest.php +++ b/tests/Feature/EditorialEditorTest.php @@ -5,6 +5,7 @@ use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionDisplayRelease; use App\Domain\Catalog\CompositionKind; +use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; use App\Filament\Pages\EditorialDesk; use App\Filament\Resources\Courses\CourseResource; @@ -14,6 +15,7 @@ use App\Models\User; use Filament\Facades\Filament; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Storage; use Livewire\Livewire; use Tests\TestCase; @@ -299,6 +301,98 @@ public function test_guests_cannot_open_the_trainer_preview(): void ->assertRedirect(); } + public function test_catalog_cards_show_text_status_and_a_single_film_suggestion(): void + { + Storage::fake('media_derived'); + $content = app(ContentService::class); + $film = $this->filmWithPicture($content, 'Lara im Park'); + $withFilm = $content->publishComposition( + $content->createComposition('Modul mit Film', CompositionKind::Uebung), + [['role' => 'Film', 'target' => $film]], + ); + $withFilm->composition->summary = 'Kinder erkennen eine Grenze, bevor sie jemanden um Hilfe bitten.'; + $withFilm->composition->save(); + $plain = $content->createComposition('Modul ohne Bild', CompositionKind::Uebung); + $plain->summary = str_repeat('Ausführliche Kartenbeschreibung. ', 12); + $plain->save(); + $editor = $this->editor(); + app(CompositionDisplayRelease::class)->release($withFilm, $editor); + + Livewire::actingAs($editor, 'staff') + ->test(EditorialDesk::class) + ->assertSee('Kinder erkennen eine Grenze') + ->assertSee('Vorschlag aus dem Film Lara im Park') + ->assertSee('In der Mitgliederbibliothek') + ->assertSee('Kein Titelbild') + ->assertSee('Ausführliche Kartenbeschreibung') + ->assertSee('Nicht auf der Website') + ->assertSee('Kein aktives Angebot') + ->assertDontSee('Zur Anzeige freigeben') + ->set('visibility', 'entwurf') + ->assertSee('Modul ohne Bild') + ->assertDontSee('Modul mit Film'); + + Livewire::actingAs($editor, 'staff') + ->test(EditExercise::class, ['record' => $withFilm->composition_id]) + ->assertSee('In Mitgliederbibliothek anzeigen') + ->assertSee('Vorschlag aus dem Film Lara im Park') + ->assertSee('Katalogvorschau') + ->assertDontSee('Zur Anzeige freigeben'); + } + + public function test_a_chosen_picture_and_description_do_not_create_a_version(): void + { + Storage::fake('media_derived'); + $content = app(ContentService::class); + $first = $this->filmWithPicture($content, 'Lara im Park'); + $second = $this->filmWithPicture($content, 'Lara im Hof'); + $version = $content->publishComposition( + $content->createComposition('Modul mit zwei Filmen', CompositionKind::Uebung), + [ + ['role' => 'Film', 'target' => $first], + ['role' => 'Weiterer Film', 'target' => $second], + ], + ); + $editor = $this->editor(); + + Livewire::actingAs($editor, 'staff') + ->test(EditExercise::class, ['record' => $version->composition_id]) + ->assertSee('Lara im Park als Titelbild') + ->assertSee('Lara im Hof als Titelbild') + ->assertDontSee('Vorschlag aus dem Film') + ->call('adoptPicture', $first->element->id) + ->assertSet('feedback', 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.') + ->set('description', 'Eine fachliche Beschreibung für die Bibliothek.') + ->set('summary', 'Kurzer Kartentext') + ->call('saveDisplay') + ->assertSet('feedback', 'Die Anzeige ist gespeichert. Die Fassung bleibt unverändert.'); + + $composition = $version->composition->fresh(); + + $this->assertSame(1, $composition->versions()->count()); + $this->assertSame('vorschau/komposition-'.$composition->id.'.jpg', $composition->thumbnail_path); + $this->assertSame('element:'.$first->element->id, $composition->thumbnail_source); + $this->assertSame('Eine fachliche Beschreibung für die Bibliothek.', $composition->description); + Storage::disk('media_derived')->assertExists($composition->thumbnail_path); + $this->get('/medien/'.$composition->thumbnail_path)->assertNotFound(); + } + + private function filmWithPicture(ContentService $content, string $title): ContentElementVersion + { + $element = $content->createElement('film', 'film', $title); + $version = $content->publishElementVersion($element, 'Film'); + $element->thumbnail_path = 'vorschau/element-'.$element->id.'.jpg'; + $element->thumbnail_alt = $title; + $element->save(); + $image = imagecreatetruecolor(8, 8); + ob_start(); + imagepng($image); + Storage::disk('media_derived')->put($element->thumbnail_path, ob_get_clean()); + imagedestroy($image); + + return $version->fresh(); + } + private function editor(): User { $editor = User::factory()->redakteur()->create();