Stelle die Kataloglisten und das Angebot auf die gemeinsamen Muster um.
CI Feature / test (push) Successful in 1m0s
Deploy Test / test (push) Successful in 54s
Deploy Test / deploy (push) Successful in 23s

- Lizenzartikel, Pakete, Rechteprofile und Angebote nutzen die gemeinsame
  Bestandsliste (ListsCatalog): Suche, Zustandsfilter, lesbare Zustände aus
  vorhandenen Daten statt „Aktueller Stand: 1“ oder „Fassungen: aktiv“
  (Stand veröffentlicht/in Arbeit/gesperrt, in aktivem Angebot, Fassung aktiv
  mit Vergabe und Preis, Bestandteile, Zweck und Fähigkeiten). Lizenzartikel
  zeigen ihr Titelbild.
- Anlegedialoge benennen Zweck und Bestätigung und öffnen danach den neuen
  Eintrag, statt in der Liste stehen zu bleiben.
- Angebot im gemeinsamen Rahmen (Kopf, Positionen, aufgelöster
  Leistungsumfang, Fassungsverlauf). Eine Maske für Anlegen und Ändern
  (FACH-20): „Fassung aktivieren“ bzw. „Geänderte Fassung aktivieren“, bei einer
  Änderung mit der aktiven Fassung vorbelegt (FACH-08). Wirkung unverändert
  OfferService::activate: die bisherige Fassung wird beendet und bleibt
  gespeichert. „Als Vorlage verwenden“ (FACH-09) bleibt offen (OFF-04).
- Entfernt: editorial/catalog-card (ersetzt).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-20 08:29:28 +01:00
1 parent 532979aa86
commit 660b50f418
10 files changed
+828 -80

No files matched your search

