query = ''; $this->kindFilter = 'alle'; $this->pillar = ''; $this->saeule = ''; $this->visibility = 'alle'; $this->bestandGrenze = Bestand::SCHRITT; } public function hasActiveFilters(): bool { return trim($this->query) !== '' || $this->kindFilter !== 'alle' || $this->pillar !== '' || $this->saeule !== '' || $this->visibility !== 'alle'; } /** * @return array */ public function bestand(): array { $this->normalizeLegacyPillarFilter(); $fixed = $this->fixedKind(); $einheit = match ($fixed) { CompositionKind::Kurs => ['Programm', 'Programme'], CompositionKind::Uebung => ['Modul', 'Module'], CompositionKind::Kombination => ['Fachliche Kombination', 'Fachliche Kombinationen'], default => ['Programm oder Modul', 'Programme und Module'], }; $gruppen = []; foreach ($this->dimensionFilters() as $gruppe) { $optionen = []; foreach ($gruppe['values'] as $value) { $optionen[(string) $value['id']] = $value['label']; } $gruppen[] = ['label' => $gruppe['label'], 'optionen' => $optionen]; } return [ 'suche' => ['eigenschaft' => 'query', 'label' => 'Suche', 'platzhalter' => 'Titel oder Kurzbeschreibung'], 'segmente' => $fixed === null ? [[ 'eigenschaft' => 'kindFilter', 'label' => 'Art', 'vorgabe' => 'alle', 'optionen' => ['alle' => 'Alle', 'programm' => 'Programme', 'modul' => 'Module'], ]] : [], 'filter' => [[ 'eigenschaft' => 'visibility', 'label' => 'Stand', 'vorgabe' => 'alle', 'optionen' => ['alle' => 'Jeder Stand', 'bibliothek' => 'In der Mitgliederbibliothek', 'verborgen' => 'Nicht in der Mitgliederbibliothek', 'entwurf' => 'Noch ohne Fassung'], ]], 'weitere' => [ ...($this->pillarOptions() === [] ? [] : [[ 'eigenschaft' => 'saeule', 'label' => 'Fachliche Säule', 'vorgabe' => '', 'alle' => 'Alle Säulen', 'optionen' => $this->pillarOptions(), ]]), ...($gruppen === [] ? [] : [[ 'eigenschaft' => 'pillar', 'label' => 'Fachliche Einordnung', 'vorgabe' => '', 'alle' => 'Alle Einordnungen', 'gruppen' => $gruppen, ]]), ], 'zeilen' => $this->entries(), 'einheit' => $einheit, 'leer' => [ 'titel' => $fixed === CompositionKind::Kombination ? 'Noch keine fachlichen Kombinationen' : 'Noch keine '.$einheit[1], 'text' => 'Mit „'.match ($fixed) { CompositionKind::Kurs => 'Programm anlegen', CompositionKind::Kombination => CompositionKind::Kombination->createLabel(), default => 'Modul anlegen', }.'“ oben entsteht der erste Eintrag. Der Name genügt.', ], ]; } /** * @return list}> */ public function dimensionFilters(): array { return app(EditorialVocabulary::class)->dimensionFilterGroups(ctype_digit($this->pillar) ? [(int) $this->pillar] : []); } /** * Zeilen der gemeinsamen Bestandsliste. * * @return list> */ public function entries(): array { $needle = mb_strtolower(trim($this->query)); $catalog = app(EditorialCatalog::class); $offered = $catalog->offeredCompositionIds(); $this->normalizeLegacyPillarFilter(); $pillarIds = $this->pillar === '' ? null : $this->pillarSubjects((int) $this->pillar); $saeuleIds = ctype_digit($this->saeule) && $this->saeule !== '' ? $this->saeuleSubjects((int) $this->saeule) : null; $fixed = $this->fixedKind(); $kinds = $fixed !== null ? [$fixed] : match ($this->kindFilter) { 'programm' => [CompositionKind::Kurs], 'modul' => [CompositionKind::Uebung], default => [CompositionKind::Kurs, CompositionKind::Uebung], }; $canEdit = ContentElementResource::editor(); $rows = []; $compositions = Composition::query() ->whereIn('kind', $kinds) ->with(['editorialContentKind', 'versions.members.contentElementVersion.element']) ->orderBy('designation') ->get(); foreach ($compositions as $composition) { $kind = $composition->kind instanceof CompositionKind ? $composition->kind : CompositionKind::from((string) $composition->kind); if ($pillarIds !== null && ! in_array($composition->id, $pillarIds, true)) { continue; } if ($saeuleIds !== null && ! in_array($composition->id, $saeuleIds, true)) { continue; } $stand = $catalog->stand($composition); if (! $this->matchesVisibility($stand)) { continue; } $title = $catalog->compositionTitle($composition); $summary = trim((string) ($composition->summary ?? '')); $haystack = mb_strtolower($title.' '.$composition->designation.' '.$summary.' '.(string) $composition->description); if ($needle !== '' && ! str_contains($haystack, $needle)) { continue; } $cover = $catalog->cover($composition, $this->coverMembers($composition)); $url = EditorialCatalog::editUrl($composition); $rows[] = [ 'schluessel' => 'c'.$composition->id, 'titel' => $title, 'meta' => $kind->deskLabel().($title !== $composition->designation ? ' · '.$composition->designation : ''), 'text' => $summary, 'bild' => $cover['url'], 'bildFehlt' => 'Kein Titelbild', 'hinweise' => filled($cover['note']) ? ['Bild: '.$cover['note']] : [], 'symbol' => 'modul', 'url' => $url, 'chips' => array_map(fn (array $chip): array => [ 'label' => $chip['label'], 'ton' => match ($chip['tone']) { 'pine' => 'gut', 'yellow' => 'offen', 'quiet' => 'leise', default => 'neutral', }, ], $catalog->statusChips($composition, in_array($composition->id, $offered, true))), 'aktionen' => array_values(array_filter([ ['label' => 'Aufbau', 'href' => $url, 'icon' => 'modul'], $canEdit ? ['label' => 'Redaktion', 'href' => $url.'?redaktion=1', 'icon' => 'stift'] : null, ])), ]; } return $rows; } /** * Anlegedialog für Module und Programme; derselbe auf dem Arbeitsplatz und in den Listen. */ protected function createCompositionAction(CompositionKind $kind): Action { $label = $kind === CompositionKind::Kurs ? 'Programm' : 'Modul'; return Action::make($kind === CompositionKind::Kurs ? 'createProgram' : 'createModule') ->label($label.' anlegen') ->modalHeading('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') ->visible(fn (): bool => ContentElementResource::editor()) ->schema([ TextInput::make('designation')->label('Name')->required()->maxLength(255), ]) ->action(function (array $data) use ($kind): void { abort_unless(ContentElementResource::editor(), 403); $composition = app(EditorialCatalog::class)->create(trim((string) $data['designation']), $kind); $this->redirect(EditorialCatalog::editUrl($composition), navigate: false); }); } /** * @return list */ private function coverMembers(Composition $composition): array { $draft = $composition->working_draft; if (is_array($draft) && is_array($draft['members'] ?? null) && $draft['members'] !== []) { return $draft['members']; } $version = $composition->versions ->filter(fn ($item): bool => $item->status === ContentVersionStatus::Bereit) ->sortByDesc('number') ->first(); if ($version === null) { return []; } $members = []; foreach ($version->members as $member) { $members[] = ['target' => $member->content_element_version_id ? 'element:'.$member->content_element_version_id : 'composition:'.$member->nested_composition_version_id]; } return $members; } /** * Alte Adressen mit einem Säulenwert der Einordnung (`?pillar=…`) gelten für die zentrale Säule. */ private function normalizeLegacyPillarFilter(): void { if (ctype_digit($this->pillar) && $this->pillar !== '' && $this->saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $this->pillar))) { [$this->saeule, $this->pillar] = [(string) $pillar, '']; } } /** * @return array */ private function pillarOptions(): array { return Pillar::query()->orderBy('sort_order')->orderBy('name')->pluck('name', 'id') ->mapWithKeys(fn (string $name, int|string $id): array => [(string) $id => $name])->all(); } /** * Direkt zugeordnete Module und Programme einer Säule. Die Säulen der enthaltenen Medien zählen hier nicht. * * @return list */ private function saeuleSubjects(int $pillarId): array { return DB::table('composition_pillar')->where('pillar_id', $pillarId)->pluck('composition_id') ->map(fn (mixed $id): int => (int) $id)->all(); } /** * @return list */ private function pillarSubjects(int $valueId): array { return IdentityDimensionValue::query() ->where('subject_type', (new Composition)->getMorphClass()) ->where('editorial_dimension_value_id', $valueId) ->pluck('subject_id') ->map(fn (mixed $id): int => (int) $id) ->all(); } /** * @param array{text: string, number: int|null, released_number: int|null} $stand */ private function matchesVisibility(array $stand): bool { return match ($this->visibility) { 'bibliothek' => $stand['released_number'] !== null, 'verborgen' => $stand['number'] !== null && $stand['released_number'] === null, 'entwurf' => $stand['number'] === null, default => true, }; } }