Vereinheitliche die fachlichen Säulen auf die zentrale Säulenverwaltung
CI Feature / test (push) Successful in 1m34s
Deploy Test / test (push) Successful in 1m29s
Deploy Test / deploy (push) Successful in 29s

Module, Programme und Lizenzartikel verwenden wie Medien und Seiten die Tabelle
pillars; die Kopie „Fachliche Säule“ in den redaktionellen Dimensionen wird nirgends
mehr angeboten, geändert oder gefiltert und bleibt nur als Verlauf erhalten.

- Migration (nur Ergänzungen): composition_pillar und license_article_pillar mit
  restrictOnDelete, pillar_id an den alten Dimensionswerten als dokumentierte
  Abbildung, einmalige wiederholbare Übernahme (LegacyPillarAdoption).
- Übernahme nur über die gespeicherte Kennung pfeiler-<Nummer> und nur direkte
  Zuordnungen; mehrdeutige, abgeleitete und verwaiste Fälle werden gemeldet, nicht
  geraten. Medien bleiben bei ihrer Zuordnung. Alte Zeilen bleiben unverändert.
  Befehl: php artisan luf:saeulen-uebernehmen [--dry-run].
- Editoren von Modul, Programm und Lizenzartikel wählen Säulen aus der Säulenverwaltung;
  PillarService::assign gilt für alle Objektarten, Löschschutz zählt alle Objektarten.
- Filter: Module und Programme, Aufbau-Picker und Mitgliederbibliothek nach der
  Säulenzuordnung; alte Adressen mit einem Säulenwert der Einordnung folgen der Säule.
- Abgeleitete Säulen (aus enthaltenen Medien) bleiben getrennt von direkten.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-21 10:11:42 +01:00
1 parent d5c2b34b9d
commit 7c48a6480c
25 files changed
+1250 -44

No files matched your search

