70 lines
2.8 KiB
PHP
70 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Traits\PlayerProps;
|
|
|
|
use App\Filament\Widgets\PlayerProps\PositionHirarchie;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
trait PlayerForPosition
|
|
{
|
|
public function getPlayerForPosition(array &$lineup, array &$id_used, int $place, Collection $players)
|
|
{
|
|
$log = 0;
|
|
|
|
$position = $this->activeBoxes[$place];
|
|
|
|
$hirarchy = PositionHirarchie::load();
|
|
|
|
$fitered = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
|
|
|
if (isset($fitered['id'])) {
|
|
|
|
if ($log) {
|
|
Log::debug("A $place - $position", $fitered);
|
|
}
|
|
|
|
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'min' => $fitered['min'], 'place' => $place, 'position' => $position];
|
|
$id_used[] = $fitered['id'];
|
|
} else {
|
|
if (isset($hirarchy[$position])) {
|
|
$position2 = $hirarchy[$position][0];
|
|
$fitered = $players->where('pos', $position2)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
|
|
|
if (isset($fitered['id'])) {
|
|
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'min' => $fitered['min'], 'place' => $place, 'position' => $position];
|
|
$id_used[] = $fitered['id'];
|
|
if ($log) {
|
|
Log::debug("B $place - $position $position2", $fitered);
|
|
}
|
|
|
|
} elseif (isset($hirarchy[$position][1])) {
|
|
$position3 = $hirarchy[$position][1];
|
|
$fitered = $players->where('pos', $position3)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
|
|
|
if (isset($fitered['id'])) {
|
|
if ($log) {
|
|
Log::debug("C $place - $position $position2 $position3", $fitered);
|
|
}
|
|
|
|
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'min' => $fitered['min'], 'place' => $place, 'position' => $position];
|
|
$id_used[] = $fitered['id'];
|
|
} elseif (isset($hirarchy[$position][2])) {
|
|
$position4 = $hirarchy[$position][2];
|
|
$fitered = $players->where('pos', $position4)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
|
|
|
if (isset($fitered['id'])) {
|
|
if ($log) {
|
|
Log::debug("D $place - $position $position2 $position3 $position4", $fitered);
|
|
}
|
|
|
|
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'min' => $fitered['min'], 'place' => $place, 'position' => $position];
|
|
$id_used[] = $fitered['id'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|