filter playeer played
This commit is contained in:
1 parent
74e9285bac
commit
5081ec9e32
30 files changed
+4114
-1420
No files matched your search
@@ -2,71 +2,85 @@
|
||||
|
||||
namespace App\Actions\Selections;
|
||||
|
||||
use App\Models\StatistikoDetail;
|
||||
use App\Models\StatistikoPlayer;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Models\SofaScorePlayerPerSeason;
|
||||
use App\Models\StatistikoEvent;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
|
||||
class LoadPlayer
|
||||
{
|
||||
public static function load($get)
|
||||
public static function load(Get $get)
|
||||
{
|
||||
// $res = CompetitionGroup::with('country')->where('id', $league_id)->first();
|
||||
// $season_mode = $res->country->season_mode;
|
||||
|
||||
$team_id = $get('team_id');
|
||||
|
||||
$season = $get('season');
|
||||
|
||||
$res_details = StatistikoDetail::where('txodds_id', $team_id)->get();
|
||||
$team_position = $get('team_position');
|
||||
|
||||
if (! $res_details) {
|
||||
return [];
|
||||
$season_or_date = $filter['season_or_date'] ?? 'season';
|
||||
if($season_or_date != 'season' or !count($season)) {
|
||||
$season[] = date('Y');
|
||||
}
|
||||
|
||||
$player_ids = [];
|
||||
foreach ($res_details as $val) {
|
||||
$player_ids[] = $val->tm_player_id;
|
||||
}
|
||||
$res_player = StatistikoPlayer::whereIn('tm_player_id', $player_ids)
|
||||
->with('event')
|
||||
->where('minutes_played', '>', 0)
|
||||
->select('match_id','tm_player_id')
|
||||
->get();
|
||||
$counting = [];
|
||||
foreach ($res_player as $val) {
|
||||
if(in_array($val->event->season, $season)){
|
||||
$tm_player_id = $val->tm_player_id;
|
||||
if(!isset($counting[$tm_player_id])){
|
||||
$counting[$tm_player_id] = 1;
|
||||
}else {
|
||||
$counting[$tm_player_id]++;
|
||||
}
|
||||
$matches = StatistikoEvent::where(function ($query) use ($team_id, $team_position) {
|
||||
switch ($team_position) {
|
||||
case 'home':
|
||||
return $query->where('home_id', '=', $team_id);
|
||||
case 'away':
|
||||
return $query->where('away_id', '=', $team_id);
|
||||
default:
|
||||
return $query->where('home_id', '=', $team_id)
|
||||
->orWhere('away_id', '=', $team_id);
|
||||
}
|
||||
}
|
||||
})->pluck('match_id')->toArray();
|
||||
|
||||
if (! $counting) {
|
||||
return [];
|
||||
}
|
||||
$matches_count = count($matches);
|
||||
|
||||
$colorlevel = round(max($counting)/3);
|
||||
$player = SofaScorePlayerPerSeason::with('details')->where('tx_team_id', $team_id)->whereIn('season', $season)->get();
|
||||
|
||||
$arr = [];
|
||||
foreach ($res_details as $val) {
|
||||
|
||||
$tm_player_id = $val->tm_player_id;
|
||||
$position = strtoupper($val->position);
|
||||
foreach ($player as $val) {
|
||||
|
||||
$matches_played = isset($counting[$tm_player_id]) ? $counting[$tm_player_id] : 0;
|
||||
if($matches_played < $colorlevel){
|
||||
$arr[$position][$val->tm_player_id] = '<span class="text-red-600">'.$val->name.' ('.$matches_played.')</span>';
|
||||
switch ($team_position) {
|
||||
case 'home':
|
||||
$events_played = $val->events_played_home;
|
||||
break;
|
||||
case 'away':
|
||||
$events_played = $val->events_played_away;
|
||||
break;
|
||||
default:
|
||||
$events_played = $val->events_played_home + $val->events_played_away;
|
||||
break;
|
||||
}
|
||||
else if($matches_played < $colorlevel*2){
|
||||
$arr[$position][$val->tm_player_id] = '<span class="text-blue-500">'.$val->name.' ('.$matches_played.')</span>';
|
||||
|
||||
$colorlevel = round($matches_count/3);
|
||||
|
||||
$position = strtoupper($val->details->position);
|
||||
|
||||
if($events_played < $colorlevel){
|
||||
$arr[$position][$val->tm_player_id] = '<span class="text-red-600 dark:text-red-500">'.$val->details->name.' ('.$events_played.')</span>';
|
||||
}
|
||||
else if($events_played < $colorlevel*2){
|
||||
$arr[$position][$val->tm_player_id] = '<span class="text-blue-600 dark:text-blue-500">'.$val->details->name.' ('.$events_played.')</span>';
|
||||
}
|
||||
else {
|
||||
$arr[$position][$val->tm_player_id] = '<span class="text-green-500">'.$val->name.' ('.$matches_played.')</span>';
|
||||
$arr[$position][$val->tm_player_id] = '<span class="text-green-600 dark:text-green-500">'.$val->details->name.' ('.$events_played.')</span>';
|
||||
}
|
||||
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function convertToHoursMins(int $time, $format = '%02dh:%02dm')
|
||||
{
|
||||
if ($time < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hours = floor($time / 60);
|
||||
$minutes = $time % 60;
|
||||
|
||||
return sprintf($format, $hours, $minutes);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user