From bbee288e69032a5d04bb337a2540399555423ad4 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 23 Nov 2026 17:03:32 +0100 Subject: [PATCH] =?UTF-8?q?Pflege=20=C3=9Cbungen=20im=20Aufbauarbeitsplatz?= =?UTF-8?q?=20und=20weise=20Verwendung=20und=20Sperrfolgen=20nach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/Domain/Catalog/CompositionRelease.php | 15 +- app/Domain/Catalog/ExerciseUsage.php | 106 +++++++++ app/Domain/Catalog/OfferCoverage.php | 21 ++ app/Domain/Catalog/OfferService.php | 6 + .../Compositions/Pages/EditComposition.php | 203 +++++++++++++++++- .../Pages/ListCompositionKind.php | 4 +- .../Practices/Pages/EditPractice.php | 11 + .../Practices/Pages/ListPractices.php | 17 ++ .../Resources/Practices/PracticeResource.php | 38 ++++ app/Filament/Support/CatalogReading.php | 4 +- app/Filament/Support/EditorialCatalog.php | 17 +- app/Filament/Support/ListsCompositions.php | 17 +- .../Controllers/Member/LibraryController.php | 5 +- app/Http/LibraryCatalog.php | 44 +++- .../views/filament/editorial/editor.blade.php | 2 +- .../verwaltung/aufbau-angaben.blade.php | 35 ++- .../filament/verwaltung/aufbau.blade.php | 34 ++- .../rueckfall/RueckfallGegenNeueDatenTest.php | 143 ++++++++++++ scripts/rueckfall/build-daten.php | 84 ++++++++ tests/Feature/UebungAusgabeTest.php | 18 ++ tests/Feature/UebungEditorTest.php | 152 +++++++++++++ tests/Feature/UebungSperreTest.php | 154 +++++++++++++ 22 files changed, 1104 insertions(+), 26 deletions(-) create mode 100644 app/Domain/Catalog/ExerciseUsage.php create mode 100644 app/Filament/Resources/Practices/Pages/EditPractice.php create mode 100644 app/Filament/Resources/Practices/Pages/ListPractices.php create mode 100644 app/Filament/Resources/Practices/PracticeResource.php create mode 100644 scripts/rueckfall/RueckfallGegenNeueDatenTest.php create mode 100644 scripts/rueckfall/build-daten.php create mode 100644 tests/Feature/UebungEditorTest.php create mode 100644 tests/Feature/UebungSperreTest.php diff --git a/app/Domain/Catalog/CompositionRelease.php b/app/Domain/Catalog/CompositionRelease.php index 56527dd..b99d23a 100644 --- a/app/Domain/Catalog/CompositionRelease.php +++ b/app/Domain/Catalog/CompositionRelease.php @@ -54,6 +54,7 @@ public function publish( ?string $note, array $didactic, bool $consent, + array $variants = [], ): CompositionVersion { $review = $this->review($host, $members); @@ -67,8 +68,8 @@ public function publish( $this->publishedDrafts = []; - return DB::transaction(function () use ($host, $members, $actor, $note, $didactic): CompositionVersion { - return $this->materialize($host, $members, $didactic, $actor, $note, []); + return DB::transaction(function () use ($host, $members, $actor, $note, $didactic, $variants): CompositionVersion { + return $this->materialize($host, $members, $didactic, $actor, $note, [], $variants); }); } @@ -330,6 +331,7 @@ private function materialize( ?User $actor, ?string $note, array $stack, + array $variants = [], ): CompositionVersion { if (isset($this->publishedDrafts[$composition->id])) { return $this->publishedDrafts[$composition->id]; @@ -347,6 +349,9 @@ private function materialize( 'role' => trim((string) ($member['role'] ?? '')), 'note' => trim((string) ($member['note'] ?? '')), 'target' => $this->resolveTarget((string) ($member['target'] ?? ''), $actor, $stack), + 'variant' => isset($member['variant']) && $member['variant'] !== '' ? (string) $member['variant'] : null, + 'requirement' => $member['requirement'] ?? 'erforderlich', + 'selection' => is_array($member['selection'] ?? null) && $member['selection'] !== [] ? array_values($member['selection']) : null, ]; } @@ -358,8 +363,11 @@ private function materialize( [ 'learning_goal' => $didactic['learning_goal'] ?? null, 'duration_minutes' => $didactic['duration_minutes'] ?? null, + 'duration_max' => $didactic['duration_max'] ?? null, 'material_note' => $didactic['material_note'] ?? null, + 'prerequisites' => $didactic['prerequisites'] ?? null, ], + $variants, ); $this->publishedDrafts[$composition->id] = $version; @@ -420,11 +428,14 @@ private function resolveTarget(string $target, ?User $actor, array $stack): Cont [ 'learning_goal' => $draft['learning_goal'] ?? null, 'duration_minutes' => $draft['duration_minutes'] ?? null, + 'duration_max' => $draft['duration_max'] ?? null, 'material_note' => $draft['material_note'] ?? null, + 'prerequisites' => $draft['prerequisites'] ?? null, ], $actor, is_string($draft['revision_note'] ?? null) ? $draft['revision_note'] : null, $stack, + is_array($draft['variants'] ?? null) ? $draft['variants'] : [], ); app(EditorialWorkingDraft::class)->clear($composition); diff --git a/app/Domain/Catalog/ExerciseUsage.php b/app/Domain/Catalog/ExerciseUsage.php new file mode 100644 index 0000000..a948f2a --- /dev/null +++ b/app/Domain/Catalog/ExerciseUsage.php @@ -0,0 +1,106 @@ +>, releases: list>}> + */ + public function forComposition(Composition $composition): array + { + $guide = app(ExerciseGuide::class); + $result = []; + + foreach ($composition->versions()->orderBy('number')->get() as $version) { + $hosts = []; + $roots = [$version->id => $version]; + $queue = [$version->id]; + $seen = [$version->id]; + + while ($queue !== []) { + $current = array_shift($queue); + + foreach (CompositionMember::query()->where('nested_composition_version_id', $current)->with('compositionVersion.composition')->orderBy('id')->get() as $member) { + $host = $member->compositionVersion; + + if ($host === null || $host->composition === null) { + continue; + } + + $hosts[] = [ + 'composition' => $host->composition, + 'version' => $host, + 'role' => $member->role, + 'position' => $member->position, + 'selection' => $member->variant_selection, + 'direct' => $current === $version->id, + ]; + + if (! in_array($host->id, $seen, true)) { + $seen[] = $host->id; + $roots[$host->id] = $host; + $queue[] = $host->id; + } + } + } + + $releases = []; + + foreach (ArticleRelease::query()->whereIn('root_composition_version_id', array_keys($roots))->with('article')->orderBy('license_article_id')->orderBy('number')->get() as $release) { + $root = $roots[$release->root_composition_version_id]; + $releases[] = [ + 'article' => $release->article, + 'release' => $release, + 'status' => $release->status, + 'path' => $root->id === $version->id ? null : $guide->pathTo($root, $version->id), + 'root' => $root, + ]; + } + + $result[] = ['version' => $version, 'hosts' => $hosts, 'releases' => $releases]; + } + + return $result; + } + + /** + * Folgen einer Sperre dieser Medienfassung je Artikel-Stand. Die Festschreibung bleibt unverändert; gesperrt wird + * nur die Ausgabe des Mediums. + * + * @return list + */ + public function blockImpact(ContentElementVersion $version): array + { + $impact = []; + + foreach (ReleaseContent::query()->where('content_element_version_id', $version->id)->with('release.article')->orderBy('id')->get() as $content) { + $release = $content->release; + $required = ($content->requirement ?? CompositionMember::REQUIRED) === CompositionMember::REQUIRED; + $effect = match (true) { + ! $required => 'Nur dieses ergänzende Medium entfällt. Die Übung bleibt vollständig durchführbar.', + $content->variant_key !== null => 'Die Variante „'.$content->variant_key.'“ ist nicht mehr vollständig durchführbar. Andere Varianten bleiben nutzbar.', + default => 'Ein erforderlicher Bestandteil entfällt. Die Anleitung bleibt lesbar.', + }; + $impact[] = [ + 'article' => $release->article, + 'release' => $release, + 'status' => $release->status, + 'variant' => $content->variant_key, + 'requirement' => $content->requirement, + 'path' => $content->path, + 'effect' => $effect, + ]; + } + + return $impact; + } +} diff --git a/app/Domain/Catalog/OfferCoverage.php b/app/Domain/Catalog/OfferCoverage.php index 6711c6e..368a8f7 100644 --- a/app/Domain/Catalog/OfferCoverage.php +++ b/app/Domain/Catalog/OfferCoverage.php @@ -6,6 +6,27 @@ class OfferCoverage { public function __construct(private readonly ContentResolver $resolver) {} + /** + * Bestandteile der Fassung, deren Medienfassung gesperrt ist. Ein Angebot soll nicht aktiviert werden, solange sein + * Umfang gesperrte Bestandteile enthält; die Prüfung nennt sie vorab. + * + * @return list + */ + public function blockedLeaves(CompositionVersion $version): array + { + $rows = $this->resolver->expand($version); + $blocked = ContentElementVersion::query() + ->whereIn('id', array_column($rows, 'version_id')) + ->where('status', ContentVersionStatus::Gesperrt->value) + ->pluck('id') + ->all(); + + return array_values(array_map( + fn (array $row): string => $row['path'], + array_filter($rows, fn (array $row): bool => in_array($row['version_id'], $blocked, true)), + )); + } + /** * @param list $articles * @return list diff --git a/app/Domain/Catalog/OfferService.php b/app/Domain/Catalog/OfferService.php index f2d4680..f584529 100644 --- a/app/Domain/Catalog/OfferService.php +++ b/app/Domain/Catalog/OfferService.php @@ -289,6 +289,12 @@ private function assertCoverage(array $lines, array $attributes): void } } + $blocked = app(OfferCoverage::class)->blockedLeaves($version); + + if ($blocked !== []) { + throw new DomainRuleException('Das Angebot enthält gesperrte Bestandteile: '.implode(', ', $blocked)); + } + $missing = app(OfferCoverage::class)->missingLeaves($version, $articles); if ($missing !== []) { diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index cf943d1..e393746 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -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 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 + */ + 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 $member + * @return array{variant: string|null, requirement: string, selection: list|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 + */ + 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, ]; diff --git a/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php b/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php index 6bb179e..8017dbf 100644 --- a/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php +++ b/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php @@ -33,12 +33,12 @@ protected function fixedKind(): ?CompositionKind private function onDesk(): bool { - return in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung], true); + return in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung, CompositionKind::Exercise], true); } public function getSubheading(): string|Htmlable|null { - $desk = $this->onDesk() ? ' Programme und Module stehen gemeinsam auch auf dem Arbeitsplatz.' : ''; + $desk = $this->onDesk() && $this->kind() !== CompositionKind::Exercise ? ' Programme und Module stehen gemeinsam auch auf dem Arbeitsplatz.' : ''; return $this->kind()->deskExplanation().$desk; } diff --git a/app/Filament/Resources/Practices/Pages/EditPractice.php b/app/Filament/Resources/Practices/Pages/EditPractice.php new file mode 100644 index 0000000..d1fda47 --- /dev/null +++ b/app/Filament/Resources/Practices/Pages/EditPractice.php @@ -0,0 +1,11 @@ + ListPractices::route('/'), + 'edit' => EditPractice::route('/{record}'), + ]; + } +} diff --git a/app/Filament/Support/CatalogReading.php b/app/Filament/Support/CatalogReading.php index b6084ed..75cfdcf 100644 --- a/app/Filament/Support/CatalogReading.php +++ b/app/Filament/Support/CatalogReading.php @@ -280,7 +280,9 @@ public function elementUsage(ContentElement $element): array foreach ($contents as $content) { $lines[] = 'Lizenzartikel '.$content->release->article->code .' · Stand '.$content->release->number - .' · '.$content->path; + .' · '.$content->path + .($content->variant_key !== null ? ' · Variante '.$content->variant_key : '') + .($content->requirement === CompositionMember::SUPPLEMENTARY ? ' · ergänzend' : ''); } return $lines === [] diff --git a/app/Filament/Support/EditorialCatalog.php b/app/Filament/Support/EditorialCatalog.php index bfa401c..393432c 100644 --- a/app/Filament/Support/EditorialCatalog.php +++ b/app/Filament/Support/EditorialCatalog.php @@ -21,6 +21,7 @@ use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Resources\Courses\CourseResource; use App\Filament\Resources\Exercises\ExerciseResource; +use App\Filament\Resources\Practices\PracticeResource; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; @@ -33,6 +34,7 @@ class EditorialCatalog public function rows(CompositionVersion $version, int $exceptCompositionId): array { $version->loadMissing([ + 'members.variant', 'members.contentElementVersion.element.editorialContentKind', 'members.nestedCompositionVersion.composition.editorialContentKind', ]); @@ -50,6 +52,9 @@ public function rows(CompositionVersion $version, int $exceptCompositionId): arr $row['role'] = $member->role; $row['note'] = trim((string) ($member->placement_note ?? '')); + $row['variant'] = $member->variant?->key; + $row['requirement'] = $member->requirement ?: 'erforderlich'; + $row['selection'] = is_array($member->variant_selection) ? $member->variant_selection : null; $rows[] = $row; } @@ -244,7 +249,11 @@ public function search(string $query, string $scope, int $exceptCompositionId): ->with('composition.editorialContentKind') ->whereHas('composition', function ($builder) use ($scope, $query, $like): void { if ($scope === 'module') { - $builder->where('kind', CompositionKind::Uebung); + $builder->whereIn('kind', [CompositionKind::Uebung, CompositionKind::Exercise]); + } + + if ($scope === 'uebungen') { + $builder->where('kind', CompositionKind::Exercise); } if ($query === '') { @@ -317,7 +326,7 @@ public function browse(string $query, string $kind, string $dimension, int $exce ->where('composition_id', '!=', $exceptCompositionId) ->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId, $pillarId): void { if ($kind === 'modul') { - $builder->where('kind', CompositionKind::Uebung); + $builder->whereIn('kind', [CompositionKind::Uebung, CompositionKind::Exercise]); } if ($dimensionId > 0) { @@ -363,7 +372,7 @@ public function browse(string $query, string $kind, string $dimension, int $exce $builder->where('status', ContentVersionStatus::Bereit); }) ->when($kind === 'modul', function ($builder): void { - $builder->where('kind', CompositionKind::Uebung); + $builder->whereIn('kind', [CompositionKind::Uebung, CompositionKind::Exercise]); }) ->orderByDesc('id') ->get(); @@ -1073,6 +1082,7 @@ public function create(string $designation, CompositionKind $kind): Composition $slug = match ($kind) { CompositionKind::Kurs => 'programm', CompositionKind::Uebung => 'modul', + CompositionKind::Exercise => 'uebung', default => null, }; $editorial = $slug === null ? null : EditorialContentKind::query()->where('slug', $slug)->first(); @@ -1094,6 +1104,7 @@ public static function editUrl(Composition $composition): string CompositionKind::Kurs => CourseResource::class, CompositionKind::Kombination => CombinationResource::class, CompositionKind::Uebung => ExerciseResource::class, + CompositionKind::Exercise => PracticeResource::class, }; return $resource::getUrl('edit', ['record' => $composition]); diff --git a/app/Filament/Support/ListsCompositions.php b/app/Filament/Support/ListsCompositions.php index 54fb114..b4207ec 100644 --- a/app/Filament/Support/ListsCompositions.php +++ b/app/Filament/Support/ListsCompositions.php @@ -74,6 +74,7 @@ public function bestand(): array $einheit = match ($fixed) { CompositionKind::Kurs => ['Programm', 'Programme'], CompositionKind::Uebung => ['Modul', 'Module'], + CompositionKind::Exercise => ['Übung', 'Übungen'], CompositionKind::Kombination => ['Fachliche Kombination', 'Fachliche Kombinationen'], default => ['Programm oder Modul', 'Programme und Module'], }; @@ -188,7 +189,7 @@ public function entries(): array $rows[] = [ 'schluessel' => 'c'.$composition->id, 'titel' => $title, - 'meta' => $kind->deskLabel().($title !== $composition->designation ? ' · '.$composition->designation : ''), + 'meta' => $kind->deskLabel().($title !== $composition->designation ? ' · '.$composition->designation : '').($kind === CompositionKind::Exercise ? ' · Herkunft: lokal' : ''), 'text' => $summary, 'bild' => $cover['url'], 'bildFehlt' => 'Kein Titelbild', @@ -219,11 +220,19 @@ public function entries(): array */ protected function createCompositionAction(CompositionKind $kind): Action { - $label = $kind === CompositionKind::Kurs ? 'Programm' : 'Modul'; + $label = match ($kind) { + CompositionKind::Kurs => 'Programm', + CompositionKind::Exercise => 'Übung', + default => 'Modul', + }; - return Action::make($kind === CompositionKind::Kurs ? 'createProgram' : 'createModule') + return Action::make(match ($kind) { + CompositionKind::Kurs => 'createProgram', + CompositionKind::Exercise => 'createExercise', + default => 'createModule', + }) ->label($label.' anlegen') - ->modalHeading('Neues '.$label) + ->modalHeading(($kind === CompositionKind::Exercise ? 'Neue ' : 'Neues ').$label) ->modalDescription('Der Name genügt. Danach öffnet sich der Aufbau; Texte, Bilder und Einordnung folgen dort und in der Redaktion.') ->modalSubmitActionLabel($label.' anlegen') ->modalWidth('lg') diff --git a/app/Http/Controllers/Member/LibraryController.php b/app/Http/Controllers/Member/LibraryController.php index c8754fd..1de6b95 100644 --- a/app/Http/Controllers/Member/LibraryController.php +++ b/app/Http/Controllers/Member/LibraryController.php @@ -6,6 +6,7 @@ use App\Domain\Catalog\Composition; use App\Domain\Catalog\ContentElement; use App\Domain\Catalog\ContentElementVersion; +use App\Domain\Catalog\ContentVersionStatus; use App\Domain\Catalog\EditorialVocabulary; use App\Domain\Catalog\IdentityDimension; use App\Domain\Catalog\LicenseArticle; @@ -501,8 +502,10 @@ private function maySeeThumbnail(Request $request, string $kind, int $subject): return true; } + // Ein gesperrtes Medium zeigt auch kein Vorschaubild mehr (Sperre gilt für Ausgaben und Ableitungen). if ($kind === 'element' && $release->contents->contains( - fn ($content): bool => $content->elementVersion?->content_element_id === $subject, + fn ($content): bool => $content->elementVersion?->content_element_id === $subject + && $content->elementVersion->status !== ContentVersionStatus::Gesperrt, )) { return true; } diff --git a/app/Http/LibraryCatalog.php b/app/Http/LibraryCatalog.php index f3d2539..d715389 100644 --- a/app/Http/LibraryCatalog.php +++ b/app/Http/LibraryCatalog.php @@ -5,11 +5,13 @@ use App\Domain\Catalog\ArticleRelease; use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionDisplayRelease; +use App\Domain\Catalog\CompositionKind; use App\Domain\Catalog\CompositionStructureReader; use App\Domain\Catalog\CompositionVersion; use App\Domain\Catalog\ContentElement; use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\EditorialProfileReader; +use App\Domain\Catalog\ExerciseGuide; use App\Domain\Catalog\ReleaseStatus; use App\Domain\Catalog\StructureNode; use App\Domain\Entitlement\DecideAccess; @@ -389,7 +391,7 @@ private function present(User $user, StructureNode $node, bool $full, int $rootI 'view_url' => $view, 'poster_url' => $poster, 'download_url' => $download, - 'program_url' => $this->programUrl($node), + 'program_url' => $this->exerciseUrl($user, $rootId, $node) ?? $this->programUrl($node), 'composition_id' => $node->compositionId, 'element_id' => $node->contentElementId, 'version_id' => $node->contentElementVersionId, @@ -491,6 +493,46 @@ private function element(int $id): ?ContentElement return $this->elements[$id]; } + /** + * Eine Übung im Zusammenhang des erworbenen Moduls oder Programms: die im Stand gebundene Fassung und ihre Varianten, + * nicht die jeweils neueste Fassung der Übung. Gefunden wird der jüngste auslieferbare Stand des Kontos, dessen + * festgeschriebene Wurzel diese Fassung an einer Stelle einbindet. + */ + private function exerciseUrl(User $user, int $rootId, StructureNode $node): ?string + { + if ($node->compositionVersionId === null) { + return null; + } + + $nested = CompositionVersion::query()->with('composition')->find($node->compositionVersionId); + + if ($nested?->composition?->kind !== CompositionKind::Exercise) { + return null; + } + + $guide = app(ExerciseGuide::class); + + foreach ($this->grants($user) as $grant) { + $releases = ArticleRelease::query() + ->where('license_article_id', $grant->license_article_id) + ->whereIn('status', [ReleaseStatus::Veroeffentlicht, ReleaseStatus::AbgeloestVerfuegbar]) + ->whereHas('rootCompositionVersion', fn ($query) => $query->where('composition_id', $rootId)) + ->with('rootCompositionVersion') + ->orderByDesc('number') + ->get(); + + foreach ($releases as $release) { + $path = $guide->pathTo($release->rootCompositionVersion, $nested->id); + + if ($path !== null) { + return route('member.exercise', ['article' => $grant->license_article_id, 'release' => $release->id, 'path' => $path]); + } + } + } + + return null; + } + private function programUrl(StructureNode $node): ?string { if ($node->compositionId === null || $node->compositionVersionId === null) { diff --git a/resources/views/filament/editorial/editor.blade.php b/resources/views/filament/editorial/editor.blade.php index 6d80dbc..e4502ba 100644 --- a/resources/views/filament/editorial/editor.blade.php +++ b/resources/views/filament/editorial/editor.blade.php @@ -30,7 +30,7 @@
@include('filament.verwaltung.kopf', [ 'zurueck' => ['label' => 'Zum Arbeitsplatz', 'href' => \App\Filament\Pages\EditorialDesk::getUrl()], - 'brot' => [['label' => $this->isProgram() ? 'Programme' : 'Module', 'href' => $this::getResource()::getUrl('index')], $titel], + 'brot' => [['label' => $this->hostKind()->plural() === 'Kurse' ? 'Programme' : $this->hostKind()->plural(), 'href' => $this::getResource()::getUrl('index')], $titel], 'titel' => $titel, 'typ' => $this->hostLabel().' · '.$typ, 'status' => [ diff --git a/resources/views/filament/verwaltung/aufbau-angaben.blade.php b/resources/views/filament/verwaltung/aufbau-angaben.blade.php index a5bd9b8..bd371d7 100644 --- a/resources/views/filament/verwaltung/aufbau-angaben.blade.php +++ b/resources/views/filament/verwaltung/aufbau-angaben.blade.php @@ -2,7 +2,7 @@ @php $cover = $this->coverPicture(); $filme = $this->frameFilms(); - $ort = $this->isProgram() ? 'dieses Programms' : 'dieses Moduls'; + $ort = $this->isProgram() ? 'dieses Programms' : ($this->isExercise() ? 'dieser Übung' : 'dieses Moduls'); @endphp
@@ -19,9 +19,40 @@
-