wip order classes
This commit is contained in:
1 parent
fe4fa6e9cf
commit
7bf4258c4a
29 files changed
+140
-124
No files matched your search
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Charts\LoadEvents;
|
||||
|
||||
use App\Filament\Pages\Selections\Helper\GetSeason;
|
||||
use App\Models\StatistikoEvent;
|
||||
use App\Models\StatistikoPlayer;
|
||||
|
||||
class LoadEventsQueryAll
|
||||
{
|
||||
public static function load(array $filter, object $match)
|
||||
{
|
||||
$league_id = (int) $filter['league_id'] ?? 0;
|
||||
$team_id = (int) $filter['team_id'] ?? 0;
|
||||
$season = $filter['season'];
|
||||
$seasonmode = $filter['seasonmode'];
|
||||
$season_or_date = $filter['season_or_date'];
|
||||
$accuracy = (float) $filter['accuracy'] ?? 0.5;
|
||||
$start = $filter['start_date'] ?? 0;
|
||||
$end = $filter['end_date'] ?? 0;
|
||||
if ($season_or_date == 'season') {
|
||||
$start = 0;
|
||||
$end = 0;
|
||||
}
|
||||
$ss_player_id = (int) $filter['ss_player_id'] ?? 0;
|
||||
$player_on_field = $filter['player_on_field'] ?? 'all';
|
||||
$similar_past_matches = $filter['similar_past_matches'];
|
||||
$team_position = $filter['team_position'];
|
||||
$home_id = $match->home_id;
|
||||
$away_id = $match->away_id;
|
||||
|
||||
$handicap_range = [];
|
||||
$total_range = [];
|
||||
if ($similar_past_matches != 'none') {
|
||||
$team_id = 0;
|
||||
$team_position = '';
|
||||
$exp_handicap = $match->exp_away - $match->exp_home;
|
||||
$exp_total = $match->exp_away + $match->exp_home;
|
||||
$handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy];
|
||||
$total_range = [$exp_total - $accuracy, $exp_total + $accuracy];
|
||||
}
|
||||
|
||||
if ($similar_past_matches != 'none') {
|
||||
$team_position = '';
|
||||
$team_id = 0;
|
||||
$ss_player_id = 0;
|
||||
}
|
||||
|
||||
// dd($season);
|
||||
$season = GetSeason::load($season, $seasonmode);
|
||||
|
||||
/**
|
||||
* IF WITH PLAYER
|
||||
*/
|
||||
$matches_played = [];
|
||||
|
||||
if ($ss_player_id) {
|
||||
$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();
|
||||
|
||||
if (! $matches_played) {
|
||||
$matches_played[] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// dd($handicap_range, $total_range);
|
||||
/**
|
||||
* STATTISTIC DATA
|
||||
*/
|
||||
return StatistikoEvent::with('home')->with('away')
|
||||
->where(function ($query) use ($league_id, $similar_past_matches) {
|
||||
switch ($similar_past_matches) {
|
||||
case 'none':
|
||||
case 'league':
|
||||
return $query->where('league_id', $league_id);
|
||||
}
|
||||
})
|
||||
->where(function ($query) use ($team_id, $home_id, $away_id, $similar_past_matches) {
|
||||
if ($similar_past_matches == 'none') {
|
||||
if ($team_id) {
|
||||
return $query->orWhere('home_id', $team_id)
|
||||
->orWhere('away_id', '=', $team_id);
|
||||
} else {
|
||||
return $query->whereIn('home_id', [$home_id, $away_id])->orWhereIn('away_id', [$home_id, $away_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);
|
||||
}
|
||||
})
|
||||
->when($handicap_range, function ($query) use ($handicap_range) {
|
||||
return $query->whereBetween('exp_handicap', $handicap_range);
|
||||
})->when($total_range, function ($query) use ($total_range) {
|
||||
return $query->whereBetween('exp_total', $total_range);
|
||||
})
|
||||
->when($start, function ($query) use ($start) {
|
||||
return $query->whereDate('starttime', '>=', $start);
|
||||
})->when($end, function ($query) use ($end) {
|
||||
return $query->whereDate('starttime', '<=', $end);
|
||||
})
|
||||
->when($season, function ($query) use ($season, $season_or_date, $similar_past_matches) {
|
||||
if ($similar_past_matches == 'none' && $season_or_date == 'season') {
|
||||
return $query->whereIn('season', $season);
|
||||
}
|
||||
})
|
||||
->orderBy('starttime', 'ASC')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user