New feature: get pairings from round objects

This commit is contained in:
Jeroen De Meerleer 2019-05-01 15:50:44 +02:00
parent c9b88c3528
commit 1e6858d18b
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
3 changed files with 38 additions and 0 deletions

View File

@ -9,6 +9,8 @@
namespace JeroenED\Libpairtwo\Models; namespace JeroenED\Libpairtwo\Models;
use DateTime; use DateTime;
use JeroenED\Libpairtwo\Game;
use JeroenED\Libpairtwo\Pairing;
class Round class Round
{ {
@ -21,6 +23,9 @@ class Round
/** @var int */ /** @var int */
private $roundNo; private $roundNo;
/** @var Pairing[] */
private $pairings = [];
/** /**
* @return DateTime * @return DateTime
* *
@ -69,4 +74,21 @@ class Round
{ {
$this->roundNo = $roundNo; $this->roundNo = $roundNo;
} }
/**
* @return Pairing[]
*/
public function getPairings(): array
{
return $this->pairings;
}
/**
* @param Pairing[] $pairings
*/
public function setPairings(array $pairings): void
{
$this->pairings = $pairings;
}
} }

View File

@ -9,6 +9,8 @@
namespace JeroenED\Libpairtwo; namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Models\Round as RoundModel; use JeroenED\Libpairtwo\Models\Round as RoundModel;
use JeroenED\Libpairtwo\Game;
use JeroenED\Libpairtwo\Pairing;
class Round extends RoundModel class Round extends RoundModel
{ {
@ -23,4 +25,16 @@ class Round extends RoundModel
$newarray[] = $game; $newarray[] = $game;
$this->setGames($newarray); $this->setGames($newarray);
} }
/**
* Adds a pairing to the round
*
* @param Pairing $pairing
*/
public function addPairing(Pairing $pairing)
{
$newarray = $this->getPairings();
$newarray[] = $pairing;
$this->setPairings($newarray);
}
} }

View File

@ -100,6 +100,8 @@ class Tournament extends TournamentModel
$pairing->getPlayer()->addPairing($pairing); $pairing->getPlayer()->addPairing($pairing);
$round = $pairing->getRound(); $round = $pairing->getRound();
$color = $pairing->getColor(); $color = $pairing->getColor();
$this->getRoundByNo($round)->addPairing($pairing);
$opponent = null; $opponent = null;
foreach ($cache as $key=>$cached) { foreach ($cache as $key=>$cached) {
if (!is_null($cached)) { if (!is_null($cached)) {