Rangliste almost done

This commit is contained in:
Torsten 2017-06-26 17:21:30 +02:00
parent 12651fc2e8
commit 43fd8c8cbf
579 changed files with 172489 additions and 127 deletions

View file

@ -7,6 +7,7 @@ use App\Season;
use App\Round;
use App\Game;
use App\Tipp;
use App\User;
use Auth;
use Log;
@ -55,10 +56,24 @@ class TippsController extends Controller
public function index()
{
if (Auth::guest()) { return redirect("/"); }
$user = Auth::user();
$activeSeason = Season::getCurrent();
if (!$activeSeason) {
return redirect('/');
}
if (! User::payment_date($user->id, $activeSeason->id)) {
return view('users.no_payment');
}
$rounds = null;
$user = Auth::user();
TippsController::createTipps($user->id); // ggfs. fehlender Tipp Eintraege einfügen
@ -93,33 +108,39 @@ class TippsController extends Controller
$user=Auth::user();
// Fetch, modify, save Tipp
$tipp = Tipp::where('id', request('id'))->first();
$tipp->score1= request('score1');
$tipp->score2= request('score2');
if (request()->has('joker')) {
$tipp->joker=true;
} else {
$tipp->joker=false;
if (Round::hasLockedGame(request('round_id'))==false) { // Jokermod nur wenn Runde noch nicht begonnen hat
$tipp->joker=true;
} else {
$tipp->joker = false;
}
}
$tipp->save();
// Joker gesetzt ? Dann Jokerflag für alle Tipps der selben Runde entfernen
if ($tipp->joker){
$games = DB::table('games')->where('round_id','=',request('round_id'))->get();
foreach($games as $game) {
Log::info("Checking for joker strip");
$game=Game::where('id','=',$tipp->game_id)->first();
$round_id=$game->round_id;
$tipp = Tipp::where('user_id',$user->id)->where('game_id',$game->id)->first();
$games = DB::table('games')->where('round_id', '=', request('round_id'))->get();
foreach ($games as $game) {
$tipp = Tipp::where('user_id', $user->id)->where('game_id', $game->id)->first();
Log::info("Testing game_id " . $game->id);
if ($tipp->id != request('id')) {
$tipp->joker=false;
Log::info("Resetting game_id " . $game->id);
$tipp->joker = false;
$tipp->save();
}
}
}
// Redirect to the Rounds Index