56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Leagues;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use App\Season;
|
|
|
|
use DB;
|
|
use Log;
|
|
|
|
class League extends Model
|
|
{
|
|
|
|
const RANK_LEAGUE1 = 1;
|
|
const RANK_LEAGUE2 = 2;
|
|
const RANK_LEAGUE3 = 3;
|
|
const RANK_QUALIFICATION = 4;
|
|
|
|
protected $table ='leagues';
|
|
protected $fillable = [
|
|
'id','season_id','is_qualification','rank','subrank','start_round_id','round_count','name'
|
|
];
|
|
//
|
|
public static function neededLeagues($member_count, $round_count) {
|
|
$max_members_per_league=22;
|
|
if ( $round_count < $max_members_per_league-1 ) { $max_members_per_league = $round_count+1; }
|
|
if ($member_count <= $max_members_per_league) return $member_count;
|
|
|
|
$neededLeagues = intdiv($member_count, $max_members_per_league);
|
|
|
|
if ( $member_count - $max_members_per_league * $neededLeagues ) {
|
|
$neededLeagues+=1;
|
|
}
|
|
return $neededLeagues;
|
|
}
|
|
|
|
public static function getMemberCount($league_id) {
|
|
$members = DB::table('leagues_members')->where('league_id','=',$league_id)->get();
|
|
return sizeof($members);
|
|
}
|
|
|
|
|
|
public static function getNames() {
|
|
$season = Season::getCurrent();
|
|
|
|
$leagues = League::where('season_id','=',$season->id)->orderBy('rank')->orderBy('name')->get();
|
|
|
|
$leagueNames = array();
|
|
foreach($leagues as $league) {
|
|
$leagueNames[$league->id] = $league->name;
|
|
}
|
|
return $leagueNames;
|
|
}
|
|
|
|
}
|