diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index 2c968e9..f00ab91 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -2,17 +2,24 @@ namespace App\Filament\Resources\Compositions\Pages; +use App\Domain\Catalog\ArticleRelease; use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionDisplayRelease; use App\Domain\Catalog\CompositionKind; use App\Domain\Catalog\CompositionMember; +use App\Domain\Catalog\CompositionStructureReader; use App\Domain\Catalog\CompositionVersion; use App\Domain\Catalog\ContentElementVersion; 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\EditorialDimensionValue; +use App\Domain\Catalog\IdentityDimension; +use App\Domain\Catalog\IdentityDimensionValue; use App\Domain\Catalog\IdentityProfile; +use App\Domain\Catalog\StructureNode; use App\Filament\Resources\Combinations\CombinationResource; use App\Filament\Resources\Courses\CourseResource; use App\Filament\Resources\Exercises\ExerciseResource; @@ -21,6 +28,8 @@ use App\Models\User; use Filament\Actions\Action; use Filament\Facades\Filament; +use Filament\Forms\Components\CheckboxList; +use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Placeholder; use Filament\Forms\Components\Repeater; use Filament\Forms\Components\Select; @@ -50,6 +59,12 @@ public function form(Schema $schema): Schema TextInput::make('display_title')->label('Anzeigetitel') ->helperText('Erscheint in der Bibliothek. Leer lässt die Bezeichnung stehen.'), Textarea::make('summary')->label('Kurzbeschreibung')->rows(3), + Textarea::make('learning_goal')->label('Lernziel')->rows(2) + ->helperText('Gehört zur Fassung. Eine Änderung legt eine neue Fassung an.'), + TextInput::make('duration_minutes')->label('Zeitbedarf in Minuten')->numeric()->minValue(1), + Textarea::make('material_note')->label('Materialbedarf')->rows(2), + Placeholder::make('status')->label('Stand')->content(fn (): HtmlString => new HtmlString(e($this->statusText()))), + Placeholder::make('outline')->label('Gliederung der aktuellen Fassung')->content(fn (): HtmlString => new HtmlString($this->outlineHtml())), Select::make('kind')->label('Art')->options(CompositionKind::options())->required() ->helperText('Übung, Kurs und fachliche Kombination sind verschiedene Zusammenstellungen. Die Art lässt sich hier ändern.'), Select::make('editorial_content_kind_id') @@ -66,11 +81,25 @@ public function form(Schema $schema): Schema ->where('nested_composition_version_id', $version->id) ->with('compositionVersion.composition') ->get() - ->map(fn (CompositionMember $member): string => ($member->compositionVersion->composition->designation ?? 'Programm').' · '.$member->role) + ->map(fn (CompositionMember $member): string => ($member->compositionVersion->composition->designation ?? 'Programm').', Rolle '.$member->role) ->all(); + $articles = ArticleRelease::query() + ->where('root_composition_version_id', $version->id) + ->with('article') + ->get() + ->map(fn (ArticleRelease $release): string => 'Lizenzartikel '.$release->article->code.', Stand '.$release->number) + ->all(); + $lines = [...$lines, ...$articles]; - return new HtmlString($lines === [] ? 'In keiner anderen Fassung enthalten.' : e(implode(' · ', $lines))); + return new HtmlString($lines === [] ? 'In keinem anderen Programm und in keinem Lizenzartikel.' : implode('
', array_map(e(...), $lines))); }), + CheckboxList::make('dimension_ids')->label('Fachliche Einordnung') + ->options(fn (): array => self::dimensionOptions()) + ->columns(1) + ->helperText('Wirkt auf die Suche in der Bibliothek und legt keine neue Fassung an.'), + FileUpload::make('thumbnail_upload')->label('Vorschaubild') + ->disk('cms_incoming')->directory('vorschau')->visibility('private')->image() + ->helperText('Ersetzt nur das Bild der Karte. Die Fassung und die Dateien bleiben unverändert.'), Placeholder::make('history')->label('Aktuelle Fassung')->content(function (): HtmlString { /** @var Composition $composition */ $composition = $this->getRecord(); @@ -89,8 +118,9 @@ public function form(Schema $schema): Schema ->label('Bausteine der neuen Fassung') ->schema([ TextInput::make('role')->label('Rolle')->placeholder('Film, Merkblatt, Übung')->required(), - Select::make('target')->label('Fassung')->required()->searchable() - ->options(fn (): array => CatalogOptions::assignmentTargets($this->getRecord()->getKey())), + Select::make('target')->label('Vorhandener Inhalt')->required()->searchable() + ->options(fn (): array => CatalogOptions::assignmentTargets($this->getRecord()->getKey())) + ->helperText('Titel, Inhaltsart und Fassungsnummer. Es wird genau diese Fassung verwendet.'), ]) ->minItems(1) ->reorderable() @@ -177,6 +207,15 @@ protected function mutateFormDataBeforeFill(array $data): array 'summary' => $composition->summary, 'kind' => $kind instanceof CompositionKind ? $kind->value : $kind, 'editorial_content_kind_id' => $composition->editorial_content_kind_id, + 'learning_goal' => $version?->learning_goal, + 'duration_minutes' => $version?->duration_minutes, + 'material_note' => $version?->material_note, + 'dimension_ids' => IdentityDimensionValue::query() + ->where('subject_type', $composition->getMorphClass()) + ->where('subject_id', $composition->id) + ->where('origin', 'direkt') + ->pluck('editorial_dimension_value_id') + ->all(), 'members' => $members, 'note' => null, ]; @@ -196,10 +235,20 @@ protected function handleRecordUpdate(Model $record, array $data): Model 'summary' => $data['summary'] ?? null, ], auth()->user()); $record->kind = $kind; - $record->editorial_content_kind_id = filled($data['editorial_content_kind_id'] ?? null) - ? (int) $data['editorial_content_kind_id'] - : null; + if (array_key_exists('editorial_content_kind_id', $data)) { + $record->editorial_content_kind_id = filled($data['editorial_content_kind_id'] ?? null) + ? (int) $data['editorial_content_kind_id'] + : null; + } + if (is_string($data['thumbnail_upload'] ?? null) && $data['thumbnail_upload'] !== '') { + $record->thumbnail_path = $data['thumbnail_upload']; + $record->thumbnail_error = null; + $record->thumbnail_alt = $record->designation; + } $record->save(); + if (array_key_exists('dimension_ids', $data)) { + $this->syncDimensions($record, array_map(intval(...), $data['dimension_ids'] ?? [])); + } $members = []; @@ -216,14 +265,21 @@ protected function handleRecordUpdate(Model $record, array $data): Model } $note = is_string($data['note'] ?? null) ? trim($data['note']) : ''; + $current = $this->currentReadyVersion(); + $didactic = [ + 'learning_goal' => $this->blankToNull(array_key_exists('learning_goal', $data) ? $data['learning_goal'] : $current?->learning_goal), + 'duration_minutes' => $this->minutes(array_key_exists('duration_minutes', $data) ? $data['duration_minutes'] : $current?->duration_minutes), + 'material_note' => $this->blankToNull(array_key_exists('material_note', $data) ? $data['material_note'] : $current?->material_note), + ]; - if ($note !== '' || ! $this->sameMembers($record, $members)) { + if ($note !== '' || ! $this->sameMembers($record, $members) || $this->didacticChanged($current, $didactic)) { $actor = Filament::auth()->user(); app(ContentService::class)->publishComposition( $record, $members, $actor instanceof User ? $actor : null, $note !== '' ? $note : null, + $didactic, ); $this->savedTitle = 'Die neue Fassung ist veröffentlicht. Die bisherige Fassung bleibt erhalten.'; } else { @@ -303,4 +359,118 @@ private function sameMembers(Composition $composition, array $members): bool return $current === $next; } + + /** + * @param array{learning_goal: mixed, duration_minutes: mixed, material_note: mixed} $didactic + */ + private function didacticChanged(?CompositionVersion $version, array $didactic): bool + { + if ($version === null) { + return true; + } + + $storedMinutes = $version->duration_minutes === null ? null : (int) $version->duration_minutes; + + return $version->learning_goal !== $didactic['learning_goal'] + || $version->material_note !== $didactic['material_note'] + || $storedMinutes !== $didactic['duration_minutes']; + } + + private function minutes(mixed $value): ?int + { + if ($value === null || $value === '') { + return null; + } + + return (int) $value; + } + + private function blankToNull(mixed $value): ?string + { + if (! is_string($value)) { + return null; + } + + $value = trim($value); + + return $value === '' ? null : $value; + } + + /** + * @param list $ids + */ + private function syncDimensions(Composition $composition, array $ids): void + { + IdentityDimensionValue::query() + ->where('subject_type', $composition->getMorphClass()) + ->where('subject_id', $composition->id) + ->where('origin', 'direkt') + ->whereNotIn('editorial_dimension_value_id', $ids === [] ? [0] : $ids) + ->delete(); + + foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) { + app(IdentityDimension::class)->assign($composition, $value, 'direkt'); + } + } + + /** + * @return array + */ + private static function dimensionOptions(): array + { + $options = []; + + foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) { + foreach ($dimension->values as $value) { + $options[$value->id] = $dimension->label.': '.$value->label; + } + } + + return $options; + } + + private function statusText(): string + { + /** @var Composition $composition */ + $composition = $this->getRecord(); + $version = $this->currentReadyVersion(); + + if ($version === null) { + return 'Noch keine technisch bereite Fassung. Speichern legt die erste Fassung an.'; + } + + $released = app(CompositionDisplayRelease::class)->isReleased($version); + $older = $composition->versions()->where('number', '<', $version->number)->orderBy('number')->pluck('number')->all(); + $history = $older === [] ? 'Es gibt keine ältere Fassung.' : 'Ältere Fassungen: '.implode(', ', $older).'.'; + + return 'Fassung '.$version->number.' ist technisch bereit. ' + .($released ? 'Sie ist zur Anzeige freigegeben. ' : 'Sie ist noch nicht zur Anzeige freigegeben. ') + .$history; + } + + private function outlineHtml(): string + { + $version = $this->currentReadyVersion(); + + if ($version === null) { + return 'Die Gliederung erscheint, sobald eine Fassung bereit ist.'; + } + + $lines = []; + $this->outlineLines(app(CompositionStructureReader::class)->tree($version), 0, $lines); + + return $lines === [] ? 'Diese Fassung hat noch keine Bestandteile.' : implode('
', array_map(e(...), $lines)); + } + + /** + * @param list $nodes + * @param list $lines + */ + private function outlineLines(array $nodes, int $depth, array &$lines): void + { + foreach ($nodes as $node) { + $lines[] = str_repeat('– ', $depth).$node->role.': '.$node->title; + $this->outlineLines($node->children, $depth + 1, $lines); + } + } } diff --git a/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php b/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php index afc7d17..4614998 100644 --- a/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php +++ b/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php @@ -4,6 +4,7 @@ use App\Domain\Catalog\CompositionKind; use App\Domain\Catalog\ContentService; +use App\Domain\Catalog\EditorialContentKind; use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; @@ -26,7 +27,11 @@ protected function getHeaderActions(): array { return [ Action::make('create') - ->label($this->kind()->createLabel()) + ->label(match ($this->kind()) { + CompositionKind::Kurs => 'Programm anlegen', + CompositionKind::Uebung => 'Modul anlegen', + default => $this->kind()->createLabel(), + }) ->visible(fn (): bool => ContentElementResource::editor()) ->schema([ TextInput::make('designation')->label('Bezeichnung')->required(), @@ -35,6 +40,16 @@ protected function getHeaderActions(): array $composition = null; $this->report(function () use ($data, &$composition): void { $composition = app(ContentService::class)->createComposition($data['designation'], $this->kind()); + $slug = match ($this->kind()) { + CompositionKind::Kurs => 'programm', + CompositionKind::Uebung => 'modul', + default => null, + }; + $editorial = $slug === null ? null : EditorialContentKind::query()->where('slug', $slug)->first(); + if ($editorial !== null) { + $composition->editorial_content_kind_id = $editorial->id; + $composition->save(); + } }, $this->kind()->label().' ist angelegt.'); if ($composition !== null) { diff --git a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php index 9a0edfa..1040033 100644 --- a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php @@ -2,13 +2,19 @@ namespace App\Filament\Resources\ContentElements\Pages; +use App\Domain\Catalog\Composition; use App\Domain\Catalog\ContentElement; use App\Domain\Catalog\ContentService; use App\Domain\Catalog\DomainRuleException; use App\Domain\Catalog\EditorialContentKind; +use App\Domain\Catalog\EditorialDimension; +use App\Domain\Catalog\EditorialDimensionValue; +use App\Domain\Catalog\IdentityDimension; +use App\Domain\Catalog\IdentityDimensionValue; use App\Domain\Catalog\IdentityProfile; use App\Domain\Catalog\Pillar; use App\Domain\Catalog\PillarService; +use App\Domain\Catalog\ReleaseContent; use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Support\ElementRevision; use App\Filament\Support\MediaUploadLimit; @@ -58,6 +64,43 @@ public function form(Schema $schema): Schema ->options(fn (): array => EditorialContentKind::selectOptions()) ->nullable() ->helperText('Optional für Bibliothek und Website. Ändert weder die Ausgabeart noch eine Fassung.'), + Placeholder::make('usage')->label('Verwendung')->content(function (): HtmlString { + /** @var ContentElement $element */ + $element = $this->getRecord(); + $versionIds = $element->versions()->pluck('id'); + $compositionIds = []; + + foreach ($element->versions as $version) { + $compositionIds = [...$compositionIds, ...app(ContentService::class)->containingCompositionIds($version)]; + } + + $names = Composition::query()->whereIn('id', array_unique($compositionIds))->orderBy('designation')->pluck('designation')->all(); + $articles = ReleaseContent::query() + ->whereIn('content_element_version_id', $versionIds) + ->with('release.article') + ->get() + ->map(fn (ReleaseContent $content): string => 'Lizenzartikel '.($content->release->article->code ?? '')) + ->unique() + ->all(); + $lines = [...array_map(fn (string $name): string => 'Enthalten in '.$name, $names), ...$articles]; + + return new HtmlString($lines === [] ? 'Noch in keinem Modul, Programm oder Lizenzartikel.' : implode('
', array_map(e(...), $lines))); + }), + CheckboxList::make('dimension_ids')->label('Fachliche Einordnung') + ->options(function (): array { + $options = []; + foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) { + foreach ($dimension->values as $value) { + $options[$value->id] = $dimension->label.': '.$value->label; + } + } + + return $options; + }) + ->helperText('Wirkt auf die Suche und legt keine neue Fassung an.'), + FileUpload::make('thumbnail_upload')->label('Vorschaubild') + ->disk('cms_incoming')->directory('vorschau')->visibility('private')->image() + ->helperText('Nur die Karte. Die Inhaltsfassung bleibt unverändert.'), CheckboxList::make('pillars') ->label('Fachliche Säulen') ->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all()) @@ -128,6 +171,13 @@ protected function mutateFormDataBeforeFill(array $data): array 'display_title' => $this->getRecord()->display_title, 'description' => $this->getRecord()->description, 'summary' => $this->getRecord()->summary, + 'editorial_content_kind_id' => $this->getRecord()->editorial_content_kind_id, + 'dimension_ids' => IdentityDimensionValue::query() + ->where('subject_type', $this->getRecord()->getMorphClass()) + ->where('subject_id', $this->getRecord()->id) + ->where('origin', 'direkt') + ->pluck('editorial_dimension_value_id') + ->all(), 'pillars' => $this->getRecord()->pillars()->pluck('pillars.id')->all(), ]; } @@ -144,6 +194,30 @@ protected function handleRecordUpdate(Model $record, array $data): Model 'display_title' => $data['display_title'] ?? null, 'summary' => $data['summary'] ?? null, ], auth()->user()); + if (array_key_exists('editorial_content_kind_id', $data)) { + $record->editorial_content_kind_id = filled($data['editorial_content_kind_id'] ?? null) + ? (int) $data['editorial_content_kind_id'] + : null; + $record->save(); + } + if (is_string($data['thumbnail_upload'] ?? null) && $data['thumbnail_upload'] !== '') { + $record->thumbnail_path = $data['thumbnail_upload']; + $record->thumbnail_error = null; + $record->thumbnail_alt = $record->working_title; + $record->save(); + } + if (array_key_exists('dimension_ids', $data)) { + $ids = array_map(intval(...), $data['dimension_ids'] ?? []); + IdentityDimensionValue::query() + ->where('subject_type', $record->getMorphClass()) + ->where('subject_id', $record->id) + ->where('origin', 'direkt') + ->whereNotIn('editorial_dimension_value_id', $ids === [] ? [0] : $ids) + ->delete(); + foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) { + app(IdentityDimension::class)->assign($record, $value, 'direkt'); + } + } app(PillarService::class)->assign($record, array_map(intval(...), $data['pillars'] ?? [])); } catch (DomainRuleException $exception) { Notification::make()->title($exception->getMessage())->danger()->send(); diff --git a/app/Filament/Resources/ContentElements/Pages/ListContentElements.php b/app/Filament/Resources/ContentElements/Pages/ListContentElements.php index f1dec60..3e93458 100644 --- a/app/Filament/Resources/ContentElements/Pages/ListContentElements.php +++ b/app/Filament/Resources/ContentElements/Pages/ListContentElements.php @@ -31,32 +31,30 @@ protected function getHeaderActions(): array ->label('Medium anlegen') ->visible(fn (): bool => ContentElementResource::editor()) ->schema([ - TextInput::make('working_title')->label('Arbeitstitel')->required(), - Select::make('kind')->label('Art')->options([ + TextInput::make('working_title')->label('Titel')->required(), + Select::make('shape')->label('Was ist das?')->options([ 'film' => 'Film', - 'audio' => 'Audio', + 'audio' => 'Hörstück', 'bild' => 'Bild', - 'pdf' => 'PDF', + 'document' => 'Dokument', 'text' => 'Text', - 'aufgabe' => 'Aufgabe', - ])->required(), - Select::make('output_class')->label('Ausgabeklasse')->options([ - 'film' => 'Film', - 'audio' => 'Audio', - 'bild' => 'Bild', - 'pdf' => 'PDF', - 'text' => 'Text', - ])->required(), - Textarea::make('body')->label('Text'), - EditContentElement::uploadField(), - TextInput::make('decision_seconds')->label('Entscheidungsmarke in Sekunden')->numeric()->minValue(0), - TextInput::make('change_note')->label('Änderungsnotiz'), + ])->required()->live(), + Textarea::make('body')->label('Text')->visible(fn ($get): bool => $get('shape') === 'text'), + EditContentElement::uploadField()->visible(fn ($get): bool => $get('shape') !== 'text'), + TextInput::make('change_note')->label('Notiz zur ersten Fassung'), ]) ->action(function (array $data): void { $element = null; $this->report(function () use ($data, &$element): void { $service = app(ContentService::class); - $element = $service->createElement($data['kind'], $data['output_class'], $data['working_title']); + [$kind, $output] = match ($data['shape']) { + 'audio' => ['audio', 'audio'], + 'bild' => ['bild', 'bild'], + 'document' => ['dokument', 'document'], + 'text' => ['text', 'text'], + default => ['film', 'film'], + }; + $element = $service->createElement($kind, $output, $data['working_title']); $metadata = []; $incoming = IncomingFile::store($data['incoming'] ?? null); diff --git a/app/Filament/Resources/Courses/CourseResource.php b/app/Filament/Resources/Courses/CourseResource.php index 1a852b9..4e66f11 100644 --- a/app/Filament/Resources/Courses/CourseResource.php +++ b/app/Filament/Resources/Courses/CourseResource.php @@ -11,11 +11,11 @@ class CourseResource extends CompositionKindResource { protected static ?string $slug = 'kurse'; - protected static ?string $navigationLabel = 'Kurse'; + protected static ?string $navigationLabel = 'Programme'; - protected static ?string $modelLabel = 'Kurs'; + protected static ?string $modelLabel = 'Programm'; - protected static ?string $pluralModelLabel = 'Kurse'; + protected static ?string $pluralModelLabel = 'Programme'; protected static ?int $navigationSort = 4; diff --git a/app/Filament/Resources/Exercises/ExerciseResource.php b/app/Filament/Resources/Exercises/ExerciseResource.php index 1ddfa05..adf107c 100644 --- a/app/Filament/Resources/Exercises/ExerciseResource.php +++ b/app/Filament/Resources/Exercises/ExerciseResource.php @@ -11,11 +11,11 @@ class ExerciseResource extends CompositionKindResource { protected static ?string $slug = 'uebungen'; - protected static ?string $navigationLabel = 'Übungen'; + protected static ?string $navigationLabel = 'Module'; - protected static ?string $modelLabel = 'Übung'; + protected static ?string $modelLabel = 'Modul'; - protected static ?string $pluralModelLabel = 'Übungen'; + protected static ?string $pluralModelLabel = 'Module'; protected static ?int $navigationSort = 3; diff --git a/app/Filament/Resources/Offers/Pages/ViewOffer.php b/app/Filament/Resources/Offers/Pages/ViewOffer.php index 4b21668..5a9a6af 100644 --- a/app/Filament/Resources/Offers/Pages/ViewOffer.php +++ b/app/Filament/Resources/Offers/Pages/ViewOffer.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\Offers\Pages; use App\Domain\Catalog\BundleVersion; +use App\Domain\Catalog\CompositionVersion; use App\Domain\Catalog\LicenseArticle; use App\Domain\Catalog\Offer; use App\Domain\Catalog\OfferService; @@ -34,6 +35,18 @@ protected function getHeaderActions(): array ])->required(), TextInput::make('price_cents')->label('Preis in Cent')->numeric() ->helperText('Nur bei einem Kauf. 500 bedeutet 5,00 €.'), + Select::make('composition_version_id')->label('Programmfassung, die abgedeckt sein muss') + ->options(function (): array { + return CompositionVersion::query() + ->where('status', 'bereit') + ->with('composition.editorialContentKind') + ->orderByDesc('id') + ->get() + ->mapWithKeys(fn (CompositionVersion $version): array => [$version->id => CatalogOptions::compositionLabel($version)]) + ->all(); + }) + ->searchable() + ->helperText('Wenn gewählt, lässt sich die Fassung nur aktivieren, wenn jeder Bestandteil in den Artikeln enthalten ist.'), Repeater::make('lines')->label('Positionen')->schema([ Select::make('kind')->label('Ziel')->options([ 'article' => 'Lizenzartikel', @@ -65,6 +78,7 @@ protected function getHeaderActions(): array 'grant_kind' => $data['grant_kind'], 'price_cents' => $data['price_cents'] === null || $data['price_cents'] === '' ? null : (int) $data['price_cents'], 'holder_kind' => 'person', + 'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null, ]); }, 'Die Angebotsfassung ist aktiv.'); $this->getRecord()->unsetRelations(); diff --git a/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php b/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php index bbc2ce1..c3c6311 100644 --- a/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php +++ b/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php @@ -34,11 +34,13 @@ protected function getHeaderActions(): array 'institutionell' => 'Institutionell', ])->required(), CheckboxList::make('capabilities')->label('Fähigkeiten')->options([ - 'film:streamen' => 'Film streamen', - 'film:ansehen' => 'Film ansehen', - 'audio:streamen' => 'Audio streamen', + 'film:streamen' => 'Film ansehen', + 'film:laden' => 'Film herunterladen', + 'audio:streamen' => 'Hörstück ansehen', + 'document:ansehen' => 'Dokument ansehen', + 'document:laden' => 'Dokument herunterladen', 'pdf:ansehen' => 'PDF ansehen', - 'pdf:laden' => 'PDF laden', + 'pdf:laden' => 'PDF herunterladen', 'text:ansehen' => 'Text ansehen', 'bild:ansehen' => 'Bild ansehen', ])->required(), diff --git a/app/Filament/Support/CatalogOptions.php b/app/Filament/Support/CatalogOptions.php index df6f96f..6c0a9f8 100644 --- a/app/Filament/Support/CatalogOptions.php +++ b/app/Filament/Support/CatalogOptions.php @@ -30,23 +30,57 @@ public static function elements(): array */ public static function assignmentTargets(?int $exceptCompositionId = null): array { - $options = []; + $media = []; + $structures = []; - foreach (ContentElementVersion::query()->where('status', ContentVersionStatus::Bereit)->with('element')->orderBy('id')->get() as $version) { - $options['element:'.$version->id] = 'Medium: '.$version->element->working_title.' · Fassung '.$version->number; + foreach (ContentElementVersion::query()->where('status', ContentVersionStatus::Bereit)->with('element.editorialContentKind')->orderBy('id')->get() as $version) { + $media['element:'.$version->id] = self::elementLabel($version); } - foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->with('composition')->orderBy('id')->get() as $version) { + foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->with('composition.editorialContentKind')->orderBy('id')->get() as $version) { if ($exceptCompositionId !== null && (int) $version->composition_id === $exceptCompositionId) { continue; } - $kind = $version->composition->kind; - $label = $kind instanceof CompositionKind ? $kind->label() : 'Zusammenstellung'; - $options['composition:'.$version->id] = $label.': '.$version->composition->designation.' · Fassung '.$version->number; + $structures['composition:'.$version->id] = self::compositionLabel($version); } - return $options; + return array_filter([ + 'Medien und Dokumente' => $media, + 'Module und Programme' => $structures, + ]); + } + + public static function elementLabel(ContentElementVersion $version): string + { + $kind = $version->element->editorialContentKind?->label; + $kind = $kind ?: self::outputLabel((string) $version->element->output_class); + + return $version->element->working_title.', '.$kind.', Fassung '.$version->number; + } + + public static function compositionLabel(CompositionVersion $version): string + { + $editorial = $version->composition->editorialContentKind?->label; + $technical = $version->composition->kind; + $kind = $editorial ?: ($technical instanceof CompositionKind ? $technical->label() : 'Zusammenstellung'); + $title = filled($version->composition->display_title) + ? $version->composition->display_title + : $version->composition->designation; + + return $title.', '.$kind.', Fassung '.$version->number; + } + + private static function outputLabel(string $outputClass): string + { + return match ($outputClass) { + 'film' => 'Film', + 'audio' => 'Hörstück', + 'bild' => 'Bild', + 'document', 'pdf' => 'Dokument', + 'text' => 'Text', + default => 'Medium', + }; } /** @@ -56,12 +90,12 @@ public static function readyTargets(): array { $options = []; - foreach (ContentElementVersion::query()->where('status', ContentVersionStatus::Bereit)->with('element')->orderBy('id')->get() as $version) { - $options['element:'.$version->id] = $version->element->working_title.' · Fassung '.$version->number; + foreach (ContentElementVersion::query()->where('status', ContentVersionStatus::Bereit)->with('element.editorialContentKind')->orderBy('id')->get() as $version) { + $options['element:'.$version->id] = self::elementLabel($version); } - foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->with('composition')->orderBy('id')->get() as $version) { - $options['composition:'.$version->id] = $version->composition->designation.' · Fassung '.$version->number; + foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->with('composition.editorialContentKind')->orderBy('id')->get() as $version) { + $options['composition:'.$version->id] = self::compositionLabel($version); } return $options; diff --git a/tests/Feature/MediaAdministrationTest.php b/tests/Feature/MediaAdministrationTest.php index 8e784e1..6be8f19 100644 --- a/tests/Feature/MediaAdministrationTest.php +++ b/tests/Feature/MediaAdministrationTest.php @@ -137,6 +137,21 @@ public function test_an_exercise_can_gain_and_drop_a_medium_without_losing_the_o $this->assertSame($sheet->id, $versions[0]->members->first()->content_element_version_id); $this->assertSame($film->id, $versions[1]->members->first()->content_element_version_id); $this->assertSame('Film', $versions[1]->members->first()->role); + + Livewire::test(EditExercise::class, ['record' => $exercise->composition_id]) + ->fillForm([ + 'designation' => 'Alltag üben', + 'kind' => 'uebung', + 'learning_goal' => 'Den Abstand üben', + 'members' => [ + ['role' => 'Film', 'target' => 'element:'.$film->id], + ], + ]) + ->call('save') + ->assertHasNoFormErrors(); + + $this->assertSame('Den Abstand üben', $exercise->composition->versions()->orderByDesc('number')->first()->learning_goal); + $this->assertSame(3, $exercise->composition->versions()->count()); } public function test_a_catalog_keeper_cannot_edit_media(): void