Show player matches for single userId

This commit is contained in:
Torsten 2017-09-30 13:14:46 +02:00
parent 93d7670b48
commit 98ebdb6c93
7 changed files with 163 additions and 9 deletions

View file

@ -155,13 +155,9 @@ class Match extends Model
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);
if ($maxRoundId==-1) {$maxRoundId=Round::getLastCompleteRoundId();}
foreach($matches as $key => $match) {
if (!Round::isCompleted($match->round_id)) continue;
@ -175,9 +171,12 @@ class Match extends Model
$matches[$key]->user1_rankscore = $user1_score;
$matches[$key]->user2_rankscore = $user2_score;
//$matches[$key]->user1_hits = $roundtipps[$user1_key][]
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;
@ -187,8 +186,31 @@ class Match extends Model
$matches[$key]->user2_league_score = 1;
}
// error_log($match->user1_id." vs ".$match->user2_id. " =>" . $user1_score.":".$user2_score);
}
return $matches;
}
public static function getMatchResultsForUser($userId, $maxRoundId=-1) {
$season = Season::getCurrent();
$leagues = League::where('season_id','=',$season->id)->get();
$matchList=array();
foreach($leagues as $league) {
$member=LeagueMember::where('league_id','=',$league->id)->where('user_id','=',$userId)->first();
if ($member) {
// $userId ist member dieser League
$matchResults = Match::getMatchResults($league->id,$maxRoundId);
foreach($matchResults as $result) {
if ($result->user1_id == $userId || $result->user2_id==$userId) {
array_push($matchList, $result);
}
}
}
}
return $matchList;
}
}