diff --git a/app/Console/Commands/Grapper/Sofascore.php b/app/Console/Commands/Grapper/Sofascore.php index b1be2540..a225a6bf 100644 --- a/app/Console/Commands/Grapper/Sofascore.php +++ b/app/Console/Commands/Grapper/Sofascore.php @@ -11,6 +11,7 @@ use App\Console\Commands\Grapper\Sofascore\Rose; use App\Console\Commands\Grapper\Sofascore\SendMail; use App\Console\Commands\Grapper\Sofascore\SettingsToLocal; use App\Console\Commands\Grapper\Sofascore\SqlMover; +use App\Console\Commands\Grapper\Sofascore\TournamentTeams; use App\Console\Commands\Nuh; use App\Models\SofaScoreTask; use App\Utilities\Notice; @@ -26,7 +27,7 @@ class Sofascore public static string $excel_name; - public static string $useragent; + public static string $useragent = '4'; public static function switch() { @@ -44,25 +45,21 @@ class Sofascore case 3: self::setStorage(); - Grapper::load(); break; case 4: self::setStorage(); - ZipFolder::create(); break; case 5: self::setStorage(); - SendMail::run(); break; case 6: self::setStorage(); - Rose::run(); break; @@ -72,10 +69,13 @@ class Sofascore case 8: self::setStorage(); - MakeExcel::create(); break; + case 9: + TournamentTeams::get(); + break; + default: Notice::note('id not valid', 'br', 1); } @@ -87,7 +87,6 @@ class Sofascore self::$storage = storage_path('sofascore_data') . '/'; // for grapper to start with - self::$useragent = 4; $storage_name = Strings::clean(SofaScoreTask::where('id', $task)->value('name')) . '/'; diff --git a/app/Console/Commands/Grapper/Sofascore/TournamentTeams.php b/app/Console/Commands/Grapper/Sofascore/TournamentTeams.php new file mode 100644 index 00000000..1e032eb4 --- /dev/null +++ b/app/Console/Commands/Grapper/Sofascore/TournamentTeams.php @@ -0,0 +1,73 @@ +where('enabled', 1)->get(); + + SofaScoreRosa::query()->update(['grapped' => 0]); + + foreach ($tournaments as $tournament) { + + $tournaments_counter++; + + if ($debug) { + Notice::note("Tournament: $tournament->name", 'bb'); + } + + $url = Nuh::$options['base_url'] . "api/v1/unique-tournament/$tournament->tournament_id/seasons"; + + Sleeper::rand(1); + + $data = CurlSofa::load($url); + + $season_id = $data['seasons'][0]['id']; + + $url = Nuh::$options['base_url'] . "api/v1/unique-tournament/$tournament->tournament_id/season/$season_id/standings/total"; + + Sleeper::rand(); + + $data = CurlSofa::load($url); + + foreach ($data['standings'][0]['rows'] as $row) { + $teams_counter++; + + $ssteam_id = $row['team']['id']; + $name = $row['team']['name']; + $country_id = $tournament->sofascore_category->country_id; + + SofaScoreRosa::updateOrCreate([ + 'sport_id' => $tournament->sport_id, + 'ssteam_id' => (int) $ssteam_id, + ], [ + 'ss_tournament_id' => (int) $tournament->tournament_id, + 'country_id' => (int) $country_id, + 'ssteam_name' => $name, + 'grapped' => 1, + 'disabled' => 0, + ]); + } + } + + if ($debug) { + Notice::note("summe tournaments: $tournaments_counter", 'p'); + Notice::note("summe teams: $teams_counter", 'p'); + } + } +} diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/Pages/EditSofaScoreRosa.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/Pages/EditSofaScoreRosa.php index 3ea95c03..5ce5cd5f 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/Pages/EditSofaScoreRosa.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/Pages/EditSofaScoreRosa.php @@ -13,7 +13,7 @@ class EditSofaScoreRosa extends EditRecord protected function getHeaderActions(): array { return [ - DeleteAction::make(), + // DeleteAction::make(), ]; } } diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/Tables/SofaScoreRosasTable.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/Tables/SofaScoreRosasTable.php index 5465d2d0..e9cd7109 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/Tables/SofaScoreRosasTable.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/Tables/SofaScoreRosasTable.php @@ -2,89 +2,63 @@ namespace App\Filament\Clusters\StaticData\Resources\SofaScoreRosas\Tables; -use App\Models\Country; -use App\Models\SofaScoreRosa; -use Filament\Actions\Action; -use Filament\Actions\BulkAction; -use Filament\Actions\BulkActionGroup; -use Filament\Actions\CreateAction; -use Filament\Actions\EditAction; +use App\Models\SofaScoreTournament; +use App\Models\Sport; +use Filament\Forms\Components\Select; +use Filament\Schemas\Components\Utilities\Get; use Filament\Tables\Columns\TextColumn; -use Filament\Tables\Columns\ToggleColumn; use Filament\Tables\Enums\FiltersLayout; -use Filament\Tables\Filters\SelectFilter; -use Filament\Tables\Filters\TernaryFilter; +use Filament\Tables\Filters\Filter; use Filament\Tables\Table; -use Illuminate\Support\Collection; +use Illuminate\Database\Eloquent\Builder; class SofaScoreRosasTable { public static function configure(Table $table): Table { return $table - ->description('The squad for the team selected will be send next day via mail. The selection will be unset after sending.') ->columns([ - TextColumn::make('ssteam_id')->label('Id')->badge()->width('1rem'), + TextColumn::make('ssteam_id')->label('SSId')->badge()->width('1rem'), TextColumn::make('country.name')->label('Country'), + TextColumn::make('tournament.name')->label('Tournament'), TextColumn::make('ssteam_name')->label('Name'), - ToggleColumn::make('is_active'), + TextColumn::make('updated_at')->dateTime('Y-m-d H:i:s') ]) ->filters([ - SelectFilter::make('country_id') - ->searchable() - ->label('Country') - ->options(function () { - $res = SofaScoreRosa::groupBy('country_id')->pluck('country_id')->toArray(); - return Country::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id'); + Filter::make('filters') + ->columns(3)->columnSpan(3) + ->schema([ + Select::make('sport_id') + ->default(1) + ->selectablePlaceholder(false) + ->label('Sport') + ->options(Sport::where('is_active', 1)->pluck('name', 'id')) + ->afterStateUpdated(function (callable $set) { + $set('ss_tournament_id', null); + }) + ->live(), + Select::make('ss_tournament_id') + ->label('Tournament') + ->options(function (Get $get) { + $res = SofaScoreTournament::with('sofascore_category')->where('enabled', 1)->where('sport_id', $get('sport_id'))->get(); + $return = []; + foreach ($res as $value) { + $return[$value->tournament_id] = $value->sofascore_category->name . ' ' . $value->name; + } + return $return; + }) + ->live(), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query->when( + $data['sport_id'], + fn(Builder $query, $sport_id) => $query->where('sport_id', $sport_id) + )->when( + $data['ss_tournament_id'], + fn(Builder $query, $ss_tournament_id) => $query->where('ss_tournament_id', $ss_tournament_id) + ); }), - TernaryFilter::make('is_active'), ], layout: FiltersLayout::AboveContent) - ->deferFilters(false) - ->headerActions([ - Action::make('all_on') - ->icon('phosphor-toggle-right-fill') - ->action(function (): void { - SofaScoreRosa::query()->update(['is_active' => 1]); - }), - Action::make('all_off') - ->icon('phosphor-toggle-left-fill') - ->color('danger') - ->action(function (): void { - SofaScoreRosa::query()->update(['is_active' => 0]); - }), - CreateAction::make() - ->icon('phosphor-plus') - ->label('Team'), - ]) - ->recordActions([ - EditAction::make(), - ]) - ->toolbarActions([ - BulkActionGroup::make([ - BulkAction::make('Enable selected') - ->color('primary') - ->icon('phosphor-toggle-right-fill') - ->action(function (Collection $records): void { - foreach ($records as $record) { - SofaScoreRosa::where('id', '=', $record->id) - ->update( - ['is_active' => 1] - ); - } - }), - BulkAction::make('Disable selected') - ->icon('phosphor-toggle-left-fill') - ->action(function (Collection $records): void { - foreach ($records as $record) { - SofaScoreRosa::where('id', '=', $record->id) - ->update( - ['is_active' => 0] - ); - } - }), - - // DeleteBulkAction::make(), - ]), - ]); + ->deferFilters(false); } } diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php index a87e5aed..c4cf2151 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php @@ -7,7 +7,6 @@ use App\Models\SofaScoreTournament; use App\Models\Sport; 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; @@ -34,16 +33,21 @@ class SofaScoreTournamentsTable ->size(IconSize::Medium) ->tooltip(fn($record) => $record->id) ->visibleFrom('lg'), - TextColumn::make('sport.name'), + TextColumn::make('sport.name') + ->sortable(), TextColumn::make('tournament_id') ->label('Id') ->sortable() ->searchable(), TextColumn::make('sofascore_category.name') - ->icon(fn($record) => $record->sofascore_category->country->icon), + ->label('Country') + ->icon(fn($record) => $record->sofascore_category->country->icon) + ->sortable(), TextColumn::make('name')->searchable()->sortable(), - ToggleColumn::make('enabled')->label('In Statistiko')->alignCenter(), - // ToggleColumn::make('disabled')->label('Hidden'), + ToggleColumn::make('enabled') + ->label('In Statistiko') + ->alignCenter() + ->sortable(), ]) ->filters([ Filter::make('filters') diff --git a/app/Models/SofaScoreRosa.php b/app/Models/SofaScoreRosa.php index 080ec53d..5eeaf5e9 100644 --- a/app/Models/SofaScoreRosa.php +++ b/app/Models/SofaScoreRosa.php @@ -7,14 +7,23 @@ use Illuminate\Database\Eloquent\Model; class SofaScoreRosa extends Model { protected $fillable = [ + 'sport_id', 'ssteam_id', 'ssteam_name', + 'ss_tournament_id', 'country_id', 'is_active', + 'grapped', + 'disabled', ]; public function country() { return $this->belongsTo(Country::class); } + + public function tournament() + { + return $this->belongsTo(SofaScoreTournament::class, 'ss_tournament_id', 'tournament_id'); + } } diff --git a/database/migrations/2026_07_20_150818_create_sofa_score_roses_table.php b/database/migrations/2026_07_20_150818_create_sofa_score_roses_table.php index 8acb1804..eccf9d35 100644 --- a/database/migrations/2026_07_20_150818_create_sofa_score_roses_table.php +++ b/database/migrations/2026_07_20_150818_create_sofa_score_roses_table.php @@ -13,15 +13,17 @@ return new class extends Migration { Schema::create('sofa_score_rosas', function (Blueprint $table) { $table->id(); + $table->integer('sport_id')->index(); + $table->integer('ssteam_id')->index(); $table->integer('country_id')->default(0)->nullable()->index()->references('id')->on('countries'); - $table->integer('ssteam_id'); $table->string('ssteam_name'); + $table->integer('ss_tournament_id')->default(0)->nullable()->index(); $table->boolean('is_active')->default(false); + $table->boolean('disabled')->default(false); $table->boolean('grapped')->default(false); $table->timestamps(); }); } - /** * Reverse the migrations. */ diff --git a/resources/extra-countries/north-america.svg b/resources/extra-countries/north-america.svg index c85301e7..33518840 100644 --- a/resources/extra-countries/north-america.svg +++ b/resources/extra-countries/north-america.svg @@ -1,8 +1,450 @@ - - - - - - - + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +