From 444ce18f63e84ce733aa189ac2ddb95b93a714a6 Mon Sep 17 00:00:00 2001 From: Torsten Date: Wed, 11 Oct 2017 11:14:23 +0200 Subject: [PATCH] Working in Liga Auf/Abstieg --- pfosten/app/Season.php | 7 ++++ pfosten/app/Test.php | 60 ++++++++++++++++++++++++++++++++++ pfosten/app/User.php | 6 ++-- pfosten/app/leagues/League.php | 46 ++++++++++++++++++++++++-- 4 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 pfosten/app/Test.php diff --git a/pfosten/app/Season.php b/pfosten/app/Season.php index 6c70397b..893ab543 100644 --- a/pfosten/app/Season.php +++ b/pfosten/app/Season.php @@ -43,4 +43,11 @@ class Season extends Model $setting->current_season_id=$season_id; $setting->save(); } + + public static function getLast() { + $seasons=Season::where('id','>',0)->orderBy('id','DESC')->get(); + if (sizeof($seasons)<2) { return null; } + return $seasons[1]; + } + } diff --git a/pfosten/app/Test.php b/pfosten/app/Test.php new file mode 100644 index 00000000..0a0854fd --- /dev/null +++ b/pfosten/app/Test.php @@ -0,0 +1,60 @@ +id, $seasonId, '01.01.2017'); + $cnt+=1; + } + return $cnt." Users in season_id ".$seasonId." set to paid"; + } + + public static function fillSeason($seasonId) { + error_log("creating all tipps started"); + Tipp::createAllTips(); + error_log("creating all tipps completed"); + $users = User::all(); + + error_log("setting payment started"); + Test::paySeason($seasonId); + error_log("setting payment completed"); + + + error_log("Users: ".sizeof($users)); + + // Spielergebnisse faken + $rounds=Round::where('season_id','=',$seasonId)->get(); + error_log("Rounds: ".sizeof($rounds)); + foreach ($rounds as $round) { + $games=Game::where('round_id','=',$round->id)->get(); + $jokerSet=false; + error_log("Faking Tipps and game results for all users for: ".$round->name); + foreach ($games as $game) { + $game->score1=random_int(0,3); + $game->score2=random_int(0,3); + $game->save(); + foreach ($users as $user) { + // Tipps faken + $tipp=Tipp::where('game_id','=',$game->id)->where('user_id','=',$user->id)->first(); + $tipp->score1 = random_int(0,3); + $tipp->score2 = random_int(0,3); + if (!$jokerSet) { + $tipp->joker=true; + } + $tipp->save(); + } + $jokerSet=true; + } + } + + } +} diff --git a/pfosten/app/User.php b/pfosten/app/User.php index 48bc1fae..eefafd6e 100644 --- a/pfosten/app/User.php +++ b/pfosten/app/User.php @@ -179,9 +179,11 @@ class User extends Authenticatable // aktiv = hat die Saison bezahlt. - public static function getActives() { + public static function getActives($seasonId=-1) { + $currentSeason=Season::getCurrent(); - $users = User::whereNull('deleted')->get(); + if ($seasonId != -1) { $currentSeason = Season::where('id','=',$seasonId); } + $users = User::all(); $payments = Payment::where('season_id','=',$currentSeason->id)->get(); $payref = array(); diff --git a/pfosten/app/leagues/League.php b/pfosten/app/leagues/League.php index 6dc0b4ea..cccf91a2 100644 --- a/pfosten/app/leagues/League.php +++ b/pfosten/app/leagues/League.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model; use App\Season; use App\Round; +use App\User; use DB; use Log; @@ -66,8 +67,9 @@ class League extends Model return ($score1[1] < $score2[1]); } - public static function getRanking($rank) { + public static function getRanking($rank, $seasonId=-1) { $season = Season::getCurrent(); + if ($seasonId > -1) { $season=Season::where('id','=',$seasonId)->first(); }; $leagues = League::where('rank','=',$rank)->where('season_id','=', $season->id)->orderBy('id')->get(); error_log("LeagueCount:".sizeof($leagues)); @@ -80,7 +82,7 @@ class League extends Model foreach($memberIds as $memberId) { $tpl=array(); $tpl[0]=$memberId; - $tpl[1]=0; + $tpl[1]=0; // league_score $tpl[2]=0; // goals $tpl[3]=0; // countergoals $memberScores[$memberId] = $tpl; @@ -105,4 +107,44 @@ class League extends Model return $leagueScores; } + + + // Aktuelle Liga-Zuordnung auf Basis des Rangs in der letzten Liga + public static function getNewLeagueForPlayers() + { + $lastSeason = Season::getLast(); + $currentSeason = Season::getCurrent(); + + if (!$lastSeason) { + dd("No last season handling implemented. Please fix/implement."); + //TODO: Implement a qualification round + } + + $users = User::getActives(); + $usersLastSeason = User::getActives($lastSeason->id); + + // Wenn der User in den roundTipps der previousSeaoson nicht existiert, nahm er an der Runde nicht + // teil, und ist automatisch Liga 3. + + foreach ($users as $key => $user) { + + $found = false; + foreach ($usersLastSeason as $userLastSeason) { + if ($userLastSeason->id == $user->id) $found = true; + } + + if (!$found) { + $users[$key]['rank']=League::RANK_LEAGUE3; // In der letzten Season unter den Actives nicht gefunden + } else { + // League1, 1-16: RANK_LEAGUE1 + // League1, 17-22: RANK_LEAGUE2 + // League2, 1-6: RANK_LEAGUE1 + // League2, 7-16: RANK_LEAGUE2 + // League2, 17-22: RANK_LEAGUE3 + // League3, best6: RANK_LEAGUE2 + // League3, 7-end: RANK_LEAGUE3 + } + + } + } }