TimeLogger moved, League ranking also for not completed but started rounds

This commit is contained in:
Torsten 2018-08-17 17:16:01 +02:00
parent 78a4a04cdf
commit 90c6d60ecd
26 changed files with 692 additions and 376 deletions

View file

@ -12,6 +12,7 @@ use App\Game;
use Carbon;
use Log;
use DB;
use App\MyClasses\TimeLogger;
class User extends Authenticatable
{
@ -138,10 +139,77 @@ class User extends Authenticatable
return $dbDate;
}
public static function hasMissingTipp($user_id) {
// TODO: implement hasMissingTipps($user_array)
// OPTIMIZED VERSION FOR hasMissingTipp
public static function getMissingTippsAndJokers($users) {
$round = Round::getFirstTippableRound();
if (!$round) return false;
$tippClock=new TimeLogger("User::getMissingTippsAndJokers()");
Log::info($tippClock->getStartMessage());
// expecting collection of user db objects like: $users = DB::table('users')->where('deleted',null)->orderBy('lastname')->get();
$idlist = array();
$usersWithoutJoker=array();
foreach($users as $key => $user) {
array_push($idlist,$key);
array_push($usersWithoutJoker,$key);
}
$games = Game::where('round_id','=',$round->id)->get();
$gameIds=array();
foreach ($games as $key => $game) {
array_push($gameIds,$key);
Log::info("GAME_ID:".$key);
}
$tipps = Tipp::whereIn('game_id', $gameIds)->get();
Log::info("Fetched advanced tipps, checking now for missing tipps and jokers");
$usersWithoutTipps=array();
foreach($tipps as $tipp) {
if ($tipp->score1 == -1 || $tipp->score2 == -1) {
$usersWithoutTipps[$tipp->user_id]="no_tipp";
Log::info("UserId ".$tipp->user_id." is missing a tipp!");
}
if ($tipp->joker == true) {
Log::info("Removing from jokerlist: ".$tipp->user_id);
unset($usersWithoutJoker[$tipp->user_id]);
}
}
foreach ($usersWithoutJoker as $id) {
Log::info("Jokerless:".$id);
}
$result=array();
$result["MISSING_TIPP"]=$usersWithoutTipps;
$result["MISSING_JOKER"]=$usersWithoutJoker;
Log::info("USERLIST: ".implode(",",$idlist));
Log::info($tippClock->getEndMessage());
foreach(array_keys($result) as $key => $value) {
Log::info("Main key: ".$key.", value=".$value);
}
$mtipps=$result["MISSING_TIPP"];
foreach($mtipps as $key => $value) {
Log::info("MTipp: ".$key." => ".$value);
}
return $result;
}
public static function hasMissingTipp($user_id) {
$round = Round::getFirstTippableRound();
if (!$round) return false;
//$a=new TimeLogger("User::hasMissingTipp()");
//Log::info($a->getStartMessage());
$round_id = $round->id;
$games = Game::where('round_id','=',$round_id)->get();
@ -151,14 +219,18 @@ class User extends Authenticatable
if(!$tipp) {
Log::info("Tipp doesnt exist: game_id=".$game->id.", user_id=".$user_id);
//Log::info($a->getEndMessage());
return 1;
}
if ($tipp->score1 == -1 || $tipp->score2 == -1) {
//Log::info("!!! User ".$user_id." has a missing tipp for game_id ".$game->id.", round = ".$round_id);
//Log::info($a->getEndMessage());
return 1;
}
}
//Log::info($a->getEndMessage());
return 0;
}