...
This commit is contained in:
parent
ed0c445bfa
commit
30f6157606
15 changed files with 248 additions and 169 deletions
|
|
@ -65,114 +65,9 @@ class LeaguesController extends Controller
|
|||
return view('leagues.index', compact('season','rounds','start_round_id','start_round_name','league_mode','round_count'));
|
||||
}
|
||||
|
||||
public function createLeagues($start_round_id, $round_count, $league_mode) {
|
||||
$currentSeason=Season::getCurrent();
|
||||
|
||||
// Eventuell vorhandene Ligen loeschen
|
||||
$leagues=League::where('season_id','=',$currentSeason->id)->get();
|
||||
if ($leagues) {
|
||||
foreach ($leagues as $league) {
|
||||
DB::table('leagues_matches')->where('league_id', '=', $league->id)->delete();
|
||||
DB::table('leagues_members')->where('league_id', '=', $league->id)->delete();
|
||||
DB::table('leagues')->where('id', '=', $league->id)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$active_member_count=sizeof(User::getActives());
|
||||
Log::info("Aktive Spieler: ".$active_member_count);
|
||||
$neededLeagues = League::neededLeagues($active_member_count, $round_count);
|
||||
Log::info("Benötigte Quali-Gruppen: ".$neededLeagues);
|
||||
|
||||
$league_ids=array();
|
||||
Log::info("League Mode:".$league_mode);
|
||||
|
||||
if ($league_mode=="Qualifikation") {
|
||||
for ($league_nr=1; $league_nr<=$neededLeagues; $league_nr+=1) {
|
||||
$league = League::create([
|
||||
'is_qualification' => true,
|
||||
'name' => 'Qualifikationsgruppe '.$league_nr,
|
||||
'rank' => '4',
|
||||
'subrank' => $league_nr,
|
||||
'round_count' => $round_count,
|
||||
'season_id' => $currentSeason->id,
|
||||
'start_round_id' => $start_round_id
|
||||
]);
|
||||
$league->save();
|
||||
$league_ids[$league_nr-1] = $league->id;
|
||||
}
|
||||
|
||||
// Distribute members
|
||||
$users = User::getActives();
|
||||
shuffle($users);
|
||||
$league_index=0;
|
||||
Log::info("Distributing Members between groups");
|
||||
while(sizeof($users)>0) {
|
||||
$user = array_pop($users);
|
||||
|
||||
$leagueMember = LeagueMember::create([
|
||||
'user_id' => $user->id,
|
||||
'league_id' => $league_ids[$league_index]
|
||||
]);
|
||||
$leagueMember->save();
|
||||
|
||||
$league_index+=1;
|
||||
if (sizeof($league_ids)==$league_index) { $league_index=0; }
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// ToDo: Branch Qualifikation/Liga entfällt in Zukunft, da Quali der Fallback für den Fall ist, dass keine vorherige Saison existiert.
|
||||
// Pokal und Play-Off findet hier nicht statt, da diese Wettbewerbe die Matches abgängig von existierenden Vorrunden-Ergebnissen erzeugen,
|
||||
// und daher zwangsläufig inkrementell sein müssen.
|
||||
|
||||
$league_size1= min(22,$active_member_count);
|
||||
$league1 = League::create([
|
||||
'is_qualification' => false,
|
||||
'name' => 'Spielerliga 1',
|
||||
'rank' => '1',
|
||||
'subrank' => '1',
|
||||
'round_count' => $round_count,
|
||||
'season_id' => $currentSeason->id,
|
||||
'start_round_id' => $start_round_id
|
||||
]);
|
||||
|
||||
$league_size2=min(22,$active_member_count - $league_size1);
|
||||
|
||||
if ($league_size2>0) {
|
||||
$league2 = League::create([
|
||||
'is_qualification' => false,
|
||||
'name' => 'Spielerliga 2',
|
||||
'rank' => '2',
|
||||
'subrank' => '1',
|
||||
'round_count' => $round_count,
|
||||
'season_id' => $currentSeason->id,
|
||||
'start_round_id' => $start_round_id
|
||||
]);
|
||||
|
||||
$league_size3 = $active_member_count - $league_size1 - $league_size2;
|
||||
|
||||
if ($league_size3>0) {
|
||||
$neededLeagues = League::neededLeagues($league_size3, $round_count);
|
||||
for ($league_nr=1; $league_nr<=$neededLeagues; $league_nr+=1) {
|
||||
$league = League::create([
|
||||
'is_qualification' => false,
|
||||
'name' => 'Spielerliga 3, Gruppe '.$league_nr,
|
||||
'rank' => '3',
|
||||
'subrank' => $league_nr,
|
||||
'round_count' => $round_count,
|
||||
'season_id' => $currentSeason->id,
|
||||
'start_round_id' => $start_round_id
|
||||
]);
|
||||
$league->save();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: LeagueMembers zu den Leagues hinzufügen, abhängig vom zuzuordnenden Platz
|
||||
|
||||
}
|
||||
}
|
||||
public function createLeagues($start_round_id, $round_count) {
|
||||
|
||||
League::createLeagues($start_round_id, $round_count);
|
||||
Match::createMatchups();
|
||||
|
||||
return redirect("/seasons");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue