Added some useful functions

This commit is contained in:
Jeroen De Meerleer 2019-05-30 21:01:30 +02:00
parent 374e339353
commit 9bf31b7ec5
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -96,4 +96,35 @@ class Player extends PlayerModel
$this->setIds($currentIds); $this->setIds($currentIds);
return $this; return $this;
} }
/**
* @return int
*/
public function getNoOfWins()
{
$wins = 0;
foreach ($this->getPairings() as $pairing) {
if (array_search($pairing->getResult(), Constants::Won) !== false) {
$wins++;
}
}
return $wins;
}
/**
* @param Player $player
* @return float|null
*/
public function getPoints(): float
{
$points = 0;
foreach ($this->getPairings() as $pairing) {
if (array_search($pairing->getResult(), Constants::Won) !== false) {
$points = $points + 1;
} elseif (array_search($pairing->getResult(), Constants::Draw) !== false) {
$points = $points + 0.5;
}
}
return $points;
}
} }