Updated to support american sorting

This commit is contained in:
Jeroen De Meerleer 2019-02-06 20:10:52 +01:00
parent 2bc179c0bb
commit d1d4806b0b
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 28CCCB8F62BFADD6
1 changed files with 19 additions and 3 deletions

View File

@ -9,6 +9,7 @@
namespace JeroenED\Libpairtwo; namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Models\Tournament as TournamentModel; use JeroenED\Libpairtwo\Models\Tournament as TournamentModel;
use phpDocumentor\Reflection\Types\Boolean;
class Tournament extends TournamentModel class Tournament extends TournamentModel
{ {
@ -55,17 +56,32 @@ class Tournament extends TournamentModel
/** /**
* @return array * @return array
*/ */
public function getRanking() public function getRanking(bool $sort)
{ {
$players = $this->getPlayers(); $players = $this->getPlayers();
usort($players, array($this, "cmp")); $sort ? usort($players, array($this, "SortNormal")) : usort($players, array($this, "SortAmerican"));
return $players; return $players;
} }
private function cmp($a, $b) /**
* @param $a
* @param $b
* @return mixed
*/
private function sortNormal($a, $b)
{ {
return $b->getPoints() - $a->getPoints(); return $b->getPoints() - $a->getPoints();
} }
/**
* @param $a
* @param $b
* @return mixed
*/
private function sortAmerican($a, $b)
{
return $b->getScoreAmerican() - $a->getScoreAmerican();
}
} }