wip grapper tournaments

This commit is contained in:
salam committed 2026-07-29 16:09:59 +02:00
1 parent acf74c5e82
commit 06c014fa1b
9 files changed
+165 -42

No files matched your search

@@ -33,6 +33,7 @@ class Sofascore
{
$function = Nuh::$options['fun'];
switch ($function) {
case 1:
@@ -6,6 +6,7 @@ use App\Console\Commands\Nuh;
use App\Models\SofaScoreRosa;
use App\Models\SofaScoreTask;
use App\Models\SofaScoreTaskTournament;
use App\Models\SofaScoreTournament;
use App\Utilities\Notice;
use Illuminate\Support\Facades\DB;
@@ -38,12 +39,12 @@ class SettingsToLocal
}
if ($debug) {
Notice::note('SofaScoreRosa', 'g');
Notice::note('SofaScoreTournament', 'g');
}
SofaScoreRosa::truncate();
$rows = DB::connection('remote_mariadb')->table('sofa_score_rosas')->get();
SofaScoreTournament::truncate();
$rows = DB::connection('remote_mariadb')->table('sofa_score_tournaments')->get();
foreach ($rows as $row) {
SofaScoreRosa::insert((array) $row);
SofaScoreTournament::insert((array) $row);
}
}
}
@@ -6,6 +6,7 @@ use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa;
use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper;
use App\Console\Commands\Nuh;
use App\Models\SofaScoreRosa;
use App\Models\SofaScoreRosaTournament;
use App\Models\SofaScoreTournament;
use App\Utilities\Notice;
@@ -22,13 +23,14 @@ class TournamentTeams
$tournaments = SofaScoreTournament::with('sofascore_category')->where('enabled', 1)->get();
SofaScoreRosa::query()->update(['grapped' => 0]);
SofaScoreRosaTournament::query()->update(['grapped' => 0]);
foreach ($tournaments as $tournament) {
$tournaments_counter++;
if ($debug) {
Notice::note("Tournament: $tournament->name", 'bb');
Notice::note("$tournaments_counter Tournament: $tournament->name", 'bb');
}
$url = Nuh::$options['base_url'] . "api/v1/unique-tournament/$tournament->tournament_id/seasons";
@@ -45,26 +47,37 @@ class TournamentTeams
$data = CurlSofa::load($url);
foreach ($data['standings'][0]['rows'] as $row) {
$teams_counter++;
if (isset($data['standings'])) {
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;
$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,
]);
SofaScoreRosa::updateOrCreate([
'sport_id' => $tournament->sport_id,
'ssteam_id' => (int) $ssteam_id,
], [
'country_id' => (int) $country_id,
'ssteam_name' => $name,
'grapped' => 1,
'disabled' => 0,
]);
SofaScoreRosaTournament::updateOrCreate([
'ss_tournament_id' => (int) $tournament->tournament_id,
'ssteam_id' => (int) $ssteam_id,
], [
'grapped' => 1,
'disabled' => 0,
]);
}
}
}
SofaScoreRosa::where('grapped', 0)->update(['disabled' => 1]);
SofaScoreRosaTournament::where('grapped', 0)->update(['disabled' => 1]);
if ($debug) {
Notice::note("summe tournaments: $tournaments_counter", 'p');
Notice::note("summe teams: $teams_counter", 'p');
@@ -2,6 +2,7 @@
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreRosas\Tables;
use App\Models\SofaScoreRosaTournament;
use App\Models\SofaScoreTournament;
use App\Models\Sport;
use Filament\Forms\Components\Select;
@@ -17,10 +18,11 @@ class SofaScoreRosasTable
public static function configure(Table $table): Table
{
return $table
->defaultPaginationPageOption(50)
->columns([
TextColumn::make('ssteam_id')->label('SSId')->badge()->width('1rem'),
TextColumn::make('country.name')->label('Country'),
TextColumn::make('tournament.name')->label('Tournament'),
TextColumn::make('tournament_rosa.tournament.name')->label('Tournament'),
TextColumn::make('ssteam_name')->label('Name'),
TextColumn::make('updated_at')->dateTime('Y-m-d H:i:s')
])
@@ -38,13 +40,17 @@ class SofaScoreRosasTable
})
->live(),
Select::make('ss_tournament_id')
->default(23)
->label('Tournament')
->selectablePlaceholder(false)
->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[$value->tournament_id] = $value->sofascore_category->name . ' - ' . $value->name;
}
asort($return);
return $return;
})
->live(),
@@ -55,7 +61,11 @@ class SofaScoreRosasTable
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)
function (Builder $query, $ss_tournament_id) {
$ssteam_ids = SofaScoreRosaTournament::where('ss_tournament_id', $ss_tournament_id)->pluck('ssteam_id')->toArray();
$query->whereIn('ssteam_id', $ssteam_ids);
}
);
}),
], layout: FiltersLayout::AboveContent)
+2 -2
View File
@@ -22,8 +22,8 @@ class SofaScoreRosa extends Model
return $this->belongsTo(Country::class);
}
public function tournament()
public function tournament_rosa()
{
return $this->belongsTo(SofaScoreTournament::class, 'ss_tournament_id', 'tournament_id');
return $this->belongsTo(SofaScoreRosaTournament::class, 'ssteam_id', 'ssteam_id');
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SofaScoreRosaTournament extends Model
{
protected $fillable = [
'ssteam_id',
'ss_tournament_id',
'grapped',
'disabled',
];
public function tournament()
{
return $this->belongsTo(SofaScoreTournament::class, 'ss_tournament_id', 'tournament_id');
}
}