Working on League Matchings (Qualification)

This commit is contained in:
Torsten 2017-09-18 08:28:42 +02:00
parent 82e60df35f
commit 9c0f94758d
4 changed files with 8552 additions and 9 deletions

View file

@ -10,7 +10,7 @@ class Match extends Model
{
protected $table ='leagues_matches';
protected $fillable = [
'id','league_id','user1_id','user2_idsubrank','start_round_id','name'
'id','league_id','round_id','user1_id','user2_id'
];
public static function createMissingMatchups() {
@ -50,7 +50,6 @@ class Match extends Model
// add Match
array_push($matches, [$user1, $user2]);
}
}
}
@ -72,17 +71,48 @@ class Match extends Model
*/
// SOOOO
// VIEL
// SPASS !!!
// In der Runde darf es nicht schon ein bestehendes Match mit dem User geben
// $round = Match::getFreeRound($user_id, $league_id)
}
}
}
}
// Wieviele Spiele finden pro Runde statt ? => Jeder Spieler spielt, also GruppenGröße/2, bei ungerader Gruppengröße gibt es spielfreie Tage.
public static function getFreeRound($user_id, $league_id) {
$round_matches = Match::where('league_id','=',$league_id)->orderBy('round_id')->get();
$membercount = League::getMemberCount($league_id);
$max_size = divint($membercount,2);
$current_round_id=-1;
$current_member_count=0;
$is_round_usable=true;
foreach($round_matches as $round_match) {
$current_member_count+=1;
// 1.) Runde darf nicht schon Gruppengröße/2 Matches enthalten (siehe $max_size)
// 2.) Spieler darf in der Runde nicht schon spielen (als user1_id enthalten sein)
if ($current_member_count>$max_size) { $is_round_usable=false; continue; }
if ($round_match->user1_id == $user_id) { $is_round_usable=false; continue; }
if ($round_match->round_id != $current_round_id) {
if ($is_round_usable && $current_round_id!=-1) { return $round_match->round_id; }
$current_round_id=$round_match->match_id;
$current_member_count=0;
$is_round_usable = true;
}
}
return -1; // No suitable/free round found for Player Match.
}
}