Files
nuhodds_fi4/app/Filament/Widgets/Data/LoadPlayerBackup.php
T
2026-05-29 16:38:15 +02:00

108 lines
2.7 KiB
PHP

<?php
namespace App\Filament\Widgets\Data;
use App\Models\StatistikoPlayer;
use Illuminate\Support\Carbon;
class LoadPlayer
{
public static $last_query = [];
public static function load($filter)
{
// dd($filter);
if (self::$last_query) {
return self::$last_query;
}
$league_id = (int) $filter['league_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$tm_player_id = (int) $filter['tm_player_id'] ?? 0;
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
$statistic_type = $filter['statistic_type'];
$team_position = $filter['team_position'];
if (! $league_id) {
return [];
}
if (! $team_id) {
return [];
}
if (! $tm_player_id) {
return [];
}
if ($statistic_type == 'none') {
$statistic_type = 'gls';
}
$res = StatistikoPlayer::with('event')->where('tm_player_id', (int) $tm_player_id)->get();
$labels = [];
$datasets = [];
foreach ($res as $value) {
// dd($value);
$val = 0;
if (isset($value->event->starttime)) {
// $labels[] = $value->event->starttime->format('d.M.y');
$labels[] = 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;
}
}
$datasets[] = $val;
}
$data = [
'datasets' => [
[
'label' => ucfirst($team_position),
'data' => $datasets,
'tension' => 0.5,
'borderColor' => '#36A2EB',
],
],
'labels' => $labels,
];
self::$last_query = $data;
return $data;
}
}