Better sorting function

This commit is contained in:
Jeroen De Meerleer 2019-02-06 18:22:25 +01:00
parent c9d5407f0c
commit 93125bb79c
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -58,19 +58,14 @@ class Tournament extends TournamentModel
public function getRanking()
{
$players = $this->getPlayers();
$rankingsArray = array();
foreach ($players as $player) {
$rankingsArray[$player->getPoints()] = $player;
}
ksort($rankingsArray);
$finalArray = array();
$i = 0;
foreach ($rankingsArray as $ranking) {
$finalArray[$i] = $ranking;
$i++;
usort($players, array($this, "cmp"));
return $players;
}
return $finalArray;
private function cmp($a, $b)
{
return $b->getPoints() - $a->getPoints();
}
}