Rangliste almost done
This commit is contained in:
parent
12651fc2e8
commit
43fd8c8cbf
579 changed files with 172489 additions and 127 deletions
|
|
@ -5,18 +5,21 @@ namespace App\Http\Controllers;
|
|||
use Illuminate\Http\Request;
|
||||
use App\Game;
|
||||
use Carbon\Carbon;
|
||||
use Auth;
|
||||
use App\User;
|
||||
|
||||
class GamesController extends Controller
|
||||
{
|
||||
public function edit($game_id) {
|
||||
if (Auth::guest()) { return redirect("/login"); }
|
||||
$game=Game::where('id',$game_id)->first();
|
||||
//$testdate=str_replace(' UTC ','T',date('Y-m-d h:m'));
|
||||
|
||||
return view('games.edit',compact('game'));
|
||||
$kickoff_german = User::toGermanDate($game->kickoff);
|
||||
return view('games.edit',compact('game','kickoff_german'));
|
||||
}
|
||||
|
||||
public function store() {
|
||||
|
||||
if (Auth::guest()) { return redirect("/login"); }
|
||||
// Validate form
|
||||
$this->validate(request(), [
|
||||
'id' => 'required',
|
||||
|
|
@ -33,7 +36,7 @@ class GamesController extends Controller
|
|||
$game->team2 = request('team2');
|
||||
$game->score1= request('score1');
|
||||
$game->score2= request('score2');
|
||||
$game->kickoff=request('kickoff');
|
||||
$game->kickoff=User::toDBDate(request('kickoff'));
|
||||
$game->save();
|
||||
|
||||
// Redirect to the Rounds Index
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|||
use Illuminate\Http\Request;
|
||||
|
||||
use App\User;
|
||||
use Log;
|
||||
|
||||
class RegistrationController extends Controller
|
||||
{
|
||||
|
|
@ -18,6 +19,7 @@ class RegistrationController extends Controller
|
|||
// Validate form
|
||||
$this->validate(request(), [
|
||||
'name' => 'required',
|
||||
'fullname' => 'required',
|
||||
'email' => 'required|email',
|
||||
'password' => 'required|confirmed'
|
||||
|
||||
|
|
@ -27,9 +29,18 @@ class RegistrationController extends Controller
|
|||
//$user = User::create(request(['name','email','password']));
|
||||
$user = User::create([
|
||||
'name' => request('name'),
|
||||
'fullname' => request('fullname'),
|
||||
'email'=> request('email'),
|
||||
'password' => bcrypt(request('password'))]);
|
||||
// Sign them in
|
||||
|
||||
// First user is made admin automatically
|
||||
Log::info("User count:" . User::all()->count());
|
||||
if (User::all()->count()==1) {
|
||||
$user->admin = true;
|
||||
}
|
||||
$user->save();
|
||||
|
||||
auth()->login($user);
|
||||
|
||||
// Redirect to the home page
|
||||
|
|
|
|||
|
|
@ -6,11 +6,16 @@ use Illuminate\Http\Request;
|
|||
use App\Season;
|
||||
use App\Round;
|
||||
use App\Game;
|
||||
use App\User;
|
||||
use DB;
|
||||
use Auth;
|
||||
|
||||
class RoundsController extends Controller
|
||||
{
|
||||
public function index() {
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
$activeSeason=Season::getCurrent();
|
||||
$rounds =null;
|
||||
|
||||
|
|
@ -28,6 +33,9 @@ class RoundsController extends Controller
|
|||
|
||||
|
||||
public function create() {
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
$currentSeason = Season::getCurrent();
|
||||
if ($currentSeason) {
|
||||
return view('rounds.create', compact('currentSeason'));
|
||||
|
|
@ -37,6 +45,8 @@ class RoundsController extends Controller
|
|||
|
||||
|
||||
public function store() {
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
// Validate form
|
||||
$this->validate(request(), [
|
||||
|
|
@ -68,28 +78,28 @@ class RoundsController extends Controller
|
|||
'round_id' => $round_id,
|
||||
'team1' => request('game1_team1'),
|
||||
'team2' => request('game1_team2'),
|
||||
'kickoff' => request('game1_kickoff')
|
||||
'kickoff' => User::toDBDate(request('game1_kickoff'))
|
||||
]);
|
||||
|
||||
$game2 = Game::create([
|
||||
'round_id' => $round_id,
|
||||
'team1' => request('game2_team1'),
|
||||
'team2' => request('game2_team2'),
|
||||
'kickoff' => request('game2_kickoff')
|
||||
'kickoff' => User::toDBDate(request('game2_kickoff'))
|
||||
]);
|
||||
|
||||
$game3 = Game::create([
|
||||
'round_id' => $round_id,
|
||||
'team1' => request('game3_team1'),
|
||||
'team2' => request('game3_team2'),
|
||||
'kickoff' => request('game3_kickoff')
|
||||
'kickoff' => User::toDBDate(request('game3_kickoff'))
|
||||
]);
|
||||
|
||||
$game4 = Game::create([
|
||||
'round_id' => $round_id,
|
||||
'team1' => request('game4_team1'),
|
||||
'team2' => request('game4_team2'),
|
||||
'kickoff' => request('game4_kickoff')
|
||||
'kickoff' => User::toDBDate(request('game4_kickoff'))
|
||||
]);
|
||||
// Sign them in
|
||||
|
||||
|
|
@ -105,6 +115,9 @@ class RoundsController extends Controller
|
|||
|
||||
public function storename()
|
||||
{
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
// Validate form
|
||||
$this->validate(request(), [
|
||||
'round_id' => 'required',
|
||||
|
|
|
|||
|
|
@ -5,10 +5,15 @@ namespace App\Http\Controllers;
|
|||
use Illuminate\Http\Request;
|
||||
use App\Season;
|
||||
use DB;
|
||||
use Auth;
|
||||
use Log;
|
||||
|
||||
class SeasonsController extends Controller
|
||||
{
|
||||
public function index() {
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
$seasons = DB::table('seasons')->get();
|
||||
$activeSeason=Season::getCurrent();
|
||||
return view('seasons.index', compact('seasons','activeSeason'));
|
||||
|
|
@ -16,11 +21,15 @@ class SeasonsController extends Controller
|
|||
|
||||
|
||||
public function create() {
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
return view('seasons.create');
|
||||
}
|
||||
|
||||
public function store() {
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
// Validate form
|
||||
$this->validate(request(), [
|
||||
|
|
@ -33,9 +42,23 @@ class SeasonsController extends Controller
|
|||
'name' => request('name')
|
||||
]);
|
||||
|
||||
if (Season::all()->count()==1) {
|
||||
Season::setCurrent($season->id);
|
||||
Log::info('Setting season id=' .$season->id);
|
||||
}
|
||||
|
||||
|
||||
// Redirect to the home page
|
||||
return redirect('/seasons');
|
||||
}
|
||||
|
||||
|
||||
public function setcurrent($new_season_id) {
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
Season::setCurrent($new_season_id);
|
||||
return redirect("/seasons");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,6 @@ class SessionsController extends Controller
|
|||
public function store() {
|
||||
// Attempt to authenticate the user
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!auth()->attempt(request(['name','password']))) {
|
||||
return back()->withErrors(['message'=>'Bitte Logindaten prüfen und nochmal versuchen.']);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -6,15 +6,25 @@ use Illuminate\Http\Request;
|
|||
use App\User;
|
||||
use App\Season;
|
||||
use App\Payment;
|
||||
use App\Round;
|
||||
use App\Game;
|
||||
use App\Tipp;
|
||||
use DB;
|
||||
use Auth;
|
||||
use Log;
|
||||
|
||||
class UsersController extends Controller
|
||||
{
|
||||
public function main() {
|
||||
|
||||
|
||||
return view('main');
|
||||
}
|
||||
|
||||
public function index() {
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
$users = DB::table('users')->where('deleted',null)->get();
|
||||
return view('users.index', compact('users'));
|
||||
}
|
||||
|
|
@ -36,17 +46,25 @@ class UsersController extends Controller
|
|||
|
||||
|
||||
public function edit($user_id) {
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
if (!Auth::user()->admin) { return redirect("/"); }
|
||||
|
||||
$user = User::where('id',$user_id)->first();
|
||||
$season_id = Season::getCurrent()->id;
|
||||
|
||||
$paid_date_str="";
|
||||
$val=User::payment_date($user_id, $season_id);
|
||||
if ($val) { $paid_date_str=$val;}
|
||||
Log::info("UserController:edit => payment_date=".$val);
|
||||
|
||||
if ($val) { $paid_date_str=User::toGermanDate($val);}
|
||||
Log::info("German Date=".$paid_date_str);
|
||||
|
||||
return view ('users.edit', compact('user','paid_date_str'));
|
||||
}
|
||||
|
||||
public function store() {
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
|
||||
$season_id = Season::getCurrent()->id;
|
||||
|
||||
|
||||
|
|
@ -55,14 +73,16 @@ class UsersController extends Controller
|
|||
$this->validate(request(), [
|
||||
'id' => 'required',
|
||||
'name' => 'required',
|
||||
'fullname' => 'required',
|
||||
'email'=> 'required'
|
||||
]);
|
||||
|
||||
// Create and save the season
|
||||
|
||||
|
||||
$user=User::where('id', request('id'))->first();
|
||||
|
||||
$user->name=request('name');
|
||||
$user->fullname=request('fullname');
|
||||
$user->email=request('email');
|
||||
|
||||
if (request()->has('admin')) {
|
||||
|
|
@ -72,6 +92,8 @@ class UsersController extends Controller
|
|||
$user->admin=false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
$user->save();
|
||||
|
|
@ -84,10 +106,77 @@ class UsersController extends Controller
|
|||
return redirect('/users');
|
||||
}
|
||||
|
||||
public function ranking() {
|
||||
|
||||
|
||||
public function ranking($round_id) {
|
||||
$currentSeason=Season::getCurrent();
|
||||
if (!$currentSeason) { return redirect("/"); }
|
||||
|
||||
if($round_id==-1) {
|
||||
$round_id = Round::getLastCompleteRoundId();
|
||||
//Log::info("Last complete round id=" . $round_id);
|
||||
if ($round_id==-1) {return redirect("/");}
|
||||
}
|
||||
|
||||
if (Auth::guest()) { return redirect("/"); }
|
||||
|
||||
|
||||
|
||||
|
||||
TippsController::createAllTips();
|
||||
|
||||
$users = DB::table('users')->where('deleted',null)->get();
|
||||
return view('users.ranking', compact('users'));
|
||||
|
||||
foreach($users as $user) {
|
||||
$user->totalScore=0;
|
||||
$user->dayScore=0;
|
||||
}
|
||||
|
||||
$rounds=Round::where([['season_id','=',$currentSeason->id],['id','<=',$round_id]])->orderBy('id')->get();
|
||||
|
||||
foreach($rounds as $round) {
|
||||
$games=Game::where('round_id','=',$round->id)->orderBy('id')->get();
|
||||
$index=0;
|
||||
foreach($games as $game) {
|
||||
foreach($users as $user) {
|
||||
$tipp = Tipp::where('game_id','=',$game->id)->where('user_id','=',$user->id)->first();
|
||||
if ($tipp) {
|
||||
$score = Tipp::getScoreLocal($game->score1,$game->score2,$tipp->score1,$tipp->score2,$tipp->joker);
|
||||
$user->totalScore += $score;
|
||||
|
||||
|
||||
if ($game->round_id == $round_id) {
|
||||
$user->dayScore += $score;
|
||||
}
|
||||
|
||||
//if ($user->id==3 && $score>0) { Log::info("Adding score=" . $score. "from game_id=".$game->id."(".$game->team1." - ".$game->team2.", ".$round->name.") totalScore=".$user->totalScore.", dayScore=".$user->dayScore); }
|
||||
|
||||
$tippDisplay[$user->id][$game->id][0] = $tipp->score1 ==-1 ? 'x' : $tipp->score1;
|
||||
$tippDisplay[$user->id][$game->id][1] = $tipp->score2 ==-1 ? 'x' : $tipp->score2;
|
||||
$tippDisplay[$user->id][$game->id][2] = $tipp->joker;
|
||||
}
|
||||
|
||||
}
|
||||
$index+=1;
|
||||
}
|
||||
}
|
||||
|
||||
$arr=[];
|
||||
foreach($users as $user) {
|
||||
array_push($arr, $user);
|
||||
}
|
||||
usort($arr, array($this,"cmp"));
|
||||
$users=$arr;
|
||||
|
||||
$round=Round::where('id','=',$round_id)->first();
|
||||
$games=Game::where('round_id','=',$round->id)->get();
|
||||
|
||||
return view('users.ranking', compact('users','round','games','tippDisplay'));
|
||||
|
||||
}
|
||||
|
||||
public function cmp($user1, $user2) {
|
||||
return ($user1->totalScore < $user2->totalScore);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue