mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-12-23 12:50:59 +01:00
Added pairings to player object
This commit is contained in:
parent
fc2292414f
commit
b265e4c23d
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user