'DR', 4 => 'MR', 6 => 'RW', 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 => 'LM']; public bool $copyDisabled = true; public bool $calculationDisabled = true; public string $ss_team_name = ''; public array $lineups = [3331 => [2, 9, 23, 30, 10, 24, 12, 19, 26, 21]]; public array $lineup = [2, 9, 23, 30, 10, 24, 12, 19, 26, 21]; public array $boxes = []; public array $beschriftung = []; public function mount(array $filters) { $this->ss_team_name = SofaScoreRosa::where('ss_team_id', $filters['team_id'])->value('ss_team_name'); $this->sourceRecords = PlayerCalculator::load($filters); for ($i = 1; $i <= 35; $i++) { $this->boxes[$i] = []; if (isset($this->activeBoxes[$i])) { $this->beschriftung[$i] = $this->activeBoxes[$i]; } else { $this->beschriftung[$i] = ''; } } // Log::debug('beschriftung', $this->beschriftung); } public function getHeadingTable(): HtmlString { return new HtmlString('
' . $this->ss_team_name . '
Gls
Fls
Ofs
Snt
Tsh
Crd
Foot
Evt
Ømin
'); } public function table(Table $table): Table { return $table ->headerActions([ Action::make('close') ->icon('phosphor-x') ->close(), Action::make('reset') ->icon('phosphor-arrows-clockwise') ->action(fn() => $this->clearAll()), Action::make('calculate') ->icon('phosphor-calculator') ->disabled($this->calculationDisabled) ->action(fn() => $this->calculateAspg()), Action::make('copy') ->icon('phosphor-copy') ->disabled($this->copyDisabled) ->action(fn() => $this->copyResult()), ]) /** * WICHTIG: Da Filament v5 zwingend eine Query braucht, nutzen wir ein * leeres Modell (z.B. ein beliebiges Basis-Modell deines Projekts) NUR als Dummy-Builder. * Alternativ kannst du ein anonymes Model nutzen. */ ->query(User::query()->whereRaw('1 = 0')) // Verhindert DB-Abfragen ->paginated(false) ->striped() ->defaultSort('name') ->columns([ ViewColumn::make('drag_card') ->columnSpanFull() ->label(fn() => $this->getHeadingTable()) ->view('filament.tables.columns.drag-card'), ]) ->filters([ SelectFilter::make('player_position') ->columnSpanFull() ->native(false) ->options([ 'attack' => 'Attack', 'midfield' => 'Midfield', 'defence' => 'Defence', 'goalkeeper' => 'Goalkeeper', ])->modifyFormFieldUsing(fn(Select $component) => $component->allowHtml()) ->query(function ($query) { return $query; }), ], layout: FiltersLayout::AboveContent) ->deferFilters(false) ->records(function () { $collection = collect($this->sourceRecords); $selectedPosition = $this->tableFilters['player_position']['value'] ?? null; if (! empty($selectedPosition)) { $collection = $collection->where('player_position', $selectedPosition); } return $collection; }); } #[On('element-dropped-in-box')] public function handleElementDropped(mixed $elementData, mixed $boxNumber): void { $boxNumber = (int) $boxNumber; $player = is_array($elementData) ? $elementData : json_decode($elementData, true); if (! $player || ! isset($player['id'])) { return; } foreach ($this->sourceRecords as $k => $record) { if ($record['id'] == (int) $player['id']) { $this->calculationDisabled = false; if ($this->boxes[$boxNumber]) { $this->clearBox($boxNumber); } $this->boxes[$boxNumber] = $record; $this->sourceRecords[$k]['active'] = 1; $this->sourceRecords[$k]['position'] = $this->activeBoxes[$boxNumber]; } } } public function clearBox(int $boxNumber): void { if (isset($this->boxes[$boxNumber])) { $tmp = $this->boxes[$boxNumber]; $player_id = 0; foreach ($tmp as $key => $value) { if ($key == 'id') { $player_id = $value; } } foreach ($this->sourceRecords as $k => $record) { if ($record['id'] == (int) $player_id) { $this->boxes[$boxNumber] = []; $this->sourceRecords[$k]['position'] = ''; $this->sourceRecords[$k]['active'] = 0; } } } } public function calculateAspg(): void { $this->copyDisabled = false; } public function clearAll(): void { for ($i = 1; $i <= 35; $i++) { $this->boxes[$i] = []; } foreach ($this->sourceRecords as $k => $record) { $this->sourceRecords[$k]['position'] = ''; $this->sourceRecords[$k]['active'] = 0; } $this->copyDisabled = true; $this->calculationDisabled = true; } public function copyResult() { return; $copystring = ''; foreach ($this->results as $row) { unset($row['origin']); unset($row['pcolor']); unset($row['ecolor']); unset($row['info']); $copystring .= implode("\t", $row) . "\n"; } $this->js("navigator.clipboard.writeText(`$copystring`)"); } public function render() { return view('livewire.board-dispatcher'); } }