Führe die zentrale Pflege redaktioneller Stammdaten ein
CI Feature / test (push) Successful in 1m12s
Deploy Test / test (push) Successful in 1m7s
Deploy Test / deploy (push) Successful in 23s

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>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-20 21:18:03 +01:00
1 parent c84ae10809
commit f774d43647
24 files changed
+1543 -91

No files matched your search

+59 -1
View File
@@ -2,17 +2,49 @@
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Fachliche Materialart (FACH-56 bis FACH-58). Die Bezeichnung ist pflegbar, die Kennung (slug) bleibt nach dem Anlegen
* fest. Zulässige Objektkontexte bestimmen, wo eine Materialart neu gewählt werden kann; vorhandene Zuordnungen bleiben
* immer erhalten (siehe EditorialVocabulary).
*/
class EditorialContentKind extends Model
{
/** Objektkontexte aus dem Fachmodell: Medium (ContentElement), Modul und Programm (Composition), Lizenzartikel. */
public const CONTEXTS = [
'medium' => 'Medium',
'modul' => 'Modul',
'programm' => 'Programm',
'lizenzartikel' => 'Lizenzartikel',
];
/**
* Kennungen, auf die der Code fachlich verweist: öffentliche Programmseiten und das Anlegen von Programmen und
* Modulen (programm, modul), Vertraulichkeit von Traineranleitungen (traineranleitung). Ihre Bezeichnung bleibt
* pflegbar; deaktivieren, Kontexte ändern und löschen sind gesperrt.
*/
public const SYSTEM_SLUGS = ['programm', 'modul', 'traineranleitung'];
protected $fillable = [
'slug',
'label',
'sort_order',
'is_active',
'contexts',
];
protected function casts(): array
{
return [
'is_active' => 'boolean',
'contexts' => 'array',
'sort_order' => 'integer',
];
}
public function compositions(): HasMany
{
return $this->hasMany(Composition::class);
@@ -23,11 +55,37 @@ public function contentElements(): HasMany
return $this->hasMany(ContentElement::class);
}
public function licenseArticles(): HasMany
{
return $this->hasMany(LicenseArticle::class);
}
/**
* @param Builder<EditorialContentKind> $query
*/
public function scopeActive(Builder $query): void
{
$query->where('is_active', true);
}
public function allows(string $context): bool
{
return in_array($context, (array) ($this->contexts ?? []), true);
}
public function isSystem(): bool
{
return in_array($this->slug, self::SYSTEM_SLUGS, true);
}
/**
* Alle Materialarten in Pflegereihenfolge (ohne Kontext- oder Aktivfilter). Für Auswahlstellen gilt
* EditorialVocabulary.
*
* @return array<int, string>
*/
public static function selectOptions(): array
{
return static::query()->orderBy('sort_order')->pluck('label', 'id')->all();
return static::query()->orderBy('sort_order')->orderBy('id')->pluck('label', 'id')->all();
}
}
+6 -2
View File
@@ -8,11 +8,15 @@
class EditorialDimension extends Model
{
/** Gespiegelte Säulen; gepflegt werden Säulen über die Säulenverwaltung, nicht als Stammdaten. */
public const PILLAR_SLUG = 'saeule';
protected $fillable = ['slug', 'label'];
/** Werte in Pflegereihenfolge. */
public function values(): HasMany
{
return $this->hasMany(EditorialDimensionValue::class);
return $this->hasMany(EditorialDimensionValue::class)->orderBy('sort_order')->orderBy('id');
}
/**
@@ -26,7 +30,7 @@ public static function forSubject(Model $subject): Collection
$query = static::query()->with('values')->orderBy('label');
if ($subject instanceof ContentElement) {
$query->where('slug', '!=', 'saeule');
$query->where('slug', '!=', self::PILLAR_SLUG);
}
return $query->get();
@@ -7,7 +7,15 @@
class EditorialDimensionValue extends Model
{
protected $fillable = ['editorial_dimension_id', 'slug', 'label'];
protected $fillable = ['editorial_dimension_id', 'slug', 'label', 'sort_order', 'is_active'];
protected function casts(): array
{
return [
'is_active' => 'boolean',
'sort_order' => 'integer',
];
}
public function dimension(): BelongsTo
{
+252
View File
@@ -0,0 +1,252 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
/**
* Eine Regelquelle für redaktionelle Stammdaten (FACH-56 bis FACH-58): Welche fachlichen Materialarten und welche
* Einordnungswerte Editor, Filter und Picker anbieten.
*
* - Neu wählbar sind nur aktive Werte; Materialarten zusätzlich nur im zulässigen Objektkontext.
* - Vorhandene Zuordnungen bleiben sichtbar und erhalten, auch wenn der Wert inaktiv ist oder sein Kontext geändert
* wurde; sie sind gekennzeichnet.
* - Filter finden auch Objekte mit inaktiven Werten; ein gewählter Filter bleibt erhalten.
*/
final class EditorialVocabulary
{
public const INACTIVE_SUFFIX = ' (inaktiv)';
public const OUT_OF_CONTEXT_SUFFIX = ' (hier nicht vorgesehen)';
/**
* Objektkontext eines Fachobjekts nach dem Fachmodell, null wenn es keine Materialart trägt.
*/
public function contextOf(Model $subject): ?string
{
if ($subject instanceof ContentElement) {
return 'medium';
}
if ($subject instanceof LicenseArticle) {
return 'lizenzartikel';
}
if ($subject instanceof Composition) {
return self::compositionContext($subject->kind instanceof CompositionKind ? $subject->kind : CompositionKind::tryFrom((string) $subject->kind));
}
return null;
}
public static function compositionContext(?CompositionKind $kind): ?string
{
return match ($kind) {
CompositionKind::Kurs => 'programm',
CompositionKind::Uebung => 'modul',
default => null,
};
}
/**
* Auswahl der Materialart in einem Editor: aktive, im Kontext zulässige Arten in Pflegereihenfolge, dazu die
* bereits zugeordnete Art mit Kennzeichnung, falls sie inaktiv oder hier nicht vorgesehen ist.
*
* @return array<int, string>
*/
public function kindOptions(string $context, ?int $currentId = null): array
{
$options = [];
foreach (EditorialContentKind::query()->orderBy('sort_order')->orderBy('id')->get() as $kind) {
$offered = $kind->is_active && $kind->allows($context);
if ($offered) {
$options[$kind->id] = (string) $kind->label;
} elseif ($currentId !== null && $kind->id === $currentId) {
$options[$kind->id] = $this->kindLabel($kind, $context);
}
}
return $options;
}
/**
* Prüft eine neue Materialart serverseitig. Die bereits gespeicherte Art bleibt immer zulässig.
*/
public function kindError(string $context, ?int $newId, ?int $storedId): ?string
{
if ($newId === null || $newId === $storedId) {
return null;
}
$kind = EditorialContentKind::query()->find($newId);
if (! $kind instanceof EditorialContentKind) {
return 'Diese fachliche Materialart gibt es nicht mehr.';
}
if (! $kind->is_active) {
return 'Die fachliche Materialart „'.$kind->label.'“ ist deaktiviert und kann nicht neu gewählt werden.';
}
if (! $kind->allows($context)) {
return 'Die fachliche Materialart „'.$kind->label.'“ ist für '.(EditorialContentKind::CONTEXTS[$context] ?? $context).' nicht vorgesehen.';
}
return null;
}
/**
* Filteroptionen der Materialart für einen Bestand: im Kontext zulässige Arten und Arten, die dort tatsächlich
* vorkommen (gekennzeichnet), dazu ein bereits gewählter Filter.
*
* @return array<string, string>
*/
public function kindFilterOptions(string $context, string $selected = ''): array
{
$used = $this->usedKindIds($context);
$options = [];
foreach (EditorialContentKind::query()->orderBy('sort_order')->orderBy('id')->get() as $kind) {
$show = ($kind->allows($context) && $kind->is_active) || in_array($kind->id, $used, true) || (string) $kind->id === $selected;
if ($show) {
$options[(string) $kind->id] = $this->kindLabel($kind, $context);
}
}
return $options;
}
public function kindLabel(EditorialContentKind $kind, string $context): string
{
return (string) $kind->label
.(! $kind->is_active ? self::INACTIVE_SUFFIX : (! $kind->allows($context) ? self::OUT_OF_CONTEXT_SUFFIX : ''));
}
/**
* @return list<int>
*/
private function usedKindIds(string $context): array
{
$query = match ($context) {
'medium' => DB::table('content_elements'),
'lizenzartikel' => DB::table('license_articles'),
'programm' => DB::table('compositions')->where('kind', CompositionKind::Kurs->value),
'modul' => DB::table('compositions')->where('kind', CompositionKind::Uebung->value),
default => null,
};
return $query === null ? [] : $query->whereNotNull('editorial_content_kind_id')->distinct()
->pluck('editorial_content_kind_id')->map(fn ($id): int => (int) $id)->all();
}
/**
* Einordnung im Editor: je angebotener Dimension aktive Werte und bereits zugeordnete inaktive Werte (gekennzeichnet).
*
* @param list<int> $assignedIds
* @return list<array{label: string, values: list<array{id: int, label: string, inactive: bool}>}>
*/
public function dimensionGroups(Model $subject, array $assignedIds): array
{
$groups = [];
foreach (EditorialDimension::forSubject($subject) as $dimension) {
$values = [];
foreach ($dimension->values as $value) {
if ($value->is_active || in_array((int) $value->id, $assignedIds, true)) {
$values[] = [
'id' => (int) $value->id,
'label' => (string) $value->label.($value->is_active ? '' : self::INACTIVE_SUFFIX),
'inactive' => ! $value->is_active,
];
}
}
if ($values !== []) {
$groups[] = ['label' => (string) $dimension->label, 'values' => $values];
}
}
return $groups;
}
/**
* Filtergruppen der Einordnung: aktive Werte, verwendete inaktive Werte (gekennzeichnet) und gewählte Filter.
*
* @param list<int> $selectedIds
* @return list<array{label: string, values: list<array{id: int, label: string}>}>
*/
public function dimensionFilterGroups(array $selectedIds = [], bool $withPillars = true): array
{
$used = DB::table('identity_dimension_values')->distinct()->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all();
$groups = [];
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
if (! $withPillars && $dimension->slug === EditorialDimension::PILLAR_SLUG) {
continue;
}
$values = [];
foreach ($dimension->values as $value) {
$id = (int) $value->id;
if ($value->is_active || in_array($id, $used, true) || in_array($id, $selectedIds, true)) {
$values[] = ['id' => $id, 'label' => (string) $value->label.($value->is_active ? '' : self::INACTIVE_SUFFIX)];
}
}
if ($values !== []) {
$groups[] = ['label' => (string) $dimension->label, 'values' => $values];
}
}
return $groups;
}
/**
* Öffentliche Filter der Mitgliederbibliothek: nur aktive Werte, ein bereits gewählter Wert bleibt sichtbar.
*
* @param list<int> $selectedIds
* @return Collection<int, EditorialDimension>
*/
public function memberFilterDimensions(array $selectedIds = []): Collection
{
$dimensions = EditorialDimension::query()->with('values')->orderBy('label')->get();
foreach ($dimensions as $dimension) {
$dimension->setRelation('values', $dimension->values
->filter(fn (EditorialDimensionValue $value): bool => $value->is_active || in_array((int) $value->id, $selectedIds, true))
->values());
}
return $dimensions->filter(fn (EditorialDimension $dimension): bool => $dimension->values->isNotEmpty())->values();
}
/**
* Für replaceOffered: Werte, die bei diesem Fachobjekt gesetzt oder entfernt werden dürfen. Aktive Werte der
* angebotenen Dimensionen und die bereits zugeordneten inaktiven (der Editor zeigt sie gekennzeichnet an).
*
* @param list<int> $assignedIds
* @return list<int>
*/
public function editableValueIds(Model $subject, array $assignedIds): array
{
$ids = [];
foreach (EditorialDimension::forSubject($subject) as $dimension) {
foreach ($dimension->values as $value) {
if ($value->is_active || in_array((int) $value->id, $assignedIds, true)) {
$ids[] = (int) $value->id;
}
}
}
return $ids;
}
}
+10 -1
View File
@@ -57,11 +57,20 @@ public function matches(Model $subject, array $valueIds): bool
* Ersetzt nur die Werte der Dimensionen, die dieses Fachobjekt anbietet.
* Nicht angebotene Zuordnungen, etwa gespiegelte Säulen am Inhaltselement, bleiben.
*
* Inaktive Werte (Stammdatenpflege) sind nicht neu wählbar. Bereits zugeordnete inaktive Werte zeigt der Editor
* gekennzeichnet an; sie bleiben, solange sie mitgeschickt werden, und werden nur bei ausdrücklicher Abwahl entfernt.
*
* @param list<int> $valueIds
*/
public function replaceOffered(Model $subject, array $valueIds): void
{
$offeredIds = EditorialDimension::offeredValueIds($subject);
$assigned = IdentityDimensionValue::query()
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->pluck('editorial_dimension_value_id')
->map(fn ($id): int => (int) $id)
->all();
$offeredIds = app(EditorialVocabulary::class)->editableValueIds($subject, $assigned);
$ids = array_values(array_intersect(
array_values(array_unique(array_map(intval(...), $valueIds))),
$offeredIds,