Files
laraundfelix/app/Console/Commands/SeedLibraryReview.php
T
LarsandCursor 1d8315c9a4
Deploy Test / test (push) Successful in 17s
Deploy Test / deploy (push) Successful in 23s
Gestalte den Mitgliederbereich fuer den Kursraum
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 08:43:13 +01:00

122 lines
4.5 KiB
PHP

<?php
namespace App\Console\Commands;
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;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
use App\Domain\Entitlement\GrantIssuer;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
class SeedLibraryReview extends Command
{
protected $signature = 'library:review-fixture {--actor=}';
protected $description = 'Legt einmalig einen gekennzeichneten Prüfbestand für die Bibliothek an';
public function handle(
ContentService $content,
ArticleService $articles,
OfferService $offers,
CompositionDisplayRelease $display,
): int {
$existing = Composition::query()->where('designation', 'Prüfprogramm Abstand')->first();
if ($existing === null) {
$created = $this->createFixture($content, $articles, $offers, $display);
if ($created !== self::SUCCESS) {
return $created;
}
} else {
$existing->display_title = 'Prüfprogramm Abstand und ein bewusst langer Titel für die Kursraumansicht';
$existing->summary = 'Gekennzeichneter Prüfbestand für die Testinstanz. Der Titel ist lang, damit die Karte im Kursraum prüfbar bleibt.';
$existing->save();
}
$this->ensureTrainer();
$this->info('Prüfbestand und Trainingskonto sind bereit.');
return self::SUCCESS;
}
private function createFixture(
ContentService $content,
ArticleService $articles,
OfferService $offers,
CompositionDisplayRelease $display,
): int {
$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 und ein bewusst langer Titel für die Kursraumansicht';
$composition->summary = 'Gekennzeichneter Prüfbestand für die Testinstanz. Der Titel ist lang, damit die Karte im Kursraum prüfbar bleibt.';
$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');
return self::SUCCESS;
}
private function ensureTrainer(): void
{
$trainer = User::query()->where('email', 'trainer-pruefung@example.test')->first();
if ($trainer === null) {
$trainer = User::factory()->create([
'name' => 'Trainer Prüfung',
'email' => 'trainer-pruefung@example.test',
'password' => Hash::make('Kursraum-Pruefung'),
]);
}
$offer = Offer::query()->where('name', 'Prüfprogramm Abstand')->first();
if ($offer !== null) {
app(GrantIssuer::class)->claim($trainer, $offer);
}
}
}