wip ss tournament active disabled

This commit is contained in:
salam committed 2026-06-25 13:59:49 +02:00
1 parent eae94f1d42
commit 537cdd1b31
2 files changed
+96 -32

No files matched your search

@@ -11,6 +11,8 @@ use Filament\Actions\BulkAction;
use Filament\Actions\BulkActionGroup;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Components\ToggleButtons;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Support\Enums\IconSize;
use Filament\Tables\Columns\IconColumn;
@@ -18,7 +20,6 @@ use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ToggleColumn;
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
@@ -29,30 +30,32 @@ class SofaScoreTournamentsTable
{
return $table
->headerActions([
Action::make('soccer')
Action::make('grapping')
->icon('phosphor-power')
->requiresConfirmation()
->modalDescription('This will disable all leagues for soccer')
->action(fn () => SofaScoreTournament::where('sport_id', 1)->update(['enabled' => 0])
),
Action::make('ice-hockey')
->tooltip('Will stop grapping for selected sport')
->schema([
Select::make('sport')
->options(Sport::where('is_active', 1)
->pluck('name', 'id'))
->required(),
])
->action(function (array $data): void {
$sport_id = $data['sport_id'];
SofaScoreTournament::where('sport_id', $sport_id)->update(['enabled' => 0]);
}),
Action::make('disabled')
->icon('phosphor-power')
->requiresConfirmation()
->modalDescription('This will disable all leagues for ice hockey')
->action(fn () => SofaScoreTournament::where('sport_id', 2)->update(['enabled' => 0])
),
Action::make('basketball')
->icon('phosphor-power')
->requiresConfirmation()
->modalDescription('This will disable all leagues for basketball')
->action(fn () => SofaScoreTournament::where('sport_id', 3)->update(['enabled' => 0])
),
Action::make('tennis')
->icon('phosphor-power')
->requiresConfirmation()
->modalDescription('This will disable all leagues for tennis')
->action(fn () => SofaScoreTournament::where('sport_id', 5)->update(['enabled' => 0])
),
->tooltip('Will activate all disabled leagues for selected sport')
->schema([
Select::make('sport')
->options(Sport::where('is_active', 1)
->pluck('name', 'id'))
->required(),
])
->action(function (array $data): void {
$sport_id = $data['sport_id'];
SofaScoreTournament::where('sport_id', $sport_id)->update(['disabled' => 0]);
}),
])
->poll()
->columns([
@@ -70,11 +73,12 @@ class SofaScoreTournamentsTable
TextColumn::make('sofascore_category.name')
->icon(fn ($record) => $record->sofascore_category->country->icon),
TextColumn::make('name')->searchable()->sortable(),
ToggleColumn::make('enabled'),
ToggleColumn::make('enabled')->label('Enable'),
ToggleColumn::make('disabled')->label('Disable'),
])
->filters([
Filter::make('filters')
->columns(3)->columnSpan(3)
->columns(7)->columnSpan(7)
->schema([
Select::make('sport_id')
->default(1)
@@ -88,6 +92,7 @@ class SofaScoreTournamentsTable
Select::make('sofa_score_categorie_id')
->searchable()
->multiple()
->columnSpan(2)
->label('Categorie')
->options(function (Get $get) {
$res = SofaScoreTournament::where('sport_id', $get('sport_id'))
@@ -98,7 +103,24 @@ class SofaScoreTournamentsTable
return SofaScoreCategorie::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
})
->live(),
DatePicker::make('day')->live(),
ToggleButtons::make('filter-grapping')
->inline()
->columnSpan(2)
->default('active')
->options([
'all' => 'All',
'active' => 'Active',
'disabled' => 'Disabled',
]),
ToggleButtons::make('filter-disabled')
->inline()
->columnSpan(2)
->default('active')
->options([
'all' => 'All',
'active' => 'Active',
'hidden' => 'Hidden',
]),
])
->query(function (Builder $query, array $data): Builder {
return $query->when(
@@ -114,14 +136,31 @@ class SofaScoreTournamentsTable
}
}
)->when(
$data['day'],
function (Builder $query, $day) {
$res = SofaScoreDayTournament::where('day', $day)->pluck('tournament_id')->toArray();
$query->whereIn('tournament_id', $res);
$data['filter-grapping'],
function (Builder $query, $filtergrapping) {
switch ($filtergrapping) {
case 'active':
$query->where('enabled', 1);
break;
case 'disabled':
$query->where('enabled', 0);
break;
}
}
)->when(
$data['filter-disabled'],
function (Builder $query, $filterdisabled) {
switch ($filterdisabled) {
case 'active':
$query->where('disabled', 0);
break;
case 'hidden':
$query->where('disabled', 1);
break;
}
}
);
}),
TernaryFilter::make('enabled')->placeholder('All'),
], layout: FiltersLayout::AboveContent)
->deferFilters(false)
->toolbarActions([
@@ -148,7 +187,31 @@ class SofaScoreTournamentsTable
);
}
}),
]),
])->label('Grapping'),
BulkActionGroup::make([
BulkAction::make('Hide')
->icon('phosphor-toggle-right-fill')
->color('primary')
->action(function (Collection $records): void {
foreach ($records as $record) {
SofaScoreTournament::where('id', '=', $record->id)
->update(
['disabled' => 1]
);
}
}),
BulkAction::make('Show')
->icon('phosphor-toggle-left-fill')
->color('gray')
->action(function (Collection $records): void {
foreach ($records as $record) {
SofaScoreTournament::where('id', '=', $record->id)
->update(
['disabled' => 0]
);
}
}),
])->label('Disabled'),
]);
}
}
@@ -19,6 +19,7 @@ return new class extends Migration
$table->string('slug')->index();
$table->string('name');
$table->boolean('enabled')->index()->default(0);
$table->boolean('disabled')->index()->default(0);
$table->timestamps();
});
}