diff --git a/pfosten/app/Http/Controllers/Leagues/LeaguesController.php b/pfosten/app/Http/Controllers/Leagues/LeaguesController.php index 235987b5..3b8e23fd 100644 --- a/pfosten/app/Http/Controllers/Leagues/LeaguesController.php +++ b/pfosten/app/Http/Controllers/Leagues/LeaguesController.php @@ -171,9 +171,11 @@ class LeaguesController extends Controller return redirect("/seasons"); } - public function showLeagueRounds($league_rank, $round_id) { // $round_id = $max_round_id + public function showLeagueRounds($league_rank, $maxRoundId) { if (Auth::guest()) { return redirect("/"); } + $maxRoundId = min(Round::getLastCompleteRoundId(),$maxRoundId); + $season=Season::getCurrent(); $roundNames = Round::getNames(); $leagueNames = League::getNames(); @@ -182,9 +184,9 @@ class LeaguesController extends Controller $matchesTotal = array(); foreach ($leagues as $league) { - $matches = Match::getLeagueMatches($league->id); + $matches = Match::getMatchResults($league->id, $maxRoundId); foreach ($matches as $match) { - if ($match->round_id <= $round_id) { + if ($match->round_id <= $maxRoundId) { if (!key_exists($match->round_id, $matchesTotal)) { $matchesTotal[$match->round_id]=array(); } diff --git a/pfosten/app/leagues/League.php b/pfosten/app/leagues/League.php index cc7f19f6..3f393f9f 100644 --- a/pfosten/app/leagues/League.php +++ b/pfosten/app/leagues/League.php @@ -53,4 +53,10 @@ class League extends Model return $leagueNames; } + public static function getStartRoundId($leagueId) + { + $league = League::where('id','=',$leagueId)->first(); + return $league->start_round_id; + } + } diff --git a/pfosten/app/leagues/Match.php b/pfosten/app/leagues/Match.php index 6b46f9d4..e2ca1c44 100644 --- a/pfosten/app/leagues/Match.php +++ b/pfosten/app/leagues/Match.php @@ -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; + } } diff --git a/pfosten/resources/views/leagues/matches.blade.php b/pfosten/resources/views/leagues/matches.blade.php index a415cb85..ca24fed5 100755 --- a/pfosten/resources/views/leagues/matches.blade.php +++ b/pfosten/resources/views/leagues/matches.blade.php @@ -25,9 +25,9 @@ @foreach($matchesTotal[$round_id][$league_id] as $match)
{{ $message_text_joker }}
{{ $nextRoundName }} sperrt sich: {{ $nextRoundLockTime }} ( noch {{ $hourDiffToLock }} Stunden )
{{ $nextRoundName }} sperrt sich: {{ $nextRoundLockTime }} ( noch {{ $hourDiffToLock }} )