This commit is contained in:
salam committed 2026-09-04 08:21:34 +02:00
1 parent f013d2563e
commit 884b468839
15 files changed
+319 -251

No files matched your search

+52 -41
View File
@@ -67,7 +67,7 @@ class Statistic extends BaseDashboard
case 'season_or_date':
$this->filters[$filter] = 'season';
break;
default;
default:
$this->filters[$filter] = null;
break;
}
@@ -94,32 +94,42 @@ class Statistic extends BaseDashboard
->modalCancelAction(false) // Optional: hides the cancel button too
->label('Calculate')
->icon('icon-player')
->color(fn(): string => $this->filters['team_id'] ? 'primary' : 'gray')
->disabled(fn(): string => $this->filters['team_id'] ? false : true)
->color(fn (): string => $this->filters['team_id'] ? 'primary' : 'gray')
->disabled(fn (): string => $this->filters['team_id'] ? false : true)
->slideOverPosition(SlideOverPosition::Start)
->modalWidth(Width::SevenExtraLarge)
->slideOver()
->schema([
Grid::make(2)
->extraAttributes([
'class' => 'justify-between w-full gap-4'
'class' => 'justify-between w-full gap-4',
])
->schema([
ToggleButtons::make('status')
->live()
->hiddenLabel()
->multiple()
->inline()
->default('attack')
->options([
'attack' => 'Attack',
'midfield' => 'Midfield',
'defence' => 'Defence',
'goalkeeper' => 'Goalkeeper',
])->icons([
'attack' => 'phosphor-lightning',
'midfield' => 'phosphor-align-center-horizontal-simple',
'defence' => 'phosphor-shield',
'goalkeeper' => 'phosphor-barricade',
]),
])
->colors([
'attack' => 'warning',
'midfield' => 'info',
'defence' => 'success',
'goalkeeper' => 'gray',
])
->afterStateUpdated(function (ToggleButtons $component, $state, $livewire) {
// 1. Fetch the enabled options array
$livewireComponent = $component->getLivewire();
$data = json_encode($livewireComponent->mountedActions);
$livewire->js('toggle_type(\''.$data.'\')');
}),
Grid::make(5)
->schema([
Action::make('restart')
@@ -141,11 +151,11 @@ class Statistic extends BaseDashboard
->icon('phosphor-calculator'),
])
->extraAttributes([
'class' => 'flex justify-center items-center gap-0'
])
])
'class' => 'flex justify-center items-center gap-0',
]),
]),
])
->modalContentFooter(view('filament.modals.player-calculator-modal', ['filters' => $this->filters]))
->modalContentFooter(view('filament.modals.player-calculator-modal', ['filters' => $this->filters])),
];
}
@@ -183,10 +193,10 @@ class Statistic extends BaseDashboard
->live()
->preload()
->searchable(false)
->prefixIconColor(fn(Get $get): string => $get('sofascore_category_id') ? 'success' : 'danger')
->prefixIconColor(fn (Get $get): string => $get('sofascore_category_id') ? 'success' : 'danger')
->prefixIcon('phosphor-globe-fill')
->hiddenLabel()
->options(fn() => LoadSofaScoreCategory::load())
->options(fn () => LoadSofaScoreCategory::load())
->placeholder('Country')
->afterStateUpdated(function (callable $set, $state) {
$set('seasonmode', SofaScoreCategory::where('id', $state)->value('season_mode'));
@@ -199,10 +209,10 @@ class Statistic extends BaseDashboard
Select::make('league_id')
->live()
->preload()
->prefixIconColor(fn(Get $get): string => $get('league_id') ? 'success' : 'danger')
->prefixIconColor(fn (Get $get): string => $get('league_id') ? 'success' : 'danger')
->prefixIcon('phosphor-trophy-fill')
->hiddenLabel()
->options(fn(Get $get) => LoadStatisticFixturesLeaguesOptions::load($get('sofascore_category_id')))
->options(fn (Get $get) => LoadStatisticFixturesLeaguesOptions::load($get('sofascore_category_id')))
->placeholder('League')
->afterStateUpdated(function (callable $set) {
$set('match_id', null);
@@ -213,7 +223,7 @@ class Statistic extends BaseDashboard
Select::make('match_id')
->live()
->hiddenLabel()
->prefixIconColor(fn(Get $get): string => $get('match_id') ? 'success' : 'danger')
->prefixIconColor(fn (Get $get): string => $get('match_id') ? 'success' : 'danger')
->prefixIcon('phosphor-calendar-check-fill')
->options(function (Get $get) {
return LoadStatisticFixturesMatchOptions::load($get('league_id'));
@@ -238,7 +248,7 @@ class Statistic extends BaseDashboard
}
})
->prefixIcon('phosphor-users-three-fill')
->hidden(fn(Get $get) => $get('similar_past_matches') != 'none')
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->options(function (Get $get) {
if ($get('match_id')) {
$res = StatisticFixtures::where('id', $get('match_id'))->first();
@@ -267,9 +277,9 @@ class Statistic extends BaseDashboard
Action::make('iconInfo')
->color('success')
->icon('phosphor-question-fill')
->tooltip(fn() => 'Team Position')
->tooltip(fn () => 'Team Position')
)
->hidden(fn(Get $get) => $get('similar_past_matches') != 'none')
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->default('all')
->selectablePlaceholder(false)
->options([
@@ -325,17 +335,17 @@ class Statistic extends BaseDashboard
->hiddenLabel()
->suffixAction(Action::make('reset')
->icon('phosphor-x-circle')
->action(fn(callable $set) => $set('similar_past_matches', 'none'))
->color(fn(Get $get): string => $get('similar_past_matches') != 'none' ? 'info' : 'gray'))
->action(fn (callable $set) => $set('similar_past_matches', 'none'))
->color(fn (Get $get): string => $get('similar_past_matches') != 'none' ? 'info' : 'gray'))
->placeholder('Similar Past Matches')
->suffix(fn(Get $get): string|HtmlString => $get('similar_past_matches') != 'none' ? new HtmlString('<div class="text-center w-24 font-bold rounded p-1 bg-blue-600 dark:bg-blue-700 text-white dark:text-gray-300">± ' . $get('accuracy') . '</div>') : '')
->suffix(fn (Get $get): string|HtmlString => $get('similar_past_matches') != 'none' ? new HtmlString('<div class="text-center w-24 font-bold rounded p-1 bg-blue-600 dark:bg-blue-700 text-white dark:text-gray-300">± '.$get('accuracy').'</div>') : '')
->prefix('SPM')
->prefixAction(
Action::make('iconInfo')
->icon('phosphor-question-fill')
// ->color(fn(Get $get): string => $get('similar_past_matches') != 'none' ? 'success' : 'primary')
->color('success')
->tooltip(fn() => $this->tooltip_similar_past_matches())
->tooltip(fn () => $this->tooltip_similar_past_matches())
)
->default('none')
->selectablePlaceholder(false)
@@ -355,7 +365,7 @@ class Statistic extends BaseDashboard
Slider::make('accuracy')
->live()
->hiddenLabel()
->hidden(fn(Get $get) => $get('similar_past_matches') == 'none')
->hidden(fn (Get $get) => $get('similar_past_matches') == 'none')
->fillTrack()
->minValue(0)
->maxValue(0.25)
@@ -374,17 +384,17 @@ class Statistic extends BaseDashboard
->hiddenLabel()
->allowHtml()
->placeholder('Player')
->hidden(fn(Get $get) => $get('similar_past_matches') != 'none')
->prefixIconColor(fn(Get $get): string => $get('similar_past_matches') == 'none' ? 'success' : '')
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->prefixIconColor(fn (Get $get): string => $get('similar_past_matches') == 'none' ? 'success' : '')
->prefixIcon('icon-player')
->preload()
->searchable()
->extraAttributes(fn() => ['id' => 'player_selector'])
->extraAttributes(fn () => ['id' => 'player_selector'])
->suffixAction(
Action::make('iconInfo')
->icon('phosphor-question-fill')
->color('success')
->tooltip(fn() => $this->tooltip_player_info())
->tooltip(fn () => $this->tooltip_player_info())
)
->options(function (Get $get) {
$team_id = $get('team_id');
@@ -392,6 +402,7 @@ class Statistic extends BaseDashboard
$sofascore_category_id = $get('sofascore_category_id');
$season = $get('season');
$seasonmode = $get('seasonmode');
return LoadPlayer::load($team_id, $team_position, $sofascore_category_id, $season, $seasonmode);
}),
Select::make('player_on_field')
@@ -400,7 +411,7 @@ class Statistic extends BaseDashboard
->placeholder('Time on field')
->prefixIcon('phosphor-watch-fill')
->default('all')
->hidden(fn(Get $get) => ! $get('ss_player_id'))
->hidden(fn (Get $get) => ! $get('ss_player_id'))
->prefixIconColor('success')
->selectablePlaceholder(false)
->options([
@@ -420,7 +431,7 @@ class Statistic extends BaseDashboard
->extraAttributes([
'class' => 'radio-statistic-group',
])
->hidden(fn(Get $get) => $get('similar_past_matches') != 'none')
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->columnSpan([
'default' => 4,
'sm' => 4,
@@ -444,7 +455,7 @@ class Statistic extends BaseDashboard
->multiple()
->placeholder('Current Season')
->prefixIconColor('success')
->hidden(fn(Get $get) => $get('seasonmode') == 'halfyear' || $get('season_or_date') == 'date' || $get('similar_past_matches') != 'none')
->hidden(fn (Get $get) => $get('seasonmode') == 'halfyear' || $get('season_or_date') == 'date' || $get('similar_past_matches') != 'none')
->prefixIcon('phosphor-calendar-star-fill')
->options([
'2026' => '2026',
@@ -464,7 +475,7 @@ class Statistic extends BaseDashboard
->multiple()
->placeholder('Current Season')
->prefixIconColor('success')
->hidden(fn(Get $get) => $get('seasonmode') == 'fullyear' || $get('season_or_date') == 'date' || $get('similar_past_matches') != 'none')
->hidden(fn (Get $get) => $get('seasonmode') == 'fullyear' || $get('season_or_date') == 'date' || $get('similar_past_matches') != 'none')
->prefixIcon('phosphor-calendar-star-fill')
->options([
'26/27' => '26/27',
@@ -480,30 +491,30 @@ class Statistic extends BaseDashboard
DatePicker::make('start_date')
->live()
->hiddenLabel()
->hidden(fn(Get $get) => $get('season_or_date') == 'season')
->hidden(fn (Get $get) => $get('season_or_date') == 'season')
->native(false)
->prefixIconColor(fn(Get $get): string => $get('start_date') ? 'success' : 'primary')
->prefixIconColor(fn (Get $get): string => $get('start_date') ? 'success' : 'primary')
->prefixIcon('phosphor-calendar-fill')
->prefix('Start')
->suffixAction(
Action::make('clear_start')
->icon('phosphor-x')
->color('gray')
->action(fn(Set $set) => $set('start_date', null))
->action(fn (Set $set) => $set('start_date', null))
),
DatePicker::make('end_date')
->live()
->hiddenLabel()
->hidden(fn(Get $get) => $get('season_or_date') == 'season')
->hidden(fn (Get $get) => $get('season_or_date') == 'season')
->native(false)
->prefixIconColor(fn(Get $get): string => $get('end_date') ? 'success' : 'primary')
->prefixIconColor(fn (Get $get): string => $get('end_date') ? 'success' : 'primary')
->prefixIcon('phosphor-calendar-fill')
->prefix('End')
->suffixAction(
Action::make('clear_end')
->icon('phosphor-x')
->color('gray')
->action(fn(Set $set) => $set('end_date', null))
->action(fn (Set $set) => $set('end_date', null))
),
]);
}
@@ -4,7 +4,6 @@ namespace App\Livewire\Mapper;
class LoadGridPositions
{
public static function load()
{
$arr = [];
+37 -11
View File
@@ -13,6 +13,7 @@ use Livewire\Component;
class PlayerCalculator extends Component
{
use InteractsWithPageFilters;
public $grid = [];
public function mount(array $filters)
@@ -25,8 +26,29 @@ class PlayerCalculator extends Component
array_splice($pla, $i, 0, [$v]);
$i += 2;
}
$this->grid = $pla;
// dd($this->grid);
$x = 1;
$y = 1;
foreach ($pla as $ele) {
foreach ($ele as $val) {
$tmp = [];
if (is_array($val)) {
foreach ($val as $key => $value) {
$tmp[$key] = $value;
}
$tmp['type'] = '';
} else {
$tmp['type'] = $val != 0 ? $val : '';
}
$tmp['x'] = 104 * $x;
$tmp['y'] = 104 * $y;
$this->grid[] = $tmp;
$x++;
if ($x > 10) {
$x = 1;
$y++;
}
}
}
}
public static function load(array $filters)
@@ -58,7 +80,7 @@ class PlayerCalculator extends Component
foreach ($player as $val) {
if ($val->details) {
$player_id = $val->ss_player_id;
if (!isset($arr[$player_id])) {
if (! isset($arr[$player_id])) {
$arr[$player_id]['player_name'] = $val->details->player_name;
$arr[$player_id]['events_played_home'] = $val->events_played_home;
$arr[$player_id]['events_played_away'] = $val->events_played_away;
@@ -76,7 +98,6 @@ class PlayerCalculator extends Component
}
}
$result = [];
foreach ($arr as $player_id => $val) {
@@ -95,27 +116,31 @@ class PlayerCalculator extends Component
break;
}
$colorlevel = round($matches->count() / 3);
if (in_array($val['player_position'], $positions_map['MIDFIELD'])) {
$position = 'MIDFIELD';
} else if (in_array($val['player_position'], $positions_map['DEFENCE'])) {
$position_color = 'info';
} elseif (in_array($val['player_position'], $positions_map['DEFENCE'])) {
$position = 'DEFENCE';
} else if (in_array($val['player_position'], $positions_map['ATTACK'])) {
$position_color = 'success';
} elseif (in_array($val['player_position'], $positions_map['ATTACK'])) {
$position = 'ATTACK';
} else if (in_array($val['player_position'], $positions_map['GOALKEEPER'])) {
$position_color = 'warning';
} elseif (in_array($val['player_position'], $positions_map['GOALKEEPER'])) {
$position = 'GOALKEEPER';
$position_color = 'gray';
} else {
$position = 'NO SPECIFIC POSITION';
$position_color = '';
}
$name = $val['player_name'];
$preferred_foot = $val['preferred_foot'] ?? '-';
$everage_minutes = round($minues_played / $events_played) . ' min';
$everage_minutes = round($minues_played / $events_played).' min';
if ($colorlevel > 1 && $events_played < $colorlevel) {
$color = 'danger';
} else if ($events_played < $colorlevel * 2) {
} elseif ($events_played < $colorlevel * 2) {
$color = 'info';
} else {
$color = 'success';
@@ -125,8 +150,9 @@ class PlayerCalculator extends Component
'player_id' => $player_id,
'name' => $name,
'position' => $position,
'position_color' => $position_color,
'color' => $color,
'info' => 'Ev ' . $events_played . ', ' . $preferred_foot . ', ' . $everage_minutes,
'info' => 'Ev '.$events_played.', '.$preferred_foot.', '.$everage_minutes,
];
}