Pflege Übungen im Aufbauarbeitsplatz und weise Verwendung und Sperrfolgen nach
CI Feature / test (push) Successful in 2m34s

Eigener Eintrag Übungen unter Inhalte (Bestand, Anlegen, gemeinsamer Aufbau mit Varianten, Verwendung und
Variantenauswahl im Modul und Programm), Verwendungsnachweis über verschachtelte und ältere Stände,
Auswirkungsbericht einer Mediensperre, gesperrte Bestandteile verhindern die Angebotsaktivierung, Vorschaubilder
gesperrter Medien werden nicht mehr ausgeliefert, Rückfalltest gegen die Daten des neuen Stands.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-23 17:03:32 +01:00
1 parent d1f97a351a
commit bbee288e69
22 files changed
+1104 -26

No files matched your search

@@ -40,6 +40,7 @@
use Filament\Support\Exceptions\Halt;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Livewire\WithFileUploads;
@@ -69,6 +70,15 @@ abstract class EditComposition extends EditRecord
public string $materialNote = '';
/** @var list<array{key: string, name: string, description: string}> Durchführungsvarianten einer Übung */
public array $variants = [];
public string $durationMax = '';
public string $prerequisites = '';
public string $newVariantName = '';
public string $revisionNote = '';
public string $search = '';
@@ -490,6 +500,138 @@ public function cancelText(): void
$this->newTextBody = '';
}
public function isExercise(): bool
{
return $this->hostKind() === CompositionKind::Exercise;
}
public function addVariant(): void
{
$name = trim($this->newVariantName);
if ($name === '') {
$this->feedback = 'Eine Variante braucht einen Namen.';
return;
}
$base = Str::slug($name) ?: 'variante';
$key = $base;
$n = 2;
while (in_array($key, array_column($this->variants, 'key'), true)) {
$key = $base.'-'.$n++;
}
$this->variants[] = ['key' => $key, 'name' => $name, 'description' => ''];
$this->newVariantName = '';
$this->feedback = 'Variante „'.$name.'“ ist angelegt. Ordne ihr Bestandteile zu. Gespeichert wird mit „Entwurf speichern“.';
}
public function removeVariant(string $key): void
{
foreach ($this->members as $member) {
if (($member['variant'] ?? null) === $key) {
$this->feedback = 'Diese Variante hat noch Bestandteile. Ordne sie zuerst einer anderen Variante oder dem gemeinsamen Teil zu.';
return;
}
}
$this->variants = array_values(array_filter($this->variants, fn (array $variant): bool => $variant['key'] !== $key));
$this->feedback = 'Die Variante ist aus diesem Entwurf genommen. Eine freigegebene Fassung bleibt unverändert.';
}
public function setMemberVariant(int $index, string $key): void
{
if (! isset($this->members[$index])) {
return;
}
$this->members[$index]['variant'] = $key === '' ? null : $key;
}
public function setMemberRequirement(int $index, string $requirement): void
{
if (! isset($this->members[$index]) || ! in_array($requirement, ['erforderlich', 'ergaenzend'], true)) {
return;
}
$this->members[$index]['requirement'] = $requirement;
}
/**
* Angebotene Varianten der eingebundenen Übungsfassung. Ohne Auswahl werden alle angeboten.
*/
public function toggleVariantSelection(int $index, string $key): void
{
if (! isset($this->members[$index])) {
return;
}
$all = array_column($this->offeredVariants((string) ($this->members[$index]['target'] ?? '')), 'key');
$current = $this->members[$index]['selection'] ?? null;
$current = is_array($current) ? $current : $all;
$current = in_array($key, $current, true) ? array_values(array_diff($current, [$key])) : [...$current, $key];
if ($current === []) {
$this->feedback = 'Mindestens eine Variante muss angeboten werden.';
return;
}
$this->members[$index]['selection'] = count($current) === count($all) ? null : array_values($current);
}
/**
* @return list<array{key: string, name: string}>
*/
public function offeredVariants(string $target): array
{
if (preg_match('/^composition:(\d+)$/', $target, $match) !== 1) {
return [];
}
return CompositionVersion::query()->find((int) $match[1])?->variants
->map(fn ($variant): array => ['key' => $variant->key, 'name' => $variant->name])
->all() ?? [];
}
/**
* @param array<string, mixed> $member
* @return array{variant: string|null, requirement: string, selection: list<string>|null}
*/
private function memberExtras(array $member): array
{
$selection = $member['selection'] ?? null;
return [
'variant' => isset($member['variant']) && $member['variant'] !== '' ? (string) $member['variant'] : null,
'requirement' => ($member['requirement'] ?? 'erforderlich') === 'ergaenzend' ? 'ergaenzend' : 'erforderlich',
'selection' => is_array($selection) && $selection !== [] ? array_values(array_map('strval', $selection)) : null,
];
}
/**
* @return list<array{key: string, name: string, description: string}>
*/
private function normalizeVariants(mixed $variants): array
{
$result = [];
foreach (is_array($variants) ? $variants : [] as $variant) {
if (is_array($variant) && trim((string) ($variant['key'] ?? '')) !== '') {
$result[] = [
'key' => trim((string) $variant['key']),
'name' => trim((string) ($variant['name'] ?? '')),
'description' => trim((string) ($variant['description'] ?? '')),
];
}
}
return $result;
}
/**
* Rückfallschutz: Enthält dieser Aufbau (in einer Fassung oder im Entwurf) einen Bestandteil, den dieser Programmstand
* nicht kennt, bleibt er schreibgeschützt. Der Editor könnte den Bestandteil sonst nicht laden und würde ihn beim
@@ -969,7 +1111,7 @@ private function includePart(string $target, bool $allowDraft): bool
return false;
}
foreach ($this->members as $index => $member) {
foreach ($this->isExercise() ? [] : $this->members as $index => $member) {
if (($member['target'] ?? '') === $target) {
$this->selected = $index;
$this->panel = 'bestandteil';
@@ -989,6 +1131,7 @@ private function includePart(string $target, bool $allowDraft): bool
$row['role'] = app(EditorialCatalog::class)->defaultRole((string) $row['kind']);
$row['note'] = '';
$row = [...$row, ...$this->memberExtras([])];
$this->members[] = $row;
$this->members = array_values($this->members);
$this->selected = array_key_last($this->members);
@@ -1079,6 +1222,7 @@ public function useVersion(int $index, string $target): void
$this->commitRoleDraft();
$row['role'] = $this->members[$index]['role'] ?? $row['kind'];
$row['note'] = $this->members[$index]['note'] ?? '';
$row = [...$row, ...$this->memberExtras($this->members[$index])];
$this->members[$index] = $row;
$this->syncRoleDraft();
$this->feedback = $row['version_label'].' ist für diese Stelle ausgewählt. Der Entwurf speichert das. Eine freigegebene Fassung bleibt unverändert.';
@@ -1611,9 +1755,12 @@ public function publishRevision(): bool
[
'learning_goal' => $this->blank($this->learningGoal),
'duration_minutes' => $minutes,
'duration_max' => $this->blank($this->durationMax),
'material_note' => $this->blank($this->materialNote),
'prerequisites' => $this->blank($this->prerequisites),
],
$this->releaseConsent,
$this->normalizeVariants($this->variants),
);
} catch (DomainRuleException $exception) {
$this->feedback = $exception->getMessage();
@@ -1730,7 +1877,8 @@ protected function loadAufbau(): void
$this->imageCaptionText = $this->captionFor($composition->thumbnail_source);
$this->catalogScope = match ($this->hostKind()) {
CompositionKind::Kurs => 'module',
CompositionKind::Uebung => 'medien',
CompositionKind::Uebung => 'uebungen',
CompositionKind::Exercise => 'medien',
default => 'alles',
};
@@ -1744,6 +1892,9 @@ protected function loadAufbau(): void
if ($version === null) {
$this->members = [];
$this->variants = [];
$this->durationMax = '';
$this->prerequisites = '';
$this->learningGoal = '';
$this->durationMinutes = '';
$this->materialNote = '';
@@ -1777,10 +1928,14 @@ protected function applyDraft(array $draft): void
$row['role'] = (string) ($member['role'] ?? $row['kind']);
$row['note'] = trim((string) ($member['note'] ?? ''));
$row = [...$row, ...$this->memberExtras($member)];
$rows[] = $row;
}
$this->members = $rows;
$this->variants = $this->normalizeVariants($draft['variants'] ?? []);
$this->durationMax = ($draft['duration_max'] ?? null) === null ? '' : (string) $draft['duration_max'];
$this->prerequisites = (string) ($draft['prerequisites'] ?? '');
$this->learningGoal = (string) ($draft['learning_goal'] ?? '');
$this->durationMinutes = ($draft['duration_minutes'] ?? null) === null ? '' : (string) $draft['duration_minutes'];
$this->materialNote = (string) ($draft['material_note'] ?? '');
@@ -1798,6 +1953,11 @@ protected function applyDraft(array $draft): void
protected function applyVersion(CompositionVersion $version): void
{
$this->members = app(EditorialCatalog::class)->rows($version, (int) $this->getRecord()->getKey());
$this->variants = $this->normalizeVariants($version->variants->map(fn ($variant): array => [
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description,
])->all());
$this->durationMax = $version->duration_max === null ? '' : (string) $version->duration_max;
$this->prerequisites = (string) ($version->prerequisites ?? '');
$this->learningGoal = (string) ($version->learning_goal ?? '');
$this->durationMinutes = $version->duration_minutes === null ? '' : (string) $version->duration_minutes;
$this->materialNote = (string) ($version->material_note ?? '');
@@ -1884,18 +2044,21 @@ protected function needsRevision(): bool
protected function sameMembers(CompositionVersion $version): bool
{
$version->loadMissing('members');
$version->loadMissing('members.variant');
$current = $version->members->map(function ($member): string {
$target = $member->content_element_version_id
? 'element:'.$member->content_element_version_id
: 'composition:'.$member->nested_composition_version_id;
return $member->role.'|'.$target.'|'.trim((string) ($member->placement_note ?? ''));
return $member->role.'|'.$target.'|'.trim((string) ($member->placement_note ?? ''))
.'|'.($member->variant?->key ?? '').'|'.($member->requirement ?: 'erforderlich').'|'.json_encode($member->variant_selection);
})->all();
$next = array_values(array_map(
fn (array $member): string => trim((string) ($member['role'] ?? '')).'|'.($member['target'] ?? '').'|'.trim((string) ($member['note'] ?? '')),
$this->members,
));
$next = array_values(array_map(function (array $member): string {
$extras = $this->memberExtras($member);
return trim((string) ($member['role'] ?? '')).'|'.($member['target'] ?? '').'|'.trim((string) ($member['note'] ?? ''))
.'|'.($extras['variant'] ?? '').'|'.$extras['requirement'].'|'.json_encode($extras['selection']);
}, $this->members));
return $current === $next;
}
@@ -1910,8 +2073,15 @@ protected function didacticChanged(CompositionVersion $version): bool
$storedMinutes = $version->duration_minutes === null ? null : (int) $version->duration_minutes;
$storedVariants = $this->normalizeVariants($version->variants->map(fn ($variant): array => [
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description,
])->all());
return $version->learning_goal !== $this->blank($this->learningGoal)
|| $version->material_note !== $this->blank($this->materialNote)
|| $version->prerequisites !== $this->blank($this->prerequisites)
|| ($version->duration_max === null ? null : (string) $version->duration_max) !== $this->blank($this->durationMax)
|| $storedVariants !== $this->normalizeVariants($this->variants)
|| $storedMinutes !== $minutes;
}
@@ -2122,12 +2292,16 @@ protected function payload(): array
'learning_goal' => $this->blank($this->learningGoal),
'duration_minutes' => $minutes === false ? $this->durationMinutes : $minutes,
'material_note' => $this->blank($this->materialNote),
'duration_max' => $this->blank($this->durationMax),
'prerequisites' => $this->blank($this->prerequisites),
'variants' => $this->normalizeVariants($this->variants),
'revision_note' => $this->blank($this->revisionNote),
'members' => array_values(array_map(
fn (array $member): array => [
'role' => trim((string) ($member['role'] ?? '')),
'target' => (string) ($member['target'] ?? ''),
'note' => trim((string) ($member['note'] ?? '')),
...$this->memberExtras($member),
],
$members,
)),
@@ -2162,6 +2336,9 @@ protected function readyPayload(): array
'learning_goal' => null,
'duration_minutes' => null,
'material_note' => null,
'duration_max' => null,
'prerequisites' => null,
'variants' => [],
'revision_note' => null,
'members' => [],
];
@@ -2173,12 +2350,18 @@ protected function readyPayload(): array
'learning_goal' => $version->learning_goal,
'duration_minutes' => $version->duration_minutes === null ? null : (int) $version->duration_minutes,
'material_note' => $version->material_note,
'duration_max' => $version->duration_max === null ? null : (string) $version->duration_max,
'prerequisites' => $version->prerequisites,
'variants' => $this->normalizeVariants($version->variants->map(fn ($variant): array => [
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description,
])->all()),
'revision_note' => null,
'members' => array_values(array_map(
fn (array $row): array => [
'role' => trim((string) ($row['role'] ?? '')),
'target' => (string) ($row['target'] ?? ''),
'note' => trim((string) ($row['note'] ?? '')),
...$this->memberExtras($row),
],
$rows,
)),
@@ -2202,6 +2385,7 @@ protected function normalizePayload(array $payload): array
'role' => trim((string) ($member['role'] ?? '')),
'target' => (string) ($member['target'] ?? ''),
'note' => trim((string) ($member['note'] ?? '')),
...$this->memberExtras($member),
];
}
@@ -2209,6 +2393,9 @@ protected function normalizePayload(array $payload): array
'learning_goal' => $payload['learning_goal'] ?? null,
'duration_minutes' => $payload['duration_minutes'] ?? null,
'material_note' => $payload['material_note'] ?? null,
'duration_max' => isset($payload['duration_max']) && $payload['duration_max'] !== '' ? (string) $payload['duration_max'] : null,
'prerequisites' => $payload['prerequisites'] ?? null,
'variants' => $this->normalizeVariants($payload['variants'] ?? []),
'revision_note' => $payload['revision_note'] ?? null,
'members' => $members,
];