4in1 Tipp
This commit is contained in:
parent
bf5af4722c
commit
557050d05f
4 changed files with 285 additions and 2 deletions
|
|
@ -103,6 +103,24 @@ class TippsController extends Controller
|
||||||
return view('tipps.edit',compact('tipp','game'));
|
return view('tipps.edit',compact('tipp','game'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function edit4($round_id) {
|
||||||
|
$user=Auth::user();
|
||||||
|
Log::info("Multi fetch result for tipps");
|
||||||
|
$round=Round::where('id','=', $round_id)->first();
|
||||||
|
$games=Game::where('round_id', '=', $round_id)->get();
|
||||||
|
|
||||||
|
$tipps=Tipp::whereIn('game_id', [$games[0]->id, $games[1]->id, $games[2]->id, $games[3]->id])->where('user_id',$user->id)->get();
|
||||||
|
|
||||||
|
$tipp1=$tipps[0];
|
||||||
|
$game1=Game::where('id','=',$tipp1->game_id)->first();
|
||||||
|
$tipp2=$tipps[1];
|
||||||
|
$game2=Game::where('id','=',$tipp2->game_id)->first();
|
||||||
|
$tipp3=$tipps[2];
|
||||||
|
$game3=Game::where('id','=',$tipp3->game_id)->first();
|
||||||
|
$tipp4=$tipps[3];
|
||||||
|
$game4=Game::where('id','=',$tipp4->game_id)->first();
|
||||||
|
return view('tipps.edit4',compact('round','tipp1','tipp2','tipp3','tipp4', 'game1', 'game2', 'game3', 'game4'));
|
||||||
|
}
|
||||||
|
|
||||||
public function store() {
|
public function store() {
|
||||||
// Validate form
|
// Validate form
|
||||||
|
|
@ -151,7 +169,6 @@ class TippsController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$tipp->save();
|
$tipp->save();
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -184,6 +201,131 @@ class TippsController extends Controller
|
||||||
return redirect($tippLink);
|
return redirect($tippLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to store all 4 tipps of the round one by one.
|
||||||
|
// If one fails, previous saves are kept, but user
|
||||||
|
// is redirected to edit4 page again.
|
||||||
|
public function store4() {
|
||||||
|
// Validate form
|
||||||
|
$this->validate(request(), [
|
||||||
|
'round_id' => 'required',
|
||||||
|
'game_id_1' => 'required',
|
||||||
|
'game_id_2' => 'required',
|
||||||
|
'game_id_3' => 'required',
|
||||||
|
'game_id_4' => 'required',
|
||||||
|
'tipp_id_1' => 'required',
|
||||||
|
'tipp_id_2' => 'required',
|
||||||
|
'tipp_id_3' => 'required',
|
||||||
|
'tipp_id_4' => 'required',
|
||||||
|
'score1_1' => 'required',
|
||||||
|
'score1_2' => 'required',
|
||||||
|
'score1_3' => 'required',
|
||||||
|
'score1_4' => 'required',
|
||||||
|
'score2_1' => 'required',
|
||||||
|
'score2_2' => 'required',
|
||||||
|
'score2_3' => 'required',
|
||||||
|
'score2_4' => 'required',
|
||||||
|
'round_id' => 'required'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$round_id= request('round_id');
|
||||||
|
$game_id_1=request('game_id_1');
|
||||||
|
$game_id_2=request('game_id_2');
|
||||||
|
$game_id_3=request('game_id_3');
|
||||||
|
$game_id_4=request('game_id_4');
|
||||||
|
$tipp_id_1=request('tipp_id_1');
|
||||||
|
$tipp_id_2=request('tipp_id_2');
|
||||||
|
$tipp_id_3=request('tipp_id_3');
|
||||||
|
$tipp_id_4=request('tipp_id_4');
|
||||||
|
$score1_1=request('score1_1');
|
||||||
|
$score1_2=request('score1_2');
|
||||||
|
$score1_3=request('score1_3');
|
||||||
|
$score1_4=request('score1_4');
|
||||||
|
$score2_1=request('score2_1');
|
||||||
|
$score2_2=request('score2_2');
|
||||||
|
$score2_3=request('score2_3');
|
||||||
|
$score2_4=request('score2_4');
|
||||||
|
|
||||||
|
$joker_1=false;
|
||||||
|
$joker_2=false;
|
||||||
|
$joker_3=false;
|
||||||
|
$joker_4=false;
|
||||||
|
|
||||||
|
|
||||||
|
if (request()->has('joker_1')) {
|
||||||
|
$joker_1=true;
|
||||||
|
} elseif (request()->has('joker_2')) {
|
||||||
|
$joker_2=true;
|
||||||
|
} elseif (request()->has('joker_3')) {
|
||||||
|
$joker_3=true;
|
||||||
|
} elseif (request()->has('joker_4')) {
|
||||||
|
$joker_4=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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/');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store tipp if valid.
|
||||||
|
public function tryStore($tipp_id, $game_id, $round_id, $score1, $score2, $has_joker ) {
|
||||||
|
error_log("Starting tryStore");
|
||||||
|
$user=Auth::user();
|
||||||
|
|
||||||
|
$tipp = Tipp::where('id', $tipp_id)->first();
|
||||||
|
error_log("tipp_id=".$tipp->id);
|
||||||
|
$game = Game::where('id', $game_id)->first();
|
||||||
|
$round= Round::where('id',$round_id)->first();
|
||||||
|
|
||||||
|
$tipp->joker=$has_joker;
|
||||||
|
|
||||||
|
// Neuerung 2020-01-09: Joker nur speichern, wenn Ergebnis nicht schon zu oft "gejokert" wurde.
|
||||||
|
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);
|
||||||
|
if (array_key_exists($key,$jokertipps)) {
|
||||||
|
//Log::info("Key found in jokertipps array");
|
||||||
|
|
||||||
|
$value=$jokertipps[$key];
|
||||||
|
//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");
|
||||||
|
return false; // Returning false should make store4 method return to edit4 page.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$tipp->score1=$score1;
|
||||||
|
$tipp->score2=$score2;
|
||||||
|
$tipp->joker=$has_joker;
|
||||||
|
$tipp->save();
|
||||||
|
error_log("Returning true");
|
||||||
|
return true; // Returning true should make store4 method return to general tipps (index) page.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// belongs to old single tipp functionality.
|
||||||
public static function joker_impossible() {
|
public static function joker_impossible() {
|
||||||
return view('tipps.joker_impossible');
|
return view('tipps.joker_impossible');
|
||||||
|
|
||||||
|
|
|
||||||
126
pfosten/resources/views/tipps/edit4.blade.php
Normal file
126
pfosten/resources/views/tipps/edit4.blade.php
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
@extends('layouts.layout')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<h1>{{$round->name}}</h1>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
|
||||||
|
<div >
|
||||||
|
<form method="POST" action="/tipps/store4">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<!-- 1 -->
|
||||||
|
<div>
|
||||||
|
<h3>
|
||||||
|
<span style="float:left; width:200px;">{{ $game1->team1 }} : </span>
|
||||||
|
<span style="float:left; width:200px;">{{ $game1->team2 }}</span>
|
||||||
|
|
||||||
|
<input style="float:left; width:50px;" type="text" class="lead" id="" name="score1_1" value="{{ $tipp1->score1==-1? '': $tipp1->score1 }}" required>
|
||||||
|
<p style="float:left; width:25px;"> : </p>
|
||||||
|
<input style="float:left; width:50px;" type="text" class="lead" id="" name="score2_1" value="{{ $tipp1->score2==-1? '': $tipp1->score2 }}" required>
|
||||||
|
<label class="lead" style="float:left; width:50px;"> Joker </label>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span >
|
||||||
|
@if (App\Round::hasLockedGame($game1->round_id))
|
||||||
|
{{ Form::checkbox('joker', 'yes', $tipp1->joker, array('disabled') ) }} <!-- name, value, checked -->
|
||||||
|
@else
|
||||||
|
{{ Form::checkbox('joker', 'yes', $tipp1->joker) }} <!-- name, value, checked -->
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
|
<input type="hidden" name="tipp_id_1" value="{{ $tipp1->id }}">
|
||||||
|
<input type="hidden" name="game_id_1" value="{{ $game1->id }}">
|
||||||
|
<!-- round_id is the same for all 4 games. -->
|
||||||
|
<input type="hidden" name="round_id" value="{{ $game1->round_id }}">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 2 -->
|
||||||
|
|
||||||
|
<h1> </h1>
|
||||||
|
<div>
|
||||||
|
<h3>
|
||||||
|
<span style="float:left; width:200px;">{{ $game2->team1 }} : </span>
|
||||||
|
<span style="float:left; width:200px;">{{ $game2->team2 }}</span>
|
||||||
|
|
||||||
|
<input style="float:left; width:50px;" type="text" class="lead" id="" name="score1_2" value="{{ $tipp2->score1==-1? '': $tipp2->score1 }}" required>
|
||||||
|
<p style="float:left; width:25px;"> : </p>
|
||||||
|
<input style="float:left; width:50px;" type="text" class="lead" id="" name="score2_2" value="{{ $tipp2->score2==-1? '': $tipp2->score2 }}" required>
|
||||||
|
<label class="lead" style="float:left; width:50px;"> Joker </label>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span >
|
||||||
|
@if (App\Round::hasLockedGame($game2->round_id))
|
||||||
|
{{ Form::checkbox('joker', 'yes', $tipp2->joker, array('disabled') ) }} <!-- name, value, checked -->
|
||||||
|
@else
|
||||||
|
{{ Form::checkbox('joker', 'yes', $tipp2->joker) }} <!-- name, value, checked -->
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
|
<input type="hidden" name="tipp_id_2" value="{{ $tipp2->id }}">
|
||||||
|
<input type="hidden" name="game_id_2" value="{{ $game2->id }}">
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 3 -->
|
||||||
|
<h1> </h1>
|
||||||
|
<div>
|
||||||
|
<h3>
|
||||||
|
<span style="float:left; width:200px;">{{ $game3->team1 }} : </span>
|
||||||
|
<span style="float:left; width:200px;">{{ $game3->team2 }}</span>
|
||||||
|
|
||||||
|
<input style="float:left; width:50px;" type="text" class="lead" id="" name="score1_3" value="{{ $tipp3->score1==-1? '': $tipp3->score1 }}" required>
|
||||||
|
<p style="float:left; width:25px;"> : </p>
|
||||||
|
<input style="float:left; width:50px;" type="text" class="lead" id="" name="score2_3" value="{{ $tipp3->score2==-1? '': $tipp3->score2 }}" required>
|
||||||
|
<label class="lead" style="float:left; width:50px;"> Joker </label>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span >
|
||||||
|
@if (App\Round::hasLockedGame($game3->round_id))
|
||||||
|
{{ Form::checkbox('joker', 'yes', $tipp3->joker, array('disabled') ) }} <!-- name, value, checked -->
|
||||||
|
@else
|
||||||
|
{{ Form::checkbox('joker', 'yes', $tipp3->joker) }} <!-- name, value, checked -->
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
|
<input type="hidden" name="tipp_id_3" value="{{ $tipp3->id }}">
|
||||||
|
<input type="hidden" name="game_id_3" value="{{ $game3->id }}">
|
||||||
|
|
||||||
|
<!-- 4 -->
|
||||||
|
<h1> </h1>
|
||||||
|
<div>
|
||||||
|
<h3>
|
||||||
|
<span style="float:left; width:200px;">{{ $game4->team1 }} : </span>
|
||||||
|
<span style="float:left; width:200px;">{{ $game4->team2 }}</span>
|
||||||
|
|
||||||
|
<input style="float:left; width:50px;" type="text" class="lead" id="" name="score1_4" value="{{ $tipp4->score1==-1? '': $tipp4->score1 }}" required>
|
||||||
|
<p style="float:left; width:25px;"> : </p>
|
||||||
|
<input style="float:left; width:50px;" type="text" class="lead" id="" name="score2_4" value="{{ $tipp4->score2==-1? '': $tipp4->score2 }}" required>
|
||||||
|
<label class="lead" style="float:left; width:50px;"> Joker </label>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span >
|
||||||
|
@if (App\Round::hasLockedGame($game4->round_id))
|
||||||
|
{{ Form::checkbox('joker', 'yes', $tipp4->joker, array('disabled') ) }} <!-- name, value, checked -->
|
||||||
|
@else
|
||||||
|
{{ Form::checkbox('joker', 'yes', $tipp4->joker) }} <!-- name, value, checked -->
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
|
<input type="hidden" name="tipp_id_4" value="{{ $tipp4->id }}">
|
||||||
|
<input type="hidden" name="game_id_4" value="{{ $game4->id }}">
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<p> </p>
|
||||||
|
<button type="submit" class="btn btn-primary">Ok</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
@ -66,6 +66,14 @@
|
||||||
@endforeach
|
@endforeach
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<!-- 4 in 1 functionality -->
|
||||||
|
@if (Auth::user()->admin)
|
||||||
|
@if(App\Round::hasLockedGame($round->id)!=true)
|
||||||
|
<a href="/tipps/edit4/{{$game->round_id}}">Runde Tippen</a>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<p> </p>
|
<p> </p>
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,15 @@ Route::get('/users/payout/{user_id}','UsersController@money_ranking_detail');
|
||||||
|
|
||||||
Route::get('/tipps','TippsController@index');
|
Route::get('/tipps','TippsController@index');
|
||||||
Route::get('/tipps/joker_impossible','TippsController@joker_impossible');
|
Route::get('/tipps/joker_impossible','TippsController@joker_impossible');
|
||||||
Route::get('/tipps/edit/{tipp_id}','TippsController@edit');
|
|
||||||
Route::post('/tipps/store','TippsController@store');
|
Route::post('/tipps/store','TippsController@store');
|
||||||
|
Route::get('/tipps/edit/{tipp_id}','TippsController@edit');
|
||||||
|
|
||||||
|
|
||||||
|
// New routes start
|
||||||
|
Route::get('/tipps/edit4/{round_id}','TippsController@edit4');
|
||||||
|
Route::post('/tipps/store4','TippsController@store4');
|
||||||
|
// New routes end
|
||||||
|
|
||||||
|
|
||||||
Route::get('/email','UsersController@mailtest');
|
Route::get('/email','UsersController@mailtest');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue