2017-06-20 08:43:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use App\Season;
|
2017-08-16 17:30:32 +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;
|
|
|
|
|
use Log;
|
2017-06-20 08:43:36 +02:00
|
|
|
|
|
|
|
|
class SeasonsController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function index() {
|
2017-06-26 17:21:30 +02:00
|
|
|
if (Auth::guest()) { return redirect("/"); }
|
|
|
|
|
if (!Auth::user()->admin) { return redirect("/"); }
|
2017-08-19 16:53:39 +02:00
|
|
|
$seasons = DB::table('seasons')->get();
|
2017-08-30 14:52:21 +02:00
|
|
|
|
|
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
$currentSeason=Season::getCurrent();
|
2017-08-16 17:30:32 +02:00
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
$active_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->whereNotNull('paid_date')->get() );
|
2017-08-16 17:30:32 +02:00
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
$quotas = Quota::getQuotas($currentSeason->id);
|
2017-08-30 14:52:21 +02:00
|
|
|
if (!$quotas) {
|
|
|
|
|
Quota::createDefaultQuota($currentSeason->id);
|
|
|
|
|
$quotas = Quota::getQuotas($currentSeason->id);
|
|
|
|
|
}
|
2017-08-19 16:53:39 +02:00
|
|
|
|
|
|
|
|
$active_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->whereNotNull('paid_date')->get() );
|
|
|
|
|
|
2017-08-30 14:52:21 +02:00
|
|
|
$quotas = Quota::getQuotas($currentSeason->id);
|
|
|
|
|
$payouts = Quota::getPayouts($currentSeason->id);
|
2017-08-19 16:53:39 +02:00
|
|
|
|
|
|
|
|
|
2017-08-30 14:52:21 +02:00
|
|
|
return view('seasons.index', compact('seasons','currentSeason','active_user_count','quotas','payouts'));
|
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("/"); }
|
2017-06-20 08:43:36 +02:00
|
|
|
|
|
|
|
|
return view('seasons.create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function store() {
|
2017-06-26 17:21:30 +02:00
|
|
|
if (Auth::guest()) { return redirect("/"); }
|
|
|
|
|
if (!Auth::user()->admin) { return redirect("/"); }
|
2017-06-20 08:43:36 +02:00
|
|
|
|
|
|
|
|
// Validate form
|
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
'name' => 'required'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Create and save the season
|
|
|
|
|
|
|
|
|
|
$season = Season::create([
|
|
|
|
|
'name' => request('name')
|
|
|
|
|
]);
|
|
|
|
|
|
2017-06-26 17:21:30 +02:00
|
|
|
if (Season::all()->count()==1) {
|
|
|
|
|
Season::setCurrent($season->id);
|
|
|
|
|
Log::info('Setting season id=' .$season->id);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
Quota::createDefaultQuota($season->id);
|
2017-06-20 08:43:36 +02:00
|
|
|
|
|
|
|
|
// Redirect to the home page
|
|
|
|
|
return redirect('/seasons');
|
|
|
|
|
}
|
2017-08-19 16:53:39 +02:00
|
|
|
public function store_quota() {
|
|
|
|
|
if (Auth::guest()) { return redirect("/"); }
|
|
|
|
|
if (!Auth::user()->admin) { return redirect("/"); }
|
2017-06-20 08:43:36 +02:00
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
$currentSeason=Season::getCurrent();
|
|
|
|
|
|
|
|
|
|
// Validate form
|
|
|
|
|
$this->validate(request(), [
|
2017-08-30 14:52:21 +02:00
|
|
|
'round_count' => 'required',
|
2017-08-19 16:53:39 +02:00
|
|
|
'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
|
|
|
|
|
|
2017-08-30 14:52:21 +02:00
|
|
|
Quota::setQuota('Runden',request('round_count'), $currentSeason->id);
|
2017-08-19 16:53:39 +02:00
|
|
|
Quota::setQuota('Einsatz',request('einsatz'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Tagessieg',request('tagessieg'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Gruenes Trikot',request('gruenes_trikot'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Pokal',request('pokal'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platzierung',request('platzierung'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platz 1',request('platz1'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platz 2',request('platz2'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platz 3',request('platz3'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platz 4',request('platz4'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platz 5',request('platz5'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platz 6',request('platz6'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platz 7',request('platz7'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platz 8',request('platz8'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platz 9',request('platz9'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Platz 10',request('platz10'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Liga-Wertung',request('liga'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Liga Platz 1',request('liga_platz1'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Liga Platz 2',request('liga_platz2'), $currentSeason->id);
|
|
|
|
|
Quota::setQuota('Liga Platz 3',request('liga_platz3'), $currentSeason->id);
|
|
|
|
|
|
|
|
|
|
// Redirect to the home page
|
|
|
|
|
return redirect('/seasons');
|
|
|
|
|
}
|
2017-06-26 17:21:30 +02:00
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-16 17:30:32 +02:00
|
|
|
}
|