Files
LarsandCursor cd79fb99d7
Deploy Test / test (push) Successful in 13s
Deploy Test / deploy (push) Successful in 23s
Zeige im Katalog, wie Inhalte, Pakete und Rechte zusammenhängen.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-15 10:03:19 +01:00

80 lines
2.6 KiB
PHP

<?php
namespace App\Filament\Resources\Bundles;
use App\Domain\Catalog\Bundle;
use App\Filament\Resources\Bundles\Pages\ListBundles;
use App\Filament\Resources\Bundles\Pages\ViewBundle;
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
use App\Filament\Support\CatalogReading;
use Filament\Infolists\Components\TextEntry;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Auth\Access\Response;
use Illuminate\Database\Eloquent\Model;
class BundleResource extends Resource
{
protected static ?string $model = Bundle::class;
protected static string|\UnitEnum|null $navigationGroup = 'Katalog';
protected static ?string $navigationLabel = 'Pakete';
protected static ?string $modelLabel = 'Paket';
protected static ?string $pluralModelLabel = 'Pakete';
protected static ?string $recordTitleAttribute = 'name';
protected static ?int $navigationSort = 2;
public static function canViewAny(): bool
{
return LicenseArticleResource::keeper();
}
public static function getViewAuthorizationResponse(Model $record): Response
{
return LicenseArticleResource::keeper() ? Response::allow() : Response::deny();
}
public static function infolist(Schema $schema): Schema
{
return $schema->components([
Section::make('Bestandteile')->description('Was diese Fassung direkt enthält.')->schema([
TextEntry::make('parts')->hiddenLabel()->listWithLineBreaks()
->state(fn (Bundle $record): array => app(CatalogReading::class)->bundleParts($record)),
]),
Section::make('Aufgelöste Lizenzartikel')->description('Darauf werden beim Erwerb die Berechtigungen vergeben.')->schema([
TextEntry::make('articles')->hiddenLabel()->listWithLineBreaks()
->state(fn (Bundle $record): array => app(CatalogReading::class)->bundleArticles($record)),
]),
]);
}
public static function form(Schema $schema): Schema
{
return $schema;
}
public static function table(Table $table): Table
{
return $table->columns([
TextColumn::make('name')->label('Name')->searchable(),
TextColumn::make('versions_count')->counts('versions')->label('Fassungen'),
]);
}
public static function getPages(): array
{
return [
'index' => ListBundles::route('/'),
'view' => ViewBundle::route('/{record}'),
];
}
}