Files
laraundfelix/app/Console/Commands/SeedLibraryReview.php
LarsandCursor 8d0a0b8cc6
Deploy Test / test (push) Successful in 17s
Deploy Test / deploy (push) Successful in 22s
Lege das Pruefkonto ohne Faker an
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 08:45:16 +01:00

140 lines
5.2 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\Domain\Identity\AccountStatus;
use App\Domain\Identity\Party;
use App\Domain\Identity\PartyType;
use App\Domain\Identity\Profile;
use App\Models\User;
use Illuminate\Console\Command;
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) {
$party = Party::query()->create([
'type' => PartyType::Person,
'display_name' => 'Trainer Prüfung',
]);
Profile::query()->create([
'party_id' => $party->id,
'display_name' => 'Trainer Prüfung',
'visibility' => ['display_name' => 'private'],
]);
$trainer = new User;
$trainer->forceFill([
'party_id' => $party->id,
'name' => 'Trainer Prüfung',
'email' => 'trainer-pruefung@example.test',
'password' => 'Kursraum-Pruefung',
'status' => AccountStatus::Aktiv,
'confirmed_adult_at' => now(),
'email_verified_at' => now(),
]);
$trainer->save();
}
$offer = Offer::query()->where('name', 'Prüfprogramm Abstand')->first();
if ($offer !== null) {
app(GrantIssuer::class)->claim($trainer, $offer);
}
}
}