Model refactoring, reducing number of static methods

This commit is contained in:
Torsten 2017-06-28 18:05:52 +02:00
parent 92a07b1684
commit bc5ec5edce
7 changed files with 145 additions and 48 deletions

View file

@ -70,7 +70,6 @@ class TippsController extends Controller
}
$rounds = null;

View file

@ -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;
}

View file

@ -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) {

View file

@ -129,4 +129,8 @@ class User extends Authenticatable
return $dbDate;
}
public function hello() {
return "Hello";
}
}

View file

@ -31,7 +31,7 @@
<tr class="table-bordered">
<td>&nbsp;{{$game->team1 . " : " . $game->team2}}&nbsp;</td>
<td>&nbsp;{{App\User::toGermanDate($game->kickoff)}}&nbsp;</td>
<td><a href="/games/edit/{{$game->id}}">{{ App\Game::resultString($game->id) }} &nbsp; </a></td>
<td><a href="/games/edit/{{$game->id}}">{{ App\Game::resultStringSTATIC( $game->id ) }} &nbsp; </a></td>
</tr>
@endforeach

View file

@ -33,7 +33,7 @@
<td class="table-bordered" style="width:600px;"><label class="text" href="/games/edit/{{ $game->id }}">{{ $game->team1 }} : {{ $game->team2 }}</label>&nbsp;</td>
<td class="table-bordered" style="width:600px;"><label class="text" > {{ App\User::toGermanDate($game->kickoff) }}</label></td>
<td class="table-bordered" style="width:350px;">{{ App\Game::has_result($game->id)==true ? $game->score1 . ' : ' . $game->score2 : ' Tippen ' }}</td>
<td class="table-bordered" style="width:350px;">{{ $game->hasResult() ? $game->score1 . ' : ' . $game->score2 : ' Tippen ' }}</td>
<td class="table-bordered" style="width:75px;">

View file

