60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Traits\PlayerProps;
|
|
|
|
use App\Models\SsLineupMemory;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
trait Placements
|
|
{
|
|
public function loadPlacement()
|
|
{
|
|
$this->clearResultTable();
|
|
|
|
if ($this->team_id) {
|
|
|
|
$this->player_on_field_counter = 0;
|
|
|
|
$res = SsLineupMemory::where('client_id', Auth::user()->client_id)->where('team_id', $this->team_id)->where('lineup', $this->activeLineUp)->first();
|
|
|
|
if ($res) {
|
|
|
|
$placement = json_decode($res->placement, 1);
|
|
|
|
foreach ($this->players as $k => $record) {
|
|
|
|
$id = $record['id'];
|
|
|
|
if (isset($placement[$id]) && in_array($placement[$id], $this->lineup)) {
|
|
$this->boxes[$placement[$id]] = $record;
|
|
$this->players[$k]['active'] = 1;
|
|
$this->players[$k]['pos'] = $record['pos_ori'];
|
|
|
|
$this->player_on_field_counter++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// $this->calculateAspg();
|
|
}
|
|
|
|
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->team_id,
|
|
'lineup' => $this->activeLineUp,
|
|
], [
|
|
'placement' => json_encode($store),
|
|
'team_name' => $this->team_name,
|
|
]);
|
|
}
|
|
}
|