120 lines
3.3 KiB
PHP
120 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use \App\Setting;
|
|
use Log;
|
|
use \App\Leagues\League;
|
|
|
|
class Season extends Model
|
|
{
|
|
protected $fillable = [
|
|
'name','rounds',"max_identical_jokertipps"
|
|
];
|
|
/*
|
|
public function isActive() {
|
|
return $this->hasOne('App\Setting','season_id');
|
|
}
|
|
*/
|
|
|
|
public static function getCurrent() {
|
|
$setting = Setting::all()->first();
|
|
if (!$setting) {
|
|
//Log::info('Season.getCurrent(): No current season set');
|
|
error_log('Season.getCurrent(): No current season set');
|
|
return null;
|
|
}
|
|
|
|
//Log::info("current_season_id=" . $setting->current_season_id);
|
|
$currentSeason = Season::where('id',$setting->current_season_id)->first();
|
|
|
|
return $currentSeason;
|
|
}
|
|
|
|
public static function setCurrent($season_id) {
|
|
$setting = Setting::all()->first();
|
|
if (!$setting) {
|
|
$setting = Setting::create([
|
|
'current_season_id' => $season_id
|
|
]);
|
|
}
|
|
$setting->current_season_id=$season_id;
|
|
$setting->save();
|
|
}
|
|
|
|
public static function getPrevious() {
|
|
$seasons=Season::where('id','>',0)->orderBy('id','DESC')->get();
|
|
if (sizeof($seasons)<2) { return null; }
|
|
return $seasons[1];
|
|
}
|
|
|
|
public static function get($seasonId) {
|
|
if ($seasonId==-1) return Season::getCurrent();
|
|
$season=Season::where('id','=',$seasonId)->first();
|
|
return $season;
|
|
}
|
|
|
|
|
|
public static function hasQualifications($seasonId=-1) {
|
|
return Season::hasLeagueType($seasonId,League::RANK_QUALIFICATION);
|
|
}
|
|
|
|
public static function hasStandardLeague($seasonId=-1) {
|
|
return Season::hasLeagueType($seasonId,League::RANK_LEAGUE1);
|
|
}
|
|
|
|
public static function hasLeagueType($seasonId=-1, $ltype) {
|
|
$season=null;
|
|
if ($seasonId==-1) {
|
|
$season = Season::getCurrent();
|
|
if (!$season) return false;
|
|
$seasonId=$season->id;
|
|
}
|
|
$leagues = League::where('season_id', '=', $seasonId)->get();
|
|
foreach ($leagues as $league) {
|
|
if ($league->rank == $ltype) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static function hasGreenShirtGame($seasonId=-1) {
|
|
$season=null;
|
|
if ($seasonId==-1) {
|
|
$season = Season::getCurrent();
|
|
if (!$season) return false;
|
|
$seasonId=$season->id;
|
|
}
|
|
$quota=Quota::getQuota("gshirt");
|
|
return $quota>0;
|
|
}
|
|
|
|
// implemented 2020-01-08 because of needed first round_id of the season
|
|
public static function getFirstRoundId($seasonId=-1) {
|
|
$season=null;
|
|
if ($seasonId==-1) {
|
|
$season = Season::getCurrent();
|
|
} else {
|
|
$season = Season::where('id','=',$seasonId)->first();
|
|
}
|
|
|
|
if (!$season) return -1;
|
|
$seasonId=$season->id;
|
|
|
|
$firstRound = Round::where('season_id','=',$seasonId)->orderBy('id')->first();
|
|
return $firstRound->id;
|
|
}
|
|
|
|
public static function maxIdenticalJokertipps($seasonId=-1) {
|
|
$season=null;
|
|
if ($seasonId==-1) {
|
|
$season = Season::getCurrent();
|
|
} else {
|
|
$season = Season::where('id','=',$seasonId)->first();
|
|
}
|
|
|
|
return $season->max_identical_jokertipps;
|
|
}
|
|
|
|
|
|
}
|