@ -43,7 +43,17 @@
<table>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Spieler</span>
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;width:50px;">Rang</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;width:50px;">Tagessieg</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;width:150px;">Spieler</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
@ -58,57 +68,112 @@
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Spiel 1 - Heim-Mannschaft</span>
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[0]->team1}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Spiel 1 - Gast-Mannschaft</span>
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[0]->team2}}</span>
</div>
</th>
<tr class="table-bordered">
<td class="table-bordered" align="center" style="width:25px;">#</td>
<td class="table-bordered" align="center" style="width:200px;">Name</td>
<td class="table-bordered" align="center">&nbsp;Total&nbsp;</td>
<td class="table-bordered" align="center">&nbsp;Tag&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;">&nbsp;{{$games[0]->team1}}&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;">&nbsp;{{$games[0]->team2}}&nbsp;</td>
<td class="table-bordered" align="center">&nbsp;Joker&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;">&nbsp;{{$games[1]->team1}}&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;">&nbsp;{{$games[1]->team2}}&nbsp;</td>
<td class="table-bordered" align="center">&nbsp;Joker&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;">&nbsp;{{$games[2]->team1}}&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;">&nbsp;{{$games[2]->team2}}&nbsp;</td>
<td class="table-bordered" align="center">&nbsp;Joker&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;">&nbsp;{{$games[3]->team1}}&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;">&nbsp;{{$games[3]->team2}}&nbsp;</td>
<td class="table-bordered" align="center">&nbsp;Joker&nbsp;</td>
</tr>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Joker</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[1]->team1}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[1]->team2}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Joker</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[2]->team1}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[2]->team2}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Joker</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[3]->team1}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[3]->team2}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Joker</span>
</div>
</th>
@foreach($users as $user)
@if (App\User::is_season_paid($user->id)=="Ja")
<tr>
<td class="table-bordered">&nbsp;<span class="text list-unstyled" href="#" style="width:25px;">&nbsp;{{ $user->rank }}&nbsp;</span></td>
<td class="table-bordered">&nbsp;<a class="text list-unstyled" href="#" style="width:350px;vertical-align: middle;">{{ $user->fullname }}&nbsp;</a></td>
<td class="table-bordered">&nbsp;<span class="text list-unstyled" href="#" >&nbsp;{{ $user->rank }}&nbsp;</span></td>
<td class="table-bordered"><div style="margin: 0 auto; width: 32px;"><img src="/img/crown.png" style="{{ (1==1 ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></div></td>
<td class="table-bordered">&nbsp;<a class="text list-unstyled" href="#" style="vertical-align: middle;">{{ $user->fullname }}&nbsp;</a></td>
<td class="table-bordered" align="center">&nbsp;{{ $user->totalScore }}&nbsp;</td>
<td class="table-bordered" align="center">&nbsp;{{ $user->dayScore }}&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;{{App\Tipp::getCol($user->id,$games[0]->id)}}">&nbsp;{{ $tippDisplay[$user->id][$games[0]->id][0] }}&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;{{App\Tipp::getCol($user->id,$games[0]->id)}}">&nbsp;{{ $tippDisplay[$user->id][$games[0]->id][1] }}&nbsp;</td>
<td class="table-bordered"><img src="/img/joker.png" style="{{ ($tippDisplay[$user->id][$games[0]->id][2]==true ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></td>
<td class="table-bordered" align="center" style="width:150px;{{App\Tipp::getCol($user->id,$games[1]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[1]->id][0] }}&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;{{App\Tipp::getCol($user->id,$games[1]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[1]->id][1] }}&nbsp;</td>
<td class="table-bordered"><img src="/img/joker.png" style="{{ ($tippDisplay[$user->id][$games[1]->id][2]==true ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></td>
<td class="table-bordered" align="center" style="width:150px;{{App\Tipp::getCol($user->id,$games[2]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[2]->id][0] }}&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;{{App\Tipp::getCol($user->id,$games[2]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[2]->id][1] }}&nbsp;</td>
<td class="table-bordered"><img src="/img/joker.png" style="{{ ($tippDisplay[$user->id][$games[2]->id][2]==true ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></td>
<td class="table-bordered" align="center" style="width:150px;{{App\Tipp::getCol($user->id,$games[3]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[3]->id][0] }}&nbsp;</td>
<td class="table-bordered" align="center" style="width:150px;{{App\Tipp::getCol($user->id,$games[3]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[3]->id][1] }}&nbsp;</td>
<td class="table-bordered"><img src="/img/joker.png" style="{{ ($tippDisplay[$user->id][$games[3]->id][2]==true ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></td>
<td class="table-bordered" align="center" style="{{App\Tipp::getCol($user->id,$games[0]->id)}}">&nbsp;{{ $tippDisplay[$user->id][$games[0]->id][0] }}&nbsp;</td>
<td class="table-bordered" align="center" style="{{App\Tipp::getCol($user->id,$games[0]->id)}}">&nbsp;{{ $tippDisplay[$user->id][$games[0]->id][1] }}&nbsp;</td>
<td class="table-bordered"><div style="margin: 0 auto; width: 32px;"><img src="/img/joker.png" style="{{ ($tippDisplay[$user->id][$games[0]->id][2]==true ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></div></td>
<td class="table-bordered" align="center" style="{{App\Tipp::getCol($user->id,$games[1]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[1]->id][0] }}&nbsp;</td>
<td class="table-bordered" align="center" style="{{App\Tipp::getCol($user->id,$games[1]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[1]->id][1] }}&nbsp;</td>
<td class="table-bordered"><div style="margin: 0 auto; width: 32px;"><img src="/img/joker.png" style="{{ ($tippDisplay[$user->id][$games[1]->id][2]==true ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></div></td>
<td class="table-bordered" align="center" style="{{App\Tipp::getCol($user->id,$games[2]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[2]->id][0] }}&nbsp;</td>
<td class="table-bordered" align="center" style="{{App\Tipp::getCol($user->id,$games[2]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[2]->id][1] }}&nbsp;</td>
<td class="table-bordered"><div style="margin: 0 auto; width: 32px;"><img src="/img/joker.png" style="{{ ($tippDisplay[$user->id][$games[2]->id][2]==true ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></div></td>
<td class="table-bordered" align="center" style="{{App\Tipp::getCol($user->id,$games[3]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[3]->id][0] }}&nbsp;</td>
<td class="table-bordered" align="center" style="{{App\Tipp::getCol($user->id,$games[3]->id)}}">&nbsp;{{$tippDisplay[$user->id][$games[3]->id][1] }}&nbsp;</td>
<td class="table-bordered"><div style="margin: 0 auto; width: 32px;"><img src="/img/joker.png" style="{{ ($tippDisplay[$user->id][$games[3]->id][2]==true ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></div></td>
</tr>
@endif
@endforeach
<!-- Control Cell width -->
<tr>
<td> <div></div></td>
<td> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
</tr>
</table>
<p>&nbsp;</p>