Created
September 10, 2017 11:31
-
-
Save uberswe/7cdeddc748011fa2c8204053d3cbe39b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach ($tournament->groups as $group) { | |
$i = 0; | |
foreach ($group->games->all() as $game) { | |
$x = 0; | |
foreach ($game->teams as $team) { | |
foreach ($teams as $t) { | |
if ($t == $team->name) { | |
break; | |
} | |
} | |
$teamids[$team->id] = $team->name; | |
} | |
foreach ($game->teams as $team) { | |
if ($teams[$i][$x] !== $team->name) { | |
$team->name = $teams[$i][$x]; | |
$team->save(); | |
} | |
// TODO Maybe we can check team id to determine first or second, or check array index? | |
$s = 0; | |
$s2 = 0; | |
foreach ($game->scores as $score) { | |
if ($score->team_id == $team->id) { | |
$s++; | |
if ($results[$column][$i][$s2] != $score->score && $results[$column][$i][$s2] != null && $results[$column][$i][$s2] != "null") { | |
Score::where(['team_id' => $team->id, 'game_id' => $game->id])->delete(); | |
$score = Score::create(['score' => $results[$column][$i][$s2], 'team_id' => $team->id, 'game_id' => $game->id]); | |
$score->save(); | |
// TODO Does the new score require us to add a game? Modify a game? | |
} | |
} | |
$s2++; | |
} | |
// We assume that each game always has two scores | |
if ($s == 0) { | |
foreach ($results[$column][$i] as $k=>$rs) { | |
$sc = Score::where(['team_id' => $team->id, 'game_id' => $game->id])->first(); | |
if (!$sc && $rs != null && $rs != "null") { | |
$score = Score::create(['score' => $rs, 'team_id' => $team->id, 'game_id' => $game->id]); | |
$score->save(); | |
} | |
} | |
} | |
$x++; | |
} | |
$i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment