Show joker_impossible even for store4

This commit is contained in:
Torsten Schneider 2021-04-11 23:04:39 +02:00
parent 8a32f41bf4
commit 6b8ae8ad49
3 changed files with 26 additions and 18 deletions

View file

@ -104,6 +104,9 @@ class TippsController extends Controller
public function edit4($round_id) {
$user=Auth::user();
Log::info("TippsController::edit4 for user-id ".$user->id);
Log::info("Multi fetch result for tipps");
$round=Round::where('id','=', $round_id)->first();
$games=Game::where('round_id', '=', $round_id)->get();
@ -131,7 +134,7 @@ class TippsController extends Controller
]);
$user=Auth::user();
Log::info("TippsController::store for user-id ".$user->id);
// Fetch, modify, save Tipp
$tipp = Tipp::where('id', request('id'))->first();
$game = Game::where('id', $tipp->game_id)->first();
@ -262,22 +265,27 @@ class TippsController extends Controller
// If store fails, the jokerlimit has been reached. Redirect to edit4 page
if (self::tryStore($tipp_id_1, $game_id_1, $round_id, $score1_1, $score2_1, $joker_1 ) == false) {
return redirect('/tipps/edit4/'.$round_id);
//return redirect('/tipps/edit4/'.$round_id);
return redirect('/tipps/joker_impossible');
}
// If store fails, the jokerlimit has been reached. Redirect to edit4 page
if (self::tryStore($tipp_id_2, $game_id_2, $round_id, $score1_2, $score2_2, $joker_2) == false) {
return redirect('/tipps/edit4/'.$round_id);
return redirect('/tipps/joker_impossible');
}
// If store fails, the jokerlimit has been reached. Redirect to edit4 page
if (self::tryStore($tipp_id_3, $game_id_3, $round_id, $score1_3, $score2_3, $joker_3 ) == false) {
return redirect('/tipps/edit4/'.$round_id);
return redirect('/tipps/joker_impossible');
}
// If store fails, the jokerlimit has been reached. Redirect to edit4 page
if (self::tryStore($tipp_id_4, $game_id_4, $round_id, $score1_4, $score2_4, $joker_4 ) == false) {
return redirect('/tipps/edit4/'.$round_id);
return redirect('/tipps/joker_impossible');
}
return redirect('/tipps/');
@ -285,11 +293,11 @@ class TippsController extends Controller
// Store tipp if valid.
public function tryStore($tipp_id, $game_id, $round_id, $score1, $score2, $has_joker ) {
error_log("Starting tryStore");
Log::info("Starting tryStore");
$user=Auth::user();
$tipp = Tipp::where('id', $tipp_id)->first();
error_log("tipp_id=".$tipp->id);
Log::info("tipp_id=".$tipp->id);
$game = Game::where('id', $game_id)->first();
$round= Round::where('id',$round_id)->first();
@ -299,27 +307,26 @@ class TippsController extends Controller
if ($tipp->joker) {
$jokertipps=Tipp::getJokerUsageArray($user->id,$round_id);
$key=$tipp->score1.":".$tipp->score2;
//Log::info("Key(Gamescore):".$key);
error_log("Key(Gamescore):".$key);
Log::info("Key(Gamescore):".$key);
if (array_key_exists($key,$jokertipps)) {
//Log::info("Key found in jokertipps array");
$value=$jokertipps[$key];
//Log::info("Stored value:".$value);
Log::info("Stored value:".$value);
$limit=Season::getCurrent()->maxIdenticalJokertipps();
if (intval($value)>=intval($limit)) {
//Log::info("**JOKERLIMIT REACHED FOR GAMESCORE:".$key);
error_log("**JOKERLIMIT REACHED FOR GAMESCORE:".$key);
error_log("Returning false");
Log::info("**JOKERLIMIT REACHED FOR GAMESCORE:".$key);
Log::info("Returning false");
return false; // Returning false should make store4 method return to edit4 page.
}
}
}
Log::info("tryStore: Saving score ".$score1.":".$score2." for user-id ".$user->id);
$tipp->score1=$score1;
$tipp->score2=$score2;
$tipp->joker=$has_joker;
$tipp->save();
error_log("Returning true");
Log::info("Returning true");
return true; // Returning true should make store4 method return to general tipps (index) page.
}

View file

@ -67,8 +67,9 @@
</table>
<!-- 4 in 1 functionality -->
@if (Auth::user()->admin)
@if(App\Round::hasLockedGame($round->id)!=true)
@if(App\Round::hasLockedGame($round->id)!=true)
@if (Auth::user()->admin)
<a href="/tipps/edit4/{{$game->round_id}}">Runde Tippen</a>
@endif
@endif

View file

@ -4,8 +4,8 @@
<section class="jumbotron text-center">
<div class="container">
<h2>Ungültige Tippeingabe: Joker wurde zu oft verwendet.</h2>
<div><a href="/tipps" class="btn btn-primary">Zu den Tipps</a></div>
<h2>Ung&uuml;ltige Tippeingabe: Joker wurde zu oft verwendet.</h2>
<div><a href="/tipps#{{\App\Round::getFirstTippableRoundId()}}" class="btn btn-primary">Zu den Tipps</a></div>
</div>
</section>