From 17c924b45cde55042da36e228ab86084a1407fb6 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 1 Feb 2019 15:55:34 +0100 Subject: [PATCH] Added some more fields --- src/Models/Player.php | 22 +++++-- src/Models/Tournament.php | 18 ++++++ src/Sws.php | 130 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 162 insertions(+), 8 deletions(-) diff --git a/src/Models/Player.php b/src/Models/Player.php index 82e692d..e817f9b 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -30,6 +30,7 @@ class Player private $Category; private $Title; private $Sex; + private $NumberOfTies; private $Absent; /** @@ -294,6 +295,22 @@ class Player $this->Sex = $Sex; } + /** + * @return mixed + */ + public function getNumberOfTies() + { + return $this->NumberOfTies; + } + + /** + * @param mixed $NumberOfTies + */ + public function setNumberOfTies($NumberOfTies): void + { + $this->NumberOfTies = $NumberOfTies; + } + /** * @return mixed */ @@ -309,7 +326,4 @@ class Player { $this->Absent = $Absent; } - - - -} \ No newline at end of file +} diff --git a/src/Models/Tournament.php b/src/Models/Tournament.php index 9bdc627..55dc789 100644 --- a/src/Models/Tournament.php +++ b/src/Models/Tournament.php @@ -25,6 +25,8 @@ */ namespace JeroenED\Libpairtwo\Models; +use JeroenED\Libpairtwo\Enums\TournamentSystem; + /** * Description of Sws @@ -51,6 +53,7 @@ class Tournament private $FirstPeriod; private $SecondPeriod; private $Federation; + private $Players; /** * @return string @@ -340,5 +343,20 @@ class Tournament $this->Federation = $Federation; } + /** + * @return array + */ + public function getPlayers() + { + return $this->Players; + } + + /** + * @param array $Players + */ + public function setPlayers($Players): void + { + $this->Players = $Players; + } } diff --git a/src/Sws.php b/src/Sws.php index 925a552..6ad0fb7 100644 --- a/src/Sws.php +++ b/src/Sws.php @@ -41,7 +41,6 @@ class Sws extends SwsModel private const PT_DAYFACTOR = 32; private const PT_MONTHFACTOR = 16; private const PT_YEARFACTOR = 512; - private const PT_SYSTEMYEAR = 1900; private const PT_PASTOFFSET = 117; @@ -226,12 +225,125 @@ class Sws extends SwsModel $offset += $length; // Players - $length = 68 * $sws->getBinaryData("NewPlayer"); + for ($i = 0; $i < $sws->getBinaryData("NewPlayer"); $i++) { + $player = new Player(); + + $length = 4; + $player->SetRank(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $sws->setBinaryData("Players($i)_NamePos", self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $player->SetFideId(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $player->SetExtraPts(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $player->SetKbsbElo(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $player->SetDateOfBirth(self::ReadData('Date', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $player->setKbsbID(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $player->setPoints(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $player->setClubNr(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $player->setScoreBucholtz(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $player->setScoreAmerican(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $sws->setBinaryData("Players($i)_HelpValue", self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 4; + $player->setFideElo(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $sws->setBinaryData("Players($i)_NameLength", self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 3; + $player->setNation(self::ReadData('String', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $player->setCategory(self::ReadData('String', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $player->setTitle(new Title(self::ReadData('Int', substr($swscontents, $offset, $length)))); + $offset += $length; + + $length = 1; + $player->setSex(new Sex(self::ReadData('Int', substr($swscontents, $offset, $length)))); + $offset += $length; + + $length = 1; + $player->setNumberOfTies(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $player->setAbsent(self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $sws->setBinaryData("Players($i)_ColorDiff", self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $sws->setBinaryData("Players($i)_ColorPref", self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $sws->setBinaryData("Players($i)_Paired", self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $sws->setBinaryData("Players($i)_Float", self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $sws->setBinaryData("Players($i)_FloatPrev", self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $sws->setBinaryData("Players($i)_FloatBefore", self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $length = 1; + $sws->setBinaryData("Players($i)_TieMatch", self::ReadData('Int', substr($swscontents, $offset, $length))); + $offset += $length; + + $sws->getTournament()->addPlayer($player); + } + /* $length = 68 * $sws->getBinaryData("NewPlayer"); $sws->setBinaryData("Players", self::ReadData('String', substr($swscontents, $offset, $length))); - $offset += $length; + $offset += $length;*/ // PlayerNames - $length = $sws->getBinaryData("NewNamePos"); + $length = (Integer)$sws->getBinaryData("NewNamePos") + 0; $sws->setBinaryData("PlayerNames", self::ReadData('String', substr($swscontents, $offset, $length))); $offset += $length; @@ -344,6 +456,11 @@ class Sws extends SwsModel return $sws; } + /** + * @param String $type + * @param String $data + * @return array|bool|\DateTime|float|int|string + */ private static function ReadData(String $type, String $data) { switch ($type) { @@ -378,8 +495,13 @@ class Sws extends SwsModel break; } + return false; } + /** + * @param $date + * @return bool|\DateTime + */ private static function UIntToTimestamp($date) { $curyear = date('Y');