Zeige freigegebene Programme als Aufbau in der Bibliothek
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
fc08e6d0f2
commit
7b54c38623
7 files changed
+307
-22
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Member;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
@@ -10,6 +11,7 @@
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\CourseOutline;
|
||||
use App\Http\LibraryCatalog;
|
||||
use App\Http\SignedLink;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -20,12 +22,12 @@ class LibraryController extends Controller
|
||||
{
|
||||
public function index(Request $request): View
|
||||
{
|
||||
return view('member.library', [
|
||||
'grants' => $this->grantQuery($request)->with([
|
||||
'article.currentRelease.rootCompositionVersion.composition',
|
||||
'article.currentRelease.rootElementVersion.element',
|
||||
])->get(),
|
||||
]);
|
||||
return view('member.library', app(LibraryCatalog::class)->index($request->user()));
|
||||
}
|
||||
|
||||
public function program(Request $request, Composition $composition): View
|
||||
{
|
||||
return view('member.program', app(LibraryCatalog::class)->program($request->user(), $composition));
|
||||
}
|
||||
|
||||
public function materials(Request $request): View
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\CompositionStructureReader;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ReleaseStatus;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class LibraryCatalog
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CompositionDisplayRelease $display,
|
||||
private readonly CompositionStructureReader $structure,
|
||||
private readonly DecideAccess $access,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array{programs: list<array<string, mixed>>, materials: list<array<string, mixed>>}
|
||||
*/
|
||||
public function index(User $user): array
|
||||
{
|
||||
$programs = [];
|
||||
$materials = [];
|
||||
|
||||
foreach ($this->grants($user) as $grant) {
|
||||
$article = $grant->article;
|
||||
$release = $article->currentRelease;
|
||||
$composition = $release?->rootCompositionVersion?->composition;
|
||||
$version = $release?->rootCompositionVersion;
|
||||
|
||||
if ($composition !== null && $version !== null && $this->display->isReleased($version)) {
|
||||
$programs[$composition->id] = [
|
||||
'composition' => $composition,
|
||||
'version' => $version,
|
||||
'title' => $composition->designation,
|
||||
'kind' => $composition->editorialContentKind?->label
|
||||
?? ($composition->kind?->label()),
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$materials[$article->id] = [
|
||||
'article' => $article,
|
||||
'title' => app(CourseOutline::class)->title($article),
|
||||
'kind' => app(CourseOutline::class)->kindLabel($article),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'programs' => array_values($programs),
|
||||
'materials' => array_values($materials),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{composition: Composition, title: string, kind: ?string, nodes: list<array<string, mixed>>}
|
||||
*/
|
||||
public function program(User $user, Composition $composition): array
|
||||
{
|
||||
$version = $this->display->highestReleasedVersion($composition);
|
||||
abort_if($version === null, 404);
|
||||
|
||||
return [
|
||||
'composition' => $composition,
|
||||
'title' => $composition->designation,
|
||||
'kind' => $composition->editorialContentKind?->label
|
||||
?? ($composition->kind?->label()),
|
||||
'nodes' => array_map(
|
||||
fn (StructureNode $node): array => $this->present($user, $node),
|
||||
$this->structure->tree($version),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function present(User $user, StructureNode $node): array
|
||||
{
|
||||
$view = null;
|
||||
$download = null;
|
||||
|
||||
if ($node->contentElementVersionId !== null) {
|
||||
$view = $this->open($user, $node->contentElementVersionId, $this->viewAction($node->outputClass));
|
||||
$download = $this->open($user, $node->contentElementVersionId, 'laden');
|
||||
}
|
||||
|
||||
return [
|
||||
'role' => $node->role,
|
||||
'title' => $node->title,
|
||||
'kind' => $node->editorialKindLabel ?? $node->technicalKindLabel,
|
||||
'output_class' => $node->outputClass,
|
||||
'view_url' => $view,
|
||||
'download_url' => $download,
|
||||
'children' => array_map(
|
||||
fn (StructureNode $child): array => $this->present($user, $child),
|
||||
$node->children,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
private function viewAction(?string $outputClass): string
|
||||
{
|
||||
return in_array($outputClass, ['film', 'audio'], true) ? 'streamen' : 'ansehen';
|
||||
}
|
||||
|
||||
private function open(User $user, int $versionId, string $action): ?string
|
||||
{
|
||||
$version = ContentElementVersion::query()->with('element')->find($versionId);
|
||||
|
||||
if ($version === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$releases = ArticleRelease::query()
|
||||
->whereIn('status', [ReleaseStatus::Veroeffentlicht, ReleaseStatus::AbgeloestVerfuegbar])
|
||||
->whereHas('contents', fn ($query) => $query->where('content_element_version_id', $versionId))
|
||||
->with('article')
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
|
||||
foreach ($releases as $release) {
|
||||
$decision = ($this->access)($user, $release->article, $release, $version, $action);
|
||||
|
||||
if (! $decision->allowed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
'article' => $release->article->id,
|
||||
'release' => $release->id,
|
||||
'version' => $version->id,
|
||||
'action' => $action,
|
||||
'reader' => $user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Grant>
|
||||
*/
|
||||
private function grants(User $user): Collection
|
||||
{
|
||||
return Grant::query()
|
||||
->where('status', GrantStatus::Aktiv)
|
||||
->whereHas('acquisition', fn ($query) => $query->where('party_id', $user->party_id))
|
||||
->with([
|
||||
'article.currentRelease.rootCompositionVersion.composition.editorialContentKind',
|
||||
'article.currentRelease.rootElementVersion.element.editorialContentKind',
|
||||
])
|
||||
->orderBy('id')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
@@ -4,27 +4,33 @@
|
||||
|
||||
@section('content')
|
||||
@include('member.partials.nav')
|
||||
@inject('courses', App\Http\CourseOutline::class)
|
||||
<h1>Bibliothek</h1>
|
||||
<p class="lede">Jede Berechtigung öffnet ein Programm, ein Modul oder ein einzelnes Material.</p>
|
||||
@if ($grants->isEmpty())
|
||||
<p class="lede">Programme zeigen den Aufbau. Einzelne Materialien stehen darunter, solange sie zu keinem freigegebenen Programm gehören.</p>
|
||||
@if ($programs === [] && $materials === [])
|
||||
<div class="empty">
|
||||
<p>Noch nichts in der Bibliothek. Unter Angebote können Sie ein kostenloses Material abrufen oder ein Angebot im Testmodus kaufen.</p>
|
||||
<p><a class="button" href="{{ route('member.offers') }}">Zu den Angeboten</a></p>
|
||||
</div>
|
||||
@else
|
||||
<ul class="catalog">
|
||||
@foreach ($grants as $grant)
|
||||
<li>
|
||||
<a href="{{ route('member.article', $grant->article) }}"><strong>{{ $courses->kindLabel($grant->article) ? $courses->kindLabel($grant->article).': ' : '' }}{{ $courses->title($grant->article) }}</strong></a>
|
||||
@if ($grant->article->currentRelease?->classification_note)
|
||||
<span>{{ $grant->article->currentRelease->classification_note }}</span>
|
||||
@endif
|
||||
@if ($grant->article->currentRelease?->change_note)
|
||||
<span>{{ $grant->article->currentRelease->change_note }}</span>
|
||||
@endif
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@if ($programs !== [])
|
||||
<h2>Programme und Module</h2>
|
||||
<ul class="catalog">
|
||||
@foreach ($programs as $program)
|
||||
<li>
|
||||
<a href="{{ route('member.program', $program['composition']) }}"><strong>{{ $program['kind'] ? $program['kind'].': ' : '' }}{{ $program['title'] }}</strong></a>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
@if ($materials !== [])
|
||||
<h2>Materialien</h2>
|
||||
<ul class="catalog">
|
||||
@foreach ($materials as $material)
|
||||
<li>
|
||||
<a href="{{ route('member.article', $material['article']) }}"><strong>{{ $material['kind'] ? $material['kind'].': ' : '' }}{{ $material['title'] }}</strong></a>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
@endif
|
||||
@endsection
|
||||
@@ -0,0 +1,27 @@
|
||||
<ol class="course">
|
||||
@foreach ($nodes as $node)
|
||||
<li>
|
||||
<h2>{{ $node['role'] }}: {{ $node['title'] }}</h2>
|
||||
@if ($node['kind'])
|
||||
<p>{{ $node['kind'] }}</p>
|
||||
@endif
|
||||
@if ($node['output_class'] === 'film' || $node['output_class'] === 'audio')
|
||||
@if ($node['view_url'])
|
||||
<video controls preload="metadata" playsinline src="{{ $node['view_url'] }}"></video>
|
||||
@else
|
||||
<p>Für diesen Film liegt keine Freigabe vor.</p>
|
||||
@endif
|
||||
@elseif ($node['view_url'])
|
||||
<p><a href="{{ $node['view_url'] }}">Ansehen</a></p>
|
||||
@elseif ($node['children'] === [])
|
||||
<p>Für diesen Teil liegt keine Freigabe vor.</p>
|
||||
@endif
|
||||
@if ($node['download_url'])
|
||||
<p><a href="{{ $node['download_url'] }}">Laden</a></p>
|
||||
@endif
|
||||
@if ($node['children'] !== [])
|
||||
@include('member.partials.structure', ['nodes' => $node['children']])
|
||||
@endif
|
||||
</li>
|
||||
@endforeach
|
||||
</ol>
|
||||
@@ -0,0 +1,13 @@
|
||||
@extends('layouts.site')
|
||||
|
||||
@section('title', $title)
|
||||
|
||||
@section('content')
|
||||
@include('member.partials.nav')
|
||||
<p><a href="{{ route('member.library') }}">Bibliothek</a></p>
|
||||
<h1>{{ $title }}</h1>
|
||||
@if ($kind)
|
||||
<p>{{ $kind }}</p>
|
||||
@endif
|
||||
@include('member.partials.structure', ['nodes' => $nodes])
|
||||
@endsection
|
||||
@@ -53,6 +53,7 @@
|
||||
Route::middleware(['auth', 'verified'])->prefix('bereich')->name('member.')->group(function () {
|
||||
Route::get('/', [MemberController::class, 'dashboard'])->name('dashboard');
|
||||
Route::get('/bibliothek', [LibraryController::class, 'index'])->name('library');
|
||||
Route::get('/bibliothek/programm/{composition}', [LibraryController::class, 'program'])->name('program');
|
||||
Route::get('/bibliothek/{article}', [LibraryController::class, 'show'])->name('article');
|
||||
Route::get('/ausgabe/{article}/{release}/{version}/{action}', [LibraryController::class, 'media'])
|
||||
->middleware('signed:relative')
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LibraryProgramTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_a_released_program_shows_its_structure_and_an_unreleased_one_stays_material(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$film = $content->publishElementVersion(
|
||||
$content->createElement('film', 'film', 'Hofszene'),
|
||||
null,
|
||||
['file' => 'inhalte/hof.mp4'],
|
||||
);
|
||||
$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]],
|
||||
);
|
||||
$hidden = $content->publishComposition(
|
||||
$content->createComposition('Noch nicht zeigen'),
|
||||
[['role' => 'Film', 'target' => $film]],
|
||||
);
|
||||
|
||||
$articles = app(ArticleService::class);
|
||||
$visibleArticle = $articles->create('sichtbar');
|
||||
$articles->publishRelease($visibleArticle, $released, 'Programmartikel.');
|
||||
$hiddenArticle = $articles->create('verborgen');
|
||||
$articles->publishRelease($hiddenArticle, $hidden, 'Nicht freigegeben.');
|
||||
|
||||
$offers = app(OfferService::class);
|
||||
$rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen', 'laden']]);
|
||||
$offer = $offers->create('Programmzugang');
|
||||
$offers->activate($offer, [
|
||||
['target' => $visibleArticle->fresh(), 'rights' => $rights],
|
||||
], ['grant_kind' => 'auf_abruf']);
|
||||
|
||||
$member = User::factory()->create();
|
||||
app(GrantIssuer::class)->claim($member, $offer);
|
||||
app(CompositionDisplayRelease::class)->release($released, $member);
|
||||
|
||||
$this->actingAs($member)
|
||||
->get(route('member.library'))
|
||||
->assertOk()
|
||||
->assertSee('Sicher auf dem Schulweg')
|
||||
->assertDontSee('Noch nicht zeigen');
|
||||
|
||||
$this->actingAs($member)
|
||||
->get(route('member.program', $released->composition))
|
||||
->assertOk()
|
||||
->assertSee('Film: Hofszene')
|
||||
->assertSee('Laden')
|
||||
->assertSee('<video', false);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user