From d6a13837c560b329ccaac3d342e5d5f1c3e85941 Mon Sep 17 00:00:00 2001 From: salam Date: Thu, 22 Oct 2026 15:26:07 +0200 Subject: [PATCH] wip --- ...ofaScoreTournamentsTeamRelationManager.php | 69 +++++++++++++++++++ .../SofaScoreTournamentResource.php | 14 ++++ .../Tables/SofaScoreTournamentsTable.php | 46 +++---------- app/Models/SofaScoreRosaTournament.php | 5 ++ app/Models/SofaScoreTournament.php | 5 ++ 5 files changed, 103 insertions(+), 36 deletions(-) create mode 100644 app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/RelationManagers/SofaScoreTournamentsTeamRelationManager.php diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/RelationManagers/SofaScoreTournamentsTeamRelationManager.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/RelationManagers/SofaScoreTournamentsTeamRelationManager.php new file mode 100644 index 00000000..d6ed6198 --- /dev/null +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/RelationManagers/SofaScoreTournamentsTeamRelationManager.php @@ -0,0 +1,69 @@ +components([ + Select::make('ss_team_id') + ->searchable() + ->label('Team') + ->options(function () { + return SofaScoreRosa::query()->orderBy('ss_team_name')->pluck('ss_team_name', 'ss_team_id'); + }), + ]); + } + + public function table(Table $table): Table + { + return $table + ->columns([ + TextColumn::make('ss_tournament_id'), + TextColumn::make('tournament.name')->badge(), + TextColumn::make('ss_team_id'), + TextColumn::make('team.ss_team_name')->color('success'), + ToggleColumn::make('disabled'), + ]) + ->striped() + ->paginated(false) + ->recordActions([ + DeleteAction::make() + ->iconButton(), + ]) + ->headerActions([ + CreateAction::make('Add') + ->label('Add Team') + ->icon('phosphor-plus'), + ]); + } +} diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/SofaScoreTournamentResource.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/SofaScoreTournamentResource.php index 2f14e155..59aabfd3 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/SofaScoreTournamentResource.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/SofaScoreTournamentResource.php @@ -2,7 +2,9 @@ namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments; +use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Pages\EditSofaScoreTournament; use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Pages\ListSofaScoreTournaments; +use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\RelationManagers\SofaScoreTournamentsTeamRelationManager; use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Schemas\SofaScoreTournamentForm; use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Tables\SofaScoreTournamentsTable; use App\Filament\Clusters\StaticData\StaticDataCluster; @@ -27,6 +29,9 @@ class SofaScoreTournamentResource extends Resource protected static ?int $navigationSort = 2; + // Choose where you want the submenu to appear: + // SubNavigationPosition::Start (Left Sidebar) or SubNavigationPosition::Top (Horizontal Tabs) + public static function form(Schema $schema): Schema { return SofaScoreTournamentForm::configure($schema); @@ -59,6 +64,15 @@ class SofaScoreTournamentResource extends Resource { return [ 'index' => ListSofaScoreTournaments::route('/'), + 'edit' => EditSofaScoreTournament::route('/{record}/edit'), + + ]; + } + + public static function getRelations(): array + { + return [ + SofaScoreTournamentsTeamRelationManager::class, ]; } } diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php index 9a8aaf21..bf23645a 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php @@ -2,16 +2,11 @@ namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Tables; -use App\Models\SofaScoreRosa; -use App\Models\SofaScoreRosaTournament; -use App\Models\SofaScoreTournament; -use Filament\Actions\Action; +use Filament\Actions\EditAction; use Filament\Forms\Components\Toggle; -use Filament\Notifications\Notification; use Filament\Support\Enums\IconSize; use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\TextColumn; -use Filament\Tables\Columns\TextInputColumn; use Filament\Tables\Columns\ToggleColumn; use Filament\Tables\Enums\FiltersLayout; use Filament\Tables\Filters\Filter; @@ -23,31 +18,6 @@ class SofaScoreTournamentsTable public static function configure(Table $table): Table { return $table - ->headerActions([ - Action::make('update_rose_tornaments') - ->label('Update Roosters') - ->action(function () { - $res = SofaScoreTournament::whereNotNull('ss_liga_code')->where('ss_liga_code', '<>', '')->where('enabled', 1)->pluck('ss_liga_code', 'tournament_id'); - - foreach ($res as $tournament_id => $ss_liga_code) { - SofaScoreRosaTournament::where('ss_tournament_id', $tournament_id)->update(['grapped' => 0, 'disabled' => 1]); - - $rosa = SofaScoreRosa::where('cc', $ss_liga_code)->where('is_active', 1)->get(); - - foreach ($rosa as $team) { - SofaScoreRosaTournament::updateOrCreate( - ['ss_team_id' => $team->ss_team_id, 'ss_tournament_id' => $tournament_id], - ['disabled' => 0] - ); - } - } - }) - ->successNotification( - Notification::make() - ->success() - ->title('Tournament Roosters table updated') - ), - ]) ->columns([ IconColumn::make('sport.icon') ->label('') @@ -69,10 +39,10 @@ class SofaScoreTournamentsTable ->searchable() ->icon(fn ($record) => $record->sofascore_category->flag) ->sortable(), - TextInputColumn::make('ss_liga_code') - ->label('SofaScore Liga Code') - ->searchable() - ->sortable(), + // TextInputColumn::make('ss_liga_code') + // ->label('SofaScore Liga Code') + // ->searchable() + // ->sortable(), TextColumn::make('name') ->searchable() ->sortable(), @@ -98,6 +68,10 @@ class SofaScoreTournamentsTable ); }), ], layout: FiltersLayout::AboveContent) - ->deferFilters(false); + ->deferFilters(false) + ->recordActions([ + EditAction::make() + ->iconButton(), + ]); } } diff --git a/app/Models/SofaScoreRosaTournament.php b/app/Models/SofaScoreRosaTournament.php index cec3f62d..d3a50519 100644 --- a/app/Models/SofaScoreRosaTournament.php +++ b/app/Models/SofaScoreRosaTournament.php @@ -21,4 +21,9 @@ class SofaScoreRosaTournament extends Model { return $this->belongsTo(SofaScoreTournament::class, 'ss_tournament_id', 'tournament_id'); } + + public function team() + { + return $this->belongsTo(SofaScoreRosa::class, 'ss_team_id', 'ss_team_id'); + } } diff --git a/app/Models/SofaScoreTournament.php b/app/Models/SofaScoreTournament.php index 28724450..6377d27a 100644 --- a/app/Models/SofaScoreTournament.php +++ b/app/Models/SofaScoreTournament.php @@ -31,4 +31,9 @@ class SofaScoreTournament extends Model { return $this->belongsTo(SofaScoreCategory::class, 'sofa_score_category_id', 'id'); } + + public function rosa_tournament() + { + return $this->belongsTo(SofaScoreRosaTournament::class, 'tournament_id', 'ss_tournament_id'); + } }