148 lines
6.4 KiB
PHP
148 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Clusters\StaticData\Resources\StatistikoEvents\Tables;
|
|
|
|
use App\Models\CompetitionGroup;
|
|
use App\Models\Sport;
|
|
use App\Models\StatistikoEvent;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\Checkbox;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Schemas\Components\Utilities\Get;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\Filter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class StatistikoEventsTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->poll('15s')
|
|
->striped()
|
|
->columns([
|
|
IconColumn::make('sport_id')
|
|
->label('')
|
|
->icon(fn(string $state): string => match ($state) {
|
|
'1' => 'icon-soccerball',
|
|
}),
|
|
TextColumn::make('match_id')
|
|
->sortable(),
|
|
TextColumn::make('league.name')
|
|
->searchable()
|
|
->copyable()
|
|
->copyMessage('Liga name copied')
|
|
->description(fn($record) => ucwords($record->league?->country->name))
|
|
->copyMessageDuration(1500),
|
|
TextColumn::make('home.name')
|
|
->searchable()
|
|
->copyable()
|
|
->copyMessage('Home team name copied')
|
|
->copyMessageDuration(1500),
|
|
TextColumn::make('away.name')
|
|
->searchable()
|
|
->copyable()
|
|
->copyMessage('Away team name copied')
|
|
->copyMessageDuration(1500),
|
|
TextColumn::make('starttime')->dateTime('d.m.Y H:i'),
|
|
|
|
])
|
|
->filters([
|
|
Filter::make('event_filters')
|
|
->columns(5)->columnSpan(5)
|
|
->schema([
|
|
Select::make('sport_id')
|
|
->default(1)
|
|
->options(fn() => Sport::query()->where('is_active', 1)->pluck('name', 'id'))
|
|
->selectablePlaceholder(false)
|
|
->label('Sport')
|
|
->live(),
|
|
Select::make('league_id')
|
|
->options(function (Get $get) {
|
|
if ($get('sport_id')) {
|
|
$leagues = StatistikoEvent::where('sport_id', $get('sport_id'))->groupBy('league_id')->pluck('league_id')->toArray();
|
|
if ($leagues)
|
|
return CompetitionGroup::query()->whereIn('id', $leagues)->orderBy('name')->pluck('name', 'id');
|
|
}
|
|
})
|
|
->preload()
|
|
->searchable()
|
|
->label('League'),
|
|
Select::make('home_id')
|
|
->relationship('home', 'name')
|
|
->searchable()
|
|
->label('Home'),
|
|
Select::make('away_id')
|
|
->relationship('away', 'name')
|
|
->searchable()
|
|
->label('Away'),
|
|
Checkbox::make('find_double'),
|
|
])->query(function (Builder $query, array $data): Builder {
|
|
return $query->when(
|
|
$data['find_double'],
|
|
function (Builder $query) use ($data) {
|
|
if (!$data['sport_id']) {
|
|
$data['sport_id'] = 1;
|
|
}
|
|
StatistikoEvent::where('exp_home', 0)->delete();
|
|
StatistikoEvent::where('exp_away', 0)->delete();
|
|
StatistikoEvent::where('exp_handicap', 0)->delete();
|
|
StatistikoEvent::where('exp_total', 0)->delete();
|
|
|
|
$events = StatistikoEvent::where('sport_id', (int) $data['sport_id'])->pluck('match_id')->toArray();
|
|
$doublEvents = array_diff_assoc(
|
|
$events,
|
|
array_unique($events)
|
|
);
|
|
$query->whereIn('match_id', $doublEvents)->orderBy('match_id');
|
|
}
|
|
)->when(
|
|
$data['sport_id'],
|
|
function (Builder $query, $sport_id) {
|
|
$query->where('sport_id', (int) $sport_id);
|
|
}
|
|
)->when(
|
|
$data['league_id'],
|
|
function (Builder $query, $league_id) {
|
|
$query->where('league_id', (int) $league_id);
|
|
}
|
|
)->when(
|
|
$data['home_id'],
|
|
function (Builder $query, $home_id) {
|
|
$query->where('home_id', (int) $home_id);
|
|
}
|
|
)->when(
|
|
$data['away_id'],
|
|
function (Builder $query, $away_id) {
|
|
$query->where('away_id', (int) $away_id);
|
|
}
|
|
);
|
|
})->indicateUsing(function (array $data): ?string {
|
|
if (! $data['find_double']) {
|
|
return null;
|
|
}
|
|
return 'Find Double';
|
|
}),
|
|
|
|
], layout: FiltersLayout::AboveContent)
|
|
->filtersFormColumns(5)
|
|
->persistFiltersInSession()
|
|
->deferFilters(false)
|
|
->recordActions([
|
|
EditAction::make()->iconButton(),
|
|
DeleteAction::make()->iconButton(),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
}
|