Files
nuhodds_fi4/app/Actions/Selections/LoadPlayer.php
T
2026-06-18 17:57:22 +02:00

58 lines
1.9 KiB
PHP

<?php
namespace App\Actions\Selections;
use App\Models\StatistikoDetail;
use App\Models\StatistikoPlayer;
class LoadPlayer
{
public static function load($team_id)
{
// $res = CompetitionGroup::with('country')->where('id', $league_id)->first();
// $season_mode = $res->country->season_mode;
$res_details = StatistikoDetail::where('txodds_id', $team_id)->get();
if (! $res_details) {
return [];
}
$player_ids = [];
foreach ($res_details as $val) {
$player_ids[] = $val->tm_player_id;
}
$res_player = StatistikoPlayer::whereIn('tm_player_id', $player_ids)
->where('minutes_played', '>', 0)
->select('match_id','tm_player_id')
->get();
$counting = [];
foreach ($res_player as $val) {
$tm_player_id = $val->tm_player_id;
if(!isset($counting[$tm_player_id])){
$counting[$tm_player_id] = 1;
}else {
$counting[$tm_player_id]++;
}
}
$colorlevel = round(max($counting)/3);
$arr = [];
foreach ($res_details as $val) {
$tm_player_id = $val->tm_player_id;
$matches_played = isset($counting[$tm_player_id]) ? $counting[$tm_player_id] : 0;
if($matches_played < $colorlevel){
$arr[$val->position][$val->tm_player_id] = '<span class="text-gray-500">'.$val->name.' ('.$matches_played.')</span>';
}
else if($matches_played < $colorlevel*2){
$arr[$val->position][$val->tm_player_id] = '<span class="text-blue-500">'.$val->name.' ('.$matches_played.')</span>';
}
else {
$arr[$val->position][$val->tm_player_id] = '<span class="text-green-500">'.$val->name.' ('.$matches_played.')</span>';
}
}
return $arr;
}
}