Paket 2: konfigurierbare Inhaltsart an Identitaet
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7820bececb
commit
1a2b1298b5
8 files changed
+233
-1
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class EditorialContentKind extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'slug',
|
||||
'label',
|
||||
'sort_order',
|
||||
];
|
||||
|
||||
public function compositions(): HasMany
|
||||
{
|
||||
return $this->hasMany(Composition::class);
|
||||
}
|
||||
|
||||
public function contentElements(): HasMany
|
||||
{
|
||||
return $this->hasMany(ContentElement::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function selectOptions(): array
|
||||
{
|
||||
return static::query()->orderBy('sort_order')->pluck('label', 'id')->all();
|
||||
}
|
||||
}
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('editorial_content_kinds', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Http\CourseOutline;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EditorialContentKindTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_a_composition_without_editorial_kind_keeps_technical_kind_label(): void
|
||||
{
|
||||
$article = $this->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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user