Eine Fassung bleibt nummeriert und kann deaktiviert werden. Beschreibung und fachliche Säulen gehören zum Medium und legen keine neue Fassung an. Co-authored-by: Cursor <cursoragent@cursor.com>
105 lines
3.4 KiB
PHP
105 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ContentElements;
|
|
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Identity\StaffRole;
|
|
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
|
use App\Filament\Resources\ContentElements\Pages\ListContentElements;
|
|
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
|
use App\Models\User;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Auth\Access\Response;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class ContentElementResource extends Resource
|
|
{
|
|
protected static ?string $model = ContentElement::class;
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
|
|
|
protected static ?string $navigationLabel = 'Medien';
|
|
|
|
protected static ?string $modelLabel = 'Medium';
|
|
|
|
protected static ?string $pluralModelLabel = 'Medien';
|
|
|
|
protected static ?string $recordTitleAttribute = 'working_title';
|
|
|
|
protected static ?int $navigationSort = 1;
|
|
|
|
public static function canViewAny(): bool
|
|
{
|
|
$user = Filament::auth()->user();
|
|
|
|
return $user instanceof User && (
|
|
$user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)
|
|
);
|
|
}
|
|
|
|
public static function editor(): bool
|
|
{
|
|
$user = Filament::auth()->user();
|
|
|
|
return $user instanceof User && $user->hasStaffRole(StaffRole::Redakteur);
|
|
}
|
|
|
|
public static function getViewAuthorizationResponse(Model $record): Response
|
|
{
|
|
return self::canViewAny() ? Response::allow() : Response::deny();
|
|
}
|
|
|
|
public static function getEditAuthorizationResponse(Model $record): Response
|
|
{
|
|
return self::editor() ? Response::allow() : Response::deny();
|
|
}
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema;
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table->recordUrl(
|
|
fn (ContentElement $record): string => static::getUrl('view', ['record' => $record])
|
|
)->columns([
|
|
TextColumn::make('working_title')->label('Arbeitstitel')->searchable(),
|
|
TextColumn::make('kind')->label('Art'),
|
|
TextColumn::make('pillar_names')->label('Säulen')->state(
|
|
fn (ContentElement $record): string => $record->pillars->pluck('name')->join(', ') ?: '—'
|
|
),
|
|
TextColumn::make('stand')->label('Aktuelle Fassung')->state(function (ContentElement $record): string {
|
|
$version = $record->versions->sortByDesc('number')->first();
|
|
|
|
if ($version === null) {
|
|
return 'noch keine Fassung';
|
|
}
|
|
|
|
$file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
|
|
|
|
return 'Fassung '.$version->number.(is_string($file) && $file !== '' ? ' · mit Datei' : ' · ohne Datei');
|
|
}),
|
|
]);
|
|
}
|
|
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
return parent::getEloquentQuery()->with(['versions', 'pillars']);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListContentElements::route('/'),
|
|
'view' => ViewContentElement::route('/{record}'),
|
|
'edit' => EditContentElement::route('/{record}/bearbeiten'),
|
|
];
|
|
}
|
|
}
|