From cbddd2fc467db2f95a577124e4f99eb74c1197dc Mon Sep 17 00:00:00 2001 From: salam Date: Sun, 30 Aug 2026 20:31:06 +0200 Subject: [PATCH] player incl player_on_field --- app/Filament/Widgets/Data/LoadPlayer.php | 50 +++++++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/app/Filament/Widgets/Data/LoadPlayer.php b/app/Filament/Widgets/Data/LoadPlayer.php index 08aa5cde..3c57e0d0 100644 --- a/app/Filament/Widgets/Data/LoadPlayer.php +++ b/app/Filament/Widgets/Data/LoadPlayer.php @@ -2,9 +2,10 @@ namespace App\Filament\Widgets\Data; -use Illuminate\Support\Carbon; use App\Models\StatistikoDetail; +use App\Models\StatistikoEvent; use App\Models\StatistikoPlayer; +use Illuminate\Support\Carbon; class LoadPlayer { @@ -17,6 +18,7 @@ class LoadPlayer // if (self::$last_query) { // return self::$last_query; // } + $team_position = $filter['team_position']; $league_id = (int) $filter['league_id'] ?? 0; @@ -24,6 +26,9 @@ class LoadPlayer $ss_player_id = (int) $filter['ss_player_id'] ?? 0; + $player_on_field = $filter['player_on_field'] ?? 'all'; + + // dd($player_on_field); $statistic_type = $filter['statistic_type'] ?? 'gls'; @@ -45,7 +50,48 @@ class LoadPlayer $player_name = StatistikoDetail::where('ss_player_id', (int) $ss_player_id)->value('player_name'); - $res = StatistikoPlayer::with('event')->where('ss_player_id', (int) $ss_player_id)->get(); + $matches_season = StatistikoEvent::where(function ($query) use ($team_id, $team_position) { + switch ($team_position) { + case 'home': + return $query->where('home_id', '=', $team_id); + case 'away': + return $query->where('away_id', '=', $team_id); + default: + return $query->where('home_id', '=', $team_id) + ->orWhere('away_id', '=', $team_id); + } + })->pluck('match_id')->toArray(); + + $matches_played = StatistikoPlayer::query() + ->whereIn('match_id', $matches_season) + ->where('ss_player_id', $ss_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('minutes_played', '>', 0); + case 'lineup': + return $query->where('lineup', 'T')->where('minutes_played', '>', 0); + case 'substituted': + return $query->where('lineup', 'P')->where('minutes_played', '>', 0); + default: + return $query->where('minutes_played', '>', 0); + } + }) + ->pluck('match_id')->toArray(); + + $res = StatistikoPlayer::with('event') + ->where('ss_player_id', (int) $ss_player_id) + ->when($matches_played, function ($query) use ($matches_played, $player_on_field) { + if ($player_on_field == 'notplayed') { + return $query->whereNotIn('match_id', $matches_played); + } else { + return $query->whereIn('match_id', $matches_played); + } + })->get(); $tmp = []; foreach ($res as $value) {