diff --git a/src/Enums/Color.php b/src/Enums/Color.php new file mode 100644 index 0000000..16353c3 --- /dev/null +++ b/src/Enums/Color.php @@ -0,0 +1,20 @@ +Player; + } + + /** + * @param Player $Player + */ + public function setPlayer(Player $Player): void + { + $this->Player = $Player; + } + + /** + * @return mixed + */ + public function getOpponent(): Player + { + return $this->Opponent; + } + + /** + * @param mixed $Opponent + */ + public function setOpponent(Player $Opponent): void + { + $this->Opponent = $Opponent; + } + + /** + * @return Color + */ + public function getColor(): Color + { + return $this->Color; + } + + /** + * @param Color $Color + */ + public function setColor(Color $Color): void + { + $this->Color = $Color; + } + + /** + * @return Result + */ + public function getResult(): Result + { + return $this->Result; + } + + /** + * @param Result $Result + */ + public function setResult(Result $Result): void + { + $this->Result = $Result; + } + + /** + * @return int + */ + public function getRound(): int + { + return $this->Round; + } + + /** + * @param int $Round + */ + public function setRound(int $Round): void + { + $this->Round = $Round; + } + + +} diff --git a/src/Models/Tournament.php b/src/Models/Tournament.php index bac122b..f4ff6ab 100644 --- a/src/Models/Tournament.php +++ b/src/Models/Tournament.php @@ -55,6 +55,7 @@ class Tournament private $Federation; private $Players; private $Year; + private $Pairings; /** * @return string @@ -376,4 +377,22 @@ class Tournament $this->Year = $Year; } + /** + * @return Pairing[] + */ + public function getPairings() + { + return $this->Pairings; + } + + /** + * @param Pairing[] $Pairings + */ + public function setPairings($Pairings): void + { + $this->Pairings = $Pairings; + } + + + } diff --git a/src/Pairing.php b/src/Pairing.php new file mode 100644 index 0000000..770a958 --- /dev/null +++ b/src/Pairing.php @@ -0,0 +1,16 @@ +getBinaryData("CurrentRound") > 0) { - // echo "go" . PHP_EOL; - for ($i = 0; $i < $sws->getBinaryData("CreatedRounds"); $i++) { - $game = new Game(); + for ($i = 0; $i < $sws->getBinaryData("NewPlayer"); $i++) { + for ($x = 0; $x < $sws->getBinaryData("CreatedRounds"); $x++) { + $pairing = new Pairing(); - $length = 4; - //echo $offset . "Opponent: " . self::ReadData('String', substr($swscontents, $offset, $length)) . PHP_EOL; - $offset += $length; + $pairing->setPlayer($sws->getTournament()->getPlayerById($i)); - $length = 1; - //echo $offset . "Color: " . self::ReadData('String', substr($swscontents, $offset, $length)) . PHP_EOL; - $offset += $length; + $length = 4; + $opponent = self::ReadData('Int', substr($swscontents, $offset, $length)); + if ($opponent != 4294967295) { + $pairing->setOpponent($sws->getTournament()->getPlayerById($opponent)); + } + $offset += $length; - $length = 1; - //echo $offset . "Result: " . self::ReadData('String', substr($swscontents, $offset, $length)) . PHP_EOL; - $offset += $length; + $length = 1; + $pairing->setColor(new Color(self::ReadData('Int', substr($swscontents, $offset, $length)))); + $offset += $length; + + $length = 1; + $pairing->setResult(new Result(self::ReadData('Int', substr($swscontents, $offset, $length)))); + $offset += $length; + + $pairing->setRound($x); + $offset += 2; + + $sws->getTournament()->addPairing($pairing); + } } - } return $sws; @@ -518,6 +530,7 @@ class Sws extends SwsModel } $hex = implode($hex); + $hex = ($hex == "") ? "00" : $hex; if ($type == 'Hex') { return $hex; } elseif ($type == 'Int') { diff --git a/src/Tournament.php b/src/Tournament.php index c258acd..ba3674f 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -53,6 +53,16 @@ class Tournament extends TournamentModel $this->setRounds($newArray); } + /** + * @param Pairing $pairing + */ + public function addPairing(Pairing $pairing) + { + $newArray = $this->GetPairings(); + $newArray[] = $pairing; + $this->setPairings($newArray); + } + /** * @return array */