@@ -0,0 +1,25 @@
<?php
namespace App\Console\Commands;
use App\Domain\Catalog\LegacyPillarAdoption;
use Illuminate\Console\Command;
class AdoptLegacyPillars extends Command
{
protected $signature = 'luf:saeulen-uebernehmen {--dry-run : Nur berichten, nichts schreiben}';
protected $description = 'Übernimmt die alte Dimension „Fachliche Säule“ in die zentrale Säulenverwaltung und berichtet ungeklärte Fälle';
public function handle(): int
{
$dryRun = (bool) $this->option('dry-run');
$report = (new LegacyPillarAdoption)->run($dryRun);
foreach (LegacyPillarAdoption::lines($report, $dryRun) as $line) {
$this->line($line);
}
return $report['unresolved'] === [] ? self::SUCCESS : self::FAILURE;
}
}
+10
View File
@@ -4,6 +4,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Composition extends Model
@@ -44,4 +45,13 @@ public function versions(): HasMany
{
return $this->hasMany(CompositionVersion::class);
}
/**
* Direkt zugeordnete fachliche Säulen (zentrale Säulenverwaltung). Die Säulen der enthaltenen Medien sind davon
* getrennt und werden zur Laufzeit abgeleitet (CatalogReading::memberPillars).
*/
public function pillars(): BelongsToMany
{
return $this->belongsToMany(Pillar::class)->orderBy('pillars.sort_order')->orderBy('pillars.name');
}
}
+4 -9
View File
@@ -20,20 +20,15 @@ public function values(): HasMany
}
/**
* Inhaltselemente pflegen Themen über die Säulen, nicht noch einmal über die Dimension.
* Module, Programme und Lizenzartikel haben keine Säulenauswahl und behalten die Dimension.
* Fachliche Säulen werden für alle Objektarten über die zentrale Säulenverwaltung gewählt (`pillars`), nie über
* eine Dimension. Die alte Dimension „Fachliche Säule“ bleibt nur als Verlauf in der Datenbank und wird nirgends
* mehr angeboten, geändert oder gefiltert.
*
* @return Collection<int, self>
*/
public static function forSubject(Model $subject): Collection
{
$query = static::query()->with('values')->orderBy('label');
if ($subject instanceof ContentElement) {
$query->where('slug', '!=', self::PILLAR_SLUG);
}
return $query->get();
return static::query()->with('values')->where('slug', '!=', self::PILLAR_SLUG)->orderBy('label')->get();
}
/**
@@ -7,7 +7,7 @@
class EditorialDimensionValue extends Model
{
protected $fillable = ['editorial_dimension_id', 'slug', 'label', 'sort_order', 'is_active'];
protected $fillable = ['editorial_dimension_id', 'pillar_id', 'slug', 'label', 'sort_order', 'is_active'];
protected function casts(): array
{
+3 -3
View File
@@ -181,13 +181,13 @@ public function dimensionGroups(Model $subject, array $assignedIds): array
* @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
public function dimensionFilterGroups(array $selectedIds = []): 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) {
if ($dimension->slug === EditorialDimension::PILLAR_SLUG) {
continue;
}
@@ -217,7 +217,7 @@ public function dimensionFilterGroups(array $selectedIds = [], bool $withPillars
*/
public function memberFilterDimensions(array $selectedIds = []): Collection
{
$dimensions = EditorialDimension::query()->with('values')->orderBy('label')->get();
$dimensions = EditorialDimension::query()->with('values')->where('slug', '!=', EditorialDimension::PILLAR_SLUG)->orderBy('label')->get();
foreach ($dimensions as $dimension) {
$dimension->setRelation('values', $dimension->values
+270
View File
@@ -0,0 +1,270 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Support\Facades\DB;
/**
* Übernimmt die frühere Kopie „Fachliche Säule“ (Dimension `saeule`) in die zentrale Säulenverwaltung (Tabelle
* `pillars`). Verlustfrei, wiederholbar und ohne Raten:
*
* - **Zuordnung Wert → Säule** nur über die gespeicherte Kennung `pfeiler-{Säulenkennung}`, die die Migration
* vom 16.11.2026 beim Spiegeln geschrieben hat, und nur, wenn die Säule existiert und nicht jünger als der Wert ist
* (sonst kann die Kennung nicht aus ihr entstanden sein). Eine abweichende Bezeichnung ist nach einem Umbenennen
* erwartet und wird nur berichtet. Die Verknüpfung steht in `editorial_dimension_values.pillar_id`.
* - **Übernommen** werden nur direkte Zuordnungen von Modulen, Programmen und Lizenzartikeln in `composition_pillar`
* und `license_article_pillar` (insert-or-ignore, daher beliebig oft ausführbar).
* - **Nicht übernommen, sondern gemeldet:** Werte ohne belastbare Kennung, Zuordnungen zu fehlenden Objekten,
* abgeleitete Zuordnungen und unbekannte Objektarten. Abgeleitete Säulen eines Programms oder Moduls entstehen zur
* Laufzeit aus den enthaltenen Medien und werden nie als direkte Zuordnung gespeichert.
* - **Medien:** Die gespiegelten Zeilen sind eine veraltete Kopie; maßgeblich ist `content_element_pillar`. Sie werden
* nicht zurückgemischt, nur gezählt.
* - Alte Zeilen werden weder geändert noch gelöscht.
*
* Nur die Datenbankfassade, damit spätere Änderungen an Modellen die Migration nicht berühren.
*/
final class LegacyPillarAdoption
{
/** @var array<string, array{table: string, column: string, subjects: string}> */
private const TARGETS = [
'composition' => ['table' => 'composition_pillar', 'column' => 'composition_id', 'subjects' => 'compositions'],
'license_article' => ['table' => 'license_article_pillar', 'column' => 'license_article_id', 'subjects' => 'license_articles'],
];
/**
* @return array{
* mapping: list<array<string, mixed>>,
* unresolved: list<array<string, mixed>>,
* copied: array<string, int>,
* already: array<string, int>,
* before: array<string, int>,
* after: array<string, int>,
* mirror: array<string, int>
* }
*/
public function run(bool $dryRun = false): array
{
$report = [
'mapping' => [],
'unresolved' => [],
'copied' => ['composition' => 0, 'license_article' => 0],
'already' => ['composition' => 0, 'license_article' => 0],
'before' => $this->counts(),
'after' => [],
'mirror' => ['element_rows' => 0, 'missing_in_pivot' => 0, 'only_in_pivot' => 0],
];
$dimension = DB::table('editorial_dimensions')->where('slug', 'saeule')->first();
if ($dimension === null) {
$report['after'] = $report['before'];
return $report;
}
$resolved = [];
foreach (DB::table('editorial_dimension_values')->where('editorial_dimension_id', $dimension->id)->orderBy('id')->get() as $value) {
$pillar = $this->pillarFor($value);
if (is_string($pillar)) {
$report['unresolved'][] = ['art' => 'Wert', 'wert_id' => (int) $value->id, 'wert' => $value->label, 'kennung' => $value->slug, 'grund' => $pillar];
$report['mapping'][] = ['wert_id' => (int) $value->id, 'wert' => $value->label, 'saeule_id' => null, 'status' => 'offen'];
continue;
}
$resolved[(int) $value->id] = (int) $pillar->id;
$status = $value->pillar_id === null ? 'zugeordnet' : 'bereits zugeordnet';
$hint = $value->label !== $pillar->name ? 'über Kennung zugeordnet, Bezeichnung weicht ab („'.$pillar->name.'“)' : null;
$report['mapping'][] = ['wert_id' => (int) $value->id, 'wert' => $value->label, 'saeule_id' => (int) $pillar->id, 'saeule' => $pillar->name, 'status' => $status, 'hinweis' => $hint];
if ($value->pillar_id === null && ! $dryRun) {
DB::table('editorial_dimension_values')->where('id', $value->id)->update(['pillar_id' => $pillar->id]);
}
}
$subjectTypes = $this->subjectTypes();
foreach (DB::table('identity_dimension_values')
->whereIn('editorial_dimension_value_id', DB::table('editorial_dimension_values')->where('editorial_dimension_id', $dimension->id)->select('id'))
->orderBy('id')->get() as $row) {
$valueId = (int) $row->editorial_dimension_value_id;
$label = DB::table('editorial_dimension_values')->where('id', $valueId)->value('label');
$target = $subjectTypes[$row->subject_type] ?? null;
if ($target === 'content_element') {
$report['mirror']['element_rows']++;
continue;
}
$where = ['art' => 'Zuordnung', 'zuordnung_id' => (int) $row->id, 'wert_id' => $valueId, 'wert' => $label, 'objektart' => $row->subject_type, 'objekt_id' => (int) $row->subject_id, 'herkunft' => $row->origin];
if ($target === null) {
$report['unresolved'][] = $where + ['grund' => 'unbekannte Objektart'];
continue;
}
if ($row->origin !== 'direkt') {
$report['unresolved'][] = $where + ['grund' => 'abgeleitete Zuordnung (wird nicht als direkte übernommen)'];
continue;
}
if (! isset($resolved[$valueId])) {
$report['unresolved'][] = $where + ['grund' => 'Wert ohne belastbare Säule'];
continue;
}
$config = self::TARGETS[$target];
if (! DB::table($config['subjects'])->where('id', $row->subject_id)->exists()) {
$report['unresolved'][] = $where + ['grund' => 'Objekt nicht mehr vorhanden'];
continue;
}
$present = DB::table($config['table'])->where($config['column'], $row->subject_id)->where('pillar_id', $resolved[$valueId])->exists();
if ($present) {
$report['already'][$target]++;
continue;
}
if (! $dryRun) {
DB::table($config['table'])->insertOrIgnore([$config['column'] => $row->subject_id, 'pillar_id' => $resolved[$valueId]]);
}
$report['copied'][$target]++;
}
$report['mirror'] = array_merge($report['mirror'], $this->mirrorDivergence($dimension->id, $resolved));
$report['after'] = $dryRun ? $report['before'] : $this->counts();
return $report;
}
/**
* @param array<string, mixed> $report
* @return list<string>
*/
public static function lines(array $report, bool $dryRun = false): array
{
$names = ['composition' => 'Module und Programme', 'license_article' => 'Lizenzartikel'];
$lines = [$dryRun ? 'Probelauf, es wird nichts geschrieben.' : 'Übernahme abgeschlossen.', ''];
foreach ($report['mapping'] as $row) {
$lines[] = sprintf('Wert %d „%s“ → %s%s', $row['wert_id'], $row['wert'], $row['saeule_id'] === null ? 'keine Säule (offen)' : 'Säule '.$row['saeule_id'].' „'.($row['saeule'] ?? '').'“ ('.$row['status'].')', ! empty($row['hinweis']) ? ' – '.$row['hinweis'] : '');
}
$lines[] = '';
foreach ($names as $key => $label) {
$lines[] = sprintf('%s: %d übernommen, %d bereits vorhanden, Zuordnungen vorher %d, nachher %d', $label, $report['copied'][$key], $report['already'][$key], $report['before'][$key], $report['after'][$key]);
}
$lines[] = sprintf('Medien (nur Information): %d gespiegelte Zeilen, %d nicht mehr in der Medienzuordnung, %d nur dort. Maßgeblich bleibt die Medienzuordnung.', $report['mirror']['element_rows'], $report['mirror']['missing_in_pivot'], $report['mirror']['only_in_pivot']);
if ($report['unresolved'] === []) {
$lines[] = 'Keine ungeklärten Fälle.';
} else {
$lines[] = '';
$lines[] = 'Ungeklärt, bitte entscheiden (nichts wurde geändert):';
foreach ($report['unresolved'] as $row) {
$lines[] = '- '.json_encode($row, JSON_UNESCAPED_UNICODE);
}
}
return $lines;
}
/**
* Die Säule zu einem alten Wert, oder der Grund, warum es keine belastbare gibt.
*/
private function pillarFor(object $value): object|string
{
if (preg_match('/^pfeiler-(\d+)$/', (string) $value->slug, $match) !== 1) {
return 'Kennung ist nicht „pfeiler-<Nummer>“, keine belastbare Verknüpfung';
}
$pillar = DB::table('pillars')->where('id', (int) $match[1])->first();
if ($pillar === null) {
return 'Die Säule zur Kennung existiert nicht mehr';
}
if ($value->pillar_id !== null && (int) $value->pillar_id !== (int) $pillar->id) {
return 'Gespeicherte Verknüpfung (Säule '.$value->pillar_id.') und Kennung (Säule '.$pillar->id.') widersprechen sich';
}
if ($pillar->created_at !== null && $value->created_at !== null && $pillar->created_at > $value->created_at) {
return 'Die Säule ist jünger als der Wert; die Kennung kann nicht aus ihr entstanden sein';
}
return $pillar;
}
/**
* @return array<string, string> Objektart wie gespeichert => Ziel
*/
private function subjectTypes(): array
{
$types = [];
foreach ([
'composition' => [Composition::class],
'license_article' => [LicenseArticle::class],
'content_element' => [ContentElement::class],
] as $target => $classes) {
foreach ($classes as $class) {
$types[$class] = $target;
$types[(new $class)->getMorphClass()] = $target;
}
}
return $types;
}
/**
* @return array<string, int>
*/
private function counts(): array
{
return [
'composition' => DB::table('composition_pillar')->count(),
'license_article' => DB::table('license_article_pillar')->count(),
];
}
/**
* @param array<int, int> $resolved
* @return array{missing_in_pivot: int, only_in_pivot: int}
*/
private function mirrorDivergence(int $dimensionId, array $resolved): array
{
$mirrored = [];
foreach (DB::table('identity_dimension_values')
->whereIn('subject_type', array_unique([ContentElement::class, (new ContentElement)->getMorphClass()]))
->whereIn('editorial_dimension_value_id', array_keys($resolved) ?: [0])
->get() as $row) {
$mirrored[$row->subject_id.':'.$resolved[(int) $row->editorial_dimension_value_id]] = true;
}
$pivot = [];
foreach (DB::table('content_element_pillar')->get() as $row) {
$pivot[$row->content_element_id.':'.$row->pillar_id] = true;
}
return [
'missing_in_pivot' => count(array_diff_key($mirrored, $pivot)),
'only_in_pivot' => count(array_diff_key($pivot, $mirrored)),
];
}
}
+7
View File
@@ -4,6 +4,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class LicenseArticle extends Model
@@ -49,4 +50,10 @@ public function editorialContentKind(): BelongsTo
{
return $this->belongsTo(EditorialContentKind::class);
}
/** Direkt zugeordnete fachliche Säulen (zentrale Säulenverwaltung). */
public function pillars(): BelongsToMany
{
return $this->belongsToMany(Pillar::class)->orderBy('pillars.sort_order')->orderBy('pillars.name');
}
}
+10
View File
@@ -34,6 +34,16 @@ public function pages(): BelongsToMany
return $this->belongsToMany(Page::class);
}
public function compositions(): BelongsToMany
{
return $this->belongsToMany(Composition::class);
}
public function licenseArticles(): BelongsToMany
{
return $this->belongsToMany(LicenseArticle::class);
}
/**
* @param Builder<Pillar> $query
* @return Builder<Pillar>
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Support\Facades\DB;
/**
* Alte Filteradressen: Vor der Vereinheitlichung war „Fachliche Säule“ ein Wert der redaktionellen Einordnung
* (`?einordnung=…`, `?pillar=…`, `dimension[]=…`). Verweist ein solcher Wert über `pillar_id` auf eine zentrale Säule,
* gilt der Filter jetzt für diese Säule, statt stillschweigend zu entfallen.
*/
final class PillarFilterCompat
{
/**
* @return int|null|false Kennung der Säule; null: alter Säulenwert ohne belastbare Verknüpfung; false: kein Säulenwert
*/
public static function pillarOfLegacyValue(int $valueId): int|false|null
{
$row = DB::table('editorial_dimension_values')
->join('editorial_dimensions', 'editorial_dimensions.id', '=', 'editorial_dimension_values.editorial_dimension_id')
->where('editorial_dimension_values.id', $valueId)
->where('editorial_dimensions.slug', EditorialDimension::PILLAR_SLUG)
->first(['editorial_dimension_values.pillar_id']);
if ($row === null) {
return false;
}
return $row->pillar_id === null ? null : (int) $row->pillar_id;
}
}
+42 -6
View File
@@ -40,19 +40,55 @@ public function present(Pillar $pillar, string $name, string $slug, ?string $sum
public function delete(Pillar $pillar): void
{
if ($pillar->elements()->exists() || $pillar->pages()->exists()) {
throw new DomainRuleException('Eine Säule mit zugeordneten Medien oder Seiten wird nicht gelöscht.');
$usage = $this->usage($pillar);
if (array_sum($usage) > 0) {
throw new DomainRuleException('Eine Säule mit zugeordneten Objekten wird nicht gelöscht ('.$this->usageText($usage).'). Ordnen Sie sie zuerst anders zu.');
}
$pillar->delete();
}
/**
* @param list<int> $pillarIds
* Zuordnungen je Objektart: Medien, Module und Programme, Lizenzartikel, Seiten.
*
* @return array{medien: int, zusammenstellungen: int, lizenzartikel: int, seiten: int}
*/
public function assign(ContentElement $element, array $pillarIds): void
public function usage(Pillar $pillar): array
{
$element->pillars()->sync($this->ids($pillarIds));
return [
'medien' => $pillar->elements()->count(),
'zusammenstellungen' => $pillar->compositions()->count(),
'lizenzartikel' => $pillar->licenseArticles()->count(),
'seiten' => $pillar->pages()->count(),
];
}
/**
* @param array{medien: int, zusammenstellungen: int, lizenzartikel: int, seiten: int} $usage
*/
public function usageText(array $usage): string
{
$parts = [];
foreach (['medien' => ['Medium', 'Medien'], 'zusammenstellungen' => ['Modul oder Programm', 'Module und Programme'], 'lizenzartikel' => ['Lizenzartikel', 'Lizenzartikel'], 'seiten' => ['Seite', 'Seiten']] as $key => [$one, $many]) {
if ($usage[$key] > 0) {
$parts[] = $usage[$key].' '.($usage[$key] === 1 ? $one : $many);
}
}
return $parts === [] ? 'nirgends zugeordnet' : implode(', ', $parts);
}
/**
* Ordnet einem Medium, Modul, Programm, Lizenzartikel oder einer Seite Säulen zu. Alle Objektarten verwenden
* dieselbe zentrale Säule und dieselbe Speicherregel; die Zuordnung ersetzt die bisherige vollständig.
*
* @param list<int|string> $pillarIds
*/
public function assign(ContentElement|Composition|LicenseArticle|Page $subject, array $pillarIds): void
{
$subject->pillars()->sync($this->ids($pillarIds));
}
/**
@@ -60,7 +96,7 @@ public function assign(ContentElement $element, array $pillarIds): void
*/
public function assignPages(Page $page, array $pillarIds): void
{
$page->pillars()->sync($this->ids($pillarIds));
$this->assign($page, $pillarIds);
}
/**
@@ -22,6 +22,7 @@
use App\Domain\Cms\Catalog\PublicCatalogReader;
use App\Domain\Cms\Widgets\RenderContext;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\AssignsPillars;
use App\Filament\Support\EditorialCatalog;
use App\Filament\Support\ManagesEditorialSurface;
use App\Filament\Support\MediumForm;
@@ -43,6 +44,7 @@
abstract class EditComposition extends EditRecord
{
use AssignsPillars;
use ManagesEditorialSurface;
use WithFileUploads;
@@ -398,11 +400,15 @@ public function redaktionTexteHinweis(): string
*/
public function einordnungGruppen(): array
{
return array_map(fn (array $group): array => [
$groups = array_map(fn (array $group): array => [
'legend' => $group['label'],
'model' => 'dimensionIds',
'values' => $group['values'],
], $this->dimensionGroups());
$pillars = $this->pillarGroup();
return $pillars === null ? $groups : [$pillars, ...$groups];
}
/**
@@ -466,7 +472,7 @@ public function einordnungUnsaved(): bool
sort($stored);
sort($current);
return $stored !== $current;
return $stored !== $current || $this->pillarsUnsaved($record);
}
public function openText(): void
@@ -1654,6 +1660,7 @@ protected function fillRedaktion(): void
->pluck('editorial_dimension_value_id')
->map(fn (mixed $id): string => (string) (int) $id)
->all();
$this->loadPillarIds($composition);
}
/**
@@ -1913,6 +1920,7 @@ protected function persistRedaktion(): bool
'description' => $this->description,
], $this->actor());
$this->syncDimensions($record, array_map(intval(...), $this->dimensionIds));
$this->persistPillarIds($record);
$record->refresh();
$this->getRecord()->setRawAttributes($record->getAttributes());
@@ -3,6 +3,7 @@
namespace App\Filament\Resources\ContentElements\Pages;
use App\Domain\Catalog\EditorialVocabulary;
use App\Domain\Catalog\PillarFilterCompat;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\Bestand;
use App\Filament\Support\MediaLibrary;
@@ -170,6 +171,11 @@ public function resetFilters(): void
*/
public function bestand(): array
{
// Alte Adressen mit einem Säulenwert der Einordnung gelten für die zentrale Säule.
if (ctype_digit($this->einordnung) && $this->saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $this->einordnung))) {
[$this->saeule, $this->einordnung] = [(string) $pillar, ''];
}
$optionen = fn (array $liste, string $wert, string $label): array => collect($liste)
->mapWithKeys(fn (array $eintrag): array => [(string) $eintrag[$wert] => $eintrag[$label]])
->all();
@@ -16,6 +16,7 @@
use App\Domain\Catalog\LicenseArticle;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
use App\Filament\Support\AssignsPillars;
use App\Filament\Support\CatalogOptions;
use App\Filament\Support\EditorialCatalog;
use App\Filament\Support\ManagesEditorialSurface;
@@ -30,6 +31,7 @@
class ViewLicenseArticle extends ViewRecord
{
use AssignsPillars;
use ManagesEditorialSurface;
use ReportsDomainRules;
@@ -115,6 +117,7 @@ protected function saveRedaktionTexte(): bool
], auth()->user());
app(IdentityDimension::class)->replaceOffered($article, array_map(intval(...), $this->dimensionIds));
$this->persistPillarIds($article);
$article->refresh();
$this->fillLicenseEditorial();
@@ -159,7 +162,7 @@ public function einordnungUnsaved(): bool
sort($stored);
sort($current);
return $stored !== $current;
return $stored !== $current || $this->pillarsUnsaved($article);
}
/**
@@ -270,11 +273,15 @@ public function einordnungArt(): array
*/
public function einordnungGruppen(): array
{
return array_map(fn (array $group): array => [
$groups = array_map(fn (array $group): array => [
'legend' => $group['label'],
'model' => 'dimensionIds',
'values' => $group['values'],
], $this->licenseDimensionGroups());
$pillars = $this->pillarGroup();
return $pillars === null ? $groups : [$pillars, ...$groups];
}
private function sourceTitle(Model $source): string
@@ -312,6 +319,7 @@ private function fillLicenseEditorial(): void
->where('origin', 'direkt')
->pluck('editorial_dimension_value_id')
->all();
$this->loadPillarIds($article);
}
protected function getHeaderActions(): array
@@ -22,7 +22,7 @@ class ListPillars extends ListRecords
public function getSubheading(): string|Htmlable|null
{
return 'Die fachlichen Säulen des Materials. Eine veröffentlichte Säule ist ein Themenbereich der Website. Ein Medium und eine Seite können mehreren Säulen zugeordnet sein.';
return 'Die fachlichen Säulen des Materials. Eine veröffentlichte Säule ist ein Themenbereich der Website. Medien, Module, Programme, Lizenzartikel und Seiten können mehreren Säulen zugeordnet sein. Hier ist die einzige Pflegestelle der Säulen.';
}
protected function getHeaderActions(): array
@@ -50,11 +50,28 @@ protected function getHeaderActions(): array
];
}
/**
* Zuordnungen aller Objektarten; ohne Zuordnung wie bisher „0 Medien“.
*/
private function usageLabel(PillarService $service, Pillar $pillar): string
{
$usage = [
'medien' => (int) $pillar->elements_count,
'zusammenstellungen' => (int) $pillar->compositions_count,
'lizenzartikel' => (int) $pillar->license_articles_count,
'seiten' => (int) $pillar->pages_count,
];
return array_sum($usage) === 0 ? '0 Medien' : $service->usageText($usage);
}
protected function catalogRows(): array
{
$rows = [];
foreach (Pillar::query()->withCount('elements')->orderBy('sort_order')->orderBy('name')->get() as $pillar) {
$service = app(PillarService::class);
foreach (Pillar::query()->withCount(['elements', 'compositions', 'licenseArticles', 'pages'])->orderBy('sort_order')->orderBy('name')->get() as $pillar) {
$public = $pillar->published_at !== null;
$url = PillarResource::getUrl('edit', ['record' => $pillar]);
$rows[] = [
@@ -66,7 +83,7 @@ protected function catalogRows(): array
'url' => $url,
'chips' => [
$public ? ['label' => 'Auf der Website veröffentlicht', 'ton' => 'gut'] : ['label' => 'Intern', 'ton' => 'leise'],
['label' => $pillar->elements_count === 1 ? '1 Medium' : $pillar->elements_count.' Medien', 'ton' => 'neutral'],
['label' => $this->usageLabel($service, $pillar), 'ton' => 'neutral'],
],
'zustand' => [$public ? 'oeffentlich' : 'intern'],
'aktionen' => [['label' => 'Bearbeiten', 'href' => $url, 'icon' => 'stift']],
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Filament\Support;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PillarService;
/**
* Fachliche Säulen im Redaktionsmanager von Modul, Programm und Lizenzartikel (wie bei Medien): Die Auswahl kommt aus
* der zentralen Säulenverwaltung, die Zuordnung ersetzt die bisherige vollständig und bleibt beim Speichern anderer
* Angaben erhalten, weil der gespeicherte Stand geladen und mitgeschrieben wird.
*
* Eine Zuordnung veröffentlicht nichts: Ob eine Säule eine Themenseite hat, entscheidet allein die Säulenverwaltung.
*/
trait AssignsPillars
{
/** @var list<int|string> */
public array $pillarIds = [];
/**
* @return array{legend: string, model: string, values: list<array{id: int, label: string}>}|null
*/
public function pillarGroup(): ?array
{
$values = Pillar::query()->orderBy('sort_order')->orderBy('name')->get(['id', 'name'])
->map(fn (Pillar $pillar): array => ['id' => (int) $pillar->id, 'label' => (string) $pillar->name])
->all();
return $values === [] ? null : ['legend' => 'Fachliche Säulen', 'model' => 'pillarIds', 'values' => $values];
}
protected function loadPillarIds(Composition|LicenseArticle $subject): void
{
$this->pillarIds = $subject->pillars()->pluck('pillars.id')->map(fn (mixed $id): string => (string) (int) $id)->all();
}
protected function persistPillarIds(Composition|LicenseArticle $subject): void
{
app(PillarService::class)->assign($subject, array_map(intval(...), $this->pillarIds));
}
protected function pillarsUnsaved(Composition|LicenseArticle $subject): bool
{
$stored = $subject->pillars()->pluck('pillars.id')->map(fn (mixed $id): int => (int) $id)->all();
$current = array_map(intval(...), $this->pillarIds);
sort($stored);
sort($current);
return $stored !== $current;
}
}
+18
View File
@@ -5,6 +5,7 @@
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\EditorialVocabulary;
use App\Domain\Catalog\Pillar;
use App\Domain\Cms\Catalog\PublicMaterialReader;
use App\Domain\Cms\Widgets\Support\WebsiteImage;
use App\Http\Controllers\ContentPreviewController;
@@ -27,6 +28,9 @@ trait ChoosesMedia
public string $pickerDimension = '';
/** Filter „Fachliche Säule“ (Kennung der Säule aus der zentralen Säulenverwaltung). */
public string $pickerSaeule = '';
/** Filter „Fachliche Materialart“ (Kennung), gleiche Regel wie Medieneditor und Medienfilter. */
public string $pickerMaterialart = '';
@@ -108,6 +112,8 @@ public function pickerResult(): array
$this->pickerKind,
$this->pickerDimension,
$this->pickerExceptId(),
false,
ctype_digit($this->pickerSaeule) ? (int) $this->pickerSaeule : 0,
));
}
@@ -204,6 +210,7 @@ protected function resetPicker(string $purpose): void
$this->pickerOpen = true;
$this->pickerQuery = '';
$this->pickerDimension = '';
$this->pickerSaeule = '';
$this->pickerMaterialart = '';
$this->pickerInspected = '';
$this->pickerSelected = '';
@@ -239,6 +246,17 @@ private function filterByMaterialart(array $result): array
return $result;
}
/**
* Säulen für den Picker-Filter, in der Reihenfolge der Säulenverwaltung.
*
* @return array<string, string>
*/
public function pickerSaeulen(): array
{
return Pillar::query()->orderBy('sort_order')->orderBy('name')->pluck('name', 'id')
->mapWithKeys(fn (string $name, int|string $id): array => [(string) $id => $name])->all();
}
/**
* Einordnungsfilter des Pickers: dieselbe Filterregel wie Medien- und Kompositionslisten (verwendete inaktive Werte
* bleiben auffindbar, ein gewählter Filter bleibt sichtbar).
+33 -5
View File
@@ -272,7 +272,7 @@ public function search(string $query, string $scope, int $exceptCompositionId):
/**
* @return array{items: list<array<string, string|null>>, more: bool}
*/
public function browse(string $query, string $kind, string $dimension, int $exceptCompositionId, bool $elementsOnly = false): array
public function browse(string $query, string $kind, string $dimension, int $exceptCompositionId, bool $elementsOnly = false, int $pillarId = 0): array
{
$query = trim($query);
$like = '%'.str_replace(['%', '_'], ['', ''], $query).'%';
@@ -284,8 +284,8 @@ public function browse(string $query, string $kind, string $dimension, int $exce
$latestElements = ContentElementVersion::query()
->selectRaw('MAX(id)')
->whereIn('status', [ContentVersionStatus::Bereit, ContentVersionStatus::Entwurf])
->whereHas('element', function ($builder) use ($query, $like, $kind, $dimensionId): void {
$this->constrainElement($builder, $query, $like, $kind, $dimensionId);
->whereHas('element', function ($builder) use ($query, $like, $kind, $dimensionId, $pillarId): void {
$this->constrainElement($builder, $query, $like, $kind, $dimensionId, $pillarId);
})
->groupBy('content_element_id');
$elements = ContentElementVersion::query()
@@ -309,7 +309,7 @@ public function browse(string $query, string $kind, string $dimension, int $exce
->selectRaw('MAX(id)')
->where('status', ContentVersionStatus::Bereit)
->where('composition_id', '!=', $exceptCompositionId)
->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId): void {
->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId, $pillarId): void {
if ($kind === 'modul') {
$builder->where('kind', CompositionKind::Uebung);
}
@@ -318,6 +318,10 @@ public function browse(string $query, string $kind, string $dimension, int $exce
$builder->whereIn('id', $this->dimensionSubjectIds(Composition::class, $dimensionId));
}
if ($pillarId > 0) {
$builder->whereIn('id', $this->pillarSubjectIds(Composition::class, $pillarId));
}
if ($query === '') {
return;
}
@@ -370,6 +374,10 @@ public function browse(string $query, string $kind, string $dimension, int $exce
continue;
}
if ($pillarId > 0 && ! in_array($composition->id, $this->pillarSubjectIds(Composition::class, $pillarId), true)) {
continue;
}
$title = $this->compositionTitle($composition);
if ($query !== '' && ! str_contains(mb_strtolower($title.' '.(string) ($composition->summary ?? '')), mb_strtolower($query))) {
@@ -564,7 +572,7 @@ private function withVisibility(array $rows): array
/**
* @param Builder<ContentElement> $builder
*/
private function constrainElement($builder, string $query, string $like, string $kind, int $dimensionId): void
private function constrainElement($builder, string $query, string $like, string $kind, int $dimensionId, int $pillarId = 0): void
{
$outputs = match ($kind) {
'film' => ['film'],
@@ -583,6 +591,10 @@ private function constrainElement($builder, string $query, string $like, string
$builder->whereIn('id', $this->dimensionSubjectIds(ContentElement::class, $dimensionId));
}
if ($pillarId > 0) {
$builder->whereIn('id', $this->pillarSubjectIds(ContentElement::class, $pillarId));
}
if ($query === '') {
return;
}
@@ -597,6 +609,22 @@ private function constrainElement($builder, string $query, string $like, string
});
}
/**
* Direkt einer Säule zugeordnete Medien oder Module und Programme (zentrale Säulenverwaltung).
*
* @param class-string<Model> $class
* @return list<int>
*/
private function pillarSubjectIds(string $class, int $pillarId): array
{
[$table, $column] = $class === Composition::class
? ['composition_pillar', 'composition_id']
: ['content_element_pillar', 'content_element_id'];
return DB::table($table)->where('pillar_id', $pillarId)->pluck($column)
->map(fn (mixed $id): int => (int) $id)->all();
}
/**
* @param class-string<Model> $class
* @return list<int>
+55 -5
View File
@@ -7,9 +7,12 @@
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\EditorialVocabulary;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PillarFilterCompat;
use App\Filament\Resources\ContentElements\ContentElementResource;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Illuminate\Support\Facades\DB;
use Livewire\Attributes\Url;
/**
@@ -29,6 +32,10 @@ trait ListsCompositions
#[Url]
public string $pillar = '';
/** Fachliche Säule (zentrale Säulenverwaltung), direkt zugeordnet. */
#[Url(as: 'saeule', except: '')]
public string $saeule = '';
#[Url]
public string $visibility = 'alle';
@@ -39,7 +46,7 @@ protected function fixedKind(): ?CompositionKind
protected function bestandFilterEigenschaften(): array
{
return ['query', 'kindFilter', 'pillar', 'visibility'];
return ['query', 'kindFilter', 'pillar', 'saeule', 'visibility'];
}
public function resetFilters(): void
@@ -47,13 +54,14 @@ public function resetFilters(): void
$this->query = '';
$this->kindFilter = 'alle';
$this->pillar = '';
$this->saeule = '';
$this->visibility = 'alle';
$this->bestandGrenze = Bestand::SCHRITT;
}
public function hasActiveFilters(): bool
{
return trim($this->query) !== '' || $this->kindFilter !== 'alle' || $this->pillar !== '' || $this->visibility !== 'alle';
return trim($this->query) !== '' || $this->kindFilter !== 'alle' || $this->pillar !== '' || $this->saeule !== '' || $this->visibility !== 'alle';
}
/**
@@ -61,6 +69,7 @@ public function hasActiveFilters(): bool
*/
public function bestand(): array
{
$this->normalizeLegacyPillarFilter();
$fixed = $this->fixedKind();
$einheit = match ($fixed) {
CompositionKind::Kurs => ['Programm', 'Programme'],
@@ -90,9 +99,14 @@ public function bestand(): array
'eigenschaft' => 'visibility', 'label' => 'Stand', 'vorgabe' => 'alle',
'optionen' => ['alle' => 'Jeder Stand', 'bibliothek' => 'In der Mitgliederbibliothek', 'verborgen' => 'Nicht in der Mitgliederbibliothek', 'entwurf' => 'Noch ohne Fassung'],
]],
'weitere' => $gruppen === [] ? [] : [[
'eigenschaft' => 'pillar', 'label' => 'Fachliche Einordnung', 'vorgabe' => '', 'alle' => 'Alle Einordnungen', 'gruppen' => $gruppen,
]],
'weitere' => [
...($this->pillarOptions() === [] ? [] : [[
'eigenschaft' => 'saeule', 'label' => 'Fachliche Säule', 'vorgabe' => '', 'alle' => 'Alle Säulen', 'optionen' => $this->pillarOptions(),
]]),
...($gruppen === [] ? [] : [[
'eigenschaft' => 'pillar', 'label' => 'Fachliche Einordnung', 'vorgabe' => '', 'alle' => 'Alle Einordnungen', 'gruppen' => $gruppen,
]]),
],
'zeilen' => $this->entries(),
'einheit' => $einheit,
'leer' => [
@@ -124,7 +138,9 @@ public function entries(): array
$needle = mb_strtolower(trim($this->query));
$catalog = app(EditorialCatalog::class);
$offered = $catalog->offeredCompositionIds();
$this->normalizeLegacyPillarFilter();
$pillarIds = $this->pillar === '' ? null : $this->pillarSubjects((int) $this->pillar);
$saeuleIds = ctype_digit($this->saeule) && $this->saeule !== '' ? $this->saeuleSubjects((int) $this->saeule) : null;
$fixed = $this->fixedKind();
$kinds = $fixed !== null ? [$fixed] : match ($this->kindFilter) {
'programm' => [CompositionKind::Kurs],
@@ -149,6 +165,10 @@ public function entries(): array
continue;
}
if ($saeuleIds !== null && ! in_array($composition->id, $saeuleIds, true)) {
continue;
}
$stand = $catalog->stand($composition);
if (! $this->matchesVisibility($stand)) {
@@ -249,6 +269,36 @@ private function coverMembers(Composition $composition): array
return $members;
}
/**
* Alte Adressen mit einem Säulenwert der Einordnung (`?pillar=…`) gelten für die zentrale Säule.
*/
private function normalizeLegacyPillarFilter(): void
{
if (ctype_digit($this->pillar) && $this->pillar !== '' && $this->saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $this->pillar))) {
[$this->saeule, $this->pillar] = [(string) $pillar, ''];
}
}
/**
* @return array<string, string>
*/
private function pillarOptions(): array
{
return Pillar::query()->orderBy('sort_order')->orderBy('name')->pluck('name', 'id')
->mapWithKeys(fn (string $name, int|string $id): array => [(string) $id => $name])->all();
}
/**
* Direkt zugeordnete Module und Programme einer Säule. Die Säulen der enthaltenen Medien zählen hier nicht.
*
* @return list<int>
*/
private function saeuleSubjects(int $pillarId): array
{
return DB::table('composition_pillar')->where('pillar_id', $pillarId)->pluck('composition_id')
->map(fn (mixed $id): int => (int) $id)->all();
}
/**
* @return list<int>
*/
+10 -2
View File
@@ -11,6 +11,7 @@
use App\Domain\Catalog\EditorialVocabulary;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PillarFilterCompat;
use App\Domain\Catalog\ReleaseContent;
use App\Domain\Media\ThumbnailRef;
use App\Filament\Resources\ContentElements\ContentElementResource;
@@ -132,6 +133,13 @@ public function cards(array $filters, bool $canEdit): array
*/
private function normalize(array $filters): array
{
$saeule = ctype_digit($filters['saeule'] ?? '') ? $filters['saeule'] : '';
$einordnung = ctype_digit($filters['einordnung'] ?? '') ? $filters['einordnung'] : '';
if ($einordnung !== '' && $saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $einordnung))) {
[$saeule, $einordnung] = [(string) $pillar, ''];
}
return [
'suche' => trim($filters['suche'] ?? ''),
'art' => $this->choice($filters['art'] ?? '', ['film', 'text', 'document', 'bild', 'audio']),
@@ -139,8 +147,8 @@ private function normalize(array $filters): array
'entwurf' => $this->choice($filters['entwurf'] ?? '', ['offen', 'keiner']),
'fassung' => $this->choice($filters['fassung'] ?? '', ['mit', 'nur']),
'nutzung' => $this->choice($filters['nutzung'] ?? '', ['verwendet', 'unbenutzt']),
'saeule' => ctype_digit($filters['saeule'] ?? '') ? $filters['saeule'] : '',
'einordnung' => ctype_digit($filters['einordnung'] ?? '') ? $filters['einordnung'] : '',
'saeule' => $saeule,
'einordnung' => $einordnung,
'inhaltsart' => ctype_digit($filters['inhaltsart'] ?? '') ? $filters['inhaltsart'] : '',
'verarbeitung' => $this->choice($filters['verarbeitung'] ?? '', ['fehler', 'uebernahme']),
'archiv' => $this->choice($filters['archiv'] ?? '', ['aktiv', 'archiviert', 'alle'], 'aktiv'),
@@ -9,6 +9,8 @@
use App\Domain\Catalog\EditorialVocabulary;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PillarFilterCompat;
use App\Domain\Entitlement\DecideAccess;
use App\Domain\Entitlement\Grant;
use App\Domain\Entitlement\GrantStatus;
@@ -20,8 +22,10 @@
use App\Http\CourseOutline;
use App\Http\LibraryCatalog;
use App\Http\SignedLink;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -35,8 +39,21 @@ public function index(Request $request, ?string $sicht = null): View
$query = trim((string) $request->query('q', ''));
$nutzung = (string) $request->query('nutzung', '');
$dimensionIds = array_values(array_filter(array_map(intval(...), (array) $request->query('dimension', []))));
$saeuleIds = array_values(array_filter(array_map(intval(...), (array) $request->query('saeule', []))));
$dimensions = app(IdentityDimension::class);
// Alte Adressen: Säulen waren ein Wert der Einordnung. Mit belastbarer Verknüpfung gilt der Filter der Säule.
foreach ($dimensionIds as $index => $valueId) {
if (is_int($pillarId = PillarFilterCompat::pillarOfLegacyValue($valueId))) {
$saeuleIds[] = $pillarId;
unset($dimensionIds[$index]);
}
}
$dimensionIds = array_values($dimensionIds);
$saeuleIds = array_values(array_unique($saeuleIds));
$pillarOptions = $this->visiblePillars($catalog, $saeuleIds);
foreach (['programs', 'modules'] as $shelf) {
if ($query !== '') {
$catalog[$shelf] = array_values(array_filter(
@@ -50,6 +67,12 @@ public function index(Request $request, ?string $sicht = null): View
fn (array $card): bool => $dimensions->matches($card['composition'], $dimensionIds),
));
}
if ($saeuleIds !== []) {
$catalog[$shelf] = array_values(array_filter(
$catalog[$shelf],
fn (array $card): bool => $this->hasPillar($card['composition'], $saeuleIds),
));
}
if (in_array($nutzung, ['nutzbar', 'teilweise', 'nicht enthalten'], true)) {
$catalog[$shelf] = array_values(array_filter(
$catalog[$shelf],
@@ -79,6 +102,13 @@ function (array $card) use ($dimensions, $dimensionIds): bool {
));
}
if ($saeuleIds !== []) {
$catalog['materials'] = array_values(array_filter(
$catalog['materials'],
fn (array $card): bool => $this->hasPillar($this->materialSubject($card), $saeuleIds),
));
}
if ($nutzung === 'teilweise' || $nutzung === 'nicht enthalten') {
$catalog['materials'] = [];
}
@@ -89,11 +119,65 @@ function (array $card) use ($dimensions, $dimensionIds): bool {
'sicht' => $sicht,
'nutzung' => $nutzung,
'dimensionIds' => $dimensionIds,
'saeuleIds' => $saeuleIds,
'filterPillars' => $pillarOptions,
'filterDimensions' => app(EditorialVocabulary::class)->memberFilterDimensions(array_map(intval(...), $dimensionIds)),
'libraryEmpty' => $untouched,
]);
}
/**
* Subjekt eines Materialkarte: Programm oder Modul, Medium oder der Artikel selbst.
*
* @param array<string, mixed> $card
*/
private function materialSubject(array $card): Model
{
$release = $card['article']->currentRelease;
return $release?->rootCompositionVersion?->composition
?? $release?->rootElementVersion?->element
?? $card['article'];
}
/**
* Direkte Säulenzuordnung des Objekts selbst; die Säulen enthaltener Medien zählen hier nicht.
*
* @param list<int> $pillarIds
*/
private function hasPillar(Model $subject, array $pillarIds): bool
{
return $subject->pillars()->whereIn('pillars.id', $pillarIds)->exists();
}
/**
* Säulen für den Filter: nur solche, die ein sichtbares Objekt der Bibliothek tatsächlich trägt, und eine bereits
* gewählte. So erscheinen neue oder interne Säulen ohne Zuordnung nicht in der Bibliothek.
*
* @param array<string, mixed> $catalog
* @param list<int> $selected
* @return Collection<int, Pillar>
*/
private function visiblePillars(array $catalog, array $selected)
{
$used = [];
foreach (array_merge($catalog['programs'], $catalog['modules']) as $card) {
foreach ($card['composition']->pillars()->pluck('pillars.id') as $id) {
$used[(int) $id] = true;
}
}
foreach ($catalog['materials'] as $card) {
foreach ($this->materialSubject($card)->pillars()->pluck('pillars.id') as $id) {
$used[(int) $id] = true;
}
}
return Pillar::query()->whereIn('id', array_values(array_unique([...array_keys($used), ...$selected])))
->orderBy('sort_order')->orderBy('name')->get();
}
public function programs(Request $request): View
{
return $this->index($request, 'programme');
@@ -0,0 +1,59 @@
<?php
use App\Domain\Catalog\LegacyPillarAdoption;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
/**
* Fachliche Säulen vereinheitlichen: Module, Programme und Lizenzartikel verwenden wie Medien und Seiten die zentrale
* Säulenverwaltung (`pillars`) statt der Kopie „Fachliche Säule“ in den redaktionellen Dimensionen.
*
* Nur Ergänzungen: zwei Zuordnungstabellen (die Säule wird beim Löschen nie still entfernt, wie bei Medien und Seiten),
* die Verknüpfung `pillar_id` an den alten Dimensionswerten und die einmalige, wiederholbare Übernahme durch
* LegacyPillarAdoption. Alte Tabellen und Zeilen bleiben unverändert erhalten.
*/
return new class extends Migration
{
public function up(): void
{
Schema::create('composition_pillar', function (Blueprint $table) {
$table->foreignId('composition_id')->constrained()->cascadeOnDelete();
$table->foreignId('pillar_id')->constrained()->restrictOnDelete();
$table->primary(['composition_id', 'pillar_id']);
});
Schema::create('license_article_pillar', function (Blueprint $table) {
$table->foreignId('license_article_id')->constrained()->cascadeOnDelete();
$table->foreignId('pillar_id')->constrained()->restrictOnDelete();
$table->primary(['license_article_id', 'pillar_id']);
});
Schema::table('editorial_dimension_values', function (Blueprint $table) {
$table->foreignId('pillar_id')->nullable()->after('editorial_dimension_id')->constrained('pillars')->nullOnDelete();
});
$report = (new LegacyPillarAdoption)->run();
foreach (LegacyPillarAdoption::lines($report) as $line) {
if ($line !== '') {
Log::info('Säulenübernahme: '.$line);
}
}
if ($report['unresolved'] !== []) {
Log::warning('Säulenübernahme: '.count($report['unresolved']).' Fälle ungeklärt; „php artisan luf:saeulen-uebernehmen --dry-run“ listet sie.');
}
}
public function down(): void
{
Schema::table('editorial_dimension_values', function (Blueprint $table) {
$table->dropConstrainedForeignId('pillar_id');
});
Schema::dropIfExists('license_article_pillar');
Schema::dropIfExists('composition_pillar');
}
};
@@ -69,6 +69,15 @@
@endforeach
</select>
@endif
@if ($zweck === 'aufbau' && ($saeulen = $this->pickerSaeulen()) !== [])
<label class="vw-sr" for="picker-saeule">Fachliche Säule</label>
<select id="picker-saeule" class="vw-auswahlfeld" wire:model.live="pickerSaeule">
<option value="">Fachliche Säule: alle</option>
@foreach ($saeulen as $wert => $label)
<option value="{{ $wert }}">Fachliche Säule: {{ $label }}</option>
@endforeach
</select>
@endif
@if ($zweck === 'aufbau' && ($dimensionen = $this->pickerDimensionGroups()) !== [])
<label class="vw-sr" for="picker-einordnung">Fachliche Einordnung</label>
<select id="picker-einordnung" class="vw-auswahlfeld" wire:model.live="pickerDimension">
@@ -87,7 +96,7 @@
<div class="vw-dialog-inhalt is-picker" style="padding: 0;">
<div class="vw-picker" style="height: 100%;">
<div class="vw-picker-liste" wire:loading.class="opacity-60" wire:target="pickerQuery,pickerKind,pickerDimension,pickerMaterialart">
<div class="vw-picker-liste" wire:loading.class="opacity-60" wire:target="pickerQuery,pickerKind,pickerDimension,pickerSaeule,pickerMaterialart">
@if ($ergebnis['items'] === [])
<div class="vw-leer"><strong>Nichts gefunden.</strong><p>Ändere die Suche oder den Inhaltstyp.</p></div>
@else
+12 -1
View File
@@ -20,6 +20,17 @@
<form class="finder" method="get" action="{{ $sicht === 'programme' ? route('member.programs') : ($sicht === 'module' ? route('member.modules') : route('member.library')) }}">
<label class="finder-query" for="q">Suche</label>
<input id="q" name="q" type="search" value="{{ $query ?? '' }}" placeholder="Titel oder Kurzbeschreibung">
@if ($filterPillars->isNotEmpty())
<fieldset>
<legend>Fachliche Säulen</legend>
@foreach ($filterPillars as $pillar)
<label class="check">
<input type="checkbox" name="saeule[]" value="{{ $pillar->id }}" @checked(in_array($pillar->id, $saeuleIds, true))>
<span>{{ $pillar->name }}</span>
</label>
@endforeach
</fieldset>
@endif
@if ($filterDimensions->isNotEmpty())
@foreach ($filterDimensions as $dimension)
<fieldset>
@@ -54,7 +65,7 @@
@if ($visible === 0)
<div class="empty">
@if ($libraryEmpty && ($query ?? '') === '' && ($nutzung ?? '') === '' && $dimensionIds === [])
@if ($libraryEmpty && ($query ?? '') === '' && ($nutzung ?? '') === '' && $dimensionIds === [] && $saeuleIds === [])
<h2>Noch nichts in der Bibliothek</h2>
<p>Unter Angebote können Sie ein kostenloses Material abrufen oder ein Angebot im Testmodus kaufen.</p>
<p><a class="button" href="{{ route('member.offers') }}">Zu den Angeboten</a></p>
+5 -4
View File
@@ -334,7 +334,7 @@ public function test_a_license_article_overrides_only_its_own_presentation(): vo
$this->assertSame('leer', app(EditorialProfileReader::class)->read($ambiguous->fresh())->origin('summary'));
}
public function test_content_elements_do_not_offer_the_pillar_dimension_a_second_time(): void
public function test_no_object_offers_the_legacy_pillar_dimension_any_more(): void
{
$pillar = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe', 'sort_order' => 1]);
$dimension = EditorialDimension::query()->where('slug', 'saeule')->firstOrFail();
@@ -363,7 +363,7 @@ public function test_content_elements_do_not_offer_the_pillar_dimension_a_second
->where('subject_id', $film->id)
->pluck('editorial_dimension_value_id')
->all();
$this->assertContains($value->id, $assigned);
$this->assertContains($value->id, $assigned, 'Die alte Zeile bleibt als Verlauf erhalten.');
$this->assertContains($kinder->id, $assigned);
$module = $content->createComposition('Modul mit Säule');
@@ -373,8 +373,9 @@ public function test_content_elements_do_not_offer_the_pillar_dimension_a_second
]]);
Livewire::test(EditExercise::class, ['record' => $module->getKey()])
->call('openRedaktion', 'einordnung')
->assertSee('Nähe als Dimension')
->assertDontSee('Fachliche Säulen');
->assertDontSee('Nähe als Dimension')
->assertSee('Fachliche Säulen')
->assertSee('Nähe');
}
public function test_classification_is_filterable_and_does_not_change_use_or_release(): void
+462
View File
@@ -0,0 +1,462 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionDisplayRelease;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\EditorialVocabulary;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\LegacyPillarAdoption;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PillarService;
use App\Domain\Cms\Page;
use App\Domain\Entitlement\GrantIssuer;
use App\Filament\Pages\RedaktionelleStammdaten;
use App\Filament\Resources\ContentElements\Pages\ListContentElements;
use App\Filament\Resources\Courses\Pages\EditCourse;
use App\Filament\Resources\Exercises\Pages\EditExercise;
use App\Filament\Resources\Exercises\Pages\ListExercises;
use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle;
use App\Filament\Resources\Pillars\Pages\ListPillars;
use App\Filament\Support\CatalogReading;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Livewire\Livewire;
use Tests\TestCase;
/**
* Fachliche Säulen aus einer Quelle: Die zentrale Säulenverwaltung (`pillars`) gilt für Medien, Module, Programme,
* Lizenzartikel und Seiten. Die frühere Kopie als Dimension „Fachliche Säule“ bleibt nur als Verlauf erhalten und wird
* verlustfrei und wiederholbar übernommen.
*/
class PillarUnificationTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
}
protected function tearDown(): void
{
Carbon::setTestNow();
parent::tearDown();
}
public function test_a_central_pillar_is_chosen_for_modules_programs_and_license_articles_without_publishing_anything(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$program = $content->createComposition('Programm Schulweg', CompositionKind::Kurs);
$article = app(ArticleService::class)->create('artikel-abstand');
$pillar = app(PillarService::class)->create('Meine Grenzen');
$editor = $this->editor();
$keeper = $this->keeper();
Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])
->call('openRedaktion', 'einordnung')->assertSee('Fachliche Säulen')->assertSee('Meine Grenzen')
->set('pillarIds', [(string) $pillar->id])->call('saveDisplay')->assertSet('feedbackError', false);
Livewire::actingAs($editor, 'staff')->test(EditCourse::class, ['record' => $program->getKey()])
->call('openRedaktion', 'einordnung')->assertSee('Meine Grenzen')
->set('pillarIds', [(string) $pillar->id])->call('saveDisplay');
Livewire::actingAs($keeper, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->call('openRedaktion', 'einordnung')->assertSee('Meine Grenzen')
->set('pillarIds', [(string) $pillar->id])->call('saveLicenseEditorial');
$this->assertSame([$pillar->id], $module->fresh()->pillars->pluck('id')->all());
$this->assertSame([$pillar->id], $program->fresh()->pillars->pluck('id')->all());
$this->assertSame([$pillar->id], $article->fresh()->pillars->pluck('id')->all());
$this->assertNull($pillar->fresh()->published_at, 'Anlegen und Zuordnen veröffentlicht keine Themenseite.');
}
public function test_renaming_a_pillar_shows_the_new_name_everywhere_and_keeps_every_assignment(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$article = app(ArticleService::class)->create('artikel-abstand');
$film = $content->createElement('film', 'film', 'Lara im Park');
$pillar = app(PillarService::class)->create('Nähe');
foreach ([$module, $article, $film] as $subject) {
app(PillarService::class)->assign($subject, [$pillar->id]);
}
$editor = $this->editor();
$keeper = $this->keeper();
app(PillarService::class)->present($pillar, 'Nähe und Distanz', $pillar->slug, null, false, 0);
Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])
->call('openRedaktion', 'einordnung')->assertSee('Nähe und Distanz')->assertSet('pillarIds', [(string) $pillar->id]);
Livewire::actingAs($keeper, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->call('openRedaktion', 'einordnung')->assertSee('Nähe und Distanz')->assertSet('pillarIds', [(string) $pillar->id]);
Livewire::actingAs($editor, 'staff')->test(ListExercises::class)->assertOk();
Livewire::withQueryParams(['saeule' => (string) $pillar->id])->actingAs($editor, 'staff')
->test(ListContentElements::class)->assertSee('Lara im Park');
Livewire::actingAs($editor, 'staff')->test(ListPillars::class)->assertSee('Nähe und Distanz')->assertSee('1 Medium, 1 Modul oder Programm, 1 Lizenzartikel');
$this->assertSame($pillar->id, $module->pillars()->value('pillars.id'));
$this->assertSame($pillar->id, $article->pillars()->value('pillars.id'));
$this->assertSame($pillar->id, $film->pillars()->value('pillars.id'));
}
public function test_saving_other_details_keeps_the_pillar_assignments(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$article = app(ArticleService::class)->create('artikel-abstand');
$first = app(PillarService::class)->create('Eins');
$second = app(PillarService::class)->create('Zwei');
app(PillarService::class)->assign($module, [$first->id, $second->id]);
app(PillarService::class)->assign($article, [$second->id]);
$editor = $this->editor();
$keeper = $this->keeper();
Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])
->set('teaser', 'Nur der Teaser ändert sich.')->call('saveDisplay');
Livewire::actingAs($keeper, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->call('openRedaktion')->set('summary', 'Nur die Beschreibung ändert sich.')->call('saveLicenseEditorial');
$this->assertEqualsCanonicalizing([$first->id, $second->id], $module->fresh()->pillars->pluck('id')->all());
$this->assertSame([$second->id], $article->fresh()->pillars->pluck('id')->all());
$this->assertSame('Nur der Teaser ändert sich.', $module->fresh()->teaser);
// Gezieltes Abwählen entfernt genau diese Säule.
Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])
->set('pillarIds', [(string) $second->id])->call('saveDisplay');
$this->assertSame([$second->id], $module->fresh()->pillars->pluck('id')->all());
}
public function test_the_adoption_carries_every_direct_assignment_over_and_is_repeatable(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$program = $content->createComposition('Programm Schulweg', CompositionKind::Kurs);
$article = app(ArticleService::class)->create('artikel-abstand');
$film = $content->createElement('film', 'film', 'Lara im Park');
$nahe = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']);
$mut = Pillar::query()->create(['name' => 'Mut', 'slug' => 'mut']);
$nahe->refresh();
$nearValue = $this->legacyValue($nahe, 'Nähe');
$courageValue = $this->legacyValue($mut, 'Mut (alter Name)');
$identity = app(IdentityDimension::class);
$identity->assign($module, $nearValue);
$identity->assign($module, $courageValue);
$identity->assign($program, $nearValue);
$identity->assign($article, $courageValue);
$identity->assign($film, $nearValue);
// Medien: maßgeblich ist die Medienzuordnung, die Spiegelzeile wird nicht zurückgemischt.
app(PillarService::class)->assign($film, [$mut->id]);
$legacyBefore = IdentityDimensionValue::query()->count();
$report = (new LegacyPillarAdoption)->run();
$this->assertEqualsCanonicalizing([$nahe->id, $mut->id], $module->pillars()->pluck('pillars.id')->all());
$this->assertSame([$nahe->id], $program->pillars()->pluck('pillars.id')->all());
$this->assertSame([$mut->id], $article->pillars()->pluck('pillars.id')->all());
$this->assertSame([$mut->id], $film->pillars()->pluck('pillars.id')->all(), 'Die Medienzuordnung bleibt maßgeblich.');
$this->assertSame(['composition' => 3, 'license_article' => 1], $report['copied']);
$this->assertSame([], $report['unresolved']);
$this->assertSame($nahe->id, $nearValue->fresh()->pillar_id);
$this->assertSame($mut->id, $courageValue->fresh()->pillar_id);
$this->assertSame($legacyBefore, IdentityDimensionValue::query()->count(), 'Alte Zeilen bleiben unverändert erhalten.');
$this->assertSame(1, $report['mirror']['element_rows'], 'Eine gespiegelte Medienzeile wird nur gezählt.');
$this->assertSame(1, $report['mirror']['missing_in_pivot']);
$this->assertTrue(collect($report['mapping'])->contains(fn (array $row): bool => $row['wert_id'] === $courageValue->id && str_contains((string) $row['hinweis'], 'Bezeichnung weicht ab')));
$again = (new LegacyPillarAdoption)->run();
$this->assertSame(['composition' => 0, 'license_article' => 0], $again['copied']);
$this->assertSame(['composition' => 3, 'license_article' => 1], $again['already']);
$this->assertSame(4, DB::table('composition_pillar')->count() + DB::table('license_article_pillar')->count());
$dry = (new LegacyPillarAdoption)->run(dryRun: true);
$this->assertSame(4, $dry['before']['composition'] + $dry['before']['license_article']);
}
public function test_ambiguous_old_values_are_reported_and_never_assigned_by_guessing(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$program = $content->createComposition('Programm Schulweg', CompositionKind::Kurs);
$article = app(ArticleService::class)->create('artikel-abstand');
$film = $content->createElement('film', 'film', 'Lara im Park');
$nahe = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']);
$good = $this->legacyValue($nahe, 'Nähe');
// Gleicher Name, aber ohne Kennung zur Säule: ähnlich klingend ist kein Nachweis.
$sameName = $this->legacyValue($nahe, 'Nähe', slug: 'naehe-kopie');
// Kennung verweist auf eine Säule, die es nicht mehr gibt.
$gone = $this->legacyValue($nahe, 'Verschwunden', slug: 'pfeiler-9999');
$identity = app(IdentityDimension::class);
$identity->assign($module, $good);
$identity->assign($module, $sameName);
$identity->assign($program, $gone);
$identity->assign($article, $good, 'abgeleitet');
$identity->assign($film, $sameName);
DB::table('identity_dimension_values')->insert([
'subject_type' => $module->getMorphClass(), 'subject_id' => 99999, 'editorial_dimension_value_id' => $good->id,
'origin' => 'direkt', 'created_at' => now(), 'updated_at' => now(),
]);
$report = (new LegacyPillarAdoption)->run();
$this->assertSame([$nahe->id], $module->pillars()->pluck('pillars.id')->all(), 'Nur der belastbare Wert wird übernommen.');
$this->assertSame([], $program->pillars()->pluck('pillars.id')->all());
$this->assertSame([], $article->pillars()->pluck('pillars.id')->all(), 'Eine abgeleitete Zuordnung wird nicht zur direkten.');
$this->assertNull($sameName->fresh()->pillar_id);
$this->assertNull($gone->fresh()->pillar_id);
$reasons = collect($report['unresolved'])->pluck('grund')->implode(' | ');
$this->assertStringContainsString('keine belastbare Verknüpfung', $reasons);
$this->assertStringContainsString('existiert nicht mehr', $reasons);
$this->assertStringContainsString('abgeleitete Zuordnung', $reasons);
$this->assertStringContainsString('Objekt nicht mehr vorhanden', $reasons);
$this->assertStringContainsString('Wert ohne belastbare Säule', $reasons);
$lines = implode("\n", LegacyPillarAdoption::lines($report));
$this->assertStringContainsString('Ungeklärt, bitte entscheiden', $lines);
$this->assertStringContainsString('naehe-kopie', $lines);
$this->assertSame(1, DB::table('identity_dimension_values')->where('origin', 'abgeleitet')->count(), 'Nichts wurde gelöscht.');
$this->artisan('luf:saeulen-uebernehmen', ['--dry-run' => true])->assertFailed();
}
public function test_a_pillar_younger_than_the_old_value_is_not_a_reliable_reference(): void
{
Carbon::setTestNow('2026-11-16 08:00:00');
$value = $this->legacyValue(Pillar::query()->create(['name' => 'Alt', 'slug' => 'alt']), 'Alt', slug: 'pfeiler-2');
Carbon::setTestNow('2026-11-20 08:00:00');
Pillar::query()->create(['id' => 2, 'name' => 'Später angelegt', 'slug' => 'spaeter']);
$report = (new LegacyPillarAdoption)->run();
$this->assertNull($value->fresh()->pillar_id);
$this->assertStringContainsString('jünger', (string) ($report['unresolved'][0]['grund'] ?? ''));
}
public function test_direct_and_derived_pillars_keep_their_own_meaning(): void
{
$content = app(ContentService::class);
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Hofszene'), null, ['file' => 'inhalte/hof.mp4']);
$module = $content->createComposition('Modul Hof', CompositionKind::Uebung);
$content->publishComposition($module, [['role' => 'Film', 'target' => $film]]);
$fromMedia = app(PillarService::class)->create('Aus dem Medium');
$direct = app(PillarService::class)->create('Direkt am Modul');
app(PillarService::class)->assign($film->element, [$fromMedia->id]);
app(PillarService::class)->assign($module, [$direct->id]);
$derived = app(CatalogReading::class)->memberPillars($module);
$this->assertSame(['Hofszene — Aus dem Medium'], array_map(fn (string $line): string => str_replace('Film: ', '', $line), $derived));
$this->assertSame([$direct->id], $module->pillars()->pluck('pillars.id')->all(), 'Die Säule des Mediums wird nicht zur direkten Zuordnung des Moduls.');
$editor = $this->editor();
Livewire::withQueryParams(['saeule' => (string) $fromMedia->id])->actingAs($editor, 'staff')
->test(ListExercises::class)->assertDontSee('Modul Hof');
Livewire::withQueryParams(['saeule' => (string) $direct->id])->actingAs($editor, 'staff')
->test(ListExercises::class)->assertSee('Modul Hof');
}
public function test_filters_find_exactly_the_assigned_objects_and_old_addresses_follow_the_pillar(): void
{
$content = app(ContentService::class);
$withPillar = $content->createComposition('Mit Säule', CompositionKind::Uebung);
$content->createComposition('Ohne Säule', CompositionKind::Uebung);
$pillar = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']);
$value = $this->legacyValue($pillar, 'Nähe');
app(PillarService::class)->assign($withPillar, [$pillar->id]);
(new LegacyPillarAdoption)->run();
$editor = $this->editor();
Livewire::withQueryParams(['saeule' => (string) $pillar->id])->actingAs($editor, 'staff')->test(ListExercises::class)
->assertSee('Mit Säule')->assertDontSee('Ohne Säule');
// Alte Adresse mit dem früheren Säulenwert der Einordnung.
Livewire::withQueryParams(['pillar' => (string) $value->id])->actingAs($editor, 'staff')->test(ListExercises::class)
->assertSet('saeule', (string) $pillar->id)->assertSet('pillar', '')->assertSee('Mit Säule')->assertDontSee('Ohne Säule');
Livewire::withQueryParams(['einordnung' => (string) $value->id])->actingAs($editor, 'staff')->test(ListContentElements::class)
->assertSet('saeule', (string) $pillar->id)->assertSet('einordnung', '');
// Der Picker im Aufbau filtert Medien und Module nach der Säule.
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Film mit Säule'), 'Film');
$content->publishElementVersion($content->createElement('film', 'film', 'Film ohne Säule'), 'Film');
app(PillarService::class)->assign($film->element, [$pillar->id]);
$picker = Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $withPillar->getKey()])
->call('openPicker');
$this->assertSame($pillar->name, $picker->instance()->pickerSaeulen()[(string) $pillar->id]);
$ids = fn (array $items): array => array_column($items, 'title');
$picker->set('pickerKind', 'film');
$this->assertContains('Film ohne Säule', $ids($picker->instance()->pickerResult()['items']), 'Ohne Filter erscheinen beide.');
$picker->set('pickerSaeule', (string) $pillar->id);
$this->assertSame(['Film mit Säule'], array_values(array_filter($ids($picker->instance()->pickerResult()['items']), fn ($t) => str_starts_with((string) $t, 'Film '))));
}
public function test_a_used_pillar_cannot_be_deleted_by_the_service_or_the_database(): void
{
$content = app(ContentService::class);
$service = app(PillarService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$article = app(ArticleService::class)->create('artikel-abstand');
$byModule = $service->create('Durch Modul');
$byArticle = $service->create('Durch Artikel');
$service->assign($module, [$byModule->id]);
$service->assign($article, [$byArticle->id]);
foreach ([$byModule, $byArticle] as $pillar) {
try {
$service->delete($pillar);
$this->fail('Eine verwendete Säule darf nicht gelöscht werden.');
} catch (DomainRuleException $exception) {
$this->assertStringContainsString('zugeordneten Objekten', $exception->getMessage());
}
}
$this->assertStringContainsString('1 Modul oder Programm', $service->usageText($service->usage($byModule)));
$this->assertStringContainsString('1 Lizenzartikel', $service->usageText($service->usage($byArticle)));
// Auch ein Zugriff an der Anwendung vorbei scheitert in der Datenbank.
$this->expectException(QueryException::class);
DB::table('pillars')->where('id', $byModule->id)->delete();
}
public function test_pillar_assignment_follows_the_editorial_permissions(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$article = app(ArticleService::class)->create('artikel-abstand');
$pillar = app(PillarService::class)->create('Nähe');
$moderator = User::factory()->systemverwalter()->create();
$moderator->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
Livewire::actingAs($moderator, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])->assertForbidden();
Livewire::actingAs($moderator, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()])->assertForbidden();
Livewire::actingAs($moderator, 'staff')->test(ListPillars::class)->assertForbidden();
$this->assertSame([], $module->pillars()->pluck('pillars.id')->all());
$this->assertNotNull($pillar->fresh());
}
public function test_the_stammdaten_workplace_points_to_the_pillar_management_and_offers_no_pillar_copy(): void
{
Livewire::actingAs($this->editor(), 'staff')->test(RedaktionelleStammdaten::class)
->assertSee('Fachliche Säulen')
->assertSee(route('filament.verwaltung.resources.saeulen.index', [], false), false);
$this->assertArrayNotHasKey(EditorialDimension::PILLAR_SLUG, (new RedaktionelleStammdaten)->gruppen());
foreach ([Composition::class, LicenseArticle::class] as $class) {
$this->assertNotContains(EditorialDimension::PILLAR_SLUG, EditorialDimension::forSubject(new $class)->pluck('slug')->all());
}
$vocabulary = app(EditorialVocabulary::class);
$this->legacyValue(Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']), 'Nähe');
$this->assertNotContains('Fachliche Säule', array_column($vocabulary->dimensionFilterGroups(), 'label'));
$this->assertNotContains('Fachliche Säule', $vocabulary->memberFilterDimensions()->pluck('label')->all());
}
public function test_the_member_library_filters_by_direct_pillars_and_lists_only_used_ones(): void
{
$content = app(ContentService::class);
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Hofszene'), null, ['file' => 'inhalte/hof.mp4']);
$withPillar = $content->publishComposition($content->createComposition('Schulweg mit Säule'), [['role' => 'Film', 'target' => $film]]);
$without = $content->publishComposition($content->createComposition('Schulweg ohne Säule'), [['role' => 'Film', 'target' => $film]]);
$pillar = app(PillarService::class)->create('Sicher unterwegs');
$unused = app(PillarService::class)->create('Noch ohne Zuordnung');
app(PillarService::class)->assign($withPillar->composition, [$pillar->id]);
$articles = app(ArticleService::class);
$offers = app(OfferService::class);
$rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']]);
$offer = $offers->create('Zugang');
$items = [];
foreach ([[$withPillar, 'mit'], [$without, 'ohne']] as [$version, $code]) {
$article = $articles->create($code);
$articles->publishRelease($article, $version, 'Text');
$items[] = ['target' => $article->fresh(), 'rights' => $rights];
}
$offers->activate($offer, $items, ['grant_kind' => 'auf_abruf']);
$member = User::factory()->create();
app(GrantIssuer::class)->claim($member, $offer);
foreach ([$withPillar, $without] as $version) {
app(CompositionDisplayRelease::class)->release($version, $member);
}
$this->actingAs($member)->get(route('member.library'))
->assertOk()->assertSee('Schulweg mit Säule')->assertSee('Schulweg ohne Säule')
->assertSee('Fachliche Säulen')->assertSee('Sicher unterwegs')->assertDontSee('Noch ohne Zuordnung');
$this->actingAs($member)->get(route('member.library', ['saeule' => [$pillar->id]]))
->assertOk()->assertSee('Schulweg mit Säule')->assertDontSee('Schulweg ohne Säule');
$this->assertNotNull($unused->fresh());
}
public function test_published_pages_and_saved_versions_stay_unchanged_by_the_adoption(): void
{
$content = app(ContentService::class);
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Hofszene'), null, ['file' => 'inhalte/hof.mp4']);
$module = $content->createComposition('Modul Hof', CompositionKind::Uebung);
$version = $content->publishComposition($module, [['role' => 'Film', 'target' => $film]]);
$pillar = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe', 'published_at' => null]);
$theme = Pillar::query()->create(['name' => 'Veröffentlicht', 'slug' => 'oeffentlich', 'published_at' => now()]);
$page = Page::query()->where('path', '/praevention')->firstOrFail();
app(PillarService::class)->assignPages($page, [$theme->id]);
app(IdentityDimension::class)->assign($module, $this->legacyValue($pillar, 'Nähe'));
$before = [
'seite' => $this->page('/praevention'),
'thema' => $this->page('/themen/oeffentlich'),
'fassungen' => DB::table('composition_versions')->orderBy('id')->get()->toJson(),
'revisionen' => DB::table('page_revisions')->orderBy('id')->get()->toJson(),
'themen' => DB::table('pillars')->orderBy('id')->get(['id', 'name', 'slug', 'published_at'])->toJson(),
'freigaben' => DB::table('article_releases')->count(),
];
(new LegacyPillarAdoption)->run();
$this->assertSame($before['seite'], $this->page('/praevention'));
$this->assertSame($before['thema'], $this->page('/themen/oeffentlich'));
$this->assertSame($before['fassungen'], DB::table('composition_versions')->orderBy('id')->get()->toJson());
$this->assertSame($before['revisionen'], DB::table('page_revisions')->orderBy('id')->get()->toJson());
$this->assertSame($before['themen'], DB::table('pillars')->orderBy('id')->get(['id', 'name', 'slug', 'published_at'])->toJson(), 'Die Übernahme veröffentlicht nichts.');
$this->assertSame($before['freigaben'], DB::table('article_releases')->count());
$this->assertSame([$pillar->id], $module->pillars()->pluck('pillars.id')->all());
$this->assertNotNull($version);
}
private function legacyValue(Pillar $pillar, string $label, ?string $slug = null): EditorialDimensionValue
{
$dimension = EditorialDimension::query()->where('slug', EditorialDimension::PILLAR_SLUG)->firstOrFail();
return EditorialDimensionValue::query()->create([
'editorial_dimension_id' => $dimension->id,
'slug' => $slug ?? 'pfeiler-'.$pillar->id,
'label' => $label,
]);
}
private function keeper(): User
{
$keeper = User::factory()->redakteur()->katalogverwalter()->create();
$keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $keeper;
}
/** Seiten ohne Vorladehinweise der Schriften, die ein zweiter Aufruf im selben Test weglässt. */
private function page(string $path): string
{
return preg_replace('/<link rel="preload"[^>]*>\s*/', '', (string) $this->get($path)->getContent());
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
}