- Bestand direkt unter der Suche; Pille je wirksamem Filterfeld, Klick öffnet den Dialog beim Feld - Dialog mit Checkboxen für Materialart, Technische Art, Freigabe und Verwendung, übrige Kriterien unter Weitere Filter - ODER innerhalb eines Felds, UND zwischen Feldern; Anwenden übernimmt, Abbrechen verwirft - Standard speichern, wiederherstellen und löschen im Dialog; alte Adressen und Standards gelten weiter Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
687 lines
26 KiB
PHP
687 lines
26 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ContentElements\Pages;
|
|
|
|
use App\Domain\Catalog\EditorialVocabulary;
|
|
use App\Domain\Catalog\PillarFilterCompat;
|
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
|
use App\Filament\Support\Bestand;
|
|
use App\Filament\Support\MaterialKindSelection;
|
|
use App\Filament\Support\MediaLibrary;
|
|
use App\Filament\Support\MediumForm;
|
|
use App\Filament\Support\ReportsDomainRules;
|
|
use App\Filament\Support\ShowsBestand;
|
|
use App\Models\UserViewDefault;
|
|
use Filament\Actions\Action;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\ListRecords;
|
|
use Filament\Schemas\Components\RenderHook;
|
|
use Filament\Schemas\Components\View;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Enums\Width;
|
|
use Filament\View\PanelsRenderHook;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
use Livewire\Attributes\Url;
|
|
|
|
class ListContentElements extends ListRecords
|
|
{
|
|
use ReportsDomainRules;
|
|
use ShowsBestand;
|
|
|
|
protected static string $resource = ContentElementResource::class;
|
|
|
|
#[Url(as: 'suche', except: '')]
|
|
public string $suche = '';
|
|
|
|
/** Dokument 14 §3: kompakte Liste als Grundansicht; Kacheln bleiben wählbar. */
|
|
#[Url(as: 'ansicht', except: 'liste')]
|
|
public string $ansicht = 'liste';
|
|
|
|
#[Url(as: 'art', except: '')]
|
|
public string $art = '';
|
|
|
|
#[Url(as: 'freigabe', except: '')]
|
|
public string $freigabe = '';
|
|
|
|
#[Url(as: 'schutz', except: '')]
|
|
public string $schutz = '';
|
|
|
|
#[Url(as: 'entwurf', except: '')]
|
|
public string $entwurf = '';
|
|
|
|
#[Url(as: 'fassung', except: '')]
|
|
public string $fassung = '';
|
|
|
|
#[Url(as: 'nutzung', except: '')]
|
|
public string $nutzung = '';
|
|
|
|
#[Url(as: 'saeule', except: '')]
|
|
public string $saeule = '';
|
|
|
|
/** Frühere Adresse mit einer einzelnen Materialart (zum Beispiel aus den Stammdaten); wird zu `arten`. */
|
|
#[Url(as: 'inhaltsart', except: '')]
|
|
public string $inhaltsart = '';
|
|
|
|
/**
|
|
* Mehrfachauswahl der fachlichen Materialarten (MaterialKindSelection). Leer heißt: allgemeine Startansicht, also
|
|
* alle Materialarten und Medien ohne Materialart, aber ohne Übungsabschnitte.
|
|
*/
|
|
#[Url(as: 'arten', except: '')]
|
|
public string $arten = '';
|
|
|
|
/** Der Filterdialog ist offen. */
|
|
public bool $filterOffen = false;
|
|
|
|
/** Das Filterfeld, bei dem der Dialog beginnt (leer: beim ersten Feld). */
|
|
public string $filterFokus = '';
|
|
|
|
/**
|
|
* Arbeitsstand des Dialogs: die Auswahl seit dem Öffnen. Erst „Anwenden“ übernimmt sie in die Filter der Liste,
|
|
* „Abbrechen“ verwirft sie.
|
|
*
|
|
* @var array<string, mixed>
|
|
*/
|
|
public array $filterDraft = [];
|
|
|
|
/** Filterfelder mit mehreren Werten (ODER); verschiedene Felder gelten zusammen (UND). */
|
|
private const MULTI_FIELDS = ['art', 'freigabe', 'nutzung'];
|
|
|
|
#[Url(as: 'einordnung', except: '')]
|
|
public string $einordnung = '';
|
|
|
|
#[Url(as: 'verarbeitung', except: '')]
|
|
public string $verarbeitung = '';
|
|
|
|
#[Url(as: 'archiv', except: 'aktiv')]
|
|
public string $archiv = 'aktiv';
|
|
|
|
/** Eigenschaften, die der persönliche Standard festhält. Die Suche gehört nicht dazu: Sie ist Teil der Arbeit, kein Zustand der Ansicht. */
|
|
private const DEFAULT_FILTERS = ['arten', 'art', 'freigabe', 'schutz', 'entwurf', 'fassung', 'nutzung', 'saeule', 'einordnung', 'verarbeitung', 'archiv', 'ansicht'];
|
|
|
|
public function mount(): void
|
|
{
|
|
parent::mount();
|
|
|
|
if ($this->inhaltsart !== '' && $this->arten === '') {
|
|
$this->arten = ctype_digit($this->inhaltsart) ? MaterialKindSelection::encode([MaterialKindSelection::key((int) $this->inhaltsart)]) : '';
|
|
}
|
|
|
|
$this->inhaltsart = '';
|
|
|
|
// Ohne eigene Vorgaben in der Adresse startet der Medienmanager mit dem persönlichen Standard.
|
|
$given = array_intersect(array_keys(request()->query()), ['suche', 'ansicht', 'art', 'arten', 'inhaltsart', 'freigabe', 'schutz', 'entwurf', 'fassung', 'nutzung', 'saeule', 'einordnung', 'verarbeitung', 'archiv']);
|
|
|
|
if ($given === [] && ($saved = $this->savedDefault()) !== null) {
|
|
$this->applyFilters($saved);
|
|
}
|
|
}
|
|
|
|
public function getSubheading(): string|Htmlable|null
|
|
{
|
|
return 'Die Dateien und Texte. Ein Modul oder ein Programm verweist auf eine Fassung; die Datei wird nicht für jede Verwendung neu hochgeladen.';
|
|
}
|
|
|
|
public function getMaxContentWidth(): Width|string|null
|
|
{
|
|
return Width::Full;
|
|
}
|
|
|
|
public function content(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_BEFORE),
|
|
View::make('filament.verwaltung.bestand'),
|
|
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_AFTER),
|
|
]);
|
|
}
|
|
|
|
protected function bestandFilterEigenschaften(): array
|
|
{
|
|
return ['suche', 'art', 'arten', 'schutz', 'freigabe', 'entwurf', 'fassung', 'nutzung', 'saeule', 'inhaltsart', 'einordnung', 'verarbeitung', 'archiv'];
|
|
}
|
|
|
|
public function showingList(): bool
|
|
{
|
|
return $this->ansicht === 'liste';
|
|
}
|
|
|
|
/**
|
|
* @return list<array<string, mixed>>
|
|
*/
|
|
public function cards(): array
|
|
{
|
|
return app(MediaLibrary::class)->cards($this->libraryFilters(), ContentElementResource::editor());
|
|
}
|
|
|
|
/**
|
|
* @return list<array{value: string, label: string}>
|
|
*/
|
|
public function typeOptions(): array
|
|
{
|
|
return app(MediaLibrary::class)->types();
|
|
}
|
|
|
|
/**
|
|
* @return list<array{id: int, name: string}>
|
|
*/
|
|
public function pillarOptions(): array
|
|
{
|
|
return app(MediaLibrary::class)->pillars();
|
|
}
|
|
|
|
/**
|
|
* @return list<array{id: int, label: string}>
|
|
*/
|
|
public function classificationOptions(): array
|
|
{
|
|
return app(MediaLibrary::class)->classifications(ctype_digit($this->einordnung) ? [(int) $this->einordnung] : []);
|
|
}
|
|
|
|
public function filtersActive(): bool
|
|
{
|
|
return trim($this->suche) !== ''
|
|
|| $this->art !== ''
|
|
|| $this->freigabe !== ''
|
|
|| $this->schutz !== ''
|
|
|| $this->entwurf !== ''
|
|
|| $this->fassung !== ''
|
|
|| $this->nutzung !== ''
|
|
|| $this->saeule !== ''
|
|
|| $this->einordnung !== ''
|
|
|| $this->arten !== ''
|
|
|| $this->verarbeitung !== ''
|
|
|| $this->archiv !== 'aktiv';
|
|
}
|
|
|
|
public function resetFilters(): void
|
|
{
|
|
$this->suche = '';
|
|
$this->art = '';
|
|
$this->freigabe = '';
|
|
$this->schutz = '';
|
|
$this->entwurf = '';
|
|
$this->fassung = '';
|
|
$this->nutzung = '';
|
|
$this->saeule = '';
|
|
$this->einordnung = '';
|
|
$this->inhaltsart = '';
|
|
$this->arten = '';
|
|
$this->verarbeitung = '';
|
|
$this->archiv = 'aktiv';
|
|
$this->bestandGrenze = Bestand::SCHRITT;
|
|
}
|
|
|
|
// ---------------------------------------------------------------- Materialarten und persönlicher Standard
|
|
|
|
/**
|
|
* Die wählbaren Materialarten mit Schlüssel: die Arten der redaktionellen Stammdaten, „Übungsabschnitt“ und „Ohne
|
|
* Materialart“.
|
|
*
|
|
* @return array<string, array{label: string, automatic: bool}>
|
|
*/
|
|
public function artChoices(): array
|
|
{
|
|
$chosen = array_map(
|
|
fn (string $key): int => (int) substr($key, 1),
|
|
array_filter(MaterialKindSelection::decode($this->arten) ?? [], fn (string $key): bool => $key !== MaterialKindSelection::WITHOUT),
|
|
);
|
|
$choices = [];
|
|
|
|
foreach (app(EditorialVocabulary::class)->mediumKindChoices(array_values($chosen)) as $kind) {
|
|
$choices[MaterialKindSelection::key($kind['id'])] = ['label' => $kind['label'], 'automatic' => $kind['automatic']];
|
|
}
|
|
|
|
$choices[MaterialKindSelection::WITHOUT] = ['label' => 'Ohne Materialart', 'automatic' => false];
|
|
|
|
return $choices;
|
|
}
|
|
|
|
/**
|
|
* Allgemeine Startansicht: alle Materialarten und Medien ohne Materialart, ohne Übungsabschnitte.
|
|
*
|
|
* @return list<string>
|
|
*/
|
|
private function defaultArten(): array
|
|
{
|
|
return array_keys(array_filter($this->artChoices(), fn (array $choice): bool => ! $choice['automatic']));
|
|
}
|
|
|
|
/**
|
|
* @return list<string> die gerade gewählten Schlüssel
|
|
*/
|
|
public function selectedArten(): array
|
|
{
|
|
return MaterialKindSelection::decode($this->arten) ?? $this->defaultArten();
|
|
}
|
|
|
|
/**
|
|
* @param list<string> $keys
|
|
*/
|
|
private function storeArten(array $keys): void
|
|
{
|
|
$default = $this->defaultArten();
|
|
sort($keys);
|
|
sort($default);
|
|
|
|
// Die allgemeine Startansicht bleibt ohne Eintrag in der Adresse.
|
|
$this->arten = $keys === $default ? '' : MaterialKindSelection::encode($keys);
|
|
$this->bestandGrenze = Bestand::SCHRITT;
|
|
}
|
|
|
|
private function userId(): ?int
|
|
{
|
|
$id = Filament::auth()->id();
|
|
|
|
return $id === null ? null : (int) $id;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>|null
|
|
*/
|
|
private function savedDefault(): ?array
|
|
{
|
|
return UserViewDefault::filtersFor($this->userId(), UserViewDefault::MEDIA);
|
|
}
|
|
|
|
public function hasSavedDefault(): bool
|
|
{
|
|
return $this->savedDefault() !== null;
|
|
}
|
|
|
|
/**
|
|
* Die aktuellen Filter (ohne Suche) als persönlicher Standard dieses Kontos.
|
|
*/
|
|
public function saveDefault(): void
|
|
{
|
|
$userId = $this->userId();
|
|
|
|
if ($userId === null) {
|
|
return;
|
|
}
|
|
|
|
$filters = [];
|
|
|
|
foreach (self::DEFAULT_FILTERS as $name) {
|
|
$filters[$name] = (string) $this->{$name};
|
|
}
|
|
|
|
UserViewDefault::remember($userId, UserViewDefault::MEDIA, $filters);
|
|
$this->filterOffen = false;
|
|
Notification::make()->title('Standard gespeichert')->body('Der Medienmanager startet für dich mit diesen Filtern.')->success()->send();
|
|
}
|
|
|
|
public function restoreDefault(): void
|
|
{
|
|
$saved = $this->savedDefault();
|
|
|
|
if ($saved === null) {
|
|
Notification::make()->title('Kein persönlicher Standard gespeichert')->warning()->send();
|
|
|
|
return;
|
|
}
|
|
|
|
$this->suche = '';
|
|
$this->applyFilters($saved);
|
|
$this->filterOffen = false;
|
|
Notification::make()->title('Dein Standard ist geladen')->success()->send();
|
|
}
|
|
|
|
public function deleteDefault(): void
|
|
{
|
|
$userId = $this->userId();
|
|
|
|
if ($userId !== null) {
|
|
UserViewDefault::forget($userId, UserViewDefault::MEDIA);
|
|
}
|
|
|
|
$this->resetFilters();
|
|
$this->ansicht = 'liste';
|
|
$this->filterOffen = false;
|
|
Notification::make()->title('Persönlicher Standard gelöscht')->body('Der Medienmanager startet wieder mit der allgemeinen Auswahl.')->success()->send();
|
|
}
|
|
|
|
/**
|
|
* @param array<string, string> $filters
|
|
*/
|
|
private function applyFilters(array $filters): void
|
|
{
|
|
foreach (self::DEFAULT_FILTERS as $name) {
|
|
if (array_key_exists($name, $filters)) {
|
|
$this->{$name} = (string) $filters[$name];
|
|
}
|
|
}
|
|
|
|
$this->ansicht = $this->ansicht === 'kacheln' ? 'kacheln' : 'liste';
|
|
$this->archiv = in_array($this->archiv, ['aktiv', 'archiviert', 'alle'], true) ? $this->archiv : 'aktiv';
|
|
$this->bestandGrenze = Bestand::SCHRITT;
|
|
}
|
|
|
|
// ---------------------------------------------------------------- Filterdialog
|
|
|
|
/**
|
|
* Filterfelder mit Checkboxen (Mehrfachauswahl). Mehrere Werte eines Felds gelten als ODER.
|
|
*
|
|
* @return array<string, array{label: string, kurz: string, optionen: array<string, string>}>
|
|
*/
|
|
private function multiFields(): array
|
|
{
|
|
$arten = array_map(fn (array $choice): string => $choice['label'], $this->artChoices());
|
|
|
|
return [
|
|
'arten' => ['label' => 'Fachliche Materialart', 'kurz' => 'Materialart', 'optionen' => $arten],
|
|
'art' => ['label' => 'Technische Art', 'kurz' => 'Technische Art', 'optionen' => collect($this->typeOptions())->mapWithKeys(fn (array $type): array => [$type['value'] => $type['label']])->all()],
|
|
'freigabe' => ['label' => 'Freigabe', 'kurz' => 'Freigabe', 'optionen' => ['freigegeben' => 'Freigegebene Fassung', 'entwurf' => 'Nur offener Entwurf', 'ohne' => 'Keine freigegebene Fassung']],
|
|
'nutzung' => ['label' => 'Verwendung', 'kurz' => 'Verwendung', 'optionen' => ['verwendet' => 'Verwendet', 'unbenutzt' => 'Nicht verwendet']],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Weitere Kriterien mit einem Wert je Feld, unter „Weitere Filter“ im Dialog.
|
|
*
|
|
* @return array<string, array{label: string, vorgabe: string, alle: string|null, optionen: array<string, string>}>
|
|
*/
|
|
private function singleFields(): array
|
|
{
|
|
$optionen = fn (array $liste, string $wert, string $label): array => collect($liste)
|
|
->mapWithKeys(fn (array $eintrag): array => [(string) $eintrag[$wert] => $eintrag[$label]])
|
|
->all();
|
|
$fields = [
|
|
'schutz' => ['label' => 'Schutz', 'vorgabe' => '', 'alle' => 'Alle Medien', 'optionen' => ['geschuetzt' => 'Geschützte Medien', 'oeffentlich' => 'Öffentliche Medien', 'website' => 'Auf der Website frei']],
|
|
'entwurf' => ['label' => 'Entwurf', 'vorgabe' => '', 'alle' => 'Entwurf egal', 'optionen' => ['offen' => 'Offener Entwurf', 'keiner' => 'Kein offener Entwurf']],
|
|
'fassung' => ['label' => 'Deaktivierte Fassungen', 'vorgabe' => '', 'alle' => 'Regulärer Bestand', 'optionen' => ['mit' => 'Mit deaktivierter Fassung', 'nur' => 'Nur deaktivierte Fassungen']],
|
|
];
|
|
|
|
if (($pillars = $this->pillarOptions()) !== []) {
|
|
$fields['saeule'] = ['label' => 'Fachliche Säule', 'vorgabe' => '', 'alle' => 'Alle Säulen', 'optionen' => $optionen($pillars, 'id', 'name')];
|
|
}
|
|
|
|
if (($classes = $this->classificationOptions()) !== []) {
|
|
$fields['einordnung'] = ['label' => 'Einordnung', 'vorgabe' => '', 'alle' => 'Alle Einordnungen', 'optionen' => $optionen($classes, 'id', 'label')];
|
|
}
|
|
|
|
$fields['verarbeitung'] = ['label' => 'Verarbeitung', 'vorgabe' => '', 'alle' => 'Verarbeitung egal', 'optionen' => ['fehler' => 'Verarbeitungsfehler', 'uebernahme' => 'Datei wird übernommen']];
|
|
$fields['archiv'] = ['label' => 'Archiv', 'vorgabe' => 'aktiv', 'alle' => null, 'optionen' => ['aktiv' => 'Aktive Medien', 'archiviert' => 'Archivierte Medien', 'alle' => 'Auch archivierte']];
|
|
|
|
return $fields;
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
private function appliedList(string $field): array
|
|
{
|
|
$value = trim((string) $this->{$field});
|
|
|
|
return $value === '' ? [] : array_values(array_filter(array_map('trim', explode(',', $value)), fn (string $part): bool => $part !== ''));
|
|
}
|
|
|
|
/**
|
|
* Die Auswahl der Liste als Arbeitsstand des Dialogs.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function draftFromApplied(): array
|
|
{
|
|
$draft = ['arten' => $this->selectedArten()];
|
|
|
|
foreach (self::MULTI_FIELDS as $field) {
|
|
$draft[$field] = $this->appliedList($field);
|
|
}
|
|
|
|
foreach (array_keys($this->singleFields()) as $field) {
|
|
$draft[$field] = (string) $this->{$field};
|
|
}
|
|
|
|
return $draft;
|
|
}
|
|
|
|
public function openFilter(string $field = ''): void
|
|
{
|
|
$this->filterDraft = $this->draftFromApplied();
|
|
$this->filterFokus = $field;
|
|
$this->filterOffen = true;
|
|
}
|
|
|
|
/** Verwirft die Auswahl seit dem Öffnen. */
|
|
public function cancelFilter(): void
|
|
{
|
|
$this->filterOffen = false;
|
|
$this->filterDraft = [];
|
|
$this->filterFokus = '';
|
|
}
|
|
|
|
/** Alle Materialarten im Dialog ankreuzen, auch Übungsabschnitte und „Ohne Materialart“. */
|
|
public function draftAlleArten(): void
|
|
{
|
|
$this->filterDraft['arten'] = array_keys($this->artChoices());
|
|
}
|
|
|
|
/** Übernimmt die Auswahl des Dialogs in die Liste. */
|
|
public function applyFilter(): void
|
|
{
|
|
$this->applyDraft();
|
|
$this->filterOffen = false;
|
|
$this->filterDraft = [];
|
|
$this->filterFokus = '';
|
|
}
|
|
|
|
/** Übernimmt die Auswahl des Dialogs und merkt sie als persönlichen Standard. */
|
|
public function saveDefaultFromDialog(): void
|
|
{
|
|
$this->applyDraft();
|
|
$this->filterDraft = [];
|
|
$this->filterFokus = '';
|
|
$this->saveDefault();
|
|
}
|
|
|
|
private function applyDraft(): void
|
|
{
|
|
$draft = $this->filterDraft;
|
|
$known = array_keys($this->artChoices());
|
|
$this->storeArten(array_values(array_intersect($known, array_map('strval', (array) ($draft['arten'] ?? [])))));
|
|
$options = $this->multiFields();
|
|
|
|
foreach (self::MULTI_FIELDS as $field) {
|
|
$allowed = array_keys($options[$field]['optionen']);
|
|
$chosen = array_values(array_intersect($allowed, array_map('strval', (array) ($draft[$field] ?? []))));
|
|
// Alle Werte angekreuzt heißt: keine Einschränkung.
|
|
$this->{$field} = count($chosen) === count($allowed) ? '' : implode(',', $chosen);
|
|
}
|
|
|
|
foreach ($this->singleFields() as $field => $definition) {
|
|
$value = (string) ($draft[$field] ?? $definition['vorgabe']);
|
|
$this->{$field} = array_key_exists($value, $definition['optionen']) ? $value : $definition['vorgabe'];
|
|
}
|
|
|
|
$this->bestandGrenze = Bestand::SCHRITT;
|
|
}
|
|
|
|
/**
|
|
* Die wirksamen Filter als Pillen unter der Suche. Ein Klick öffnet den Dialog beim Filterfeld. In der allgemeinen
|
|
* Startansicht erklärt eine Pille, warum Übungsabschnitte fehlen.
|
|
*
|
|
* @return list<array{feld: string, label: string, info: bool}>
|
|
*/
|
|
private function filterPills(): array
|
|
{
|
|
$pills = [];
|
|
$short = function (array $labels): string {
|
|
$joined = implode(', ', $labels);
|
|
|
|
return count($labels) <= 3 && mb_strlen($joined) <= 40 ? $joined : count($labels).' gewählt';
|
|
};
|
|
$multi = $this->multiFields();
|
|
|
|
if ($this->arten === '') {
|
|
$pills[] = ['feld' => 'arten', 'label' => 'Übungsabschnitte ausgeblendet', 'info' => true];
|
|
} else {
|
|
$selected = $this->selectedArten();
|
|
|
|
if ($selected === []) {
|
|
$pills[] = ['feld' => 'arten', 'label' => 'Materialart · keine gewählt', 'info' => false];
|
|
} elseif (count($selected) < count($multi['arten']['optionen'])) {
|
|
$pills[] = ['feld' => 'arten', 'label' => 'Materialart · '.$short(array_map(fn (string $key): string => $multi['arten']['optionen'][$key] ?? $key, $selected)), 'info' => false];
|
|
}
|
|
}
|
|
|
|
foreach (self::MULTI_FIELDS as $field) {
|
|
$values = $this->appliedList($field);
|
|
|
|
if ($values !== []) {
|
|
$pills[] = ['feld' => $field, 'label' => $multi[$field]['kurz'].' · '.$short(array_map(fn (string $value): string => $multi[$field]['optionen'][$value] ?? $value, $values)), 'info' => false];
|
|
}
|
|
}
|
|
|
|
foreach ($this->singleFields() as $field => $definition) {
|
|
$value = (string) $this->{$field};
|
|
|
|
if ($value !== $definition['vorgabe']) {
|
|
$pills[] = ['feld' => $field, 'label' => $definition['label'].' · '.($definition['optionen'][$value] ?? $value), 'info' => false];
|
|
}
|
|
}
|
|
|
|
return $pills;
|
|
}
|
|
|
|
/**
|
|
* Gemeinsame Bestandsliste: Suche mit Filterknopf, wirksame Filter als Pillen, alle Kriterien im Filterdialog.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function bestand(): array
|
|
{
|
|
// Alte Adressen mit einem Säulenwert der Einordnung gelten für die zentrale Säule.
|
|
if (ctype_digit($this->einordnung) && $this->saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $this->einordnung))) {
|
|
[$this->saeule, $this->einordnung] = [(string) $pillar, ''];
|
|
}
|
|
|
|
$pills = $this->filterPills();
|
|
$keine = $this->selectedArten() === [];
|
|
$gespeichert = $this->hasSavedDefault();
|
|
$dialog = [
|
|
'offen' => $this->filterOffen,
|
|
'fokus' => $this->filterFokus,
|
|
'pillen' => $pills,
|
|
'anzahl' => count(array_filter($pills, fn (array $pill): bool => ! $pill['info'])),
|
|
'felder' => $this->multiFields(),
|
|
'weitere' => $this->singleFields(),
|
|
'entwurf' => 'filterDraft',
|
|
'gespeichert' => $gespeichert,
|
|
'hinweis' => 'Mehrere Werte eines Felds zeigen Medien, auf die einer davon zutrifft. Verschiedene Felder gelten zusammen. Freigabe meint die Fassung des Mediums, nicht die Website und keinen Zugriff. Geschützte Medien haben eine Inhaltsfassung und laufen über Lizenzen. Öffentliche Medien sind eigenständige Präsentationsmedien ohne Fassung für die Website. Materialart und Einordnung sind die redaktionelle Klassifikation; Verwendung zeigt, wo das Medium tatsächlich eingebunden ist. Übungsabschnitte, die Texte der Übungen, erscheinen erst, wenn du sie unter Materialart ankreuzt. „Als Standard speichern“ merkt die Filter für dein Konto, ohne die Suche.',
|
|
];
|
|
|
|
return [
|
|
'suche' => ['eigenschaft' => 'suche', 'label' => 'Suche', 'platzhalter' => 'Titel, Beschreibung oder Suchbegriff'],
|
|
'filterdialog' => $dialog,
|
|
'zeilen' => array_map($this->zeile(...), $this->cards()),
|
|
'einheit' => ['Medium', 'Medien'],
|
|
'leerHinweis' => $keine ? 'Öffne den Filter und wähle mindestens eine Materialart aus, um Medien zu sehen. „Alle auswählen“ zeigt alles, auch die Übungsabschnitte.' : null,
|
|
'leer' => ['titel' => 'Noch keine Medien', 'text' => 'Mit „Medium anlegen“ oben lädst du eine Datei hoch oder schreibst einen Text.'],
|
|
'ansicht' => 'ansicht',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $card
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function zeile(array $card): array
|
|
{
|
|
$chips = [['label' => $card['presentation'] ? 'Präsentationsmedium, ohne Inhaltsfassung' : $card['stand'], 'ton' => match ($card['standTone']) {
|
|
'ready' => 'gut',
|
|
'draft' => 'offen',
|
|
'blocked' => 'achtung',
|
|
default => 'leise',
|
|
}]];
|
|
|
|
if ($card['websiteReleased']) {
|
|
$chips[] = ['label' => 'Für die Website freigegeben', 'ton' => 'gut'];
|
|
} elseif ($card['presentation']) {
|
|
$chips[] = ['label' => 'Nicht für die Website freigegeben', 'ton' => 'offen'];
|
|
}
|
|
|
|
foreach ([['draftNote', 'offen'], ['blockedNote', 'achtung'], ['processing', 'offen'], ['versionLabel', 'leise']] as [$feld, $ton]) {
|
|
if (filled($card[$feld] ?? null)) {
|
|
$chips[] = ['label' => (string) $card[$feld], 'ton' => $ton];
|
|
}
|
|
}
|
|
|
|
if ($card['archived']) {
|
|
$chips[] = ['label' => 'Archiviert', 'ton' => 'leise'];
|
|
}
|
|
|
|
return [
|
|
'schluessel' => 'm'.$card['id'],
|
|
'titel' => $card['title'],
|
|
'meta' => $card['type'].(filled($card['editorialKind'] ?? null) ? ' · '.$card['editorialKind'] : '').($card['exercise'] !== null ? ' · Übung: '.$card['exercise']['title'] : ''),
|
|
'text' => $card['description'],
|
|
'bild' => $card['image'],
|
|
'bildAlt' => $card['imageAlt'],
|
|
'symbol' => match ($card['typeKey']) {
|
|
'film' => 'film',
|
|
'bild' => 'bild',
|
|
'audio' => 'audio',
|
|
default => 'dokument',
|
|
},
|
|
'url' => $card['url'],
|
|
'chips' => $chips,
|
|
'hinweise' => array_values(array_filter([
|
|
$card['imageNote'] ? 'Vorschaubild: '.$card['imageNote'] : null,
|
|
$card['usageNote'] ? 'Einsatz: '.$card['usageNote'] : null,
|
|
$card['licenseNote'] ? 'Interner Lizenzvermerk: '.$card['licenseNote'] : null,
|
|
])),
|
|
'zusatz' => ['view' => 'filament.media.usages', 'daten' => ['card' => $card]],
|
|
'aktionen' => array_values(array_filter([
|
|
['label' => 'Ansehen', 'href' => $card['url'], 'icon' => 'auge'],
|
|
$card['editUrl'] ? ['label' => 'Redaktion', 'href' => $card['editUrl'], 'icon' => 'stift'] : null,
|
|
($card['exercise']['url'] ?? null) ? ['label' => 'Zur Übung', 'href' => $card['exercise']['url'], 'icon' => 'stift'] : null,
|
|
])),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
private function libraryFilters(): array
|
|
{
|
|
return [
|
|
'suche' => $this->suche,
|
|
'art' => $this->art,
|
|
'freigabe' => $this->freigabe,
|
|
'schutz' => $this->schutz,
|
|
'entwurf' => $this->entwurf,
|
|
'fassung' => $this->fassung,
|
|
'nutzung' => $this->nutzung,
|
|
'saeule' => $this->saeule,
|
|
'einordnung' => $this->einordnung,
|
|
'inhaltsart' => $this->inhaltsart,
|
|
'arten' => $this->arten === '' ? MaterialKindSelection::encode($this->defaultArten()) : $this->arten,
|
|
'verarbeitung' => $this->verarbeitung,
|
|
'archiv' => $this->archiv,
|
|
];
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('create')
|
|
->label('Medium anlegen')
|
|
->modalSubmitActionLabel('Medium anlegen')
|
|
->visible(fn (): bool => ContentElementResource::editor())
|
|
->modalDescription('Dieselbe Maske gilt im Medienbestand, im Modul und im Programm. Der Upload zeigt seinen Fortschritt. Beschreibung, Hinweise und Vorschaubild gehören dazu.')
|
|
->schema(fn (): array => MediumForm::fields(creating: true))
|
|
->action(function (array $data): void {
|
|
$element = null;
|
|
$this->report(function () use ($data, &$element): void {
|
|
$element = MediumForm::create($data, hold: false);
|
|
}, 'Das Medium ist angelegt.');
|
|
|
|
if ($element !== null) {
|
|
$this->redirect(ContentElementResource::getUrl('view', ['record' => $element]));
|
|
}
|
|
}),
|
|
];
|
|
}
|
|
}
|