Arbeit an Auf/Abstieg
This commit is contained in:
parent
8edec26147
commit
ed0c445bfa
5 changed files with 107 additions and 18 deletions
|
|
@ -85,6 +85,7 @@ class LeaguesController extends Controller
|
|||
|
||||
$league_ids=array();
|
||||
Log::info("League Mode:".$league_mode);
|
||||
|
||||
if ($league_mode=="Qualifikation") {
|
||||
for ($league_nr=1; $league_nr<=$neededLeagues; $league_nr+=1) {
|
||||
$league = League::create([
|
||||
|
|
@ -119,10 +120,11 @@ class LeaguesController extends Controller
|
|||
}
|
||||
|
||||
} else {
|
||||
// ToDo: Achtel-, Viertel-, Halb-, Finale require additional leagues; Same with Pokal, so createMissingLeagues method will be needed in the future
|
||||
|
||||
// ToDo: Branch Qualifikation/Liga entfällt in Zukunft, da Quali der Fallback für den Fall ist, dass keine vorherige Saison existiert.
|
||||
// Pokal und Play-Off findet hier nicht statt, da diese Wettbewerbe die Matches abgängig von existierenden Vorrunden-Ergebnissen erzeugen,
|
||||
// und daher zwangsläufig inkrementell sein müssen.
|
||||
|
||||
## !! ##
|
||||
$league_size1= min(22,$active_member_count);
|
||||
$league1 = League::create([
|
||||
'is_qualification' => false,
|
||||
|
|
@ -165,6 +167,9 @@ class LeaguesController extends Controller
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: LeagueMembers zu den Leagues hinzufügen, abhängig vom zuzuordnenden Platz
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -141,8 +141,9 @@ class Round extends Model
|
|||
return $hourDiffToLock;
|
||||
}
|
||||
|
||||
public static function getNames() {
|
||||
public static function getNames($seasonId=-1) {
|
||||
$season= Season::getCurrent();
|
||||
if ($seasonId!=-1) { $season = Season::where('id','=',$seasonId)->first(); }
|
||||
$rounds = Round::where('season_id','=',$season->id)->get();
|
||||
|
||||
Log::info("START");
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class Season extends Model
|
|||
$setting->save();
|
||||
}
|
||||
|
||||
public static function getLast() {
|
||||
public static function getPrevious() {
|
||||
$seasons=Season::where('id','>',0)->orderBy('id','DESC')->get();
|
||||
if (sizeof($seasons)<2) { return null; }
|
||||
return $seasons[1];
|
||||
|
|
|
|||
|
|
@ -108,8 +108,7 @@ class League extends Model
|
|||
}
|
||||
|
||||
|
||||
|
||||
// Für Auf/Abstiegsberechnung
|
||||
// Für Auf/Abstiegsberechnung - wird auf previous Season angewendet.
|
||||
public static function getUnifiedRanking($rank, $seasonId=-1) {
|
||||
$leagueScores = League::getRanking($rank, $seasonId);
|
||||
$unifiedScores = array();
|
||||
|
|
@ -125,21 +124,25 @@ class League extends Model
|
|||
|
||||
|
||||
// Aktuelle Liga-Zuordnung auf Basis des Rangs in der letzten Liga
|
||||
public static function getNewLeagueForPlayers()
|
||||
public static function setLeagueForPlayers()
|
||||
{
|
||||
$lastSeason = Season::getLast();
|
||||
$previousSeason = Season::getPrevious();
|
||||
$currentSeason = Season::getCurrent();
|
||||
|
||||
if (!$lastSeason) {
|
||||
if (!$previousSeason) {
|
||||
dd("No last season handling implemented. Please fix/implement.");
|
||||
//TODO: Implement a qualification round
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$users = User::getActives();
|
||||
$usersLastSeason = User::getActives($lastSeason->id);
|
||||
$usersLastSeason = User::getActives($previousSeason->id);
|
||||
|
||||
// Wenn der User in den roundTipps der previousSeaoson nicht existiert, nahm er an der Runde nicht
|
||||
// teil, und ist automatisch Liga 3.
|
||||
$league1 = League::getUnifiedRanking(1, $previousSeason->id);
|
||||
$league2 = League::getUnifiedRanking( 2, $previousSeason->id);
|
||||
$league3 = League::getUnifiedRanking( 3, $previousSeason->id);
|
||||
//$lastLeagues = League::where('season_id','=',$previousSeason->id)->get();
|
||||
|
||||
foreach ($users as $key => $user) {
|
||||
|
||||
|
|
@ -151,6 +154,7 @@ class League extends Model
|
|||
if (!$found) {
|
||||
$users[$key]['rank']=League::RANK_LEAGUE3; // In der letzten Season unter den Actives nicht gefunden
|
||||
} else {
|
||||
|
||||
// League1, 1-16: RANK_LEAGUE1
|
||||
// League1, 17-22: RANK_LEAGUE2
|
||||
// League2, 1-6: RANK_LEAGUE1
|
||||
|
|
@ -158,6 +162,79 @@ class League extends Model
|
|||
// League2, 17-22: RANK_LEAGUE3
|
||||
// League3, best6: RANK_LEAGUE2
|
||||
// League3, 7-end: RANK_LEAGUE3
|
||||
//
|
||||
foreach($league1 as $index => $entry) {
|
||||
$userId = $entry[0];
|
||||
$score = $entry[1];
|
||||
$goals = $entry[2];
|
||||
$cGoals = $entry[3];
|
||||
$leagueId = -1;
|
||||
if ($user->id == $userId) {
|
||||
$rank=-1;
|
||||
if ($index<16) {
|
||||
$rank=1;
|
||||
$leagueId=$league1->id;
|
||||
} else {
|
||||
$rank=2;
|
||||
$leagueId=$league2->id;
|
||||
}
|
||||
$leagueMember = LeagueMember::create([
|
||||
'user_id' => $userId,
|
||||
'league_id' => $leagueId
|
||||
]);
|
||||
$leagueMember->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach($league2 as $index => $entry) {
|
||||
$userId = $entry[0];
|
||||
$score = $entry[1];
|
||||
$goals = $entry[2];
|
||||
$cGoals = $entry[3];
|
||||
$leagueId = -1;
|
||||
if ($user->id == $userId) {
|
||||
$rank=-1;
|
||||
$leagueId=$league1->id;
|
||||
if ($index<6) {
|
||||
$rank=1;
|
||||
} elseif ($index<16) {
|
||||
$rank=2;
|
||||
$leagueId=$league2->id;
|
||||
} else {
|
||||
$rank=3;
|
||||
$leagueId=$league3->id;
|
||||
}
|
||||
$leagueMember = LeagueMember::create([
|
||||
'user_id' => $userId,
|
||||
'league_id' => $leagueId
|
||||
]);
|
||||
$leagueMember->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach($league3 as $index => $entry) {
|
||||
$userId = $entry[0];
|
||||
$score = $entry[1];
|
||||
$goals = $entry[2];
|
||||
$cGoals = $entry[3];
|
||||
if ($user->id == $userId) {
|
||||
$rank=-1;
|
||||
if ($index<6) {
|
||||
$rank=2;
|
||||
$leagueId=$league2->id;
|
||||
} else {
|
||||
$rank=3;
|
||||
$leagueId=$league3->id;
|
||||
}
|
||||
$leagueMember = LeagueMember::create([
|
||||
'user_id' => $userId,
|
||||
'league_id' => $leagueId
|
||||
]);
|
||||
$leagueMember->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@ class Match extends Model
|
|||
$currentSeason = Season::getCurrent();
|
||||
$leagues = League::where('season_id', '=', $currentSeason->id)->get();
|
||||
foreach ($leagues as $league) {
|
||||
|
||||
// Wenn es keine previous League gibt, dann ist $league->rank immer RANK_QUALIFICATION,
|
||||
// ansonsten ist es einer von RANK_LEAGUE1, RANK_LEAGUE2, RANK_LEAGUE3
|
||||
|
||||
if ($league->rank == League::RANK_QUALIFICATION) {
|
||||
$rounds = Round::where('id','>=',$league->start_round_id)->get();
|
||||
$roundNr=1;
|
||||
|
|
@ -87,14 +91,16 @@ class Match extends Model
|
|||
}
|
||||
|
||||
|
||||
public static function getLeagueMatches($league_id) {
|
||||
//$matches = Match::where('league_id','=',$league_id)->orderBy('round_id')->get();
|
||||
$matches = DB::table('leagues_matches')->where('league_id','=',$league_id)->orderBy('round_id')->get();
|
||||
$season = Season::getCurrent();
|
||||
|
||||
$roundnames = Round::getNames();
|
||||
public static function getLeagueMatches($leagueId) {
|
||||
//error_log("App\Match::getLeagueMatches(leagueId=".$leagueId.")");
|
||||
$matches = DB::table('leagues_matches')->where('league_id','=',$leagueId)->orderBy('round_id')->get();
|
||||
$league=League::where('id','=',$leagueId)->first();
|
||||
$season = Season::where('id','=',$league->season_id)->first();
|
||||
$roundnames = Round::getNames($season->id);
|
||||
$usernames = User::getNames();
|
||||
|
||||
foreach($matches as $match) {
|
||||
//error_log("Needed round_id: ".$match->round_id);
|
||||
$match->round_name = $roundnames[$match->round_id];
|
||||
$match->user1_name = $usernames[$match->user1_id];
|
||||
$match->user2_name = $usernames[$match->user2_id];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue