mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-23 06:56:58 +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\Title;
|
||||||
use JeroenED\Libpairtwo\Enums\Gender;
|
use JeroenED\Libpairtwo\Enums\Gender;
|
||||||
|
use JeroenED\Libpairtwo\Pairing;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
class Player
|
class Player
|
||||||
@ -68,6 +69,9 @@ class Player
|
|||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $Absent;
|
private $Absent;
|
||||||
|
|
||||||
|
/** @var Pairing[] */
|
||||||
|
private $Pairings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -359,4 +363,22 @@ class Player
|
|||||||
{
|
{
|
||||||
$this->Absent = $Absent;
|
$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
|
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
|
public function pairingsToRounds(): void
|
||||||
{
|
{
|
||||||
|
/** @var Pairing[] $pairings */
|
||||||
$pairings = $this->getPairings();
|
$pairings = $this->getPairings();
|
||||||
|
|
||||||
/** @var Pairing[] */
|
/** @var Pairing[] */
|
||||||
$cache = array();
|
$cache = array();
|
||||||
|
|
||||||
foreach ($pairings as $pairing) {
|
foreach ($pairings as $pairing) {
|
||||||
|
// Add pairing to player
|
||||||
|
$pairing->getPlayer()->addPairing($pairing);
|
||||||
$round = $pairing->getRound();
|
$round = $pairing->getRound();
|
||||||
$color = $pairing->getColor();
|
$color = $pairing->getColor();
|
||||||
$opponent = null;
|
$opponent = null;
|
||||||
foreach ($cache as $key=>$cached) {
|
foreach ($cache as $key=>$cached) {
|
||||||
if (!is_null($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;
|
$opponent = $cached;
|
||||||
$cache[$key] == null;
|
$cache[$key] = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user