@@ -2,8 +2,12 @@
namespace App\Filament\Resources\Bundles\Pages;
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\BundleService;
use App\Domain\Catalog\BundleStatus;
use App\Domain\Catalog\StatusValue;
use App\Filament\Resources\Bundles\BundleResource;
use App\Filament\Support\ListsCatalog;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
@@ -12,6 +16,7 @@
class ListBundles extends ListRecords
{
use ListsCatalog;
use ReportsDomainRules;
protected static string $resource = BundleResource::class;
@@ -24,13 +29,83 @@ public function getSubheading(): string|Htmlable|null
protected function getHeaderActions(): array
{
return [
Action::make('create')->label('Paket anlegen')->schema([
TextInput::make('name')->label('Name')->required(),
])->action(function (array $data): void {
$this->report(function () use ($data): void {
app(BundleService::class)->create($data['name']);
}, 'Das Paket ist angelegt.');
}),
Action::make('create')->label('Paket anlegen')
->modalHeading('Neues Paket')
->modalDescription('Der Name genügt. Bestandteile stellst du danach am Paket zusammen.')
->modalSubmitActionLabel('Paket anlegen')
->schema([
TextInput::make('name')->label('Name')->required(),
])->action(function (array $data): void {
$bundle = null;
$this->report(function () use ($data, &$bundle): void {
$bundle = app(BundleService::class)->create($data['name']);
}, 'Das Paket ist angelegt.');
if ($bundle instanceof Bundle) {
$this->redirect(BundleResource::getUrl('view', ['record' => $bundle]));
}
}),
];
}
protected function catalogRows(): array
{
$rows = [];
foreach (Bundle::query()->with(['versions.items'])->orderBy('name')->get() as $bundle) {
$versions = $bundle->versions->sortByDesc('number');
$published = $versions->first(fn ($version): bool => StatusValue::of($version->status) === BundleStatus::Veroeffentlicht->value);
$draft = $versions->first(fn ($version): bool => StatusValue::of($version->status) === BundleStatus::Entwurf->value);
$chips = [];
$zustand = [];
if ($published !== null) {
$chips[] = ['label' => 'Fassung '.$published->number.' veröffentlicht', 'ton' => 'gut'];
$chips[] = ['label' => $published->items->count() === 1 ? '1 Bestandteil' : $published->items->count().' Bestandteile', 'ton' => 'leise'];
$zustand[] = 'veroeffentlicht';
} else {
$chips[] = ['label' => $versions->isEmpty() ? 'Noch keine Fassung' : 'Noch nicht veröffentlicht', 'ton' => 'offen'];
$zustand[] = 'ohne';
}
if ($draft !== null) {
$chips[] = ['label' => 'Fassung '.$draft->number.' in Arbeit', 'ton' => 'offen'];
$zustand[] = 'entwurf';
}
if ($bundle->archived_at !== null) {
$chips[] = ['label' => 'Archiviert', 'ton' => 'leise'];
$zustand[] = 'archiviert';
}
$url = BundleResource::getUrl('view', ['record' => $bundle]);
$rows[] = [
'schluessel' => 'p'.$bundle->id,
'titel' => $bundle->name,
'meta' => 'Paket',
'symbol' => 'modul',
'url' => $url,
'chips' => $chips,
'zustand' => $zustand,
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
];
}
return $rows;
}
protected function zustandOptionen(): array
{
return ['alle' => 'Jeder Zustand', 'veroeffentlicht' => 'Veröffentlicht', 'ohne' => 'Noch nicht veröffentlicht', 'entwurf' => 'Fassung in Arbeit', 'archiviert' => 'Archiviert'];
}
protected function einheit(): array
{
return ['Paket', 'Pakete'];
}
protected function leer(): array
{
return ['titel' => 'Noch keine Pakete', 'text' => 'Mit „Paket anlegen“ oben entsteht das erste Paket.'];
}
}
@@ -3,15 +3,24 @@
namespace App\Filament\Resources\LicenseArticles\Pages;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\PresentationMedia;
use App\Domain\Catalog\ReleaseStatus;
use App\Domain\Catalog\StatusValue;
use App\Domain\Media\ThumbnailRef;
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
use App\Filament\Support\ListsCatalog;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\DB;
class ListLicenseArticles extends ListRecords
{
use ListsCatalog;
use ReportsDomainRules;
protected static string $resource = LicenseArticleResource::class;
@@ -26,15 +35,118 @@ protected function getHeaderActions(): array
return [
Action::make('create')
->label('Artikel anlegen')
->modalHeading('Neuer Lizenzartikel')
->modalDescription('Kennung und Produktlinie genügen. Titel, Texte und Stand pflegst du danach am Artikel.')
->modalSubmitActionLabel('Artikel anlegen')
->schema([
TextInput::make('code')->label('Kennung')->required(),
TextInput::make('product_line')->label('Produktlinie'),
])
->action(function (array $data): void {
$this->report(function () use ($data): void {
app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null);
$article = null;
$this->report(function () use ($data, &$article): void {
$article = app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null);
}, 'Der Lizenzartikel ist angelegt.');
if ($article instanceof LicenseArticle) {
$this->redirect(LicenseArticleResource::getUrl('view', ['record' => $article]));
}
}),
];
}
protected function catalogRows(): array
{
$offered = DB::table('resolved_scopes')
->join('offer_versions', 'offer_versions.id', '=', 'resolved_scopes.offer_version_id')
->where('offer_versions.status', 'aktiv')
->distinct()
->pluck('resolved_scopes.license_article_id')
->map(fn (mixed $id): int => (int) $id)
->all();
$presentation = app(PresentationMedia::class);
$rows = [];
foreach (LicenseArticle::query()->with(['currentRelease', 'releases'])->orderBy('code')->get() as $article) {
$current = $article->currentRelease;
$currentStatus = $current !== null ? StatusValue::of($current->status) : null;
$draft = $article->releases->first(fn ($release): bool => StatusValue::of($release->status) === ReleaseStatus::Entwurf->value);
$chips = [];
$zustand = [];
if ($current === null) {
$chips[] = ['label' => 'Noch kein Stand', 'ton' => 'offen'];
$zustand[] = 'ohne';
} elseif ($currentStatus === ReleaseStatus::Gesperrt->value) {
$chips[] = ['label' => 'Stand '.$current->number.' gesperrt', 'ton' => 'achtung'];
$zustand[] = 'gesperrt';
} else {
$chips[] = ['label' => 'Stand '.$current->number.' veröffentlicht', 'ton' => 'gut'];
$zustand[] = 'stand';
}
if ($draft !== null) {
$chips[] = ['label' => 'Stand '.$draft->number.' in Arbeit', 'ton' => 'offen'];
$zustand[] = 'entwurf';
}
$inOffer = in_array($article->id, $offered, true);
$chips[] = $inOffer ? ['label' => 'In einem aktiven Angebot', 'ton' => 'gut'] : ['label' => 'In keinem aktiven Angebot', 'ton' => 'leise'];
$zustand[] = $inOffer ? 'angebot' : 'ohne-angebot';
if ($article->archived_at !== null) {
$chips[] = ['label' => 'Archiviert', 'ton' => 'leise'];
$zustand[] = 'archiviert';
}
$coverId = $presentation->coverElementId($article);
$cover = $coverId !== null ? ContentElement::query()->find($coverId) : null;
$title = trim((string) ($article->display_title ?: $article->working_title)) ?: $article->code;
$url = LicenseArticleResource::getUrl('view', ['record' => $article]);
$rows[] = [
'schluessel' => 'a'.$article->id,
'titel' => $title,
'meta' => 'Lizenzartikel · '.$article->code.(filled($article->product_line) ? ' · '.$article->product_line : ''),
'text' => trim((string) ($article->teaser ?: $article->summary)),
'bild' => $cover !== null ? ThumbnailRef::url('editorial.card', 'element', $cover->id, $cover->thumbnail_path) : null,
'symbol' => 'dokument',
'url' => $url,
'chips' => $chips,
'zustand' => $zustand,
'suchtext' => implode(' ', array_filter([$article->code, $article->working_title, $article->display_title, $article->summary, $article->product_line, $article->search_terms])),
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
];
}
return $rows;
}
protected function zustandOptionen(): array
{
return [
'alle' => 'Jeder Zustand',
'stand' => 'Mit veröffentlichtem Stand',
'ohne' => 'Noch ohne Stand',
'entwurf' => 'Stand in Arbeit',
'gesperrt' => 'Gesperrter Stand',
'angebot' => 'In einem aktiven Angebot',
'ohne-angebot' => 'In keinem aktiven Angebot',
'archiviert' => 'Archiviert',
];
}
protected function einheit(): array
{
return ['Lizenzartikel', 'Lizenzartikel'];
}
protected function leer(): array
{
return ['titel' => 'Noch keine Lizenzartikel', 'text' => 'Mit „Artikel anlegen“ oben entsteht der erste Artikel.'];
}
protected function suchPlatzhalter(): string
{
return 'Kennung, Titel oder Produktlinie';
}
}
@@ -2,8 +2,13 @@
namespace App\Filament\Resources\Offers\Pages;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\OfferStatus;
use App\Domain\Catalog\OfferVersion;
use App\Domain\Catalog\StatusValue;
use App\Filament\Resources\Offers\OfferResource;
use App\Filament\Support\ListsCatalog;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
@@ -12,6 +17,7 @@
class ListOffers extends ListRecords
{
use ListsCatalog;
use ReportsDomainRules;
protected static string $resource = OfferResource::class;
@@ -24,13 +30,94 @@ public function getSubheading(): string|Htmlable|null
protected function getHeaderActions(): array
{
return [
Action::make('create')->label('Angebot anlegen')->schema([
TextInput::make('name')->label('Name')->required(),
])->action(function (array $data): void {
$this->report(function () use ($data): void {
app(OfferService::class)->create($data['name']);
}, 'Das Angebot ist angelegt.');
}),
Action::make('create')->label('Angebot anlegen')
->modalHeading('Neues Angebot')
->modalDescription('Der Name genügt. Positionen, Vergabe und Preis legst du danach am Angebot fest.')
->modalSubmitActionLabel('Angebot anlegen')
->schema([
TextInput::make('name')->label('Name')->required(),
])->action(function (array $data): void {
$offer = null;
$this->report(function () use ($data, &$offer): void {
$offer = app(OfferService::class)->create($data['name']);
}, 'Das Angebot ist angelegt.');
if ($offer instanceof Offer) {
$this->redirect(OfferResource::getUrl('view', ['record' => $offer]));
}
}),
];
}
protected function catalogRows(): array
{
$rows = [];
foreach (Offer::query()->with(['versions.lines.article', 'versions.lines.bundleVersion.bundle', 'versions.lines.rights.profile'])->orderBy('name')->get() as $offer) {
$versions = $offer->versions->sortByDesc('number');
$active = $versions->first(fn ($version): bool => StatusValue::of($version->status) === OfferStatus::Aktiv->value);
$ended = $versions->filter(fn ($version): bool => StatusValue::of($version->status) === OfferStatus::Beendet->value)->count();
$chips = [];
$zustand = [];
$text = '';
if ($active !== null) {
$chips[] = ['label' => 'Fassung '.$active->number.' aktiv', 'ton' => 'gut'];
$chips[] = ['label' => $this->vergabe($active), 'ton' => 'neutral'];
$zustand[] = 'aktiv';
$text = $active->lines->map(fn ($line): string => ($line->article !== null
? 'Lizenzartikel '.$line->article->code
: 'Paket '.($line->bundleVersion?->bundle?->name ?? '–')).' · '.($line->rights?->profile?->name ?? ''))->implode('; ');
} else {
$chips[] = ['label' => 'Keine aktive Fassung', 'ton' => 'offen'];
$zustand[] = 'ohne';
}
if ($ended > 0) {
$chips[] = ['label' => $ended === 1 ? '1 beendete Fassung' : $ended.' beendete Fassungen', 'ton' => 'leise'];
}
$url = OfferResource::getUrl('view', ['record' => $offer]);
$rows[] = [
'schluessel' => 'o'.$offer->id,
'titel' => $offer->name,
'meta' => 'Angebot',
'text' => $text,
'symbol' => 'etikett',
'url' => $url,
'chips' => $chips,
'zustand' => $zustand,
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
];
}
return $rows;
}
private function vergabe(OfferVersion $version): string
{
$kind = match ($version->grant_kind) {
'kauf' => 'Kauf',
'auf_abruf' => 'Auf Abruf',
'bei_registrierung' => 'Bei Registrierung',
default => (string) $version->grant_kind,
};
return $version->price_cents === null ? $kind : $kind.' · '.number_format($version->price_cents / 100, 2, ',', '.').' €';
}
protected function zustandOptionen(): array
{
return ['alle' => 'Jeder Zustand', 'aktiv' => 'Mit aktiver Fassung', 'ohne' => 'Ohne aktive Fassung'];
}
protected function einheit(): array
{
return ['Angebot', 'Angebote'];
}
protected function leer(): array
{
return ['titel' => 'Noch keine Angebote', 'text' => 'Mit „Angebot anlegen“ oben entsteht das erste Angebot.'];
}
}
@@ -7,9 +7,13 @@
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\OfferStatus;
use App\Domain\Catalog\OfferVersion;
use App\Domain\Catalog\RightsProfileVersion;
use App\Domain\Catalog\StatusValue;
use App\Filament\Resources\Offers\OfferResource;
use App\Filament\Support\CatalogOptions;
use App\Filament\Support\CatalogReading;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\Repeater;
@@ -17,17 +21,75 @@
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ViewRecord;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\View;
use Filament\Schemas\Schema;
use Filament\Support\Enums\Width;
use Illuminate\Contracts\Support\Htmlable;
/**
* Angebot im gemeinsamen Rahmen. Anlegen und Ändern nutzen dieselbe Maske (FACH-20): „Fassung aktivieren“ legt die
* nächste, danach unveränderliche Angebotsfassung an; bei einer Änderung ist die Maske mit der aktiven Fassung
* vorbelegt (FACH-08). Die Wirkung bleibt die bestehende von OfferService::activate.
*/
class ViewOffer extends ViewRecord
{
use ReportsDomainRules;
protected static string $resource = OfferResource::class;
public function getTitle(): string|Htmlable
{
return (string) $this->getRecord()->name;
}
public function getHeading(): string|Htmlable
{
return '';
}
public function getMaxContentWidth(): Width|string|null
{
return Width::Full;
}
protected function getHeaderActions(): array
{
return [
Action::make('activate')->label('Fassung aktivieren')->schema([
return [];
}
public function infolist(Schema $schema): Schema
{
return $schema->components([
View::make('filament.catalog.angebot')->viewData(fn (): array => $this->angebotDaten())->columnSpanFull(),
])->columns(1);
}
public function activeVersion(): ?OfferVersion
{
/** @var Offer $offer */
$offer = $this->getRecord();
return $offer->versions()
->where('status', OfferStatus::Aktiv)
->orderByDesc('number')
->with(['lines.article', 'lines.bundleVersion.bundle', 'lines.rights.profile'])
->first();
}
public function activateAction(): Action
{
return Action::make('activate')
->label(fn (): string => $this->activeVersion() !== null ? 'Geänderte Fassung aktivieren' : 'Fassung aktivieren')
->modalHeading(fn (): string => $this->activeVersion() !== null
? 'Angebot ändern: Fassung '.$this->nextNumber().' aktivieren'
: 'Erste Fassung aktivieren')
->modalDescription(fn (): string => ($active = $this->activeVersion()) !== null
? 'Die Maske ist mit Fassung '.$active->number.' vorbelegt. Beim Aktivieren wird Fassung '.$active->number.' beendet und bleibt unverändert gespeichert; neue Erwerbe nutzen Fassung '.$this->nextNumber().'. Bereits begründete Berechtigungen ändern sich dadurch nicht.'
: 'Positionen, Vergabe und Preis bilden die erste Fassung. Nach dem Aktivieren ist sie unveränderlich; Änderungen ergeben eine weitere Fassung.')
->modalSubmitActionLabel(fn (): string => 'Fassung '.$this->nextNumber().' aktivieren')
->modalWidth('4xl')
->fillForm(fn (): array => $this->formFromActive())
->schema([
Select::make('grant_kind')->label('Vergabe')->options([
'kauf' => 'Kauf',
'auf_abruf' => 'Auf Abruf',
@@ -57,9 +119,10 @@ protected function getHeaderActions(): array
Select::make('bundle_version_id')->label('Paketfassung')->options(fn (): array => CatalogOptions::bundleVersions())
->visible(fn (Get $get): bool => $get('kind') === 'bundle'),
Select::make('rights_id')->label('Rechte')->options(fn (): array => CatalogOptions::rights())->required(),
])->minItems(1),
])->action(function (array $data): void {
$this->report(function () use ($data): void {
])->minItems(1)->addActionLabel('Position hinzufügen'),
])
->action(function (array $data): void {
$this->report(function () use ($data): string {
/** @var Offer $offer */
$offer = $this->getRecord();
$lines = [];
@@ -74,16 +137,93 @@ protected function getHeaderActions(): array
];
}
app(OfferService::class)->activate($offer, $lines, [
$version = app(OfferService::class)->activate($offer, $lines, [
'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,
]);
return 'Fassung '.$version->number.' ist aktiv.';
}, 'Die Angebotsfassung ist aktiv.');
$this->getRecord()->unsetRelations();
$this->getRecord()->refresh();
}),
});
}
/**
* Vorbelegung aus der aktiven Fassung; ohne aktive Fassung eine leere Position.
*
* @return array<string, mixed>
*/
private function formFromActive(): array
{
$active = $this->activeVersion();
if ($active === null) {
return ['grant_kind' => 'kauf', 'lines' => [['kind' => 'article']]];
}
return [
'grant_kind' => $active->grant_kind,
'price_cents' => $active->price_cents,
'lines' => $active->lines->sortBy('position')->map(fn ($line): array => [
'kind' => $line->license_article_id !== null ? 'article' : 'bundle',
'article_id' => $line->license_article_id,
'bundle_version_id' => $line->bundle_version_id,
'rights_id' => $line->rights_profile_version_id,
])->values()->all(),
];
}
private function nextNumber(): int
{
return ((int) $this->getRecord()->versions()->max('number')) + 1;
}
/**
* @return array<string, mixed>
*/
private function angebotDaten(): array
{
/** @var Offer $offer */
$offer = $this->getRecord();
$active = $this->activeVersion();
$reading = app(CatalogReading::class);
$versions = $offer->versions()->orderByDesc('number')->get();
return [
'offer' => $offer,
'active' => $active,
'grants' => $active !== null ? $reading->offerGrants($offer) : [],
'versions' => $versions->map(fn (OfferVersion $version): array => [
'number' => $version->number,
'status' => match (StatusValue::of($version->status)) {
'aktiv' => 'Aktiv',
'beendet' => 'Beendet',
default => 'Entwurf',
},
'ton' => match (StatusValue::of($version->status)) {
'aktiv' => 'gut',
'beendet' => 'leise',
default => 'offen',
},
'vergabe' => $this->vergabe($version),
'wann' => $version->activated_at?->format('d.m.Y'),
])->all(),
'vergabe' => $active !== null ? $this->vergabe($active) : null,
];
}
private function vergabe(OfferVersion $version): string
{
$kind = match ($version->grant_kind) {
'kauf' => 'Kauf',
'auf_abruf' => 'Auf Abruf',
'bei_registrierung' => 'Bei Registrierung',
default => (string) $version->grant_kind,
};
return $version->price_cents === null ? $kind : $kind.' · '.number_format($version->price_cents / 100, 2, ',', '.').' €';
}
}
@@ -3,7 +3,9 @@
namespace App\Filament\Resources\RightsProfiles\Pages;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\RightsProfile;
use App\Filament\Resources\RightsProfiles\RightsProfileResource;
use App\Filament\Support\ListsCatalog;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\CheckboxList;
@@ -14,8 +16,22 @@
class ListRightsProfiles extends ListRecords
{
use ListsCatalog;
use ReportsDomainRules;
/** Lesbare Fähigkeiten; dieselben Werte wie im Anlegedialog. */
public const FAEHIGKEITEN = [
'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 herunterladen',
'text:ansehen' => 'Text ansehen',
'bild:ansehen' => 'Bild ansehen',
];
protected static string $resource = RightsProfileResource::class;
public function getSubheading(): string|Htmlable|null
@@ -26,36 +42,90 @@ public function getSubheading(): string|Htmlable|null
protected function getHeaderActions(): array
{
return [
Action::make('create')->label('Rechteprofil anlegen')->schema([
TextInput::make('name')->label('Name')->required(),
Select::make('purpose')->label('Zweck')->options([
'ehrenamtlich' => 'Ehrenamtlich',
'kommerziell' => 'Kommerziell',
'institutionell' => 'Institutionell',
])->required(),
CheckboxList::make('capabilities')->label('Fähigkeiten')->options([
'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 herunterladen',
'text:ansehen' => 'Text ansehen',
'bild:ansehen' => 'Bild ansehen',
])->required(),
])->action(function (array $data): void {
$this->report(function () use ($data): void {
$capabilities = [];
Action::make('create')->label('Rechteprofil anlegen')
->modalHeading('Neues Rechteprofil')
->modalDescription('Zweck und erlaubte Handlungen. Ein Angebot verbindet das Profil später mit Artikeln.')
->modalSubmitActionLabel('Rechteprofil anlegen')
->schema([
TextInput::make('name')->label('Name')->required(),
Select::make('purpose')->label('Zweck')->options([
'ehrenamtlich' => 'Ehrenamtlich',
'kommerziell' => 'Kommerziell',
'institutionell' => 'Institutionell',
])->required(),
CheckboxList::make('capabilities')->label('Fähigkeiten')->options(self::FAEHIGKEITEN)->required(),
])->action(function (array $data): void {
$this->report(function () use ($data): void {
$capabilities = [];
foreach ($data['capabilities'] as $entry) {
[$class, $action] = explode(':', $entry, 2);
$capabilities[$class][] = $action;
}
foreach ($data['capabilities'] as $entry) {
[$class, $action] = explode(':', $entry, 2);
$capabilities[$class][] = $action;
}
app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities);
}, 'Das Rechteprofil ist angelegt.');
}),
app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities);
}, 'Das Rechteprofil ist angelegt.');
}),
];
}
protected function catalogRows(): array
{
$rows = [];
foreach (RightsProfile::query()->with('versions')->orderBy('name')->get() as $profile) {
$version = $profile->versions->sortByDesc('number')->first();
$faehigkeiten = [];
foreach ($version?->capabilities ?? [] as $class => $actions) {
foreach ((array) $actions as $action) {
$faehigkeiten[] = self::FAEHIGKEITEN[$class.':'.$action] ?? $class.': '.$action;
}
}
$purpose = match ((string) $version?->purpose) {
'ehrenamtlich' => 'Ehrenamtlich',
'kommerziell' => 'Kommerziell',
'institutionell' => 'Institutionell',
default => (string) $version?->purpose,
};
$chips = $version === null
? [['label' => 'Noch keine Fassung', 'ton' => 'offen']]
: [['label' => 'Fassung '.$version->number, 'ton' => 'neutral'], ['label' => $purpose, 'ton' => 'leise']];
if ($version?->locked_at !== null) {
$chips[] = ['label' => 'Festgeschrieben', 'ton' => 'leise'];
}
$url = RightsProfileResource::getUrl('view', ['record' => $profile]);
$rows[] = [
'schluessel' => 'r'.$profile->id,
'titel' => $profile->name,
'meta' => 'Rechteprofil',
'text' => $faehigkeiten === [] ? 'Keine Fähigkeiten' : implode(', ', $faehigkeiten),
'symbol' => 'schluessel',
'url' => $url,
'chips' => $chips,
'zustand' => [(string) $version?->purpose],
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
];
}
return $rows;
}
protected function zustandOptionen(): array
{
return ['alle' => 'Jeder Zweck', 'ehrenamtlich' => 'Ehrenamtlich', 'kommerziell' => 'Kommerziell', 'institutionell' => 'Institutionell'];
}
protected function einheit(): array
{
return ['Rechteprofil', 'Rechteprofile'];
}
protected function leer(): array
{
return ['titel' => 'Noch keine Rechteprofile', 'text' => 'Mit „Rechteprofil anlegen“ oben entsteht das erste Profil.'];
}
}
+90
View File
@@ -0,0 +1,90 @@
<?php
namespace App\Filament\Support;
use Filament\Schemas\Components\View;
use Filament\Schemas\Schema;
use Filament\Support\Enums\Width;
use Livewire\Attributes\Url;
/**
* Kataloglisten (Lizenzartikel, Pakete, Rechteprofile, Angebote) in der gemeinsamen Bestandsliste. Die Seite liefert
* Zeilen mit 'suchtext' und 'zustand' (Liste von Zustandsschlüsseln) sowie die Zustandsoptionen.
*/
trait ListsCatalog
{
use ShowsBestand;
#[Url(as: 'suche', except: '')]
public string $suche = '';
#[Url(as: 'zustand', except: 'alle')]
public string $zustand = 'alle';
/**
* @return list<array<string, mixed>>
*/
abstract protected function catalogRows(): array;
/**
* @return array<string, string> Zustandsschlüssel => Bezeichnung, beginnend mit 'alle'
*/
abstract protected function zustandOptionen(): array;
/**
* @return array{0: string, 1: string}
*/
abstract protected function einheit(): array;
/**
* @return array{titel: string, text: string}
*/
abstract protected function leer(): array;
protected function suchPlatzhalter(): string
{
return 'Name oder Beschreibung';
}
public function getMaxContentWidth(): Width|string|null
{
return Width::Full;
}
public function content(Schema $schema): Schema
{
return $schema->components([View::make('filament.verwaltung.bestand')]);
}
public function resetFilters(): void
{
$this->suche = '';
$this->zustand = 'alle';
$this->bestandGrenze = Bestand::SCHRITT;
}
/**
* @return array<string, mixed>
*/
public function bestand(): array
{
$needle = mb_strtolower(trim($this->suche));
$rows = array_values(array_filter($this->catalogRows(), function (array $row) use ($needle): bool {
if ($this->zustand !== 'alle' && ! in_array($this->zustand, $row['zustand'] ?? [], true)) {
return false;
}
return $needle === '' || str_contains(mb_strtolower(implode(' ', array_filter([
$row['titel'], $row['meta'] ?? '', $row['text'] ?? '', $row['suchtext'] ?? '',
]))), $needle);
}));
return [
'suche' => ['eigenschaft' => 'suche', 'label' => 'Suche', 'platzhalter' => $this->suchPlatzhalter()],
'filter' => [['eigenschaft' => 'zustand', 'label' => 'Zustand', 'vorgabe' => 'alle', 'optionen' => $this->zustandOptionen()]],
'zeilen' => $rows,
'einheit' => $this->einheit(),
'leer' => $this->leer(),
];
}
}