wip fix
This commit is contained in:
1 parent
9bcd4432c6
commit
6f92f9e1d5
1209 files changed
+220940
No files matched your search
+154
@@ -0,0 +1,154 @@
|
||||
<?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')
|
||||
->sortable()
|
||||
->label('')
|
||||
->icon(fn(string $state): string => match ($state) {
|
||||
'1' => 'icon-soccerball',
|
||||
}),
|
||||
TextColumn::make('match_id')->color('info')->icon('phosphor-copy')->copyable()
|
||||
->sortable()
|
||||
->searchable(
|
||||
query: fn($query, $search) => $query->orWhere('match_id', (int) $search)
|
||||
),
|
||||
IconColumn::make('league.sofascore_category.flag')
|
||||
->label('')
|
||||
->icon(function ($state): string {
|
||||
return $state;
|
||||
}),
|
||||
TextColumn::make('league.name')
|
||||
->tooltip(fn($record) => $record->league_id)
|
||||
->sortable(
|
||||
query: fn(Builder $query) => $query->orderBy('name')
|
||||
)
|
||||
->searchable(),
|
||||
TextColumn::make('home.ss_team_name')->color('info')
|
||||
->tooltip(fn($record) => $record->home_id)
|
||||
->sortable()
|
||||
->searchable(),
|
||||
TextColumn::make('away.ss_team_name')->color('success')
|
||||
->tooltip(fn($record) => $record->away_id)
|
||||
->sortable()
|
||||
->searchable(),
|
||||
TextColumn::make('starttime')->dateTime('Y-m-d H:i')
|
||||
->sortable(),
|
||||
])
|
||||
->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(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user