wip Expectations
This commit is contained in:
1 parent
3db428899c
commit
1dbdbcf586
26 files changed
+704
-268
No files matched your search
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Data\LoadEvents;
|
||||
|
||||
use App\Models\StatistikoEvent;
|
||||
|
||||
class LoadEventsQuery
|
||||
{
|
||||
public static function load(array $filter, array $matches_played, array $handicap_range, array $total_range)
|
||||
{
|
||||
$league_id = (int) $filter['league_id'] ?? 0;
|
||||
$team_id = (int) $filter['team_id'] ?? 0;
|
||||
$season = $filter['season'] ?? 0;
|
||||
$start = $filter['start_date'] ?? 0;
|
||||
$end = $filter['end_date'] ?? 0;
|
||||
$player_on_field = $filter['player_on_field'] ?? 'all';
|
||||
$similar_past_matches = $filter['similar_past_matches'];
|
||||
$statistic_type = $filter['statistic_type'] ?? 'gls';
|
||||
|
||||
if ($statistic_type == 'none') {
|
||||
$statistic_type = 'gls';
|
||||
}
|
||||
|
||||
/**
|
||||
* STATTISTIC DATA
|
||||
*/
|
||||
$res = 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, $similar_past_matches) {
|
||||
if ($similar_past_matches == 'none') {
|
||||
return $query->where('home_id', '=', $team_id)
|
||||
->orWhere('away_id', '=', $team_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->where('starttime', '>=', $start);
|
||||
})->when($end, function ($query) use ($end) {
|
||||
return $query->where('starttime', '<=', $end);
|
||||
})->when($season, function ($query) use ($season) {
|
||||
return $query->whereIn('season', $season);
|
||||
})
|
||||
->orderBy('starttime', 'ASC')
|
||||
->get();
|
||||
|
||||
$arr = [];
|
||||
foreach ($res as $value) {
|
||||
$tmp = [];
|
||||
$tmp['match_id'] = $value->match_id;
|
||||
$tmp['sport_id'] = $value->sport_id;
|
||||
$tmp['league_id'] = $value->league_id;
|
||||
$tmp['home_id'] = $value->home_id;
|
||||
$tmp['away_id'] = $value->away_id;
|
||||
$tmp['starttime'] = $value->starttime;
|
||||
$tmp['season'] = $value->season;
|
||||
$tmp['exp_home'] = $value->exp_home;
|
||||
$tmp['exp_away'] = $value->exp_away;
|
||||
$tmp['exp_handicap'] = $value->exp_handicap;
|
||||
$tmp['exp_total'] = $value->exp_total;
|
||||
$tmp['result_code'] = $value->result_code;
|
||||
$tmp['home'] = $value->home->ss_team_name;
|
||||
$tmp['away'] = $value->away->ss_team_name;
|
||||
|
||||
switch ($statistic_type) {
|
||||
case 'gls':
|
||||
$tmp['val_home'] = $value->gls_h;
|
||||
$tmp['val_away'] = $value->gls_a;
|
||||
break;
|
||||
case 'crn':
|
||||
$tmp['val_home'] = $value->crn_h;
|
||||
$tmp['val_away'] = $value->crn_a;
|
||||
break;
|
||||
case 'fls':
|
||||
$tmp['val_home'] = $value->fls_h;
|
||||
$tmp['val_away'] = $value->fls_a;
|
||||
break;
|
||||
case 'ofs':
|
||||
$tmp['val_home'] = $value->ofs_h;
|
||||
$tmp['val_away'] = $value->ofs_a;
|
||||
break;
|
||||
case 'crd':
|
||||
$tmp['val_home'] = $value->crd_h;
|
||||
$tmp['val_away'] = $value->crd_a;
|
||||
break;
|
||||
case 'snt':
|
||||
$tmp['val_home'] = $value->snt_h;
|
||||
$tmp['val_away'] = $value->snt_a;
|
||||
break;
|
||||
case 'tsh':
|
||||
$tmp['val_home'] = $value->tsh_h;
|
||||
$tmp['val_away'] = $value->tsh_a;
|
||||
break;
|
||||
}
|
||||
|
||||
$arr['all'][] = $tmp;
|
||||
if ($value->home_id == $team_id)
|
||||
$arr['home'][] = $tmp;
|
||||
if ($value->away_id == $team_id)
|
||||
$arr['away'][] = $tmp;
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user