diff --git a/composer.json b/composer.json index 93d2046..42317cd 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,8 @@ "keywords": ["chess", "frbe-kbsb", "pairtwo"], "license": "MIT", "require": { - "php": "^7.1" + "php": "^7.1", + "myclabs/php-enum": "^1.6" }, "require-dev": { "phpunit/phpunit": "^7.0", diff --git a/res/testsws.sws b/res/testsws.sws index faceb27..a9acb25 100644 Binary files a/res/testsws.sws and b/res/testsws.sws differ diff --git a/src/Models/Tournament.php b/src/Models/Tournament.php index a39a764..9bdc627 100644 --- a/src/Models/Tournament.php +++ b/src/Models/Tournament.php @@ -35,6 +35,7 @@ class Tournament { private $Name; private $Organiser; + private $OrganiserClubNo; private $OrganiserClub; private $OrganiserPlace; private $OrganiserCountry; @@ -47,6 +48,9 @@ class Tournament private $Tempo; private $NonRatedElo; private $System; + private $FirstPeriod; + private $SecondPeriod; + private $Federation; /** * @return string @@ -81,7 +85,7 @@ class Tournament } /** - * @return integer + * @return String */ public function getOrganiserClub() { @@ -89,13 +93,29 @@ class Tournament } /** - * @param integer $OrganiserClub + * @param String $OrganiserClub */ public function setOrganiserClub($OrganiserClub): void { $this->OrganiserClub = $OrganiserClub; } + /** + * @return integer + */ + public function getOrganiserClubNo() + { + return $this->OrganiserClubNo; + } + + /** + * @param integer $OrganiserClubno + */ + public function setOrganiserClubNo($OrganiserClubNo): void + { + $this->OrganiserClubNo = $OrganiserClubNo; + } + /** * @return string */ @@ -257,7 +277,7 @@ class Tournament } /** - * @return integer + * @return TournamentSystem */ public function getSystem() { @@ -265,12 +285,60 @@ class Tournament } /** - * @param integer $System + * @param TournamentSystem $System */ public function setSystem($System): void { $this->System = $System; } + /** + * @return String + */ + public function getFirstPeriod() + { + return $this->FirstPeriod; + } + + /** + * @param String $FirstPeriod + */ + public function setFirstPeriod($FirstPeriod): void + { + $this->FirstPeriod = $FirstPeriod; + } + + /** + * @return String + */ + public function getSecondPeriod() + { + return $this->SecondPeriod; + } + + /** + * @param String $SecondPeriod + */ + public function setSecondPeriod($SecondPeriod): void + { + $this->SecondPeriod = $SecondPeriod; + } + + /** + * @return String + */ + public function getFederation() + { + return $this->Federation; + } + + /** + * @param String $Federation + */ + public function setFederation($Federation): void + { + $this->Federation = $Federation; + } + } diff --git a/src/Models/TournamentSystem.php b/src/Models/TournamentSystem.php new file mode 100644 index 0000000..2919527 --- /dev/null +++ b/src/Models/TournamentSystem.php @@ -0,0 +1,19 @@ +getTournament()->setStartDate(self::UIntToTimestamp(hexdec(self::readhexdata(substr($swscontents, $offset, $length))))); $offset += $length; @@ -284,6 +284,63 @@ class Sws $sws->getTournament()->setEndDate(self::UIntToTimestamp(hexdec(self::readhexdata(substr($swscontents, $offset, $length))))); $offset += $length; + // Place + $length = 36; + $sws->getTournament()->setOrganiserPlace(substr($swscontents, $offset, $length)); + $offset += $length; + + // First period + $length = 32; + $sws->getTournament()->setFirstPeriod(substr($swscontents, $offset, $length)); + $offset += $length; + + // Second period + $length = 32; + $sws->getTournament()->setSecondPeriod(substr($swscontents, $offset, $length)); + $offset += $length; + + // Unrated Elo + $length = 4; + $sws->getTournament()->setNonRatedElo(hexdec(self::readhexdata(substr($swscontents, $offset, $length)))); + $offset += $length; + + // Type + $length = 4; + $sws->getTournament()->setSystem(new TournamentSystem(hexdec(self::readhexdata(substr($swscontents, $offset, $length))))); + $offset += $length; + + // Federation + $length = 12; + $sws->getTournament()->setFederation(substr($swscontents, $offset, $length)); + $offset += $length; + + // Soustype + /* + * 32 Bits: + * 1 bit = Libre? + * 6 bits = First round sent to FIDE + * 6 bits = First round sent to FRBE-KBSB + * 6 bits = Last round sent to FIDE + * 6 bits = Last round sent to FRBE-KBSB + * 6 bits = Number of the First board + * 1 bit = Double round robin + */ + $length = 4; + $sws->setBinaryData('SousType', self::readhexdata(substr($swscontents, $offset, $length))); + $offset += $length; + + // Organising club no + $length = 4; + $sws->getTournament()->setOrganiserClubNo(substr($swscontents, $offset, $length)); + echo dechex($offset); + $offset += $length; + + // Organising club + $length = 12; + $sws->getTournament()->setOrganiserClub(substr($swscontents, $offset, $length)); + $offset += $length; + + return $sws; } diff --git a/tests/ReadSws_test.php b/tests/ReadSws_test.php index 0760b91..a24dd5a 100644 --- a/tests/ReadSws_test.php +++ b/tests/ReadSws_test.php @@ -28,16 +28,20 @@ Use JeroenED\Libpairtwo\Sws; require_once '../vendor/autoload.php'; $sws = Sws::readSws('../res/testsws.sws'); -echo "Name: " . $sws->getTournament()->getName() . "\n"; -echo "Organiser: " . $sws->getTournament()->getOrganiser(). "\n"; -echo "Tempo: " . $sws->getTournament()->getTempo() . "\n"; -echo "Country: " . $sws->getTournament()->getOrganiserCountry() . "\n"; -echo "Arbiter: " . $sws->getTournament()->getArbiter() . "\n"; -echo "Rounds: " . $sws->getTournament()->getRounds() . "\n"; -echo "Participants: " . $sws->getTournament()->getRounds() . "\n"; -echo "Fidehomol: " . $sws->getTournament()->getFideHomol() . "\n"; -echo "Start-Date: " . $sws->getTournament()->getStartDate()->format('d/m/Y') . "\n"; -echo "Start-Date: " . $sws->getTournament()->getEndDate()->format('d/m/Y') . "\n"; -//echo "Start-Date hex: " . $sws->getBinaryData("startdate") . "\n"; +echo "Name: " . $sws->getTournament()->getName() . PHP_EOL; +echo "Organiser: " . $sws->getTournament()->getOrganiser(). PHP_EOL; +echo "Tempo: " . $sws->getTournament()->getTempo() . PHP_EOL; +echo "Country: " . $sws->getTournament()->getOrganiserCountry() . PHP_EOL; +echo "Arbiter: " . $sws->getTournament()->getArbiter() . PHP_EOL; +echo "Rounds: " . $sws->getTournament()->getRounds() . PHP_EOL; +echo "Participants: " . $sws->getTournament()->getRounds() . PHP_EOL; +echo "Fidehomol: " . $sws->getTournament()->getFideHomol() . PHP_EOL; +echo "Start-Date: " . $sws->getTournament()->getStartDate()->format('d/m/Y') . PHP_EOL; +echo "End-Date: " . $sws->getTournament()->getEndDate()->format('d/m/Y') . PHP_EOL; +echo "System: " . $sws->getTournament()->getSystem()->getKey() . PHP_EOL; +echo "Place: " . $sws->getTournament()->getOrganiserPlace() . PHP_EOL; +echo "Unrated-Elo: " . $sws->getTournament()->getNonRatedElo() . PHP_EOL; +echo "Federatiop: " . $sws->getTournament()->getFederation() . PHP_EOL; +echo "Organiser: " . $sws->getTournament()->getOrganiserClubNo() . PHP_EOL; //echo $sws->getBinaryData("Tournament"); //echo $sws->getBinaryData("Players");