Führe die zentrale Pflege redaktioneller Stammdaten ein
FACH-56 bis FACH-58: Arbeitsplatz „Redaktionelle Stammdaten“ für fachliche Materialarten, Altersbereich und Zielgruppe, Einsatzbereiche und Verwendungszwecke (bestehende Tabellen; Säulen bleiben in ihrer Verwaltung). - Migration (nur Ergänzungen): aktiv/inaktiv für Materialarten und Werte, Reihenfolge der Werte, zulässige Objektkontexte der Materialarten, einmalig aus dem Bestand abgeleitet; jede vorhandene Zuordnung bleibt zulässig. - EditorialVocabulary als eine Regelquelle für Redaktion (Medium, Modul, Programm, Lizenzartikel), Medien- und Kompositionsfilter, Picker und Mitgliederbibliothek: neu wählbar nur aktive, kontextgerechte Werte; vorhandene inaktive Zuordnungen sichtbar und beim Speichern erhalten; serverseitige Prüfung der Materialart. - Kennung fest, Bezeichnung pflegbar; verwendete Werte nur deaktivierbar; Systemkennungen (programm, modul, traineranleitung) geschützt. - „Inhaltsart“ heißt durchgängig „Fachliche Materialart“; der Picker trennt Medienart und fachliche Materialart und filtert danach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c84ae10809
commit
f774d43647
24 files changed
+1543
-91
No files matched your search
@@ -67,7 +67,7 @@ private function createFixture(
|
||||
$kind = EditorialContentKind::query()->where('slug', 'programm')->first();
|
||||
|
||||
if ($kind === null) {
|
||||
$this->error('Die Inhaltsart Programm fehlt.');
|
||||
$this->error('Die fachliche Materialart Programm fehlt.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -0,0 +1,671 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialDimensionValue;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
|
||||
use App\Filament\Resources\Pillars\PillarResource;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\Exceptions\Halt;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Attributes\Url;
|
||||
|
||||
/**
|
||||
* Redaktionelle Stammdaten (FACH-56 bis FACH-58): fachliche Materialarten und die Werte der Einordnung (Altersbereich
|
||||
* und Zielgruppe, Einsatzbereiche, Verwendungszwecke) zentral pflegen. Bestehende Tabellen, keine Kopien.
|
||||
*
|
||||
* - Bezeichnung pflegbar, Kennung fest; Zuordnungen hängen an der Kennung des Datensatzes und bleiben beim Umbenennen.
|
||||
* - Verwendete Werte werden deaktiviert statt gelöscht; Löschen nur ohne jede Zuordnung.
|
||||
* - Materialarten haben zulässige Objektkontexte; vorhandene Zuordnungen bleiben bei einer Änderung erhalten.
|
||||
* - Säulen werden in der vorhandenen Säulenverwaltung gepflegt (verlinkt), nicht hier.
|
||||
*/
|
||||
class RedaktionelleStammdaten extends Page implements HasTable
|
||||
{
|
||||
use InteractsWithTable;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
|
||||
protected static ?string $navigationLabel = 'Redaktionelle Stammdaten';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
protected static ?string $slug = 'stammdaten';
|
||||
|
||||
protected static ?string $title = 'Redaktionelle Stammdaten';
|
||||
|
||||
protected string $view = 'filament.stammdaten';
|
||||
|
||||
/** Bevorzugte Reihenfolge der Einordnungsgruppen; weitere Dimensionen folgen nach Bezeichnung. */
|
||||
private const DIMENSION_ORDER = ['zielgruppe', 'einsatzbereich', 'verwendungszweck'];
|
||||
|
||||
#[Url(as: 'gruppe', except: 'materialart')]
|
||||
public string $gruppe = 'materialart';
|
||||
|
||||
/** @var array<int, array<string, int>>|null */
|
||||
private ?array $verwendungCache = null;
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return self::darfPflegen();
|
||||
}
|
||||
|
||||
public static function darfPflegen(): bool
|
||||
{
|
||||
return ContentElementResource::editor();
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
if (! array_key_exists($this->gruppe, $this->gruppen())) {
|
||||
$this->gruppe = 'materialart';
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Auswahlwerte für Redaktion, Filter und Picker. Bezeichnungen sind änderbar, Zuordnungen bleiben erhalten; verwendete Werte werden deaktiviert statt gelöscht.';
|
||||
}
|
||||
|
||||
public function getMaxContentWidth(): Width|string|null
|
||||
{
|
||||
return Width::Full;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string> Schlüssel => Bezeichnung
|
||||
*/
|
||||
public function gruppen(): array
|
||||
{
|
||||
$gruppen = ['materialart' => 'Fachliche Materialarten'];
|
||||
$dimensionen = EditorialDimension::query()->where('slug', '!=', EditorialDimension::PILLAR_SLUG)->get()
|
||||
->sortBy(fn (EditorialDimension $d): string => sprintf('%02d', array_search($d->slug, self::DIMENSION_ORDER, true) === false ? 99 : array_search($d->slug, self::DIMENSION_ORDER, true)).$d->label);
|
||||
|
||||
foreach ($dimensionen as $dimension) {
|
||||
$gruppen[$dimension->slug] = (string) $dimension->label;
|
||||
}
|
||||
|
||||
return $gruppen;
|
||||
}
|
||||
|
||||
public function zeigeGruppe(string $gruppe): void
|
||||
{
|
||||
if (array_key_exists($gruppe, $this->gruppen())) {
|
||||
$this->gruppe = $gruppe;
|
||||
$this->verwendungCache = null;
|
||||
$this->resetTable();
|
||||
}
|
||||
}
|
||||
|
||||
public function saeulenUrl(): string
|
||||
{
|
||||
return PillarResource::getUrl('index');
|
||||
}
|
||||
|
||||
private function istMaterialart(): bool
|
||||
{
|
||||
return $this->gruppe === 'materialart';
|
||||
}
|
||||
|
||||
private function dimension(): ?EditorialDimension
|
||||
{
|
||||
return $this->istMaterialart() ? null : EditorialDimension::query()->where('slug', $this->gruppe)->first();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// Tabelle
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
$materialart = $this->istMaterialart();
|
||||
|
||||
return $table
|
||||
->query(function (): Builder {
|
||||
if ($this->istMaterialart()) {
|
||||
return EditorialContentKind::query();
|
||||
}
|
||||
|
||||
return EditorialDimensionValue::query()->where('editorial_dimension_id', $this->dimension()?->id ?? 0);
|
||||
})
|
||||
->defaultSort('sort_order')
|
||||
->reorderable('sort_order')
|
||||
->reorderRecordsTriggerAction(fn (Action $action, bool $isReordering): Action => $action
|
||||
->button()
|
||||
->label($isReordering ? 'Sortieren beenden' : 'Per Ziehen sortieren'))
|
||||
->paginated(false)
|
||||
->searchPlaceholder('Bezeichnung oder Kennung')
|
||||
->columns(array_values(array_filter([
|
||||
TextColumn::make('label')
|
||||
->label('Bezeichnung')
|
||||
->searchable(['label', 'slug'])
|
||||
->weight('semibold')
|
||||
->description(fn (Model $record): string => 'Kennung: '.$record->slug
|
||||
.($record instanceof EditorialContentKind && $record->isSystem() ? ' · vom System verwendet' : '')),
|
||||
$materialart ? TextColumn::make('contexts')
|
||||
->label('Zulässig für')
|
||||
->state(fn (EditorialContentKind $record): array => array_values(array_map(
|
||||
fn (string $context): string => EditorialContentKind::CONTEXTS[$context] ?? $context,
|
||||
(array) ($record->contexts ?? []),
|
||||
)))
|
||||
->badge()
|
||||
->color('gray') : null,
|
||||
TextColumn::make('is_active')
|
||||
->label('Status')
|
||||
->formatStateUsing(fn (bool $state): string => $state ? 'Aktiv' : 'Inaktiv')
|
||||
->badge()
|
||||
->color(fn (bool $state): string => $state ? 'success' : 'gray'),
|
||||
TextColumn::make('verwendung')
|
||||
->label('Verwendung')
|
||||
->state(fn (Model $record): string => $this->verwendungText($record))
|
||||
->action($this->verwendungAction()->name('verwendungZeigen')),
|
||||
])))
|
||||
->filters([
|
||||
SelectFilter::make('is_active')
|
||||
->label('Status')
|
||||
->options(['1' => 'Aktiv', '0' => 'Inaktiv']),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('hoch')
|
||||
->label('Nach oben')
|
||||
->icon('heroicon-m-arrow-up')
|
||||
->iconButton()
|
||||
->color('gray')
|
||||
->authorize(fn (): bool => self::darfPflegen())
|
||||
->disabled(fn (Model $record): bool => $this->nachbar($record, -1) === null)
|
||||
->action(fn (Model $record) => $this->verschiebe($record, -1)),
|
||||
Action::make('runter')
|
||||
->label('Nach unten')
|
||||
->icon('heroicon-m-arrow-down')
|
||||
->iconButton()
|
||||
->color('gray')
|
||||
->authorize(fn (): bool => self::darfPflegen())
|
||||
->disabled(fn (Model $record): bool => $this->nachbar($record, 1) === null)
|
||||
->action(fn (Model $record) => $this->verschiebe($record, 1)),
|
||||
$this->bearbeitenAction(),
|
||||
ActionGroup::make([
|
||||
$this->verwendungAction(),
|
||||
$this->umschaltenAction(),
|
||||
$this->loeschenAction(),
|
||||
])->label('Weitere')->icon('heroicon-m-chevron-down')->button()->size('sm')->color('gray'),
|
||||
])
|
||||
->emptyStateHeading('Noch keine Werte')
|
||||
->emptyStateDescription('Mit „Wert anlegen“ entsteht der erste Wert dieser Gruppe.');
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('anlegen')
|
||||
->label('Wert anlegen')
|
||||
->icon('heroicon-o-plus')
|
||||
->authorize(fn (): bool => self::darfPflegen())
|
||||
->modalHeading(fn (): string => 'Neuer Wert: '.($this->gruppen()[$this->gruppe] ?? ''))
|
||||
->schema(fn (): array => $this->formular(null))
|
||||
->fillForm(fn (): array => ['contexts' => ['medium']])
|
||||
->modalSubmitActionLabel('Anlegen')
|
||||
->action(function (array $data): void {
|
||||
$this->anlegen($data);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// Formular, Anlegen, Bearbeiten
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @return list<mixed>
|
||||
*/
|
||||
private function formular(?Model $record): array
|
||||
{
|
||||
$felder = [
|
||||
TextInput::make('label')
|
||||
->label('Bezeichnung')
|
||||
->required()
|
||||
->maxLength(120)
|
||||
->helperText($record !== null
|
||||
? 'Die Kennung „'.$record->slug.'“ bleibt; vorhandene Zuordnungen behalten den Wert und zeigen die neue Bezeichnung.'
|
||||
: 'Die Kennung entsteht aus der Bezeichnung und bleibt danach fest.'),
|
||||
];
|
||||
|
||||
if ($this->istMaterialart()) {
|
||||
$system = $record instanceof EditorialContentKind && $record->isSystem();
|
||||
$felder[] = CheckboxList::make('contexts')
|
||||
->label('Zulässig für')
|
||||
->options(EditorialContentKind::CONTEXTS)
|
||||
->required()
|
||||
->live()
|
||||
->columns(['default' => 2, 'md' => 4])
|
||||
->disabled($system)
|
||||
->dehydrated(! $system)
|
||||
->helperText($system
|
||||
? 'Diese Materialart verwendet das System; ihre Kontexte bleiben fest.'
|
||||
: 'Nur hier wird die Materialart neu angeboten. Programm und Modul gehören zu den Objektarten Programm und Modul, nicht zu Medien.');
|
||||
|
||||
if ($record instanceof EditorialContentKind) {
|
||||
$felder[] = Placeholder::make('konflikt')
|
||||
->label('Bestehende Zuordnungen')
|
||||
->visible(fn (Get $get): bool => $this->kontextKonflikte($record, (array) $get('contexts')) !== [])
|
||||
->content(fn (Get $get): HtmlString => new HtmlString('<span style="color: #9a5b00">'
|
||||
.e(implode(' ', $this->kontextKonflikte($record, (array) $get('contexts'))))
|
||||
.' Diese Zuordnungen bleiben erhalten und werden dort als „hier nicht vorgesehen“ gekennzeichnet; neu wählbar ist die Materialart dort nicht mehr.</span>'));
|
||||
$felder[] = Checkbox::make('konflikt_bestaetigt')
|
||||
->label('Ich habe die bestehenden Zuordnungen geprüft.')
|
||||
->accepted()
|
||||
->visible(fn (Get $get): bool => $this->kontextKonflikte($record, (array) $get('contexts')) !== []);
|
||||
}
|
||||
}
|
||||
|
||||
return $felder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string> Meldungen je entferntem Kontext mit Verwendung
|
||||
*/
|
||||
private function kontextKonflikte(EditorialContentKind $kind, array $neu): array
|
||||
{
|
||||
$verwendung = $this->verwendung($kind);
|
||||
$meldungen = [];
|
||||
|
||||
foreach ((array) ($kind->contexts ?? []) as $context) {
|
||||
if (! in_array($context, $neu, true) && ($verwendung[$context] ?? 0) > 0) {
|
||||
$meldungen[] = (EditorialContentKind::CONTEXTS[$context] ?? $context).': '.$verwendung[$context].' '.($verwendung[$context] === 1 ? 'Zuordnung' : 'Zuordnungen').'.';
|
||||
}
|
||||
}
|
||||
|
||||
return $meldungen;
|
||||
}
|
||||
|
||||
private function bearbeitenAction(): Action
|
||||
{
|
||||
return Action::make('bearbeiten')
|
||||
->label('Bearbeiten')
|
||||
->icon('heroicon-o-pencil-square')
|
||||
->button()
|
||||
->size('sm')
|
||||
->color('gray')
|
||||
->authorize(fn (): bool => self::darfPflegen())
|
||||
->modalHeading(fn (Model $record): string => '„'.$record->label.'“ bearbeiten')
|
||||
->schema(fn (Model $record): array => $this->formular($record))
|
||||
->fillForm(fn (Model $record): array => [
|
||||
'label' => $record->label,
|
||||
'contexts' => $record instanceof EditorialContentKind ? (array) ($record->contexts ?? []) : [],
|
||||
])
|
||||
->modalSubmitActionLabel('Speichern')
|
||||
->action(function (Model $record, array $data): void {
|
||||
$label = trim((string) $data['label']);
|
||||
$this->pruefeBezeichnung($label, $record);
|
||||
$record->label = $label;
|
||||
|
||||
if ($record instanceof EditorialContentKind && ! $record->isSystem() && isset($data['contexts'])) {
|
||||
$record->contexts = $this->kontexte((array) $data['contexts']);
|
||||
}
|
||||
|
||||
$record->save();
|
||||
Notification::make()->success()->title('Gespeichert')->body('Die neue Bezeichnung gilt sofort in Redaktion, Filtern und Picker.')->send();
|
||||
});
|
||||
}
|
||||
|
||||
private function anlegen(array $data): void
|
||||
{
|
||||
$label = trim((string) $data['label']);
|
||||
$this->pruefeBezeichnung($label, null);
|
||||
|
||||
if ($this->istMaterialart()) {
|
||||
EditorialContentKind::query()->create([
|
||||
'label' => $label,
|
||||
'slug' => $this->freieKennung($label, EditorialContentKind::query()),
|
||||
'sort_order' => (int) EditorialContentKind::query()->max('sort_order') + 10,
|
||||
'is_active' => true,
|
||||
'contexts' => $this->kontexte((array) ($data['contexts'] ?? [])),
|
||||
]);
|
||||
} else {
|
||||
$dimension = $this->dimension();
|
||||
abort_if($dimension === null, 404);
|
||||
$werte = EditorialDimensionValue::query()->where('editorial_dimension_id', $dimension->id);
|
||||
EditorialDimensionValue::query()->create([
|
||||
'editorial_dimension_id' => $dimension->id,
|
||||
'label' => $label,
|
||||
'slug' => $this->freieKennung($label, clone $werte),
|
||||
'sort_order' => (int) (clone $werte)->max('sort_order') + 10,
|
||||
'is_active' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->verwendungCache = null;
|
||||
Notification::make()->success()->title('Angelegt: „'.$label.'“')->body('Der Wert ist sofort in der passenden Redaktion wählbar.')->send();
|
||||
}
|
||||
|
||||
private function pruefeBezeichnung(string $label, ?Model $ausser): void
|
||||
{
|
||||
$query = $this->istMaterialart()
|
||||
? EditorialContentKind::query()
|
||||
: EditorialDimensionValue::query()->where('editorial_dimension_id', $this->dimension()?->id ?? 0);
|
||||
|
||||
$doppelt = $query->whereRaw('LOWER(label) = ?', [mb_strtolower($label)])
|
||||
->when($ausser !== null, fn (Builder $q) => $q->whereKeyNot($ausser->getKey()))
|
||||
->exists();
|
||||
|
||||
if ($label === '' || $doppelt) {
|
||||
Notification::make()->danger()->title($label === '' ? 'Die Bezeichnung fehlt.' : 'Diese Bezeichnung gibt es in der Gruppe schon.')->send();
|
||||
throw new Halt;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function kontexte(array $kontexte): array
|
||||
{
|
||||
$erlaubt = array_keys(EditorialContentKind::CONTEXTS);
|
||||
|
||||
return array_values(array_filter($erlaubt, fn (string $context): bool => in_array($context, $kontexte, true)));
|
||||
}
|
||||
|
||||
private function freieKennung(string $label, Builder $query): string
|
||||
{
|
||||
$basis = Str::slug($label) ?: 'wert';
|
||||
$kennung = $basis;
|
||||
$nummer = 2;
|
||||
|
||||
while ((clone $query)->where('slug', $kennung)->exists()) {
|
||||
$kennung = $basis.'-'.$nummer++;
|
||||
}
|
||||
|
||||
return $kennung;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// Aktiv, Löschen, Reihenfolge
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
private function umschaltenAction(): Action
|
||||
{
|
||||
return Action::make('umschalten')
|
||||
->label(fn (Model $record): string => $record->is_active ? 'Deaktivieren' : 'Reaktivieren')
|
||||
->icon(fn (Model $record): string => $record->is_active ? 'heroicon-o-eye-slash' : 'heroicon-o-eye')
|
||||
->authorize(fn (): bool => self::darfPflegen())
|
||||
->hidden(fn (Model $record): bool => $record instanceof EditorialContentKind && $record->isSystem())
|
||||
->requiresConfirmation()
|
||||
->modalHeading(fn (Model $record): string => '„'.$record->label.'“ '.($record->is_active ? 'deaktivieren?' : 'reaktivieren?'))
|
||||
->modalDescription(fn (Model $record): string => $record->is_active
|
||||
? 'Der Wert wird für neue Zuordnungen nicht mehr angeboten. '.$this->verwendungSatz($record).' Filter finden diese Objekte weiterhin.'
|
||||
: 'Der Wert wird wieder für neue Zuordnungen angeboten.')
|
||||
->modalSubmitActionLabel(fn (Model $record): string => $record->is_active ? 'Deaktivieren' : 'Reaktivieren')
|
||||
->action(function (Model $record): void {
|
||||
abort_if($record instanceof EditorialContentKind && $record->isSystem(), 403);
|
||||
$record->is_active = ! $record->is_active;
|
||||
$record->save();
|
||||
});
|
||||
}
|
||||
|
||||
private function loeschenAction(): Action
|
||||
{
|
||||
return Action::make('loeschen')
|
||||
->label('Löschen')
|
||||
->icon('heroicon-o-trash')
|
||||
->color('danger')
|
||||
->authorize(fn (): bool => self::darfPflegen())
|
||||
->visible(fn (Model $record): bool => $this->loeschbar($record))
|
||||
->requiresConfirmation()
|
||||
->modalHeading(fn (Model $record): string => '„'.$record->label.'“ löschen?')
|
||||
->modalDescription('Der Wert ist nirgends zugeordnet und wird endgültig entfernt.')
|
||||
->modalSubmitActionLabel('Löschen')
|
||||
->action(function (Model $record): void {
|
||||
// Erneut prüfen: Zwischenzeitlich entstandene Zuordnungen würden die Datenbank sonst still lösen.
|
||||
if (! $this->loeschbar($record)) {
|
||||
Notification::make()->danger()->title('Nicht gelöscht: Der Wert ist inzwischen zugeordnet. Deaktivieren Sie ihn stattdessen.')->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$record->delete();
|
||||
$this->verwendungCache = null;
|
||||
});
|
||||
}
|
||||
|
||||
private function loeschbar(Model $record): bool
|
||||
{
|
||||
if ($record instanceof EditorialContentKind && $record->isSystem()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return array_sum($this->verwendung($record, frisch: true)) === 0;
|
||||
}
|
||||
|
||||
private function nachbar(Model $record, int $richtung): ?Model
|
||||
{
|
||||
$liste = $this->geordnet();
|
||||
$index = $liste->search(fn (Model $m): bool => $m->is($record));
|
||||
|
||||
return $index === false ? null : $liste->get($index + $richtung);
|
||||
}
|
||||
|
||||
private function verschiebe(Model $record, int $richtung): void
|
||||
{
|
||||
$liste = $this->geordnet()->values();
|
||||
$index = $liste->search(fn (Model $m): bool => $m->is($record));
|
||||
|
||||
if ($index === false || $liste->get($index + $richtung) === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$neu = $liste->all();
|
||||
[$neu[$index], $neu[$index + $richtung]] = [$neu[$index + $richtung], $neu[$index]];
|
||||
|
||||
DB::transaction(function () use ($neu): void {
|
||||
foreach (array_values($neu) as $position => $eintrag) {
|
||||
if ((int) $eintrag->sort_order !== ($position + 1) * 10) {
|
||||
$eintrag->sort_order = ($position + 1) * 10;
|
||||
$eintrag->save();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Model>
|
||||
*/
|
||||
private function geordnet(): Collection
|
||||
{
|
||||
$query = $this->istMaterialart()
|
||||
? EditorialContentKind::query()
|
||||
: EditorialDimensionValue::query()->where('editorial_dimension_id', $this->dimension()?->id ?? 0);
|
||||
|
||||
return $query->orderBy('sort_order')->orderBy('id')->get()->values();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// Verwendung
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Zuordnungen je Objektkontext.
|
||||
*
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function verwendung(Model $record, bool $frisch = false): array
|
||||
{
|
||||
if ($frisch || $this->verwendungCache === null) {
|
||||
$this->verwendungCache = $this->istMaterialart() ? $this->materialartVerwendung() : $this->einordnungVerwendung();
|
||||
}
|
||||
|
||||
return $this->verwendungCache[(int) $record->getKey()] ?? [];
|
||||
}
|
||||
|
||||
private function verwendungText(Model $record): string
|
||||
{
|
||||
$teile = [];
|
||||
|
||||
foreach ($this->verwendung($record) as $context => $anzahl) {
|
||||
if ($anzahl > 0) {
|
||||
$teile[] = $anzahl.' '.$this->einheit($context, $anzahl);
|
||||
}
|
||||
}
|
||||
|
||||
return $teile === [] ? 'Nicht verwendet' : implode(' · ', $teile);
|
||||
}
|
||||
|
||||
private function verwendungSatz(Model $record): string
|
||||
{
|
||||
$text = $this->verwendungText($record);
|
||||
|
||||
return $text === 'Nicht verwendet'
|
||||
? 'Er ist derzeit nirgends zugeordnet.'
|
||||
: 'Bestehende Zuordnungen ('.$text.') bleiben erhalten und sichtbar.';
|
||||
}
|
||||
|
||||
private function einheit(string $context, int $anzahl): string
|
||||
{
|
||||
return match ($context) {
|
||||
'medium' => $anzahl === 1 ? 'Medium' : 'Medien',
|
||||
'modul' => $anzahl === 1 ? 'Modul' : 'Module',
|
||||
'programm' => $anzahl === 1 ? 'Programm' : 'Programme',
|
||||
'lizenzartikel' => 'Lizenzartikel',
|
||||
default => $anzahl === 1 ? 'Kombination' : 'Kombinationen',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, int>>
|
||||
*/
|
||||
private function materialartVerwendung(): array
|
||||
{
|
||||
$ergebnis = [];
|
||||
|
||||
foreach (DB::table('content_elements')->whereNotNull('editorial_content_kind_id')->groupBy('editorial_content_kind_id')->selectRaw('editorial_content_kind_id as id, count(*) as anzahl')->get() as $zeile) {
|
||||
$ergebnis[(int) $zeile->id]['medium'] = (int) $zeile->anzahl;
|
||||
}
|
||||
|
||||
foreach (DB::table('compositions')->whereNotNull('editorial_content_kind_id')->groupBy('editorial_content_kind_id', 'kind')->selectRaw('editorial_content_kind_id as id, kind, count(*) as anzahl')->get() as $zeile) {
|
||||
$context = EditorialVocabulary::compositionContext(CompositionKind::tryFrom((string) $zeile->kind)) ?? 'kombination';
|
||||
$ergebnis[(int) $zeile->id][$context] = ($ergebnis[(int) $zeile->id][$context] ?? 0) + (int) $zeile->anzahl;
|
||||
}
|
||||
|
||||
foreach (DB::table('license_articles')->whereNotNull('editorial_content_kind_id')->groupBy('editorial_content_kind_id')->selectRaw('editorial_content_kind_id as id, count(*) as anzahl')->get() as $zeile) {
|
||||
$ergebnis[(int) $zeile->id]['lizenzartikel'] = (int) $zeile->anzahl;
|
||||
}
|
||||
|
||||
return $ergebnis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, int>>
|
||||
*/
|
||||
private function einordnungVerwendung(): array
|
||||
{
|
||||
$ergebnis = [];
|
||||
$zeilen = DB::table('identity_dimension_values')
|
||||
->leftJoin('compositions', function ($join): void {
|
||||
$join->on('compositions.id', '=', 'identity_dimension_values.subject_id')
|
||||
->where('identity_dimension_values.subject_type', (new Composition)->getMorphClass());
|
||||
})
|
||||
->groupBy('identity_dimension_values.editorial_dimension_value_id', 'identity_dimension_values.subject_type', 'compositions.kind')
|
||||
->selectRaw('identity_dimension_values.editorial_dimension_value_id as id, identity_dimension_values.subject_type as typ, compositions.kind as kind, count(*) as anzahl')
|
||||
->get();
|
||||
|
||||
foreach ($zeilen as $zeile) {
|
||||
$context = match ($zeile->typ) {
|
||||
(new ContentElement)->getMorphClass() => 'medium',
|
||||
(new LicenseArticle)->getMorphClass() => 'lizenzartikel',
|
||||
default => EditorialVocabulary::compositionContext(CompositionKind::tryFrom((string) $zeile->kind)) ?? 'kombination',
|
||||
};
|
||||
$ergebnis[(int) $zeile->id][$context] = ($ergebnis[(int) $zeile->id][$context] ?? 0) + (int) $zeile->anzahl;
|
||||
}
|
||||
|
||||
return $ergebnis;
|
||||
}
|
||||
|
||||
private function verwendungAction(): Action
|
||||
{
|
||||
return Action::make('verwendung')
|
||||
->label('Verwendung')
|
||||
->icon('heroicon-m-list-bullet')
|
||||
->authorize(fn (): bool => self::darfPflegen())
|
||||
->modalHeading(fn (Model $record): string => 'Verwendung von „'.$record->label.'“')
|
||||
->modalContent(fn (Model $record) => view('filament.stammdaten-verwendung', $this->verwendungListe($record)))
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Schließen');
|
||||
}
|
||||
|
||||
/**
|
||||
* Zugeordnete Objekte mit Links in ihre Bearbeitung und gefilterte Bestandslisten.
|
||||
*
|
||||
* @return array{zeilen: list<array{art: string, titel: string, url: string}>, mehr: int, filter: list<array{label: string, url: string}>}
|
||||
*/
|
||||
public function verwendungListe(Model $record): array
|
||||
{
|
||||
$grenze = 40;
|
||||
$zeilen = [];
|
||||
$filter = [];
|
||||
|
||||
if ($record instanceof EditorialContentKind) {
|
||||
$medien = ContentElement::query()->where('editorial_content_kind_id', $record->id);
|
||||
$kompositionen = Composition::query()->where('editorial_content_kind_id', $record->id);
|
||||
$artikel = LicenseArticle::query()->where('editorial_content_kind_id', $record->id);
|
||||
if ((clone $medien)->exists()) {
|
||||
$filter[] = ['label' => 'Im Medienmanager filtern', 'url' => ContentElementResource::getUrl('index', ['inhaltsart' => $record->id])];
|
||||
}
|
||||
} else {
|
||||
$zuordnung = fn (string $klasse) => DB::table('identity_dimension_values')
|
||||
->where('editorial_dimension_value_id', $record->getKey())
|
||||
->where('subject_type', (new $klasse)->getMorphClass())
|
||||
->pluck('subject_id');
|
||||
$medien = ContentElement::query()->whereKey($zuordnung(ContentElement::class));
|
||||
$kompositionen = Composition::query()->whereKey($zuordnung(Composition::class));
|
||||
$artikel = LicenseArticle::query()->whereKey($zuordnung(LicenseArticle::class));
|
||||
if ((clone $medien)->exists()) {
|
||||
$filter[] = ['label' => 'Im Medienmanager filtern', 'url' => ContentElementResource::getUrl('index', ['einordnung' => $record->getKey()])];
|
||||
}
|
||||
if ((clone $kompositionen)->exists()) {
|
||||
$filter[] = ['label' => 'Programme und Module filtern', 'url' => EditorialDesk::getUrl(['pillar' => $record->getKey()])];
|
||||
}
|
||||
}
|
||||
|
||||
$gesamt = (clone $medien)->count() + (clone $kompositionen)->count() + (clone $artikel)->count();
|
||||
|
||||
foreach ($medien->orderBy('working_title')->limit($grenze)->get() as $element) {
|
||||
$zeilen[] = ['art' => 'Medium', 'titel' => (string) ($element->display_title ?: $element->working_title), 'url' => ContentElementResource::getUrl('view', ['record' => $element])];
|
||||
}
|
||||
|
||||
foreach ($kompositionen->orderBy('designation')->limit($grenze)->get() as $composition) {
|
||||
$context = EditorialVocabulary::compositionContext($composition->kind instanceof CompositionKind ? $composition->kind : CompositionKind::tryFrom((string) $composition->kind));
|
||||
$zeilen[] = ['art' => EditorialContentKind::CONTEXTS[$context ?? ''] ?? 'Kombination', 'titel' => (string) ($composition->display_title ?: $composition->designation), 'url' => EditorialCatalog::editUrl($composition)];
|
||||
}
|
||||
|
||||
foreach ($artikel->orderBy('code')->limit($grenze)->get() as $article) {
|
||||
$zeilen[] = ['art' => 'Lizenzartikel', 'titel' => trim($article->code.' '.($article->display_title ?: $article->working_title)), 'url' => LicenseArticleResource::getUrl('view', ['record' => $article])];
|
||||
}
|
||||
|
||||
return ['zeilen' => $zeilen, 'mehr' => max(0, $gesamt - count($zeilen)), 'filter' => $filter];
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\EditorialWorkingDraft;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
@@ -708,21 +708,10 @@ public function usageLines(): array
|
||||
*/
|
||||
public function dimensionGroups(): array
|
||||
{
|
||||
$groups = [];
|
||||
|
||||
foreach (EditorialDimension::forSubject($this->getRecord()) as $dimension) {
|
||||
$values = [];
|
||||
|
||||
foreach ($dimension->values as $value) {
|
||||
$values[] = ['id' => $value->id, 'label' => $value->label];
|
||||
}
|
||||
|
||||
if ($values !== []) {
|
||||
$groups[] = ['label' => $dimension->label, 'values' => $values];
|
||||
}
|
||||
}
|
||||
|
||||
return $groups;
|
||||
return app(EditorialVocabulary::class)->dimensionGroups($this->getRecord(), IdentityDimensionValue::query()
|
||||
->where('subject_type', $this->getRecord()->getMorphClass())
|
||||
->where('subject_id', $this->getRecord()->getKey())
|
||||
->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
@@ -74,8 +73,8 @@ public function form(Schema $schema): Schema
|
||||
->helperText('Erscheint in der Bibliothek. Leer lässt den Arbeitstitel stehen. Speichern legt keine Fassung an.'),
|
||||
Textarea::make('summary')->label('Kurzbeschreibung')->rows(3),
|
||||
Select::make('editorial_content_kind_id')
|
||||
->label('Inhaltsart')
|
||||
->options(fn (): array => EditorialContentKind::selectOptions())
|
||||
->label('Fachliche Materialart')
|
||||
->options(fn (): array => app(EditorialVocabulary::class)->kindOptions('medium', $this->getRecord()->editorial_content_kind_id !== null ? (int) $this->getRecord()->editorial_content_kind_id : null))
|
||||
->nullable()
|
||||
->helperText('Optional für Bibliothek und Website. Ändert weder die Ausgabeart noch eine Fassung.'),
|
||||
Placeholder::make('usage')->label('Verwendung')->content(function (): HtmlString {
|
||||
@@ -103,9 +102,12 @@ public function form(Schema $schema): Schema
|
||||
CheckboxList::make('dimension_ids')->label('Fachliche Einordnung')
|
||||
->options(function (): array {
|
||||
$options = [];
|
||||
foreach (EditorialDimension::forSubject($this->getRecord()) as $dimension) {
|
||||
foreach ($dimension->values as $value) {
|
||||
$options[$value->id] = $dimension->label.': '.$value->label;
|
||||
foreach (app(EditorialVocabulary::class)->dimensionGroups($this->getRecord(), IdentityDimensionValue::query()
|
||||
->where('subject_type', $this->getRecord()->getMorphClass())
|
||||
->where('subject_id', $this->getRecord()->getKey())
|
||||
->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all()) as $dimension) {
|
||||
foreach ($dimension['values'] as $value) {
|
||||
$options[$value['id']] = $dimension['label'].': '.$value['label'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\ContentElements\Pages;
|
||||
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\Bestand;
|
||||
use App\Filament\Support\MediaLibrary;
|
||||
@@ -121,7 +121,7 @@ public function pillarOptions(): array
|
||||
*/
|
||||
public function classificationOptions(): array
|
||||
{
|
||||
return app(MediaLibrary::class)->classifications();
|
||||
return app(MediaLibrary::class)->classifications(ctype_digit($this->einordnung) ? [(int) $this->einordnung] : []);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +129,7 @@ public function classificationOptions(): array
|
||||
*/
|
||||
public function contentKindOptions(): array
|
||||
{
|
||||
return EditorialContentKind::selectOptions();
|
||||
return app(EditorialVocabulary::class)->kindFilterOptions('medium', $this->inhaltsart);
|
||||
}
|
||||
|
||||
public function filtersActive(): bool
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\IdentityChange;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
@@ -648,6 +647,19 @@ protected function saveRedaktionTexte(): bool
|
||||
return false;
|
||||
}
|
||||
|
||||
$kindError = app(EditorialVocabulary::class)->kindError(
|
||||
'medium',
|
||||
filled($this->kindId) ? (int) $this->kindId : null,
|
||||
$element->editorial_content_kind_id !== null ? (int) $element->editorial_content_kind_id : null,
|
||||
);
|
||||
|
||||
if ($kindError !== null) {
|
||||
$this->deskFeedback = $kindError;
|
||||
$this->redaktionFehlerFeld = 'kindId';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->versionsBeforeSave = $element->versions()->count();
|
||||
app(IdentityProfile::class)->fill($element, [
|
||||
'working_title' => $title,
|
||||
@@ -776,8 +788,8 @@ public function einordnungArt(): array
|
||||
{
|
||||
return [
|
||||
'model' => 'kindId',
|
||||
'options' => EditorialContentKind::selectOptions(),
|
||||
'hilfe' => 'Fachliche Materialart, unabhängig von der Dateiart.',
|
||||
'options' => app(EditorialVocabulary::class)->kindOptions('medium', $this->getRecord()->editorial_content_kind_id !== null ? (int) $this->getRecord()->editorial_content_kind_id : null),
|
||||
'hilfe' => 'Fachliche Materialart, unabhängig von der technischen Medienart.',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -793,11 +805,14 @@ public function einordnungGruppen(): array
|
||||
->map(fn (Pillar $pillar): array => ['id' => (int) $pillar->id, 'label' => (string) $pillar->name])->all(),
|
||||
]];
|
||||
|
||||
foreach (EditorialDimension::forSubject($this->getRecord()) as $dimension) {
|
||||
foreach (app(EditorialVocabulary::class)->dimensionGroups($this->getRecord(), IdentityDimensionValue::query()
|
||||
->where('subject_type', $this->getRecord()->getMorphClass())
|
||||
->where('subject_id', $this->getRecord()->getKey())
|
||||
->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all()) as $dimension) {
|
||||
$groups[] = [
|
||||
'legend' => (string) $dimension->label,
|
||||
'legend' => $dimension['label'],
|
||||
'model' => 'dimensionIds',
|
||||
'values' => collect($dimension->values)->map(fn ($value): array => ['id' => (int) $value->id, 'label' => (string) $value->label])->all(),
|
||||
'values' => $dimension['values'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1014,7 +1029,7 @@ public function editorialHistory(): array
|
||||
'thumbnail_alt' => 'Alternativtext',
|
||||
'thumbnail_path' => 'Vorschaubild',
|
||||
'thumbnail_source' => 'Herkunft des Vorschaubilds',
|
||||
'editorial_content_kind_id' => 'Inhaltsart',
|
||||
'editorial_content_kind_id' => 'Fachliche Materialart',
|
||||
];
|
||||
|
||||
return IdentityChange::query()
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialProfileReader;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
@@ -92,6 +91,19 @@ protected function saveRedaktionTexte(): bool
|
||||
$this->releaseBeforeSave = $article->current_release_id;
|
||||
$this->releaseCountBeforeSave = $article->releases()->count();
|
||||
|
||||
$kindError = app(EditorialVocabulary::class)->kindError(
|
||||
'lizenzartikel',
|
||||
filled($this->kindId) ? (int) $this->kindId : null,
|
||||
$article->editorial_content_kind_id !== null ? (int) $article->editorial_content_kind_id : null,
|
||||
);
|
||||
|
||||
if ($kindError !== null) {
|
||||
$this->deskFeedback = $kindError;
|
||||
$this->redaktionFehlerFeld = 'kindId';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
app(IdentityProfile::class)->fill($article, [
|
||||
'working_title' => $this->workingTitle,
|
||||
'display_title' => $this->displayTitle,
|
||||
@@ -248,7 +260,7 @@ public function einordnungArt(): array
|
||||
{
|
||||
return [
|
||||
'model' => 'kindId',
|
||||
'options' => EditorialContentKind::selectOptions(),
|
||||
'options' => app(EditorialVocabulary::class)->kindOptions('lizenzartikel', $this->getRecord()->editorial_content_kind_id !== null ? (int) $this->getRecord()->editorial_content_kind_id : null),
|
||||
'hilfe' => 'Die Einordnung des Artikels ändert weder die Quelle noch den Preis.',
|
||||
];
|
||||
}
|
||||
@@ -277,21 +289,10 @@ private function sourceTitle(Model $source): string
|
||||
*/
|
||||
public function licenseDimensionGroups(): array
|
||||
{
|
||||
$groups = [];
|
||||
|
||||
foreach (EditorialDimension::forSubject($this->getRecord()) as $dimension) {
|
||||
$values = [];
|
||||
|
||||
foreach ($dimension->values as $value) {
|
||||
$values[] = ['id' => $value->id, 'label' => $value->label];
|
||||
}
|
||||
|
||||
if ($values !== []) {
|
||||
$groups[] = ['label' => $dimension->label, 'values' => $values];
|
||||
}
|
||||
}
|
||||
|
||||
return $groups;
|
||||
return app(EditorialVocabulary::class)->dimensionGroups($this->getRecord(), IdentityDimensionValue::query()
|
||||
->where('subject_type', $this->getRecord()->getMorphClass())
|
||||
->where('subject_id', $this->getRecord()->getKey())
|
||||
->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all());
|
||||
}
|
||||
|
||||
private function fillLicenseEditorial(): void
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
@@ -26,6 +27,9 @@ trait ChoosesMedia
|
||||
|
||||
public string $pickerDimension = '';
|
||||
|
||||
/** Filter „Fachliche Materialart“ (Kennung), gleiche Regel wie Medieneditor und Medienfilter. */
|
||||
public string $pickerMaterialart = '';
|
||||
|
||||
public string $pickerInspected = '';
|
||||
|
||||
public string $pickerSelected = '';
|
||||
@@ -99,15 +103,16 @@ public function pickerResult(): array
|
||||
}
|
||||
|
||||
if ($this->pickerPurpose === 'aufbau') {
|
||||
return app(EditorialCatalog::class)->browse(
|
||||
return $this->filterByMaterialart(app(EditorialCatalog::class)->browse(
|
||||
$this->pickerQuery,
|
||||
$this->pickerKind,
|
||||
$this->pickerDimension,
|
||||
$this->pickerExceptId(),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
$result = app(EditorialCatalog::class)->presentationBrowse($this->pickerQuery, $this->pickerKind);
|
||||
$result = $this->filterByMaterialart($result);
|
||||
|
||||
// CMS: nur Bilder, die als Website-Bild wählbar sind (keine vertraulichen Arten, nicht archiviert).
|
||||
if ($this->pickerPurpose === 'website-bild') {
|
||||
@@ -159,6 +164,7 @@ public function pickerDetail(): ?array
|
||||
$row['released'] = $element->website_released_at !== null;
|
||||
$row['output_label'] = PublicMaterialReader::outputLabel((string) $element->output_class);
|
||||
$row['pillars'] = $element->pillars->pluck('name')->all();
|
||||
$row['material'] = $element->editorialContentKind?->label;
|
||||
$row['usage'] = app(CatalogReading::class)->elementUsage($element);
|
||||
}
|
||||
|
||||
@@ -198,10 +204,38 @@ protected function resetPicker(string $purpose): void
|
||||
$this->pickerOpen = true;
|
||||
$this->pickerQuery = '';
|
||||
$this->pickerDimension = '';
|
||||
$this->pickerMaterialart = '';
|
||||
$this->pickerInspected = '';
|
||||
$this->pickerSelected = '';
|
||||
$this->pickerMarked = [];
|
||||
$this->replacingKey = null;
|
||||
$this->bindToVersion = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fachliche Materialarten, nach denen der Picker Medien eingrenzen kann (Kontext Medium).
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function pickerMaterialarten(): array
|
||||
{
|
||||
return app(EditorialVocabulary::class)->kindFilterOptions('medium', $this->pickerMaterialart);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{items: list<array<string, mixed>>, more: bool} $result
|
||||
* @return array{items: list<array<string, mixed>>, more: bool}
|
||||
*/
|
||||
private function filterByMaterialart(array $result): array
|
||||
{
|
||||
if (! ctype_digit($this->pickerMaterialart)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$ids = array_values(array_filter(array_map(fn (array $item): int => (int) ($item['element_id'] ?? 0), $result['items'])));
|
||||
$passend = ContentElement::query()->whereKey($ids)->where('editorial_content_kind_id', (int) $this->pickerMaterialart)->pluck('id')->map(fn ($id): int => (int) $id)->all();
|
||||
$result['items'] = array_values(array_filter($result['items'], fn (array $item): bool => in_array((int) ($item['element_id'] ?? 0), $passend, true)));
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use Filament\Actions\Action;
|
||||
@@ -111,21 +111,7 @@ public function bestand(): array
|
||||
*/
|
||||
public function dimensionFilters(): array
|
||||
{
|
||||
$groups = [];
|
||||
|
||||
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
|
||||
$values = [];
|
||||
|
||||
foreach ($dimension->values as $value) {
|
||||
$values[] = ['id' => $value->id, 'label' => $value->label];
|
||||
}
|
||||
|
||||
if ($values !== []) {
|
||||
$groups[] = ['label' => $dimension->label, 'values' => $values];
|
||||
}
|
||||
}
|
||||
|
||||
return $groups;
|
||||
return app(EditorialVocabulary::class)->dimensionFilterGroups(ctype_digit($this->pillar) ? [(int) $this->pillar] : []);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -232,7 +232,7 @@ public function saveRedaktion(): void
|
||||
|
||||
if (! $this->saveRedaktionTexte()) {
|
||||
$this->deskFeedbackError = true;
|
||||
$this->redaktionTab = 'texte';
|
||||
$this->redaktionTab = $this->redaktionFehlerFeld === 'kindId' ? 'einordnung' : 'texte';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\ReleaseContent;
|
||||
@@ -50,15 +50,16 @@ public function pillars(): array
|
||||
/**
|
||||
* @return list<array{id: int, label: string}>
|
||||
*/
|
||||
public function classifications(): array
|
||||
public function classifications(array $selectedIds = []): array
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
|
||||
foreach ($dimension->values->sortBy('label') as $value) {
|
||||
// Gleiche Regel wie Editor und Picker; verwendete inaktive Werte und gewählte Filter bleiben auffindbar.
|
||||
foreach (app(EditorialVocabulary::class)->dimensionFilterGroups($selectedIds) as $dimension) {
|
||||
foreach ($dimension['values'] as $value) {
|
||||
$options[] = [
|
||||
'id' => $value->id,
|
||||
'label' => $dimension->label.': '.$value->label,
|
||||
'id' => $value['id'],
|
||||
'label' => $dimension['label'].': '.$value['label'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
@@ -89,7 +89,7 @@ function (array $card) use ($dimensions, $dimensionIds): bool {
|
||||
'sicht' => $sicht,
|
||||
'nutzung' => $nutzung,
|
||||
'dimensionIds' => $dimensionIds,
|
||||
'filterDimensions' => EditorialDimension::query()->with('values')->orderBy('label')->get(),
|
||||
'filterDimensions' => app(EditorialVocabulary::class)->memberFilterDimensions(array_map(intval(...), $dimensionIds)),
|
||||
'libraryEmpty' => $untouched,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Redaktionelle Stammdaten zentral pflegen (FACH-56 bis FACH-58). Nur Ergänzungen, nichts wird umbenannt oder gelöscht:
|
||||
*
|
||||
* - Fachliche Materialarten: aktiv/inaktiv und zulässige Objektkontexte (medium, modul, programm, lizenzartikel).
|
||||
* - Werte der Einordnung (Zielgruppe, Einsatzbereich, Verwendungszweck): aktiv/inaktiv und Reihenfolge.
|
||||
*
|
||||
* Die Kontexte werden einmalig aus dem Bestand abgeleitet: Programm und Modul gelten für ihre Objektart, alle übrigen
|
||||
* Materialarten für Medien; Lizenzartikel behalten wie bisher die ganze Auswahl. Danach wird jeder Kontext ergänzt, in
|
||||
* dem eine Materialart tatsächlich verwendet wird, damit keine vorhandene Zuordnung unzulässig wird.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('editorial_content_kinds', function (Blueprint $table) {
|
||||
$table->boolean('is_active')->default(true)->after('sort_order');
|
||||
$table->json('contexts')->nullable()->after('is_active');
|
||||
});
|
||||
|
||||
Schema::table('editorial_dimension_values', function (Blueprint $table) {
|
||||
$table->unsignedInteger('sort_order')->default(0)->after('label');
|
||||
$table->boolean('is_active')->default(true)->after('sort_order');
|
||||
});
|
||||
|
||||
foreach (DB::table('editorial_dimension_values')->orderBy('editorial_dimension_id')->orderBy('id')->get(['id', 'editorial_dimension_id']) as $index => $value) {
|
||||
DB::table('editorial_dimension_values')->where('id', $value->id)->update(['sort_order' => ($index + 1) * 10]);
|
||||
}
|
||||
|
||||
$compositionContexts = ['kurs' => 'programm', 'uebung' => 'modul'];
|
||||
|
||||
foreach (DB::table('editorial_content_kinds')->get(['id', 'slug']) as $kind) {
|
||||
$contexts = match ($kind->slug) {
|
||||
'programm' => ['programm', 'lizenzartikel'],
|
||||
'modul' => ['modul', 'lizenzartikel'],
|
||||
default => ['medium', 'lizenzartikel'],
|
||||
};
|
||||
|
||||
if (DB::table('content_elements')->where('editorial_content_kind_id', $kind->id)->exists()) {
|
||||
$contexts[] = 'medium';
|
||||
}
|
||||
|
||||
foreach (DB::table('compositions')->where('editorial_content_kind_id', $kind->id)->distinct()->pluck('kind') as $compositionKind) {
|
||||
if (isset($compositionContexts[$compositionKind])) {
|
||||
$contexts[] = $compositionContexts[$compositionKind];
|
||||
}
|
||||
}
|
||||
|
||||
$order = ['medium', 'modul', 'programm', 'lizenzartikel'];
|
||||
$contexts = array_values(array_filter($order, fn (string $context): bool => in_array($context, $contexts, true)));
|
||||
|
||||
DB::table('editorial_content_kinds')->where('id', $kind->id)->update(['contexts' => json_encode($contexts)]);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('editorial_dimension_values', function (Blueprint $table) {
|
||||
$table->dropColumn(['sort_order', 'is_active']);
|
||||
});
|
||||
|
||||
Schema::table('editorial_content_kinds', function (Blueprint $table) {
|
||||
$table->dropColumn(['is_active', 'contexts']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<div class="vw" style="display: grid; gap: 0.75rem;">
|
||||
@if ($zeilen === [])
|
||||
<p class="vw-feld-hilfe">Dieser Wert ist derzeit nirgends zugeordnet.</p>
|
||||
@else
|
||||
<ul style="display: grid; gap: 0.35rem; margin: 0; padding: 0; list-style: none;">
|
||||
@foreach ($zeilen as $zeile)
|
||||
<li style="display: flex; gap: 0.75rem; align-items: baseline;">
|
||||
<span class="vw-zustand">{{ $zeile['art'] }}</span>
|
||||
<a class="vw-link" style="min-height: 0; padding: 0;" href="{{ $zeile['url'] }}">{{ $zeile['titel'] }}</a>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@if ($mehr > 0)
|
||||
<p class="vw-feld-hilfe">Und {{ $mehr }} weitere. Die gefilterten Listen zeigen alle.</p>
|
||||
@endif
|
||||
@endif
|
||||
@if ($filter !== [])
|
||||
<p style="display: flex; flex-wrap: wrap; gap: 0.5rem 1rem;">
|
||||
@foreach ($filter as $link)
|
||||
<a class="vw-link" href="{{ $link['url'] }}">{{ $link['label'] }}</a>
|
||||
@endforeach
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
@@ -0,0 +1,27 @@
|
||||
<x-filament-panels::page>
|
||||
<div class="vw">
|
||||
<div class="vw-register-zeile">
|
||||
<div class="vw-register" role="tablist" aria-label="Gruppen der redaktionellen Stammdaten">
|
||||
@foreach ($this->gruppen() as $wert => $label)
|
||||
<button type="button" role="tab" aria-selected="{{ $this->gruppe === $wert ? 'true' : 'false' }}" tabindex="{{ $this->gruppe === $wert ? '0' : '-1' }}"
|
||||
wire:click="zeigeGruppe('{{ $wert }}')"
|
||||
x-on:keydown.right.prevent="$el.nextElementSibling?.focus()" x-on:keydown.left.prevent="$el.previousElementSibling?.focus()">
|
||||
{{ $label }}
|
||||
</button>
|
||||
@endforeach
|
||||
</div>
|
||||
<a class="vw-link is-quiet vw-stammdaten-saeulen" href="{{ $this->saeulenUrl() }}">Fachliche Säulen @include('filament.verwaltung.icon', ['name' => 'extern'])</a>
|
||||
</div>
|
||||
<p class="vw-feld-hilfe" style="margin: 0 0 0.75rem;">
|
||||
@if ($this->gruppe === 'materialart')
|
||||
Fachliche Materialart eines Mediums, Moduls, Programms oder Lizenzartikels – unabhängig von der technischen Medienart. „Zulässig für“ bestimmt, wo sie neu gewählt werden kann.
|
||||
@else
|
||||
Einordnung für Suche und Filter. Sie gibt nichts frei, erteilt keine Rechte und ist keine tatsächliche Verwendung.
|
||||
@endif
|
||||
Fachliche Säulen werden in der Säulenverwaltung gepflegt.
|
||||
</p>
|
||||
</div>
|
||||
<div wire:key="stammdaten-{{ $this->gruppe }}">
|
||||
{{ $this->table }}
|
||||
</div>
|
||||
</x-filament-panels::page>
|
||||
@@ -8,7 +8,7 @@
|
||||
<span class="vw-feld-hilfe">Steuert Suche und Filter. Sie gibt kein Medium frei, erteilt keine Rechte und ist keine tatsächliche Verwendung.</span>
|
||||
</div>
|
||||
@if ($art)
|
||||
<label class="vw-feldlabel" style="max-width: 24rem;">Inhaltsart
|
||||
<label class="vw-feldlabel" style="max-width: 24rem;">Fachliche Materialart
|
||||
<select class="vw-auswahlfeld" wire:model.live="{{ $art['model'] }}" @disabled(! $editable)>
|
||||
<option value="">Keine Angabe</option>
|
||||
@foreach ($art['options'] as $id => $label)
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
$bindbar = in_array($zweck, ['praesentation', 'austausch'], true) && in_array($this->presentationRole, \App\Domain\Catalog\PresentationRole::BOUND_ROLES, true);
|
||||
$symbol = fn (?string $output): string => match ($output) { 'film' => 'film', 'bild' => 'bild', 'audio' => 'audio', default => 'dokument' };
|
||||
$kopf = $this->pickerKontext();
|
||||
$artLabel = $zweck === 'aufbau' ? 'Inhaltstyp' : 'Medienart';
|
||||
$materialarten = $this->pickerMaterialarten();
|
||||
@endphp
|
||||
<div class="vw vw-dialog" role="dialog" aria-modal="true" aria-labelledby="picker-titel" wire:key="picker-{{ $zweck }}"
|
||||
x-data x-trap.noscroll="true"
|
||||
@@ -52,12 +54,21 @@
|
||||
@include('filament.verwaltung.icon', ['name' => 'suche'])
|
||||
<input type="search" class="vw-eingabe" wire:model.live.debounce.300ms="pickerQuery" placeholder="Titel oder Suchbegriff" autofocus>
|
||||
</label>
|
||||
<label class="vw-sr" for="picker-art">Inhaltstyp</label>
|
||||
<label class="vw-sr" for="picker-art">{{ $artLabel }}</label>
|
||||
<select id="picker-art" class="vw-auswahlfeld" wire:model.live="pickerKind">
|
||||
@foreach ($this->pickerKinds() as $wert => $label)
|
||||
<option value="{{ $wert }}">Inhaltstyp: {{ $label }}</option>
|
||||
<option value="{{ $wert }}">{{ $artLabel }}: {{ $label }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@if ($materialarten !== [])
|
||||
<label class="vw-sr" for="picker-materialart">Fachliche Materialart</label>
|
||||
<select id="picker-materialart" class="vw-auswahlfeld" wire:model.live="pickerMaterialart">
|
||||
<option value="">Fachliche Materialart: alle</option>
|
||||
@foreach ($materialarten as $wert => $label)
|
||||
<option value="{{ $wert }}">Fachliche Materialart: {{ $label }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@endif
|
||||
@if ($zweck === 'aufbau' && method_exists($this, 'dimensionGroups') && ($dimensionen = $this->dimensionGroups()) !== [])
|
||||
<label class="vw-sr" for="picker-einordnung">Fachliche Einordnung</label>
|
||||
<select id="picker-einordnung" class="vw-auswahlfeld" wire:model.live="pickerDimension">
|
||||
@@ -76,7 +87,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">
|
||||
<div class="vw-picker-liste" wire:loading.class="opacity-60" wire:target="pickerQuery,pickerKind,pickerDimension,pickerMaterialart">
|
||||
@if ($ergebnis['items'] === [])
|
||||
<div class="vw-leer"><strong>Nichts gefunden.</strong><p>Ändere die Suche oder den Inhaltstyp.</p></div>
|
||||
@else
|
||||
@@ -119,7 +130,11 @@
|
||||
<p>{{ \Illuminate\Support\Str::limit((string) $detail['summary'], 280) }}</p>
|
||||
@endif
|
||||
<div class="vw-detail-fakten">
|
||||
<span><b>Inhaltstyp:</b> {{ $detail['kind'] }}</span>
|
||||
@if (filled($detail['material'] ?? null))
|
||||
<span><b>Fachliche Materialart:</b> {{ $detail['material'] }}</span>
|
||||
@else
|
||||
<span><b>Art:</b> {{ $detail['kind'] }}</span>
|
||||
@endif
|
||||
@if (filled($detail['output_label'] ?? null))<span><b>Medienart:</b> {{ $detail['output_label'] }}</span>@endif
|
||||
@if (filled($detail['version_label'] ?? null))<span><b>Stand:</b> {{ $detail['version_label'] }}</span>@endif
|
||||
</div>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<p>{{ $entry->summary }}</p>
|
||||
@endif
|
||||
@unless ($entry->public)
|
||||
<p class="preview-note">Nur in der Redaktionsvorschau sichtbar: Für diese Inhaltsart gibt es noch keine öffentliche Freigabe (öffentliches Profil, ADR-29).</p>
|
||||
<p class="preview-note">Nur in der Redaktionsvorschau sichtbar: Für diese fachliche Materialart gibt es noch keine öffentliche Freigabe (öffentliches Profil, ADR-29).</p>
|
||||
@endunless
|
||||
</div>
|
||||
</li>
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
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\PillarService;
|
||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||
use App\Filament\Pages\RedaktionelleStammdaten;
|
||||
use App\Filament\Resources\ContentElements\Pages\ListContentElements;
|
||||
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
||||
use App\Filament\Support\MediaLibrary;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Testing\TestAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Redaktionelle Stammdaten (FACH-56 bis FACH-58): zentrale Pflege, Schutz von Identität und Zuordnungen, zulässige
|
||||
* Kontexte und dieselben Regeln in Editor, Filter und Picker.
|
||||
*/
|
||||
class RedaktionelleStammdatenTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
}
|
||||
|
||||
public function test_a_new_value_is_offered_in_the_matching_editor_and_saved_and_found(): void
|
||||
{
|
||||
$editor = $this->editor();
|
||||
$film = app(ContentService::class)->createElement('film', 'film', 'Lara im Park');
|
||||
|
||||
Livewire::actingAs($editor, 'staff')
|
||||
->test(RedaktionelleStammdaten::class)
|
||||
->call('zeigeGruppe', 'zielgruppe')
|
||||
->callAction('anlegen', ['label' => 'Großeltern'])
|
||||
->assertHasNoActionErrors()
|
||||
->call('zeigeGruppe', 'materialart')
|
||||
->callAction('anlegen', ['label' => 'Rollenspielkarte', 'contexts' => ['medium']])
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$wert = $this->value('zielgruppe', 'grosseltern');
|
||||
$art = EditorialContentKind::query()->where('slug', 'rollenspielkarte')->firstOrFail();
|
||||
$this->assertTrue($art->is_active);
|
||||
$this->assertSame(['medium'], $art->contexts);
|
||||
$this->assertArrayNotHasKey($art->id, app(EditorialVocabulary::class)->kindOptions('lizenzartikel'), 'Nur im gewählten Kontext angeboten.');
|
||||
|
||||
Livewire::actingAs($editor, 'staff')
|
||||
->test(ViewContentElement::class, ['record' => $film->getKey()])
|
||||
->call('openRedaktion', 'einordnung')
|
||||
->assertSee('Großeltern')
|
||||
->assertSee('Rollenspielkarte')
|
||||
->set('kindId', $art->id)
|
||||
->set('dimensionIds', [$wert->id])
|
||||
->call('saveEditorial')
|
||||
->assertSet('deskFeedbackError', false);
|
||||
|
||||
$this->assertSame($art->id, $film->fresh()->editorial_content_kind_id);
|
||||
$this->assertTrue($this->assigned($film, $wert));
|
||||
|
||||
Livewire::withQueryParams(['einordnung' => (string) $wert->id])->actingAs($editor, 'staff')
|
||||
->test(ListContentElements::class)->assertSee('Lara im Park');
|
||||
Livewire::withQueryParams(['inhaltsart' => (string) $art->id])->actingAs($editor, 'staff')
|
||||
->test(ListContentElements::class)->assertSee('Lara im Park');
|
||||
}
|
||||
|
||||
public function test_renaming_keeps_identity_and_assignments_everywhere(): void
|
||||
{
|
||||
$film = app(ContentService::class)->createElement('film', 'film', 'Lara im Park');
|
||||
$kinder = $this->value('zielgruppe', 'kinder');
|
||||
app(IdentityDimension::class)->assign($film, $kinder);
|
||||
$trainer = EditorialContentKind::query()->where('slug', 'traineranleitung')->firstOrFail();
|
||||
|
||||
Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(RedaktionelleStammdaten::class)
|
||||
->call('zeigeGruppe', 'zielgruppe')
|
||||
->callAction(TestAction::make('bearbeiten')->table($kinder), ['label' => 'Kinder (6–10 Jahre)'])
|
||||
->assertHasNoActionErrors()
|
||||
->call('zeigeGruppe', 'materialart')
|
||||
->callAction(TestAction::make('bearbeiten')->table($trainer), ['label' => 'Anleitung für Trainer'])
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$kinder->refresh();
|
||||
$this->assertSame('kinder', $kinder->slug, 'Die Kennung bleibt.');
|
||||
$this->assertSame('Kinder (6–10 Jahre)', $kinder->label);
|
||||
$this->assertTrue($this->assigned($film, $kinder));
|
||||
$this->assertContains('Altersbereich und Zielgruppe: Kinder (6–10 Jahre)', array_column(app(MediaLibrary::class)->classifications(), 'label'));
|
||||
|
||||
// Systemkennung: Vertraulichkeit hängt an der Kennung, nicht an der Bezeichnung.
|
||||
$this->assertSame('traineranleitung', $trainer->fresh()->slug);
|
||||
$anleitung = app(ContentService::class)->createElement('bild', 'bild', 'Ablauf intern');
|
||||
$anleitung->forceFill(['editorial_content_kind_id' => $trainer->id])->save();
|
||||
$this->assertFalse(WebsiteImage::isSelectable($anleitung->fresh()));
|
||||
}
|
||||
|
||||
public function test_deactivating_keeps_assignments_visible_blocks_new_choice_and_survives_other_saves(): void
|
||||
{
|
||||
$editor = $this->editor();
|
||||
$film = app(ContentService::class)->createElement('film', 'film', 'Lara im Park');
|
||||
$anderes = app(ContentService::class)->createElement('film', 'film', 'Felix im Bus');
|
||||
$schule = $this->value('einsatzbereich', 'schule');
|
||||
$art = EditorialContentKind::query()->where('slug', 'unterrichtsfilm')->firstOrFail();
|
||||
app(IdentityDimension::class)->assign($film, $schule);
|
||||
$film->forceFill(['editorial_content_kind_id' => $art->id])->save();
|
||||
|
||||
$stammdaten = Livewire::actingAs($editor, 'staff')->test(RedaktionelleStammdaten::class)
|
||||
->call('zeigeGruppe', 'einsatzbereich')
|
||||
->callAction(TestAction::make('umschalten')->table($schule))
|
||||
->call('zeigeGruppe', 'materialart')
|
||||
->callAction(TestAction::make('umschalten')->table($art));
|
||||
$this->assertFalse($schule->fresh()->is_active);
|
||||
$this->assertFalse($art->fresh()->is_active);
|
||||
|
||||
// Bestehende Zuordnung sichtbar und erhalten, auch wenn andere Angaben gespeichert werden.
|
||||
Livewire::actingAs($editor, 'staff')
|
||||
->test(ViewContentElement::class, ['record' => $film->getKey()])
|
||||
->call('openRedaktion', 'einordnung')
|
||||
->assertSee('Schule (inaktiv)')
|
||||
->assertSee('Unterrichtsfilm (inaktiv)')
|
||||
->set('teaser', 'Neuer Teaser')
|
||||
->call('saveEditorial')
|
||||
->assertSet('deskFeedbackError', false);
|
||||
$this->assertTrue($this->assigned($film, $schule), 'Die inaktive Zuordnung bleibt beim Speichern anderer Angaben.');
|
||||
$this->assertSame($art->id, $film->fresh()->editorial_content_kind_id);
|
||||
|
||||
// Neue Auswahl ausgeschlossen: weder angeboten noch serverseitig angenommen.
|
||||
Livewire::actingAs($editor, 'staff')
|
||||
->test(ViewContentElement::class, ['record' => $anderes->getKey()])
|
||||
->call('openRedaktion', 'einordnung')
|
||||
->assertSee('Kita')
|
||||
->assertDontSee('Schule (inaktiv)')
|
||||
->assertDontSee('Unterrichtsfilm')
|
||||
->set('dimensionIds', [$schule->id])
|
||||
->set('kindId', $art->id)
|
||||
->call('saveEditorial')
|
||||
->assertSet('deskFeedbackError', true)
|
||||
->assertSet('redaktionTab', 'einordnung');
|
||||
$this->assertNull($anderes->fresh()->editorial_content_kind_id);
|
||||
app(IdentityDimension::class)->replaceOffered($anderes, [$schule->id]);
|
||||
$this->assertFalse($this->assigned($anderes, $schule));
|
||||
|
||||
// Filter findet die Zuordnung weiterhin; ein gewählter Filter bleibt.
|
||||
$this->assertContains('Einsatzbereich: Schule (inaktiv)', array_column(app(MediaLibrary::class)->classifications(), 'label'));
|
||||
Livewire::withQueryParams(['einordnung' => (string) $schule->id])->actingAs($editor, 'staff')
|
||||
->test(ListContentElements::class)->assertSet('einordnung', (string) $schule->id)->assertSee('Lara im Park')->assertDontSee('Felix im Bus');
|
||||
|
||||
// Reaktivieren und Reihenfolge ändern.
|
||||
$stammdaten->call('zeigeGruppe', 'einsatzbereich')
|
||||
->callAction(TestAction::make('umschalten')->table($schule->fresh()));
|
||||
$this->assertTrue($schule->fresh()->is_active);
|
||||
$erster = $this->dimension('einsatzbereich')->values()->first();
|
||||
$stammdaten->callAction(TestAction::make('runter')->table($erster));
|
||||
$this->assertNotSame($erster->id, $this->dimension('einsatzbereich')->values()->first()->id);
|
||||
$stammdaten->callAction(TestAction::make('hoch')->table($erster->fresh()));
|
||||
$this->assertSame($erster->id, $this->dimension('einsatzbereich')->values()->first()->id);
|
||||
}
|
||||
|
||||
public function test_object_kinds_are_not_offered_as_material_of_a_medium(): void
|
||||
{
|
||||
$editor = $this->editor();
|
||||
$bild = app(ContentService::class)->createElement('bild', 'bild', 'Szenenbild');
|
||||
$programm = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
|
||||
$modul = EditorialContentKind::query()->where('slug', 'modul')->firstOrFail();
|
||||
$vokabular = app(EditorialVocabulary::class);
|
||||
|
||||
foreach ([$vokabular->kindOptions('medium'), $vokabular->kindFilterOptions('medium')] as $optionen) {
|
||||
$this->assertArrayNotHasKey($programm->id, $optionen);
|
||||
$this->assertArrayNotHasKey($modul->id, $optionen);
|
||||
}
|
||||
$this->assertArrayHasKey($programm->id, $vokabular->kindOptions('programm'));
|
||||
$this->assertArrayHasKey($modul->id, $vokabular->kindOptions('modul'));
|
||||
|
||||
$seite = Livewire::actingAs($editor, 'staff')->test(ViewContentElement::class, ['record' => $bild->getKey()]);
|
||||
$this->assertArrayNotHasKey($programm->id, $seite->instance()->einordnungArt()['options']);
|
||||
$this->assertArrayNotHasKey($programm->id, $seite->instance()->pickerMaterialarten());
|
||||
$seite->set('kindId', $programm->id)->call('saveEditorial')->assertSet('deskFeedbackError', true);
|
||||
$this->assertNull($bild->fresh()->editorial_content_kind_id);
|
||||
}
|
||||
|
||||
public function test_changing_contexts_of_a_used_kind_asks_and_keeps_assignments(): void
|
||||
{
|
||||
$film = app(ContentService::class)->createElement('film', 'film', 'Lara im Park');
|
||||
$art = EditorialContentKind::query()->where('slug', 'interview')->firstOrFail();
|
||||
$film->forceFill(['editorial_content_kind_id' => $art->id])->save();
|
||||
|
||||
$seite = Livewire::actingAs($this->editor(), 'staff')->test(RedaktionelleStammdaten::class);
|
||||
$seite->callAction(TestAction::make('bearbeiten')->table($art), ['label' => 'Interview', 'contexts' => ['lizenzartikel']])
|
||||
->assertHasActionErrors(['konflikt_bestaetigt']);
|
||||
$this->assertContains('medium', $art->fresh()->contexts);
|
||||
|
||||
Livewire::actingAs($this->editor(), 'staff')->test(RedaktionelleStammdaten::class)
|
||||
->callAction(TestAction::make('bearbeiten')->table($art), ['label' => 'Interview', 'contexts' => ['lizenzartikel'], 'konflikt_bestaetigt' => true])
|
||||
->assertHasNoActionErrors();
|
||||
$this->assertSame(['lizenzartikel'], $art->fresh()->contexts);
|
||||
$this->assertSame($art->id, $film->fresh()->editorial_content_kind_id, 'Die Zuordnung bleibt.');
|
||||
$this->assertSame('Interview (hier nicht vorgesehen)', app(EditorialVocabulary::class)->kindOptions('medium', $art->id)[$art->id]);
|
||||
}
|
||||
|
||||
public function test_used_values_cannot_be_deleted_and_system_kinds_stay_fixed(): void
|
||||
{
|
||||
$film = app(ContentService::class)->createElement('film', 'film', 'Lara im Park');
|
||||
$kinder = $this->value('zielgruppe', 'kinder');
|
||||
app(IdentityDimension::class)->assign($film, $kinder);
|
||||
$unbenutzt = $this->value('zielgruppe', 'eltern');
|
||||
$programm = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
|
||||
|
||||
Livewire::actingAs($this->editor(), 'staff')->test(RedaktionelleStammdaten::class)
|
||||
->call('zeigeGruppe', 'zielgruppe')
|
||||
->assertActionHidden(TestAction::make('loeschen')->table($kinder))
|
||||
->callAction(TestAction::make('loeschen')->table($unbenutzt))
|
||||
->call('zeigeGruppe', 'materialart')
|
||||
->assertActionHidden(TestAction::make('umschalten')->table($programm))
|
||||
->assertActionHidden(TestAction::make('loeschen')->table($programm));
|
||||
|
||||
$this->assertNotNull($kinder->fresh());
|
||||
$this->assertNull($unbenutzt->fresh());
|
||||
$this->assertTrue($programm->fresh()->is_active);
|
||||
}
|
||||
|
||||
public function test_pillars_keep_their_own_management(): void
|
||||
{
|
||||
$editor = $this->editor();
|
||||
app(PillarService::class)->create('Neue Säule');
|
||||
|
||||
$this->actingAs($editor, 'staff')->get('/verwaltung/saeulen')->assertOk()->assertSee('Neue Säule');
|
||||
Livewire::actingAs($editor, 'staff')->test(RedaktionelleStammdaten::class)
|
||||
->assertSee('Fachliche Säulen')
|
||||
->assertDontSee('pfeiler-1');
|
||||
$this->assertArrayNotHasKey(EditorialDimension::PILLAR_SLUG, (new RedaktionelleStammdaten)->gruppen());
|
||||
}
|
||||
|
||||
public function test_staff_without_the_editor_role_cannot_change_master_data(): void
|
||||
{
|
||||
$katalog = User::factory()->katalogverwalter()->create();
|
||||
$katalog->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$kinder = $this->value('zielgruppe', 'kinder');
|
||||
|
||||
$this->actingAs($katalog, 'staff')->get('/verwaltung/stammdaten')->assertForbidden();
|
||||
Livewire::actingAs($katalog, 'staff')->test(RedaktionelleStammdaten::class)->assertForbidden();
|
||||
$this->assertTrue($kinder->fresh()->is_active);
|
||||
}
|
||||
|
||||
private function assigned(ContentElement $element, EditorialDimensionValue $value): bool
|
||||
{
|
||||
return IdentityDimensionValue::query()
|
||||
->where('subject_type', $element->getMorphClass())
|
||||
->where('subject_id', $element->id)
|
||||
->where('editorial_dimension_value_id', $value->id)
|
||||
->exists();
|
||||
}
|
||||
|
||||
private function dimension(string $slug): EditorialDimension
|
||||
{
|
||||
return EditorialDimension::query()->where('slug', $slug)->firstOrFail();
|
||||
}
|
||||
|
||||
private function value(string $dimension, string $slug): EditorialDimensionValue
|
||||
{
|
||||
return EditorialDimensionValue::query()
|
||||
->where('editorial_dimension_id', $this->dimension($dimension)->id)
|
||||
->where('slug', $slug)
|
||||
->firstOrFail();
|
||||
}
|
||||
|
||||
private function editor(): User
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
return $editor;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user