From bc5ec5edcea6c8f95295fefb218e944798ccbb6e Mon Sep 17 00:00:00 2001 From: Torsten Date: Wed, 28 Jun 2017 18:05:52 +0200 Subject: [PATCH] Model refactoring, reducing number of static methods --- .../app/Http/Controllers/TippsController.php | 1 - .../app/Http/Controllers/UsersController.php | 30 +++- pfosten/app/Tipp.php | 17 ++- pfosten/app/User.php | 4 + .../resources/views/rounds/index.blade.php | 2 +- pfosten/resources/views/tipps/index.blade.php | 2 +- .../resources/views/users/ranking.blade.php | 137 +++++++++++++----- 7 files changed, 145 insertions(+), 48 deletions(-) diff --git a/pfosten/app/Http/Controllers/TippsController.php b/pfosten/app/Http/Controllers/TippsController.php index b52ab672..865476db 100644 --- a/pfosten/app/Http/Controllers/TippsController.php +++ b/pfosten/app/Http/Controllers/TippsController.php @@ -70,7 +70,6 @@ class TippsController extends Controller } - $rounds = null; diff --git a/pfosten/app/Http/Controllers/UsersController.php b/pfosten/app/Http/Controllers/UsersController.php index ab9889e0..b445e603 100644 --- a/pfosten/app/Http/Controllers/UsersController.php +++ b/pfosten/app/Http/Controllers/UsersController.php @@ -119,7 +119,6 @@ class UsersController extends Controller if($round_id==-1) { $round_id = Round::getLastLockedRoundId(); - //Log::info("Last complete round id=" . $round_id); if ($round_id==-1) {return redirect("/");} } @@ -130,8 +129,29 @@ class UsersController extends Controller $users = DB::table('users')->where('deleted',null)->get(); foreach($users as $user) { - $user->totalScore=0; - $user->dayScore=0; + $user->totalScore=0; // Summe Ranglisten-Punkte bis heute + $user->dayScore=0; // Heute gemachte Ranglisten-Punkte + + $user->dayWinScore=0; // Tagessieg-Punkte, nur exakte Ergebnisse zählen + $user->dayWinHighestJoker=0; // Tagessieg-Punkte, nur exakte Ergebnisse zählen + + $round=Round::where('id','=',$round_id)->first(); + $games=Game::where('round_id','=',$round->id); + foreach($games as $game) { + $tipp = Tipps::where([['game_id','=',$game->id],['user_id','=',$user->id]])->first(); + if ($tipp) { + $score = Tipp::getDayScoreLocal($game->score1,$game->score2,$tipp->score1,$tipp->score2,$tipp->joker); + $scorevalue = intdiv($score,100); // Jokeranteil herausrechnen + $jokervalue = $score - $scorevalue*100; + $user->dayWinScore+=$scorevalue; + + if ( $jokervalue > $user->dayWinHighestJoker ) { + $user->dayWinHighestJoker=$jokervalue; + } + } else { + Log::info("No tipp found for game_id=".$game->id.", user_id=".$user->id); + } + } } $rounds=Round::where([['season_id','=',$currentSeason->id],['id','<=',$round_id]])->orderBy('id')->get(); @@ -141,12 +161,13 @@ class UsersController extends Controller $index=0; foreach($games as $game) { foreach($users as $user) { + $tipp = Tipp::where('game_id','=',$game->id)->where('user_id','=',$user->id)->first(); if ($tipp) { + // Ranglisten-Punkte berechen $score = Tipp::getScoreLocal($game->score1,$game->score2,$tipp->score1,$tipp->score2,$tipp->joker); $user->totalScore += $score; - if ($game->round_id == $round_id) { $user->dayScore += $score; } @@ -155,7 +176,6 @@ class UsersController extends Controller $tippDisplay[$user->id][$game->id][1] = $tipp->score2 ==-1 ? 'x' : $tipp->score2; $tippDisplay[$user->id][$game->id][2] = $tipp->joker; } - } $index+=1; } diff --git a/pfosten/app/Tipp.php b/pfosten/app/Tipp.php index b9a09dad..01dfb96e 100644 --- a/pfosten/app/Tipp.php +++ b/pfosten/app/Tipp.php @@ -15,7 +15,7 @@ class Tipp extends Model // get tendency Color public static function getCol($user_id,$game_id) { - $tipp=Tipp::getTipp($user_id,$game_id); + $tipp = Tipp::getTipp($user_id,$game_id); $game = Game::where('id',$tipp->game_id)->first(); $tippTendenz = $tipp->score1 - $tipp->score2; @@ -62,12 +62,9 @@ class Tipp extends Model if ($tippTendenz==$gameTendenz) { $score=1; } - if ( ($tipp1 == $goals1) && ($tipp2 == $goals2) ) { $bonus = max(0,$goals1 + $goals2 - 3); $score= 2 + $bonus; - - } if ($joker==true) { @@ -79,6 +76,18 @@ class Tipp extends Model return $score; } + // Bei Tagessieg gilt nur wer am meisten genau richtig getippt hat, + // Bei Gleichstand wer den höchsten Jokersieg hat ( Jokersieg mit mehr Toren zählt mehr) + public static function getDayScoreLocal($goals1, $goals2, $tipp1, $tipp2, $joker) { + if ($tipp1==-1||$tipp2==-1||$goals1==-1||$goals2==-1) { return 0; } // Ungetippt oder Spiel hat noch kein Ergebnis + if ( ($tipp1 != $goals1) || ($tipp2 != $goals2) ) return 0; + + $jokerValue=0; + if ($joker) { + $jokerValue = max(0, $goals1 + $goals2 - 3) + 1; + } + return 100 + $jokerValue; + } public static function getTippScore($user_id,$game_id, $team=0) { diff --git a/pfosten/app/User.php b/pfosten/app/User.php index 376f3f67..dbad0c44 100644 --- a/pfosten/app/User.php +++ b/pfosten/app/User.php @@ -129,4 +129,8 @@ class User extends Authenticatable return $dbDate; } + + public function hello() { + return "Hello"; + } } diff --git a/pfosten/resources/views/rounds/index.blade.php b/pfosten/resources/views/rounds/index.blade.php index ab90d515..3d651b9b 100644 --- a/pfosten/resources/views/rounds/index.blade.php +++ b/pfosten/resources/views/rounds/index.blade.php @@ -31,7 +31,7 @@  {{$game->team1 . " : " . $game->team2}}   {{App\User::toGermanDate($game->kickoff)}}  - {{ App\Game::resultString($game->id) }}   + {{ App\Game::resultStringSTATIC( $game->id ) }}   @endforeach diff --git a/pfosten/resources/views/tipps/index.blade.php b/pfosten/resources/views/tipps/index.blade.php index 0d465835..346786ea 100644 --- a/pfosten/resources/views/tipps/index.blade.php +++ b/pfosten/resources/views/tipps/index.blade.php @@ -33,7 +33,7 @@   - {{ App\Game::has_result($game->id)==true ? $game->score1 . ' : ' . $game->score2 : ' Tippen ' }} + {{ $game->hasResult() ? $game->score1 . ' : ' . $game->score2 : ' Tippen ' }} diff --git a/pfosten/resources/views/users/ranking.blade.php b/pfosten/resources/views/users/ranking.blade.php index 1d0ca1d4..f4e59e03 100644 --- a/pfosten/resources/views/users/ranking.blade.php +++ b/pfosten/resources/views/users/ranking.blade.php @@ -43,7 +43,17 @@ + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + @foreach($users as $user) @if (App\User::is_season_paid($user->id)=="Ja") - - + + + - - - - - - - - - - - - - + + + + + + + + + + + + @endif @endforeach + + + + + + + + + + + + + + + + + + +
- Spieler + Rang +
+
+
+ Tagessieg +
+
+
+ Spieler
@@ -58,57 +68,112 @@
- Spiel 1 - Heim-Mannschaft + {{$games[0]->team1}}
- Spiel 1 - Gast-Mannschaft + {{$games[0]->team2}}
#Name Total  Tag  {{$games[0]->team1}}  {{$games[0]->team2}}  Joker  {{$games[1]->team1}}  {{$games[1]->team2}}  Joker  {{$games[2]->team1}}  {{$games[2]->team2}}  Joker  {{$games[3]->team1}}  {{$games[3]->team2}}  Joker 
+
+ Joker +
+
+
+ {{$games[1]->team1}} +
+
+
+ {{$games[1]->team2}} +
+
+
+ Joker +
+
+
+ {{$games[2]->team1}} +
+
+
+ {{$games[2]->team2}} +
+
+
+ Joker +
+
+
+ {{$games[3]->team1}} +
+
+
+ {{$games[3]->team2}} +
+
+
+ Joker +
+
  {{ $user->rank }}  {{ $user->fullname }}   {{ $user->rank }} 
 {{ $user->fullname }}   {{ $user->totalScore }}  {{ $user->dayScore }}  {{ $tippDisplay[$user->id][$games[0]->id][0] }}  {{ $tippDisplay[$user->id][$games[0]->id][1] }}  {{$tippDisplay[$user->id][$games[1]->id][0] }}  {{$tippDisplay[$user->id][$games[1]->id][1] }}  {{$tippDisplay[$user->id][$games[2]->id][0] }}  {{$tippDisplay[$user->id][$games[2]->id][1] }}  {{$tippDisplay[$user->id][$games[3]->id][0] }}  {{$tippDisplay[$user->id][$games[3]->id][1] }}  {{ $tippDisplay[$user->id][$games[0]->id][0] }}  {{ $tippDisplay[$user->id][$games[0]->id][1] }} 
 {{$tippDisplay[$user->id][$games[1]->id][0] }}  {{$tippDisplay[$user->id][$games[1]->id][1] }} 
 {{$tippDisplay[$user->id][$games[2]->id][0] }}  {{$tippDisplay[$user->id][$games[2]->id][1] }} 
 {{$tippDisplay[$user->id][$games[3]->id][0] }}  {{$tippDisplay[$user->id][$games[3]->id][1] }}