Ein Foto gehoert zu keinem (ganzjaehrig) oder mehreren Erscheinungsbildern und erscheint nur dort, vor den ganzjaehrigen Fotos. Bausteine waehlen "automatisch" oder eine eigene Auswahl; Titelbereich und Abschluss zeigen das erste passende Foto ihrer Liste. Titelbild und "Bilder je Baustein" des Erscheinungsbilds werden in die Bausteine uebernommen und entfallen dort. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
4.2 KiB
PHP
97 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Photos\Tables;
|
|
|
|
use App\Enums\PhotoCategory;
|
|
use App\Filament\Resources\Photos\Schemas\PhotoForm;
|
|
use App\Models\Appearance;
|
|
use App\Models\Photo;
|
|
use Filament\Actions\BulkAction;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\Layout\Stack;
|
|
use Filament\Tables\Columns\SpatieMediaLibraryImageColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
class PhotosTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->reorderable('sort_order')
|
|
->defaultSort('sort_order')
|
|
->contentGrid(['md' => 3, 'xl' => 4])
|
|
->paginated([24, 48, 'all'])
|
|
->columns([
|
|
Stack::make([
|
|
SpatieMediaLibraryImageColumn::make('image')
|
|
->collection(Photo::COLLECTION)
|
|
->conversion('sm')
|
|
->imageHeight(180)
|
|
->extraImgAttributes(['class' => 'w-full object-cover rounded-lg']),
|
|
TextColumn::make('alt_text')
|
|
->weight('medium')
|
|
->searchable(),
|
|
TextColumn::make('category')
|
|
->badge(),
|
|
TextColumn::make('appearance_ids')
|
|
->label('Zeigen in')
|
|
->state(fn (Photo $record): array => $record->appearanceNames())
|
|
->badge()
|
|
->color('warning')
|
|
->icon('heroicon-m-sun'),
|
|
IconColumn::make('is_published')
|
|
->boolean()
|
|
->trueIcon('heroicon-o-eye')
|
|
->falseIcon('heroicon-o-eye-slash'),
|
|
])->space(2),
|
|
])
|
|
->filters([
|
|
SelectFilter::make('category')
|
|
->label('Kategorie')
|
|
->options(PhotoCategory::class),
|
|
SelectFilter::make('season')
|
|
->label('Zeigen in')
|
|
->options(fn (): array => ['all_year' => 'ganzjährig', ...Appearance::photoOptions()])
|
|
->query(fn (Builder $query, array $data): Builder => match (true) {
|
|
blank($data['value'] ?? null) => $query,
|
|
$data['value'] === 'all_year' => $query->where(fn (Builder $query) => $query->whereNull('appearance_ids')->orWhereJsonLength('appearance_ids', 0)),
|
|
default => $query->whereJsonContains('appearance_ids', (int) $data['value']),
|
|
}),
|
|
])
|
|
->recordActions([
|
|
EditAction::make(),
|
|
DeleteAction::make(),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
BulkAction::make('seasons')
|
|
->label('Zeigen in …')
|
|
->icon('heroicon-o-sun')
|
|
->schema([
|
|
Select::make('appearance_ids')
|
|
->label('Zeigen in')
|
|
->multiple()
|
|
->options(fn (): array => Appearance::photoOptions())
|
|
->placeholder('ganzjährig')
|
|
->helperText('Leer = ganzjährig. Ersetzt die bisherige Zuordnung der ausgewählten Fotos.'),
|
|
])
|
|
->action(function (Collection $records, array $data): void {
|
|
$records->each(fn (Photo $photo) => $photo->update(['appearance_ids' => PhotoForm::appearanceIds($data['appearance_ids'] ?? [])]));
|
|
})
|
|
->authorizeIndividualRecords('update')
|
|
->deselectRecordsAfterCompletion(),
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
}
|