2017-06-20 08:43:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use App\Season;
|
2017-10-06 12:17:49 +02:00
|
|
|
use App\Round;
|
2017-08-16 17:30:32 +02:00
|
|
|
use App\Quota;
|
2017-09-03 09:03:39 +02:00
|
|
|
use App\User;
|
2017-10-06 12:17:49 +02:00
|
|
|
use App\Game;
|
|
|
|
|
use App\Tipp;
|
2018-01-18 15:15:31 +01:00
|
|
|
use App\ManualPayout;
|
2017-10-06 12:17:49 +02:00
|
|
|
use Carbon;
|
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("/"); }
|
2017-10-25 10:42:05 +02:00
|
|
|
if (!Auth::user()->admin) { return redirect("/"); }
|
2017-08-30 14:52:21 +02:00
|
|
|
|
2017-10-25 10:42:05 +02:00
|
|
|
$seasons = DB::table('seasons')->get();
|
2017-08-19 16:53:39 +02:00
|
|
|
$currentSeason=Season::getCurrent();
|
2018-01-18 15:15:31 +01:00
|
|
|
$users = User::getActivesSortedByName();
|
2018-01-16 08:50:29 +01:00
|
|
|
$active_user_count = sizeof( $users );
|
2017-08-16 17:30:32 +02:00
|
|
|
|
2017-10-25 10:42:05 +02:00
|
|
|
$currentSeasonId=-1;
|
|
|
|
|
if ($currentSeason) {
|
2018-01-10 08:45:01 +01:00
|
|
|
$quotas = Quota::getQuotasForDisplay();
|
2017-11-10 15:32:54 +01:00
|
|
|
$payouts = Quota::getPayouts();
|
2017-08-30 14:52:21 +02:00
|
|
|
}
|
2017-08-19 16:53:39 +02:00
|
|
|
|
2018-01-18 15:15:31 +01:00
|
|
|
$winnerNames=array();
|
2024-06-30 13:16:49 +02:00
|
|
|
/*
|
2018-01-18 15:15:31 +01:00
|
|
|
$manualPayoutTypes=array('liga_platz1','liga_platz2','liga_platz3', 'liga_platz2_1', 'liga_platz3_1', 'pokal');
|
|
|
|
|
foreach($manualPayoutTypes as $payoutType) {
|
|
|
|
|
$user = ManualPayout::getWinner($payoutType);
|
|
|
|
|
$name="Festlegen";
|
|
|
|
|
if ($user) $name = $user->name;
|
|
|
|
|
$winnerNames[$payoutType] = $name;
|
|
|
|
|
}
|
2024-06-30 13:16:49 +02:00
|
|
|
*/
|
2018-01-18 15:15:31 +01:00
|
|
|
|
|
|
|
|
return view('seasons.index', compact('seasons','currentSeason','active_user_count','quotas','payouts', 'users', 'winnerNames'));
|
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(), [
|
2017-10-06 12:17:49 +02:00
|
|
|
'name' => 'required',
|
|
|
|
|
'roundcount' => 'required'
|
2017-06-20 08:43:36 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Create and save the season
|
|
|
|
|
|
|
|
|
|
$season = Season::create([
|
2017-10-06 12:17:49 +02:00
|
|
|
'name' => request('name'),
|
|
|
|
|
'rounds' => request('roundcount')
|
2017-06-20 08:43:36 +02:00
|
|
|
]);
|
2017-10-06 12:17:49 +02:00
|
|
|
$season->save();
|
|
|
|
|
Season::setCurrent($season->id);
|
|
|
|
|
Log::info('Setting season id=' .$season->id);
|
|
|
|
|
|
2017-11-10 15:32:54 +01:00
|
|
|
Quota::createDefaultQuota();
|
2017-10-06 12:17:49 +02:00
|
|
|
|
|
|
|
|
$nr=1;
|
|
|
|
|
$roundcount=request('roundcount');
|
|
|
|
|
$seasonId = Season::getCurrent()->id;
|
2017-12-19 08:23:22 +01:00
|
|
|
$endOfSeason = Carbon\Carbon::now()->addMonth(7);
|
2017-10-06 12:17:49 +02:00
|
|
|
|
|
|
|
|
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'))
|
2017-12-19 08:23:22 +01:00
|
|
|
'kickoff' => $endOfSeason
|
2017-10-06 12:17:49 +02:00
|
|
|
]);
|
|
|
|
|
$game1->save();
|
|
|
|
|
|
|
|
|
|
$game2 = Game::create([
|
|
|
|
|
'round_id' => $round_id,
|
|
|
|
|
'team1' => "Mannschaft 3",
|
|
|
|
|
'team2' => "Mannschaft 4",
|
2017-12-19 08:23:22 +01:00
|
|
|
'kickoff' => $endOfSeason
|
2017-10-06 12:17:49 +02:00
|
|
|
]);
|
|
|
|
|
$game2->save();
|
|
|
|
|
|
|
|
|
|
$game3 = Game::create([
|
|
|
|
|
'round_id' => $round_id,
|
|
|
|
|
'team1' => "Mannschaft 5",
|
|
|
|
|
'team2' => "Mannschaft 6",
|
2017-12-19 08:23:22 +01:00
|
|
|
'kickoff' => $endOfSeason
|
2017-10-06 12:17:49 +02:00
|
|
|
]);
|
|
|
|
|
$game3->save();
|
|
|
|
|
|
|
|
|
|
$game4 = Game::create([
|
|
|
|
|
'round_id' => $round_id,
|
|
|
|
|
'team1' => "Mannschaft 7",
|
|
|
|
|
'team2' => "Mannschaft 8",
|
2017-12-19 08:23:22 +01:00
|
|
|
'kickoff' => $endOfSeason
|
2017-10-06 12:17:49 +02:00
|
|
|
]);
|
|
|
|
|
$game4->save();
|
|
|
|
|
// Sign them in
|
|
|
|
|
$nr+=1;
|
2017-06-20 08:43:36 +02:00
|
|
|
|
2017-06-26 17:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-06 12:17:49 +02:00
|
|
|
Log::info("Round creation completed, now setting Tipps");
|
2017-06-20 08:43:36 +02:00
|
|
|
|
2017-10-06 12:17:49 +02:00
|
|
|
Tipp::createAllTips();
|
2017-06-20 08:43:36 +02:00
|
|
|
// Redirect to the home page
|
|
|
|
|
return redirect('/seasons');
|
|
|
|
|
}
|
2017-10-06 12:17:49 +02:00
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
public function store_quota() {
|
|
|
|
|
if (Auth::guest()) { return redirect("/"); }
|
|
|
|
|
if (!Auth::user()->admin) { return redirect("/"); }
|
2024-06-30 13:16:49 +02:00
|
|
|
Log::info("--store_quota--");
|
|
|
|
|
Log::info(request());
|
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',
|
|
|
|
|
'platzierung' => 'required',
|
|
|
|
|
'platz1' => 'required',
|
|
|
|
|
'platz2' => 'required',
|
|
|
|
|
'platz3' => 'required',
|
|
|
|
|
'platz4' => 'required',
|
|
|
|
|
'platz5' => 'required',
|
|
|
|
|
'platz6' => 'required',
|
|
|
|
|
'platz7' => 'required',
|
|
|
|
|
'platz8' => 'required',
|
|
|
|
|
'platz9' => 'required',
|
|
|
|
|
'platz10' => 'required'
|
|
|
|
|
]);
|
2024-06-30 13:16:49 +02:00
|
|
|
Log::info("request validated");
|
2017-08-19 16:53:39 +02:00
|
|
|
|
|
|
|
|
// Create and save the season
|
2018-02-09 09:59:32 +01:00
|
|
|
Quota::setQuota('runden', request('round_count'));
|
2018-01-26 10:09:20 +01:00
|
|
|
Quota::setQuota('einsatz', request('einsatz'));
|
|
|
|
|
Quota::setQuota('tagessieg', str_replace(",",".",request('tagessieg')));
|
|
|
|
|
Quota::setQuota('platzierung', str_replace(",",".",request('platzierung')));
|
|
|
|
|
Quota::setQuota('platz1', str_replace(",",".",request('platz1')));
|
|
|
|
|
Quota::setQuota('platz2', str_replace(",",".",request('platz2')));
|
2024-06-30 13:16:49 +02:00
|
|
|
Quota::setQuota('platz3', str_replace(",",".",request('platz3')));
|
|
|
|
|
Quota::setQuota('platz4', str_replace(",",".",request('platz4')));
|
|
|
|
|
Quota::setQuota('platz5', str_replace(",",".",request('platz5')));
|
|
|
|
|
Quota::setQuota('platz6', str_replace(",",".",request('platz6')));
|
|
|
|
|
Quota::setQuota('platz7', str_replace(",",".",request('platz7')));
|
|
|
|
|
Quota::setQuota('platz8', str_replace(",",".",request('platz8')));
|
|
|
|
|
Quota::setQuota('platz9', str_replace(",",".",request('platz9')));
|
|
|
|
|
Quota::setQuota('platz10', str_replace(",",".",request('platz10')));
|
|
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
// Redirect to the home page
|
|
|
|
|
return redirect('/seasons');
|
|
|
|
|
}
|
2018-01-18 15:15:31 +01:00
|
|
|
public function setcurrent($new_season_id)
|
|
|
|
|
{
|
|
|
|
|
if (Auth::guest()) {
|
|
|
|
|
return redirect("/");
|
|
|
|
|
}
|
|
|
|
|
if (!Auth::user()->admin) {
|
|
|
|
|
return redirect("/");
|
|
|
|
|
}
|
2017-06-26 17:21:30 +02:00
|
|
|
|
|
|
|
|
Season::setCurrent($new_season_id);
|
|
|
|
|
return redirect("/seasons");
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 15:15:31 +01:00
|
|
|
public function set_winner( $userId, $quotaName) {
|
|
|
|
|
if (Auth::guest()) { return redirect("/"); }
|
|
|
|
|
if (!Auth::user()->admin) { return redirect("/"); }
|
|
|
|
|
|
|
|
|
|
ManualPayout::setWinner( $userId, $quotaName);
|
|
|
|
|
return redirect('/seasons');
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-08-16 17:30:32 +02:00
|
|
|
}
|