tippspiel/pfosten/app/Http/Controllers/RoundsController.php

186 lines
5.1 KiB
PHP
Raw Normal View History

2017-06-20 08:43:36 +02:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Season;
use App\Round;
use App\Game;
2017-06-26 17:21:30 +02:00
use App\User;
use App\Tipp;
use App\Quota;
2017-06-20 08:43:36 +02:00
use DB;
2017-06-26 17:21:30 +02:00
use Auth;
use Log;
use App\MyClasses\TimeLogger;
2017-06-20 08:43:36 +02:00
class RoundsController extends Controller
{
public function index() {
2017-06-26 17:21:30 +02:00
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$a=new TimeLogger("RoundsController::index()");
Log::info($a->getStartMessage());
2017-06-20 08:43:36 +02:00
$activeSeason=Season::getCurrent();
$rounds =null;
if ($activeSeason) {
$activeSeasonId = Season::getCurrent()->id;
$rounds = Round::all()->where('season_id', '=', $activeSeasonId);
}
2017-11-10 15:32:54 +01:00
$quotas = Quota::getQuotas();
$round_count = Round::getCount();
Log::info($a->getEndMessage());
return view('rounds.index', compact('rounds','activeSeason', 'round_count'));
2017-06-22 17:00:09 +02:00
2017-06-20 08:43:36 +02:00
}
public function create() {
2017-06-26 17:21:30 +02:00
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$currentSeason = Season::getCurrent();
if ($currentSeason) {
return view('rounds.create', compact('currentSeason'));
}
redirect()->home()->withErrors('Es muss zuerst eine Saison angelegt werden');
}
public function store() {
2017-06-26 17:21:30 +02:00
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$a=new TimeLogger("RoundsController::store() start");
Log::info($a->getStartMessage());
// Validate form
$this->validate(request(), [
'name' => 'required',
'game1_team1' => 'required',
'game1_team2' => 'required',
'game1_kickoff' => 'required',
'game2_team1' => 'required',
'game2_team2' => 'required',
'game2_kickoff' => 'required',
'game3_team1' => 'required',
'game3_team2' => 'required',
'game3_kickoff' => 'required',
'game4_team1' => 'required',
'game4_team2' => 'required',
'game4_kickoff' => 'required'
]);
$seasonId = Season::getCurrent()->id;
$round = Round::create([
'name' => request('name'),
'season_id' => $seasonId
]);
$round->save();
$round_id = $round->id;
$game1 = Game::create([
'round_id' => $round_id,
'team1' => request('game1_team1'),
'team2' => request('game1_team2'),
2017-06-26 17:21:30 +02:00
'kickoff' => User::toDBDate(request('game1_kickoff'))
]);
$game2 = Game::create([
'round_id' => $round_id,
'team1' => request('game2_team1'),
'team2' => request('game2_team2'),
2017-06-26 17:21:30 +02:00
'kickoff' => User::toDBDate(request('game2_kickoff'))
]);
$game3 = Game::create([
'round_id' => $round_id,
'team1' => request('game3_team1'),
'team2' => request('game3_team2'),
2017-06-26 17:21:30 +02:00
'kickoff' => User::toDBDate(request('game3_kickoff'))
]);
$game4 = Game::create([
'round_id' => $round_id,
'team1' => request('game4_team1'),
'team2' => request('game4_team2'),
2017-06-26 17:21:30 +02:00
'kickoff' => User::toDBDate(request('game4_kickoff'))
]);
// Sign them in
Tipp::createAllTips();
Log::info($a->getEndMessage());
// Redirect to the home page
2017-06-22 17:00:09 +02:00
return redirect('/rounds');
}
public function store_report() {
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$a=new TimeLogger("RoundsController::store_report()");
Log::info($a->getStartMessage());
// Validate form
$this->validate(request(), [
2017-08-01 13:35:34 +02:00
'round_id' => 'required'
]);
$seasonId = Season::getCurrent()->id;
$round = Round::where('id','=',request('round_id'))->first();
//Log::info("Report = ".request("report"));
2017-08-01 13:35:34 +02:00
$round->report="";
if (request("report")){
$round->report = str_replace("\n","<br/>", request("report"));
2017-08-01 13:35:34 +02:00
}
$round->save();
Log::info($a->getEndMessage());
// Redirect to the home page
return redirect('/rounds');
}
public function editname($round_id)
{
$round = Round::where('id', $round_id)->first();
return view('rounds.editname', compact('round'));
}
public function storename()
{
2017-06-26 17:21:30 +02:00
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$a=new TimeLogger("RoundsController::storename()");
Log::info($a->getStartMessage());
// Validate form
$this->validate(request(), [
'round_id' => 'required',
'name' => 'required'
]);
$round = Round::where('id', request('round_id'))->first();
$round->name = request('name');
$round->save();
Log::info($a->getEndMessage());
return redirect('/rounds');
}
2017-06-20 08:43:36 +02:00
}