diff --git a/pfosten/app/Http/Controllers/UsersController.php b/pfosten/app/Http/Controllers/UsersController.php index ca4babc9..b9e4856b 100755 --- a/pfosten/app/Http/Controllers/UsersController.php +++ b/pfosten/app/Http/Controllers/UsersController.php @@ -12,6 +12,7 @@ use App\Tipp; use DB; use Auth; use Log; +use Carbon; class UsersController extends Controller { @@ -245,15 +246,31 @@ class UsersController extends Controller } - - public function ranking2($max_round_id) { $currentSeason = Season::getCurrent(); + + + // Check ob mindestens eine Runde der Saison gelockt ist angezeigt werden kann + if($max_round_id==-1) { + $max_round_id = Round::getLastLockedRoundId(); + if ($max_round_id==-1) { + $sql="select DATE_FORMAT(date_sub(min(games.kickoff), interval 1 hour),'%d.%m.%Y %H:%i') as start_date from rounds,games where rounds.season_id=".$currentSeason->id." and games.round_id=rounds.id;"; + $date = DB::select($sql); + + if (count($date)>0) { + $start_date = $date[0]->start_date; + return view('users.no_ranking', compact('start_date')); + } else { + return redirect("/"); + } + } + } + // Hier werden _alle_ Tipps der aktuellen Saison ausgerechnet, die $round_id Begrenzung wird erst spƤter ausgewertet. $sql = "select users.id as user_id, users.name as user_name, "; $sql = $sql . "rounds.id as round_id, rounds.name as round_name, "; - $sql = $sql . "games.id as game_id, games.team1, games.team2, games.score1 as game_score1, games.score2 as game_score2, "; + $sql = $sql . "games.id as game_id, games.team1, games.team2, games.score1 as game_score1, games.score2 as game_score2, games.kickoff as game_kickoff, "; $sql = $sql . "tipps.id as tipp_id, tipps.score1 as tipp_score1, tipps.score2 as tipp_score2, tipps.joker "; $sql = $sql . "from users,rounds,games,tipps,payments "; $sql = $sql . "where rounds.season_id=".$currentSeason->id." "; @@ -268,6 +285,8 @@ class UsersController extends Controller $user_ids=array(); $round_ids=array(); + if ($max_round_id==-1) { $max_round_id=Round::getLastLockedRoundId(); } + foreach ($result as $entry) { $round_id = $entry->round_id; if ($max_round_id >-1 && $round_id>$max_round_id) break; @@ -286,9 +305,14 @@ class UsersController extends Controller $roundtipps[$key]['user_name'] = $entry->user_name; $roundtipps[$key]['user_id'] = $entry->user_id; - $roundtipps[$key]['rankscore']=Tipp::getScoreLocal($entry->game_score1,$entry->game_score2,$entry->tipp_score1,$entry->tipp_score2,$entry->joker); + $roundtipps[$key]['rankscore']=0; $roundtipps[$key]['dayscore']=Tipp::getDayScoreLocal($entry->game_score1,$entry->game_score2,$entry->tipp_score1,$entry->tipp_score2,$entry->joker); + + $roundtipps[$key]['earliest_kickoff']=$entry->game_kickoff; } + $roundtipps[$key]['rankscore']+=Tipp::getScoreLocal($entry->game_score1,$entry->game_score2,$entry->tipp_score1,$entry->tipp_score2,$entry->joker); + + if ($entry->game_kickoff < $roundtipps[$key]['earliest_kickoff']) { $roundtipps[$key]['earliest_kickoff']=$entry->game_kickoff; } array_push($roundtipps[$key]['tipps'], $entry->tipp_score1, $entry->tipp_score2, $entry->joker); array_push($roundtipps[$key]['results'], $entry->game_score1, $entry->game_score2); @@ -301,43 +325,82 @@ class UsersController extends Controller //Log::info($user_ids); //Log::info($round_ids); + + Log::info("max_round_id=".$max_round_id); + // Aufbau der Rankingliste in rankingDisplay, sowie aufaddieren der jeweiligen Punkte. $rankingDisplay=array(); foreach ($user_ids as $user_id) { - $ranking_sum = 0; + $rankscore_total= 0; $payout_sum = 0; + foreach($round_ids as $round_id) { $key = $round_id . "_" . $user_id; + if ($user_id==1) { Log::info("Processing round: ".$round_id);} if (!array_key_exists($user_id, $rankingDisplay)) { $rankingDisplay[$user_id] = array(); - $rankingDisplay[$user_id]["rankscore"] = 0; + + /* + if ($user_id==1) { + Log::info("round_id=".$round_id.", rankscore from var=".$roundtipps[$key]["rankscore"]. ", old_total=" .$rankscore_total); + } + */ + $rankingDisplay[$user_id]["dayscore"] = 0; $rankingDisplay[$user_id]["user_name"] = $roundtipps[$key]["user_name"]; + $rankingDisplay[$user_id]["is_dayscorewinner"] = 0; } - if (!array_key_exists("tipp_score1", $rankingDisplay[$user_id])) { - $rankingDisplay[$user_id]["tipp_score1"] = $roundtipps[$key]["tipps"][0]; - $rankingDisplay[$user_id]["tipp_score2"] = $roundtipps[$key]["tipps"][1]; - // Determine coloration for Game1 - } elseif (!array_key_exists("tipp_score3", $rankingDisplay[$user_id])) { - $rankingDisplay[$user_id]["tipp_score3"] = $roundtipps[$key]["tipps"][2]; - $rankingDisplay[$user_id]["tipp_score4"] = $roundtipps[$key]["tipps"][3]; - // Determine coloration for Game2 - } elseif (!array_key_exists("tipp_score5", $rankingDisplay[$user_id])) { - $rankingDisplay[$user_id]["tipp_score5"] = $roundtipps[$key]["tipps"][4]; - $rankingDisplay[$user_id]["tipp_score6"] = $roundtipps[$key]["tipps"][5]; - // Determine coloration for Game3 - } elseif (!array_key_exists("tipp_score7", $rankingDisplay[$user_id])) { - $rankingDisplay[$user_id]["tipp_score7"] = $roundtipps[$key]["tipps"][6]; - $rankingDisplay[$user_id]["tipp_score8"] = $roundtipps[$key]["tipps"][7]; - // Determine coloration for Game4 - } + + $rankingDisplay[$user_id]["rankscore"] = $rankscore_total + $roundtipps[$key]["rankscore"]; $rankscore_total=$rankingDisplay[$user_id]["rankscore"]; + + $rankingDisplay[$user_id]["tipp_score1"] = $roundtipps[$key]["tipps"][0]; + $rankingDisplay[$user_id]["tipp_score2"] = $roundtipps[$key]["tipps"][1]; + $rankingDisplay[$user_id]["joker1"] = $roundtipps[$key]["tipps"][2]; + + $rankingDisplay[$user_id]["result_score1"] = + $rankingDisplay[$user_id]["result_score2"] = $roundtipps[$key]["results"][1]; + + // Determine coloration for Game1 + $rankingDisplay[$user_id]["trendCol1"] = Tipp::trendCol($roundtipps[$key]["results"][0],$roundtipps[$key]["results"][1], + $roundtipps[$key]["tipps"][0],$roundtipps[$key]["tipps"][1], + $roundtipps[$key]["tipps"][2]); + + + $rankingDisplay[$user_id]["tipp_score3"] = $roundtipps[$key]["tipps"][3]; + $rankingDisplay[$user_id]["tipp_score4"] = $roundtipps[$key]["tipps"][4]; + $rankingDisplay[$user_id]["joker2"] = $roundtipps[$key]["tipps"][5]; + // Determine coloration for Game2 + $rankingDisplay[$user_id]["trendCol2"] = Tipp::trendCol($roundtipps[$key]["results"][2],$roundtipps[$key]["results"][3], + $roundtipps[$key]["tipps"][3],$roundtipps[$key]["tipps"][4], + $roundtipps[$key]["tipps"][5]); + + $rankingDisplay[$user_id]["tipp_score5"] = $roundtipps[$key]["tipps"][6]; + $rankingDisplay[$user_id]["tipp_score6"] = $roundtipps[$key]["tipps"][7]; + $rankingDisplay[$user_id]["joker3"] = $roundtipps[$key]["tipps"][8]; + // Determine coloration for Game3 + $rankingDisplay[$user_id]["trendCol3"] = Tipp::trendCol($roundtipps[$key]["results"][4],$roundtipps[$key]["results"][5], + $roundtipps[$key]["tipps"][6],$roundtipps[$key]["tipps"][7], + $roundtipps[$key]["tipps"][8]); + + $rankingDisplay[$user_id]["tipp_score7"] = $roundtipps[$key]["tipps"][9]; + $rankingDisplay[$user_id]["tipp_score8"] = $roundtipps[$key]["tipps"][10]; + $rankingDisplay[$user_id]["joker4"] = $roundtipps[$key]["tipps"][11]; + // Determine coloration for Game4 + $rankingDisplay[$user_id]["trendCol4"] = Tipp::trendCol($roundtipps[$key]["results"][6],$roundtipps[$key]["results"][7], + $roundtipps[$key]["tipps"][9],$roundtipps[$key]["tipps"][10], + $roundtipps[$key]["tipps"][11]); + } + + //TODO: Loop: Determine DayScoreWinner, Rank (multiple identical possible), Sort rankingDisplay array + } - - - - + $userids = array_keys($rankingDisplay); + $round=Round::where('id','=',$max_round_id)->first(); + $games=Game::where('round_id','=',$max_round_id)->get(); + $all_rounds=Round::where('season_id','=',$currentSeason->id)->get(); + return view('users.ranking2', compact('all_rounds','rankingDisplay','userids','round','games')); } diff --git a/pfosten/app/Tipp.php b/pfosten/app/Tipp.php index 348fb742..1289a3dd 100755 --- a/pfosten/app/Tipp.php +++ b/pfosten/app/Tipp.php @@ -13,6 +13,32 @@ class Tipp extends Model 'id', 'user_id', 'game_id','score1','score2','joker' ]; + public static function trendCol($score1, $score2, $tipp1, $tipp2, $joker) { + $tippTendenz = $tipp1 - $tipp2; + + if ($tippTendenz > 0) {$tippTendenz=1;} + if ($tippTendenz < 0) {$tippTendenz=-1;} + + $gameTendenz = $score1 - $score2; + if ($gameTendenz<0) {$gameTendenz=-1;} + if ($gameTendenz>0) {$gameTendenz=1;} + + if ($tippTendenz!=$gameTendenz || $score1 ==-1 || $score2==-1 || $tipp1 == -1 || $tipp2==-1) { + return ""; + } + + $styling='background-color:grey;'; + + if ( ($tipp1 == $score1) && ($tipp2 == $score2) ) { + $styling='background-color:orange;'; + if ($joker) { + $styling='background-color:red'; + } + } + return $styling; + } + + // get tendency Color public static function getCol($user_id,$game_id) { $tipp = Tipp::getTipp($user_id,$game_id); diff --git a/pfosten/resources/views/users/ranking2.blade.php b/pfosten/resources/views/users/ranking2.blade.php new file mode 100755 index 00000000..f60b2972 --- /dev/null +++ b/pfosten/resources/views/users/ranking2.blade.php @@ -0,0 +1,200 @@ +@extends('layouts.layout') + +@section('content') + +
+ + @foreach($all_rounds as $r) + @if (App\Round::hasLockedGame($r->id) ) +
+ @if ($r->id == $round->id) + + @else + {{$r->name}} + @endif +
+ @endif + @endforeach + +
+ + +
+
+ +

Saison: {{ App\Season::getCurrent()->name }}

+

Runde: {{ $round->name }}

+

Rangliste und Tippübersicht

+ + + + + + + + + + + + + +
=richtige Tendenz
=richtiges Ergebnis
=richtiges Ergebnis mit Joker
+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + @foreach($userids as $userid) + + + + + + + + + + + + + + + + + + + + + + @endforeach + + + + + + + + + + + + + + + + + + + +
+
+ Rang +
+
+
+ Tagessieg +
+
+
+ Spieler +
+
+
+ Punkte Gesamt +
+
+
+ Punkte 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 +
+
  {{ $rankingDisplay[$userid]["rankscore"] }} 
 {{ $rankingDisplay[$userid]["user_name"] }}   {{ $rankingDisplay[$userid]["rankscore"] }}  {{ $rankingDisplay[$userid]["dayscore"] }}  {{ $rankingDisplay[$userid]["tipp_score1"] }}  {{ $rankingDisplay[$userid]["tipp_score2"] }} 
 {{$rankingDisplay[$userid]["tipp_score3"] }}  {{$rankingDisplay[$userid]["tipp_score4"] }} 
 {{$rankingDisplay[$userid]["tipp_score5"] }}  {{$rankingDisplay[$userid]["tipp_score6"] }} 
 {{$rankingDisplay[$userid]["tipp_score7"] }}  {{$rankingDisplay[$userid]["tipp_score8"] }} 
+ +

 

+ +
+ +
+ + + +@endsection + + + + + + + + + + + + +