From 74e9285bacfafff913c0f697af26706a1876a6fb Mon Sep 17 00:00:00 2001 From: salam Date: Thu, 25 Jun 2026 20:25:06 +0200 Subject: [PATCH] wip player filter --- app/Actions/Selections/LoadPlayer.php | 22 +++++++++++++-------- app/Filament/Pages/Statistic.php | 2 +- app/Filament/Widgets/Data/LoadEvents.php | 21 +++++++++----------- app/Filament/Widgets/StatsMedianAverage.php | 6 ++++++ 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/app/Actions/Selections/LoadPlayer.php b/app/Actions/Selections/LoadPlayer.php index eb04c03a..17066740 100644 --- a/app/Actions/Selections/LoadPlayer.php +++ b/app/Actions/Selections/LoadPlayer.php @@ -4,14 +4,18 @@ namespace App\Actions\Selections; use App\Models\StatistikoDetail; use App\Models\StatistikoPlayer; +use Illuminate\Support\Facades\Log; class LoadPlayer { - public static function load($team_id) + public static function load($get) { // $res = CompetitionGroup::with('country')->where('id', $league_id)->first(); // $season_mode = $res->country->season_mode; + $team_id = $get('team_id'); + $season = $get('season'); + $res_details = StatistikoDetail::where('txodds_id', $team_id)->get(); if (! $res_details) { @@ -23,17 +27,19 @@ class LoadPlayer $player_ids[] = $val->tm_player_id; } $res_player = StatistikoPlayer::whereIn('tm_player_id', $player_ids) + ->with('event') ->where('minutes_played', '>', 0) ->select('match_id','tm_player_id') ->get(); $counting = []; foreach ($res_player as $val) { - $tm_player_id = $val->tm_player_id; - - if(!isset($counting[$tm_player_id])){ - $counting[$tm_player_id] = 1; - }else { - $counting[$tm_player_id]++; + if(in_array($val->event->season, $season)){ + $tm_player_id = $val->tm_player_id; + if(!isset($counting[$tm_player_id])){ + $counting[$tm_player_id] = 1; + }else { + $counting[$tm_player_id]++; + } } } @@ -63,4 +69,4 @@ class LoadPlayer } return $arr; } -} \ No newline at end of file +} diff --git a/app/Filament/Pages/Statistic.php b/app/Filament/Pages/Statistic.php index b0dbf3da..a5e07ea9 100644 --- a/app/Filament/Pages/Statistic.php +++ b/app/Filament/Pages/Statistic.php @@ -232,7 +232,7 @@ class Statistic extends BaseDashboard ->preload() ->searchable() ->options(function (Get $get) { - return LoadPlayer::load($get('team_id')); + return LoadPlayer::load($get); }), Select::make('player_on_field') ->live() diff --git a/app/Filament/Widgets/Data/LoadEvents.php b/app/Filament/Widgets/Data/LoadEvents.php index 2df2d853..8f9e0de3 100644 --- a/app/Filament/Widgets/Data/LoadEvents.php +++ b/app/Filament/Widgets/Data/LoadEvents.php @@ -3,7 +3,6 @@ namespace App\Filament\Widgets\Data; use App\Filament\Widgets\Data\LoadEvents\LoadEventsAverages; -use App\Models\CompetitionGroup; use App\Models\StatisticFixtures; use App\Models\StatistikoDetail; use App\Models\StatistikoEvent; @@ -12,16 +11,8 @@ use Illuminate\Support\Carbon; class LoadEvents { - public static $last_query = []; - public static function load(array $filter, bool $hasdots) { - // dd($filter); - - // if (self::$last_query) { - // return self::$last_query; - // } - $league_id = (int) $filter['league_id'] ?? 0; $match_id = (int) $filter['match_id'] ?? 0; @@ -42,7 +33,7 @@ class LoadEvents $team_position = $filter['team_position']; - $player_on_field = $filter['player_on_field']; + $player_on_field = $filter['player_on_field'] ?? 'all'; $accuracy = (float) $filter['accuracy'] ?? 0.5; @@ -108,11 +99,19 @@ class LoadEvents if ($tm_player_id) { $matches_played = StatistikoPlayer::where('tm_player_id', (int) $tm_player_id) ->when($player_on_field, function ($query) use ($player_on_field) { + // 'all' => 'All', + // 'lineup' => 'Lineup', + // 'substituted' => 'Substituted', + // 'notplayed' => 'Not Played', switch ($player_on_field) { + case 'all': + return $query->where('match_id', '>', 0); case 'lineup': return $query->where('lineup', 'T'); case 'substituted': return $query->where('lineup', 'P'); + case 'notplayed': + return $query->where('lineup', '=', ''); } }) ->pluck('match_id')->toArray(); @@ -519,8 +518,6 @@ class LoadEvents LoadEventsAverages::load($data, $filter, $labels, $events); } - self::$last_query = $data; - return $data; } diff --git a/app/Filament/Widgets/StatsMedianAverage.php b/app/Filament/Widgets/StatsMedianAverage.php index 056f7c12..4bce8ab6 100644 --- a/app/Filament/Widgets/StatsMedianAverage.php +++ b/app/Filament/Widgets/StatsMedianAverage.php @@ -6,13 +6,17 @@ use App\Filament\Widgets\Data\HelperStatisticType; use App\Filament\Widgets\Data\HelperTeamPosition; use App\Filament\Widgets\Data\LoadEvents; use App\Utilities\Round; +use Filament\Widgets\Concerns\InteractsWithPageFilters; use Filament\Widgets\StatsOverviewWidget; use Filament\Widgets\StatsOverviewWidget\Stat; +use Illuminate\Support\Facades\Log; use Illuminate\Support\HtmlString; use Livewire\Attributes\Reactive; class StatsMedianAverage extends StatsOverviewWidget { + use InteractsWithPageFilters; + protected ?string $pollingInterval = null; protected int|array|null $columns = null; @@ -31,6 +35,8 @@ class StatsMedianAverage extends StatsOverviewWidget { $data = LoadEvents::load($this->filters, false); + // Log::debug($this->filters, $data); + $team_position = HelperTeamPosition::get($this->filters); if (!$data)