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;
use DateTime;
use JeroenED\Libpairtwo\Game;
use JeroenED\Libpairtwo\Pairing;
class Round
{
@ -21,6 +23,9 @@ class Round
/** @var int */
private $roundNo;
/** @var Pairing[] */
private $pairings = [];
/**
* @return DateTime
*
@ -69,4 +74,21 @@ class Round
{
$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;
use JeroenED\Libpairtwo\Models\Round as RoundModel;
use JeroenED\Libpairtwo\Game;
use JeroenED\Libpairtwo\Pairing;
class Round extends RoundModel
{
@ -23,4 +25,16 @@ class Round extends RoundModel
$newarray[] = $game;
$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);
$round = $pairing->getRound();
$color = $pairing->getColor();
$this->getRoundByNo($round)->addPairing($pairing);
$opponent = null;
foreach ($cache as $key=>$cached) {
if (!is_null($cached)) {