Arbeit an Auf/Abstieg
This commit is contained in:
parent
5515e13f02
commit
d8a7f78cbd
7 changed files with 61 additions and 52 deletions
|
|
@ -66,8 +66,11 @@ class LeaguesController extends Controller
|
|||
}
|
||||
|
||||
public function createLeagues($start_round_id, $round_count) {
|
||||
|
||||
League::createLeagues($start_round_id, $round_count);
|
||||
|
||||
|
||||
Log::info("LeaguesController::createLeagues completed.");
|
||||
|
||||
Match::createMatchups();
|
||||
|
||||
return redirect("/seasons");
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use \App\Setting;
|
||||
use Log;
|
||||
use \App\Leagues\League;
|
||||
|
||||
class Season extends Model
|
||||
{
|
||||
|
|
@ -31,9 +32,7 @@ class Season extends Model
|
|||
return $currentSeason;
|
||||
}
|
||||
|
||||
|
||||
public static function setCurrent($season_id) {
|
||||
|
||||
$setting = Setting::all()->first();
|
||||
if (!$setting) {
|
||||
$setting = Setting::create([
|
||||
|
|
@ -50,4 +49,11 @@ class Season extends Model
|
|||
return $seasons[1];
|
||||
}
|
||||
|
||||
public static function hasQualifications($seasonId) {
|
||||
$leagues = League::where('season_id','=',$seasonId)->get();
|
||||
foreach($leagues as $league) {
|
||||
if ($league->rank == League::RANK_QUALIFICATION) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@ class League extends Model
|
|||
|
||||
public static function createLeagues($start_round_id, $round_count) {
|
||||
$currentSeason=Season::getCurrent();
|
||||
$previousSeason=Season::getPrevious();
|
||||
|
||||
// Eventuell vorhandene Ligen loeschen
|
||||
$leagues=League::where('season_id','=',$currentSeason->id)->get();
|
||||
|
|
@ -169,12 +170,13 @@ class League extends Model
|
|||
|
||||
$league_ids=array();
|
||||
|
||||
//TODO: Den Leaguemode kann die Methode selbst rausfinden.
|
||||
//TODO: Wenn es keine Vorsaison gibt -> Qualifikation
|
||||
//TODO: Ansonsten: Ligen erzeugen.
|
||||
$league_mode="Qualifikation";
|
||||
//TODO: Ansonsten: Standard-Ligen (1,2,3) erzeugen. Liga 1 und 2 sind auf 22 Spieler festgelegt.
|
||||
|
||||
if ($league_mode=="Qualifikation") {
|
||||
if (!$previousSeason) {
|
||||
// Alle Spieler werden gleichmässig auf Qualifikationsgruppen aufgeteilt
|
||||
// Dieser Modus wird gewählt, wenn es keine Vorsaison gibt, es also
|
||||
// die erste Saison im System ist.
|
||||
for ($league_nr=1; $league_nr<=$neededLeagues; $league_nr+=1) {
|
||||
$league = League::create([
|
||||
'is_qualification' => true,
|
||||
|
|
@ -208,11 +210,13 @@ class League extends Model
|
|||
}
|
||||
|
||||
} else {
|
||||
// Es gibt eine Vorsaison.
|
||||
// - 1.) Ligen erzeugen
|
||||
// - 2.) unified Liste bauen
|
||||
// - 3.) Wenn Vorsaison keine Quali war, dann Auf & Abstieg umsetzen ( unfified Liste als Basis )
|
||||
// - 4.) Member den Ligen zuordnen
|
||||
|
||||
// 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.
|
||||
|
||||
// Erzeugung der Ligen
|
||||
$league_size1= min(22,$active_member_count);
|
||||
$league1 = League::create([
|
||||
'is_qualification' => false,
|
||||
|
|
|
|||
|
|
@ -35,19 +35,18 @@ class Match extends Model
|
|||
// Wenn es keine previous League gibt, dann ist $league->rank immer RANK_QUALIFICATION,
|
||||
// ansonsten ist es einer von RANK_LEAGUE1, RANK_LEAGUE2, RANK_LEAGUE3
|
||||
|
||||
if ($league->rank == League::RANK_QUALIFICATION) {
|
||||
if ($league->rank <= League::RANK_QUALIFICATION) {
|
||||
$rounds = Round::where('id','>=',$league->start_round_id)->get();
|
||||
$roundNr=1;
|
||||
$neededRoundCount = Match::getNumberOfNeededRounds($league->id);
|
||||
|
||||
$allPairings=Match::getAllPairings($league->id, sizeof($rounds));
|
||||
Log::info("all pairings:");
|
||||
Log::info($allPairings);
|
||||
|
||||
foreach ($rounds as $round) {
|
||||
$pairings = $allPairings[$roundNr];
|
||||
// Save pairings
|
||||
foreach($pairings as $pair) {
|
||||
Log::info("Saving match. ".$pair[0]." vs ".$pair[1]." roundid=".$round->id);
|
||||
Log::info("Saving match. " . $pair[0] . " vs " . $pair[1] . " roundid=" . $round->id);
|
||||
$newMatch = Match::create([
|
||||
'league_id' => $league->id,
|
||||
'round_id' => $round->id,
|
||||
|
|
@ -55,7 +54,7 @@ class Match extends Model
|
|||
'user2_id' => $pair[1]
|
||||
]);
|
||||
$newMatch->save();
|
||||
}
|
||||
}
|
||||
$roundNr += 1;
|
||||
if ($roundNr > $neededRoundCount) break;
|
||||
}
|
||||
|
|
@ -114,8 +113,13 @@ class Match extends Model
|
|||
}
|
||||
|
||||
|
||||
// Hier findet RoundRobin statt.
|
||||
public static function getAllPairings($leagueId, $roundCount) {
|
||||
$members = LeagueMember::getMembers($leagueId);
|
||||
if (sizeof($members) % 2 == 1) { // ungerade memberzahl => freilos einfügen
|
||||
array_push($members,-1);
|
||||
}
|
||||
|
||||
shuffle($members);
|
||||
//error_log("Number of members:".sizeof($members));
|
||||
$pairingCount = Match::getNumberOfPairingsPerRound($leagueId);
|
||||
|
|
@ -155,29 +159,36 @@ class Match extends Model
|
|||
$slot = 1;
|
||||
}
|
||||
$pairings[$idx][$slot] = $userId;
|
||||
error_log($idx.",".$slot." => ".$userId);
|
||||
//error_log($idx.",".$slot." => ".$userId);
|
||||
}
|
||||
|
||||
//error_log("Pairings for RoundNr ".$currentRoundNr.":");
|
||||
$strPairings="";
|
||||
//foreach($pairings as $pairing) {
|
||||
//error_log(">".$pairing[0].":".$pairing[1]);
|
||||
//$strPairings = $strPairings." ".$pairing[0].":".$pairing[1];
|
||||
//}
|
||||
//error_log($strPairings);
|
||||
//error_log("-------");
|
||||
// Matches die nur einen Teilnehmer haben entfernen. Passiert bei ungerader Teilnehmerzahl.
|
||||
// Der nicht im Pairing befindliche Spieler hat einen spielfreien Tag.
|
||||
|
||||
$all[$currentRoundNr]=$pairings;
|
||||
$pairings_clean=array();
|
||||
foreach($pairings as $idx => $pairing) {
|
||||
if ($pairing[0] == -1 || $pairing[1] == -1) {
|
||||
//error_log("DONT ADD");
|
||||
} else {
|
||||
//error_log("adding...");
|
||||
$pairings_clean[$idx] = $pairing;
|
||||
}
|
||||
}
|
||||
$all[$currentRoundNr]=$pairings_clean;
|
||||
//$all[$currentRoundNr]=$pairings;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//foreach ($all as $roundNr => $pairings) {
|
||||
// foreach ($pairings as $pairing)
|
||||
//error_log("round_".$roundNr.":user_".$pairing[0]."!:user_".$pairing[1]."!");
|
||||
// foreach ($pairings as $slotIdx => $pairing) {
|
||||
// error_log($pairing[0]." vs ".$pairing[1]);
|
||||
// }
|
||||
// error_log("");
|
||||
//}
|
||||
//return null;
|
||||
|
||||
return $all; // $all[$roundnr]= Array of Tuples ( UserId1, UserId2 )
|
||||
//return null;
|
||||
|
||||
}
|
||||
|
||||
public static function getNumberOfPairingsPerRound($leagueId) {
|
||||
|
|
@ -190,8 +201,11 @@ class Match extends Model
|
|||
}
|
||||
|
||||
public static function getNumberOfNeededRounds($leagueId) {
|
||||
$members = LeagueMember::getMembers($leagueId);
|
||||
return sizeof($members)-1;
|
||||
$members = LeagueMember::getMembers($leagueId);
|
||||
$memberCount = sizeof($members);
|
||||
|
||||
if ($memberCount % 2 == 1) { return $memberCount; } // 1 Runde mehr wg. Freilos für 1 Spieler
|
||||
return $memberCount-1;
|
||||
}
|
||||
|
||||
public static function getMatchResults($leagueId, $maxRoundId=-1) {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
<a href="#" id="btn_league" onclick="toggleSelect('dropdown_league'); return false;" style="font-weight:normal; font-color: blue; font-size: 22px;">Spieler-Liga</a>
|
||||
<div id="dropdown_league" class="dropdown-content">
|
||||
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/league_show_rounds/league_rank=4/round_id=30">Spielplan</a>
|
||||
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/league/show/rank=4/max_round_id=-1#user_{{Auth::user()->id}}">Tabellen</a>
|
||||
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/league/show/rank=4/max_round_id=-1#playerid_{{Auth::user()->id}}">Tabellen</a>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
@foreach($playerTuples as $pos => $player)
|
||||
<tr class="table-bordered">
|
||||
<td> {{$pos+1}} </td>
|
||||
<td> <a name="user_{{$player[0]}}" class="{{ $player[0]==Auth::user()->id ? 'blink_text' : '' }}" href="/league/showSingleUserMatches/user_id={{$player[0]}}"> {{$userNames[$player[0]]}} </a> </td>
|
||||
<td> <a name="playerid_{{$player[0]}}" class="{{ $player[0]==Auth::user()->id ? 'blink_text' : '' }}" href="/league/showSingleUserMatches/user_id={{$player[0]}}"> {{$userNames[$player[0]]}} </a> </td>
|
||||
<td> {{$player[1]}} </td>
|
||||
<td> {{$player[2]-$player[3]}} </td>
|
||||
<td> {{$player[2]}}:{{$player[3]}} </td>
|
||||
|
|
|
|||
|
|
@ -25,15 +25,6 @@
|
|||
<h3>Anzahl Runden:</h3>
|
||||
<input id="input_round_count" value="{{$round_count}}"></input>
|
||||
|
||||
<h3>Liga-Modus</h3>
|
||||
|
||||
<div class="dropdown">
|
||||
<button id="btn_leaguemode" onclick="toggleDropdown('dropdown_leaguemode'); return false;" class="dropbtn">{{$league_mode}}</button>
|
||||
<div id="dropdown_leaguemode" class="dropdown-content">
|
||||
<a onclick="selectLeagueMode('Qualifikation'); return false;" href="">Qualifikation</a>
|
||||
<a onclick="selectLeagueMode('Liga-Spiel'); return false;" href="">Liga-Spiel</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
|
|
@ -48,12 +39,8 @@
|
|||
<script>
|
||||
|
||||
global_start_round_id={!! $start_round_id !!};
|
||||
global_league_mode="{!! $league_mode !!}";
|
||||
|
||||
|
||||
|
||||
console.log(global_start_round_id);
|
||||
console.log(global_league_mode);
|
||||
|
||||
function createLeague() {
|
||||
console.log("create League");
|
||||
|
|
@ -65,11 +52,6 @@
|
|||
window.location=link;
|
||||
}
|
||||
|
||||
function selectLeagueMode($modename) {
|
||||
document.getElementById("btn_leaguemode").innerHTML=$modename;
|
||||
global_league_mode=$modename;
|
||||
}
|
||||
|
||||
function setStartRound($roundname, $round_id) {
|
||||
document.getElementById("btn_startround").innerHTML=$roundname;
|
||||
//alert($round_id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue