tippspiel/pfosten/app/Season.php

76 lines
2 KiB
PHP
Raw Normal View History

2017-06-20 08:43:36 +02:00
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use \App\Setting;
2017-06-26 17:21:30 +02:00
use Log;
2017-10-29 07:13:52 +01:00
use \App\Leagues\League;
2017-06-20 08:43:36 +02:00
class Season extends Model
{
protected $fillable = [
'name','rounds'
2017-06-20 08:43:36 +02:00
];
/*
public function isActive() {
return $this->hasOne('App\Setting','season_id');
}
*/
public static function getCurrent() {
2017-06-26 17:21:30 +02:00
$setting = Setting::all()->first();
if (!$setting) {
//Log::info('Season.getCurrent(): No current season set');
error_log('Season.getCurrent(): No current season set');
2017-06-26 17:21:30 +02:00
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();
2017-06-20 08:43:36 +02:00
}
2017-10-11 11:14:23 +02:00
2017-10-16 11:19:57 +02:00
public static function getPrevious() {
2017-10-11 11:14:23 +02:00
$seasons=Season::where('id','>',0)->orderBy('id','DESC')->get();
if (sizeof($seasons)<2) { return null; }
return $seasons[1];
}
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;
2017-10-29 07:13:52 +01:00
}
return false;
}
2017-06-20 08:43:36 +02:00
}