First version almost done
This commit is contained in:
parent
b5c1f40a45
commit
7a33f5f889
14 changed files with 274 additions and 28 deletions
|
|
@ -23,8 +23,7 @@ class RoundsController extends Controller
|
|||
}
|
||||
|
||||
return view('rounds.index', compact('rounds','activeSeason'));
|
||||
//return view('rounds.index');
|
||||
//return view ('welcome');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -95,7 +94,7 @@ class RoundsController extends Controller
|
|||
// Sign them in
|
||||
|
||||
// Redirect to the home page
|
||||
return redirect()->home();
|
||||
return redirect('/rounds');
|
||||
}
|
||||
|
||||
public function editname($round_id)
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TippController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
128
pfosten/app/Http/Controllers/TippsController.php
Normal file
128
pfosten/app/Http/Controllers/TippsController.php
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Season;
|
||||
use App\Round;
|
||||
use App\Game;
|
||||
use App\Tipp;
|
||||
|
||||
use Auth;
|
||||
use Log;
|
||||
use DB;
|
||||
|
||||
|
||||
class TippsController extends Controller
|
||||
{
|
||||
public function createTipps() {
|
||||
$activeSeason = Season::getCurrent();
|
||||
$user=Auth::user();
|
||||
|
||||
// Log::info($user->id);
|
||||
// Log::info("** Start: createTipps for " . $activeSeason->name . "**");
|
||||
|
||||
$rounds = Round::all()->where('season_id', '=', $activeSeason->id);
|
||||
foreach($rounds as $round) {
|
||||
|
||||
$games=Game::all()->where('round_id','=',$round->id);
|
||||
foreach($games as $game) {
|
||||
|
||||
// Tipp erzeugen wenn noch nicht vorhanden
|
||||
$tipp = DB::table('tipps')->where([
|
||||
['game_id','=',$game->id],
|
||||
['user_id','=',$user->id]]
|
||||
)->first();
|
||||
if (! $tipp) {
|
||||
//Log::info('Creating missing tip: game_id=' . $game->id . ", user_id=" . $user->id);
|
||||
$tipp=Tipp::create([
|
||||
'user_id' => $user->id,
|
||||
'game_id'=> $game->id,
|
||||
'score1'=> -1,
|
||||
'score2'=> -1,
|
||||
'joker'=> false
|
||||
]);
|
||||
$tipp->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$activeSeason = Season::getCurrent();
|
||||
$rounds = null;
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
|
||||
$this->createTipps(); // ggfs. fehlender Tipp Eintraege einfügen
|
||||
|
||||
|
||||
if ($activeSeason) {
|
||||
$activeSeasonId = Season::getCurrent()->id;
|
||||
$rounds = Round::all()->where('season_id', '=', $activeSeasonId);
|
||||
}
|
||||
|
||||
return view('tipps.index', compact('rounds', 'activeSeason', 'user'));
|
||||
}
|
||||
|
||||
|
||||
public function edit($tipp_id) {
|
||||
$tipp = Tipp::where('id','=',$tipp_id)->first();
|
||||
$game = Game::where('id','=',$tipp->game_id)->first();
|
||||
return view('tipps.edit',compact('tipp','game'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function store() {
|
||||
// Validate form
|
||||
$this->validate(request(), [
|
||||
'id' => 'required',
|
||||
'score1' => 'required',
|
||||
'score2' => 'required',
|
||||
'round_id' => 'required'
|
||||
]);
|
||||
|
||||
$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;
|
||||
}
|
||||
$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) {
|
||||
|
||||
$tipp = Tipp::where('user_id',$user->id)->where('game_id',$game->id)->first();
|
||||
|
||||
if ($tipp->id != request('id')) {
|
||||
$tipp->joker=false;
|
||||
$tipp->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to the Rounds Index
|
||||
return redirect('/tipps');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -49,6 +49,8 @@ class UsersController extends Controller
|
|||
public function store() {
|
||||
$season_id = Season::getCurrent()->id;
|
||||
|
||||
|
||||
|
||||
// Validate form
|
||||
$this->validate(request(), [
|
||||
'id' => 'required',
|
||||
|
|
@ -63,13 +65,20 @@ class UsersController extends Controller
|
|||
$user->name=request('name');
|
||||
$user->email=request('email');
|
||||
|
||||
if (request()->has('admin')) { $user->admin=request('admin'); }
|
||||
if (request()->has('admin')) {
|
||||
$user->admin = true;
|
||||
|
||||
} else {
|
||||
$user->admin=false;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
$user->save();
|
||||
|
||||
|
||||
if (request()->has('paid')) {
|
||||
//dd(request('id'), $season_id, request('paid'));
|
||||
Payment::set_payment_date(request('id'), $season_id, request('paid'));
|
||||
}
|
||||
|
||||
|
||||
// Redirect to the home page
|
||||
return redirect('/users');
|
||||
|
|
|
|||
|
|
@ -3,8 +3,47 @@
|
|||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use DB;
|
||||
|
||||
class Tipp extends Model
|
||||
{
|
||||
//
|
||||
protected $fillable = [
|
||||
'id', 'user_id', 'game_id','score1','score2','joker'
|
||||
];
|
||||
|
||||
public static function getTipp($game_id, $user_id) {
|
||||
return DB::table('tipps')->where([
|
||||
['user_id','=',$user_id],
|
||||
['game_id','=',$game_id]
|
||||
])->first();
|
||||
}
|
||||
|
||||
public static function getScore($tipp_id) {
|
||||
$tipp = Tipp::where('id',$tipp_id)->first();
|
||||
$game = Game::where('id',$tipp->game_id)->first();
|
||||
|
||||
$tippTendenz = $tipp->score1 - $tipp->score2;
|
||||
if ($tippTendenz > 0) {$tippTendenz=1;}
|
||||
if ($tippTendenz < 0) {$tippTendenz=-1;}
|
||||
|
||||
$gameTendenz = $game->score1 - $game->score2;
|
||||
if ($gameTendenz<0) {$gameTendenz=-1;}
|
||||
if ($gameTendenz>0) {$gameTendenz=1;}
|
||||
|
||||
$score=0;
|
||||
|
||||
if ($tippTendenz == $gameTendenz) { $score=1; }
|
||||
|
||||
if ( ($tipp->score1 == $game->score1) && ($tipp->score2 == $game->score2) ) {
|
||||
$score=2;
|
||||
}
|
||||
|
||||
if ($tipp->joker==true) {
|
||||
$score = $score *2;
|
||||
}
|
||||
|
||||
if ($game->score1 == -1) { $score=0; }
|
||||
|
||||
return $score;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,9 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'timezone' => 'UTC',
|
||||
/*'timezone' => 'UTC',*/
|
||||
|
||||
'timezone' => 'Europe/Berlin',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ class CreateTippsTable extends Migration
|
|||
{
|
||||
Schema::create('tipps', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('user_id');
|
||||
$table->integer('game_id');
|
||||
$table->boolean('joker');
|
||||
$table->integer('user_id')->hasOne('App\User');
|
||||
$table->integer('game_id')->hasOne('App\Game');
|
||||
$table->integer('score1');
|
||||
$table->integer('score2');
|
||||
$table->boolean('joker')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<footer class="text-muted">
|
||||
<div class="container text-center">
|
||||
<div> </div>
|
||||
|
||||
<div class="container text-center">
|
||||
<p>Anfragen aller Art bitte an Volker Geissler.</p>
|
||||
<p>Tel. 0172xxxxxxx, vg@aol.com</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
@include('layouts.nav')
|
||||
|
||||
<div class="container">
|
||||
<div class="container" width:800px">
|
||||
@yield('content')
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
<a class="lead" href="/seasons">Saison</a>
|
||||
<a class="lead" href="/rounds">Runden</a>
|
||||
<a class="lead" href="/users">Spieler</a>
|
||||
<a class="lead" href="#">Tipps</a>
|
||||
<a class="lead" href="/register" >Rangliste</a>
|
||||
<a class="lead" href="/tipps">Tipps</a>
|
||||
<a class="lead" href="#" >Rangliste</a>
|
||||
|
||||
<label class="lead text ml-auto" >Spieler: {{ Auth::user()->name }}</label><a class="lead" href="/logout">(abmelden)</a>
|
||||
@endif
|
||||
|
|
|
|||
34
pfosten/resources/views/tipps/edit.blade.php
Normal file
34
pfosten/resources/views/tipps/edit.blade.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
@extends('layouts.layout')
|
||||
|
||||
@section('content')
|
||||
<div class="col-md-8">
|
||||
|
||||
<h1>Spieltipp:</h1>
|
||||
|
||||
|
||||
|
||||
<div style="float:left;width:250px" class="lead">{{ $game->team1 }} : {{ $game->team2 }}</div>
|
||||
<div style="float:left;width:150px" >
|
||||
<form method="POST" action="/tipps/store">
|
||||
{{ csrf_field() }}
|
||||
<div class="form-group">
|
||||
|
||||
<input style="float:left; width:50px;" type="text" class="lead" id="name" name="score1" value="{{ $tipp->score1 }}" required>
|
||||
<p style="float:left; width:25px;"> : </p>
|
||||
<input style="float:left; width:50px;" type="text" class="lead" id="name" name="score2" value="{{ $tipp->score2 }}" required>
|
||||
|
||||
<label class="lead">Joker: </label>
|
||||
{{ Form::checkbox('joker', 'yes', $tipp->joker ) }} <!-- name, value, checked -->
|
||||
<input type="hidden" name="id" value="{{ $tipp->id }}">
|
||||
<input type="hidden" name="round_id" value="{{ $game->round_id }}">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
|
||||
<button type="submit" class="btn btn-primary">Ok</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
35
pfosten/resources/views/tipps/index.blade.php
Normal file
35
pfosten/resources/views/tipps/index.blade.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
@extends('layouts.layout')
|
||||
|
||||
@section('content')
|
||||
<section class="jumbotron text-center">
|
||||
<div class="container" style="float:left; width:800px">
|
||||
|
||||
@if ($activeSeason)
|
||||
<label>Saison:{{ $activeSeason->name }}</label>
|
||||
@endif
|
||||
|
||||
<p class="lead">Tipps</p>
|
||||
|
||||
@if ($activeSeason)
|
||||
<div>
|
||||
@foreach($rounds->reverse() as $round)
|
||||
<div><label class="text lead">{{ $round->name }} </label></div>
|
||||
@foreach($round->games as $game)
|
||||
<img src="/img/joker.png" style="{{ (App\Tipp::getTipp($game->id, $user->id)->joker==true ? 'float:left;width:32px;height:32px' : 'display: none;') }}">
|
||||
|
||||
<div style="width:600px"><label class="text" href="/games/edit/{{ $game->id }}">{{ $game->team1 }} : {{ $game->team2 }} [ Anstoss {{ $game->kickoff }} ] </label>
|
||||
<a href="/tipps/edit/{{App\Tipp::getTipp($game->id,$user->id)->id}}">{{ App\Tipp::getTipp($game->id, $user->id)->score1 }} : {{ App\Tipp::getTipp($game->id, $user->id)->score2 }}</a>
|
||||
</div>
|
||||
|
||||
<label style="float:left;width=30px;">{{ App\Tipp::getScore($game->id,$user->id) }}</label>
|
||||
<p> </p>
|
||||
@endforeach
|
||||
<p> </p>
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
</section>
|
||||
@endsection
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
<div>
|
||||
<label style="float:left; width:150px" for="name">Zahlung für Saison:</label>
|
||||
<input style="width:150px" type="text" class="form-control has_datepicker" id="paid" name="paid" value="{{ $paid_date_str }}" >
|
||||
|
||||
</div>
|
||||
<p> </p>
|
||||
<div>
|
||||
|
|
@ -31,7 +32,9 @@
|
|||
<div>
|
||||
<label style="float:left; width:150px;" for="admin">Admin:</label>
|
||||
|
||||
{{ Form::checkbox('admin', 'value', $user->admin ) }}
|
||||
{{ Form::checkbox('admin', 'admin', $user->admin ) }} <!-- name, value, checked -->
|
||||
|
||||
<!-- <input style="width:150px" type="checkbox" class="form-control" id="admin" name="admin" value="{{ $user->admin }}" > -->
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -40,3 +40,7 @@ Route::post('/games/store', 'GamesController@store');
|
|||
Route::get('/users','UsersController@index');
|
||||
Route::get('/users/edit/{user_id}','UsersController@edit');
|
||||
Route::post('/users/store','UsersController@store');
|
||||
|
||||
Route::get('/tipps','TippsController@index');
|
||||
Route::get('/tipps/edit/{tipp_id}','TippsController@edit');
|
||||
Route::post('/tipps/store','TippsController@store');
|
||||
Loading…
Add table
Add a link
Reference in a new issue