2017-06-20 08:43:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use App\Season;
|
|
|
|
|
use App\Round;
|
2017-06-21 17:12:07 +02:00
|
|
|
use App\Game;
|
2017-06-26 17:21:30 +02:00
|
|
|
use App\User;
|
2017-08-24 11:47:16 +02:00
|
|
|
use App\Tipp;
|
2017-08-30 14:52:21 +02:00
|
|
|
use App\Quota;
|
2017-06-20 08:43:36 +02:00
|
|
|
use DB;
|
2017-06-26 17:21:30 +02:00
|
|
|
use Auth;
|
2017-07-25 17:10:45 +02:00
|
|
|
use Log;
|
2018-08-17 17:16:01 +02:00
|
|
|
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("/"); }
|
|
|
|
|
|
2018-08-17 17:16:01 +02:00
|
|
|
$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();
|
2017-08-30 14:52:21 +02:00
|
|
|
|
2018-08-17 17:16:01 +02:00
|
|
|
Log::info($a->getEndMessage());
|
|
|
|
|
|
2017-08-30 14:52:21 +02:00
|
|
|
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
|
|
|
}
|
2017-06-21 17:12:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public function create() {
|
2017-06-26 17:21:30 +02:00
|
|
|
if (Auth::guest()) { return redirect("/"); }
|
|
|
|
|
if (!Auth::user()->admin) { return redirect("/"); }
|
|
|
|
|
|
2017-06-21 17:12:07 +02:00
|
|
|
$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("/"); }
|
2017-06-21 17:12:07 +02:00
|
|
|
|
2018-08-17 17:16:01 +02:00
|
|
|
$a=new TimeLogger("RoundsController::store() start");
|
|
|
|
|
Log::info($a->getStartMessage());
|
|
|
|
|
|
2017-06-21 17:12:07 +02:00
|
|
|
// 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'))
|
2017-06-21 17:12:07 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$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'))
|
2017-06-21 17:12:07 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$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'))
|
2017-06-21 17:12:07 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$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'))
|
2017-06-21 17:12:07 +02:00
|
|
|
]);
|
|
|
|
|
// Sign them in
|
|
|
|
|
|
2017-08-24 11:47:16 +02:00
|
|
|
Tipp::createAllTips();
|
|
|
|
|
|
2018-08-17 17:16:01 +02:00
|
|
|
Log::info($a->getEndMessage());
|
|
|
|
|
|
2017-06-21 17:12:07 +02:00
|
|
|
// Redirect to the home page
|
2017-06-22 17:00:09 +02:00
|
|
|
return redirect('/rounds');
|
2017-06-21 17:12:07 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-25 17:10:45 +02:00
|
|
|
public function store_report() {
|
|
|
|
|
if (Auth::guest()) { return redirect("/"); }
|
|
|
|
|
if (!Auth::user()->admin) { return redirect("/"); }
|
|
|
|
|
|
2018-08-17 17:16:01 +02:00
|
|
|
$a=new TimeLogger("RoundsController::store_report()");
|
|
|
|
|
Log::info($a->getStartMessage());
|
|
|
|
|
|
2017-07-25 17:10:45 +02:00
|
|
|
// Validate form
|
|
|
|
|
$this->validate(request(), [
|
2017-08-01 13:35:34 +02:00
|
|
|
'round_id' => 'required'
|
2017-07-25 17:10:45 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$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")){
|
2017-08-19 16:53:39 +02:00
|
|
|
$round->report = str_replace("\n","<br/>", request("report"));
|
2017-08-01 13:35:34 +02:00
|
|
|
}
|
2017-07-25 17:10:45 +02:00
|
|
|
$round->save();
|
|
|
|
|
|
2018-08-17 17:16:01 +02:00
|
|
|
Log::info($a->getEndMessage());
|
2017-07-25 17:10:45 +02:00
|
|
|
|
|
|
|
|
// Redirect to the home page
|
|
|
|
|
return redirect('/rounds');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-06-21 17:12:07 +02:00
|
|
|
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("/"); }
|
|
|
|
|
|
2018-08-17 17:16:01 +02:00
|
|
|
$a=new TimeLogger("RoundsController::storename()");
|
|
|
|
|
Log::info($a->getStartMessage());
|
|
|
|
|
|
2017-06-21 17:12:07 +02:00
|
|
|
// Validate form
|
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
'round_id' => 'required',
|
|
|
|
|
'name' => 'required'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$round = Round::where('id', request('round_id'))->first();
|
|
|
|
|
$round->name = request('name');
|
|
|
|
|
$round->save();
|
|
|
|
|
|
2018-08-17 17:16:01 +02:00
|
|
|
Log::info($a->getEndMessage());
|
|
|
|
|
|
2017-06-21 17:12:07 +02:00
|
|
|
return redirect('/rounds');
|
|
|
|
|
}
|
2017-06-20 08:43:36 +02:00
|
|
|
}
|