88 lines
2.1 KiB
PHP
88 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Traits\PlayerProps;
|
|
|
|
trait LineUps
|
|
{
|
|
public function prepareLineUp()
|
|
{
|
|
$arr = [
|
|
'team_id' => $this->team_id,
|
|
'season_or_date' => $this->season_or_date,
|
|
];
|
|
|
|
$players = $this->loadPlayerAll();
|
|
|
|
$arr = collect();
|
|
foreach ($players as $value) {
|
|
if ($value['position'] != '') {
|
|
$arr->push([
|
|
'id' => $value['ss_player_id'],
|
|
'min' => $value['average_min'],
|
|
'pos' => $value['position'],
|
|
'name' => $value['player_name'],
|
|
]);
|
|
}
|
|
}
|
|
|
|
return $arr;
|
|
}
|
|
|
|
public function generateLineUp(): void
|
|
{
|
|
if ($this->activeLineUp && $this->team_id) {
|
|
|
|
$players = $this->prepareLineUp();
|
|
|
|
$places = $this->getLineUpMap($this->activeLineUp);
|
|
|
|
$lineup = [];
|
|
|
|
$id_used = [];
|
|
|
|
foreach ($places as $place) {
|
|
$this->getPlayerForPosition($lineup, $id_used, $place, $players);
|
|
}
|
|
|
|
for ($i = 1; $i <= 35; $i++) {
|
|
$this->boxes[$i] = [];
|
|
}
|
|
|
|
$this->clearResultTable();
|
|
|
|
$this->player_on_field_counter = 0;
|
|
|
|
foreach ($this->players as $k => $record) {
|
|
$id = $record['id'];
|
|
if (isset($lineup[$id])) {
|
|
|
|
$this->boxes[$lineup[$id]['place']] = $record;
|
|
|
|
$this->players[$k]['active'] = 1;
|
|
$this->players[$k]['pos'] = $lineup[$id]['position'];
|
|
|
|
$this->player_on_field_counter++;
|
|
} else {
|
|
$this->players[$k]['active'] = 0;
|
|
$this->players[$k]['pos'] = '';
|
|
}
|
|
}
|
|
|
|
$this->calculateAspg();
|
|
|
|
$this->storePlacement();
|
|
}
|
|
}
|
|
|
|
public function updateLineup(?string $state)
|
|
{
|
|
$this->clearResultTable();
|
|
|
|
if (isset($this->lineupsMap[$state])) {
|
|
$this->lineup = $this->lineUpMap[$state];
|
|
} else {
|
|
$this->lineup = [];
|
|
}
|
|
}
|
|
}
|