Created function Round::getGamesbyBoard

This commit is contained in:
Jeroen De Meerleer 2019-09-28 21:19:35 +02:00
parent 5314bc47f2
commit 575b786079
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -117,6 +117,33 @@ class Round
return $absentPairings; 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 * Returns the date of the round
* *
@ -191,7 +218,7 @@ class Round
{ {
return $this->Pairings; return $this->Pairings;
} }
/** /**
* Sets an array of all pairings for the round * Sets an array of all pairings for the round
* *