-1) { $rounds = Round::where("id", "<=", $round_id)->get(); foreach($rounds as $round) { $dpr =array(); $dpr["name"]=$round->name; $dpr["report"]=$round->report; array_push($display_rounds, $dpr); } $display_rounds = array_reverse($display_rounds); Log::info("Loaded report:".$report." round-id=".$round_id); $roundname = $round->name; } else { Log::info("No round identified. Last Locked=".$round_id); $report="";} } else {Log::info("No current season");} $nextRoundName=""; $nextRound = Round::getFirstTippableRound(); $nextRoundLockTime = ""; $diffToLock =""; if ($nextRound) { $nextRoundName = $nextRound->name; $nextRoundLockTime = $nextRound->getLockTime(); $hourDiffToLock=$nextRoundLockTime->diffInHours(Carbon\Carbon::now()); } $user=Auth::user(); $message_text_tipps=""; $message_text_joker=""; if ($user && $currentSeason) { if (User::hasMissingTipp($user->id)) { $message_text_tipps="Fehlende Tipps für ".$nextRoundName; } if (User::hasMissingJoker($user->id)) { $message_text_joker="Fehlender Joker für ".$nextRoundName; } } return view('main',compact('roundname','display_rounds','message_text_joker','message_text_tipps','nextRoundName','nextRoundLockTime', 'hourDiffToLock')); } public function index() { if (Auth::guest()) { return redirect("/"); } if (!Auth::user()->admin) { return redirect("/"); } $currentSeason=Season::getCurrent(); $active_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->whereNotNull('paid_date')->get() ); $total_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->get() ); $users = DB::table('users')->where('deleted',null)->orderBy('lastname')->get(); foreach($users as $key => $user) { // Log::info($users[0]->id); // Log::info($key); // Log::info($user->id); // // Log::info("------------------------------"); if (User::hasMissingTipp($user->id)) { $users[$key]->missingTippText="Tipps fehlen"; $users[$key]->tippStyling="red"; } else { $users[$key]->missingTippText="Runde getippt"; $users[$key]->tippStyling="green"; } if (User::hasMissingJoker($user->id)) { $users[$key]->missingJokerText="Joker fehlt"; $users[$key]->jokerStyling="red"; } else { $users[$key]->missingJokerText="Joker gesetzt"; $users[$key]->jokerStyling="green"; } } return view('users.index', compact('users','active_user_count','total_user_count')); } /* public function showUsers() { $users = DB::table('users')->orderBy('lastname')->get(); return view('users.list', compact('users')); } */ // Route-Model binding, because parameter in web.php route has same name as functionparameter public function showUser(User $userObject) { //return $userObject; // If you want it as a JSON object //$user = DB::table('users')->find($id); return view('users.show', compact('userObject')); } public function edit($user_id) { if (Auth::guest()) { return redirect("/"); } if (!Auth::user()->admin) { return redirect("/"); } $user = User::where('id',$user_id)->first(); $season_id = Season::getCurrent()->id; $paid_date_str=""; $val=User::payment_date($user_id, $season_id); if ($val) { $paid_date_str=User::toGermanDate($val);} return view ('users.edit', compact('user','paid_date_str')); } public function store() { if (Auth::guest()) { return redirect("/"); } $season_id = Season::getCurrent()->id; // Validate form $this->validate(request(), [ 'id' => 'required', 'firstname' => 'required', 'lastname' => 'required', 'email'=> 'required' ]); $user=User::where('id', request('id'))->first(); $user->name=request('firstname')." ".request('lastname'); $user->firstname=request('firstname'); $user->lastname=request('lastname'); $user->email=request('email'); if (request()->has('admin')) { $user->admin = true; } else { $user->admin=false; } $user->save(); Payment::set_payment_date(request('id'), $season_id, request('paid')); Tipp::createAllTips(); return redirect('/users'); } public function ranking($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;"; dd($sql); $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("/"); } } } // Payment made ? if (! User::payment_date(Auth::user()->id, $currentSeason->id)) { return view('users.no_payment'); } // Hier werden _alle_ Tipps der aktuellen Saison ausgerechnet, die $round_id Begrenzung wird erst später ausgewertet. // TODO: Nur die Runden durchrechnen, die aktuell sind, oder round_incomplete, alle anderen Runden (bis zur ersten unvollständigen) sollen in eine Cachetabelle gespeichert werden. $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, 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." "; $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 . "and users.deleted is null "; $sql = $sql . "order by rounds.id, games.id, users.id;"; $result=DB::select($sql); $roundtipps = array(); $user_ids=array(); $round_ids=array(); // Write sql result to roundtipps (score per round & user) 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; 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]['joker']=array(); $roundtipps[$key]['round_completed']=true; // Um ggfs. $roundtipps[$key]['user_name'] = $entry->user_name; $roundtipps[$key]['user_id'] = $entry->user_id; $roundtipps[$key]['rankscore']=0; $roundtipps[$key]['payout']=0; $roundtipps[$key]['earliest_kickoff']=$entry->game_kickoff; $roundtipps[$key]['hits']=0; // Wenigstens Tendenz getroffen. Wenn 4, dann 2 Punkte Bonus auf rankscore $roundtipps[$key]['is_dayscorewinner']=0; // Wenigstens Tendenz getroffen. Wenn 4, dann 2 Punkte Bonus auf rankscore } $game_value=Tipp::getScoreLocal($entry->game_score1,$entry->game_score2,$entry->tipp_score1,$entry->tipp_score2,$entry->joker); // Für alle 4 Spiele $roundtipps[$key]['rankscore']+=$game_value; if($game_value>0) { $roundtipps[$key]['hits']+=1;} if ($roundtipps[$key]['hits']==4) {$roundtipps[$key]['rankscore']+=2;} // Wenn alle 4 Spiele mind. Tendenz, dann 2 Punkte Bonus if ($entry->game_score1==-1 || $entry->game_score2==-1) { $roundtipps[$key]['round_completed'] = false; } array_push($roundtipps[$key]['tipps'],$entry->tipp_score1); array_push($roundtipps[$key]['tipps'],$entry->tipp_score2); array_push($roundtipps[$key]['results'],$entry->game_score1); array_push($roundtipps[$key]['results'],$entry->game_score2); array_push($roundtipps[$key]['joker'],$entry->joker); if ( $entry->game_kickoff < $roundtipps[$key]['earliest_kickoff'] ) { $roundtipps[$key]['earliest_kickoff'] = $entry->game_kickoff; } } // NOW ALL KEYS FOR ROUNDTIPPS (ROUND & USER) EXIST // CALCULATION OF SCORES, RANKS, ETC. // FIRST LOOP: COMPUTE AGGREGATED VALUES $highestDayscores=array(); foreach($user_ids as $user_id) { $totalRankScore=0; foreach($round_ids as $round_id) { $key=$round_id."_".$user_id; // Compute Dayscore values $dayScore1WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][0],$roundtipps[$key]['results'][1],$roundtipps[$key]['tipps'][0],$roundtipps[$key]['tipps'][1],$roundtipps[$key]['joker'][0],$roundtipps[$key]['rankscore']); $dayScore2WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][2],$roundtipps[$key]['results'][3],$roundtipps[$key]['tipps'][2],$roundtipps[$key]['tipps'][3],$roundtipps[$key]['joker'][1],$roundtipps[$key]['rankscore']); $dayScore3WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][4],$roundtipps[$key]['results'][5],$roundtipps[$key]['tipps'][4],$roundtipps[$key]['tipps'][5],$roundtipps[$key]['joker'][2],$roundtipps[$key]['rankscore']); $dayScore4WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][6],$roundtipps[$key]['results'][7],$roundtipps[$key]['tipps'][6],$roundtipps[$key]['tipps'][7],$roundtipps[$key]['joker'][3],$roundtipps[$key]['rankscore']); $totalDayScoreWithRankScore = Tipp::addDayScoreValues($dayScore1WithRankScore,$dayScore2WithRankScore); $totalDayScoreWithRankScore = Tipp::addDayScoreValues($totalDayScoreWithRankScore,$dayScore3WithRankScore); $totalDayScoreWithRankScore = Tipp::addDayScoreValues($totalDayScoreWithRankScore,$dayScore4WithRankScore); $roundtipps[$key]['dayScoreWithRankScore'] = $totalDayScoreWithRankScore; $roundtipps[$key]['dayscore'] = Tipp::getDayScoreWithoutRankScore($totalDayScoreWithRankScore); if (!array_key_exists($round_id,$highestDayscores)) { $highestDayscores[$round_id] = 0;} if ($highestDayscores[$round_id] < $roundtipps[$key]['dayscore'] ) { $highestDayscores[$round_id]=$roundtipps[$key]['dayscore'];} $totalRankScore += $roundtipps[$key]["rankscore"]; $roundtipps[$key]['totalRankScore'] = $totalRankScore; } } //////////////////////////////////////////////////////// // Sortier-Array nach Rang (nur für max_round_id) $userRankings = array(); foreach ($user_ids as $user_id) { $key = $max_round_id."_".$user_id; array_push($userRankings, [$user_id , $roundtipps[$key]['totalRankScore']]); } usort($userRankings,array($this, 'cmpRank')); // Ranknr identifizieren, inkl, geteilter Rankplatzierungen nur für max_round_id notwendig, da der Rest ja gar nicht angezeigt wird $lastScore=-1; $lastrank=0; $current_list_position=0; foreach($userRankings as $userRank) { $user_id=$userRank[0]; $totalRankScore=$userRank[1]; $key=$max_round_id."_".$user_id; $current_list_position+=1; if ($roundtipps[$key]["totalRankScore"]==$lastScore) { $roundtipps[$key]["rank"] = $lastrank; } else { $lastrank = $current_list_position; $roundtipps[$key]["rank"] = $current_list_position; $lastScore = $totalRankScore; } } ////////////////////////////// // START OF HURTFUL 6 PLACE RESTRICTION IF DAYSCORE WIN (exception: completely even scores) // If more than 6 DayScoreWinners: Restrict by dayscore (rank) // Compute highest dayscore // Addition: no dayscorewinner && round_completed: Payout goes to next round $payouts = Quota::getPayouts($currentSeason->id); $totalDayWinPayout = 0; foreach ($round_ids as $round_id) { $totalDayWinPayout += $payouts["tagessieg"]; $highestDayScore = $highestDayscores[$round_id]; $usersWithHighestDayScore = array(); $round_completed=false; foreach ($user_ids as $user_id) { $round_completed = $roundtipps[$key]['round_completed']; // TODO: Separaten info array roundData erzeugen, der Rundenspezifische, SPielerübergreifende Infos enthält, so wie round_completed. $key = $round_id . "_" . $user_id; if ($roundtipps[$key]['dayscore'] == $highestDayScore && $roundtipps[$key]['round_completed'] && $highestDayScore>0 ) { array_push($usersWithHighestDayScore, [$user_id, $roundtipps[$key]['dayScoreWithRankScore']]); } } if (sizeof($usersWithHighestDayScore) > 6) { usort($usersWithHighestDayScore, array($this, 'cmpDayWin')); } $count = 0; $cutOffScore = 0; $dayScoreWinnersIds = array(); foreach ($usersWithHighestDayScore as $user) { // Feld0: user_id, dayScoreWithRankScore $count += 1; if ($count > 6) { if ($user[1] < $cutOffScore) { break; } } array_push($dayScoreWinnersIds, $user[0]); $key = $round_id . "_" . $user[0]; $roundtipps[$key]['is_dayscorewinner'] = true; Log::info("Dayscorewinner Round " . $round_id . " = " . $roundtipps[$key]["user_name"]); $cutOffScore = $user[1]; } // Compute Dayscorewin payout (Tagessieg) $winnerCount = sizeof($dayScoreWinnersIds); $single_payout=0; if ($winnerCount > 0) { $single_payout = $totalDayWinPayout / $winnerCount; $single_payout = number_format((float)$single_payout, 2, '.', ''); $single_payout = str_replace(".", ",", $single_payout); $totalDayWinPayout=0; } foreach ($user_ids as $user_id) { $key = $round_id . "_" . $user_id; if ($roundtipps[$key]['is_dayscorewinner']) { $roundtipps[$key]['payout'] = $single_payout; } else { $roundtipps[$key]['payout'] = ''; } } } //////////////////// END OF ROUNDTIPPS CREATION /////////////////// ///////////////////////////// DISPLAY AUFBAU ///////////////////////////// /// // AUFBAU RANKINGLISTE A.K.A. RANKINGDISPLAY AB HIER NUR NOCH ANZEIGE-SPEZIFIKA ! // Aufbau der Rankingliste in rankingDisplay, sowie aufaddieren der jeweiligen Punkte. // Loop through games and users (again) $rankingDisplay=array(); foreach ($user_ids as $user_id) { $rankscore_total= 0; $payout_sum = 0; $round_id = $max_round_id; $key = $round_id . "_" . $user_id; if (!array_key_exists($user_id, $rankingDisplay)) { $rankingDisplay[$user_id] = array(); $rankingDisplay[$user_id]["user_id"] = $user_id; $rankingDisplay[$user_id]["round_id"] = $round_id; $rankingDisplay[$user_id]["rank"] = $roundtipps[$key]["rank"]; $rankingDisplay[$user_id]["payout"] = $roundtipps[$key]["payout"]; $rankingDisplay[$user_id]["user_name"] = $roundtipps[$key]["user_name"]; $rankingDisplay[$user_id]["is_dayscorewinner"] = $roundtipps[$key]["is_dayscorewinner"]; if ($round_id==4 && $roundtipps[$key]["is_dayscorewinner"]) { Log::info("Dayscorewinner: ".$roundtipps[$key]["user_name"]); } if ($user_id==1) { Log::info("rankscore after user init for display round_id ".$round_id." = ".$roundtipps[$key]["rankscore"]);} $rankingDisplay[$user_id]["rankscore"] = $roundtipps[$key]["rankscore"]; // Summe Rangwertung alle 4 Spiele/Tipps der letzten durchlaufenen Runde, NICHT in init stellen !! $rankingDisplay[$user_id]["dayscore"] = $roundtipps[$key]["dayscore"]; // Dayscore der letzten durchlaufenen Runde, NICHT in init stellen !! $rankingDisplay[$user_id]["dayScoreWithRankScore"] = $roundtipps[$key]["dayScoreWithRankScore"]; // Dayscore der letzten durchlaufenen Runde, NICHT in init stellen !! } $rankingDisplay[$user_id]["totalRankScore"] = $roundtipps[$key]['totalRankScore']; $rankingDisplay[$user_id]["tipp_score1"] = $roundtipps[$key]["tipps"][0]; $rankingDisplay[$user_id]["tipp_score2"] = $roundtipps[$key]["tipps"][1]; $rankingDisplay[$user_id]["joker1"] = $roundtipps[$key]["joker"][0]; $rankingDisplay[$user_id]["result_score1"] = $roundtipps[$key]["results"][0]; $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]["joker"][0]); $rankingDisplay[$user_id]["tipp_score3"] = $roundtipps[$key]["tipps"][2]; $rankingDisplay[$user_id]["tipp_score4"] = $roundtipps[$key]["tipps"][3]; $rankingDisplay[$user_id]["joker2"] = $roundtipps[$key]["joker"][1]; $rankingDisplay[$user_id]["result_score3"] = $roundtipps[$key]["results"][2]; $rankingDisplay[$user_id]["result_score4"] = $roundtipps[$key]["results"][3]; // Determine coloration for Game2 $rankingDisplay[$user_id]["trendCol2"] = Tipp::trendCol($roundtipps[$key]["results"][2],$roundtipps[$key]["results"][3], $roundtipps[$key]["tipps"][2],$roundtipps[$key]["tipps"][3], $roundtipps[$key]["joker"][1]); $rankingDisplay[$user_id]["tipp_score5"] = $roundtipps[$key]["tipps"][4]; $rankingDisplay[$user_id]["tipp_score6"] = $roundtipps[$key]["tipps"][5]; $rankingDisplay[$user_id]["joker3"] = $roundtipps[$key]["joker"][2]; $rankingDisplay[$user_id]["result_score5"] = $roundtipps[$key]["results"][4]; $rankingDisplay[$user_id]["result_score6"] = $roundtipps[$key]["results"][5]; // Determine coloration for Game3 $rankingDisplay[$user_id]["trendCol3"] = Tipp::trendCol($roundtipps[$key]["results"][4],$roundtipps[$key]["results"][5], $roundtipps[$key]["tipps"][4],$roundtipps[$key]["tipps"][5], $roundtipps[$key]["joker"][2]); $rankingDisplay[$user_id]["tipp_score7"] = $roundtipps[$key]["tipps"][6]; $rankingDisplay[$user_id]["tipp_score8"] = $roundtipps[$key]["tipps"][7]; $rankingDisplay[$user_id]["joker4"] = $roundtipps[$key]["joker"][3]; $rankingDisplay[$user_id]["result_score7"] = $roundtipps[$key]["results"][6]; $rankingDisplay[$user_id]["result_score8"] = $roundtipps[$key]["results"][7]; // Determine coloration for Game4 $rankingDisplay[$user_id]["trendCol4"] = Tipp::trendCol($roundtipps[$key]["results"][6],$roundtipps[$key]["results"][7], $roundtipps[$key]["tipps"][6],$roundtipps[$key]["tipps"][7], $roundtipps[$key]["joker"][3]); } $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(); // Sortieren nach Rankscore $entries = array(); usort($rankingDisplay, array($this,"cmp")); foreach($rankingDisplay as $entry) { array_push($entries, $entry); } $rankingDisplay = $entries; // Store game results as separate array. Wir nutzen aus, dass die Ergebnisse in jeder Zeile // von Rankingdisplay abgespeichert sind. $game_results=array(); // 4 Spielergebnisse der angezeigten Runde $a=$rankingDisplay[0]; array_push($game_results,$rankingDisplay[0]["result_score1"],$rankingDisplay[0]["result_score2"],$rankingDisplay[0]["result_score3"],$rankingDisplay[0]["result_score4"],$rankingDisplay[0]["result_score5"],$rankingDisplay[0]["result_score6"],$rankingDisplay[0]["result_score7"],$rankingDisplay[0]["result_score8"]); return view('users.ranking', compact('all_rounds','rankingDisplay','userids','round','games','game_results')); } public function cmp($user1, $user2) { return ($user1['totalRankScore'] < $user2['totalRankScore']); } public function cmpDayWin($user1, $user2) { return ($user1[1] < $user2[1]); // Feld0: user_id, Feld1: dayScoreWithRankScore } public function cmpRank($rank1, $rank2) { return ($rank1[1] < $rank2[1]); } public function show_payouts() { $currentSeason = Season::getCurrent(); $active_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->whereNotNull('paid_date')->get() ); $quotas = Quota::getQuotas($currentSeason->id); $payouts = Quota::getPayouts($currentSeason->id); return view('users.show_payouts', compact('payouts','active_user_count','quotas','currentSeason')); } public function mailtest() { // Works: // $user = User::where('id','=',1)->first(); // \Mail::to($user)->send(new RoundmailMailer); $users = User::whereIn('id',array(1))->get(); foreach($users as $user) { Log::info("Sending RoundmailMailer to: ".$user->name); \Mail::to($user)->send(new RoundmailMailer); } } public function test() { //Password::sendResetLink(['email','magus@zauberturm.de']); $request = new Request(); $request->merge(['email'=>'magus@zauberturm.de']); $broker = $this->getBroker(); $response = Password::broker($broker)->sendResetLink($request->only('email'), function (Message $message) { $message->subject($this->getEmailSubject()); }); } // App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail public function reset() { return view('auth.passwords.email'); } public function processReset(Request $request) { $response = $this->broker()->sendResetLink( $request->only('email') ); } //route: useredit => useredit view public function useredit($user_id) { if (Auth::guest()) { return redirect("/"); } $user=Auth::user(); $paid_date_str=""; $val=User::payment_date($user_id, Season::getCurrent()->id); if ($val) { $paid_date_str=User::toGermanDate($val);} return view ('users.useredit', compact('user','paid_date_str')); } public function send_reset_links_from_settings() { if (Auth::guest()) { return redirect("/"); } $this->sendResetLink(Auth::user()); } public function storeUserEdit() { Log::info("storeUserEdit"); if (Auth::guest()) { return redirect("/"); } Log::info("Auth ok"); Log::info("Request:"); Log::info(request()); $season_id = Season::getCurrent()->id; // Validate form $this->validate(request(), [ 'email'=> 'required' ]); $user=Auth::user(); $user->email=request('email'); if (request()->has('gets_reminders')) { Log::info("No reminder"); $user->gets_reminders = true; } else { Log::info("Set reminder"); $user->gets_reminders=false; } Log::info("Setting gets_reminders to: " . request('gets_reminders')); $user->save(); return redirect('/'); } }