From a6b080248a2ebc8d5399df4b78baf472ee5c703b Mon Sep 17 00:00:00 2001 From: salam Date: Sat, 12 Sep 2026 16:30:04 +0200 Subject: [PATCH] board memory wip --- app/Livewire/BoardDispatcher.php | 47 ++++++++++++++++++- app/Models/SsLineupMemory.php | 7 ++- ...132429_create_ss_lineup_memories_table.php | 1 - 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/app/Livewire/BoardDispatcher.php b/app/Livewire/BoardDispatcher.php index 58d15d66..da2aed35 100644 --- a/app/Livewire/BoardDispatcher.php +++ b/app/Livewire/BoardDispatcher.php @@ -5,6 +5,7 @@ namespace App\Livewire; use App\Models\SofaScorePlayerPerSeason; use App\Models\SofaScorePlayerPosition; use App\Models\SofaScoreRosa; +use App\Models\SsLineupMemory; use App\Models\StatisticFixtures; use App\Models\StatistikoDetail; use App\Models\User; @@ -195,7 +196,7 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa } } - $this->clearResultTable(); + $this->loadPlacement(); } public function getHeadingTable(): HtmlString @@ -353,11 +354,51 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa } } - // dd($this->boxes); + $this->storePlacement(); $this->calculateAspg(); } + public function loadPlacement() + { + $this->clearResultTable(); + + $res = SsLineupMemory::where('client_id', Auth::user()->client_id)->where('team_id', $this->filters['team_id'])->first(); + + if ($res) { + $placement = json_decode($res->placement, 1); + + foreach ($this->sourceRecords as $k => $record) { + $id = $record['id']; + if (isset($placement[$id])) { + $this->boxes[$placement[$id]] = $record; + $this->sourceRecords[$k]['active'] = 1; + $this->sourceRecords[$k]['pos'] = $record['pos_ori']; + + $this->player_on_field_counter++; + } + } + } + } + + + public function storePlacement() + { + $store = []; + foreach ($this->boxes as $pos => $value) { + if ($value) { + $store[$value['id']] = $pos; + } + } + SsLineupMemory::updateOrCreate([ + 'client_id' => Auth::user()->client_id, + 'team_id' => $this->filters['team_id'], + ], [ + 'placement' => json_encode($store), + 'lineup' => $this->lineup_selected, + ]); + } + public function updateLineup(?string $state) { $this->clearResultTable(); @@ -397,6 +438,8 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa $this->sourceRecords[$k]['tsh'] = ''; $this->sourceRecords[$k]['crd'] = ''; } + + $this->storePlacement(); } } diff --git a/app/Models/SsLineupMemory.php b/app/Models/SsLineupMemory.php index 0ff9d398..08fe8886 100644 --- a/app/Models/SsLineupMemory.php +++ b/app/Models/SsLineupMemory.php @@ -6,5 +6,10 @@ use Illuminate\Database\Eloquent\Model; class SsLineupMemory extends Model { - // + protected $fillable = [ + 'client_id', + 'team_id', + 'lineup', + 'placement', + ]; } diff --git a/database/migrations/2026_09_12_132429_create_ss_lineup_memories_table.php b/database/migrations/2026_09_12_132429_create_ss_lineup_memories_table.php index d8712f75..aec91872 100644 --- a/database/migrations/2026_09_12_132429_create_ss_lineup_memories_table.php +++ b/database/migrations/2026_09_12_132429_create_ss_lineup_memories_table.php @@ -14,7 +14,6 @@ return new class extends Migration Schema::create('ss_lineup_memories', function (Blueprint $table) { $table->id(); $table->integer('client_id')->index(); - $table->integer('sport_id')->default(1); $table->integer('team_id')->index(); $table->string('lineup'); $table->text('placement');