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() public function getRanking()
{ {
$players = $this->getPlayers(); $players = $this->getPlayers();
$rankingsArray = array();
foreach ($players as $player) {
$rankingsArray[$player->getPoints()] = $player;
}
ksort($rankingsArray);
$finalArray = array(); usort($players, array($this, "cmp"));
$i = 0;
foreach ($rankingsArray as $ranking) {
$finalArray[$i] = $ranking;
$i++;
}
return $finalArray; return $players;
}
private function cmp($a, $b)
{
return $b->getPoints() - $a->getPoints();
} }
} }