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

View file

@ -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];