198 lines
No EOL
6.5 KiB
PHP
198 lines
No EOL
6.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Season;
|
|
use App\Round;
|
|
use App\Quota;
|
|
use App\User;
|
|
use App\Game;
|
|
use App\Tipp;
|
|
use Carbon;
|
|
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();
|
|
$currentSeason=Season::getCurrent();
|
|
$users = User::getActives();
|
|
$active_user_count = sizeof( $users );
|
|
|
|
$currentSeasonId=-1;
|
|
if ($currentSeason) {
|
|
$quotas = Quota::getQuotasForDisplay();
|
|
$payouts = Quota::getPayouts();
|
|
}
|
|
|
|
return view('seasons.index', compact('seasons','currentSeason','active_user_count','quotas','payouts', 'users'));
|
|
}
|
|
|
|
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(), [
|
|
'name' => 'required',
|
|
'roundcount' => 'required'
|
|
]);
|
|
|
|
// Create and save the season
|
|
|
|
$season = Season::create([
|
|
'name' => request('name'),
|
|
'rounds' => request('roundcount')
|
|
]);
|
|
$season->save();
|
|
Season::setCurrent($season->id);
|
|
Log::info('Setting season id=' .$season->id);
|
|
|
|
Quota::createDefaultQuota();
|
|
|
|
$nr=1;
|
|
$roundcount=request('roundcount');
|
|
$seasonId = Season::getCurrent()->id;
|
|
$endOfSeason = Carbon\Carbon::now()->addMonth(7);
|
|
|
|
while($nr<=$roundcount) {
|
|
$roundname="Runde ".$nr;
|
|
Log::info("Creating: ".$roundname);
|
|
$round = Round::create([
|
|
'name' => $roundname,
|
|
'season_id' => $seasonId
|
|
]);
|
|
$round->save();
|
|
$round_id = $round->id;
|
|
|
|
$game1 = Game::create([
|
|
'round_id' => $round_id,
|
|
'team1' => "Mannschaft 1",
|
|
'team2' => "Mannschaft 2",
|
|
//'kickoff' => User::toDBDate(request('game1_kickoff'))
|
|
'kickoff' => $endOfSeason
|
|
]);
|
|
$game1->save();
|
|
|
|
$game2 = Game::create([
|
|
'round_id' => $round_id,
|
|
'team1' => "Mannschaft 3",
|
|
'team2' => "Mannschaft 4",
|
|
'kickoff' => $endOfSeason
|
|
]);
|
|
$game2->save();
|
|
|
|
$game3 = Game::create([
|
|
'round_id' => $round_id,
|
|
'team1' => "Mannschaft 5",
|
|
'team2' => "Mannschaft 6",
|
|
'kickoff' => $endOfSeason
|
|
]);
|
|
$game3->save();
|
|
|
|
$game4 = Game::create([
|
|
'round_id' => $round_id,
|
|
'team1' => "Mannschaft 7",
|
|
'team2' => "Mannschaft 8",
|
|
'kickoff' => $endOfSeason
|
|
]);
|
|
$game4->save();
|
|
// Sign them in
|
|
$nr+=1;
|
|
|
|
}
|
|
|
|
Log::info("Round creation completed, now setting Tipps");
|
|
|
|
Tipp::createAllTips();
|
|
// Redirect to the home page
|
|
return redirect('/seasons');
|
|
}
|
|
|
|
public function store_quota() {
|
|
if (Auth::guest()) { return redirect("/"); }
|
|
if (!Auth::user()->admin) { return redirect("/"); }
|
|
|
|
$currentSeason=Season::getCurrent();
|
|
|
|
// Validate form
|
|
$this->validate(request(), [
|
|
'round_count' => 'required',
|
|
'season_id' => 'required',
|
|
'einsatz' => 'required',
|
|
'tagessieg' => 'required',
|
|
'pokal' => 'required',
|
|
'gruenes_trikot' => 'required',
|
|
'platzierung' => 'required',
|
|
'liga' => 'required',
|
|
'liga_platz1' => 'required',
|
|
'liga_platz2' => 'required',
|
|
'liga_platz3' => 'required',
|
|
'platz1' => 'required',
|
|
'platz2' => 'required',
|
|
'platz3' => 'required',
|
|
'platz4' => 'required',
|
|
'platz5' => 'required',
|
|
'platz6' => 'required',
|
|
'platz7' => 'required',
|
|
'platz8' => 'required',
|
|
'platz9' => 'required',
|
|
'platz10' => 'required'
|
|
]);
|
|
|
|
|
|
// Create and save the season
|
|
|
|
|
|
|
|
|
|
|
|
Quota::setQuota('Runden', request('round_count'));
|
|
Quota::setQuota('Einsatz', request('einsatz'));
|
|
Quota::setQuota('Tagessieg', str_replace(",",".",request('tagessieg')));
|
|
Quota::setQuota('Gruenes Trikot', str_replace(",",".",request('gruenes_trikot')));
|
|
Quota::setQuota('Pokal', str_replace(",",".",request('pokal')));
|
|
|
|
Quota::setQuota('Platzierung', str_replace(",",".",request('platzierung')));
|
|
Quota::setQuota('Platz 1', str_replace(",",".",request('platz1')));
|
|
Quota::setQuota('Platz 2', str_replace(",",".",request('platz2')));
|
|
Quota::setQuota('Platz 3', str_replace(",",".",request('platz3')));
|
|
Quota::setQuota('Platz 4', str_replace(",",".",request('platz4')));
|
|
Quota::setQuota('Platz 5', str_replace(",",".",request('platz5')));
|
|
Quota::setQuota('Platz 6', str_replace(",",".",request('platz6')));
|
|
Quota::setQuota('Platz 7', str_replace(",",".",request('platz7')));
|
|
Quota::setQuota('Platz 8', str_replace(",",".",request('platz8')));
|
|
Quota::setQuota('Platz 9', str_replace(",",".",request('platz9')));
|
|
Quota::setQuota('Platz 10', str_replace(",",".",request('platz10')));
|
|
Quota::setQuota('Liga-Wertung', str_replace(",",".",request('liga')));
|
|
Quota::setQuota('Liga Platz 1', str_replace(",",".",request('liga_platz1')));
|
|
Quota::setQuota('Liga Platz 2', str_replace(",",".",request('liga_platz2')));
|
|
Quota::setQuota('Liga Platz 3', str_replace(",",".",request('liga_platz3')));
|
|
Quota::setQuota('Liga Platz 2_1', str_replace(",",".",request('liga_platz2_1')));
|
|
Quota::setQuota('Liga Platz 3_1', str_replace(",",".",request('liga_platz3_1')));
|
|
|
|
// 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");
|
|
}
|
|
|
|
} |