92 lines
2.5 KiB
PHP
92 lines
2.5 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'
|
|
];
|
|
/*
|
|
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("Gruenes Trikot");
|
|
return $quota>0;
|
|
}
|
|
|
|
}
|