Added pairings to player object

This commit is contained in:
Jeroen De Meerleer 2019-04-20 16:55:39 +02:00
parent 68e519d78b
commit 5b93c46e4d
3 changed files with 39 additions and 2 deletions

View File

@ -10,6 +10,7 @@ namespace JeroenED\Libpairtwo\Models;
use JeroenED\Libpairtwo\Enums\Title;
use JeroenED\Libpairtwo\Enums\Gender;
use JeroenED\Libpairtwo\Pairing;
use DateTime;
class Player
@ -68,6 +69,9 @@ class Player
/** @var bool */
private $Absent;
/** @var Pairing[] */
private $Pairings;
/**
* @return string
*/
@ -359,4 +363,22 @@ class Player
{
$this->Absent = $Absent;
}
/**
* @return Pairing[]
*/
public function getPairings(): array
{
return $this->Pairings;
}
/**
* @param Pairing[] $Pairings
*/
public function setPairings(array $Pairings): void
{
$this->Pairings = $Pairings;
}
}

View File

@ -12,4 +12,16 @@ use JeroenED\Libpairtwo\Models\Player as PlayerModel;
class Player extends PlayerModel
{
/**
* Adds a pairing to the tournament
*
* @param Pairing $pairing
*/
public function addPairing(Pairing $pairing)
{
$newArray = $this->GetPairings();
$newArray[] = $pairing;
$this->setPairings($newArray);
}
}

View File

@ -89,20 +89,23 @@ class Tournament extends TournamentModel
*/
public function pairingsToRounds(): void
{
/** @var Pairing[] $pairings */
$pairings = $this->getPairings();
/** @var Pairing[] */
$cache = array();
foreach ($pairings as $pairing) {
// Add pairing to player
$pairing->getPlayer()->addPairing($pairing);
$round = $pairing->getRound();
$color = $pairing->getColor();
$opponent = null;
foreach ($cache as $key=>$cached) {
if (!is_null($cached)) {
if ($cached->getOpponent() == $pairing->getPlayer() && ($cached->getRound() == $pairing->getRound())) {
if (($cached->getOpponent() == $pairing->getPlayer()) && ($cached->getRound() == $pairing->getRound())) {
$opponent = $cached;
$cache[$key] == null;
$cache[$key] = null;
break;
}
}