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-06-20 08:43:36 +02:00
|
|
|
|
|
|
|
|
class Season extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $fillable = [
|
2017-10-06 12:17:49 +02:00
|
|
|
'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');
|
2017-10-06 12:17:49 +02:00
|
|
|
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];
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-20 08:43:36 +02:00
|
|
|
}
|