118 lines
3.8 KiB
PHP
118 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\leagues;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\leagues\League;
|
|
use App\User;
|
|
|
|
class Match extends Model
|
|
{
|
|
protected $table ='leagues_matches';
|
|
protected $fillable = [
|
|
'id','league_id','round_id','user1_id','user2_id'
|
|
];
|
|
|
|
public static function createMissingMatchups() {
|
|
$currentSeason = Season::getCurrent();
|
|
$leagues = League::where('season_id','=',$currentSeason->id);
|
|
|
|
// TODO: Differentiate Matchup selection by League Type
|
|
|
|
// Liga 1
|
|
// Liga 2
|
|
// Ligen 3 1,2,3,...n
|
|
|
|
// Liga 4 (Qualifikation)
|
|
|
|
|
|
// Liga 5: Champions League
|
|
|
|
// Liga 7: Achtelfinale
|
|
// Liga 8: Viertelfinale
|
|
// Liga 9: Halbfinale
|
|
// Liga 10: Finale
|
|
|
|
foreach($leagues as $league) {
|
|
|
|
// Qualifikation
|
|
if ($league->rank == 4) {
|
|
$matches = array();
|
|
// Bereits bestehende Matches laden
|
|
DB::table('leagues_matches')->where('league_id','=',$league->id)->get();
|
|
$users = User::getActives();
|
|
foreach($users as $user1) {
|
|
$counter_users=getActives();
|
|
foreach($counter_users as $user2) {
|
|
if ($user1->id == $user2->id) continue;
|
|
|
|
if (!User::hasMatched($user1->id, $user2->id, $league->id)) {
|
|
// add Match
|
|
array_push($matches, [$user1, $user2]);
|
|
}
|
|
}
|
|
}
|
|
|
|
Log::info("Open Matches:");
|
|
foreach ($matches as $match) {
|
|
// Oh je, jetzt noch die Runde festlegen
|
|
|
|
|
|
/*
|
|
*
|
|
* Bestimmen, in welcher Runde das Spiel stattfinden soll.
|
|
* Es darf kein Heim & Rückspiel in der gleichen Runde sein,
|
|
* d.h. ein Spieler kommt in einer Runde nur einmal zu einem Match
|
|
*
|
|
* Stehen keine Runden mehr zur Verfügung (der Standardfall)
|
|
* muss die Vergabe beendet werden. Neue Runden kommen dann
|
|
* später im Verlauf der Halbsaison ins System.
|
|
*
|
|
*/
|
|
|
|
|
|
// 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.
|
|
}
|
|
}
|