From fbe5bbc7cc27f726e32fe13571b2afac6c736d5d Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 15 Jul 2019 13:39:38 +0200 Subject: [PATCH 01/19] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3996f20..7e43d6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CHANGELOG ## vx.y.z (Release: aa-bbb-cccc) +* NEW READER: `swar-4` for reading out files created with Swar version 4. ## v1.1.2 (Release: 21-jun-2019) * ENHANCEMENT: Added update section to dist/readme.md From 21fb6a70bb58581f45685fe2a1914f57c17f1413 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 15 Jul 2019 13:40:33 +0200 Subject: [PATCH 02/19] Added Swar-4 reader to IOFactory --- src/IOFactory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/IOFactory.php b/src/IOFactory.php index 78af8c9..c5f97c5 100644 --- a/src/IOFactory.php +++ b/src/IOFactory.php @@ -34,6 +34,7 @@ abstract class IOFactory * @var array */ private static $readers = [ + 'Swar-4' => Readers\Swar4::class, 'Pairtwo-6' => Readers\Pairtwo6::class, 'Pairtwo-5' => Readers\Pairtwo6::class // File structure identical ]; @@ -42,7 +43,7 @@ abstract class IOFactory /** * Creates a reader for $type * - * Compatible types are Pairtwo-5 and Pairtwo-6 + * Compatible types are Swar-4, Pairtwo-5, Pairtwo-6 * * @param string $type * @return ReaderInterface From 2791a1051f6bb7feff999e6ebf060ae28d35de18 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 15 Jul 2019 13:47:24 +0200 Subject: [PATCH 03/19] implemented reader template --- src/Readers/Swar4.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/Readers/Swar4.php diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php new file mode 100644 index 0000000..a6a1060 --- /dev/null +++ b/src/Readers/Swar4.php @@ -0,0 +1,33 @@ + + * @category Main + * @package Libpairtwo + * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer + */ + + +namespace JeroenED\Libpairtwo\Readers; + +use JeroenED\Libpairtwo\Interfaces\ReaderInterface; +use JeroenED\Libpairtwo\Tournament; + +class Swar4 implements ReaderInterface +{ + /** @var Tournament */ + private $tournament; + + public function read(string $filename): ReaderInterface + { + // TODO: Implement read() method. + } + + public function getTournament(): Tournament + { + return $this->tournament; + } +} From d370aad1906de59ecf0d1b4b0016487beb43450e Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 15 Jul 2019 14:43:23 +0200 Subject: [PATCH 04/19] Reading out first data --- src/Readers/Swar4.php | 139 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index a6a1060..3d452b6 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -13,21 +13,158 @@ namespace JeroenED\Libpairtwo\Readers; +use DateTime; use JeroenED\Libpairtwo\Interfaces\ReaderInterface; use JeroenED\Libpairtwo\Tournament; +/** + * Class Swar4 + * @package JeroenED\Libpairtwo\Readers + */ class Swar4 implements ReaderInterface { /** @var Tournament */ private $tournament; + /** @var bool|int|DateTime|string[] */ + private $binaryData; + + /** @var string */ + private $release; + + /** + * @param string $filename + * @return ReaderInterface + */ public function read(string $filename): ReaderInterface { - // TODO: Implement read() method. + $swshandle = fopen($filename, 'rb'); + + $this->setRelease($this->readData('String', $swshandle)); + + $this->setTournament(new Tournament()); + + + fclose($swshandle); + + return $this; } + /** + * @return Tournament + */ public function getTournament(): Tournament { return $this->tournament; } + + /** + * @param Tournament $tournament + */ + public function setTournament(Tournament $tournament): void + { + $this->tournament = $tournament; + } + + + /** + * @param string $type + * @param $handle + * @return array|bool|false|float|int|string + */ + private function readData(string $type, $handle, $default = null) + { + switch ($type) { + case 'String': + $length = $this->readData('Int', $handle); + $data = fread($handle, $length); + if ($data == '') { + return (is_null($default)) ? '' : $default; + } + return iconv('windows-1252', 'utf-8', $data); + break; + case 'Hex': + case 'Int': + case 'Bool': + case 'Date': + $data = fread($handle, 4); + $hex = implode(unpack("H*", $data)); + $hex = array_reverse(str_split($hex, 2)); + + foreach ($hex as $key => $item) { + if ($item == "00") { + $hex[$key] = ""; + } else { + break; + } + } + + $hex = implode($hex); + $hex = ($hex == "") ? "00" : $hex; + if ($type == 'Hex') { + if ($hex == '00') { + return (is_null($default)) ? '00' : $default; + } + return $hex; + } elseif ($type == 'Int') { + if ($hex == '00') { + return (is_null($default)) ? 0 : $default; + } + return hexdec($hex); + } elseif ($type == 'Date') { + if ($hex == '00') { + return (is_null($default)) ? $this->convertUIntToTimestamp(0) : $default; + } + return $this->convertUIntToTimestamp(hexdec($hex)); + } elseif ($type == 'Bool') { + return ($hex == "01") ? true : false; + } + break; + default: + throw new \InvalidArgumentException("Datatype not known"); + break; + } + + return false; + } + + /** + * @return string + */ + public function getRelease(): string + { + return $this->release; + } + + /** + * @param string $release + */ + public function setRelease(string $release): void + { + $this->release = $release; + } + + /** + * Returns binary data that was read out the pairtwo file but was not needed immediately + * + * @param string $Key + * @return bool|DateTime|int|string + */ + public function getBinaryData(string $Key) + { + return $this->BinaryData[$Key]; + } + + /** + * Sets binary data that is read out the pairtwo file but is not needed immediately + * + * @param string $Key + * @param bool|int|DateTime|string $Value + * @return Pairtwo6 + */ + public function setBinaryData(string $Key, $Value): Pairtwo6 + { + $this->BinaryData[$Key] = $Value; + return $this; + } } From 38e67a426153bbfc8d894c865242f37be5699545 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Tue, 16 Jul 2019 15:58:53 +0200 Subject: [PATCH 05/19] Added binaryData --- src/Tournament.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Tournament.php b/src/Tournament.php index 31ce517..8d2414c 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -102,6 +102,9 @@ class Tournament /** @var string */ private $PriorityId = 'Nation'; + /** @var bool|DateTime|int|string[] */ + private $binaryData = []; + /** * Gets a player by its ID * @@ -1313,4 +1316,28 @@ class Tournament $this->PriorityId = $PriorityId; return $this; } + + /** + * Returns binary data that was read out the pairing file but was not needed immediately + * + * @param string $Key + * @return bool|DateTime|int|string + */ + public function getBinaryData(string $Key) + { + return $this->BinaryData[$Key]; + } + + /** + * Sets binary data that is read out the pairing file but is not needed immediately + * + * @param string $Key + * @param bool|int|DateTime|string $Value + * @return Pairtwo6 + */ + public function setBinaryData(string $Key, $Value): Tournament + { + $this->BinaryData[$Key] = $Value; + return $this; + } } From ac908ea814bc9026893e4d2289d483134f96af60 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Tue, 16 Jul 2019 16:06:50 +0200 Subject: [PATCH 06/19] Reading out date fields --- src/Readers/Swar4.php | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index 3d452b6..bc9a3d9 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -76,17 +76,30 @@ class Swar4 implements ReaderInterface { switch ($type) { case 'String': + case 'Date': $length = $this->readData('Int', $handle); - $data = fread($handle, $length); - if ($data == '') { - return (is_null($default)) ? '' : $default; + echo $length . ' '; + if ($length == 0) { + return ''; + } + $data = fread($handle, $length); + if ($type == 'String') { + if ($data == '') { + return (is_null($default)) ? '' : $default; + } + echo $data . PHP_EOL; + return iconv('windows-1252', 'utf-8', $data); + } elseif ($type == 'Date') { + echo $data . 'date' . PHP_EOL; + if ($data == '') { + return (is_null($default)) ? $this->convertStringToDate('01/01/1900') : $default; + } + return $this->convertStringToDate($data); } - return iconv('windows-1252', 'utf-8', $data); break; case 'Hex': case 'Int': case 'Bool': - case 'Date': $data = fread($handle, 4); $hex = implode(unpack("H*", $data)); $hex = array_reverse(str_split($hex, 2)); @@ -111,11 +124,6 @@ class Swar4 implements ReaderInterface return (is_null($default)) ? 0 : $default; } return hexdec($hex); - } elseif ($type == 'Date') { - if ($hex == '00') { - return (is_null($default)) ? $this->convertUIntToTimestamp(0) : $default; - } - return $this->convertUIntToTimestamp(hexdec($hex)); } elseif ($type == 'Bool') { return ($hex == "01") ? true : false; } @@ -145,7 +153,7 @@ class Swar4 implements ReaderInterface } /** - * Returns binary data that was read out the pairtwo file but was not needed immediately + * Returns binary data that was read out the swar file but was not needed immediately * * @param string $Key * @return bool|DateTime|int|string @@ -156,15 +164,21 @@ class Swar4 implements ReaderInterface } /** - * Sets binary data that is read out the pairtwo file but is not needed immediately + * Sets binary data that is read out the swar file but is not needed immediately * * @param string $Key * @param bool|int|DateTime|string $Value * @return Pairtwo6 */ - public function setBinaryData(string $Key, $Value): Pairtwo6 + public function setBinaryData(string $Key, $Value): Swar4 { $this->BinaryData[$Key] = $Value; return $this; } + + public function convertStringToDate(string $string): \DateTime + { + echo $string; + return DateTime::createFromFormat('d/m/Y', $string); + } } From f3de844a4c17581a56fa61ecb4e3aab5047bcb55 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Tue, 16 Jul 2019 16:07:20 +0200 Subject: [PATCH 07/19] Reading out some more fields --- src/Readers/Swar4.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index bc9a3d9..1d95b58 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -44,6 +44,23 @@ class Swar4 implements ReaderInterface $this->setTournament(new Tournament()); + $this->setBinaryData('Guid', $this->readData('String', $swshandle)); + $this->setBinaryData('MacAddress', $this->readData('String', $swshandle)); + $this->setBinaryData('[Tournoi]', $this->readData('String', $swshandle)); + $this->getTournament()->setName($this->readData('String', $swshandle)); + $this->getTournament()->setOrganiser($this->readData('String', $swshandle)); + $this->getTournament()->setOrganiserClub($this->readData('String', $swshandle)); + $this->getTournament()->setOrganiserPlace($this->readData('String', $swshandle)); + + // @todo: Make arbiter an array to set multiple arbiters + $this->getTournament()->setArbiter($this->readData('String', $swshandle)); + $this->getTournament()->setBinaryData('Arbiter2', $this->readData('String', $swshandle)); + + $this->getTournament()->setStartDate($this->readData('Date', $swshandle)); + $this->getTournament()->setEndDate($this->readData('Date', $swshandle)); + + // Tempo string is not variable and dependant on kind of tournament + $this->getTournament()->setBinaryData('TempoIndex', $this->readData('Int', $swshandle)); fclose($swshandle); From 7cb1c512a97f696377cf5524bd57187e913758ce Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Tue, 16 Jul 2019 16:10:53 +0200 Subject: [PATCH 08/19] Removed debug output --- src/Readers/Swar4.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index 1d95b58..7318903 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -95,7 +95,6 @@ class Swar4 implements ReaderInterface case 'String': case 'Date': $length = $this->readData('Int', $handle); - echo $length . ' '; if ($length == 0) { return ''; } @@ -104,10 +103,8 @@ class Swar4 implements ReaderInterface if ($data == '') { return (is_null($default)) ? '' : $default; } - echo $data . PHP_EOL; return iconv('windows-1252', 'utf-8', $data); } elseif ($type == 'Date') { - echo $data . 'date' . PHP_EOL; if ($data == '') { return (is_null($default)) ? $this->convertStringToDate('01/01/1900') : $default; } @@ -195,7 +192,6 @@ class Swar4 implements ReaderInterface public function convertStringToDate(string $string): \DateTime { - echo $string; return DateTime::createFromFormat('d/m/Y', $string); } } From d131cf403eab999bc58b18a9c23fc8f5edcdea04 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Sat, 3 Aug 2019 13:50:34 +0200 Subject: [PATCH 09/19] Added double swiss as tournament system --- src/Enums/TournamentSystem.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Enums/TournamentSystem.php b/src/Enums/TournamentSystem.php index 2109555..0028632 100644 --- a/src/Enums/TournamentSystem.php +++ b/src/Enums/TournamentSystem.php @@ -27,6 +27,7 @@ use MyCLabs\Enum\Enum; class TournamentSystem extends Enum { const Swiss = 'Swiss'; + const DoubleSwiss = 'Swiss Double'; const Closed = 'Closed'; const American = 'American'; const Keizer = 'Keizer'; From f491a86ab63caad67431f8491ced3e72522b2d62 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Sat, 3 Aug 2019 13:51:21 +0200 Subject: [PATCH 10/19] reading out more fields --- src/Readers/Swar4.php | 52 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index 7318903..e262294 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -14,6 +14,7 @@ namespace JeroenED\Libpairtwo\Readers; use DateTime; +use JeroenED\Libpairtwo\Enums\TournamentSystem; use JeroenED\Libpairtwo\Interfaces\ReaderInterface; use JeroenED\Libpairtwo\Tournament; @@ -62,6 +63,50 @@ class Swar4 implements ReaderInterface // Tempo string is not variable and dependant on kind of tournament $this->getTournament()->setBinaryData('TempoIndex', $this->readData('Int', $swshandle)); + $this->getTournament()->setNoOfRounds($this->readData('Int', $swshandle)); + + $this->getTournament()->setBinaryData('FRBEfrom', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('FRBEto', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('FIDEfrom', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('FIDEto', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('CatSepares', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('AfficherEloOuPays', $this->readData('Int', $swshandle)); + + $this->getTournament()->setFideHomol($this->readData('Int', $swshandle)); + + $this->getTournament()->setBinaryData('FideId', $this->readData('String', $swshandle)); + $this->getTournament()->setBinaryData('FideArbitre1', $this->readData('String', $swshandle)); + $this->getTournament()->setBinaryData('FideArbitre2', $this->readData('String', $swshandle)); + $this->getTournament()->setBinaryData('FideEmail', $this->readData('String', $swshandle)); + $this->getTournament()->setBinaryData('FideRemarques', $this->readData('String', $swshandle)); + + $typeIndex = $this->readData('Int', $swshandle); + + + $this->getTournament()->setBinaryData('Dummy1', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Dummy2', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('SW_AmerPresence', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Plusieurs', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('FirstTable', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('SW321_Win', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('SW321_Nul', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('SW321_Los', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('SW321_Bye', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('SW321_Pre', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('EloUsed', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('TournoiStd', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('TbPersonel', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('ApparOrder', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('EloEqual', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('ByeValue', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('AbsValue', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('FF_Value', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Federation', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('[DATES]', $this->readData('String', $swshandle)); + + for ($i = 0; $i < $this->getTournament()->getNoOfRounds(); $i++) { + $this->getTournament()->setBinaryData('Round_' . $i . '_date', $this->readData('Date', $swshandle)); + } fclose($swshandle); return $this; @@ -87,7 +132,8 @@ class Swar4 implements ReaderInterface /** * @param string $type * @param $handle - * @return array|bool|false|float|int|string + * @param null $default + * @return array|bool|DateTime|false|float|int|string|null */ private function readData(string $type, $handle, $default = null) { @@ -190,6 +236,10 @@ class Swar4 implements ReaderInterface return $this; } + /** + * @param string $string + * @return DateTime + */ public function convertStringToDate(string $string): \DateTime { return DateTime::createFromFormat('d/m/Y', $string); From f925e08c296113a70841e9994e3f76e1eaa6ed90 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Sat, 3 Aug 2019 13:51:52 +0200 Subject: [PATCH 11/19] Don't read out old swar versions --- src/Readers/Swar4.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index e262294..a1b0173 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -15,6 +15,7 @@ namespace JeroenED\Libpairtwo\Readers; use DateTime; use JeroenED\Libpairtwo\Enums\TournamentSystem; +use JeroenED\Libpairtwo\Exceptions\IncompatibleReaderException; use JeroenED\Libpairtwo\Interfaces\ReaderInterface; use JeroenED\Libpairtwo\Tournament; @@ -33,9 +34,14 @@ class Swar4 implements ReaderInterface /** @var string */ private $release; + /** @var array */ + private const CompatibleVersions = ['v4.']; + + /** * @param string $filename * @return ReaderInterface + * @throws IncompatibleReaderException */ public function read(string $filename): ReaderInterface { @@ -43,6 +49,10 @@ class Swar4 implements ReaderInterface $this->setRelease($this->readData('String', $swshandle)); + if (array_search(substr($this->getRelease(), 0, 3), self::CompatibleVersions) === false) { + throw new IncompatibleReaderException("This file was not created with Swar 4"); + } + $this->setTournament(new Tournament()); $this->setBinaryData('Guid', $this->readData('String', $swshandle)); From 455d737ed72bc96476b330b8e58384f2cb580c9e Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 28 Aug 2019 20:49:01 +0200 Subject: [PATCH 12/19] Reading tiebreak and exclusion --- src/Readers/Swar4.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index a1b0173..b468a35 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -117,6 +117,18 @@ class Swar4 implements ReaderInterface for ($i = 0; $i < $this->getTournament()->getNoOfRounds(); $i++) { $this->getTournament()->setBinaryData('Round_' . $i . '_date', $this->readData('Date', $swshandle)); } + + $this->getTournament()->setBinaryData('[TIE_BREAK]', $this->readData('String', $swshandle)); + + for ($i = 0; $i < 5; $i++) { + $this->getTournament()->setBinaryData('Tiebreak_' . $i, $this->readData('String', $swshandle)); + } + + + $this->getTournament()->setBinaryData('[EXCLUSION]', $this->readData('String', $swshandle)); + $this->getTournament()->setBinaryData('ExclusionType', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('ExclusionValue', $this->readData('String', $swshandle)); + fclose($swshandle); return $this; From 264d2ddf81edd89e778c23cea3cc7099680a4c8a Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 25 Sep 2019 12:18:02 +0200 Subject: [PATCH 13/19] Reading out even more fields --- src/Readers/Swar4.php | 188 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 183 insertions(+), 5 deletions(-) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index b468a35..e93b0e5 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -17,7 +17,11 @@ use DateTime; use JeroenED\Libpairtwo\Enums\TournamentSystem; use JeroenED\Libpairtwo\Exceptions\IncompatibleReaderException; use JeroenED\Libpairtwo\Interfaces\ReaderInterface; +use JeroenED\Libpairtwo\Pairing; +use JeroenED\Libpairtwo\Player; use JeroenED\Libpairtwo\Tournament; +use JeroenED\Libpairtwo\Enums\Gender; +use JeroenED\Libpairtwo\Enums\Title; /** * Class Swar4 @@ -48,7 +52,6 @@ class Swar4 implements ReaderInterface $swshandle = fopen($filename, 'rb'); $this->setRelease($this->readData('String', $swshandle)); - if (array_search(substr($this->getRelease(), 0, 3), self::CompatibleVersions) === false) { throw new IncompatibleReaderException("This file was not created with Swar 4"); } @@ -92,7 +95,6 @@ class Swar4 implements ReaderInterface $typeIndex = $this->readData('Int', $swshandle); - $this->getTournament()->setBinaryData('Dummy1', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('Dummy2', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('SW_AmerPresence', $this->readData('Int', $swshandle)); @@ -121,14 +123,190 @@ class Swar4 implements ReaderInterface $this->getTournament()->setBinaryData('[TIE_BREAK]', $this->readData('String', $swshandle)); for ($i = 0; $i < 5; $i++) { - $this->getTournament()->setBinaryData('Tiebreak_' . $i, $this->readData('String', $swshandle)); + $this->getTournament()->setBinaryData('Tiebreak_' . $i, $this->readData('Int', $swshandle)); } - $this->getTournament()->setBinaryData('[EXCLUSION]', $this->readData('String', $swshandle)); $this->getTournament()->setBinaryData('ExclusionType', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('ExclusionValue', $this->readData('String', $swshandle)); - + + $this->getTournament()->setBinaryData('[CATEGORIES]', $this->readData('String', $swshandle)); + + $this->getTournament()->setBinaryData('Catogory_type', $this->readData('Int', $swshandle)); + for ($i = 0; $i <= 12; $i++) { + $this->getTournament()->setBinaryData('Category_' . $i . '_Cat1', $this->readData('String', $swshandle)); + } + + for ($i = 0; $i <= 12; $i++) { + $this->getTournament()->setBinaryData('Category_' . $i . '_Cat2', $this->readData('String', $swshandle)); + } + + $this->getTournament()->setBinaryData('[XTRA_POINTS]', $this->readData('String', $swshandle)); + + for ($i = 0; $i < 4; $i++) { + $this->getTournament()->setBinaryData('Extrapoints_' . $i . '_pts', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Extrapoints_' . $i . '_elo', $this->readData('Int', $swshandle)); + } + + $this->getTournament()->setBinaryData('[JOUEURS]', $this->readData('String', $swshandle)); + + $roundNo = 0; + $playerNo = 0; + $this->getTournament()->setBinaryData('NumberOfPlayers', $this->readData('Int', $swshandle)); + + $pt = 0; + for ($i = 0; $i < $this->getTournament()->getBinaryData('NumberOfPlayers'); $i++) { + $player = new Player(); + $player->setBinaryData('Classement', $this->readData('Int', $swshandle)); + $player->setName($this->readData('String', $swshandle)); + $player->setBinaryData('InscriptionNo', $this->readData('Int', $swshandle)); + $player->setBinaryData('Rank', $this->readData('Int', $swshandle)); + $player->setBinaryData('CatIndex', $this->readData('Int', $swshandle)); + echo ''; $this->readData('String', $swshandle); + //$player->setDateOfBirth($this->readData('Date', $swshandle)); + switch ($this->readData('Int', $swshandle)) { + case 1: + $gender = Gender::Male; + break; + case 2: + $gender = Gender::Female; + break; + default: + $gender = Gender::Neutral; + break; + } + $player->setGender(new Gender($gender)); + $player->setNation($this->readData('String', $swshandle)); + //echo ftell($swshandle); + //echo $this->readData('Int', $swshandle); exit; + $player->setId('Nation', $this->readData('Int', $swshandle)); + echo $player->getId('Nation'); + $player->setId('Fide', $this->readData('Int', $swshandle)); + $player->setBinaryData('Affliation', $this->readData('Int', $swshandle)); + $player->setElo('Nation', $this->readData('Int', $swshandle)); + $player->setElo('Fide', $this->readData('Int', $swshandle)); + exit; + switch ($this->readData('Int', $swshandle)) { + case 1: + $title = Title::NM; + break; + case 2: + $title = Title::WCM; + break; + case 3: + $title = Title::WFM; + break; + case 4: + $title = Title::CM; + break; + case 5: + $title = Title::WIM; + break; + case 6: + $title = Title::FM; + break; + case 7: + $title = Title::WGM; + break; + case 8: + $title = Title::HM; + break; + case 9: + $title = Title::IM; + break; + case 10: + $title = Title::HG; + break; + case 11: + $title = Title::GM; + break; + case 0: + default: + $title = Title::NONE; + break; + } + $player->setTitle(new Title($title)); + + $player->setId('Club', $this->readData('Int', $swshandle)); + $player->setId('ClubName', $this->readData('String', $swshandle)); + + $player->setBinaryData('NoOfMatchesNoBye', $this->readData('Int', $swshandle)); + $player->setBinaryData('Points', $this->readData('Int', $swshandle)); // To Calculate by libpairtwo + $player->setBinaryData('AmericanPoints', $this->readData('Int', $swshandle)); // To Calculate by libpairtwo + for ($i = 0; $i < 5; $i++) { + $player->setBinaryData('Tiebreak_' . $i, $this->readData('Int', $swshandle)); // To Calculate by libpairtwo + } + $player->setBinaryData('Performance', $this->readData('Int', $swshandle)); // To Calculate by libpairtwo + $player->setBinaryData('Absent', $this->readData('Int', $swshandle)); + $player->setBinaryData('AbsentRounds', $this->readData('String', $swshandle)); + $player->setBinaryData('ExtraPoints', $this->readData('Int', $swshandle)); + $player->setBinaryData('AllocatedRounds', $this->readData('Int', $swshandle)); + + $player->setBinaryData('[RONDE]', $this->readData('String', $swshandle)); + if ($player->getBinaryData('AllocatedRounds') != 0) { + for ($j = 0; $j < $player->getBinaryData('AllocatedRounds'); $j++) { + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_player', count($this->getTournament()->getPlayers())); + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_round', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_table', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_opponent', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_result', $this->readData('Hex', $swshandle)); + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_color', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_float', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_extrapoints', $this->readData('Int', $swshandle)); + + $pt++; + } + } + + $this->getTournament()->addPlayer($player); + } + + $ptn = 0; + while ('' !== $this->getTournament()->getBinaryData('Pairing_' . $ptn . '_round')) { + $pairing = new Pairing(); + + $pairing->setPlayer($this->getTournament()->getPlayerById($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_player'))); + $pairing->setRound($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_round')); + $pairing->setOpponent($this->getTournament()->getPlayerById($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_opponent'))); + switch ($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_result')) { + case 1: + $result = Result::lost; + break; + case 2: + $result = Result::absent; + break; + case 3: + $result = Result::adjourned; + break; + case 4: + $result = Result::bye; + break; + case 6: + $result = Result::draw; + break; + case 8: + $result = Result::drawadjourned; + break; + case 11: + $result = Result::won; + break; + case 12: + $result = Result::wonforfait; + break; + case 13: + $result = Result::wonadjourned; + break; + case 14: + $result = Result::wonbye; + break; + case 0: + default: + $result = Result::none; + break; + } + $pairing->setResult(new Result($result)); + $ptn++; + } fclose($swshandle); return $this; From 1e65525b279e93502313fefc0786c358f935fffc Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 25 Sep 2019 14:33:52 +0200 Subject: [PATCH 14/19] Added even more fields --- src/Readers/Swar4.php | 68 ++++++++++++++++++++++-------------------- tests/ReadSws_test.php | 4 +-- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index e93b0e5..223261a 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -22,6 +22,7 @@ use JeroenED\Libpairtwo\Player; use JeroenED\Libpairtwo\Tournament; use JeroenED\Libpairtwo\Enums\Gender; use JeroenED\Libpairtwo\Enums\Title; +use JeroenED\Libpairtwo\Enums\Result; /** * Class Swar4 @@ -162,8 +163,7 @@ class Swar4 implements ReaderInterface $player->setBinaryData('InscriptionNo', $this->readData('Int', $swshandle)); $player->setBinaryData('Rank', $this->readData('Int', $swshandle)); $player->setBinaryData('CatIndex', $this->readData('Int', $swshandle)); - echo ''; $this->readData('String', $swshandle); - //$player->setDateOfBirth($this->readData('Date', $swshandle)); + $player->setDateOfBirth($this->readData('Date', $swshandle)); switch ($this->readData('Int', $swshandle)) { case 1: $gender = Gender::Male; @@ -176,48 +176,42 @@ class Swar4 implements ReaderInterface break; } $player->setGender(new Gender($gender)); + $player->setNation($this->readData('String', $swshandle)); - //echo ftell($swshandle); - //echo $this->readData('Int', $swshandle); exit; $player->setId('Nation', $this->readData('Int', $swshandle)); - echo $player->getId('Nation'); $player->setId('Fide', $this->readData('Int', $swshandle)); $player->setBinaryData('Affliation', $this->readData('Int', $swshandle)); $player->setElo('Nation', $this->readData('Int', $swshandle)); $player->setElo('Fide', $this->readData('Int', $swshandle)); - exit; switch ($this->readData('Int', $swshandle)) { case 1: - $title = Title::NM; - break; - case 2: $title = Title::WCM; break; - case 3: + case 2: $title = Title::WFM; break; - case 4: + case 3: $title = Title::CM; break; - case 5: + case 4: $title = Title::WIM; break; - case 6: + case 5: $title = Title::FM; break; - case 7: + case 6: $title = Title::WGM; break; - case 8: + case 7: $title = Title::HM; break; - case 9: + case 8: $title = Title::IM; break; - case 10: + case 9: $title = Title::HG; break; - case 11: + case 10: $title = Title::GM; break; case 0: @@ -228,27 +222,27 @@ class Swar4 implements ReaderInterface $player->setTitle(new Title($title)); $player->setId('Club', $this->readData('Int', $swshandle)); - $player->setId('ClubName', $this->readData('String', $swshandle)); - + $player->setBinaryData('ClubName', $this->readData('String', $swshandle)); $player->setBinaryData('NoOfMatchesNoBye', $this->readData('Int', $swshandle)); $player->setBinaryData('Points', $this->readData('Int', $swshandle)); // To Calculate by libpairtwo $player->setBinaryData('AmericanPoints', $this->readData('Int', $swshandle)); // To Calculate by libpairtwo - for ($i = 0; $i < 5; $i++) { - $player->setBinaryData('Tiebreak_' . $i, $this->readData('Int', $swshandle)); // To Calculate by libpairtwo + for ($t = 0; $t < 5; $t++) { + $player->setBinaryData('Tiebreak_' . $t, $this->readData('Int', $swshandle)); // To Calculate by libpairtwo } $player->setBinaryData('Performance', $this->readData('Int', $swshandle)); // To Calculate by libpairtwo $player->setBinaryData('Absent', $this->readData('Int', $swshandle)); $player->setBinaryData('AbsentRounds', $this->readData('String', $swshandle)); $player->setBinaryData('ExtraPoints', $this->readData('Int', $swshandle)); + $player->setBinaryData('SpecialPoints', $this->readData('Int', $swshandle)); $player->setBinaryData('AllocatedRounds', $this->readData('Int', $swshandle)); - $player->setBinaryData('[RONDE]', $this->readData('String', $swshandle)); + if ($player->getBinaryData('AllocatedRounds') != 0) { for ($j = 0; $j < $player->getBinaryData('AllocatedRounds'); $j++) { - $this->getTournament()->setBinaryData('Pairing_' . $pt . '_player', count($this->getTournament()->getPlayers())); + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_player', $i); $this->getTournament()->setBinaryData('Pairing_' . $pt . '_round', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('Pairing_' . $pt . '_table', $this->readData('Int', $swshandle)); - $this->getTournament()->setBinaryData('Pairing_' . $pt . '_opponent', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_opponent', $this->readData('Int', $swshandle) - 1); $this->getTournament()->setBinaryData('Pairing_' . $pt . '_result', $this->readData('Hex', $swshandle)); $this->getTournament()->setBinaryData('Pairing_' . $pt . '_color', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('Pairing_' . $pt . '_float', $this->readData('Int', $swshandle)); @@ -262,17 +256,20 @@ class Swar4 implements ReaderInterface } $ptn = 0; - while ('' !== $this->getTournament()->getBinaryData('Pairing_' . $ptn . '_round')) { + while (null !== $this->getTournament()->getBinaryData('Pairing_' . $ptn . '_round')) { $pairing = new Pairing(); $pairing->setPlayer($this->getTournament()->getPlayerById($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_player'))); $pairing->setRound($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_round')); - $pairing->setOpponent($this->getTournament()->getPlayerById($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_opponent'))); + if($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_opponent') != 4294967294) { + $pairing->setOpponent($this->getTournament()->getPlayerById($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_opponent'))); + } + //echo $ptn . ' ' . $this->getTournament()->getBinaryData('Pairing_' . $ptn . '_round') . ' ' . $pairing->getPlayer()->getName() . ' - ' . $opponent . ' ' . $this->getTournament()->getBinaryData('Pairing_' . $ptn . '_result') . PHP_EOL; switch ($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_result')) { - case 1: + case '1000': $result = Result::lost; break; - case 2: + case '01': $result = Result::absent; break; case 3: @@ -416,11 +413,14 @@ class Swar4 implements ReaderInterface * Returns binary data that was read out the swar file but was not needed immediately * * @param string $Key - * @return bool|DateTime|int|string + * @return bool|DateTime|int|string|null */ public function getBinaryData(string $Key) { - return $this->BinaryData[$Key]; + if (isset($this->BinaryData[$Key])) { + return $this->BinaryData[$Key]; + } + return null; } /** @@ -442,6 +442,10 @@ class Swar4 implements ReaderInterface */ public function convertStringToDate(string $string): \DateTime { - return DateTime::createFromFormat('d/m/Y', $string); + if (strlen($string) == 10) { + return DateTime::createFromFormat('d/m/Y', $string); + } elseif (strlen($string) == 8) { + return DateTime::createFromFormat('Ymd', $string); + } } } diff --git a/tests/ReadSws_test.php b/tests/ReadSws_test.php index 566ce97..c4a0e85 100644 --- a/tests/ReadSws_test.php +++ b/tests/ReadSws_test.php @@ -27,8 +27,8 @@ use JeroenED\Libpairtwo\IOFactory; require_once '../vendor/autoload.php'; -$sws = IOFactory::createReader('Pairtwo-6'); -$sws->read('../res/testsws.sws'); +$sws = IOFactory::createReader('Swar-4'); +$sws->read('../res/testswar.swar'); echo "Release: " . $sws->getRelease() . PHP_EOL; echo "Name: " . $sws->getTournament()->getName() . PHP_EOL; From ae8121959edf1793bf59a17a0076120a7f1e0af3 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 25 Sep 2019 14:55:59 +0200 Subject: [PATCH 15/19] Tournament::getbinarydata returning null --- src/Tournament.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Tournament.php b/src/Tournament.php index 8d2414c..3e24b02 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -1325,7 +1325,10 @@ class Tournament */ public function getBinaryData(string $Key) { - return $this->BinaryData[$Key]; + if (isset($this->BinaryData[$Key])) { + return $this->BinaryData[$Key]; + } + return null; } /** From 08140661ddf025839218a22002755f04bc1503aa Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 25 Sep 2019 14:56:16 +0200 Subject: [PATCH 16/19] Implemented results --- src/Readers/Swar4.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index 223261a..b8b5300 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -272,31 +272,22 @@ class Swar4 implements ReaderInterface case '01': $result = Result::absent; break; - case 3: - $result = Result::adjourned; - break; - case 4: + case '0010': $result = Result::bye; break; - case 6: + case '2000': $result = Result::draw; break; - case 8: - $result = Result::drawadjourned; - break; - case 11: + case '4000': $result = Result::won; break; - case 12: + case '04': $result = Result::wonforfait; break; - case 13: - $result = Result::wonadjourned; - break; - case 14: + case '40': $result = Result::wonbye; break; - case 0: + case '00': default: $result = Result::none; break; @@ -305,7 +296,7 @@ class Swar4 implements ReaderInterface $ptn++; } fclose($swshandle); - + $this->getTournament()->pairingsToRounds(); return $this; } From fcc76d2b8e3059f43362f84e7a3af8ae361b5494 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 25 Sep 2019 16:05:31 +0200 Subject: [PATCH 17/19] Removed double Swiss --- src/Enums/TournamentSystem.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Enums/TournamentSystem.php b/src/Enums/TournamentSystem.php index 0028632..2109555 100644 --- a/src/Enums/TournamentSystem.php +++ b/src/Enums/TournamentSystem.php @@ -27,7 +27,6 @@ use MyCLabs\Enum\Enum; class TournamentSystem extends Enum { const Swiss = 'Swiss'; - const DoubleSwiss = 'Swiss Double'; const Closed = 'Closed'; const American = 'American'; const Keizer = 'Keizer'; From 802f0d12c1d2b9d1206672f029f340f3a3842dff Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 25 Sep 2019 16:06:13 +0200 Subject: [PATCH 18/19] Added even more --- src/Readers/Swar4.php | 84 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index b8b5300..42358c9 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -14,11 +14,13 @@ namespace JeroenED\Libpairtwo\Readers; use DateTime; +use JeroenED\Libpairtwo\Enums\Color; use JeroenED\Libpairtwo\Enums\TournamentSystem; use JeroenED\Libpairtwo\Exceptions\IncompatibleReaderException; use JeroenED\Libpairtwo\Interfaces\ReaderInterface; use JeroenED\Libpairtwo\Pairing; use JeroenED\Libpairtwo\Player; +use JeroenED\Libpairtwo\Round; use JeroenED\Libpairtwo\Tournament; use JeroenED\Libpairtwo\Enums\Gender; use JeroenED\Libpairtwo\Enums\Title; @@ -42,6 +44,64 @@ class Swar4 implements ReaderInterface /** @var array */ private const CompatibleVersions = ['v4.']; + private const Tempos = [ + [ + '105 min/40 moves + 15 min. QPF', + '120 min/40 moves + 15 min. with incr. 30" starting from 40th move', + '120 min/40 moves + 30 min. QPF', + '120 min/10 moves + 30 min. avec incr. 30" starting from 40th move', + '120 min QPF', + '150 min QPF', + '60 min QPF', + '60 min with incr. 30"', + '65 min QPF', + '75 min with incr. 30"', + '90 min/40 moves + 15 min with incr. 30" starting from 1st move', + '90 min/40 moves + 30 min with incr. 30" starting from 1st move', + '90 min with incr. 30"', + '50 min with incr. 10"', + 'other' + ],[ + '10 min. with incr. 10"', + '10 min. with incr. 15"', + '10 min. with incr.5"', + '11 min. QPF', + '12 min. QPF', + '13 min. with incr.3"', + '13 min. with incr.5"', + '15 min. QPF', + '15 min. with incr. 10"', + '15 min. with incr. 15"', + '15 min. with incr.5"', + '20 min. QPF', + '20 min. with incr. 10"', + '20 min. with incr. 15"', + '20 min. with incr.5"', + '25 min. QPF', + '25 min. with incr. 10"', + '25 min. with incr. 15"', + '25 min. with incr.5"', + '30 min. QPF', + '45 min. QPF', + '8 min. with incr.4"', + 'other' + ],[ + '3 min. with incr. 2"', + '3 min. with incr. 3"', + '4 min. with incr. 2"', + '4 min. with incr. 3"', + '5 min. QPF', + '5 min. with incr. 2"', + '5 min. with incr. 3"', + '6 min. with incr. 2"', + '6 min. with incr. 3"', + '7 min. with incr. 2"', + '7 min. with incr. 3"', + '8 min. with incr. 2"', + '10 min. QPF', + 'other' + ] + ]; /** * @param string $filename @@ -94,7 +154,7 @@ class Swar4 implements ReaderInterface $this->getTournament()->setBinaryData('FideEmail', $this->readData('String', $swshandle)); $this->getTournament()->setBinaryData('FideRemarques', $this->readData('String', $swshandle)); - $typeIndex = $this->readData('Int', $swshandle); + $typeIndex = $this->readData('Int', $swshandle);// Tournament System $this->getTournament()->setBinaryData('Dummy1', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('Dummy2', $this->readData('Int', $swshandle)); @@ -117,8 +177,13 @@ class Swar4 implements ReaderInterface $this->getTournament()->setBinaryData('Federation', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('[DATES]', $this->readData('String', $swshandle)); + $this->getTournament()->setTempo(Self::Tempos[$this->getTournament()->getBinaryData('TournoiStd')][$this->getTournament()->getBinaryData('TempoIndex')]); + for ($i = 0; $i < $this->getTournament()->getNoOfRounds(); $i++) { - $this->getTournament()->setBinaryData('Round_' . $i . '_date', $this->readData('Date', $swshandle)); + $round = new Round(); + $round->setRoundNo($i); + $round->setDate($this->readData('Date', $swshandle)); + $this->getTournament()->addRound($round); } $this->getTournament()->setBinaryData('[TIE_BREAK]', $this->readData('String', $swshandle)); @@ -293,7 +358,22 @@ class Swar4 implements ReaderInterface break; } $pairing->setResult(new Result($result)); + + switch ($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_color')) { + case 4294967295: + $color = Color::black; + break; + case 1: + $color = Color::white; + break; + case 0: + default: + $color = Color::none; + break; + } + $pairing->setColor(new Color($color)); $ptn++; + $this->getTournament()->addPairing($pairing); } fclose($swshandle); $this->getTournament()->pairingsToRounds(); From 5dbdf92a97d3eaf1fad68b5ec1631ba009e21d4f Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 25 Sep 2019 16:30:19 +0200 Subject: [PATCH 19/19] Swar-4 reader ready for beta-testing --- src/Readers/Swar4.php | 52 +++++++++++++++++++++++++++++++++++++++--- tests/ReadSws_test.php | 5 ++-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index 42358c9..eac6a49 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -154,7 +154,26 @@ class Swar4 implements ReaderInterface $this->getTournament()->setBinaryData('FideEmail', $this->readData('String', $swshandle)); $this->getTournament()->setBinaryData('FideRemarques', $this->readData('String', $swshandle)); - $typeIndex = $this->readData('Int', $swshandle);// Tournament System + switch ($this->readData('Int', $swshandle)) { + case 0: + case 1: + case 2: + case 3: + case 4: + default: + $system = TournamentSystem::Swiss; + break; + case 5: + case 6: + case 7: + $system = TournamentSystem::Closed; + break; + case 8: + case 9: + $system = TournamentSystem::American; + break; + } + $this->getTournament()->setSystem(new TournamentSystem($system)); $this->getTournament()->setBinaryData('Dummy1', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('Dummy2', $this->readData('Int', $swshandle)); @@ -174,7 +193,34 @@ class Swar4 implements ReaderInterface $this->getTournament()->setBinaryData('ByeValue', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('AbsValue', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('FF_Value', $this->readData('Int', $swshandle)); - $this->getTournament()->setBinaryData('Federation', $this->readData('Int', $swshandle)); + + switch ($this->readData('Int', $swshandle)) { + case 0: + default: + $federation = ''; + break; + case 1: + $federation = 'FRBE'; + break; + case 2: + $federation = 'KBSB'; + break; + case 3: + $federation = 'FEFB'; + break; + case 4: + $federation = 'VSF'; + break; + case 5: + $federation = 'SVDB'; + break; + case 6: + $federation = 'FIDE'; + break; + } + $this->getTournament()->setFederation($federation); + $this->getTournament()->setNonRatedElo(0); + $this->getTournament()->setOrganiserClubNo(0); $this->getTournament()->setBinaryData('[DATES]', $this->readData('String', $swshandle)); $this->getTournament()->setTempo(Self::Tempos[$this->getTournament()->getBinaryData('TournoiStd')][$this->getTournament()->getBinaryData('TempoIndex')]); @@ -305,7 +351,7 @@ class Swar4 implements ReaderInterface if ($player->getBinaryData('AllocatedRounds') != 0) { for ($j = 0; $j < $player->getBinaryData('AllocatedRounds'); $j++) { $this->getTournament()->setBinaryData('Pairing_' . $pt . '_player', $i); - $this->getTournament()->setBinaryData('Pairing_' . $pt . '_round', $this->readData('Int', $swshandle)); + $this->getTournament()->setBinaryData('Pairing_' . $pt . '_round', $this->readData('Int', $swshandle) - 1); $this->getTournament()->setBinaryData('Pairing_' . $pt . '_table', $this->readData('Int', $swshandle)); $this->getTournament()->setBinaryData('Pairing_' . $pt . '_opponent', $this->readData('Int', $swshandle) - 1); $this->getTournament()->setBinaryData('Pairing_' . $pt . '_result', $this->readData('Hex', $swshandle)); diff --git a/tests/ReadSws_test.php b/tests/ReadSws_test.php index c4a0e85..6ea499f 100644 --- a/tests/ReadSws_test.php +++ b/tests/ReadSws_test.php @@ -33,11 +33,12 @@ $sws->read('../res/testswar.swar'); echo "Release: " . $sws->getRelease() . PHP_EOL; echo "Name: " . $sws->getTournament()->getName() . PHP_EOL; echo "Organiser: " . $sws->getTournament()->getOrganiser(). PHP_EOL; +echo "TempoIndex: " . $sws->getTournament()->getBinaryData('TempoIndex') . PHP_EOL; +echo "TempoType: " . $sws->getTournament()->getBinaryData('TournoiStd') . PHP_EOL; echo "Tempo: " . $sws->getTournament()->getTempo() . PHP_EOL; -echo "Country: " . $sws->getTournament()->getOrganiserCountry() . PHP_EOL; +echo "Place: " . $sws->getTournament()->getOrganiserPlace() . PHP_EOL; echo "Arbiter: " . $sws->getTournament()->getArbiter() . PHP_EOL; echo "Rounds: " . $sws->getTournament()->getNoOfRounds() . PHP_EOL; -echo "Participants: " . $sws->getTournament()->getNoOfRounds() . 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;