Working on Qualification Pairings

This commit is contained in:
Torsten 2017-09-22 17:40:48 +02:00
parent 9c0f94758d
commit a66189ca00
19 changed files with 9005 additions and 237 deletions

View file

@ -13,24 +13,27 @@ use App\Season;
use App\Round;
use App\User;
use App\leagues\League;
use App\leagues\LeagueMember;
use App\Leagues\League;
use App\Leagues\LeagueMember;
use App\Leagues\Match;
use Log;
use DB;
class LeagueController extends Controller
class LeaguesController extends Controller
{
public function index($season_id) {
public function index() {
$season=Season::getCurrent();
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$season = Season::where('id','=',$season_id)->first();
$season = Season::where('id','=',$season->id)->first();
if (!$season) return redirect("/seasons");
$start_round_name="Einstellen";
$rounds = Round::where('season_id','=',$season_id)->orderBy('id')->get();
$rounds = Round::where('season_id','=',$season->id)->orderBy('id')->get();
if (!$rounds) return redirect("/seasons");
$round_count = 18;
@ -38,9 +41,9 @@ class LeagueController extends Controller
$start_round_id=$rounds[0]->id;
$league_mode="Einstellen";
$league = League::where('season_id','=',$season_id)->first();
$league = League::where('season_id','=',$season->id)->first();
if ($league) {
$startround = Round::where('season_id', '=', $season_id)->orderBy('id')->first();
$startround = Round::where('season_id', '=', $season->id)->orderBy('id')->first();
$start_round_id = $startround->id;
$startRound = Round::where('id','=',$league->start_round_id)->first();
@ -75,13 +78,13 @@ class LeagueController extends Controller
}
}
$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([
@ -101,6 +104,7 @@ class LeagueController extends Controller
$users = User::getActives();
shuffle($users);
$league_index=0;
Log::info("Distributing Members between groups");
while(sizeof($users)>0) {
$user = array_pop($users);
@ -115,7 +119,6 @@ class LeagueController extends Controller
}
} else {
// ToDo: Achtel-, Viertel-, Halb-, Finale require additional leagues; Same with Pokal, so createMissingLeagues method will be needed in the future
$league_size1= min(22,$active_member_count);
@ -134,8 +137,8 @@ class LeagueController extends Controller
if ($league_size2>0) {
$league2 = League::create([
'is_qualification' => false,
'name' => 'Spielerliga 1',
'rank' => '1',
'name' => 'Spielerliga 2',
'rank' => '2',
'subrank' => '1',
'round_count' => $round_count,
'season_id' => $currentSeason->id,
@ -163,6 +166,37 @@ class LeagueController extends Controller
}
}
Match::createMissingMatchups();
return redirect("/seasons");
}
public function showLeagueRounds($league_rank, $round_id) { // $round_id = $max_round_id
if (Auth::guest()) { return redirect("/"); }
$season=Season::getCurrent();
$roundNames = Round::getNames();
$leagueNames = League::getNames();
$leagues = League::where('season_id','=',$season->id)->where('rank','=', $league_rank)->get();
$matchesTotal = array();
foreach ($leagues as $league) {
$matches = Match::getLeagueMatches($league->id);
foreach ($matches as $match) {
if ($match->round_id <= $round_id) {
if (!key_exists($match->round_id, $matchesTotal)) {
$matchesTotal[$match->round_id]=array();
}
$lg = $matchesTotal[$match->round_id];
array_push($lg, $match);
$matchesTotal[$match->round_id] = $lg;
}
}
}
return view ('leagues.matches', compact('season', 'matchesTotal','leagues','leagueNames','roundNames'));
}
}