Files
laraundfelix/app/Console/Commands/SeedLibraryReview.php
LarsandClaude Opus 5.5 f774d43647
CI Feature / test (push) Successful in 1m12s
Deploy Test / test (push) Successful in 1m7s
Deploy Test / deploy (push) Successful in 23s
Führe die zentrale Pflege redaktioneller Stammdaten ein
FACH-56 bis FACH-58: Arbeitsplatz „Redaktionelle Stammdaten“ für fachliche
Materialarten, Altersbereich und Zielgruppe, Einsatzbereiche und
Verwendungszwecke (bestehende Tabellen; Säulen bleiben in ihrer Verwaltung).

- Migration (nur Ergänzungen): aktiv/inaktiv für Materialarten und Werte,
  Reihenfolge der Werte, zulässige Objektkontexte der Materialarten, einmalig
  aus dem Bestand abgeleitet; jede vorhandene Zuordnung bleibt zulässig.
- EditorialVocabulary als eine Regelquelle für Redaktion (Medium, Modul,
  Programm, Lizenzartikel), Medien- und Kompositionsfilter, Picker und
  Mitgliederbibliothek: neu wählbar nur aktive, kontextgerechte Werte;
  vorhandene inaktive Zuordnungen sichtbar und beim Speichern erhalten;
  serverseitige Prüfung der Materialart.
- Kennung fest, Bezeichnung pflegbar; verwendete Werte nur deaktivierbar;
  Systemkennungen (programm, modul, traineranleitung) geschützt.
- „Inhaltsart“ heißt durchgängig „Fachliche Materialart“; der Picker trennt
  Medienart und fachliche Materialart und filtert danach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 21:18:03 +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 fachliche Materialart 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);
}
}
}