80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Offers;
|
|
|
|
use App\Domain\Catalog\Offer;
|
|
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
|
|
use App\Filament\Resources\Offers\Pages\ListOffers;
|
|
use App\Filament\Resources\Offers\Pages\ViewOffer;
|
|
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 OfferResource extends Resource
|
|
{
|
|
protected static ?string $model = Offer::class;
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Katalog';
|
|
|
|
protected static ?string $navigationLabel = 'Angebote';
|
|
|
|
protected static ?string $modelLabel = 'Angebot';
|
|
|
|
protected static ?string $pluralModelLabel = 'Angebote';
|
|
|
|
protected static ?string $recordTitleAttribute = 'name';
|
|
|
|
protected static ?int $navigationSort = 4;
|
|
|
|
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('Positionen')->description('Was angeboten wird, mit welchem Rechteprofil.')->schema([
|
|
TextEntry::make('positions')->hiddenLabel()->listWithLineBreaks()
|
|
->state(fn (Offer $record): array => app(CatalogReading::class)->offerPositions($record)),
|
|
]),
|
|
Section::make('Aufgelöste Berechtigungen')->description('Diese Artikel-Rechte entstehen beim Erwerb.')->schema([
|
|
TextEntry::make('grants')->hiddenLabel()->listWithLineBreaks()
|
|
->state(fn (Offer $record): array => app(CatalogReading::class)->offerGrants($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.status')->label('Fassungen')->badge(),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListOffers::route('/'),
|
|
'view' => ViewOffer::route('/{record}'),
|
|
];
|
|
}
|
|
}
|