From 5b02895c86a52cc2ac59616f14efbbe53ffb43d3 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 8 Aug 2017 15:32:54 +0200 Subject: [PATCH] Started working on cached ranking version (ranking2) --- .../app/Http/Controllers/GamesController.php | 19 +++- .../app/Http/Controllers/UsersController.php | 99 ++++++++++++++++++- .../views/users/no_ranking.blade.php | 3 +- .../resources/views/users/ranking.blade.php | 1 - pfosten/routes/web.php | 2 +- 5 files changed, 117 insertions(+), 7 deletions(-) diff --git a/pfosten/app/Http/Controllers/GamesController.php b/pfosten/app/Http/Controllers/GamesController.php index fc279395..025494c8 100644 --- a/pfosten/app/Http/Controllers/GamesController.php +++ b/pfosten/app/Http/Controllers/GamesController.php @@ -2,11 +2,14 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +//use Illuminate\Http\Request; +use Request; use App\Game; use Carbon\Carbon; use Auth; use App\User; +use Log; + class GamesController extends Controller { @@ -21,6 +24,8 @@ class GamesController extends Controller public function store() { if (Auth::guest()) { return redirect("/login"); } // Validate form + + Log::info("Starting validation"); $this->validate(request(), [ 'id' => 'required', 'team1' => 'required', @@ -28,10 +33,20 @@ class GamesController extends Controller 'kickoff' => 'required' ]); + Log::info("Passed form validation."); + $score1=-1; $score2=-1; - if (request("score1") && request("score2")) { + + Log::info("Checking score"); + + if (is_null("score1")) Log::info("score1 is missing."); + if (is_null("score2")) Log::info("score2 is missing."); + + + if (!is_null(request("score1")) && !is_null(request("score2")) ) { + Log::info("Setting values"); $score1=request("score1"); $score2=request("score2"); } diff --git a/pfosten/app/Http/Controllers/UsersController.php b/pfosten/app/Http/Controllers/UsersController.php index 236a83db..ca4babc9 100755 --- a/pfosten/app/Http/Controllers/UsersController.php +++ b/pfosten/app/Http/Controllers/UsersController.php @@ -150,7 +150,6 @@ class UsersController extends Controller foreach($games as $game) { - if ($user->id==1) {Log::info("game-id=".$game->id.", user-id=".$user->id);} $tipp = Tipp::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); @@ -245,4 +244,102 @@ class UsersController extends Controller return ($user1->totalScore < $user2->totalScore); } + + + + public function ranking2($max_round_id) { + $currentSeason = Season::getCurrent(); + + // 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 . "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." "; + $sql = $sql . "and games.round_id=rounds.id and tipps.game_id=games.id and users.id = tipps.user_id "; + $sql = $sql . "and payments.season_id=".$currentSeason->id." and payments.user_id = users.id "; + $sql = $sql . "and payments.paid_date is not null "; + $sql = $sql . "order by rounds.id, games.id, users.id;"; + + $result=DB::select($sql); + + $roundtipps = array(); + $user_ids=array(); + $round_ids=array(); + + foreach ($result as $entry) { + $round_id = $entry->round_id; + if ($max_round_id >-1 && $round_id>$max_round_id) break; + + if (!in_array($entry->user_id,$user_ids)) { array_push($user_ids,$entry->user_id); } + if (!in_array($entry->round_id,$round_ids)) { array_push($round_ids,$entry->round_id); } + + $user_id = $entry->user_id; + + $key = $round_id."_".$user_id; + if (!array_key_exists($key,$roundtipps)) { + $roundtipps[$key]=array(); + $roundtipps[$key]['tipps']=array(); + $roundtipps[$key]['results']=array(); + + $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]['dayscore']=Tipp::getDayScoreLocal($entry->game_score1,$entry->game_score2,$entry->tipp_score1,$entry->tipp_score2,$entry->joker); + } + + array_push($roundtipps[$key]['tipps'], $entry->tipp_score1, $entry->tipp_score2, $entry->joker); + array_push($roundtipps[$key]['results'], $entry->game_score1, $entry->game_score2); + } + + //dd($roundtipps); + //dd($user_ids); + //dd($round_ids); + + //Log::info($user_ids); + //Log::info($round_ids); + + // Aufbau der Rankingliste in rankingDisplay, sowie aufaddieren der jeweiligen Punkte. + $rankingDisplay=array(); + foreach ($user_ids as $user_id) { + $ranking_sum = 0; + $payout_sum = 0; + foreach($round_ids as $round_id) { + $key = $round_id . "_" . $user_id; + if (!array_key_exists($user_id, $rankingDisplay)) { + $rankingDisplay[$user_id] = array(); + $rankingDisplay[$user_id]["rankscore"] = 0; + $rankingDisplay[$user_id]["dayscore"] = 0; + $rankingDisplay[$user_id]["user_name"] = $roundtipps[$key]["user_name"]; + } + 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 + } + } + } + + + + + + } + + + } diff --git a/pfosten/resources/views/users/no_ranking.blade.php b/pfosten/resources/views/users/no_ranking.blade.php index 5128c6ec..ea2ca3c7 100644 --- a/pfosten/resources/views/users/no_ranking.blade.php +++ b/pfosten/resources/views/users/no_ranking.blade.php @@ -4,7 +4,7 @@

-

Dein Zahlungseingang für die Saison wurde noch nicht registriert.

+

Es gibt noch keine Tipprunde, die reif für die Anzeige ist. Rangliste / Tippvergleich verfügbar ab {{ $start_date }}

@@ -15,7 +15,6 @@
-
@endsection \ No newline at end of file diff --git a/pfosten/resources/views/users/ranking.blade.php b/pfosten/resources/views/users/ranking.blade.php index 8dd326bd..4d807f74 100755 --- a/pfosten/resources/views/users/ranking.blade.php +++ b/pfosten/resources/views/users/ranking.blade.php @@ -150,7 +150,6 @@  {{$tippDisplay[$user->id][$games[3]->id][0] }}   {{$tippDisplay[$user->id][$games[3]->id][1] }} 
- @endif @endforeach diff --git a/pfosten/routes/web.php b/pfosten/routes/web.php index 3f691508..c72dae30 100644 --- a/pfosten/routes/web.php +++ b/pfosten/routes/web.php @@ -43,7 +43,7 @@ Route::get('/users','UsersController@index'); Route::get('/users/edit/{user_id}','UsersController@edit'); Route::post('/users/store','UsersController@store'); Route::get('/users/ranking/{round_id}','UsersController@ranking'); - +Route::get('/users/ranking2/{round_id}','UsersController@ranking2'); Route::get('/tipps','TippsController@index'); Route::get('/tipps/edit/{tipp_id}','TippsController@edit');