League Creation
This commit is contained in:
parent
96101cb05d
commit
7c9d5eef1e
11 changed files with 160 additions and 46 deletions
|
|
@ -7,10 +7,15 @@ use Illuminate\Http\Request;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Leagues;
|
||||
|
||||
|
||||
use Auth;
|
||||
use App\Season;
|
||||
use App\Round;
|
||||
use App\User;
|
||||
|
||||
use App\leagues\League;
|
||||
use Log;
|
||||
use DB;
|
||||
|
||||
class LeagueController extends Controller
|
||||
{
|
||||
|
|
@ -20,23 +25,29 @@ class LeagueController extends Controller
|
|||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
$season = Season::where('id','=',$season_id)->first();
|
||||
$rounds = Round::where('season_id','=',$season_id)->orderBy('id')->get();
|
||||
|
||||
$league = League::where('season_id','=',$season_id)->first();
|
||||
if (!$season) return redirect("/seasons");
|
||||
|
||||
$start_round_name="Einstellen";
|
||||
$start_round_id=-1;
|
||||
if ($league) {
|
||||
if ($league->start_round_id) {
|
||||
$startRound = Round::where('id','=',$league->start_round_id)->first();
|
||||
$start_round_name = $startRound->name;
|
||||
$start_round_id = $startRound->id;
|
||||
}
|
||||
}
|
||||
|
||||
$startRound=array();
|
||||
$startRound['id'] = $start_round_id;
|
||||
$startRound['name'] = $start_round_name;
|
||||
$rounds = Round::where('season_id','=',$season_id)->orderBy('id')->get();
|
||||
if (!$rounds) return redirect("/seasons");
|
||||
|
||||
$round_count = 18;
|
||||
$start_round_name="Einstellen";
|
||||
$start_round_id=$rounds[0]->id;
|
||||
$league_mode="Einstellen";
|
||||
|
||||
$league = League::where('season_id','=',$season_id)->first();
|
||||
if ($league) {
|
||||
$startround = Round::where('season_id', '=', $season_id)->orderBy('id')->first();
|
||||
$start_round_id = $startround->id;
|
||||
|
||||
$startRound = Round::where('id','=',$league->start_round_id)->first();
|
||||
$start_round_name = $startRound->name;
|
||||
$start_round_id = $startRound->id;
|
||||
$round_count = $league->round_count;
|
||||
if($league->is_qualification) { $league_mode="Qualifikation"; } else { $league_mode="Liga-Spiel"; }
|
||||
}
|
||||
|
||||
// Fetch existing leagues
|
||||
|
||||
|
|
@ -47,7 +58,90 @@ class LeagueController extends Controller
|
|||
|
||||
//
|
||||
|
||||
|
||||
return view('leagues.index', compact('season','rounds','startRound'));
|
||||
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);
|
||||
|
||||
// Todo: Erzeugen der Ligen. Beachten: Matchup-Generierung in separater Method, da inkrementell.
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
$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 1',
|
||||
'rank' => '1',
|
||||
'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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return redirect("/seasons");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue