Files
nuhodds_fi4/app/Filament/Widgets/Data/LoadPlayer.php
T
2026-08-29 19:13:07 +02:00

116 lines
3.0 KiB
PHP

<?php
namespace App\Filament\Widgets\Data;
use Illuminate\Support\Carbon;
use App\Models\StatistikoDetail;
use App\Models\StatistikoPlayer;
class LoadPlayer
{
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;
$team_id = (int) $filter['team_id'] ?? 0;
$ss_player_id = (int) $filter['ss_player_id'] ?? 0;
$statistic_type = $filter['statistic_type'] ?? 'gls';
$statistic_name = HelperStatisticType::get($filter);
if (! $league_id) {
return [];
}
if (! $team_id) {
return [];
}
if (! $ss_player_id) {
return [];
}
if ($statistic_type == 'none') {
$statistic_type = 'gls';
}
$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();
$tmp = [];
foreach ($res as $value) {
$val = 0;
$key = 0;
if (isset($value->event->starttime)) {
$key = round($value->event->starttime->diffInDays(Carbon::now()));
switch ($statistic_type) {
case 'gls':
$val = (int) $value->goals;
break;
case 'crn':
$val = (int) 0;
break;
case 'fls':
$val = (int) $value->fouls;
break;
case 'ofs':
$val = (int) $value->offsides;
break;
case 'crd':
$val = (int) $value->card_yellow + $value->card_red + $value->card_yellowred;
break;
case 'snt':
$val = (int) $value->shots_on_target;
break;
case 'tsh':
$val = (int) $value->shots_off_target;
break;
}
$tmp[$key] = $val;
}
}
krsort($tmp);
$dataset = [];
$labels = [];
foreach ($tmp as $key => $value) {
$labels[] = $key;
$dataset[] = $value;
}
$data = [
'datasets' => [
[
'label' => ucfirst($statistic_name),
'data' => $dataset,
'tension' => 0.5,
'borderColor' => '#36A2EB',
'pointStyle' => $hasdots,
],
],
'labels' => $labels,
'player_name' => $player_name,
];
self::$last_query = $data;
return $data;
}
}