diff --git a/app/Domain/Catalog/Composition.php b/app/Domain/Catalog/Composition.php index d57ee67..328b80e 100644 --- a/app/Domain/Catalog/Composition.php +++ b/app/Domain/Catalog/Composition.php @@ -12,6 +12,10 @@ class Composition extends Model 'designation', 'display_title', 'summary', + 'thumbnail_path', + 'thumbnail_alt', + 'thumbnail_error', + 'public_slug', 'kind', 'editorial_content_kind_id', 'archived_at', diff --git a/app/Domain/Catalog/CompositionVersion.php b/app/Domain/Catalog/CompositionVersion.php index ce3d731..ab4e423 100644 --- a/app/Domain/Catalog/CompositionVersion.php +++ b/app/Domain/Catalog/CompositionVersion.php @@ -14,6 +14,9 @@ class CompositionVersion extends Model 'status', 'members_hash', 'resolved_hash', + 'learning_goal', + 'duration_minutes', + 'material_note', ]; protected function casts(): array diff --git a/app/Domain/Catalog/ContentElement.php b/app/Domain/Catalog/ContentElement.php index 99a1e36..f27bd04 100644 --- a/app/Domain/Catalog/ContentElement.php +++ b/app/Domain/Catalog/ContentElement.php @@ -16,6 +16,9 @@ class ContentElement extends Model 'display_title', 'description', 'summary', + 'thumbnail_path', + 'thumbnail_alt', + 'thumbnail_error', 'editorial_content_kind_id', 'archived_at', ]; diff --git a/app/Domain/Catalog/ContentService.php b/app/Domain/Catalog/ContentService.php index 1e418dd..bfcf367 100644 --- a/app/Domain/Catalog/ContentService.php +++ b/app/Domain/Catalog/ContentService.php @@ -86,6 +86,7 @@ public function publishComposition( array $members, ?User $confirmedBy = null, ?string $note = null, + array $didactic = [], ): CompositionVersion { if ($members === []) { throw new DomainRuleException('Eine Komposition braucht mindestens ein Mitglied.'); @@ -97,13 +98,16 @@ public function publishComposition( $this->assertReadyMember($member['target']); } - return DB::transaction(function () use ($composition, $members, $confirmedBy, $note): CompositionVersion { + return DB::transaction(function () use ($composition, $members, $confirmedBy, $note, $didactic): CompositionVersion { $number = ((int) $composition->versions()->max('number')) + 1; $version = $composition->versions()->create([ 'number' => $number, 'status' => ContentVersionStatus::Entwurf, 'members_hash' => $this->membersHash($members), 'resolved_hash' => 'pending', + 'learning_goal' => $this->optionalText($didactic['learning_goal'] ?? null), + 'duration_minutes' => isset($didactic['duration_minutes']) ? (int) $didactic['duration_minutes'] : null, + 'material_note' => $this->optionalText($didactic['material_note'] ?? null), ]); foreach (array_values($members) as $index => $member) { @@ -219,6 +223,17 @@ private function membersHash(array $members): string return hash('sha256', json_encode($list, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE)); } + private function optionalText(mixed $value): ?string + { + if (! is_string($value)) { + return null; + } + + $value = trim($value); + + return $value === '' ? null : $value; + } + private function required(string $value, string $message): string { $value = trim($value); diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index c2bab64..2c968e9 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -5,6 +5,7 @@ use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionDisplayRelease; use App\Domain\Catalog\CompositionKind; +use App\Domain\Catalog\CompositionMember; use App\Domain\Catalog\CompositionVersion; use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; @@ -56,6 +57,20 @@ public function form(Schema $schema): Schema ->options(fn (): array => EditorialContentKind::selectOptions()) ->nullable() ->helperText('Optional für Bibliothek und Website. Ändert weder die technische Art noch eine Fassung.'), + Placeholder::make('usage')->label('Verwendung')->content(function (): HtmlString { + $version = $this->currentReadyVersion(); + if ($version === null) { + return new HtmlString('Noch keine Fassung.'); + } + $lines = CompositionMember::query() + ->where('nested_composition_version_id', $version->id) + ->with('compositionVersion.composition') + ->get() + ->map(fn (CompositionMember $member): string => ($member->compositionVersion->composition->designation ?? 'Programm').' · '.$member->role) + ->all(); + + return new HtmlString($lines === [] ? 'In keiner anderen Fassung enthalten.' : e(implode(' · ', $lines))); + }), Placeholder::make('history')->label('Aktuelle Fassung')->content(function (): HtmlString { /** @var Composition $composition */ $composition = $this->getRecord(); diff --git a/app/Http/Controllers/Member/LibraryController.php b/app/Http/Controllers/Member/LibraryController.php index 33fd8eb..3cd584f 100644 --- a/app/Http/Controllers/Member/LibraryController.php +++ b/app/Http/Controllers/Member/LibraryController.php @@ -160,6 +160,7 @@ public function media( return view('member.read', [ 'article' => $article, 'version' => $version, + 'license' => $decision->grant?->rights_snapshot['purpose'] ?? null, ]); } diff --git a/app/Http/Controllers/PublicCatalogController.php b/app/Http/Controllers/PublicCatalogController.php new file mode 100644 index 0000000..d3650f2 --- /dev/null +++ b/app/Http/Controllers/PublicCatalogController.php @@ -0,0 +1,38 @@ +where('slug', 'programm')->first(); + $programs = Composition::query() + ->when($kind !== null, fn ($query) => $query->where('editorial_content_kind_id', $kind->id)) + ->orderBy('designation') + ->get() + ->filter(fn (Composition $composition): bool => app(CompositionDisplayRelease::class)->highestReleasedVersion($composition) !== null); + + return view('public.programs', ['programs' => $programs]); + } + + public function program(Composition $composition): View + { + $kind = $composition->editorialContentKind; + abort_unless($kind?->slug === 'programm', 404); + $version = app(CompositionDisplayRelease::class)->highestReleasedVersion($composition); + abort_if($version === null, 404); + + return view('public.program', [ + 'composition' => $composition, + 'version' => $version, + 'nodes' => app(CompositionStructureReader::class)->tree($version), + ]); + } +} diff --git a/app/Http/LibraryCatalog.php b/app/Http/LibraryCatalog.php index ed800df..adf90b2 100644 --- a/app/Http/LibraryCatalog.php +++ b/app/Http/LibraryCatalog.php @@ -6,6 +6,7 @@ use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionDisplayRelease; use App\Domain\Catalog\CompositionStructureReader; +use App\Domain\Catalog\CompositionVersion; use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ReleaseStatus; use App\Domain\Catalog\StructureNode; @@ -71,16 +72,24 @@ public function program(User $user, Composition $composition): array $version = $this->display->highestReleasedVersion($composition); abort_if($version === null, 404); + $nodes = array_map( + fn (StructureNode $node): array => $this->present($user, $node), + $this->structure->tree($version), + ); + $leaves = $this->leaves($nodes); + $open = count(array_filter($leaves, fn (array $leaf): bool => $leaf['view_url'] !== null)); + return [ 'composition' => $composition, 'title' => filled($composition->display_title) ? $composition->display_title : $composition->designation, 'summary' => $composition->summary, 'kind' => $composition->editorialContentKind?->label ?? ($composition->kind?->label()), - 'nodes' => array_map( - fn (StructureNode $node): array => $this->present($user, $node), - $this->structure->tree($version), - ), + 'learning_goal' => $version->learning_goal, + 'duration_minutes' => $version->duration_minutes, + 'material_note' => $version->material_note, + 'coverage' => $leaves === [] ? 'nicht nutzbar' : ($open === count($leaves) ? 'vollständig' : ($open === 0 ? 'nicht nutzbar' : 'teilweise')), + 'nodes' => $nodes, ]; } @@ -104,6 +113,7 @@ private function present(User $user, StructureNode $node): array 'output_class' => $node->outputClass, 'view_url' => $view, 'download_url' => $download, + 'program_url' => $this->programUrl($node), 'children' => array_map( fn (StructureNode $child): array => $this->present($user, $child), $node->children, @@ -111,6 +121,42 @@ private function present(User $user, StructureNode $node): array ]; } + /** + * @param list> $nodes + * @return list> + */ + private function leaves(array $nodes): array + { + $leaves = []; + + foreach ($nodes as $node) { + if ($node['children'] === []) { + $leaves[] = $node; + + continue; + } + + $leaves = [...$leaves, ...$this->leaves($node['children'])]; + } + + return $leaves; + } + + private function programUrl(StructureNode $node): ?string + { + if ($node->compositionId === null || $node->compositionVersionId === null) { + return null; + } + + $version = CompositionVersion::query()->find($node->compositionVersionId); + + if ($version === null || ! $this->display->isReleased($version)) { + return null; + } + + return route('member.program', $node->compositionId); + } + private function viewAction(?string $outputClass): string { return in_array($outputClass, ['film', 'audio'], true) ? 'streamen' : 'ansehen'; diff --git a/database/migrations/2026_11_16_160000_library_completion.php b/database/migrations/2026_11_16_160000_library_completion.php new file mode 100644 index 0000000..4c609bf --- /dev/null +++ b/database/migrations/2026_11_16_160000_library_completion.php @@ -0,0 +1,42 @@ +string('thumbnail_path')->nullable(); + $table->string('thumbnail_alt')->nullable(); + $table->string('thumbnail_error')->nullable(); + }); + } + + Schema::table('compositions', function (Blueprint $table) { + $table->string('public_slug')->nullable()->unique(); + }); + + Schema::table('composition_versions', function (Blueprint $table) { + $table->text('learning_goal')->nullable(); + $table->unsignedSmallInteger('duration_minutes')->nullable(); + $table->text('material_note')->nullable(); + }); + } + + public function down(): void + { + Schema::table('composition_versions', function (Blueprint $table) { + $table->dropColumn(['learning_goal', 'duration_minutes', 'material_note']); + }); + Schema::table('compositions', function (Blueprint $table) { + $table->dropColumn(['thumbnail_path', 'thumbnail_alt', 'thumbnail_error', 'public_slug']); + }); + Schema::table('content_elements', function (Blueprint $table) { + $table->dropColumn(['thumbnail_path', 'thumbnail_alt', 'thumbnail_error']); + }); + } +}; diff --git a/resources/views/member/library.blade.php b/resources/views/member/library.blade.php index 4c4a5be..0bb03b7 100644 --- a/resources/views/member/library.blade.php +++ b/resources/views/member/library.blade.php @@ -26,6 +26,10 @@ @foreach ($programs as $program)
  • {{ $program['kind'] ? $program['kind'].': ' : '' }}{{ $program['title'] }} + {{ filled($program['composition']->thumbnail_path) ? ($program['composition']->thumbnail_alt ?: 'Vorschaubild') : 'Platzhalter' }} + @if (filled($program['composition']->thumbnail_error)) + {{ $program['composition']->thumbnail_error }} + @endif
  • @endforeach diff --git a/resources/views/member/partials/structure.blade.php b/resources/views/member/partials/structure.blade.php index 456c5e2..0f97147 100644 --- a/resources/views/member/partials/structure.blade.php +++ b/resources/views/member/partials/structure.blade.php @@ -1,7 +1,7 @@
      @foreach ($nodes as $node)
    1. -

      {{ $node['role'] }}: {{ $node['title'] }}

      +

      {{ $node['role'] }}: @if ($node['program_url'] ?? null){{ $node['title'] }}@else{{ $node['title'] }}@endif

      @if ($node['kind'])

      {{ $node['kind'] }}

      @endif diff --git a/resources/views/member/program.blade.php b/resources/views/member/program.blade.php index 8cf0dfd..81c5d43 100644 --- a/resources/views/member/program.blade.php +++ b/resources/views/member/program.blade.php @@ -12,5 +12,19 @@ @if (filled($summary ?? null))

      {{ $summary }}

      @endif +

      Nutzbarkeit: {{ $coverage }}

      +

      {{ filled($composition->thumbnail_path) ? ($composition->thumbnail_alt ?: 'Vorschaubild') : 'Platzhalter' }}

      + @if (filled($composition->thumbnail_error)) +

      {{ $composition->thumbnail_error }}

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

      Lernziel: {{ $learning_goal }}

      + @endif + @if ($duration_minutes) +

      Zeit: {{ $duration_minutes }} Minuten

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

      Material: {{ $material_note }}

      + @endif @include('member.partials.structure', ['nodes' => $nodes]) @endsection diff --git a/resources/views/member/read.blade.php b/resources/views/member/read.blade.php index c9041dd..f22224f 100644 --- a/resources/views/member/read.blade.php +++ b/resources/views/member/read.blade.php @@ -5,6 +5,9 @@ @section('content') @include('member.partials.nav')

      {{ $version->element->working_title }}

      + @if (filled($license ?? null)) +

      Lizenzkennzeichnung: {{ $license }}

      + @endif
      {!! nl2br(e($version->body)) !!}
      diff --git a/resources/views/public/program.blade.php b/resources/views/public/program.blade.php new file mode 100644 index 0000000..5e976d9 --- /dev/null +++ b/resources/views/public/program.blade.php @@ -0,0 +1,28 @@ +@extends('layouts.site') + +@section('title', $composition->display_title ?: $composition->designation) + +@section('content') +

      Programme

      +

      {{ $composition->display_title ?: $composition->designation }}

      + @if (filled($composition->summary)) +

      {{ $composition->summary }}

      + @endif + @if (filled($version->learning_goal)) +

      Lernziel: {{ $version->learning_goal }}

      + @endif +
        + @foreach ($nodes as $node) +
      1. +

        {{ $node->role }}: {{ $node->title }}

        + @if ($node->children !== []) +
          + @foreach ($node->children as $child) +
        1. {{ $child->role }}: {{ $child->title }}
        2. + @endforeach +
        + @endif +
      2. + @endforeach +
      +@endsection diff --git a/resources/views/public/programs.blade.php b/resources/views/public/programs.blade.php new file mode 100644 index 0000000..93f172d --- /dev/null +++ b/resources/views/public/programs.blade.php @@ -0,0 +1,17 @@ +@extends('layouts.site') + +@section('title', 'Programme') + +@section('content') +

      Programme

      +

      Gezeigt wird nur eine zur Anzeige freigegebene Programmfassung. Dateien bleiben im Mitgliederbereich.

      + @if ($programs->isEmpty()) +

      Noch kein Programm ist öffentlich gelistet.

      + @else + + @endif +@endsection diff --git a/routes/web.php b/routes/web.php index a864466..702d0eb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -9,6 +9,7 @@ use App\Http\Controllers\Member\LibraryController; use App\Http\Controllers\Member\MemberController; use App\Http\Controllers\PageController; +use App\Http\Controllers\PublicCatalogController; use App\Http\Controllers\PublicMediaController; use App\Http\Controllers\ThemeController; use Illuminate\Support\Facades\Route; @@ -16,6 +17,8 @@ Route::get('/', [PageController::class, 'home'])->name('home'); Route::get('/sitemap.xml', [PageController::class, 'sitemap'])->name('sitemap'); Route::get('/themen', [ThemeController::class, 'index'])->name('themes'); +Route::get('/programme', [PublicCatalogController::class, 'index'])->name('public.programs'); +Route::get('/programme/{composition}', [PublicCatalogController::class, 'program'])->name('public.program'); Route::get('/themen/{slug}', [ThemeController::class, 'show'])->name('theme')->where('slug', '[a-z0-9]+(?:-[a-z0-9]+)*'); Route::get('/medien/{path}', [PublicMediaController::class, 'show'])->where('path', '.*')->name('media.public'); diff --git a/tests/Feature/LibraryCompletionTest.php b/tests/Feature/LibraryCompletionTest.php new file mode 100644 index 0000000..ec78371 --- /dev/null +++ b/tests/Feature/LibraryCompletionTest.php @@ -0,0 +1,65 @@ +publishElementVersion($content->createElement('film', 'film', 'Hof'), null, ['file' => 'inhalte/hof.mp4']); + $sheet = $content->publishElementVersion($content->createElement('text', 'document', 'Blatt'), 'Text'); + $programm = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail(); + $version = $content->publishComposition( + tap($content->createComposition('Öffentliches Programm'), function ($item) use ($programm): void { + $item->editorial_content_kind_id = $programm->id; + $item->thumbnail_error = 'Kein Bild erzeugt.'; + $item->save(); + }), + [ + ['role' => 'Film', 'target' => $film], + ['role' => 'Blatt', 'target' => $sheet], + ], + null, + null, + ['learning_goal' => 'Abstand halten', 'duration_minutes' => 20, 'material_note' => 'Ein Blatt'], + ); + $articles = app(ArticleService::class); + $filmArticle = $articles->create('nur-film-fertig'); + $articles->publishRelease($filmArticle, $film, 'Nur Film.'); + $offers = app(OfferService::class); + $rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']]); + $offer = $offers->create('Teilprogramm'); + $offers->activate($offer, [['target' => $filmArticle->fresh(), 'rights' => $rights]], ['grant_kind' => 'auf_abruf']); + $member = User::factory()->create(); + app(GrantIssuer::class)->claim($member, $offer); + app(CompositionDisplayRelease::class)->release($version, $member); + + $this->actingAs($member)->get(route('member.program', $version->composition)) + ->assertOk() + ->assertSee('teilweise') + ->assertSee('Abstand halten') + ->assertSee('Kein Bild erzeugt.') + ->assertSee('Platzhalter'); + + $this->get(route('public.program', $version->composition)) + ->assertOk() + ->assertSee('Öffentliches Programm') + ->assertSee('Abstand halten') + ->assertDontSee('inhalte/hof.mp4'); + + $this->get('/medien/bibliothek/geheim.jpg')->assertNotFound(); + } +}