diff --git a/pfosten/app/Http/Controllers/Leagues/LeaguesController.php b/pfosten/app/Http/Controllers/Leagues/LeaguesController.php index faaa6ff5..e915d138 100644 --- a/pfosten/app/Http/Controllers/Leagues/LeaguesController.php +++ b/pfosten/app/Http/Controllers/Leagues/LeaguesController.php @@ -88,7 +88,7 @@ class LeaguesController extends Controller $roundNames = Round::getNames(); $leagueNames = League::getNames(); - $leagues = League::where('season_id','=',$season->id)->where('rank','<', 4)->orderBy('id')->get(); + $leagues = League::where('season_id','=',$season->id)->where('rank','<=', 4)->orderBy('id')->get(); $matchesTotal = array(); foreach ($leagues as $league) { @@ -114,6 +114,9 @@ class LeaguesController extends Controller //$leagues = array_reverse(League::getRanking($rank)); $leagueNames = League::getNames(); $userNames = User::getNames(); + + $leagues = League::where('season_id','=',$season->id)->where('rank','<=', 4)->orderBy('id')->get(); + if (!sizeof($leagues)) return redirect("/"); $totalRanking = League::getTotalRankingOverall(); // Nur für Auf/Abstiegsinfo benötigt. $rankInfo=array(); diff --git a/pfosten/app/Http/Controllers/RoundsController.php b/pfosten/app/Http/Controllers/RoundsController.php index f862f745..5064469f 100644 --- a/pfosten/app/Http/Controllers/RoundsController.php +++ b/pfosten/app/Http/Controllers/RoundsController.php @@ -27,8 +27,8 @@ class RoundsController extends Controller $rounds = Round::all()->where('season_id', '=', $activeSeasonId); } - $quotas = Quota::getQuotas($activeSeason->id); - $round_count = $quotas['Runden']; + $quotas = Quota::getQuotas(); + $round_count = Round::getCount(); return view('rounds.index', compact('rounds','activeSeason', 'round_count')); diff --git a/pfosten/app/Http/Controllers/SeasonsController.php b/pfosten/app/Http/Controllers/SeasonsController.php index 8d05b0e6..59973bbe 100644 --- a/pfosten/app/Http/Controllers/SeasonsController.php +++ b/pfosten/app/Http/Controllers/SeasonsController.php @@ -26,8 +26,8 @@ class SeasonsController extends Controller $currentSeasonId=-1; if ($currentSeason) { - $quotas = Quota::getQuotas($currentSeason->id); - $payouts = Quota::getPayouts($currentSeason->id); + $quotas = Quota::getQuotas(); + $payouts = Quota::getPayouts(); } return view('seasons.index', compact('seasons','currentSeason','active_user_count','quotas','payouts')); @@ -60,7 +60,7 @@ class SeasonsController extends Controller Season::setCurrent($season->id); Log::info('Setting season id=' .$season->id); - Quota::createDefaultQuota($season->id); + Quota::createDefaultQuota(); $nr=1; $roundcount=request('roundcount'); @@ -155,26 +155,26 @@ class SeasonsController extends Controller // Create and save the season - Quota::setQuota('Runden',request('round_count'), $currentSeason->id); - 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); + Quota::setQuota('Runden', request('round_count')); + Quota::setQuota('Einsatz', request('einsatz')); + Quota::setQuota('Tagessieg', request('tagessieg')); + Quota::setQuota('Gruenes Trikot', request('gruenes_trikot')); + Quota::setQuota('Pokal', request('pokal')); + Quota::setQuota('Platzierung', request('platzierung')); + Quota::setQuota('Platz 1', request('platz1')); + Quota::setQuota('Platz 2', request('platz2')); + Quota::setQuota('Platz 3', request('platz3')); + Quota::setQuota('Platz 4', request('platz4')); + Quota::setQuota('Platz 5', request('platz5')); + Quota::setQuota('Platz 6', request('platz6')); + Quota::setQuota('Platz 7', request('platz7')); + Quota::setQuota('Platz 8', request('platz8')); + Quota::setQuota('Platz 9', request('platz9')); + Quota::setQuota('Platz 10', request('platz10')); + Quota::setQuota('Liga-Wertung', request('liga')); + Quota::setQuota('Liga Platz 1', request('liga_platz1')); + Quota::setQuota('Liga Platz 2', request('liga_platz2')); + Quota::setQuota('Liga Platz 3', request('liga_platz3')); // Redirect to the home page return redirect('/seasons'); diff --git a/pfosten/app/Http/Controllers/UsersController.php b/pfosten/app/Http/Controllers/UsersController.php index 5e596cc1..8c53abc6 100755 --- a/pfosten/app/Http/Controllers/UsersController.php +++ b/pfosten/app/Http/Controllers/UsersController.php @@ -362,8 +362,8 @@ class UsersController extends Controller $currentSeason = Season::getCurrent(); $active_user_count = sizeof(User::getActives()); - $quotas = Quota::getQuotas($currentSeason->id); - $payouts = Quota::getPayouts($currentSeason->id); + $quotas = Quota::getQuotas(); + $payouts = Quota::getPayouts(); return view('users.show_payouts', compact('payouts','active_user_count','quotas','currentSeason')); } diff --git a/pfosten/app/Quota.php b/pfosten/app/Quota.php index 20a4b604..d48eaa28 100644 --- a/pfosten/app/Quota.php +++ b/pfosten/app/Quota.php @@ -8,21 +8,25 @@ use DB; class Quota extends Model { - public static function getPayouts($season_id) { - $quotas = Quota::getQuotas($season_id); + public static function getPayouts() { + $season_id = Season::getCurrent()->id; + + $quotas = Quota::getQuotas(); + + $roundCount=Round::getCount(); //Quotas fuer Season wegwerfen falls vorhanden und default Wert reinschreiben if (sizeof($quotas)==0) { - Quota::createDefaultQuota($season_id->id); - $quotas = Quota::getQuotas($season_id); + Quota::createDefaultQuota(); + $quotas = Quota::getQuotas(); } $active_user_count = sizeof(User::getActives()); - $euro_pott = $active_user_count * $quotas["Einsatz"]; $euro_tagessieg_sum = intval ($euro_pott * ( $quotas["Tagessieg"] / 100 ) ); - $euro_tagessieg = Quota::get6Divisor( intval($euro_tagessieg_sum / $quotas['Runden'])); + + $euro_tagessieg = Quota::get6Divisor( intval($euro_tagessieg_sum / $roundCount)); $euro_gruenes_trikot = intval($euro_pott * (($quotas["Gruenes Trikot"] / 100))); $euro_gruenes_trikot = Quota::get6Divisor($euro_gruenes_trikot); @@ -30,7 +34,7 @@ class Quota extends Model $euro_pokal= Quota::get6Divisor($euro_pokal); $euro_platzierung = intval ( $euro_pott * (($quotas["Platzierung"] / 100))); - $tagessieg_rest = $euro_tagessieg_sum - ($euro_tagessieg * $quotas['Runden']); + $tagessieg_rest = $euro_tagessieg_sum - ($euro_tagessieg * $roundCount); //Log::info("Tagessieg Rest=".$tagessieg_rest." €"); $euro_platzierung += $tagessieg_rest; @@ -52,7 +56,7 @@ class Quota extends Model $euro_liga_platz2 = Quota::get6Divisor(intval($euro_liga*(($quotas["Liga Platz 2"] / 100)))); $euro_liga_platz3 = Quota::get6Divisor(intval($euro_liga*(($quotas["Liga Platz 3"] / 100)))); - $finaler_rest = $euro_pott - ( $quotas['Runden']*$euro_tagessieg + $euro_gruenes_trikot + $euro_pokal + $euro_platz1 + $finaler_rest = $euro_pott - ( $roundCount*$euro_tagessieg + $euro_gruenes_trikot + $euro_pokal + $euro_platz1 + $euro_platz2 + $euro_platz3+ $euro_platz4 + $euro_platz5 + $euro_platz6 + $euro_platz7 + $euro_platz8 + $euro_platz9 + $euro_platz10 + $euro_liga_platz1 + $euro_liga_platz2 + $euro_liga_platz3); @@ -83,7 +87,8 @@ class Quota extends Model } // Subfunction of setQuotas - public static function setQuota($name, $value, $season_id) { + public static function setQuota($name, $value) { + $season_id = Season::getCurrent()->id; $quota = Quota::all()->where('season_id','=',$season_id)->where('name','=',$name)->first(); if (!$quota) { $quota = new Quota(); @@ -94,13 +99,14 @@ class Quota extends Model $quota->save(); } - - public static function getQuota($season_id,$quota_name) { +/* + public static function getQuota($quota_name) { $quota=Quota::all()->where('season_id','=', $season_id)->where('name','=', $quota_name)->first(); return $quota['prc']; } - - public static function getQuotas($season_id) { +*/ + public static function getQuotas() { + $season_id = Season::getCurrent()->id; $quotas=Quota::all()->where('season_id','=', $season_id); $arr=array(); foreach($quotas as $quota) { @@ -110,15 +116,17 @@ class Quota extends Model } - public static function setQuotas($quotas,$season_id) { + public static function setQuotas($quotas) { + $season_id = Season::getCurrent()->id; foreach ($quotas as $key => $quota) { setQuota($key, $quota, $season_id); } } - public static function createDefaultQuota($season_id) + public static function createDefaultQuota() { + $season_id = Season::getCurrent()->id; Log::info('Creating default quotas'); DB::table('quotas')->where('season_id', '=', $season_id)->delete(); @@ -126,13 +134,6 @@ class Quota extends Model $roundCount=Season::getCurrent()->rounds; Log::info("Creating new Quota"); - $quota = new Quota; - $quota->season_id = $season_id; - $quota->name = "Runden"; - $quota->prc = $roundCount; - $quota->save(); - - $quota = new Quota; $quota->season_id = $season_id; $quota->name = "Einsatz"; diff --git a/pfosten/app/Round.php b/pfosten/app/Round.php index f6456ccd..ef20847a 100755 --- a/pfosten/app/Round.php +++ b/pfosten/app/Round.php @@ -156,6 +156,21 @@ class Round extends Model return null; } + public static function getCount($seasonId=-1) { + $season=null; + if ($seasonId==-1) { + $season=Season::getCurrent(); + } else { + $season=Season::where('id','=', $seasonId)->first(); + } + if (!$season) return 0; + + $rounds=Round::where('season_id','=',$season->id)->get(); + + + return sizeof($rounds); + } + // TODO: CHeck : Unused ?? public static function getClosestRoundToNow() { $sql="select round_id,DATEDIFF(NOW(),kickoff) from games order by 2 desc limit 1;"; diff --git a/pfosten/app/Tipp.php b/pfosten/app/Tipp.php index 589b03b1..e5cceca7 100755 --- a/pfosten/app/Tipp.php +++ b/pfosten/app/Tipp.php @@ -398,7 +398,7 @@ class Tipp extends Model // Compute highest dayscore // Addition: no dayscorewinner && round_completed: Payout goes to next round - $payouts = Quota::getPayouts($currentSeason->id); + $payouts = Quota::getPayouts(); $totalDayWinPayout = 0; $round_count=0; @@ -476,11 +476,11 @@ class Tipp extends Model } } - $quotas=Quota::getQuotas($currentSeason->id); + $quotas=Quota::getQuotas(); error_log("Round-Count=".$round_count); - if ($round_count==$quotas["Runden"]) { + if ($round_count==Round::getCount()) { // Ranking Payout ausschütten $payout_groups =array(); $lastRoundId= array_values(array_slice($round_ids,-1))[0]; diff --git a/pfosten/resources/views/seasons/index.blade.php b/pfosten/resources/views/seasons/index.blade.php index 7dacad0b..95aab44f 100644 --- a/pfosten/resources/views/seasons/index.blade.php +++ b/pfosten/resources/views/seasons/index.blade.php @@ -28,7 +28,7 @@