Arbeit an Auf/Abstieg

This commit is contained in:
Torsten 2017-10-16 11:19:57 +02:00
parent 8edec26147
commit ed0c445bfa
5 changed files with 107 additions and 18 deletions

View file

@ -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();
}
}
}
}