diff --git a/app/Domain/Catalog/Composition.php b/app/Domain/Catalog/Composition.php index 8a6f282..188c726 100644 --- a/app/Domain/Catalog/Composition.php +++ b/app/Domain/Catalog/Composition.php @@ -3,6 +3,7 @@ namespace App\Domain\Catalog; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; class Composition extends Model @@ -10,6 +11,7 @@ class Composition extends Model protected $fillable = [ 'designation', 'kind', + 'editorial_content_kind_id', 'archived_at', ]; @@ -21,6 +23,11 @@ protected function casts(): array ]; } + public function editorialContentKind(): BelongsTo + { + return $this->belongsTo(EditorialContentKind::class); + } + public function versions(): HasMany { return $this->hasMany(CompositionVersion::class); diff --git a/app/Domain/Catalog/ContentElement.php b/app/Domain/Catalog/ContentElement.php index 1844e79..ea68840 100644 --- a/app/Domain/Catalog/ContentElement.php +++ b/app/Domain/Catalog/ContentElement.php @@ -3,6 +3,7 @@ namespace App\Domain\Catalog; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -13,6 +14,7 @@ class ContentElement extends Model 'output_class', 'working_title', 'description', + 'editorial_content_kind_id', 'archived_at', ]; @@ -23,6 +25,11 @@ protected function casts(): array ]; } + public function editorialContentKind(): BelongsTo + { + return $this->belongsTo(EditorialContentKind::class); + } + public function versions(): HasMany { return $this->hasMany(ContentElementVersion::class); diff --git a/app/Domain/Catalog/EditorialContentKind.php b/app/Domain/Catalog/EditorialContentKind.php new file mode 100644 index 0000000..6047c44 --- /dev/null +++ b/app/Domain/Catalog/EditorialContentKind.php @@ -0,0 +1,33 @@ +hasMany(Composition::class); + } + + public function contentElements(): HasMany + { + return $this->hasMany(ContentElement::class); + } + + /** + * @return array + */ + public static function selectOptions(): array + { + return static::query()->orderBy('sort_order')->pluck('label', 'id')->all(); + } +} \ No newline at end of file diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index ffe15e2..2e6dfb2 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -4,6 +4,7 @@ use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionKind; +use App\Domain\Catalog\EditorialContentKind; use App\Domain\Catalog\CompositionVersion; use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; @@ -44,6 +45,11 @@ public function form(Schema $schema): Schema TextInput::make('designation')->label('Bezeichnung')->required(), Select::make('kind')->label('Art')->options(CompositionKind::options())->required() ->helperText('Übung, Kurs und fachliche Kombination sind verschiedene Zusammenstellungen. Die Art lässt sich hier ändern.'), + Select::make('editorial_content_kind_id') + ->label('Inhaltsart') + ->options(fn (): array => EditorialContentKind::selectOptions()) + ->nullable() + ->helperText('Optional für Bibliothek und Website. Ändert weder die technische Art noch eine Fassung.'), Placeholder::make('history')->label('Aktuelle Fassung')->content(function (): HtmlString { /** @var Composition $composition */ $composition = $this->getRecord(); @@ -110,6 +116,7 @@ protected function mutateFormDataBeforeFill(array $data): array return [ 'designation' => $composition->designation, 'kind' => $kind instanceof CompositionKind ? $kind->value : $kind, + 'editorial_content_kind_id' => $composition->editorial_content_kind_id, 'members' => $members, 'note' => null, ]; @@ -125,6 +132,9 @@ protected function handleRecordUpdate(Model $record, array $data): Model $kind = CompositionKind::from($data['kind']); $record->designation = trim((string) $data['designation']); $record->kind = $kind; + $record->editorial_content_kind_id = filled($data['editorial_content_kind_id'] ?? null) + ? (int) $data['editorial_content_kind_id'] + : null; $record->save(); $members = []; diff --git a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php index cae043b..16c43de 100644 --- a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\ContentElements\Pages; use App\Domain\Catalog\ContentElement; +use App\Domain\Catalog\EditorialContentKind; use App\Domain\Catalog\ContentService; use App\Domain\Catalog\DomainRuleException; use App\Domain\Catalog\Pillar; @@ -16,6 +17,7 @@ use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Placeholder; use Filament\Forms\Components\Textarea; +use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; @@ -47,6 +49,11 @@ public function form(Schema $schema): Schema TextInput::make('working_title')->label('Arbeitstitel')->required(), Textarea::make('description')->label('Beschreibung')->rows(4) ->helperText('Gilt für das Medium, nicht für eine einzelne Fassung.'), + Select::make('editorial_content_kind_id') + ->label('Inhaltsart') + ->options(fn (): array => EditorialContentKind::selectOptions()) + ->nullable() + ->helperText('Optional für Bibliothek und Website. Ändert weder die Ausgabeart noch eine Fassung.'), CheckboxList::make('pillars') ->label('Fachliche Säulen') ->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all()) diff --git a/app/Http/CourseOutline.php b/app/Http/CourseOutline.php index 5c7a3c0..37ca130 100644 --- a/app/Http/CourseOutline.php +++ b/app/Http/CourseOutline.php @@ -34,7 +34,18 @@ public function kindLabel(LicenseArticle $article): ?string return null; } - $release->loadMissing('rootCompositionVersion.composition'); + $release->loadMissing([ + 'rootCompositionVersion.composition.editorialContentKind', + 'rootElementVersion.element.editorialContentKind', + ]); + + $editorial = $release->rootCompositionVersion?->composition?->editorialContentKind?->label + ?? $release->rootElementVersion?->element?->editorialContentKind?->label; + + if ($editorial !== null) { + return $editorial; + } + $kind = $release->rootCompositionVersion?->composition?->kind; return $kind instanceof CompositionKind ? $kind->label() : null; diff --git a/database/migrations/2026_11_16_110000_editorial_content_kinds.php b/database/migrations/2026_11_16_110000_editorial_content_kinds.php new file mode 100644 index 0000000..81e98e8 --- /dev/null +++ b/database/migrations/2026_11_16_110000_editorial_content_kinds.php @@ -0,0 +1,63 @@ +id(); + $table->string('slug')->unique(); + $table->string('label'); + $table->unsignedInteger('sort_order')->default(0); + $table->timestamps(); + }); + + $now = now(); + foreach ([ + ['slug' => 'programm', 'label' => 'Programm', 'sort_order' => 10], + ['slug' => 'modul', 'label' => 'Modul', 'sort_order' => 20], + ['slug' => 'merkblatt', 'label' => 'Merkblatt', 'sort_order' => 30], + ['slug' => 'traineranleitung', 'label' => 'Traineranleitung', 'sort_order' => 40], + ] as $row) { + DB::table('editorial_content_kinds')->insert([ + ...$row, + 'created_at' => $now, + 'updated_at' => $now, + ]); + } + + Schema::table('compositions', function (Blueprint $table) { + $table->foreignId('editorial_content_kind_id') + ->nullable() + ->after('kind') + ->constrained('editorial_content_kinds') + ->nullOnDelete(); + }); + + Schema::table('content_elements', function (Blueprint $table) { + $table->foreignId('editorial_content_kind_id') + ->nullable() + ->after('output_class') + ->constrained('editorial_content_kinds') + ->nullOnDelete(); + }); + } + + public function down(): void + { + Schema::table('content_elements', function (Blueprint $table) { + $table->dropConstrainedForeignId('editorial_content_kind_id'); + }); + + Schema::table('compositions', function (Blueprint $table) { + $table->dropConstrainedForeignId('editorial_content_kind_id'); + }); + + Schema::dropIfExists('editorial_content_kinds'); + } +}; \ No newline at end of file diff --git a/tests/Feature/EditorialContentKindTest.php b/tests/Feature/EditorialContentKindTest.php new file mode 100644 index 0000000..7482378 --- /dev/null +++ b/tests/Feature/EditorialContentKindTest.php @@ -0,0 +1,94 @@ +compositionArticle(CompositionKind::Kurs, designation: 'Demo-Kurs'); + + $this->assertSame('Kurs', app(CourseOutline::class)->kindLabel($article)); + $this->assertSame(CompositionKind::Kurs, $article->currentRelease->rootCompositionVersion->composition->kind); + } + + public function test_setting_editorial_kind_changes_display_without_touching_technical_kind(): void + { + $programm = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail(); + $article = $this->compositionArticle(CompositionKind::Kurs, designation: 'Programm-Demo'); + $composition = $article->currentRelease->rootCompositionVersion->composition; + $versionNumber = $article->currentRelease->rootCompositionVersion->number; + + $composition->editorial_content_kind_id = $programm->id; + $composition->save(); + + $composition->refresh(); + $article->refresh(); + + $this->assertSame('Programm', app(CourseOutline::class)->kindLabel($article)); + $this->assertSame(CompositionKind::Kurs, $composition->kind); + $this->assertSame($versionNumber, $article->currentRelease->rootCompositionVersion->number); + } + + public function test_an_element_can_show_merkblatt_without_changing_output_class(): void + { + $merkblatt = EditorialContentKind::query()->where('slug', 'merkblatt')->firstOrFail(); + $content = app(ContentService::class); + $articles = app(ArticleService::class); + $version = $content->publishElementVersion($content->createElement('text', 'document', 'PDF Demo'), null, ['file' => 'inhalte/demo.pdf']); + $element = $version->element; + $element->editorial_content_kind_id = $merkblatt->id; + $element->save(); + $article = $articles->create('pdf-demo'); + $articles->publishRelease($article, $version, 'Eigenständiges PDF.'); + + $this->assertSame('document', $element->fresh()->output_class); + $this->assertSame('Merkblatt', app(CourseOutline::class)->kindLabel($article->fresh())); + } + + public function test_a_new_kind_can_be_added_without_code_changes(): void + { + EditorialContentKind::query()->create([ + 'slug' => 'trainingsmodul', + 'label' => 'Trainingsmodul', + 'sort_order' => 50, + ]); + + $this->assertArrayHasKey( + EditorialContentKind::query()->where('slug', 'trainingsmodul')->value('id'), + EditorialContentKind::selectOptions(), + ); + } + + private function compositionArticle(CompositionKind $kind, string $designation) + { + $content = app(ContentService::class); + $leaf = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Inhalt'); + $composition = $content->publishComposition( + tap($content->createComposition($designation), fn ($c) => $c->update(['kind' => $kind])), + [['role' => 'Material', 'target' => $leaf]], + ); + $article = app(ArticleService::class)->create('art-'.$kind->value); + app(ArticleService::class)->publishRelease($article, $composition, 'Test.'); + $rights = app(OfferService::class)->createRightsProfile('Lesen', 'ehrenamtlich', ['text' => ['ansehen']]); + $offer = app(OfferService::class)->create('Gratis'); + app(OfferService::class)->activate($offer, [['target' => $article->fresh(), 'rights' => $rights]], ['grant_kind' => 'auf_abruf']); + $user = User::factory()->create(); + app(GrantIssuer::class)->claim($user, $offer); + + return $article->fresh(); + } +} \ No newline at end of file