} } $matches = array_reverse($matches); foreach ($matches as $k => $value) { shuffle($courts); if ($bye_team) { Scheduling::nextLevelMatch($event_id, $tour_id, $bye_team, $matches[$k]['id'], $courts[0], $allocate_time1, $y, $winner_bracket); } Scheduling::nextLevelMatch($event_id, $tour_id, $matches[$k]['id'], $matches[$k + 1]['id'], $courts[0], $allocate_time1, $y, $winner_bracket); if ($tour_type == 2) { Scheduling::nextLevelMatch($event_id, $tour_id, $value['id'], $matches[$k + 1]['id'], $courts[0], $allocate_time1, $y, $loser_bracket); } } if ($tour_type == 2) { $loss_bracket_matches = array_reverse($loss_bracket_matches); $loser_bye = Scheduling::getLoserBye($tour_id, $y - 1); foreach ($loss_bracket_matches as $k => $value) { if (count($loser_bye) == 1) { Scheduling::nextLevelMatch($event_id, $tour_id, $loser_bye[0]['id'], $value['id'], $courts[0], $allocate_time1, $y, $loser_bracket); } elseif (count($loser_bye) > 1) { Scheduling::nextLevelMatch($event_id, $tour_id, $loser_bye[0]['id'], $loser_bye[1]['id'], $courts[0], $allocate_time1, $y, $loser_bracket); } shuffle($courts); Scheduling::nextLevelMatch($event_id, $tour_id, $value['id'], $loss_bracket_matches[$k + 1]['id'], $courts[0], $allocate_time1, $y, $loser_bracket); } } } if ($tour_type == 2) { $penultimate_game = Scheduling::getFinalGame($tour_id, $event_id); Scheduling::nextLevelMatch($event_id, $tour_id, $penultimate_game[0]['wid'], $penultimate_game[0]['lid'], $courts[0], $allocate_time1, $n, $loser_bracket); $final_game = Scheduling::getFinalGame($tour_id, $event_id);