80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Compositions;
|
|
|
|
use App\Domain\Catalog\Composition;
|
|
use App\Filament\Resources\Compositions\Pages\ListCompositions;
|
|
use App\Filament\Resources\Compositions\Pages\ViewComposition;
|
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
|
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 CompositionResource extends Resource
|
|
{
|
|
protected static ?string $model = Composition::class;
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
|
|
|
protected static ?string $navigationLabel = 'Kurse und Übungen';
|
|
|
|
protected static ?string $modelLabel = 'Kurs oder Übung';
|
|
|
|
protected static ?string $pluralModelLabel = 'Kurse und Übungen';
|
|
|
|
protected static ?string $recordTitleAttribute = 'designation';
|
|
|
|
protected static ?int $navigationSort = 2;
|
|
|
|
public static function canViewAny(): bool
|
|
{
|
|
return ContentElementResource::editor();
|
|
}
|
|
|
|
public static function getViewAuthorizationResponse(Model $record): Response
|
|
{
|
|
return ContentElementResource::editor() ? Response::allow() : Response::deny();
|
|
}
|
|
|
|
public static function infolist(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
Section::make('Mitglieder')->description('Geordnete Fassungen, keine Kopie der Dateien.')->schema([
|
|
TextEntry::make('members')->hiddenLabel()->listWithLineBreaks()
|
|
->state(fn (Composition $record): array => app(CatalogReading::class)->compositionMembers($record)),
|
|
]),
|
|
Section::make('Verwendung')->schema([
|
|
TextEntry::make('usage')->hiddenLabel()->listWithLineBreaks()
|
|
->state(fn (Composition $record): array => app(CatalogReading::class)->compositionUsage($record)),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema;
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table->columns([
|
|
TextColumn::make('designation')->label('Bezeichnung')->searchable(),
|
|
TextColumn::make('versions_count')->counts('versions')->label('Fassungen'),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListCompositions::route('/'),
|
|
'view' => ViewComposition::route('/{record}'),
|
|
];
|
|
}
|
|
}
|