This commit is contained in:
salam committed 2026-10-22 15:26:10 +02:00
1 parent c6b2602564
commit d6a13837c5
5 files changed
+103 -36

No files matched your search

@@ -0,0 +1,69 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\RelationManagers;
// use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\SofaScoreTournamentResource;
use App\Filament\Clusters\StaticData\StaticDataCluster;
use App\Models\SofaScoreRosa;
use Filament\Actions\CreateAction;
use Filament\Actions\DeleteAction;
use Filament\Forms\Components\Select;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ToggleColumn;
use Filament\Tables\Table;
class SofaScoreTournamentsTeamRelationManager extends RelationManager
{
protected static string $relationship = 'rosa_tournament';
// protected static ?string $relatedResource = SofaScoreTournamentResource::class;
protected static ?string $cluster = StaticDataCluster::class;
protected static ?string $title = 'Tournament Teams';
protected static ?string $navigationLabel = 'Tournament Teams';
protected static ?string $modelLabel = 'Tournament Teams';
protected static ?string $pluralModelLabel = 'Tournament Teams';
public function form(Schema $schema): Schema
{
return $schema
->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'),
]);
}
}
@@ -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,
];
}
}
@@ -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(),
]);
}
}
+5
View File
@@ -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');
}
}
+5
View File
@@ -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');
}
}