From ee2fb7b8124186794ede8a5d76934776566f2670 Mon Sep 17 00:00:00 2001 From: salam Date: Sun, 26 Jul 2026 11:54:32 +0200 Subject: [PATCH] fix ImportPlayer --- app/Filament/Imports/Helper/ImportPlayer.php | 240 +++++++------------ 1 file changed, 81 insertions(+), 159 deletions(-) diff --git a/app/Filament/Imports/Helper/ImportPlayer.php b/app/Filament/Imports/Helper/ImportPlayer.php index b1db9151..251839f5 100644 --- a/app/Filament/Imports/Helper/ImportPlayer.php +++ b/app/Filament/Imports/Helper/ImportPlayer.php @@ -10,7 +10,75 @@ class ImportPlayer { public static function run(string $filePath): void { - $fieldnames = ['activeteam_id', 'playersubstitute_id', 'goals', 'assists', 'own_goals', 'shots_on_target', 'shots_off_target', 'shots_blocked', 'fouls', 'was_fouled', 'offsides', 'possessions_lost', 'total_tackles', 'touches', 'total_cross', 'cross_done', 'total_dribbles', 'dribbles_won', 'total_ground_duels', 'total_ground_duels_won', 'total_aerial_duels', 'total_duels_aerial_won', 'total_pass', 'pass', 'total_long_balls', 'long_balls', 'blocked_shots', 'clearances', 'dribbled_past', 'hit_woodwork', 'interceptions', 'key_pass', 'last_man_tackle', 'dispossessed', 'clearance_off_line', 'bcc', 'bcm', 'errors_lead_to_a_goal', 'errors_lead_to_a_shot', 'penalty_committed', 'penalty_miss', 'penalty_save', 'penalty_won', 'saves', 'saves_from_in_box', 'total_runs_out', 'runs_out', 'punches', 'good_high_claim', 'minutes_played', 'lineup', 'minute_event_during_the_match', 'type_event_during_the_match', 'description_event_during_the_match', 'subtype_event_during_the_match', 'card_yellow', 'card_yellowred', 'card_red', 'ingamepenalty_missed', 'penaltyshoutout_scored', 'penaltyshoutout_missed', 'player_position', 'playerrating_value', 'tm_player_id']; + $fieldnames = [ + 'sport_id', + 'match_id', + 'ss_player_id', + 'activeteam_id', + 'playersubstitute_id', + 'goals', + 'assists', + 'own_goals', + 'shots_on_target', + 'shots_off_target', + 'shots_blocked', + 'fouls', + 'was_fouled', + 'offsides', + 'possessions_lost', + 'total_tackles', + 'touches', + 'total_cross', + 'cross_done', + 'total_dribbles', + 'dribbles_won', + 'total_ground_duels', + 'total_ground_duels_won', + 'total_aerial_duels', + 'total_duels_aerial_won', + 'total_pass', + 'pass', + 'total_long_balls', + 'long_balls', + 'blocked_shots', + 'clearances', + 'dribbled_past', + 'hit_woodwork', + 'interceptions', + 'key_pass', + 'last_man_tackle', + 'dispossessed', + 'clearance_off_line', + 'bcc', + 'bcm', + 'errors_lead_to_a_goal', + 'errors_lead_to_a_shot', + 'penalty_committed', + 'penalty_miss', + 'penalty_save', + 'penalty_won', + 'saves', + 'saves_from_in_box', + 'total_runs_out', + 'runs_out', + 'punches', + 'good_high_claim', + 'minutes_played', + 'lineup', + 'minute_event_during_the_match', + 'type_event_during_the_match', + 'description_event_during_the_match', + 'subtype_event_during_the_match', + 'card_yellow', + 'card_yellowred', + 'card_red', + 'ingamepenalty_missed', + 'penaltyshoutout_scored', + 'penaltyshoutout_missed', + 'player_position', + 'playerrating_value', + 'tm_player_id' + ]; SimpleExcelReader::create(storage_path('app/public/' . $filePath)) ->getRows() @@ -23,172 +91,26 @@ class ImportPlayer $update_array = []; foreach ($fieldnames as $key => $name) { - $offset = (int) $key + 3; - $update_array[$name] = $row[$offset]; + $update_array[$name] = $row[$key]; } + $sport_id = (int) $row['sport_id']; + $match_id = (int) $row['match_id']; + $ss_player_id = (int) $row['ss_player_id']; + + unset($row['sport_id']); + unset($row['match_id']); + unset($row['ss_player_id']); + StatistikoPlayer::updateOrCreate( [ - 'sport_id' => (int) $row[0], - 'match_id' => (int) $row[1], - 'ss_player_id' => (int) $row[2], + 'sport_id' => $sport_id, + 'match_id' => $match_id, + 'ss_player_id' => $ss_player_id, ], $update_array ); - - // StatistikoPlayer::where('sport_id', (int) $row[0]) - // ->where('match_id', (int) $row[1]) - // ->where('ss_player_id', (int) $row[2]) - // ->where('tm_player_id', (int) $row[3]) - // ->update($update_array, ['upsert' => true]); - - // if ($importmode == 'update') { - - // $update_array = []; - // foreach ($fieldnames as $key => $name) { - // $offset = (int) $key + 4; - // $update_array[$name] = $row[$offset]; - // } - - // // dd($update_array); - - // StatistikoPlayer::where('sport_id', (int) $row[0]) - // ->where('match_id', (int) $row[1]) - // ->where('ss_player_id', (int) $row[2]) - // ->where('tm_player_id', (int) $row[3]) - // ->update($update_array, ['upsert' => true]); - // } else { - // $insert_array = []; - // foreach ($fieldnames as $key => $name) { - // $insert_array[$name] = $row[$key]; - // } - - // StatistikoPlayer::insert($insert_array); - // } } }); } } -// sport_id, -// ss_match_id, -// ss_player_id -// activeteam_id, -// ss_playersubstitute_id, -// goals, -// assists, -// own_goals, -// shots_on_target, -// shots_off_target, -// shots_blocked, -// fouls, -// was_fouled, -// offsides, -// possessions_lost, -// total_tackles, -// touches, -// total_cross, -// cross_done, -// total_dribbles, -// dribbles_won, -// total_ground_duels, -// total_ground_duels_won, -// total_aerial_duels, -// total_duels_aerial_won, -// total_pass, -// pass, -// total_long_balls, -// long_balls, -// blocked_shots, -// clearances, -// dribbled_past, -// hit_woodwork, -// interceptions, -// key_pass, -// last_man_tackle, -// dispossessed, -// clearance_off_line, -// bcc, -// bcm, -// errors_lead_to_a_goal, -// errors_lead_to_a_shot, -// penalty_committed, -// penalty_miss, -// penalty_save, -// penalty_won, -// saves, -// saves_from_in_box, -// total_runs_out, -// runs_out, -// punches, -// good_high_claim, -// minutes_played, -// lineup, -// minute_event_during_the_match, -// type_event_during_the_match, -// description_event_during_the_match, -// subtype_event_during_the_match, -// ss_player_position, -// ss_playerrating_value, -// tm_player_id - -// 'sport_id' => (int) $row[0], -// 'match_id' => (int) $row[1], -// 'ss_player_id' => (int) $row[2], -// 'activeteam_id' => $row[2], -// 'playersubstitute_id' => $row[3], -// 'goals' => $row[4], -// 'assists' => $row[5], -// 'own_goals' => $row[5], -// 'shots_on_target' => $row[6], -// 'shots_off_target' => $row[7], -// 'shots_blocked' => $row[8], -// 'fouls' => $row[9], -// 'was_fouled' => $row[10], -// 'offsides' => $row[11], -// 'possessions_lost' => $row[12], -// 'total_tackles' => $row[13], -// 'touches' => $row[14], -// 'total_cross' => $row[15], -// 'cross_done' => $row[16], -// 'total_dribbles' => $row[17], -// 'dribbles_won' => $row[18], -// 'total_ground_duels' => $row[19], -// 'total_ground_duels_won' => $row[20], -// 'total_aerial_duels' => $row[21], -// 'total_duels_aerial_won' => $row[22], -// 'total_pass' => $row[23], -// 'pass' => $row[24], -// 'total_long_balls' => $row[25], -// 'long_balls' => $row[26], -// 'blocked_shots' => $row[27], -// 'clearances' => $row[28], -// 'dribbled_past' => $row[29], -// 'hit_woodwork' => $row[30], -// 'interceptions' => $row[31], -// 'key_pass' => $row[32], -// 'last_man_tackle' => $row[33], -// 'dispossessed' => $row[34], -// 'clearance_off_line' => $row[35], -// 'bcc' => $row[36], -// 'bcm' => $row[37], -// 'errors_lead_to_a_goal' => $row[38], -// 'errors_lead_to_a_shot' => $row[39], -// 'penalty_committed' => $row[40], -// 'penalty_miss' => $row[41], -// 'penalty_save' => $row[42], -// 'penalty_won' => $row[43], -// 'saves' => $row[44], -// 'saves_from_in_box' => $row[45], -// 'total_runs_out' => $row[46], -// 'runs_out' => $row[47], -// 'punches' => $row[48], -// 'good_high_claim' => $row[49], -// 'minutes_played' => $row[50], -// 'lineup' => $row[51], -// 'minute_event_during_the_match' => $row[52], -// 'type_event_during_the_match' => $row[53], -// 'description_event_during_the_match' => $row[54], -// 'subtype_event_during_the_match' => $row[55], -// 'player_position' => $row[56], -// 'playerrating_value' => $row[57], -// 'tm_player_id' => $row[58],