2017-06-20 08:43:36 +02:00
< ? php
namespace App\Http\Controllers ;
use Illuminate\Http\Request ;
use App\User ;
2017-06-21 17:12:07 +02:00
use App\Season ;
use App\Payment ;
2017-06-26 17:21:30 +02:00
use App\Round ;
use App\Game ;
use App\Tipp ;
2017-08-19 16:53:39 +02:00
use App\Quota ;
2017-08-24 11:47:16 +02:00
use App\Mail\RoundmailMailer ;
2017-08-21 16:55:26 +02:00
2017-08-24 17:45:30 +02:00
use Password ;
use Illuminate\Contracts\Auth\Guard ;
use Illuminate\Foundation\Auth\ResetsPasswords ;
use Illuminate\Auth\Passwords\PasswordBroker ;
2017-06-20 08:43:36 +02:00
use DB ;
2017-06-26 17:21:30 +02:00
use Auth ;
use Log ;
2017-08-21 16:55:26 +02:00
2017-08-10 17:14:49 +02:00
use Carbon ;
2018-08-17 17:16:01 +02:00
use App\MyClasses\TimeLogger ;
2017-06-20 08:43:36 +02:00
class UsersController extends Controller
{
2017-06-21 17:12:07 +02:00
public function main () {
2018-08-17 17:16:01 +02:00
$a = new TimeLogger ( " UsersController::main() " );
Log :: info ( $a -> getStartMessage ());
2017-08-24 17:45:30 +02:00
$currentSeason = Season :: getCurrent ();
2017-08-01 13:35:34 +02:00
$roundname = " " ;
$report = " " ;
2017-06-26 17:21:30 +02:00
2017-08-24 17:45:30 +02:00
// display_rounds berechnen für Nav und Rundenberichte
2017-08-21 16:55:26 +02:00
$display_rounds = array ();
2017-08-01 13:35:34 +02:00
if ( $currentSeason ) {
2017-08-19 16:53:39 +02:00
$round_id = Round :: getLastCompleteRoundId ();
2017-08-21 16:55:26 +02:00
2017-08-01 13:35:34 +02:00
if ( $round_id > - 1 ) {
2017-11-02 16:41:07 +01:00
$rounds = Round :: where ( " id " , " <= " , $round_id ) -> where ( 'season_id' , '=' , $currentSeason -> id ) -> get ();
2017-08-21 16:55:26 +02:00
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 );
2017-08-01 13:35:34 +02:00
Log :: info ( " Loaded report: " . $report . " round-id= " . $round_id );
$roundname = $round -> name ;
2017-08-19 16:53:39 +02:00
} else { Log :: info ( " No round identified. Last Locked= " . $round_id ); $report = " " ;}
2017-08-01 13:35:34 +02:00
} else { Log :: info ( " No current season " );}
2017-08-24 17:45:30 +02:00
$nextRoundName = " " ;
2017-08-26 15:15:54 +02:00
$nextRound = Round :: getFirstTippableRound ();
2017-10-25 10:42:05 +02:00
$nextRoundName = " " ;
2017-08-28 16:34:19 +02:00
$nextRoundLockTime = " " ;
$diffToLock = " " ;
2017-10-25 10:42:05 +02:00
$hourDiffToLock = 999 ;
2017-08-28 16:34:19 +02:00
if ( $nextRound ) {
$nextRoundName = $nextRound -> name ;
$nextRoundLockTime = $nextRound -> getLockTime ();
$hourDiffToLock = $nextRoundLockTime -> diffInHours ( Carbon\Carbon :: now ());
2017-09-03 09:03:39 +02:00
if ( $hourDiffToLock == 0 ) {
$diffMin = $nextRoundLockTime -> diffInMinutes ( Carbon\Carbon :: now ());
if ( $diffMin == 0 ) { $diffMin = 1 ;}
if ( $diffMin == 1 ) {
$hourDiffToLock = $nextRoundLockTime -> diffInMinutes ( Carbon\Carbon :: now ()) . " Minute " ;
} else {
$hourDiffToLock = $nextRoundLockTime -> diffInMinutes ( Carbon\Carbon :: now ()) . " Minuten " ;
}
} else {
if ( $hourDiffToLock == 1 ) {
$hourDiffToLock = $hourDiffToLock . " Stunde " ;
} else {
$hourDiffToLock = $hourDiffToLock . " Stunden " ;
}
}
2017-08-28 16:34:19 +02:00
}
2017-08-24 17:45:30 +02:00
$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 ;
}
}
2018-08-17 17:16:01 +02:00
Log :: info ( $a -> getEndMessage ());
//error_log($a->getEndMessage());
2017-08-28 16:34:19 +02:00
return view ( 'main' , compact ( 'roundname' , 'display_rounds' , 'message_text_joker' , 'message_text_tipps' , 'nextRoundName' , 'nextRoundLockTime' , 'hourDiffToLock' ));
2017-06-20 08:43:36 +02:00
}
2018-08-17 17:16:01 +02:00
2017-06-21 17:12:07 +02:00
public function index () {
2018-08-17 17:16:01 +02:00
$a = new TimeLogger ( " UserController::index() " );
Log :: info ( $a -> getStartMessage ());
//error_log($a->getStartMessage());
2017-06-26 17:21:30 +02:00
if ( Auth :: guest ()) { return redirect ( " / " ); }
if ( ! Auth :: user () -> admin ) { return redirect ( " / " ); }
2017-09-03 09:03:39 +02:00
$activeUsers = User :: getActives ();
2017-08-24 11:47:16 +02:00
2018-08-17 17:16:01 +02:00
$b = new TimeLogger ( " UsersController::index-db_subqueries " );
Log :: info ( $b -> getStartMessage ());
2017-08-16 14:32:11 +02:00
$currentSeason = Season :: getCurrent ();
2017-10-25 10:42:05 +02:00
if ( ! $currentSeason ) { return redirect ( '/' ); }
2017-09-11 10:38:57 +02:00
2017-09-03 09:03:39 +02:00
$active_user_count = sizeof ( $activeUsers );
2018-12-28 09:00:17 +01:00
//$total_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->get() );
2017-08-16 14:32:11 +02:00
2017-08-03 20:47:51 +02:00
$users = DB :: table ( 'users' ) -> where ( 'deleted' , null ) -> orderBy ( 'lastname' ) -> get ();
2018-12-28 09:00:17 +01:00
$total_user_count = sizeof ( $users );
2017-08-16 14:32:11 +02:00
2018-08-17 17:16:01 +02:00
Log :: info ( $b -> getEndMessage ());
Log :: info ( $a -> getStartMessage ());
2018-12-28 08:54:56 +01:00
$missingTipps = User :: getMissingTippsAndJokers ( $activeUsers );
Log :: info ( " Missing tipps id overview: " );
foreach ( $missingTipps [ " MISSING_TIPP " ] as $uid => $val ) {
Log :: info ( $uid );
}
2018-08-17 17:16:01 +02:00
$c = new TimeLogger ( " UsersController::index-missingTipp Loop " );
Log :: info ( $c -> getStartMessage ());
2018-12-28 08:54:56 +01:00
$actIds = array ();
foreach ( $activeUsers as $aUser ) {
Log :: info ( " Active user: " . $aUser -> id . " " . $aUser -> name );
$actIds [ $aUser -> id ] = $aUser -> id ;
}
foreach ( $users as $index => $user ) {
Log :: info ( " Filling in data for user_id " . $user -> id );
if ( ! array_key_exists ( $user -> id , $actIds )) {
Log :: info ( " Inactive id: " . $user -> id );
$users [ $index ] -> missingTippText = " inaktiv " ;
$users [ $index ] -> tippStyling = " grey " ;
$users [ $index ] -> missingJokerText = " inaktiv " ;
$users [ $index ] -> jokerStyling = " grey " ;
2018-08-17 17:16:01 +02:00
2017-08-24 11:47:16 +02:00
} else {
2018-08-17 17:16:01 +02:00
2018-12-28 08:54:56 +01:00
if ( array_key_exists ( $user -> id , $missingTipps [ " MISSING_TIPP " ])) {
2019-01-02 16:59:19 +01:00
Log :: info ( " ..adding missing tipp " );
2018-12-28 08:54:56 +01:00
$users [ $index ] -> missingTippText = " Tipps fehlen " ;
$users [ $index ] -> tippStyling = " red " ;
} else {
2019-01-02 16:59:19 +01:00
Log :: info ( " ..adding existing tipp " );
2018-12-28 08:54:56 +01:00
$users [ $index ] -> missingTippText = " Runde getippt " ;
$users [ $index ] -> tippStyling = " green " ;
}
2018-08-17 17:16:01 +02:00
2019-01-02 16:59:19 +01:00
Log :: info ( " UsersController.index: Joker Display Check for UserId= " . $user -> id );
2018-12-28 08:54:56 +01:00
if ( array_key_exists ( $user -> id , $missingTipps [ " MISSING_JOKER " ])) {
2019-01-02 16:59:19 +01:00
Log :: info ( " UsersController.index: MISSING JOKER DETECTED -> " . $user -> id );
2018-12-28 08:54:56 +01:00
$users [ $index ] -> missingJokerText = " Joker fehlt " ;
$users [ $index ] -> jokerStyling = " red " ;
} else {
2019-01-02 16:59:19 +01:00
Log :: info ( " UsersController.index: JOKER EXISTS -> " . $user -> id );
2018-12-28 08:54:56 +01:00
$users [ $index ] -> missingJokerText = " Joker gesetzt " ;
$users [ $index ] -> jokerStyling = " green " ;
}
2017-08-24 11:47:16 +02:00
}
2017-08-17 17:41:11 +02:00
}
2018-08-17 17:16:01 +02:00
Log :: info ( $c -> getEndMessage ());
2017-11-16 09:05:26 +01:00
$round = Round :: getFirstTippableRound ();
$firstTippableRound = new Round ();
$firstTippableRound -> name = " - " ;
if ( $round ) { $firstTippableRound = $round ; }
2018-08-17 17:16:01 +02:00
Log :: info ( $a -> getEndMessage ());
//error_log($a->getEndMessage());
2017-11-16 09:05:26 +01:00
return view ( 'users.index' , compact ( 'users' , 'active_user_count' , 'total_user_count' , 'firstTippableRound' ));
2017-06-20 08:43:36 +02:00
}
2017-08-03 20:47:51 +02:00
/*
2017-06-20 08:43:36 +02:00
public function showUsers () {
2017-08-03 20:47:51 +02:00
$users = DB :: table ( 'users' ) -> orderBy ( 'lastname' ) -> get ();
2017-06-20 08:43:36 +02:00
return view ( 'users.list' , compact ( 'users' ));
}
2017-08-03 20:47:51 +02:00
*/
2017-06-20 08:43:36 +02:00
// 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' ));
}
2017-06-21 17:12:07 +02:00
public function edit ( $user_id ) {
2017-06-26 17:21:30 +02:00
if ( Auth :: guest ()) { return redirect ( " / " ); }
if ( ! Auth :: user () -> admin ) { return redirect ( " / " ); }
2017-06-21 17:12:07 +02:00
$user = User :: where ( 'id' , $user_id ) -> first ();
$season_id = Season :: getCurrent () -> id ;
$paid_date_str = " " ;
$val = User :: payment_date ( $user_id , $season_id );
2017-06-26 17:21:30 +02:00
if ( $val ) { $paid_date_str = User :: toGermanDate ( $val );}
2017-06-21 17:12:07 +02:00
return view ( 'users.edit' , compact ( 'user' , 'paid_date_str' ));
}
2017-08-28 16:34:19 +02:00
public function store () {
2017-06-26 17:21:30 +02:00
if ( Auth :: guest ()) { return redirect ( " / " ); }
2018-08-17 17:16:01 +02:00
$a = new TimeLogger ( " UsersController::store() " );
Log :: info ( $a -> getStartMessage ());
//error_log($a->getStartMessage());
2017-06-21 17:12:07 +02:00
$season_id = Season :: getCurrent () -> id ;
// Validate form
$this -> validate ( request (), [
'id' => 'required' ,
2017-08-01 14:33:22 +02:00
'firstname' => 'required' ,
'lastname' => 'required' ,
2017-06-21 17:12:07 +02:00
'email' => 'required'
]);
2017-08-01 14:33:22 +02:00
2017-06-21 17:12:07 +02:00
$user = User :: where ( 'id' , request ( 'id' )) -> first ();
2017-08-01 14:33:22 +02:00
$user -> name = request ( 'firstname' ) . " " . request ( 'lastname' );
$user -> firstname = request ( 'firstname' );
$user -> lastname = request ( 'lastname' );
2017-06-21 17:12:07 +02:00
$user -> email = request ( 'email' );
2017-11-17 12:01:24 +01:00
if ( request () -> has ( 'iban' )) { $user -> iban = request ( 'iban' ); }
if ( request () -> has ( 'bankname' )) { $user -> bankname = request ( 'bankname' ); }
if ( request () -> has ( 'blz' )) { $user -> blz = request ( 'blz' ); }
if ( request () -> has ( 'kontonr' )) { $user -> kontonr = request ( 'kontonr' ); }
2017-06-22 17:00:09 +02:00
if ( request () -> has ( 'admin' )) {
$user -> admin = true ;
} else {
$user -> admin = false ;
}
2017-06-21 17:12:07 +02:00
$user -> save ();
2017-06-22 17:00:09 +02:00
Payment :: set_payment_date ( request ( 'id' ), $season_id , request ( 'paid' ));
2017-06-21 17:12:07 +02:00
2017-08-24 11:47:16 +02:00
Tipp :: createAllTips ();
2018-08-17 17:16:01 +02:00
Log :: info ( $a -> getEndMessage ());
//error_log($a->getEndMessage());
2017-06-21 17:12:07 +02:00
return redirect ( '/users' );
}
2017-08-01 13:35:34 +02:00
2017-10-10 11:32:12 +02:00
public function ranking ( $max_round_id , $seasonId =- 1 ) {
2017-11-02 16:41:07 +01:00
if ( ! Auth :: user ()) { return redirect ( " / " ); }
2017-08-31 07:36:27 +02:00
$startTime = microtime ( true );
2018-01-10 08:45:01 +01:00
2017-10-10 11:32:12 +02:00
$season = Season :: getCurrent ();
if ( $seasonId !=- 1 ) {
$season = Season :: where ( 'id' , '=' , $seasonId ) -> first ();
2017-12-29 19:08:46 +01:00
$seasonId = $season -> id ;
} else {
$seasonId = $season -> id ;
2017-10-10 11:32:12 +02:00
}
2017-08-08 15:32:54 +02:00
2018-01-10 08:45:01 +01:00
// Check ob mindestens eine Runde der Saison gelockt ist, die angezeigt werden kann
2017-08-10 17:14:49 +02:00
if ( $max_round_id ==- 1 ) {
$max_round_id = Round :: getLastLockedRoundId ();
if ( $max_round_id ==- 1 ) {
2017-12-29 19:08:46 +01:00
$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= " . $seasonId . " and games.round_id=rounds.id order by rounds.id; " ;
2018-01-10 08:45:01 +01:00
//dd($sql);
2017-12-29 19:08:46 +01:00
$entries = DB :: select ( $sql );
2017-08-10 17:14:49 +02:00
2017-12-29 19:08:46 +01:00
if ( count ( $entries ) > 0 ) {
$start_date = $entries [ 0 ] -> start_date ;
2017-08-10 17:14:49 +02:00
return view ( 'users.no_ranking' , compact ( 'start_date' ));
} else {
return redirect ( " / " );
}
}
}
2017-10-06 12:17:49 +02:00
$max_round_id = min ( $max_round_id , Round :: getLastLockedRoundId ());
2017-08-30 14:52:21 +02:00
// Payment made ?
2017-10-10 11:32:12 +02:00
if ( ! User :: payment_date ( Auth :: user () -> id , $season -> id ) && Auth :: user () -> name != " Torsten Schneider " ) {
2017-08-30 14:52:21 +02:00
return view ( 'users.no_payment' );
}
2017-08-31 07:36:27 +02:00
$response = Tipp :: getRoundTipps ( $max_round_id );
$roundtipps = $response [ 'roundtipps' ];
2017-09-05 11:49:39 +02:00
2017-08-31 07:36:27 +02:00
$roundData = $response [ 'roundData' ];
$user_ids = $response [ 'user_ids' ];
$round_ids = $response [ 'round_ids' ];
2017-08-30 14:52:21 +02:00
2017-08-29 15:52:12 +02:00
///////////////////////////// DISPLAY AUFBAU /////////////////////////////
///
// AUFBAU RANKINGLISTE A.K.A. RANKINGDISPLAY AB HIER NUR NOCH ANZEIGE-SPEZIFIKA !
2017-08-08 15:32:54 +02:00
// Aufbau der Rankingliste in rankingDisplay, sowie aufaddieren der jeweiligen Punkte.
2017-08-29 15:52:12 +02:00
// Loop through games and users (again)
2017-08-08 15:32:54 +02:00
$rankingDisplay = array ();
2017-08-17 17:41:11 +02:00
2017-09-05 11:49:39 +02:00
$isFinalRound = false ;
2018-02-05 09:51:16 +01:00
foreach ( $user_ids as $user_id ) {
$round_id = $max_round_id ;
$key = $round_id . " _ " . $user_id ;
if ( $roundtipps [ $key ][ " ranking_payout " ] > 0 ) {
$isFinalRound = true ;
}
}
2017-09-05 11:49:39 +02:00
2018-02-04 08:20:40 +01:00
$payoutList = Quota :: getPayoutList ( $response );
2017-09-22 17:40:48 +02:00
Log :: info ( " Starting Display Loop " );
2017-08-08 15:32:54 +02:00
foreach ( $user_ids as $user_id ) {
2017-08-10 17:14:49 +02:00
$rankscore_total = 0 ;
2017-08-08 15:32:54 +02:00
$payout_sum = 0 ;
2017-08-10 17:14:49 +02:00
2017-08-29 15:52:12 +02:00
$round_id = $max_round_id ;
2017-08-17 17:41:11 +02:00
2017-08-29 15:52:12 +02:00
$key = $round_id . " _ " . $user_id ;
2017-08-28 16:34:19 +02:00
2017-08-29 15:52:12 +02:00
if ( ! array_key_exists ( $user_id , $rankingDisplay )) {
$rankingDisplay [ $user_id ] = array ();
2017-08-28 16:34:19 +02:00
2017-08-29 15:52:12 +02:00
$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 " ];
2017-08-28 16:34:19 +02:00
2017-12-11 08:47:56 +01:00
$rankingDisplay [ $user_id ][ " grank " ] = $roundtipps [ $key ][ " grank " ];
2017-12-08 08:42:05 +01:00
$rankingDisplay [ $user_id ][ " gshirt_score " ] = $roundtipps [ $key ][ " gshirt_score " ];
2017-12-04 10:20:12 +01:00
$rankingDisplay [ $user_id ][ " gshirt_totalscore " ] = $roundtipps [ $key ][ " gshirt_totalscore " ];
$rankingDisplay [ $user_id ][ " gshirt_foulcount " ] = $roundtipps [ $key ][ " gshirt_foulcount " ];
2018-01-12 08:40:42 +01:00
$rankingDisplay [ $user_id ][ " gshirt_leader " ] = $roundtipps [ $key ][ " gshirt_leader " ];
2017-12-04 10:20:12 +01:00
2017-09-05 11:49:39 +02:00
$rankingDisplay [ $user_id ][ " ranking_payout " ] = $roundtipps [ $key ][ " ranking_payout " ];
2018-02-05 09:51:16 +01:00
2017-08-28 16:34:19 +02:00
$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 !!
2017-08-29 15:52:12 +02:00
$rankingDisplay [ $user_id ][ " dayScoreWithRankScore " ] = $roundtipps [ $key ][ " dayScoreWithRankScore " ]; // Dayscore der letzten durchlaufenen Runde, NICHT in init stellen !!
2017-08-10 17:14:49 +02:00
}
2017-08-08 15:32:54 +02:00
2017-08-29 15:52:12 +02:00
$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 ]);
2018-02-04 08:20:40 +01:00
2018-02-05 09:51:16 +01:00
if ( $isFinalRound == true ) {
// Add GShirt, Playoff, Pokal payout
Log :: info ( " !> " . $user_id );
$rankingDisplay [ $user_id ][ 'gshirt_payout' ] = 0 ;
2018-02-06 08:24:41 +01:00
$rankingDisplay [ $user_id ][ 'pokal' ] = 0 ;
2018-02-05 09:51:16 +01:00
$rankingDisplay [ $user_id ][ 'playoff' ] = 0 ;
2018-02-04 08:20:40 +01:00
$userPayouts = $payoutList [ $user_id ];
2018-02-05 09:51:16 +01:00
$hasGreenShirtGame = Season :: hasGreenShirtGame ();
2018-02-04 08:20:40 +01:00
foreach ( $userPayouts as $payoutItem ) {
2018-02-06 08:24:41 +01:00
Log :: info ( $user_id . " - " . $payoutItem [ 'roundname' ]);
2018-02-05 09:51:16 +01:00
if ( $hasGreenShirtGame ) {
if ( $payoutItem [ 'roundname' ] == " Grünes Trikot " ) {
$rankingDisplay [ $user_id ][ " gshirt_payout " ] = $payoutItem [ 'payout' ];
2018-02-06 08:24:41 +01:00
Log :: info ( " GreenShirt goes to: " . $user_id );
2018-02-05 09:51:16 +01:00
}
}
if ( $payoutItem [ 'roundname' ] == 'Pokal' ) {
$rankingDisplay [ $user_id ][ " pokal " ] = $payoutItem [ 'payout' ];
Log :: info ( " Pokal goes to: " . $user_id );
}
if ( strpos ( $payoutItem [ 'roundname' ], 'Liga' ) !== false ) {
$rankingDisplay [ $user_id ][ " playoff " ] = $payoutItem [ 'payout' ];
2018-02-06 08:24:41 +01:00
Log :: info ( $payoutItem [ 'roundname' ] . " goes to: " . $user_id );
2018-02-04 08:20:40 +01:00
}
}
}
2017-08-10 17:14:49 +02:00
}
2017-08-08 15:32:54 +02:00
2017-08-10 17:14:49 +02:00
$userids = array_keys ( $rankingDisplay );
$round = Round :: where ( 'id' , '=' , $max_round_id ) -> first ();
$games = Game :: where ( 'round_id' , '=' , $max_round_id ) -> get ();
2017-10-10 11:32:12 +02:00
$all_rounds = Round :: where ( 'season_id' , '=' , $season -> id ) -> get ();
2017-08-15 16:19:19 +02:00
2017-08-30 14:52:21 +02:00
2017-08-16 14:00:25 +02:00
// Sortieren nach Rankscore
2017-08-15 16:19:19 +02:00
$entries = array ();
2017-08-17 17:41:11 +02:00
usort ( $rankingDisplay , array ( $this , " cmp " ));
2017-08-15 16:19:19 +02:00
foreach ( $rankingDisplay as $entry ) {
array_push ( $entries , $entry );
}
$rankingDisplay = $entries ;
2017-08-17 17:41:11 +02:00
// Store game results as separate array. Wir nutzen aus, dass die Ergebnisse in jeder Zeile
// von Rankingdisplay abgespeichert sind.
2017-08-31 07:36:27 +02:00
$game_results = array (); // 4 Spielergebnisse der angezeigten Runde
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 " ]);
2018-02-04 08:20:40 +01:00
Log :: info ( " UserController::ranking: ExecutionTime: " . number_format (( microtime ( true ) - $startTime ), 4 ) . " Seconds \n " );
2018-02-05 09:51:16 +01:00
//dd($rankingDisplay);
2017-09-05 11:49:39 +02:00
return view ( 'users.ranking' , compact ( 'all_rounds' , 'rankingDisplay' , 'userids' , 'round' , 'games' , 'game_results' , 'isFinalRound' ));
2017-08-08 15:32:54 +02:00
}
2017-08-17 17:41:11 +02:00
public function cmp ( $user1 , $user2 ) {
2017-08-29 15:52:12 +02:00
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 ]);
2017-08-15 16:19:19 +02:00
}
2017-08-19 16:53:39 +02:00
public function show_payouts () {
$currentSeason = Season :: getCurrent ();
2017-09-03 09:03:39 +02:00
$active_user_count = sizeof ( User :: getActives ());
2017-11-10 15:32:54 +01:00
$quotas = Quota :: getQuotas ();
$payouts = Quota :: getPayouts ();
2017-08-19 16:53:39 +02:00
2017-08-30 14:52:21 +02:00
return view ( 'users.show_payouts' , compact ( 'payouts' , 'active_user_count' , 'quotas' , 'currentSeason' ));
2017-08-19 16:53:39 +02:00
}
2017-08-08 15:32:54 +02:00
2017-09-03 09:03:39 +02:00
2017-12-29 10:10:04 +01:00
2017-08-21 16:55:26 +02:00
public function mailtest () {
// Works:
// $user = User::where('id','=',1)->first();
2017-08-24 11:47:16 +02:00
// \Mail::to($user)->send(new RoundmailMailer);
2017-08-21 16:55:26 +02:00
2017-08-24 11:47:16 +02:00
$users = User :: whereIn ( 'id' , array ( 1 )) -> get ();
2017-08-21 16:55:26 +02:00
foreach ( $users as $user ) {
2017-08-24 11:47:16 +02:00
Log :: info ( " Sending RoundmailMailer to: " . $user -> name );
\Mail :: to ( $user ) -> send ( new RoundmailMailer );
2017-08-21 16:55:26 +02:00
}
}
2017-08-24 17:45:30 +02:00
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' )
);
}
2017-08-26 15:15:54 +02:00
//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 ());
}
2017-08-28 16:34:19 +02:00
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 ;
}
2017-12-21 08:36:05 +01:00
if ( request () -> has ( 'iban' )) {
$user -> iban = request ( 'iban' );
}
if ( request () -> has ( 'blz' )) {
$user -> blz = request ( 'blz' );
}
if ( request () -> has ( 'bankname' )) {
$user -> bankname = request ( 'bankname' );
}
if ( request () -> has ( 'kontonr' )) {
$user -> kontonr = request ( 'kontonr' );
}
2017-08-28 16:34:19 +02:00
Log :: info ( " Setting gets_reminders to: " . request ( 'gets_reminders' ));
$user -> save ();
return redirect ( '/' );
}
2017-09-03 09:03:39 +02:00
public function delete ( $user_id ) {
if ( ! Auth :: user () -> admin ) redirect ( " /users " );
User :: softDelete ( $user_id );
return redirect ( " /users " );
}
2017-09-04 12:45:08 +02:00
2017-09-03 09:03:39 +02:00
public function money_ranking () {
2017-10-06 12:17:49 +02:00
if ( Auth :: guest ()) { return redirect ( " / " ); }
2017-09-03 09:03:39 +02:00
2017-12-29 19:08:46 +01:00
$currentSeason = Season :: getCurrent ();
if ( ! $currentSeason ) {
return view ( 'users.no_ranking' , compact ( 'start_date' ));
}
2018-01-10 08:45:01 +01:00
2017-09-03 09:03:39 +02:00
// Payment made ?
if ( ! User :: payment_date ( Auth :: user () -> id , $currentSeason -> id ) && Auth :: user () -> name != " Torsten Schneider " ) {
return view ( 'users.no_payment' );
}
2018-01-10 08:45:01 +01:00
// Check ob mindestens eine Runde der Saison gelockt ist angezeigt werden kann
$seasonId = $currentSeason -> id ;
$max_round_id = Round :: getLastCompleteRoundId ();
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= " . $seasonId . " and games.round_id=rounds.id order by rounds.id; " ;
//dd($sql);
2017-12-29 19:08:46 +01:00
$entries = DB :: select ( $sql );
if ( count ( $entries ) > 0 ) {
$start_date = $entries [ 0 ] -> start_date ;
return view ( 'users.no_ranking' , compact ( 'start_date' ));
} else {
return redirect ( " / " );
}
}
2018-01-08 10:09:44 +01:00
$sortedPayout = Quota :: getPayoutPerUser ();
2017-09-03 09:03:39 +02:00
return view ( 'users.payout_ranking_index' , compact ( 'sortedPayout' ));
}
2017-12-29 10:10:04 +01:00
public function money_ranking_with_iban () {
if ( Auth :: guest ()) { return redirect ( " / " ); }
$currentSeason = Season :: getCurrent ();
// Payment made ?
if ( ! User :: payment_date ( Auth :: user () -> id , $currentSeason -> id ) && Auth :: user () -> name != " Torsten Schneider " ) {
return view ( 'users.no_payment' );
}
$response = Tipp :: getRoundTipps ();
$roundtipps = $response [ 'roundtipps' ];
$roundData = $response [ 'roundData' ];
$user_ids = $response [ 'user_ids' ];
$round_ids = $response [ 'round_ids' ];
$payoutTotal = array ();
$cnt = 0 ;
foreach ( $round_ids as $round_id ) {
foreach ( $user_ids as $user_id ) {
$key = $round_id . " _ " . $user_id ;
$payout = str_replace ( " , " , " . " , $roundtipps [ $key ][ 'payout' ]);
if ( strlen ( $payout ) == 0 ) { $payout = 0 ; }
if ( ! array_key_exists ( $user_id , $payoutTotal )) {
$payoutTotal [ $user_id ][ 'amount' ] = 0 ;
$payoutTotal [ $user_id ][ 'name' ] = $roundtipps [ $key ][ 'user_name' ];
$payoutTotal [ $user_id ][ 'user_id' ] = $roundtipps [ $key ][ 'user_id' ];
}
$payoutTotal [ $user_id ][ 'amount' ] += $payout ;
$payout_ranking = $roundtipps [ $key ][ 'ranking_payout' ];
$payoutTotal [ $user_id ][ 'amount' ] += $payout_ranking ;
}
}
$sortedPayout = array ();
foreach ( $payoutTotal as $payout ) {
$payment = array ();
$payment [ 'user_id' ] = $payout [ 'user_id' ];
$payment [ 'name' ] = $payout [ 'name' ];
$payment [ 'amount' ] = $payout [ 'amount' ];
$user = User :: where ( 'id' , '=' , $payout [ 'user_id' ]) -> first ();
$payment [ 'iban' ] = $user -> iban ;
$payment [ 'blz' ] = $user -> blz ;
$payment [ 'bankname' ] = $user -> bankname ;
$payment [ 'kontonr' ] = $user -> kontonr ;
array_push ( $sortedPayout , $payment );
}
usort ( $sortedPayout , array ( $this , 'cmpPayment' ));
$users = User :: getActives ();
return view ( 'users.payout_ranking_index_with_iban' , compact ( 'sortedPayout' , 'users' ));
}
2017-09-03 09:03:39 +02:00
public function cmpPayment ( $payment1 , $payment2 ) {
return ( $payment1 [ 'amount' ] < $payment2 [ 'amount' ]);
}
2017-09-04 12:45:08 +02:00
public function money_ranking_detail ( $user_id ) {
$currentSeason = Season :: getCurrent ();
// Payment made ?
if ( ! User :: payment_date ( Auth :: user () -> id , $currentSeason -> id ) && Auth :: user () -> name != " Torsten Schneider " ) {
return view ( 'users.no_payment' );
}
2018-01-08 10:09:44 +01:00
$payouts = Quota :: getPayoutPerUserDetails ( $user_id );
2017-09-04 12:45:08 +02:00
2017-09-05 11:49:39 +02:00
2017-09-04 12:45:08 +02:00
$user = User :: where ( 'id' , '=' , $user_id ) -> first ();
return view ( 'users.payout_ranking_detail' , compact ( 'payouts' , 'user' ));
}
2017-12-12 07:58:24 +01:00
2018-01-08 10:09:44 +01:00
2018-08-17 17:16:01 +02:00
public function gshirt_ranking () {
if ( Auth :: guest ()) { return redirect ( " / " ); }
2018-01-10 08:45:01 +01:00
2018-08-17 17:16:01 +02:00
// Check ob mindestens eine Runde der Saison gelockt ist und angezeigt werden kann
2018-01-10 08:45:01 +01:00
2018-08-17 17:16:01 +02:00
$season = Season :: getCurrent ();
$seasonId = $season -> id ;
2018-01-10 08:45:01 +01:00
2018-08-17 17:16:01 +02:00
$max_round_id = Round :: getLastCompleteRoundId ();
if ( $max_round_id ==- 1 ) {
2018-01-10 08:45:01 +01:00
2018-08-17 17:16:01 +02:00
$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= " . $seasonId . " and games.round_id=rounds.id order by rounds.id; " ;
//dd($sql);
$entries = DB :: select ( $sql );
2018-01-10 08:45:01 +01:00
2018-08-17 17:16:01 +02:00
if ( count ( $entries ) > 0 ) {
$start_date = $entries [ 0 ] -> start_date ;
return view ( 'users.no_ranking' , compact ( 'start_date' ));
} else {
return redirect ( " / " );
2018-01-10 08:45:01 +01:00
}
2018-08-17 17:16:01 +02:00
}
2018-01-10 08:45:01 +01:00
2017-12-12 07:58:24 +01:00
2017-12-17 12:44:06 +01:00
$rankingDisplay = Tipp :: gshirt_table ();
2017-12-17 15:34:19 +01:00
$usernames = User :: getNames ();
2017-12-18 09:57:09 +01:00
$roundnames = array ();
foreach ( $rankingDisplay [ 0 ] as $user_round ) {
array_push ( $roundnames , $user_round [ 'round_name' ]);
}
2017-12-17 15:34:19 +01:00
return view ( 'users.gshirt_ranking' , compact ( 'rankingDisplay' , 'usernames' , 'roundnames' ));
2017-12-12 07:58:24 +01:00
}
2017-06-20 08:43:36 +02:00
}