From abcdc6908ee69bc974d149839dc4d669c6513bc5 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 16 Nov 2026 08:36:06 +0100 Subject: [PATCH] Lege einen wiederholbaren Pruefbestand fuer die Bibliothek an Co-authored-by: Cursor --- app/Console/Commands/SeedLibraryReview.php | 81 ++++++++++++++++++++++ app/Http/LibraryCatalog.php | 6 +- tests/Feature/LibraryCompletionTest.php | 11 +++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/SeedLibraryReview.php diff --git a/app/Console/Commands/SeedLibraryReview.php b/app/Console/Commands/SeedLibraryReview.php new file mode 100644 index 0000000..44a8f01 --- /dev/null +++ b/app/Console/Commands/SeedLibraryReview.php @@ -0,0 +1,81 @@ +where('designation', 'Prüfprogramm Abstand')->first(); + + if ($existing !== null) { + $this->info('Prüfbestand ist bereits vorhanden.'); + + return self::SUCCESS; + } + + $actor = User::query()->find($this->option('actor')) ?? User::query()->orderBy('id')->first(); + + if ($actor === null) { + $this->error('Es gibt kein Konto, das die Anzeigefreigabe zeichnen kann.'); + + return self::FAILURE; + } + + $kind = EditorialContentKind::query()->where('slug', 'programm')->first(); + + if ($kind === null) { + $this->error('Die Inhaltsart Programm fehlt.'); + + return self::FAILURE; + } + + $sheet = $content->publishElementVersion( + $content->createElement('text', 'document', 'Prüfblatt Abstand'), + 'Gekennzeichneter Prüftext. Kein Veröffentlichungstext.', + ); + $composition = $content->createComposition('Prüfprogramm Abstand'); + $composition->editorial_content_kind_id = $kind->id; + $composition->display_title = 'Prüfprogramm Abstand'; + $composition->summary = 'Gekennzeichneter Prüfbestand für die Testinstanz.'; + $composition->thumbnail_error = 'Prüfhinweis: kein Vorschaubild.'; + $composition->save(); + $version = $content->publishComposition($composition, [ + ['role' => 'Blatt', 'target' => $sheet], + ], $actor, 'Prüfbestand', [ + 'learning_goal' => 'Den Prüfaufbau in der Bibliothek sehen.', + 'duration_minutes' => 5, + 'material_note' => 'Nur der Prüftext.', + ]); + $article = $articles->create('pruef-abstand'); + $articles->publishRelease($article, $version, 'Prüffassung.'); + $rights = $offers->createRightsProfile('Prüfblatt ansehen', 'ehrenamtlich', [ + 'document' => ['ansehen', 'laden'], + ]); + $offer = $offers->create('Prüfprogramm Abstand'); + $offers->activate($offer, [ + ['target' => $article->fresh(), 'rights' => $rights], + ], ['grant_kind' => 'auf_abruf', 'composition_version_id' => $version->id]); + $display->release($version, $actor, 'Prüffreigabe'); + $this->info('Prüfbestand angelegt. Angebot: Prüfprogramm Abstand.'); + + return self::SUCCESS; + } +} diff --git a/app/Http/LibraryCatalog.php b/app/Http/LibraryCatalog.php index adf90b2..284a22e 100644 --- a/app/Http/LibraryCatalog.php +++ b/app/Http/LibraryCatalog.php @@ -51,7 +51,11 @@ public function index(User $user): array continue; } - $materials[$article->id] = [ + $elementId = $release?->rootElementVersion?->element_id; + $key = $composition !== null + ? 'komposition-'.$composition->id + : ($elementId !== null ? 'element-'.$elementId : 'artikel-'.$article->id); + $materials[$key] = [ 'article' => $article, 'title' => app(CourseOutline::class)->title($article), 'kind' => app(CourseOutline::class)->kindLabel($article), diff --git a/tests/Feature/LibraryCompletionTest.php b/tests/Feature/LibraryCompletionTest.php index ec78371..27280bb 100644 --- a/tests/Feature/LibraryCompletionTest.php +++ b/tests/Feature/LibraryCompletionTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature; use App\Domain\Catalog\ArticleService; +use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionDisplayRelease; use App\Domain\Catalog\ContentService; use App\Domain\Catalog\EditorialContentKind; @@ -62,4 +63,14 @@ public function test_didactic_fields_partial_coverage_and_public_page_follow_the $this->get('/medien/bibliothek/geheim.jpg')->assertNotFound(); } + + public function test_review_fixture_can_be_repeated(): void + { + $actor = User::factory()->create(); + + $this->artisan('library:review-fixture', ['--actor' => $actor->id])->assertSuccessful(); + $this->artisan('library:review-fixture', ['--actor' => $actor->id])->assertSuccessful(); + + $this->assertSame(1, Composition::query()->where('designation', 'Prüfprogramm Abstand')->count()); + } }