264 lines
6.7 KiB
PHP
264 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Filament\Widgets\PlayerProps\BoxNames;
|
|
use App\Traits\PlayerProps\BestLineUp;
|
|
use App\Traits\PlayerProps\ClearBoxes;
|
|
use App\Traits\PlayerProps\CopyData;
|
|
use App\Traits\PlayerProps\Expectations;
|
|
use App\Traits\PlayerProps\LineUpMap;
|
|
use App\Traits\PlayerProps\LineUps;
|
|
use App\Traits\PlayerProps\Placements;
|
|
use App\Traits\PlayerProps\PlayerAspg;
|
|
use App\Traits\PlayerProps\PlayerDataMerge;
|
|
use App\Traits\PlayerProps\PlayerFilter;
|
|
use App\Traits\PlayerProps\PlayerForPosition;
|
|
use App\Traits\PlayerProps\PlayerQuery;
|
|
use App\Traits\PlayerProps\SyncData;
|
|
use Filament\Widgets\Widget;
|
|
use Livewire\Attributes\On;
|
|
|
|
/**
|
|
* --- Aspettativa di Gioco (AdG) = Somma Goals fatti da Player nel DB / Somma Minuti Giocati da Player (SMG) nel DB * 90. Se la SMG è < Y per quel Player prenderemo in considerazione solo l'Aspettativa Statistica (AS). Il valore Y dovrebbe essere configurabile in una interfaccia. Il valore iniziale lo fissiamo a Y = 180
|
|
*/
|
|
class PlayerPropsDrop extends Widget
|
|
{
|
|
use BestLineUp;
|
|
use ClearBoxes;
|
|
use CopyData;
|
|
use Expectations;
|
|
use LineUpMap;
|
|
use LineUps;
|
|
use Placements;
|
|
use PlayerAspg;
|
|
use PlayerDataMerge;
|
|
use PlayerFilter;
|
|
use PlayerForPosition;
|
|
use PlayerQuery;
|
|
use SyncData;
|
|
|
|
protected string $view = 'livewire.player-props-drop';
|
|
|
|
public string $activeLineUp;
|
|
|
|
public string $team_name = '';
|
|
|
|
public string $season_or_date = 'season';
|
|
|
|
public string $date_spliter = '';
|
|
|
|
public string $season_mode;
|
|
|
|
public float $x_value = 3;
|
|
|
|
public float $y_value = 180;
|
|
|
|
public float $asp_team;
|
|
|
|
public int $count_player;
|
|
|
|
public int $home_id;
|
|
|
|
public int $away_id;
|
|
|
|
public int $team_id = 0;
|
|
|
|
public int $liga_id = 0;
|
|
|
|
public int $match_id = 0;
|
|
|
|
public int $part_1_value = 60;
|
|
|
|
public int $player_on_field_counter;
|
|
|
|
public string $team_home_away;
|
|
|
|
public array $activeBoxes;
|
|
|
|
public array $beschriftung;
|
|
|
|
public array $lineup;
|
|
|
|
public array $lineUpMap;
|
|
|
|
public array $season_selected;
|
|
|
|
public array $calculationVariables;
|
|
|
|
public array $players;
|
|
|
|
public array $boxes;
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->activeBoxes = BoxNames::load();
|
|
|
|
$this->season_or_date = 'season';
|
|
|
|
$this->lineUpMap = $this->loadLineUpMaps();
|
|
|
|
$this->player_on_field_counter = 0;
|
|
|
|
for ($i = 1; $i <= 35; $i++) {
|
|
$this->boxes[$i] = [];
|
|
if (isset($this->activeBoxes[$i])) {
|
|
$this->beschriftung[$i] = $this->activeBoxes[$i];
|
|
} else {
|
|
$this->beschriftung[$i] = '';
|
|
}
|
|
}
|
|
|
|
$this->lineup = $this->lineUpMap[$this->activeLineUp];
|
|
}
|
|
|
|
#[On('clear-all')]
|
|
public function clearAll()
|
|
{
|
|
$this->team_name = '';
|
|
$this->match_id = 0;
|
|
$this->team_id = 0;
|
|
for ($i = 1; $i <= 35; $i++) {
|
|
$this->boxes[$i] = [];
|
|
}
|
|
$this->players = [];
|
|
$this->dispatch('update-players', players: $this->players);
|
|
}
|
|
|
|
#[On('match-update')]
|
|
public function matchUpdate(?int $match_id)
|
|
{
|
|
$this->team_name = '';
|
|
$this->match_id = 0;
|
|
$this->players = [];
|
|
for ($i = 1; $i <= 35; $i++) {
|
|
$this->boxes[$i] = [];
|
|
}
|
|
if ($match_id) {
|
|
$this->match_id = $match_id;
|
|
}
|
|
$this->dispatch('update-players', players: $this->players);
|
|
}
|
|
|
|
#[On('team-update')]
|
|
public function teamUpdate(int $team_id)
|
|
{
|
|
$this->team_id = $team_id;
|
|
|
|
$this->syncData($team_id);
|
|
}
|
|
|
|
#[On('part_1_value-update')]
|
|
public function setPart1Value(int $part_1_value)
|
|
{
|
|
$this->part_1_value = $part_1_value;
|
|
|
|
if ($this->player_on_field_counter >= 10) {
|
|
|
|
$this->calculateAspg();
|
|
}
|
|
}
|
|
|
|
#[On('liga_id-update')]
|
|
public function ligaUpdate(int $liga_id)
|
|
{
|
|
$this->liga_id = $liga_id;
|
|
}
|
|
|
|
#[On('lineup-update')]
|
|
public function lineUpUpdate(int|string $activeLineUp)
|
|
{
|
|
$this->activeLineUp = $activeLineUp;
|
|
|
|
$this->lineup = $this->lineUpMap[$activeLineUp];
|
|
|
|
$this->generateLineUp();
|
|
}
|
|
|
|
#[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;
|
|
}
|
|
|
|
// when drag from field to field remove from prviouse field to prevent doubles
|
|
foreach ($this->boxes as $k => $record) {
|
|
if (count($record) && $record['id'] == (int) $player['id']) {
|
|
$this->clearBox($k);
|
|
}
|
|
}
|
|
|
|
// when drag from source remove from proviuse field
|
|
foreach ($this->players as $k => $record) {
|
|
if ($record['id'] == (int) $player['id']) {
|
|
if ($this->boxes[$boxNumber]) {
|
|
$this->clearBox($boxNumber);
|
|
}
|
|
$this->boxes[$boxNumber] = $record;
|
|
$this->players[$k]['active'] = 1;
|
|
$this->players[$k]['pos'] = $this->activeBoxes[$boxNumber];
|
|
|
|
$this->player_on_field_counter++;
|
|
}
|
|
}
|
|
|
|
$this->storePlacement();
|
|
|
|
if ($this->player_on_field_counter >= 10) {
|
|
$this->calculateAspg();
|
|
} else {
|
|
$this->dispatch('update-players', players: $this->players);
|
|
}
|
|
}
|
|
|
|
#[On('season_or_date-update')]
|
|
public function setSeasonOrData(string $season_or_date)
|
|
{
|
|
$this->season_or_date = $season_or_date;
|
|
|
|
if ($this->player_on_field_counter >= 10) {
|
|
$this->calculateAspg();
|
|
}
|
|
}
|
|
|
|
#[On('season_mode-update')]
|
|
public function setSeason(string $season_mode)
|
|
{
|
|
$this->season_mode = $season_mode;
|
|
}
|
|
|
|
#[On('season_selected-update')]
|
|
public function setSeasonSelected(array $season_selected)
|
|
{
|
|
$this->season_selected = $season_selected;
|
|
if ($this->player_on_field_counter >= 10) {
|
|
$this->calculateAspg();
|
|
}
|
|
}
|
|
|
|
#[On('date_spliter-update')]
|
|
public function setDateSpliter(string $date_spliter)
|
|
{
|
|
$this->date_spliter = $date_spliter;
|
|
if ($this->player_on_field_counter >= 10) {
|
|
$this->calculateAspg();
|
|
}
|
|
}
|
|
|
|
public function get_position(int $ss_player_id)
|
|
{
|
|
// see if player is in field and if yes get new position
|
|
foreach ($this->players as $record) {
|
|
if ($record['id'] == $ss_player_id) {
|
|
return $record['pos'];
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|