From 575b786079a879bdc0a7efa7c1008da6dde1bdd9 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Sat, 28 Sep 2019 21:19:35 +0200 Subject: [PATCH] Created function Round::getGamesbyBoard --- src/Round.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Round.php b/src/Round.php index 8e07278..ca73537 100644 --- a/src/Round.php +++ b/src/Round.php @@ -117,6 +117,33 @@ class Round return $absentPairings; } + /** + * Retuns an array with the games of this round sorted by board + * + * @return Game[] + */ + public function getGamesByBoard(): array + { + $allGames = $this->getGames(); + usort($allGames, array($this, 'sortByBoard')); + return $allGames; + } + + /** + * Sort by board + * + * @param Game $a + * @param Game $b + * @return int + */ + private function sortByBoard(Game $a, Game $b): int + { + if (($a->getBoard() == $b->getBoard()) || ($a->getBoard() === false) || ($b->getBoard() === false)) { + return 0; + } + return ($a->getBoard() > $b->getBoard()) ? +1 : -1; + } + /** * Returns the date of the round * @@ -191,7 +218,7 @@ class Round { return $this->Pairings; } - + /** * Sets an array of all pairings for the round *