Medium, Modul, Programm und Lizenzartikel nutzen denselben Objektkopf, dieselben Register (Texte, Präsentationsmedien, Einordnung) und denselben visuellen Picker. Präsentationsmedien, Abweichungen und Texte bilden einen Arbeitsstand, den nur „Redaktion speichern“ schreibt; Austausch behält die Position, Sortierung bleibt in der Rolle. Der Wechsel zur Redaktion und zurück erhält offene Eingaben des Ausgangseditors. Entfernt versteckte Mitspeicherungen: Der Didaktikdialog schreibt keine Redaktionstexte mehr, die Website-Freigabe keine offenen Quellenzeilen, Entwurf verwerfen setzt keine offenen Redaktionseingaben zurück. Tests, die alte Orte oder CSS-Zeichenketten prüften, sind auf die neue Bedienung umgestellt; neue Tests decken Arbeitsstand, Austausch, Abbrechen und Rückweg ab. Datenmodell, Fassungen und Rechte bleiben unverändert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
41658d98dd
commit
e1fd59491c
44 files changed
+3917
-2173
No files matched your search
@@ -6,6 +6,7 @@
|
||||
use App\Domain\Media\WebsiteMedia;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Präsentationsmedien sind Referenzen auf Inhaltselemente.
|
||||
@@ -60,6 +61,215 @@ public function rows(Model $subject): array
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gespeicherte Zuordnungen als bearbeitbarer Arbeitsstand, nach Rolle und Position geordnet.
|
||||
*
|
||||
* @return list<array{key: string, id: int|null, role: string, element_id: int, source: int|null}>
|
||||
*/
|
||||
public function staged(Model $subject): array
|
||||
{
|
||||
$assignments = PresentationAssignment::query()
|
||||
->with('role')
|
||||
->where('subject_type', $subject->getMorphClass())
|
||||
->where('subject_id', $subject->getKey())
|
||||
->get()
|
||||
->sortBy(fn (PresentationAssignment $row): string => sprintf('%05d-%05d-%08d', (int) $row->role?->sort_order, (int) $row->position, (int) $row->id))
|
||||
->values();
|
||||
|
||||
$rows = [];
|
||||
|
||||
foreach ($assignments as $assignment) {
|
||||
$rows[] = [
|
||||
'key' => 'a'.$assignment->id,
|
||||
'id' => (int) $assignment->id,
|
||||
'role' => (string) $assignment->role?->slug,
|
||||
'element_id' => (int) $assignment->content_element_id,
|
||||
'source' => $assignment->source_version_id !== null ? (int) $assignment->source_version_id : null,
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anzeigezeilen für einen Arbeitsstand, gruppiert nach Rolle. Liest nur, schreibt nichts.
|
||||
*
|
||||
* @param list<array{key: string, id: int|null, role: string, element_id: int, source: int|null}> $staged
|
||||
* @return list<array{role: string, label: string, multiple: bool, ordered: bool, rows: list<array<string, mixed>>}>
|
||||
*/
|
||||
public function describe(array $staged): array
|
||||
{
|
||||
$roles = PresentationRole::query()->orderBy('sort_order')->get()->keyBy('slug');
|
||||
$elements = ContentElement::query()
|
||||
->with('editorialContentKind')
|
||||
->whereIn('id', array_values(array_unique(array_map(fn (array $row): int => (int) $row['element_id'], $staged))))
|
||||
->get()
|
||||
->keyBy('id');
|
||||
$sources = ContentElementVersion::query()
|
||||
->whereIn('id', array_values(array_filter(array_map(fn (array $row): ?int => $row['source'] ?? null, $staged))))
|
||||
->get()
|
||||
->keyBy('id');
|
||||
$groups = [];
|
||||
|
||||
foreach ($roles as $slug => $role) {
|
||||
$rows = array_values(array_filter($staged, fn (array $row): bool => $row['role'] === $slug));
|
||||
|
||||
if ($rows === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$described = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$element = $elements->get((int) $row['element_id']);
|
||||
$released = $element instanceof ContentElement && $this->website->present($element) !== null;
|
||||
$source = $row['source'] !== null ? $sources->get((int) $row['source']) : null;
|
||||
|
||||
$described[] = [
|
||||
'key' => $row['key'],
|
||||
'id' => $row['id'],
|
||||
'element_id' => (int) $row['element_id'],
|
||||
'title' => $element instanceof ContentElement
|
||||
? (string) ($element->display_title ?: $element->working_title)
|
||||
: 'Medium fehlt',
|
||||
'image' => $element instanceof ContentElement
|
||||
? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path)
|
||||
: null,
|
||||
'kind' => $element?->editorialContentKind?->label,
|
||||
'output' => $element instanceof ContentElement ? (string) $element->output_class : '',
|
||||
'released' => $released,
|
||||
'release_label' => $released ? 'Für die Website freigegeben' : 'Nicht für die Website freigegeben',
|
||||
'binding' => $source instanceof ContentElementVersion ? $this->bindingFor($source) : null,
|
||||
'new' => $row['id'] === null,
|
||||
];
|
||||
}
|
||||
|
||||
$groups[] = [
|
||||
'role' => (string) $slug,
|
||||
'label' => PresentationRole::displayLabel((string) $slug, (string) $role->label),
|
||||
'multiple' => (bool) $role->multiple,
|
||||
'ordered' => (bool) $role->ordered,
|
||||
'rows' => $described,
|
||||
];
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob ein Medium im Arbeitsstand einer Rolle zugeordnet werden darf. Liefert den Ablehnungsgrund oder null.
|
||||
*/
|
||||
public function refusal(Model $subject, string $roleSlug, int $elementId): ?string
|
||||
{
|
||||
$role = PresentationRole::query()->where('slug', $roleSlug)->first();
|
||||
$element = ContentElement::query()->find($elementId);
|
||||
|
||||
if (! $role instanceof PresentationRole || ! $element instanceof ContentElement) {
|
||||
return 'Rolle oder Medium fehlt.';
|
||||
}
|
||||
|
||||
if ($element->archived_at !== null) {
|
||||
return 'Ein archiviertes Medium wird nicht zugeordnet.';
|
||||
}
|
||||
|
||||
if ($subject instanceof ContentElement && (int) $subject->getKey() === (int) $element->id) {
|
||||
return 'Ein Medium kann nicht seine eigene Präsentation sein.';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schreibt einen Arbeitsstand: entfernte Zuordnungen lösen, neue anlegen, Bindung und Reihenfolge je Rolle setzen.
|
||||
* Medien, Fassungen und Website-Freigaben bleiben unberührt.
|
||||
*
|
||||
* @param list<array{key: string, id: int|null, role: string, element_id: int, source: int|null}> $staged
|
||||
*/
|
||||
public function commit(Model $subject, array $staged, ?User $actor = null): void
|
||||
{
|
||||
$roles = PresentationRole::query()->get()->keyBy('slug');
|
||||
$seen = [];
|
||||
|
||||
foreach ($staged as $row) {
|
||||
$role = $roles->get($row['role']);
|
||||
|
||||
if (! $role instanceof PresentationRole) {
|
||||
throw new DomainRuleException('Diese Rolle gibt es nicht.');
|
||||
}
|
||||
|
||||
$refusal = $this->refusal($subject, $row['role'], (int) $row['element_id']);
|
||||
|
||||
if ($refusal !== null) {
|
||||
throw new DomainRuleException($refusal);
|
||||
}
|
||||
|
||||
$pair = $row['role'].':'.$row['element_id'];
|
||||
|
||||
if (isset($seen[$pair])) {
|
||||
throw new DomainRuleException('Ein Medium steht in derselben Rolle nur einmal.');
|
||||
}
|
||||
|
||||
$seen[$pair] = true;
|
||||
$count = count(array_filter($staged, fn (array $other): bool => $other['role'] === $row['role']));
|
||||
|
||||
if (! $role->multiple && $count > 1) {
|
||||
throw new DomainRuleException($role->label.' hat nur eine Zuordnung.');
|
||||
}
|
||||
|
||||
$element = ContentElement::query()->findOrFail((int) $row['element_id']);
|
||||
$this->checkedSource($subject, $element, $row['source']);
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($subject, $staged, $roles, $actor): void {
|
||||
$existing = PresentationAssignment::query()
|
||||
->with(['role', 'element'])
|
||||
->where('subject_type', $subject->getMorphClass())
|
||||
->where('subject_id', $subject->getKey())
|
||||
->get()
|
||||
->keyBy('id');
|
||||
$kept = array_filter(array_map(fn (array $row): ?int => $row['id'], $staged));
|
||||
|
||||
foreach ($existing as $id => $assignment) {
|
||||
if (! in_array((int) $id, $kept, true)) {
|
||||
$this->record($subject, ($assignment->role?->label ?? 'Präsentation').': '.($assignment->element?->working_title ?? ''), null, $actor);
|
||||
$assignment->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$positions = [];
|
||||
|
||||
foreach ($staged as $row) {
|
||||
$role = $roles->get($row['role']);
|
||||
$position = $positions[$row['role']] = ($positions[$row['role']] ?? 0) + 1;
|
||||
$assignment = $row['id'] !== null ? $existing->get($row['id']) : null;
|
||||
|
||||
if ($assignment instanceof PresentationAssignment) {
|
||||
$changed = (int) $assignment->position !== $position
|
||||
|| (int) ($assignment->source_version_id ?? 0) !== (int) ($row['source'] ?? 0);
|
||||
$assignment->position = $position;
|
||||
$assignment->source_version_id = $row['source'];
|
||||
|
||||
if ($changed) {
|
||||
$assignment->save();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$element = ContentElement::query()->findOrFail((int) $row['element_id']);
|
||||
PresentationAssignment::query()->create([
|
||||
'subject_type' => $subject->getMorphClass(),
|
||||
'subject_id' => $subject->getKey(),
|
||||
'content_element_id' => $element->id,
|
||||
'presentation_role_id' => $role->id,
|
||||
'position' => $position,
|
||||
'source_version_id' => $row['source'],
|
||||
]);
|
||||
$this->record($subject, null, $role->label.': '.$element->working_title, $actor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function assign(Model $subject, string $roleSlug, int $elementId, ?int $sourceVersionId, ?User $actor = null): string
|
||||
{
|
||||
$role = PresentationRole::query()->where('slug', $roleSlug)->first();
|
||||
@@ -242,7 +452,14 @@ private function binding(PresentationAssignment $assignment): ?array
|
||||
return null;
|
||||
}
|
||||
|
||||
$version = $assignment->sourceVersion;
|
||||
return $this->bindingFor($assignment->sourceVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{label: string, stale: bool}
|
||||
*/
|
||||
private function bindingFor(ContentElementVersion $version): array
|
||||
{
|
||||
$latestId = ContentElementVersion::query()
|
||||
->where('content_element_id', $version->content_element_id)
|
||||
->where('status', ContentVersionStatus::Bereit)
|
||||
|
||||
@@ -41,4 +41,20 @@ public static function selectOptions(): array
|
||||
{
|
||||
return static::query()->orderBy('sort_order')->pluck('label', 'slug')->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Kurze Bezeichnung für Überschriften und Auswahl in der Verwaltung.
|
||||
*/
|
||||
public static function displayLabel(string $slug, string $label): string
|
||||
{
|
||||
return match ($slug) {
|
||||
'titelbild' => 'Titelbild',
|
||||
'titelbild_alternativ' => 'Alternative Titelbilder',
|
||||
'trailer' => 'Trailer',
|
||||
'vorschauclip' => 'Vorschauclips',
|
||||
'interview' => 'Interviews',
|
||||
'galerie' => 'Galerie',
|
||||
default => $label,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user