Files
nuhodds_fi4/app/Filament/Pages/PlayerProps.php
T
2026-09-13 15:40:30 +02:00

284 lines
10 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Actions\LoadSofaScoreCategory;
use App\Actions\LoadStatisticFixturesLeaguesOptions;
use App\Actions\LoadStatisticFixturesMatchOptions;
use App\Filament\Widgets\PlayerPropsDrop;
use App\Filament\Widgets\PlayerPropsTable;
use App\Models\SofaScoreRosa;
use App\Models\StatisticFixtures;
use BackedEnum;
use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
class PlayerProps extends Page implements HasForms
{
use InteractsWithForms;
protected string $view = 'filament.pages.player-props';
protected static string|BackedEnum|null $navigationIcon = 'icon-soccerplayer';
public function getHeading(): string
{
return '';
}
protected static ?string $title = 'Player Props';
protected static ?int $navigationSort = 2;
public array $boxes;
public array $activeBoxes;
public array $sourceRecords;
public ?array $filterData;
public array $beschriftung;
public array $lineup;
public array $lineUpOptinos;
public array $lineUpMap;
public string $lineupActive = '3313';
public function mount(): void
{
// Initialisiert das Formular mit leeren Werten
$this->form->fill();
$this->activeBoxes = $this->boxNames();
$this->lineUpMap = $this->linUpMap();
$this->lineUpOptinos = $this->lineUpOptinos();
$this->lineup = $this->lineUpMap[$this->lineupActive];
for ($i = 1; $i <= 35; $i++) {
$this->boxes[$i] = [];
if (isset($this->activeBoxes[$i])) {
$this->beschriftung[$i] = $this->activeBoxes[$i];
} else {
$this->beschriftung[$i] = '';
}
}
}
public function getWidgetData(): array
{
return [
'beschriftung' => $this->beschriftung,
'lineup' => $this->lineup,
'boxes' => $this->boxes,
];
}
public function form(Schema $schema): Schema
{
return $schema
->columns(4)
->components([
Select::make('cid')
->live()
->preload()
->searchable(false)
->prefixIconColor(fn (Get $get): string => $get('cid') ? 'success' : 'danger')
->prefixIcon('phosphor-globe-fill')
->hiddenLabel()
->options(fn () => LoadSofaScoreCategory::load())
->placeholder('Country')
->afterStateUpdated(function (callable $set, $state) {
$set('lid', null);
$set('mid', null);
$set('tid', null);
}),
Select::make('lid')
->live()
->preload()
->prefixIconColor(fn (Get $get): string => $get('lid') ? 'success' : 'danger')
->prefixIcon('phosphor-trophy-fill')
->hiddenLabel()
->options(fn (Get $get) => LoadStatisticFixturesLeaguesOptions::load($get('cid')))
->placeholder('League')
->afterStateUpdated(function (callable $set) {
$set('mid', null);
$set('tid', null);
}),
Select::make('mid')
->live()
->hiddenLabel()
->prefixIconColor(fn (Get $get): string => $get('mid') ? 'success' : 'danger')
->prefixIcon('phosphor-calendar-check-fill')
->options(function (Get $get) {
return LoadStatisticFixturesMatchOptions::load($get('lid'));
})
->afterStateUpdated(function (callable $set) {
$set('tid', null);
})
->placeholder('Events'),
Select::make('tid')
->live()
->hiddenLabel()
->prefixIconColor(fn (Get $get): string => $get('tid') ? 'success' : 'danger')
->prefixIcon('phosphor-users-three-fill')
->options(function (Get $get) {
if ($get('mid')) {
$res = StatisticFixtures::where('id', $get('mid'))->first();
$arr = [];
if ($res) {
$arr[$res->home_id] = SofaScoreRosa::query()->where('ss_team_id', $res->home_id)->value('ss_team_name');
$arr[$res->away_id] = SofaScoreRosa::query()->where('ss_team_id', $res->away_id)->value('ss_team_name');
}
return $arr;
}
})
->placeholder('Team')->afterStateUpdated(function ($state) {
// Speichert das ausgewählte Team direkt in der Session
// session(['player_props_filter_team' => $state]);
// Widget informieren
$this->dispatch('refreshFilters', team_id: $state);
}),
])->statePath('filterData');
}
protected function getFooterWidgets(): array
{
return [
PlayerPropsTable::class,
PlayerPropsDrop::class,
];
}
public function getFooterWidgetsColumns(): int|array
{
return 5;
}
private function boxNames(): array
{
return [2 => 'DR', 4 => 'MR', 6 => 'LW', 9 => 'DC', 10 => 'DM', 11 => 'MC', 12 => 'AM', 15 => 'SW', 16 => 'DC', 17 => 'DM', 18 => 'MC', 19 => 'AM', 20 => 'SM', 21 => 'ST', 23 => 'DC', 24 => 'DM', 25 => 'MC', 26 => 'AM', 30 => 'DL', 32 => 'ML', 34 => 'RW'];
}
private function lineUpOptinos(): array
{
return [
'3313' => '3313',
'3331' => '3331',
'3331-' => '3331-',
'3331+' => '3331+',
'3412-' => '3412-',
'3412+' => '3412+',
'3421-' => '3421-',
'3421+' => '3421+',
'343-' => '343-',
'343+' => '343+',
'3511' => '3511',
'3511-' => '3511-',
'3511+' => '3511+',
'352' => '352',
'352-' => '352-',
'352+' => '352+',
'4132' => '4132',
'4213-' => '4213-',
'4213+' => '4213+',
'4222' => '4222',
'4231' => '4231',
'424' => '424',
'4312' => '4312',
'4312-' => '4312-',
'4312+' => '4312+',
'4321' => '4321',
'4321-' => '4321-',
'4321+' => '4321+',
'433' => '433',
'433-' => '433-',
'433+' => '433+',
'4411-' => '4411-',
'4411+' => '4411+',
'442' => '442',
'442-' => '442-',
'442+' => '442+',
'451' => '451',
'451-' => '451-',
'451+' => '451+',
'523-' => '523-',
'523+' => '523+',
'5311' => '5311',
'5311-' => '5311-',
'5311+' => '5311+',
'532' => '532',
'532-' => '532-',
'532+' => '532+',
'541-' => '541-',
'541+' => '541+',
];
}
private function linUpMap(): array
{
return [
'3313' => [9, 16, 23, 11, 18, 25, 19, 6, 34, 21],
'3331' => [9, 16, 23, 17, 11, 25, 12, 19, 26, 21],
'3331-' => [9, 16, 23, 10, 18, 24, 12, 19, 26, 21],
'3331+' => [9, 16, 23, 11, 18, 25, 12, 19, 26, 21],
'3412-' => [9, 16, 23, 4, 10, 24, 32, 19, 20, 21],
'3412+' => [9, 16, 23, 4, 11, 25, 32, 19, 20, 21],
'3421-' => [9, 16, 23, 4, 10, 24, 32, 12, 26, 21],
'3421+' => [9, 16, 23, 4, 11, 25, 32, 12, 26, 21],
'343-' => [9, 16, 23, 4, 10, 24, 32, 6, 34, 21],
'343+' => [9, 16, 23, 4, 11, 25, 32, 6, 34, 21],
'3511' => [9, 16, 23, 4, 11, 17, 25, 32, 19, 21],
'3511-' => [9, 16, 23, 4, 10, 18, 24, 32, 19, 21],
'3511+' => [9, 16, 23, 4, 11, 18, 25, 32, 19, 21],
'352' => [9, 16, 23, 4, 11, 17, 25, 32, 20, 21],
'352-' => [9, 16, 23, 4, 10, 18, 24, 32, 20, 21],
'352+' => [9, 16, 23, 4, 11, 18, 25, 32, 20, 21],
'4132' => [2, 9, 23, 30, 17, 12, 19, 26, 20, 21],
'4213-' => [2, 9, 23, 30, 10, 24, 19, 6, 34, 21],
'4213+' => [2, 9, 23, 30, 11, 25, 19, 6, 34, 21],
'4222' => [2, 9, 23, 30, 10, 24, 12, 26, 20, 21],
'4231' => [2, 9, 23, 30, 10, 24, 12, 19, 26, 21],
'424' => [2, 9, 23, 30, 10, 24, 6, 34, 20, 21],
'4312' => [2, 9, 23, 30, 17, 11, 25, 19, 20, 21],
'4312-' => [2, 9, 23, 30, 10, 18, 24, 19, 20, 21],
'4312+' => [2, 9, 23, 30, 11, 18, 25, 19, 20, 21],
'4321' => [2, 9, 23, 30, 17, 11, 25, 12, 26, 21],
'4321-' => [2, 9, 23, 30, 10, 18, 24, 12, 26, 21],
'4321+' => [2, 9, 23, 30, 11, 18, 25, 12, 26, 21],
'433' => [2, 9, 23, 30, 17, 11, 25, 6, 34, 21],
'433-' => [2, 9, 23, 30, 10, 18, 24, 6, 34, 21],
'433+' => [2, 9, 23, 30, 11, 18, 25, 6, 34, 21],
'4411-' => [2, 9, 23, 30, 4, 10, 24, 32, 19, 21],
'4411+' => [2, 9, 23, 30, 4, 11, 25, 32, 19, 21],
'442' => [2, 9, 23, 30, 4, 17, 18, 32, 20, 21],
'442-' => [2, 9, 23, 30, 4, 10, 24, 32, 20, 21],
'442+' => [2, 9, 23, 30, 4, 11, 25, 32, 20, 21],
'451' => [2, 9, 23, 30, 4, 17, 11, 25, 32, 21],
'451-' => [2, 9, 23, 30, 4, 10, 18, 24, 32, 21],
'451+' => [2, 9, 23, 30, 4, 11, 18, 25, 32, 21],
'523-' => [2, 9, 16, 23, 30, 10, 24, 6, 34, 21],
'523+' => [2, 9, 16, 23, 30, 11, 25, 6, 34, 21],
'5311' => [2, 9, 16, 23, 30, 17, 11, 25, 19, 21],
'5311-' => [2, 9, 16, 23, 30, 10, 18, 24, 19, 21],
'5311+' => [2, 9, 16, 23, 30, 11, 18, 25, 19, 21],
'532' => [2, 9, 16, 23, 30, 17, 11, 25, 20, 21],
'532-' => [2, 9, 16, 23, 30, 10, 18, 24, 20, 21],
'532+' => [2, 9, 16, 23, 30, 11, 18, 25, 20, 21],
'541-' => [2, 9, 16, 23, 30, 4, 10, 24, 32, 21],
'541+' => [2, 9, 16, 23, 30, 4, 11, 25, 32, 21],
];
}
}