League Quali Spielplan berechnen & anzeigen

This commit is contained in:
Torsten 2017-09-26 07:57:39 +02:00
parent e0d38fac38
commit 93d7670b48
5 changed files with 58 additions and 10 deletions

View file

@ -9,6 +9,7 @@ use App\Leagues\LeagueMember;
use App\User;
use App\Round;
use App\Season;
use App\Tipp;
use Log;
use DB;
@ -82,7 +83,6 @@ class Match extends Model
}
public static function getLeagueMatches($league_id) {
//$matches = Match::where('league_id','=',$league_id)->orderBy('round_id')->get();
$matches = DB::table('leagues_matches')->where('league_id','=',$league_id)->orderBy('round_id')->get();
@ -94,12 +94,12 @@ class Match extends Model
$match->round_name = $roundnames[$match->round_id];
$match->user1_name = $usernames[$match->user1_id];
$match->user2_name = $usernames[$match->user2_id];
// Hier könnte man die Punkte auswerten.
// Punktauswertung in Match::getResults($leagueId, $maxRoundId);
}
return $matches;
}
public static function getPairings($leagueId, $roundNr) {
$members = LeagueMember::getMembers($leagueId);
shuffle($members);
@ -151,4 +151,44 @@ class Match extends Model
$members = LeagueMember::getMembers($leagueId);
return sizeof($members)-1;
}
public static function getMatchResults($leagueId, $maxRoundId=-1) {
$roundtipps = Tipp::getRoundTipps($maxRoundId);
$roundtipps = $roundtipps["roundtipps"];
$startRoundId = League::getStartRoundId($leagueId);
$matches = Match::getLeagueMatches($leagueId, $maxRoundId);
if ($maxRoundId==-1) {$maxRoundId=Round::getLastLockedRoundId();}
$matchResults=array();
$members = LeagueMember::getMembers($leagueId);
foreach($matches as $key => $match) {
if (!Round::isCompleted($match->round_id)) continue;
$user1_key = $match->round_id."_".$match->user1_id;
$user2_key = $match->round_id."_".$match->user2_id;
$user1_score = $roundtipps[$user1_key]["rankscore"];
$user2_score = $roundtipps[$user2_key]["rankscore"];
$matches[$key]->user1_rankscore = $user1_score;
$matches[$key]->user2_rankscore = $user2_score;
if ($user1_score > $user2_score) {
$matches[$key]->user1_league_score = 3;
$matches[$key]->user2_league_score = 0;
}
else if ($user1_score < $user2_score){
$matches[$key]->user1_league_score = 0;
$matches[$key]->user2_league_score = 3;
} else {
$matches[$key]->user1_league_score = 1;
$matches[$key]->user2_league_score = 1;
}
// error_log($match->user1_id." vs ".$match->user2_id. " =>" . $user1_score.":".$user2_score);
}
return $matches;
}
}