diff --git a/CHANGELOG.md b/CHANGELOG.md index a1124cf..aa5b5ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # CHANGELOG -## vx.y.z (Release: aa-bbb-cccc) -* NEW FEATURE: `Game::getBoard()` for getting the board number of the game +## v2.0 (Release: aa-bbb-cccc) +* NEW FEATURE: `Game::Board` for getting the board number of the game +* MAJOR CHANGE: Getter and setter methods have been removed. (Please see [0d8a325](https://github.com/JeroenED/libpairtwo/commit/0d8a325eb501b775830f68fa6f600f9f4ca5588c) for more info) * CHANGE: Some fields has been renamed to match coding guideline (Please see [1ab96fa](https://github.com/JeroenED/libpairtwo/commit/1ab96fa04782c1b0f2b6bb9d1bac8397a74ab38e) for more info) * CHANGE: Logo has been redesigned * REMOVED: `Tiebreak::American` and all its uses were removed (Please see [a6015ae](https://github.com/JeroenED/libpairtwo/commit/a6015ae8169f0973f4937605d0f807aacc233630) for more info) diff --git a/src/Game.php b/src/Game.php index 0da15af..ed9d287 100644 --- a/src/Game.php +++ b/src/Game.php @@ -29,30 +29,37 @@ use DateTime; class Game { /** @var Pairing | null */ - private $White; + public $White; /** @var Pairing | null */ - private $Black; + public $Black; /** @var GameResult | null */ - private $Result; + private $CalculatedResult; /** @var int */ - private $Board; + public $Board; + + public function __get(string $key) + { + if ($key == 'Result') { + return $this->calculateResult(); + } + } /** * Returns the result for the game * * @return Gameresult */ - public function getResult(): Gameresult + private function calculateResult(): Gameresult { - if (!is_null($this->Result)) { - return $this->Result; + if (!is_null($this->CalculatedResult)) { + return $this->CalculatedResult; } - $whiteResult = $this->getWhite()->getResult(); - $blackResult = $this->getBlack()->getResult(); + $whiteResult = $this->White->Result; + $blackResult = $this->Black->Result; $whitesplit = explode(" ", $whiteResult); $blacksplit = explode(" ", $blackResult); @@ -71,84 +78,23 @@ class Game $blacksplit[0] = ''; } $result = new Gameresult($whitesplit[0] . '-' . $blacksplit[0] . $special); - $this->setResult($result); + $this->CalculatedResult = $result; return $result; } /** - * Returns the pairing for white player + * Checks if 2 games are equal * - * @return Pairing | null + * @param Game $game1 + * @param Game $game2 + * @return bool */ - public function getWhite(): ?Pairing + public function equals(Game $game): bool { - return $this->White; - } - - /** - * Sets pairing for white player - * - * @param Pairing | null $White - * @return Game - */ - public function setWhite(?Pairing $White): Game - { - $this->White = $White; - return $this; - } - - /** - * Returns the pairing for black player - * - * @return Pairing | null - */ - public function getBlack(): ?Pairing - { - return $this->Black; - } - - /** - * Sets pairing for black player - * - * @param Pairing | null $Black - * @return Game - */ - public function setBlack(?Pairing $Black): Game - { - $this->Black = $Black; - return $this; - } - - /** - * Sets result for game - * - * @param Gameresult | null $Result - * @return Game - */ - public function setResult(?Gameresult $Result): Game - { - $this->Result = $Result; - return $this; - } - - /** - * Sets the board no of the game - * - * @return int - */ - public function getBoard(): int - { - return $this->Board; - } - - /** - * Returns the board no of the game - * - * @param int $Board - */ - public function setBoard(int $Board): void - { - $this->Board = $Board; + return ( + $this->White->Player === $game->White->Player && + $this->Black->Player === $game->Black->Player && + $this->Result == $game->Result); } } diff --git a/src/Interfaces/ReaderInterface.php b/src/Interfaces/ReaderInterface.php index 428fcb4..2cd6bcd 100644 --- a/src/Interfaces/ReaderInterface.php +++ b/src/Interfaces/ReaderInterface.php @@ -32,12 +32,5 @@ interface ReaderInterface * @param $filename * @return ReaderInterface */ - public function read(string $filename): ReaderInterface; - - /** - * Gets the tournament out of $filename - * - * @return Tournament - */ - public function getTournament(): Tournament; + public function read(string $filename): void; } diff --git a/src/Pairing.php b/src/Pairing.php index 8b2d4a6..4583039 100644 --- a/src/Pairing.php +++ b/src/Pairing.php @@ -28,150 +28,20 @@ use JeroenED\Libpairtwo\Enums\Result; class Pairing { /** @var Player | null */ - private $Player; + public $Player; /** @var Player | null */ - private $Opponent; + public $Opponent; /** @var Color */ - private $Color; + public $Color; /** @var Result */ - private $Result; + public $Result; /** @var int */ - private $Round; + public $Round; /** @var int */ - private $Board; - - /** - * Returns the player of the pairing - * - * @return Player | null - */ - public function getPlayer(): ?Player - { - return $this->Player; - } - - /** - * Sets the player of the pairing - * - * @param Player | null $Player - * @return Pairing - */ - public function setPlayer(?Player $Player): Pairing - { - $this->Player = $Player; - return $this; - } - - /** - * Returns the opponent of the pairing - * - * @return Player | null - */ - public function getOpponent(): ?Player - { - return $this->Opponent; - } - - /** - * Sets the opponent of the pairing - * - * @param Player | null $Opponent - * @return Pairing - */ - public function setOpponent(?Player $Opponent): Pairing - { - $this->Opponent = $Opponent; - return $this; - } - - /** - * Returns the color of the pairing - * - * @return Color - */ - public function getColor(): Color - { - return $this->Color; - } - - /** - * Sets the color of the pairing - * - * @param Color $Color - * @return Pairing - */ - public function setColor(Color $Color): Pairing - { - $this->Color = $Color; - return $this; - } - - /** - * Returns the individual result of the pairing - * - * @return Result - */ - public function getResult(): Result - { - return $this->Result; - } - - /** - * Sets the individual result of the pairing - * - * @param Result $Result - * @return Pairing - */ - public function setResult(Result $Result): Pairing - { - $this->Result = $Result; - return $this; - } - - /** - * Returns the round number of the pairing - * - * @return int - */ - public function getRound(): int - { - return $this->Round; - } - - /** - * Sets the round number of the pairing - * - * @param int $Round - * @return Pairing - */ - public function setRound(int $Round): Pairing - { - $this->Round = $Round; - return $this; - } - - /** - * Sets the board no of the pairing - * - * @return int - */ - public function getBoard(): int - { - return $this->Board; - } - - /** - * Returns the board no of the pairing - * - * @param int $Board - */ - public function setBoard(int $Board): void - { - $this->Board = $Board; - } + public $Board; } diff --git a/src/Player.php b/src/Player.php index 80f4cbb..15448c7 100644 --- a/src/Player.php +++ b/src/Player.php @@ -29,35 +29,35 @@ use DateTime; class Player { /** @var string */ - private $Name; + public $Name; /** @var int[] */ - private $Ids; + public $Ids; /** @var int[] */ - private $Elos; + public $Elos; /** @var DateTime */ - private $DateOfBirth; + public $DateOfBirth; /** @var float[] */ - private $Tiebreaks = []; + public $Tiebreaks = []; /** @var string */ - private $Nation; + public $Nation; // TODO: Implement categories /** @var string */ - private $Category; + public $Category; /** @var Title */ - private $Title; + public $Title; /** @var Gender */ - private $Gender; + public $Gender; /** @var Pairing[] */ - private $Pairings = []; + public $Pairings = []; /** @var bool|DateTime|int|string[] */ private $BinaryData; @@ -66,14 +66,12 @@ class Player * Adds a pairing to the tournament * * @param Pairing $pairing - * @return Player */ - public function addPairing(Pairing $pairing): Player + public function addPairing(Pairing $pairing): void { - $newArray = $this->GetPairings(); + $newArray = $this->Pairings; $newArray[] = $pairing; - $this->setPairings($newArray); - return $this; + $this->Pairings = $newArray; } /** @@ -83,16 +81,16 @@ class Player * @param Tournament $tournament * @return Player[] */ - public static function getPlayersByName(string $search, Tournament $tournament): array + public static function PlayersByName(string $search, Tournament $tournament): array { /** @var Player[] */ - $players = $tournament->getPlayers(); + $players = $tournament->Players; /** @var Player[] */ $return = []; foreach ($players as $player) { - if (fnmatch($search, $player->getName())) { + if (fnmatch($search, $player->Name)) { $return[] = $player; } } @@ -107,7 +105,7 @@ class Player */ public function getElo(string $type): int { - return $this->getElos()[$type]; + return $this->Elos[$type]; } /** @@ -115,14 +113,12 @@ class Player * * @param string $type * @param int $value - * @return Player */ - public function setElo(string $type, int $value): Player + public function setElo(string $type, int $value): void { - $currentElos = $this->getElos(); + $currentElos = $this->Elos; $currentElos[$type] = $value; - $this->setElos($currentElos); - return $this; + $this->Elos = $currentElos; } /** @@ -135,7 +131,7 @@ class Player */ public function getId(string $type): string { - return $this->getIds()[$type]; + return $this->Ids[$type]; } /** @@ -145,14 +141,12 @@ class Player * * @param string $type * @param string $value - * @return Player */ - public function setId(string $type, string $value): Player + public function setId(string $type, string $value): void { - $currentIds = $this->getIds(); + $currentIds = $this->Ids; $currentIds[$type] = $value; - $this->setIds($currentIds); - return $this; + $this->Ids = $currentIds; } /** @@ -160,11 +154,11 @@ class Player * * @return int */ - public function getNoOfWins(): int + private function noOfWins(): int { $wins = 0; - foreach ($this->getPairings() as $pairing) { - if (array_search($pairing->getResult(), Constants::Won) !== false) { + foreach ($this->Pairings as $pairing) { + if (array_search($pairing->Result, Constants::Won) !== false) { $wins++; } } @@ -179,13 +173,13 @@ class Player * * @return float */ - public function getPoints(): float + public function calculatePoints(): float { $points = 0; - foreach ($this->getPairings() as $pairing) { - if (array_search($pairing->getResult(), Constants::Won) !== false) { + foreach ($this->Pairings as $pairing) { + if (array_search($pairing->Result, Constants::Won) !== false) { $points = $points + 1; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + } elseif (array_search($pairing->Result, Constants::Draw) !== false) { $points = $points + 0.5; } } @@ -201,15 +195,15 @@ class Player * * @return float */ - public function getPointsForBuchholz(): float + private function pointsForBuchholz(): float { $points = 0; - foreach ($this->getPairings() as $pairing) { - if (array_search($pairing->getResult(), Constants::NotPlayed) !== false) { + foreach ($this->Pairings as $pairing) { + if (array_search($pairing->Result, Constants::NotPlayed) !== false) { $points = $points + 0.5; - } elseif (array_search($pairing->getResult(), Constants::Won) !== false) { + } elseif (array_search($pairing->Result, Constants::Won) !== false) { $points = $points + 1; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + } elseif (array_search($pairing->Result, Constants::Draw) !== false) { $points = $points + 0.5; } } @@ -222,19 +216,19 @@ class Player * * @return int */ - public function getPerformance(string $type, int $unratedElo): float + public function Performance(string $type, int $unratedElo): float { $total = 0; $opponents = 0; - foreach ($this->getPairings() as $pairing) { - if (array_search($pairing->getResult(), Constants::NotPlayed) === false) { - $opponentElo = $pairing->getOpponent()->getElo($type); + foreach ($this->Pairings as $pairing) { + if (array_search($pairing->Result, Constants::NotPlayed) === false) { + $opponentElo = $pairing->Opponent->getElo($type); $opponentElo = $opponentElo != 0 ? $opponentElo : $unratedElo; - if (array_search($pairing->getResult(), Constants::Won) !== false) { + if (array_search($pairing->Result, Constants::Won) !== false) { $total += $opponentElo + 400; - } elseif (array_search($pairing->getResult(), Constants::Lost) !== false) { + } elseif (array_search($pairing->Result, Constants::Lost) !== false) { $total += $opponentElo - 400; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + } elseif (array_search($pairing->Result, Constants::Draw) !== false) { $total += $opponentElo; } $opponents++; @@ -249,11 +243,11 @@ class Player * * @return int */ - public function getPlayedGames(): int + private function playedGames(): int { $total = 0; - foreach ($this->getPairings() as $pairing) { - if (array_search($pairing->getResult(), Constants::Played) !== false) { + foreach ($this->Pairings as $pairing) { + if (array_search($pairing->Result, Constants::Played) !== false) { $total++; } } @@ -261,251 +255,33 @@ class Player } /** - * Returns the name of the player + * Magic method to read out several fields. If field was not found it is being searched in the binary data fields * - * @return string - */ - public function getName(): string - { - return $this->Name; - } - - /** - * Sets the name of the player - * - * @param string $Name - * @return Player - */ - public function setName(string $Name): Player - { - $this->Name = $Name; - return $this; - } - - /** - * Returns an array of all ID's of the player - * - * @return string[] - */ - public function getIds(): ?array - { - return $this->Ids; - } - - /** - * Sets an array of all ID's of the player - * - * @param string[] $Ids - * @return Player - */ - public function setIds(array $Ids): Player - { - $this->Ids = $Ids; - return $this; - } - - /** - * Returns an array of all elos of the player - * - * @return int[] - */ - public function getElos(): ?array - { - return $this->Elos; - } - - /** - * Sets an array of all elos of the player - * - * @param int[] $Elos - * @return Player - */ - public function setElos(array $Elos): Player - { - $this->Elos = $Elos; - return $this; - } - - /** - * Returns the date of birth of the player - * - * @return DateTime - */ - public function getDateOfBirth(): DateTime - { - return $this->DateOfBirth; - } - - /** - * Sets the date of birth of the player - * - * @param DateTime $DateOfBirth - * @return Player - */ - public function setDateOfBirth(DateTime $DateOfBirth): Player - { - $this->DateOfBirth = $DateOfBirth; - return $this; - } - - /** - * Returns an array of all tiebreaks for the player - * - * @return float[] - */ - public function getTiebreaks(): array - { - return $this->Tiebreaks; - } - - /** - * Sets an array of all tiebreaks for the player - * - * @param float[] $Tiebreaks - * @return Player - */ - public function setTiebreaks(array $Tiebreaks): Player - { - $this->Tiebreaks = $Tiebreaks; - return $this; - } - - /** - * Returns the nation of the player - * example value: BEL - * - * @return string - */ - public function getNation(): string - { - return $this->Nation; - } - - /** - * Sets the nation of the player - * example value: BEL - * - * @param string $Nation - * @return Player - */ - public function setNation(string $Nation): Player - { - $this->Nation = $Nation; - return $this; - } - - /** - * Returns the category of the player - * - * @return string - */ - public function getCategory(): string - { - return $this->Category; - } - - /** - * Sets the category of the player - * - * @param string $Category - * @return Player - */ - public function setCategory(string $Category): Player - { - $this->Category = $Category; - return $this; - } - - /** - * Returns the title of the player - * - * @return Title - */ - public function getTitle(): Title - { - return $this->Title; - } - - /** - * Sets the title of the player - * - * @param Title $Title - * @return Player - */ - public function setTitle(Title $Title): Player - { - $this->Title = $Title; - return $this; - } - - /** - * Returns the gender of the player - * - * @return Gender - */ - public function getGender(): Gender - { - return $this->Gender; - } - - /** - * Sets the gender of the player - * - * @param Gender $Gender - * @return Player - */ - public function setGender(Gender $Gender): Player - { - $this->Gender = $Gender; - return $this; - } - - /** - * Returns an array of all pairings of the player - * - * @return Pairing[] - */ - public function getPairings(): array - { - return $this->Pairings; - } - - /** - * Sets an array of all pairings of the player - * - * @param Pairing[] $Pairings - * @return Player - */ - public function setPairings(array $Pairings): Player - { - $this->Pairings = $Pairings; - return $this; - } - - /** - * Returns binary data that was read out the pairtwo file but was not needed immediately - * - * @param string $Key + * @param string $key * @return bool|DateTime|int|string|null */ - public function getBinaryData(string $Key) + public function __get(string $key) { - if (isset($this->BinaryData[$Key])) { - return $this->BinaryData[$Key]; + if($key == 'PlayedGames') { + return $this->playedGames(); + } elseif ($key == 'NoOfWins') { + return $this->noOfWins(); + } elseif ($key == 'PointsForBuchholz') { + return $this->pointsForBuchholz(); + } elseif (isset($this->BinaryData[$key])) { + return $this->BinaryData[$key]; } return null; } /** - * Sets binary data that is read out the pairtwo file but is not needed immediately + * 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 Player + * @param string $key + * @param bool|int|DateTime|string $Valueey */ - public function setBinaryData(string $Key, $Value): Player + public function __set(string $key, $Valueey): void { - $this->BinaryData[$Key] = $Value; - return $this; + $this->BinaryData[$key] = $Valueey; } } diff --git a/src/Readers/Pairtwo6.php b/src/Readers/Pairtwo6.php index fe65a4c..f0a54c4 100644 --- a/src/Readers/Pairtwo6.php +++ b/src/Readers/Pairtwo6.php @@ -46,95 +46,46 @@ class Pairtwo6 implements ReaderInterface private const CompatibleVersions = ['6.', '5.']; /** @var string */ - private $Release; + public $Release; /** @var Tournament */ - private $Tournament; + public $Tournament; /** @var bool|DateTime|int|string[] */ private $BinaryData; - /** - * Returns the version tag of Pairtwo which created the pairtwo file - * - * @return string - */ - public function getRelease(): string - { - return $this->Release; - } - - /** - * Sets the version tag of Pairtwo which created the pairtwo file - * - * @param string $Release - * @return Pairtwo6 - */ - public function setRelease(string $Release): Pairtwo6 - { - $this->Release = $Release; - return $this; - } - - /** - * Returns the tournament that was read out of the pairtwo file - * - * @return Tournament - */ - public function getTournament(): Tournament - { - return $this->Tournament; - } - - /** - * Sets the tournament that was read out of the pairtwo file - * - * @param Tournament $Tournament - * @return Pairtwo6 - */ - public function setTournament(Tournament $Tournament): Pairtwo6 - { - $this->Tournament = $Tournament; - return $this; - } - - /** * Returns binary data that was read out the pairtwo file but was not needed immediately * - * @param string $Key + * @param string $key * @return bool|DateTime|int|string|null */ - public function getBinaryData(string $Key) + public function __get(string $key) { - if (isset($this->BinaryData[$Key])) { - return $this->BinaryData[$Key]; + if (isset($this->BinaryData[$key])) { + return $this->BinaryData[$key]; } return null; } - /** * 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 + * @param string $key + * @param bool|int|DateTime|string $Valueey */ - public function setBinaryData(string $Key, $Value): Pairtwo6 + public function __set(string $key, $Valueey): void { - $this->BinaryData[$Key] = $Value; - return $this; + $this->BinaryData[$key] = $Valueey; } /** * Reads out $swsfile and returns a Pairtwo6 class object * * @param string $filename - * @return Pairtwo6 * @throws IncompatibleReaderException */ - public function read(string $filename): ReaderInterface + public function read(string $filename): void { $swshandle = fopen($filename, 'rb'); $swscontents = fread($swshandle, filesize($filename)); @@ -144,154 +95,154 @@ class Pairtwo6 implements ReaderInterface $length = 4; - $this->setRelease($this->readData('String', substr($swscontents, $offset, $length))); + $this->Release = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; - if (array_search(substr($this->getRelease(), 0, 2), self::CompatibleVersions) === false) { + if (array_search(substr($this->Release, 0, 2), self::CompatibleVersions) === false) { throw new IncompatibleReaderException("This file was not created with Pairtwo 5 or higher"); } - $this->setTournament(new Tournament()); - $this->getTournament()->setPriorityElo('Nation'); - $this->getTournament()->setPriorityId('Nation'); + $this->Tournament = new Tournament(); + $this->Tournament->PriorityElo = 'Nation'; + $this->Tournament->PriorityId = 'Nation'; // UserCountry $length = 4; - $this->setBinaryData("UserCountry", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->UserCountry = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // SavedOffset $length = 4; - $this->setBinaryData("SavedOffset", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->SavedOffset = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // NewPlayer $length = 4; - $this->setBinaryData("NewPlayer", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->NewPlayer = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // AmericanHandicap $length = 4; - $this->setBinaryData("AmericanHandicap", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->AmericanHandicap = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // LowOrder $length = 4; - $this->setBinaryData("LowOrder", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->LowOrder = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // PairingMethod $length = 4; - $this->setBinaryData("PairingMethod", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->PairingMethod = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // AmericanPresence $length = 4; - $this->setBinaryData("AmericanPresence", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->AmericanPresence = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // CheckSameClub $length = 4; - $this->setBinaryData("CheckSameClub", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->CheckSameClub = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // NoColorCheck $length = 4; - $this->setBinaryData("NoColorCheck", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->NoColorCheck = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // SeparateCategories $length = 4; - $this->setBinaryData("SeparateCategories", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->SeparateCategories = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // EloUsed $length = 4; - $this->setBinaryData("EloUsed", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->EloUsed = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // AlternateColors $length = 4; - $this->setBinaryData("AlternateColors", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->AlternateColors = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // MaxMeetings $length = 4; - $this->setBinaryData("MaxMeetings", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->MaxMeetings = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // MaxDistance $length = 4; - $this->setBinaryData("MaxDistance", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->MaxDistance = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // MinimizeKeizer $length = 4; - $this->setBinaryData("MinimizeKeizer", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->MinimizeKeizer = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // MinRoundsMeetings $length = 4; - $this->setBinaryData("MinRoundsMeetings", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->MinRoundsMeetings = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // MaxRoundsAbsent $length = 4; - $this->setBinaryData("MaxRoundsAbsent", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->MaxRoundsAbsent = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // SpecialPoints $length = 4 * 6; - $this->setBinaryData("SpecialPoints", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->SpecialPoints = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // NewNamePos $length = 4; - $this->setBinaryData("NewNamePos", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->NewNamePos = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // CurrentRound $length = 4; - $this->setBinaryData("CurrentRound", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->CurrentRound = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // CreatedRounds $length = 4; - $this->setBinaryData("CreatedRounds", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->CreatedRounds = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // CreatedPlayers $length = 4; - $this->setBinaryData("CreatedPlayers", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->CreatedPlayers = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // MaxSelection $length = 4; - $this->setBinaryData("MaxSelection", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->MaxSelection = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // NumberOfRounds $length = 4; - $this->setBinaryData("NumberOfRounds", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->NumberOfRounds = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // NumberOfPairings $length = 4; - $this->setBinaryData("NumberOfPairings", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->NumberOfPairings = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // CreatedPairings $length = 4; - $this->setBinaryData("CreatedPairings", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->CreatedPairings = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // PairingElems $length = 4; - $this->setBinaryData("PairingElems", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->PairingElems = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // RandomSeed $length = 4; - $this->setBinaryData("RandomSeed", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->RandomSeed = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // TieOrder @@ -348,44 +299,44 @@ class Pairtwo6 implements ReaderInterface $tiebreak = Tiebreak::None; break; } - $this->getTournament()->addTieBreak(new Tiebreak($tiebreak)); + $this->Tournament->addTieBreak(new Tiebreak($tiebreak)); $offset += $length; } // Categorie $length = 4 * 10; - $this->setBinaryData("Categorie", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->Categorie = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // ExtraPoints $length = 4 * 20; - $this->setBinaryData("ExtraPoints", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->ExtraPoints = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // SelectP $length = 4 * 20; - $this->setBinaryData("SelectP", $this->readData('Int', substr($swscontents, $offset, $length))); + $this->SelectP = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // Players - for ($i = 0; $i < $this->getBinaryData("NewPlayer"); $i++) { + for ($i = 0; $i < $this->NewPlayer; $i++) { $player = new Player(); // Rank (Unused value) $length = 4; - $player->setBinaryData("Rank", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->Rank = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 4; - $player->setBinaryData("NamePos", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->NamePos = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 4; - $player->setId('Fide', $this->readData('Int', substr($swscontents, $offset, $length) . "")); + $player->setId('Fide', $this->readData('Int', substr($swscontents, $offset, $length))); $offset += $length; $length = 4; - $player->setBinaryData("ExtraPts", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->ExtraPts = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 4; @@ -393,7 +344,7 @@ class Pairtwo6 implements ReaderInterface $offset += $length; $length = 4; - $player->SetDateOfBirth($this->readData('Date', substr($swscontents, $offset, $length))); + $player->DateOfBirth = $this->readData('Date', substr($swscontents, $offset, $length)); $offset += $length; $length = 4; @@ -401,7 +352,7 @@ class Pairtwo6 implements ReaderInterface $offset += $length; $length = 4; - $player->setBinaryData("Points", $this->readData('Int', substr($swscontents, $offset, $length)) / 2); + $player->Points = $this->readData('Int', substr($swscontents, $offset, $length)) / 2; $offset += $length; $length = 4; @@ -409,15 +360,15 @@ class Pairtwo6 implements ReaderInterface $offset += $length; $length = 4; - $player->setBinaryData("ScoreBuchholz", $this->readData('Int', substr($swscontents, $offset, $length)) / 2); + $player->ScoreBuchholz = $this->readData('Int', substr($swscontents, $offset, $length)) / 2; $offset += $length; $length = 4; - $player->setBinaryData("ScoreAmerican", $this->readData('Int', substr($swscontents, $offset, $length)) / 2); + $player->ScoreAmerican = $this->readData('Int', substr($swscontents, $offset, $length)) / 2; $offset += $length; $length = 4; - $player->setBinaryData("HelpValue", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->HelpValue = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 4; @@ -425,15 +376,15 @@ class Pairtwo6 implements ReaderInterface $offset += $length; $length = 1; - $player->setBinaryData("NameLength", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->NameLength = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 3; - $player->setNation($this->readData('String', substr($swscontents, $offset, $length))); + $player->Nation = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; $length = 1; - $player->setCategory($this->readData('String', substr($swscontents, $offset, $length))); + $player->Category = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; $length = 1; @@ -479,7 +430,7 @@ class Pairtwo6 implements ReaderInterface $title = Title::NONE; break; } - $player->setTitle(new Title($title)); + $player->Title = new Title($title); $offset += $length; $length = 1; @@ -494,129 +445,129 @@ class Pairtwo6 implements ReaderInterface $gender = Gender::Neutral; break; } - $player->setGender(new Gender($gender)); + $player->Gender = new Gender($gender); $offset += $length; $length = 1; - $player->setBinaryData('NumberOfTies', $this->readData('Int', substr($swscontents, $offset, $length))); + $player->NumberOfTies = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 1; - $player->setBinaryData('Absent', $this->readData('Bool', substr($swscontents, $offset, $length))); + $player->Absent = $this->readData('Bool', substr($swscontents, $offset, $length)); $offset += $length; $length = 1; - $player->setBinaryData("ColorDiff", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->ColorDiff = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 1; - $player->setBinaryData("ColorPref", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->ColorPref = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 1; - $player->setBinaryData("Paired", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->Paired = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 1; - $player->setBinaryData("Float", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->Float = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 1; - $player->setBinaryData("FloatPrev", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->FloatPrev = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 1; - $player->setBinaryData("FloatBefore", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->FloatBefore = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; $length = 1; - $player->setBinaryData("TieMatch", $this->readData('Int', substr($swscontents, $offset, $length))); + $player->TieMatch = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; - $this->getTournament()->addPlayer($player); + $this->Tournament->addPlayer($player); } // PlayerNames - $length = (Integer)$this->getBinaryData("NewNamePos") + 0; - $this->setBinaryData("PlayerNames", substr($swscontents, $offset, $length)); + $length = (Integer)$this->NewNamePos + 0; + $this->PlayerNames = substr($swscontents, $offset, $length); $offset += $length; - for ($i = 0; $i < $this->getBinaryData("NewPlayer"); $i++) { - $player = $this->getTournament()->getPlayerById($i); - $namelength = $player->getBinaryData("NameLength"); - $nameoffset = $player->getBinaryData("NamePos"); - $player->setName($this->readData("String", substr($this->getBinaryData("PlayerNames"), $nameoffset, $namelength))); + for ($i = 0; $i < $this->NewPlayer; $i++) { + $player = $this->Tournament->PlayerById($i); + $namelength = $player->NameLength; + $nameoffset = $player->NamePos; + $player->Name = $this->readData("String", substr($this->PlayerNames, $nameoffset, $namelength)); - $this->getTournament()->updatePlayer($i, $player); + $this->Tournament->updatePlayer($i, $player); } // TournamentName $length = 80; - $this->getTournament()->setName($this->readData('String', substr($swscontents, $offset, $length))); + $this->Tournament->Name = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; // TournamentOrganiser $length = 50; - $this->getTournament()->setOrganiser($this->readData('String', substr($swscontents, $offset, $length))); + $this->Tournament->Organiser = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; // TournamentTempo $length = 50; - $this->getTournament()->setTempo($this->readData('String', substr($swscontents, $offset, $length))); + $this->Tournament->Tempo = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; // TournamentCountry $length = 32; - $this->getTournament()->setOrganiserCountry($this->readData('String', substr($swscontents, $offset, $length))); + $this->Tournament->OrganiserCountry = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; // Arbiters $length = 128; - $this->getTournament()->setArbiter($this->readData('String', substr($swscontents, $offset, $length)), 0); + $this->Tournament->addArbiter($this->readData('String', substr($swscontents, $offset, $length))); $offset += $length; // Rounds $length = 4; - $this->getTournament()->setNoOfRounds($this->readData('Int', substr($swscontents, $offset, $length))); + $this->Tournament->NoOfRounds = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // Participants $length = 4; - $this->setBinaryData('Participants', $this->readData('Int', substr($swscontents, $offset, $length))); + $this->Participants = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // Fidehomol $length = 4; - $this->getTournament()->setFideHomol($this->readData('Int', substr($swscontents, $offset, $length))); + $this->Tournament->FideHomol = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // StartDate $length = 4; - $this->getTournament()->setStartDate($this->readData('Date', substr($swscontents, $offset, $length))); + $this->Tournament->StartDate = $this->readData('Date', substr($swscontents, $offset, $length)); $offset += $length; // EndDate $length = 4; - $this->getTournament()->setEndDate($this->readData('Date', substr($swscontents, $offset, $length))); + $this->Tournament->EndDate = $this->readData('Date', substr($swscontents, $offset, $length)); $offset += $length; // Place $length = 36; - $this->getTournament()->setOrganiserPlace($this->readData('String', substr($swscontents, $offset, $length))); + $this->Tournament->OrganiserPlace = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; // First period $length = 32; - $this->getTournament()->setFirstPeriod($this->readData('String', substr($swscontents, $offset, $length))); + $this->Tournament->FirstPeriod = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; // Second period $length = 32; - $this->getTournament()->setSecondPeriod($this->readData('String', substr($swscontents, $offset, $length))); + $this->Tournament->SecondPeriod = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; // Unrated Elo $length = 4; - $this->getTournament()->setNonRatedElo($this->readData('Int', substr($swscontents, $offset, $length))); + $this->Tournament->NonRatedElo = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // Type @@ -636,12 +587,12 @@ class Pairtwo6 implements ReaderInterface $system = TournamentSystem::Swiss; break; } - $this->getTournament()->setSystem(new TournamentSystem($system)); + $this->Tournament->System = new TournamentSystem($system); $offset += $length; // Federation $length = 12; - $this->getTournament()->setFederation($this->readData('String', substr($swscontents, $offset, $length))); + $this->Tournament->Federation = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; // Soustype @@ -656,45 +607,45 @@ class Pairtwo6 implements ReaderInterface * 1 bit = Double round robin */ $length = 4; - $this->setBinaryData('SousType', $this->readData('Hex', substr($swscontents, $offset, $length))); + $this->SousType = $this->readData('Hex', substr($swscontents, $offset, $length)); $offset += $length; // Organising club no $length = 4; - $this->getTournament()->setOrganiserClubNo($this->readData('String', substr($swscontents, $offset, $length), 0)); + $this->Tournament->OrganiserClubNo = $this->readData('String', substr($swscontents, $offset, $length), 0); $offset += $length; // Organising club $length = 8; - $this->getTournament()->setOrganiserClub($this->readData('String', substr($swscontents, $offset, $length))); + $this->Tournament->OrganiserClub = $this->readData('String', substr($swscontents, $offset, $length)); $offset += $length; // Tournament year $length = 4; - $this->getTournament()->setYear($this->readData('Int', substr($swscontents, $offset, $length))); + $this->Tournament->Year = $this->readData('Int', substr($swscontents, $offset, $length)); $offset += $length; // Round dates - for ($i = 0; $i < $this->getTournament()->getNoOfRounds(); $i++) { + for ($i = 0; $i < $this->Tournament->NoOfRounds; $i++) { $length = 4; $round = new Round(); - $round->setRoundNo($i); - $round->setDate($this->readData('Date', substr($swscontents, $offset, $length))); - $this->getTournament()->addRound($round); + $round->RoundNo = $i; + $round->Date = $this->readData('Date', substr($swscontents, $offset, $length)); + $this->Tournament->addRound($round); $offset += $length; } - if ($this->getBinaryData("CurrentRound") > 0) { - for ($i = 0; $i < $this->getBinaryData("NewPlayer"); $i++) { - for ($x = 0; $x < $this->getBinaryData("CreatedRounds"); $x++) { + if ($this->CurrentRound > 0) { + for ($i = 0; $i < $this->NewPlayer; $i++) { + for ($x = 0; $x < $this->CreatedRounds; $x++) { $pairing = new Pairing(); - $pairing->setPlayer($this->getTournament()->getPlayerById($i)); + $pairing->Player = $this->Tournament->PlayerById($i); $length = 4; $opponent = $this->readData('Int', substr($swscontents, $offset, $length)); if ($opponent != 4294967295) { - $pairing->setOpponent($this->getTournament()->getPlayerById($opponent)); + $pairing->Opponent = $this->Tournament->PlayerById($opponent); } $offset += $length; @@ -714,7 +665,7 @@ class Pairtwo6 implements ReaderInterface $color = Color::None; break; } - $pairing->setColor(new Color($color)); + $pairing->Color = new Color($color); $offset += $length; $length = 1; @@ -754,15 +705,15 @@ class Pairtwo6 implements ReaderInterface $result = Result::None; break; } - $pairing->setResult(new Result($result)); + $pairing->Result = new Result($result); $offset += $length; - $pairing->setRound($x); + $pairing->Round = $x; $offset += 2; - $pairing->setBoard(-1); - if ($x < $this->getBinaryData("CurrentRound")) { - $this->getTournament()->addPairing($pairing); + $pairing->Board = -1; + if ($x < $this->CurrentRound) { + $this->Tournament->addPairing($pairing); } } } @@ -770,8 +721,7 @@ class Pairtwo6 implements ReaderInterface $this->addTiebreaks(); - $this->getTournament()->pairingsToRounds(); - return $this; + $this->Tournament->pairingsToRounds(); } /** @@ -878,11 +828,11 @@ class Pairtwo6 implements ReaderInterface /** - * @return $this + * Adds the first tiebreak to the tournament */ - private function addTiebreaks(): Pairtwo6 + private function addTiebreaks(): void { - switch ($this->getTournament()->getSystem()) { + switch ($this->Tournament->System) { case TournamentSystem::Keizer: $firstElement = new Tiebreak(Tiebreak::Keizer); break; @@ -892,9 +842,8 @@ class Pairtwo6 implements ReaderInterface $firstElement = new Tiebreak(Tiebreak::Points); break; } - $tiebreaks = $this->getTournament()->getTiebreaks(); + $tiebreaks = $this->Tournament->Tiebreaks; array_unshift($tiebreaks, $firstElement); - $this->getTournament()->setTiebreaks($tiebreaks); - return $this; + $this->Tournament->Tiebreaks = $tiebreaks; } } diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index 71cdd99..22d0ed5 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -34,14 +34,14 @@ use DateTime; class Swar4 implements ReaderInterface { /** @var Tournament */ - private $tournament; + public $Tournament; + + /** @var string */ + public $Release; /** @var bool|int|DateTime|string[] */ private $BinaryData; - /** @var string */ - private $Release; - /** @var array */ private const CompatibleVersions = ['v4.']; @@ -106,53 +106,55 @@ class Swar4 implements ReaderInterface /** * @param string $filename - * @return ReaderInterface * @throws IncompatibleReaderException */ - public function read(string $filename): ReaderInterface + public function read(string $filename): void { $swshandle = fopen($filename, 'rb'); - $this->setRelease($this->readData('String', $swshandle)); - if (array_search(substr($this->getRelease(), 0, 3), self::CompatibleVersions) === false) { + $this->Release = $this->readData('String', $swshandle); + if (array_search(substr($this->Release, 0, 3), self::CompatibleVersions) === false) { throw new IncompatibleReaderException("This file was not created with Swar 4"); } - $this->setTournament(new Tournament()); + $this->Tournament = 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)); + $this->Guid = $this->readData('String', $swshandle); + $this->MacAddress = $this->readData('String', $swshandle); - $this->getTournament()->setArbiter($this->readData('String', $swshandle), 0); - $this->getTournament()->setArbiter($this->readData('String', $swshandle), 1); + // [Tournoi] + $this->readData('String', $swshandle); - $this->getTournament()->setStartDate($this->readData('Date', $swshandle)); - $this->getTournament()->setEndDate($this->readData('Date', $swshandle)); + $this->Tournament->Name = $this->readData('String', $swshandle); + $this->Tournament->Organiser = $this->readData('String', $swshandle); + $this->Tournament->OrganiserClub = $this->readData('String', $swshandle); + $this->Tournament->OrganiserPlace = $this->readData('String', $swshandle); + + $this->Tournament->addArbiter($this->readData('String', $swshandle)); + $this->Tournament->addArbiter($this->readData('String', $swshandle)); + + $this->Tournament->StartDate = $this->readData('Date', $swshandle); + $this->Tournament->EndDate = $this->readData('Date', $swshandle); // Tempo string is not variable and dependant on kind of tournament - $this->getTournament()->setBinaryData('TempoIndex', $this->readData('Int', $swshandle)); + $this->Tournament->TempoIndex = $this->readData('Int', $swshandle); - $this->getTournament()->setNoOfRounds($this->readData('Int', $swshandle)); + $this->Tournament->NoOfRounds = $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->Tournament->FRBEfrom = $this->readData('Int', $swshandle); + $this->Tournament->FRBEto = $this->readData('Int', $swshandle); + $this->Tournament->FIDEfrom = $this->readData('Int', $swshandle); + $this->Tournament->FIDEto = $this->readData('Int', $swshandle); + $this->Tournament->CatSepares = $this->readData('Int', $swshandle); + $this->Tournament->AfficherEloOuPays = $this->readData('Int', $swshandle); - $this->getTournament()->setFideHomol($this->readData('Int', $swshandle)); + $this->Tournament->FideHomol = $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)); + $this->Tournament->FideId = $this->readData('String', $swshandle); + $this->Tournament->FideArbitre1 = $this->readData('String', $swshandle); + $this->Tournament->FideArbitre2 = $this->readData('String', $swshandle); + $this->Tournament->FideEmail = $this->readData('String', $swshandle); + $this->Tournament->FideRemarques = $this->readData('String', $swshandle); switch ($this->readData('Int', $swshandle)) { case 0: @@ -173,26 +175,26 @@ class Swar4 implements ReaderInterface $system = TournamentSystem::American; break; } - $this->getTournament()->setSystem(new TournamentSystem($system)); + $this->Tournament->System = new TournamentSystem($system); - $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->Tournament->Dummy1 = $this->readData('Int', $swshandle); + $this->Tournament->Dummy2 = $this->readData('Int', $swshandle); + $this->Tournament->SW_AmerPresence = $this->readData('Int', $swshandle); + $this->Tournament->Plusieurs = $this->readData('Int', $swshandle); + $this->Tournament->FirstTable = $this->readData('Int', $swshandle); + $this->Tournament->SW321_Win = $this->readData('Int', $swshandle); + $this->Tournament->SW321_Nul = $this->readData('Int', $swshandle); + $this->Tournament->SW321_Los = $this->readData('Int', $swshandle); + $this->Tournament->SW321_Bye = $this->readData('Int', $swshandle); + $this->Tournament->SW321_Pre = $this->readData('Int', $swshandle); + $this->Tournament->EloUsed = $this->readData('Int', $swshandle); + $this->Tournament->TournoiStd = $this->readData('Int', $swshandle); + $this->Tournament->TbPersonel = $this->readData('Int', $swshandle); + $this->Tournament->ApparOrder = $this->readData('Int', $swshandle); + $this->Tournament->EloEqual = $this->readData('Int', $swshandle); + $this->Tournament->ByeValue = $this->readData('Int', $swshandle); + $this->Tournament->AbsValue = $this->readData('Int', $swshandle); + $this->Tournament->FF_Value = $this->readData('Int', $swshandle); switch ($this->readData('Int', $swshandle)) { case 0: @@ -218,21 +220,23 @@ class Swar4 implements ReaderInterface $federation = 'FIDE'; break; } - $this->getTournament()->setFederation($federation); - $this->getTournament()->setNonRatedElo(0); - $this->getTournament()->setOrganiserClubNo(0); - $this->getTournament()->setBinaryData('[DATES]', $this->readData('String', $swshandle)); + $this->Tournament->Federation = $federation; + $this->Tournament->NonRatedElo = 0; + $this->Tournament->OrganiserClubNo = 0; + // [DATES] + $this->readData('String', $swshandle); - $this->getTournament()->setTempo(Self::Tempos[$this->getTournament()->getBinaryData('TournoiStd')][$this->getTournament()->getBinaryData('TempoIndex')]); + $this->Tournament->Tempo = Self::Tempos[$this->Tournament->TournoiStd][$this->Tournament->TempoIndex]; - for ($i = 0; $i < $this->getTournament()->getNoOfRounds(); $i++) { + for ($i = 0; $i < $this->Tournament->NoOfRounds; $i++) { $round = new Round(); - $round->setRoundNo($i); - $round->setDate($this->readData('Date', $swshandle)); - $this->getTournament()->addRound($round); + $round->RoundNo = $i; + $round->Date = $this->readData('Date', $swshandle); + $this->Tournament->addRound($round); } - $this->getTournament()->setBinaryData('[TIE_BREAK]', $this->readData('String', $swshandle)); + // [TIE_BREAK] + $this->readData('String', $swshandle); $tiebreaks = []; for ($i = 0; $i < 5; $i++) { @@ -289,45 +293,50 @@ class Swar4 implements ReaderInterface } $tiebreaks[] = new Tiebreak($tiebreak); } - $this->getTournament()->setTiebreaks($tiebreaks); + $this->Tournament->Tiebreaks = $tiebreaks; - $this->getTournament()->setBinaryData('[EXCLUSION]', $this->readData('String', $swshandle)); - $this->getTournament()->setBinaryData('ExclusionType', $this->readData('Int', $swshandle)); - $this->getTournament()->setBinaryData('ExclusionValue', $this->readData('String', $swshandle)); + // [EXCLUSION] + $this->readData('String', $swshandle); + $this->Tournament->ExclusionType = $this->readData('Int', $swshandle); + $this->Tournament->ExclusionValue = $this->readData('String', $swshandle); - $this->getTournament()->setBinaryData('[CATEGORIES]', $this->readData('String', $swshandle)); + // [CATEGORIES] + $this->readData('String', $swshandle); - $this->getTournament()->setBinaryData('Catogory_type', $this->readData('Int', $swshandle)); + $this->Tournament->Catogory_type = $this->readData('Int', $swshandle); for ($i = 0; $i <= 12; $i++) { - $this->getTournament()->setBinaryData('Category_' . $i . '_Cat1', $this->readData('String', $swshandle)); + $category[$i]['Cat1'] =$this->readData('String', $swshandle); } for ($i = 0; $i <= 12; $i++) { - $this->getTournament()->setBinaryData('Category_' . $i . '_Cat2', $this->readData('String', $swshandle)); + $category[$i]['Cat2'] =$this->readData('String', $swshandle); } - - $this->getTournament()->setBinaryData('[XTRA_POINTS]', $this->readData('String', $swshandle)); + $this->Tournament->Category = $category; + // [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)); + $extrapoints[$i]['pts'] = $this->readData('Int', $swshandle); + $extrapoints[$i]['elo'] = $this->readData('Int', $swshandle); } + $this->Tournament->Extrapoints = $extrapoints; - $this->getTournament()->setBinaryData('[JOUEURS]', $this->readData('String', $swshandle)); + // [JOUEURS] + $this->readData('String', $swshandle); $roundNo = 0; $playerNo = 0; - $this->getTournament()->setBinaryData('NumberOfPlayers', $this->readData('Int', $swshandle)); + $this->Tournament->NumberOfPlayers = $this->readData('Int', $swshandle); $pt = 0; - for ($i = 0; $i < $this->getTournament()->getBinaryData('NumberOfPlayers'); $i++) { + for ($i = 0; $i < $this->Tournament->NumberOfPlayers; $i++) { $player = new Player(); - $player->setBinaryData('Classement', $this->readData('Int', $swshandle)); - $player->setName($this->readData('String', $swshandle)); + $player->Classement = $this->readData('Int', $swshandle); + $player->Name = $this->readData('String', $swshandle); $inscriptionNos[$this->readData('Int', $swshandle)] = $i; - $player->setBinaryData('Rank', $this->readData('Int', $swshandle)); - $player->setBinaryData('CatIndex', $this->readData('Int', $swshandle)); - $player->setDateOfBirth($this->readData('Date', $swshandle)); + $player->Rank = $this->readData('Int', $swshandle); + $player->CatIndex = $this->readData('Int', $swshandle); + $player->DateOfBirth = $this->readData('Date', $swshandle); switch ($this->readData('Int', $swshandle)) { case 1: $gender = Gender::Male; @@ -339,12 +348,12 @@ class Swar4 implements ReaderInterface $gender = Gender::Neutral; break; } - $player->setGender(new Gender($gender)); + $player->Gender = new Gender($gender); - $player->setNation($this->readData('String', $swshandle)); + $player->Nation = $this->readData('String', $swshandle); $player->setId('Nation', $this->readData('Int', $swshandle)); $player->setId('Fide', $this->readData('Int', $swshandle)); - $player->setBinaryData('Affliation', $this->readData('Int', $swshandle)); + $player->Affliation = $this->readData('Int', $swshandle); $player->setElo('Nation', $this->readData('Int', $swshandle)); $player->setElo('Fide', $this->readData('Int', $swshandle)); switch ($this->readData('Int', $swshandle)) { @@ -383,52 +392,55 @@ class Swar4 implements ReaderInterface $title = Title::NONE; break; } - $player->setTitle(new Title($title)); + $player->Title = new Title($title); $player->setId('Club', $this->readData('Int', $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 + $player->ClubName = $this->readData('String', $swshandle); + $player->NoOfMatchesNoBye = $this->readData('Int', $swshandle); + $player->Points = $this->readData('Int', $swshandle); // To Calculate by libpairtwo + $player->AmericanPoints = $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 + $tiebreaks[$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)); + $player->Tiebreak = $tiebreaks; + $player->Performance = $this->readData('Int', $swshandle); // To Calculate by libpairtwo + $player->Absent = $this->readData('Int', $swshandle); + $player->AbsentRounds = $this->readData('String', $swshandle); + $player->ExtraPoints = $this->readData('Int', $swshandle); + $player->SpecialPoints = $this->readData('Int', $swshandle); + $player->AllocatedRounds = $this->readData('Int', $swshandle); + // [RONDE] + $this->readData('String', $swshandle); - 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) - 1); - $this->getTournament()->setBinaryData('Pairing_' . $pt . '_table', $this->readData('Int', $swshandle) - 1); - $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)); + if ($player->AllocatedRounds != 0) { + for ($j = 0; $j < $player->AllocatedRounds; $j++) { + $pairing[$pt]['player'] = $i; + $pairing[$pt]['round'] = $this->readData('Int', $swshandle) - 1; + $pairing[$pt]['table'] = $this->readData('Int', $swshandle) - 1; + $pairing[$pt]['opponent'] = $this->readData('Int', $swshandle); + $pairing[$pt]['result'] = $this->readData('Hex', $swshandle); + $pairing[$pt]['color'] = $this->readData('Int', $swshandle); + $pairing[$pt]['float'] = $this->readData('Int', $swshandle); + $pairing[$pt]['extrapoints'] = $this->readData('Int', $swshandle); $pt++; } + $this->Tournament->Pairing = $pairing; } - $this->getTournament()->addPlayer($player); + $this->Tournament->addPlayer($player); } $ptn = 0; - while (null !== $this->getTournament()->getBinaryData('Pairing_' . $ptn . '_round')) { + while (isset($this->Tournament->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')); - if ($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_opponent') != 4294967295) { - $pairing->setOpponent($this->getTournament()->getPlayerById($inscriptionNos[$this->getTournament()->getBinaryData('Pairing_' . $ptn . '_opponent')])); + $pairing->Player = $this->Tournament->PlayerById($this->Tournament->Pairing[$ptn]['player']); + $pairing->Round = $this->Tournament->Pairing[$ptn]['round']; + if ($this->Tournament->Pairing[$ptn]['opponent'] != 4294967295) { + $pairing->Opponent = $this->Tournament->PlayerById($inscriptionNos[$this->Tournament->Pairing[$ptn]['opponent']]); } - switch ($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_result')) { + switch ($this->Tournament->Pairing[$ptn]['result']) { case '1000': $result = Result::Lost; break; @@ -455,12 +467,12 @@ class Swar4 implements ReaderInterface $result = Result::None; break; } - if (array_search($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_table'), [ 16383, 8191 ]) !== false) { + if (array_search($this->Tournament->Pairing[$ptn]['table'], [ 16383, 8191 ]) !== false) { $result = Result::Absent; } - $pairing->setResult(new Result($result)); + $pairing->Result = new Result($result); - switch ($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_color')) { + switch ($this->Tournament->Pairing[$ptn]['color']) { case 4294967295: $color = Color::Black; break; @@ -472,35 +484,17 @@ class Swar4 implements ReaderInterface $color = Color::None; break; } - $pairing->setColor(new Color($color)); + $pairing->Color = new Color($color); - $pairing->setBoard($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_table')); + $pairing->Board = $this->Tournament->Pairing[$ptn]['table']; $ptn++; - $this->getTournament()->addPairing($pairing); + $this->Tournament->addPairing($pairing); } fclose($swshandle); - $this->getTournament()->pairingsToRounds(); + $this->Tournament->pairingsToRounds(); $this->addTiebreaks(); - 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 @@ -568,32 +562,16 @@ class Swar4 implements ReaderInterface 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 swar file but was not needed immediately * - * @param string $Key + * @param string $key * @return bool|DateTime|int|string|null */ - public function getBinaryData(string $Key) + public function __get(string $key) { - if (isset($this->BinaryData[$Key])) { - return $this->BinaryData[$Key]; + if (isset($this->BinaryData[$key])) { + return $this->BinaryData[$key]; } return null; } @@ -601,14 +579,12 @@ class Swar4 implements ReaderInterface /** * 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 + * @param string $key + * @param bool|int|DateTime|string $Valueey */ - public function setBinaryData(string $Key, $Value): Swar4 + public function __set(string $key, $Valueey): void { - $this->BinaryData[$Key] = $Value; - return $this; + $this->BinaryData[$key] = $Valueey; } /** @@ -624,21 +600,17 @@ class Swar4 implements ReaderInterface } } - /** - * @return $this - */ - private function addTiebreaks(): Swar4 + private function addTiebreaks(): void { - switch ($this->getTournament()->getSystem()) { + switch ($this->Tournament->System) { case TournamentSystem::American: case TournamentSystem::Closed: case TournamentSystem::Swiss: default: $firstElement = new Tiebreak(Tiebreak::Points); } - $tiebreaks = $this->getTournament()->getTiebreaks(); + $tiebreaks = $this->Tournament->Tiebreaks; array_unshift($tiebreaks, $firstElement); - $this->getTournament()->setTiebreaks($tiebreaks); - return $this; + $this->Tournament->Tiebreaks = $tiebreaks; } } diff --git a/src/Round.php b/src/Round.php index ca73537..0833a22 100644 --- a/src/Round.php +++ b/src/Round.php @@ -32,55 +32,51 @@ class Round * * @var DateTime */ - private $Date; + public $Date; /** * Array of all games * * @var Game[] */ - private $Games = []; + public $Games = []; /** * Number of the round * * @var int */ - private $RoundNo; + public $RoundNo; /** * Array of all pairings for this round * * @var Pairing[] */ - private $Pairings = []; + public $Pairings = []; - /** + /* * Adds a game to the round * * @param Game $game - * @return Round */ - public function addGame(Game $game): Round + public function addGame(Game $game): void { - $newarray = $this->getGames(); + $newarray = $this->Games; $newarray[] = $game; - $this->setGames($newarray); - return $this; + $this->Games = $newarray; } /** * Adds a pairing to the round * * @param Pairing $pairing - * @return Round */ - public function addPairing(Pairing $pairing): Round + public function addPairing(Pairing $pairing): void { - $newarray = $this->getPairings(); + $newarray = $this->Pairings; $newarray[] = $pairing; - $this->setPairings($newarray); - return $this; + $this->Pairings = $newarray; } /** @@ -88,12 +84,12 @@ class Round * * @return Pairing[] */ - public function getBye(): array + private function bye(): array { - $allPairings = $this->getPairings(); + $allPairings = $this->Pairings; $byePairings = []; foreach ($allPairings as $pairing) { - if ($pairing->getResult() == Result::WonBye) { + if ($pairing->Result == Result::WonBye) { $byePairings[] = $pairing; } } @@ -105,12 +101,12 @@ class Round * * @return Pairing[] */ - public function getAbsent(): array + private function absent(): array { - $allPairings = $this->getPairings(); + $allPairings = $this->Pairings; $absentPairings = []; foreach ($allPairings as $pairing) { - if ($pairing->getResult() == Result::Absent) { + if ($pairing->Result == Result::Absent) { $absentPairings[] = $pairing; } } @@ -122,9 +118,9 @@ class Round * * @return Game[] */ - public function getGamesByBoard(): array + private function gamesByBoard(): array { - $allGames = $this->getGames(); + $allGames = $this->Games; usort($allGames, array($this, 'sortByBoard')); return $allGames; } @@ -138,96 +134,32 @@ class Round */ private function sortByBoard(Game $a, Game $b): int { - if (($a->getBoard() == $b->getBoard()) || ($a->getBoard() === false) || ($b->getBoard() === false)) { + if (($a->Board == $b->Board) || ($a->Board === false) || ($b->Board === false)) { return 0; } - return ($a->getBoard() > $b->getBoard()) ? +1 : -1; + return ($a->Board > $b->Board) ? +1 : -1; } /** - * Returns the date of the round + * Magic method to read out several fields. If field was not found it is being searched in the binary data fields * - * @return DateTime + * @param string $key + * @return bool|DateTime|int|string|null */ - public function getDate(): DateTime + public function __get(string $key) { - return $this->Date; - } - /** - * Sets the date of the round - * - * @param DateTime $Date - * @return Round - */ - public function setDate(DateTime $Date): Round - { - $this->Date = $Date; - return $this; - } - - /** - * Returns an array of all games for the round - * - * @return Game[] - */ - public function getGames(): array - { - return $this->Games; - } - - /** - * Sets an array of all games for the round - * - * @param Game[] $Games - * @return Round - */ - public function setGames(array $Games): Round - { - $this->Games = $Games; - return $this; - } - - /** - * Returns the round number of the round - * - * @return int - */ - public function getRoundNo(): int - { - return $this->RoundNo; - } - - /** - * Sets the round number of the round - * - * @param int $RoundNo - * @return Round - */ - public function setRoundNo(int $RoundNo): Round - { - $this->RoundNo = $RoundNo; - return $this; - } - - /** - * Returns an array of all pairings for the round - * - * @return Pairing[] - */ - public function getPairings(): array - { - return $this->Pairings; - } - - /** - * Sets an array of all pairings for the round - * - * @param Pairing[] $Pairings - * @return Round - */ - public function setPairings(array $Pairings): Round - { - $this->Pairings = $Pairings; - return $this; + if ($key == 'Bye') { + return $this->bye(); + } + elseif ($key == 'Absent') { + return $this->absent(); + } + elseif ($key == 'GamesByBoard') { + return $this->gamesByBoard(); + } + elseif (isset($this->BinaryData[$key])) { + return $this->BinaryData[$key]; + } + return null; } } diff --git a/src/Tournament.php b/src/Tournament.php index 360f72e..71ae04c 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -31,76 +31,76 @@ use DateTime; class Tournament { /** @var string */ - private $Name; + public $Name; /** @var string */ - private $Organiser; + public $Organiser; /** @var int */ - private $OrganiserClubNo; + public $OrganiserClubNo; /** @var string */ - private $OrganiserClub; + public $OrganiserClub; /** @var string */ - private $OrganiserPlace; + public $OrganiserPlace; /** @var string */ - private $OrganiserCountry; + public $OrganiserCountry; /** @var int */ - private $FideHomol; + public $FideHomol; /** @var DateTime */ - private $StartDate; + public $StartDate; /** @var DateTime */ - private $EndDate; + public $EndDate; /** @var string[] */ - private $Arbiters; + public $Arbiters; /** @var int */ - private $NoOfRounds; + public $NoOfRounds; /** @var Round[] */ - private $Rounds = []; + public $Rounds = []; /** @var string */ - private $Tempo; + public $Tempo; /** @var int */ - private $NonRatedElo; + public $NonRatedElo; /** @var TournamentSystem */ - private $System; + public $System; /** @var string */ - private $FirstPeriod; + public $FirstPeriod; /** @var string */ - private $SecondPeriod; + public $SecondPeriod; /** @var string */ - private $Federation; + public $Federation; /** @var Player[] */ - private $Players = []; + public $Players = []; /** @var int */ - private $Year; + public $Year; /** @var Pairing[] */ - private $Pairings = []; + public $Pairings = []; /** @var Tiebreak[] */ - private $Tiebreaks = []; + public $Tiebreaks = []; /** @var string */ - private $PriorityElo = 'Fide'; + public $PriorityElo = 'Fide'; /** @var string */ - private $PriorityId = 'Nation'; + public $PriorityId = 'Nation'; /** @var bool|DateTime|int|string[] */ private $BinaryData = []; @@ -111,23 +111,22 @@ class Tournament * @param integer $id * @return Player */ - public function getPlayerById(int $id): Player + public function PlayerById(int $id): Player { - return $this->GetPlayers()[$id]; + return $this->Players[$id]; } /** * Adds a player * * @param Player $Player - * @return Tournament + * */ - public function addPlayer(Player $Player): Tournament + public function addPlayer(Player $Player): void { - $newArray = $this->GetPlayers(); + $newArray = $this->Players; $newArray[] = $Player; - $this->setPlayers($newArray); - return $this; + $this->Players = $newArray; } /** @@ -135,42 +134,39 @@ class Tournament * * @param int $id * @param Player $player - * @return Tournament + * */ - public function updatePlayer(int $id, Player $player): Tournament + public function updatePlayer(int $id, Player $player): void { - $newArray = $this->GetPlayers(); + $newArray = $this->Players; $newArray[$id] = $player; - $this->setPlayers($newArray); - return $this; + $this->Players = $newArray; } /** * Adds a Tiebreak * * @param Tiebreak $tiebreak - * @return Tournament + * */ - public function addTiebreak(Tiebreak $tiebreak): Tournament + public function addTiebreak(Tiebreak $tiebreak): void { - $newArray = $this->getTiebreaks(); + $newArray = $this->Tiebreaks; $newArray[] = $tiebreak; - $this->setTiebreaks($newArray); - return $this; + $this->Tiebreaks = $newArray; } /** * Adds a round with given Round object * * @param Round $round - * @return Tournament + * */ - public function addRound(Round $round): Tournament + public function addRound(Round $round): void { - $newArray = $this->getRounds(); - $newArray[$round->getRoundNo()] = $round; - $this->setRounds($newArray); - return $this; + $newArray = $this->Rounds; + $newArray[$round->RoundNo] = $round; + $this->Rounds = $newArray; } /** @@ -179,23 +175,22 @@ class Tournament * @param int $roundNo * @return Round */ - public function getRoundByNo(int $roundNo): Round + public function RoundByNo(int $roundNo): Round { - return $this->getRounds()[$roundNo]; + return $this->Rounds[$roundNo]; } /** * Adds a pairing to the tournament * * @param Pairing $pairing - * @return Tournament + * */ - public function addPairing(Pairing $pairing): Tournament + public function addPairing(Pairing $pairing): void { - $newArray = $this->GetPairings(); + $newArray = $this->Pairings; $newArray[] = $pairing; - $this->setPairings($newArray); - return $this; + $this->Pairings = $newArray; } @@ -203,25 +198,24 @@ class Tournament * Adds an arbiter to the tournament * * @param string $Arbiter - * @return Tournament + * */ - public function addArbiter(string $Arbiter): Tournament + public function addArbiter(string $Arbiter): void { - $newArray = $this->getArbiters(); + $newArray = $this->Arbiters; $newArray[] = $Arbiter; - $this->setArbiters($newArray); - return $this; + $this->Arbiters = $newArray; } /** * Converts pairings into games with a black and white player * - * @return Tournament + * */ - public function pairingsToRounds(): Tournament + public function pairingsToRounds(): void { /** @var Pairing[] $pairings */ - $pairings = $this->getPairings(); + $pairings = $this->Pairings; /** @var Pairing[] */ $cache = array(); @@ -232,11 +226,11 @@ class Tournament /** @var Pairing $pairing */ foreach ($pairings as $pairing) { // Add pairing to player - $pairing->getPlayer()->addPairing($pairing); - $round = $pairing->getRound(); - $color = $pairing->getColor(); + $pairing->Player->addPairing($pairing); + $round = $pairing->Round; + $color = $pairing->Color; - $this->getRoundByNo($round)->addPairing($pairing); + $this->RoundByNo($round)->addPairing($pairing); $opponent = null; /** @@ -245,7 +239,7 @@ class Tournament */ foreach ($cache as $key=>$cached) { if (!is_null($cached)) { - if (($cached->getOpponent() == $pairing->getPlayer()) && ($cached->getRound() == $pairing->getRound())) { + if (($cached->Opponent == $pairing->Player) && ($cached->Round == $pairing->Round)) { $opponent = $cached; $cache[$key] = null; break; @@ -254,35 +248,34 @@ class Tournament } $game = new Game(); if ($color->getValue() == Color::White) { - $game->setWhite($pairing); - $game->setBlack($opponent); + $game->White = $pairing; + $game->Black = $opponent; } elseif ($color->getValue() == Color::Black) { - $game->setWhite($opponent); - $game->setBlack($pairing); + $game->White = $opponent; + $game->Black = $pairing; } - if (is_null($game->getWhite()) || is_null($game->getBlack())) { + if (is_null($game->White) || is_null($game->Black)) { $cache[] = $pairing; } else { // Check if game already exists if (!$this->gameExists($game, $round)) { - $game->setBoard($game->getWhite()->getBoard()); + $game->Board = $game->White->Board; // Add board if inexistent - if ($game->getBoard() == -1) { + if ($game->Board == -1) { if (isset($lastboards[$round])) { $lastboards[$round] += 1; } else { $lastboards[$round] = 0; } - $game->setBoard($lastboards[$round]); - $game->getWhite()->setBoard($lastboards[$round]); - $game->getBlack()->setBoard($lastboards[$round]); + $game->Board = $lastboards[$round]; + $game->White->Board = $lastboards[$round]; + $game->Black->Board = $lastboards[$round]; } $this->AddGame($game, $round); } } } - return $this; } /** @@ -297,24 +290,21 @@ class Tournament $search = [ $round ]; if ($round == -1) { $search = []; - for ($i = 0; $i < $this->getNoOfRounds(); $i++) { + for ($i = 0; $i < $this->NoOfRounds; $i++) { $search[] = $i; } } foreach ($search as $round) { - if (!isset($this->getRounds()[$round])) { + if (!isset($this->Rounds[$round])) { return false; } - $games = $this->getRounds()[$round]->getGames(); + $games = $this->Rounds[$round]->Games; if (is_null($games)) { return false; } foreach ($games as $roundgame) { - if ($roundgame->getWhite() == $game->getWhite() && - $roundgame->getBlack() == $game->getBlack() && - $roundgame->getResult() == $game->getResult() - ) { + if ($game->equals($roundgame)) { return true; } } @@ -328,18 +318,17 @@ class Tournament * * @param Game $game * @param int $round - * @return Tournament + * */ - public function addGame(Game $game, int $round): Tournament + public function addGame(Game $game, int $round): void { - if (!isset($this->getRounds()[$round])) { + if (!isset($this->Rounds[$round])) { $roundObj = new Round(); - $roundObj->setRoundNo($round); + $roundObj->RoundNo = $round; $this->addRound($roundObj); } - $this->getRoundByNo($round)->addGame($game); - return $this; + $this->RoundByNo($round)->addGame($game); } /** @@ -347,30 +336,30 @@ class Tournament * * @return Player[] */ - public function getRanking(): array + private function ranking(): array { - $players = $this->getPlayers(); - foreach ($this->getTiebreaks() as $tbkey=>$tiebreak) { + $players = $this->Players; + foreach ($this->Tiebreaks as $tbkey=>$tiebreak) { foreach ($players as $pkey => $player) { $break = $this->calculateTiebreak($tiebreak, $player, $tbkey); - $tiebreaks = $player->getTiebreaks(); + $tiebreaks = $player->Tiebreaks; $tiebreaks[$tbkey] = $break; - $player->setTiebreaks($tiebreaks); + $player->Tiebreaks = $tiebreaks; $this->updatePlayer($pkey, $player); } } $sortedplayers[0] = $players; - foreach ($this->getTiebreaks() as $tbkey=>$tiebreak) { + foreach ($this->Tiebreaks as $tbkey=>$tiebreak) { $newgroupkey = 0; $tosortplayers = $sortedplayers; $sortedplayers = []; foreach ($tosortplayers as $groupkey=>$sortedplayerselem) { usort($tosortplayers[$groupkey], $this->sortTiebreak($tbkey)); foreach ($tosortplayers[$groupkey] as $playerkey => $player) { - if (!is_null($player->getTiebreaks()[$tbkey])) { + if (!is_null($player->Tiebreaks[$tbkey])) { if ($playerkey != 0) { $newgroupkey++; - if ($player->getTiebreaks()[$tbkey] == $tosortplayers[$groupkey][$playerkey - 1]->getTiebreaks()[$tbkey]) { + if ($player->Tiebreaks[$tbkey] == $tosortplayers[$groupkey][$playerkey - 1]->Tiebreaks[$tbkey]) { $newgroupkey--; } } @@ -399,10 +388,10 @@ class Tournament private function sortTiebreak(int $key): Closure { return function (Player $a, Player $b) use ($key) { - if (($b->getTiebreaks()[$key] == $a->getTiebreaks()[$key]) || ($a->getTiebreaks()[$key] === false) || ($b->getTiebreaks()[$key] === false)) { + if (($b->Tiebreaks[$key] == $a->Tiebreaks[$key]) || ($a->Tiebreaks[$key] === false) || ($b->Tiebreaks[$key] === false)) { return 0; } - return ($b->getTiebreaks()[$key] > $a->getTiebreaks()[$key]) ? +1 : -1; + return ($b->Tiebreaks[$key] > $a->Tiebreaks[$key]) ? +1 : -1; }; } @@ -434,13 +423,13 @@ class Tournament return $this->calculateBlackWin($player); break; case Tiebreak::Between: - return $this->calculateMutualResult($player, $this->getPlayers(), $tbkey); + return $this->calculateMutualResult($player, $this->Players, $tbkey); break; case Tiebreak::Aro: - return $this->calculateAverageRating($player, $this->getPriorityElo()); + return $this->calculateAverageRating($player, $this->PriorityElo); break; case Tiebreak::AroCut: - return $this->calculateAverageRating($player, $this->getPriorityElo(), 1); + return $this->calculateAverageRating($player, $this->PriorityElo, 1); break; case Tiebreak::Koya: return $this->calculateKoya($player); @@ -473,10 +462,10 @@ class Tournament return $this->calculateCumulative($player); break; case Tiebreak::AveragePerformance: - return $this->calculateAveragePerformance($player, $this->getPriorityElo()); + return $this->calculateAveragePerformance($player, $this->PriorityElo); break; case Tiebreak::Performance: - return $player->getPerformance($this->getPriorityElo(), $this->getNonRatedElo()); + return $player->Performance($this->PriorityElo, $this->NonRatedElo); break; default: return null; @@ -488,14 +477,14 @@ class Tournament * * @return int */ - public function getAverageElo(): int + private function averageElo(): int { $totalrating = 0; $players = 0; - foreach ($this->getPlayers() as $player) { - $toadd = $player->getElo($this->getPriorityElo()); + foreach ($this->Players as $player) { + $toadd = $player->getElo($this->PriorityElo); if ($toadd == 0) { - $toadd = $this->getNonRatedElo(); + $toadd = $this->NonRatedElo; } $totalrating += $toadd; @@ -509,9 +498,9 @@ class Tournament * * @return int */ - public function getParticipants(): int + private function participants(): int { - return count($this->getPlayers()); + return count($this->Players); } /** @@ -522,7 +511,7 @@ class Tournament */ private function calculateKeizer(Player $player): ?float { - return $player->getBinaryData('ScoreAmerican'); + return $player->ScoreAmerican; } /** @@ -533,7 +522,7 @@ class Tournament */ private function calculatePoints(Player $player): ?float { - return $player->getPoints(); + return $player->calculatePoints(); } @@ -546,9 +535,9 @@ class Tournament private function calculateBaumbach(Player $player): ?float { $totalwins = 0; - foreach ($player->getPairings() as $pairing) { - if (array_search($pairing->getResult(), Constants::NotPlayed) === false) { - if (array_search($pairing->getResult(), Constants::Won) !== false) { + foreach ($player->Pairings as $pairing) { + if (array_search($pairing->Result, Constants::NotPlayed) === false) { + if (array_search($pairing->Result, Constants::Won) !== false) { $totalwins++; } } @@ -566,8 +555,8 @@ class Tournament private function calculateBlackPlayed(Player $player): ?float { $totalwins = 0; - foreach ($player->getPairings() as $pairing) { - if (array_search($pairing->getColor(), Constants::Black) !== false) { + foreach ($player->Pairings as $pairing) { + if (array_search($pairing->Color, Constants::Black) !== false) { $totalwins++; } } @@ -583,8 +572,8 @@ class Tournament private function calculateBlackWin(Player $player): ?float { $totalwins = 0; - foreach ($player->getPairings() as $pairing) { - if (array_search($pairing->getColor(), Constants::Black) !== false && array_search($pairing->getResult(), Constants::Won) !== false) { + foreach ($player->Pairings as $pairing) { + if (array_search($pairing->Color, Constants::Black) !== false && array_search($pairing->Result, Constants::Won) !== false) { $totalwins++; } } @@ -605,10 +594,10 @@ class Tournament $interestingplayers = $opponents; if ($key != 0) { $interestingplayers = []; - $playerstiebreaks = $player->getTiebreaks(); + $playerstiebreaks = $player->Tiebreaks; array_splice($playerstiebreaks, $key); foreach ($opponents as $opponent) { - $opponenttiebreaks = $opponent->getTiebreaks(); + $opponenttiebreaks = $opponent->Tiebreaks; array_splice($opponenttiebreaks, $key); if (($playerstiebreaks == $opponenttiebreaks) && ($player != $opponent)) { $interestingplayers[] = $opponent; @@ -617,11 +606,11 @@ class Tournament } $points = 0; $totalmatches = 0; - foreach ($player->getPairings() as $pairing) { - if (array_search($pairing->getOpponent(), $interestingplayers) !== false) { - if (array_search($pairing->getResult(), Constants::Won) !== false) { + foreach ($player->Pairings as $pairing) { + if (array_search($pairing->Opponent, $interestingplayers) !== false) { + if (array_search($pairing->Result, Constants::Won) !== false) { $points = $points + 1; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + } elseif (array_search($pairing->Result, Constants::Draw) !== false) { $points = $points + 0.5; } $totalmatches++; @@ -643,11 +632,11 @@ class Tournament */ private function calculateAverageRating(Player $player, string $type, int $cut = 0): ?float { - $pairings = $player->getPairings(); + $pairings = $player->Pairings; $allratings = []; foreach ($pairings as $pairing) { - if (array_search($pairing->getResult(), Constants::NotPlayed) === false) { - $toadd = $pairing->getOpponent()->getElo($type); + if (array_search($pairing->Result, Constants::NotPlayed) === false) { + $toadd = $pairing->Opponent->getElo($type); if ($toadd != 0) { $allratings[] = $toadd; } @@ -672,11 +661,11 @@ class Tournament */ private function calculateAveragePerformance(Player $player, string $type, int $cut = 0): ?float { - $pairings = $player->getPairings(); + $pairings = $player->Pairings; $allratings = []; foreach ($pairings as $pairing) { - if (array_search($pairing->getResult(), Constants::NotPlayed) === false) { - $toadd = $pairing->getOpponent()->getPerformance($type, $this->getNonRatedElo()); + if (array_search($pairing->Result, Constants::NotPlayed) === false) { + $toadd = $pairing->Opponent->Performance($type, $this->NonRatedElo); if ($toadd != 0) { $allratings[] = $toadd; } @@ -698,11 +687,11 @@ class Tournament private function calculateKoya(Player $player, int $cut = 50): ?float { $tiebreak = 0; - foreach ($player->getPairings() as $plkey => $plpairing) { - if (($plpairing->getOpponent()->getPoints() / count($plpairing->getOpponent()->getPairings()) * 100) >= $cut) { - if (array_search($plpairing->getResult(), Constants::Won) !== false) { + foreach ($player->Pairings as $plkey => $plpairing) { + if (($plpairing->Opponent->Points / count($plpairing->Opponent->Pairings) * 100) >= $cut) { + if (array_search($plpairing->Result, Constants::Won) !== false) { $tiebreak += 1; - } elseif (array_search($plpairing->getResult(), Constants::Draw) !== false) { + } elseif (array_search($plpairing->Result, Constants::Draw) !== false) { $tiebreak += 0.5; } } @@ -721,22 +710,22 @@ class Tournament private function calculateBuchholz(Player $player, int $cutlowest = 0, int $cuthighest = 0): ?float { $tiebreak = 0; - $intpairingsWithBye = $player->getPairings(); + $intpairingsWithBye = $player->Pairings; $intpairings = []; $curpoints = 0; $curround = 1; foreach ($intpairingsWithBye as $pairing) { $roundstoplay = (count($intpairingsWithBye)) - $curround; - if (is_null($pairing->getOpponent())) { - $forfait = explode(' ', $pairing->getResult())[0]+0; + if (is_null($pairing->Opponent)) { + $forfait = explode(' ', $pairing->Result)[0]+0; $notaplayer = $curpoints + (1 - $forfait) + 0.5 * $roundstoplay; $intpairings[] = $notaplayer; } else { - $intpairings[] = $pairing->getOpponent()->getPointsForBuchholz(); - if (array_search($pairing->getResult(), Constants::Won) !== false) { + $intpairings[] = $pairing->Opponent->PointsForBuchholz; + if (array_search($pairing->Result, Constants::Won) !== false) { $curpoints += 1; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + } elseif (array_search($pairing->Result, Constants::Draw) !== false) { $curpoints += 0.5; } } @@ -766,12 +755,12 @@ class Tournament private function calculateSonneborn(Player $player): ?float { $tiebreak = 0; - foreach ($player->getPairings() as $key => $pairing) { - if ($pairing->getOpponent()) { - if (array_search($pairing->getResult(), Constants::Won) !== false) { - $tiebreak += $pairing->getOpponent()->getPoints(); - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { - $tiebreak += $pairing->getOpponent()->getPoints() / 2; + foreach ($player->Pairings as $key => $pairing) { + if ($pairing->Opponent) { + if (array_search($pairing->Result, Constants::Won) !== false) { + $tiebreak += $pairing->Opponent->Points; + } elseif (array_search($pairing->Result, Constants::Draw) !== false) { + $tiebreak += $pairing->Opponent->Points / 2; } } } @@ -789,22 +778,22 @@ class Tournament private function calculateKashdan(Player $player, array $points): ?float { $tiebreak = 0; - foreach ($player->getPairings() as $pairing) { + foreach ($player->Pairings as $pairing) { $toadd = 0; - if (array_search($pairing->getResult(), Constants::Won) !== false) { + if (array_search($pairing->Result, Constants::Won) !== false) { $toadd = $points["Won"]; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + } elseif (array_search($pairing->Result, Constants::Draw) !== false) { $toadd = $points["Draw"]; - } elseif (array_search($pairing->getResult(), Constants::Lost) !== false) { + } elseif (array_search($pairing->Result, Constants::Lost) !== false) { $toadd = $points["Lost"]; } - if (array_search($pairing->getResult(), Constants::NotPlayed) !== false) { + if (array_search($pairing->Result, Constants::NotPlayed) !== false) { $toadd = $points["NotPlayed"]; } $tiebreak += $toadd; } - return $tiebreak; // - $player->getNoOfWins(); + return $tiebreak; // - $player->NoOfWins; } /** @@ -817,11 +806,11 @@ class Tournament { $tiebreak = 0; $score = []; - foreach ($player->getPairings() as $pairing) { + foreach ($player->Pairings as $pairing) { $toadd = 0; - if (array_search($pairing->getResult(), Constants::Won) !== false) { + if (array_search($pairing->Result, Constants::Won) !== false) { $toadd = 1; - } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + } elseif (array_search($pairing->Result, Constants::Draw) !== false) { $toadd = 0.5; } $tiebreak += $toadd; @@ -831,564 +820,24 @@ class Tournament } /** - * Returns the name of the tournament + * Magic method to read out several fields. If field was not found it is being searched in the binary data fields * - * @return string + * @param string $key + * @return bool|DateTime|int|string|null */ - public function getName(): string + public function __get(string $key) { - return $this->Name; - } - - /** - * Sets the name of the tournament - * - * @param string $Name - * @return Tournament - */ - public function setName(string $Name): Tournament - { - $this->Name = $Name; - return $this; - } - - /** - * Returns the organiser of the tournament - * - * @return string - */ - public function getOrganiser(): string - { - return $this->Organiser; - } - - /** - * Sets the organiser of the tournament - * - * @param string $Organiser - * @return Tournament - */ - public function setOrganiser(string $Organiser): Tournament - { - $this->Organiser = $Organiser; - return $this; - } - - /** - * Returns the clubidentifier of the tournament - * - * @return int - */ - public function getOrganiserClubNo(): int - { - return $this->OrganiserClubNo; - } - - /** - * Sets the clubidentifier of the tournament - * - * @param int $OrganiserClubNo - * @return Tournament - */ - public function setOrganiserClubNo(int $OrganiserClubNo): Tournament - { - $this->OrganiserClubNo = $OrganiserClubNo; - return $this; - } - - /** - * Returns the club of the organiser - * - * @return string - */ - public function getOrganiserClub(): string - { - return $this->OrganiserClub; - } - - /** - * Sets the club of the organiser - * - * @param string $OrganiserClub - * @return Tournament - */ - public function setOrganiserClub(string $OrganiserClub): Tournament - { - $this->OrganiserClub = $OrganiserClub; - return $this; - } - - /** - * Returns the location of the tournament - * - * @return string - */ - public function getOrganiserPlace(): string - { - return $this->OrganiserPlace; - } - - /** - * Sets the location of the tournament - * - * @param string $OrganiserPlace - * @return Tournament - */ - public function setOrganiserPlace(string $OrganiserPlace): Tournament - { - $this->OrganiserPlace = $OrganiserPlace; - return $this; - } - - /** - * Returns the country where the tournament is held - * - * @return string - */ - public function getOrganiserCountry(): string - { - return $this->OrganiserCountry; - } - - /** - * Sets the country where the tournament is held - * - * @param string $OrganiserCountry - * @return Tournament - */ - public function setOrganiserCountry(string $OrganiserCountry): Tournament - { - $this->OrganiserCountry = $OrganiserCountry; - return $this; - } - - /** - * Returns the fide homologation - * - * @return int - */ - public function getFideHomol(): int - { - return $this->FideHomol; - } - - /** - * Sets the fide homologation - * - * @param int $FideHomol - * @return Tournament - */ - public function setFideHomol(int $FideHomol): Tournament - { - $this->FideHomol = $FideHomol; - return $this; - } - - /** - * Returns the start date of the tournament - * - * @return DateTime - */ - public function getStartDate(): DateTime - { - return $this->StartDate; - } - - /** - * Sets the start date of the tournament - * - * @param DateTime $StartDate - * @return Tournament - */ - public function setStartDate(DateTime $StartDate): Tournament - { - $this->StartDate = $StartDate; - return $this; - } - - /** - * Returns the end date of the tournament - * - * @return DateTime - */ - public function getEndDate(): DateTime - { - return $this->EndDate; - } - - /** - * Sets the end date of the tournament - * - * @param DateTime $EndDate - * @return Tournament - */ - public function setEndDate(DateTime $EndDate): Tournament - { - $this->EndDate = $EndDate; - return $this; - } - - /** - * Returns the arbiter of the tournament - * - * @return string - */ - public function getArbiter(int $order = 0): string - { - return $this->Arbiters[$order]; - } - - /** - * Returns the arbiters of the tournament - * - * @return string - */ - public function getArbiters(): array - { - return $this->Arbiters; - } - - /** - * Sets the arbiter of the tournament - * - * @param string[] $Arbiter - * @return Tournament - */ - public function setArbiter(string $Arbiter, int $order = 0): Tournament - { - $this->Arbiters[$order] = $Arbiter; - return $this; - } - - /** - * Sets the arbiters of the tournament - * - * @param string[] $Arbiters - * @return Tournament - */ - public function setArbiters(array $Arbiters): Tournament - { - $this->Arbiters = $Arbiters; - return $this; - } - - /** - * Returns the number of round - * - * @return int - */ - public function getNoOfRounds(): int - { - return $this->NoOfRounds; - } - - /** - * Sets the number of rounds - * - * @param int $NoOfRounds - * @return Tournament - */ - public function setNoOfRounds(int $NoOfRounds): Tournament - { - $this->NoOfRounds = $NoOfRounds; - return $this; - } - - /** - * Returns an array containing all rounds of the tournament - * - * @return Round[] - */ - public function getRounds(): array - { - return $this->Rounds; - } - - /** - * Sets an array containing all rounds of the tournament - * - * @param Round[] $Rounds - * @return Tournament - */ - public function setRounds(array $Rounds): Tournament - { - $this->Rounds = $Rounds; - return $this; - } - - /** - * Returns the tempo of the tournament - * - * @return string - */ - public function getTempo(): string - { - return $this->Tempo; - } - - /** - * Sets the tempo of the tournament - * - * @param string $Tempo - * @return Tournament - */ - public function setTempo(string $Tempo): Tournament - { - $this->Tempo = $Tempo; - return $this; - } - - /** - * Returns the elo of a player if the player does not have one - * - * @return int - */ - public function getNonRatedElo(): int - { - return $this->NonRatedElo; - } - - /** - * Sets the elo of a player if the player does not have one - * - * @param int $NonRatedElo - * @return Tournament - */ - public function setNonRatedElo(int $NonRatedElo): Tournament - { - $this->NonRatedElo = $NonRatedElo; - return $this; - } - - /** - * Returns the tournament system - * - * @return TournamentSystem - */ - public function getSystem(): TournamentSystem - { - return $this->System; - } - - /** - * Sets the tournament system - * - * @param TournamentSystem $System - * @return Tournament - */ - public function setSystem(TournamentSystem $System): Tournament - { - $this->System = $System; - return $this; - } - - /** - * Returns the first period of the tempo - * - * @return string - */ - public function getFirstPeriod(): string - { - return $this->FirstPeriod; - } - - /** - * Sets the first period of the tempo - * - * @param string $FirstPeriod - * @return Tournament - */ - public function setFirstPeriod(string $FirstPeriod): Tournament - { - $this->FirstPeriod = $FirstPeriod; - return $this; - } - - /** - * Returns the second period of the tempo - * - * @return string - */ - public function getSecondPeriod(): string - { - return $this->SecondPeriod; - } - - /** - * Sets the second period of the tempo - * - * @param string $SecondPeriod - * @return Tournament - */ - public function setSecondPeriod(string $SecondPeriod): Tournament - { - $this->SecondPeriod = $SecondPeriod; - return $this; - } - - /** - * Returns the federation the tournament belongs to - * - * @return string - */ - public function getFederation(): string - { - return $this->Federation; - } - - /** - * Sets the federation the tournament belongs to - * - * @param string $Federation - * @return Tournament - */ - public function setFederation(string $Federation): Tournament - { - $this->Federation = $Federation; - return $this; - } - - /** - * Returns an array of all players of the tournament - * - * @return Player[] - */ - public function getPlayers(): array - { - return $this->Players; - } - - /** - * Sets an array of all players of the tournament - * - * @param Player[] $Players - * @return Tournament - */ - public function setPlayers(array $Players): Tournament - { - $this->Players = $Players; - return $this; - } - - /** - * Returns the year the tournament is held in - * - * @return int - */ - public function getYear(): int - { - return $this->Year; - } - - /** - * Sets the year the tournament is held in - * - * @param int $Year - * @return Tournament - */ - public function setYear(int $Year): Tournament - { - $this->Year = $Year; - return $this; - } - - /** - * Returns an array of all pairings of the tournament - * - * @return Pairing[] - */ - public function getPairings(): array - { - return $this->Pairings; - } - - /** - * Sets an array of all pairings of the tournament - * - * @param Pairing[] $Pairings - * @return Tournament - */ - public function setPairings(array $Pairings): Tournament - { - $this->Pairings = $Pairings; - return $this; - } - - /** - * Returns an array of all tiebreaks of the tournament - * - * @return Tiebreak[] - */ - public function getTiebreaks(): array - { - return $this->Tiebreaks; - } - - /** - * Sets an array of all tiebreaks of the tournament - * - * @param Tiebreak[] $Tiebreaks - * @return Tournament - */ - public function setTiebreaks(array $Tiebreaks): Tournament - { - $this->Tiebreaks = $Tiebreaks; - return $this; - } - - /** - * Returns the elo that has priority - * - * @return string - */ - public function getPriorityElo(): string - { - return $this->PriorityElo; - } - - /** - * Sets the elo that has priority - * - * @param string $PriorityElo - * @return Tournament - */ - public function setPriorityElo(string $PriorityElo): Tournament - { - $this->PriorityElo = $PriorityElo; - return $this; - } - /** - * Returns the identifier that has priority - * - * @return string - */ - public function getPriorityId(): string - { - return $this->PriorityId; - } - - /** - * Sets the identifier that has priority - * - * @param string $PriorityId - * @return Tournament - */ - public function setPriorityId(string $PriorityId): 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) - { - if (isset($this->BinaryData[$Key])) { - return $this->BinaryData[$Key]; + if ($key == 'Participants') { + return $this->participants(); + } + elseif ($key == 'AverageElo') { + return $this->averageElo(); + } + elseif ($key == 'Ranking') { + return $this->ranking(); + } + elseif (isset($this->BinaryData[$key])) { + return $this->BinaryData[$key]; } return null; } @@ -1396,13 +845,12 @@ class Tournament /** * 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 + * @param string $key + * @param bool|int|DateTime|string $Valueeyey + * @return void */ - public function setBinaryData(string $Key, $Value): Tournament + public function __set(string $key, $Valueey): void { - $this->BinaryData[$Key] = $Value; - return $this; + $this->BinaryData[$key] = $Valueey; } } diff --git a/tests/ReadSws_test.php b/tests/ReadSws_test.php index e84802a..11583c1 100644 --- a/tests/ReadSws_test.php +++ b/tests/ReadSws_test.php @@ -30,62 +30,62 @@ require_once '../vendor/autoload.php'; $sws = IOFactory::createReader('Swar-4'); $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 "Place: " . $sws->getTournament()->getOrganiserPlace() . PHP_EOL; -echo "Arbiter 1: " . $sws->getTournament()->getArbiter(0) . PHP_EOL; -echo "Arbiter 2: " . $sws->getTournament()->getArbiter(1) . PHP_EOL; -echo "Rounds: " . $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; -echo "System: " . $sws->getTournament()->getSystem()->getKey() . PHP_EOL; -echo "Place: " . $sws->getTournament()->getOrganiserPlace() . PHP_EOL; -echo "Unrated-Elo: " . $sws->getTournament()->getNonRatedElo() . PHP_EOL; -echo "Federation: " . $sws->getTournament()->getFederation() . PHP_EOL; -echo "Organiser: " . $sws->getTournament()->getOrganiserClubNo() . PHP_EOL; -echo "Fide Elo P1: " . $sws->getTournament()->getPlayerById(0)->getElo('Fide') . PHP_EOL; -echo "Fide Elo P2: " . $sws->getTournament()->getPlayerById(1)->getElo('Fide') . PHP_EOL; -echo "Fide Elo P3: " . $sws->getTournament()->getPlayerById(2)->getElo('Fide') . PHP_EOL; -echo "KBSB Elo P1: " . $sws->getTournament()->getPlayerById(0)->getElo('Nation') . PHP_EOL; -echo "KBSB Elo P2: " . $sws->getTournament()->getPlayerById(1)->getElo('Nation') . PHP_EOL; -echo "KBSB Elo P3: " . $sws->getTournament()->getPlayerById(2)->getElo('Nation') . PHP_EOL; -echo "Name P1: " . $sws->getTournament()->getPlayerById(0)->getName() . PHP_EOL; -echo "Name P2: " . $sws->getTournament()->getPlayerById(1)->getName() . PHP_EOL; -echo "Name P3: " . $sws->getTournament()->getPlayerById(2)->getName() . PHP_EOL; -echo "Gender P1: " . $sws->getTournament()->getPlayerById(0)->getGender()->getKey() . PHP_EOL; -echo "Gender P2: " . $sws->getTournament()->getPlayerById(1)->getGender()->getKey() . PHP_EOL; -echo "Gender P3: " . $sws->getTournament()->getPlayerById(2)->getGender()->getKey() . PHP_EOL; -echo "Absent P1: " . $sws->getTournament()->getPlayerById(0)->getBinaryData("Absent") . PHP_EOL; -echo "Absent P2: " . $sws->getTournament()->getPlayerById(1)->getBinaryData("Absent") . PHP_EOL; -echo "Absent P3: " . $sws->getTournament()->getPlayerById(2)->getBinaryData("Absent") . PHP_EOL; -echo "Date Round 1: " . $sws->getTournament()->getRoundByNo(0)->getDate()->format('d/m/Y') . PHP_EOL; -echo "Date Round 2: " . $sws->getTournament()->getRoundByNo(1)->getDate()->format('d/m/Y') . PHP_EOL; -echo "Date Round 3: " . $sws->getTournament()->getRoundByNo(2)->getDate()->format('d/m/Y') . PHP_EOL; -echo "Game Round 1: " . $sws->getTournament()->getRoundByNo(0)->getGames()[0]->getResult()->getValue() . PHP_EOL; -echo "Game Round 2: " . $sws->getTournament()->getRoundByNo(1)->getGames()[0]->getResult()->getValue() . PHP_EOL; -echo "Game Round 3: " . $sws->getTournament()->getRoundByNo(2)->getGames()[0]->getResult()->getValue() . PHP_EOL; -echo "Color Pairing 1: " . $sws->getTournament()->getPairings()[1]->getColor()->getKey() . PHP_EOL; -echo "Color Pairing 2: " . $sws->getTournament()->getPairings()[2]->getColor()->getKey() . PHP_EOL; -echo "Color Pairing 3: " . $sws->getTournament()->getPairings()[3]->getColor()->getKey() . PHP_EOL; -echo "Player Pairing 1: " . $sws->getTournament()->getPairings()[0]->getPlayer()->getName() . PHP_EOL; -echo "Player Pairing 2: " . $sws->getTournament()->getPairings()[1]->getPlayer()->getName() . PHP_EOL; -echo "Player Pairing 3: " . $sws->getTournament()->getPairings()[2]->getPlayer()->getName() . PHP_EOL; -echo "Bye Round 1: " . $sws->getTournament()->getRoundByNo(2)->getBye()[0]->getPlayer()->getName() . PHP_EOL; -echo "Absent Round 1: " . $sws->getTournament()->getRoundByNo(2)->getAbsent()[0]->getPlayer()->getName() . PHP_EOL; -echo "Tiebreak 1: " . $sws->getTournament()->getTiebreaks()[0]->getValue() . PHP_EOL; -echo "Tiebreak 2: " . $sws->getTournament()->getTiebreaks()[1]->getValue() . PHP_EOL; -echo "Tiebreak 3: " . $sws->getTournament()->getTiebreaks()[2]->getValue() . PHP_EOL; -echo "Tiebreak 4: " . $sws->getTournament()->getTiebreaks()[3]->getValue() . PHP_EOL; -echo "Tiebreak 5: " . $sws->getTournament()->getTiebreaks()[4]->getValue() . PHP_EOL; -echo "Tiebreak 6: " . $sws->getTournament()->getTiebreaks()[5]->getValue() . PHP_EOL; -echo "Average Elo: " . $sws->getTournament()->getAverageElo() . PHP_EOL; -foreach ($sws->getTournament()->getRanking() as $player) { - echo str_pad($player->getName() . '(' . $player->getElo($sws->getTournament()->getPriorityElo()) . ') ', 35) . implode_pad(' ', $player->getTiebreaks(), 5, ' ') . PHP_EOL; +echo "Release: " . $sws->Release() . PHP_EOL; +echo "Name: " . $sws->Tournament()->Name . PHP_EOL; +echo "Organiser: " . $sws->Tournament()->Organiser. PHP_EOL; +echo "TempoIndex: " . $sws->Tournament()->TempoIndex . PHP_EOL; +echo "TempoType: " . $sws->Tournament()->TournoiStd . PHP_EOL; +echo "Tempo: " . $sws->Tournament()->Tempo . PHP_EOL; +echo "Place: " . $sws->Tournament()->OrganiserPlace . PHP_EOL; +echo "Arbiter 1: " . $sws->Tournament()->Arbiters[0] . PHP_EOL; +echo "Arbiter 2: " . $sws->Tournament()->Arbiter[1] . PHP_EOL; +echo "Rounds: " . $sws->Tournament()->NoOfRounds . PHP_EOL; +echo "Fidehomol: " . $sws->Tournament()->FideHomol . PHP_EOL; +echo "Start-Date: " . $sws->Tournament()->StartDate->format('d/m/Y') . PHP_EOL; +echo "End-Date: " . $sws->Tournament()->EndDate->format('d/m/Y') . PHP_EOL; +echo "System: " . $sws->Tournament()->System->Key() . PHP_EOL; +echo "Place: " . $sws->Tournament()->OrganiserPlace . PHP_EOL; +echo "Unrated-Elo: " . $sws->Tournament()->NonRatedElo . PHP_EOL; +echo "Federation: " . $sws->Tournament()->Federation . PHP_EOL; +echo "Organiser: " . $sws->Tournament()->OrganiserClubNo . PHP_EOL; +echo "Fide Elo P1: " . $sws->Tournament()->PlayerById(0)->Elo('Fide') . PHP_EOL; +echo "Fide Elo P2: " . $sws->Tournament()->PlayerById(1)->Elo('Fide') . PHP_EOL; +echo "Fide Elo P3: " . $sws->Tournament()->PlayerById(2)->Elo('Fide') . PHP_EOL; +echo "KBSB Elo P1: " . $sws->Tournament()->PlayerById(0)->Elo('Nation') . PHP_EOL; +echo "KBSB Elo P2: " . $sws->Tournament()->PlayerById(1)->Elo('Nation') . PHP_EOL; +echo "KBSB Elo P3: " . $sws->Tournament()->PlayerById(2)->Elo('Nation') . PHP_EOL; +echo "Name P1: " . $sws->Tournament()->PlayerById(0)->Name . PHP_EOL; +echo "Name P2: " . $sws->Tournament()->PlayerById(1)->Name . PHP_EOL; +echo "Name P3: " . $sws->Tournament()->PlayerById(2)->Name . PHP_EOL; +echo "Gender P1: " . $sws->Tournament()->PlayerById(0)->Gender->Key() . PHP_EOL; +echo "Gender P2: " . $sws->Tournament()->PlayerById(1)->Gender->Key() . PHP_EOL; +echo "Gender P3: " . $sws->Tournament()->PlayerById(2)->Gender->Key() . PHP_EOL; +echo "Absent P1: " . $sws->Tournament()->PlayerById(0)->Absent . PHP_EOL; +echo "Absent P2: " . $sws->Tournament()->PlayerById(1)->Absent . PHP_EOL; +echo "Absent P3: " . $sws->Tournament()->PlayerById(2)->Absent . PHP_EOL; +echo "Date Round 1: " . $sws->Tournament()->RoundByNo(0)->Date->format('d/m/Y') . PHP_EOL; +echo "Date Round 2: " . $sws->Tournament()->RoundByNo(1)->Date->format('d/m/Y') . PHP_EOL; +echo "Date Round 3: " . $sws->Tournament()->RoundByNo(2)->Date->format('d/m/Y') . PHP_EOL; +echo "Game Round 1: " . $sws->Tournament()->RoundByNo(0)->Games[0]->Result->getValue() . PHP_EOL; +echo "Game Round 2: " . $sws->Tournament()->RoundByNo(1)->Games[0]->Result->getValue() . PHP_EOL; +echo "Game Round 3: " . $sws->Tournament()->RoundByNo(2)->Games[0]->Result->getValue() . PHP_EOL; +echo "Color Pairing 1: " . $sws->Tournament()->Pairings[1]->Color->getKey() . PHP_EOL; +echo "Color Pairing 2: " . $sws->Tournament()->Pairings[2]->Color->getKey() . PHP_EOL; +echo "Color Pairing 3: " . $sws->Tournament()->Pairings[3]->Color->getKey() . PHP_EOL; +echo "Player Pairing 1: " . $sws->Tournament()->Pairings[0]->Player->Name . PHP_EOL; +echo "Player Pairing 2: " . $sws->Tournament()->Pairings[1]->Player->Name . PHP_EOL; +echo "Player Pairing 3: " . $sws->Tournament()->Pairings[2]->Player->Name . PHP_EOL; +echo "Bye Round 1: " . $sws->Tournament()->RoundByNo(2)->Bye[0]->Player->Name . PHP_EOL; +echo "Absent Round 1: " . $sws->Tournament()->RoundByNo(2)->Absent[0]->Player->Name . PHP_EOL; +echo "Tiebreak 1: " . $sws->Tournament()->Tiebreaks[0]->Value() . PHP_EOL; +echo "Tiebreak 2: " . $sws->Tournament()->Tiebreaks[1]->Value() . PHP_EOL; +echo "Tiebreak 3: " . $sws->Tournament()->Tiebreaks[2]->Value() . PHP_EOL; +echo "Tiebreak 4: " . $sws->Tournament()->Tiebreaks[3]->Value() . PHP_EOL; +echo "Tiebreak 5: " . $sws->Tournament()->Tiebreaks[4]->Value() . PHP_EOL; +echo "Tiebreak 6: " . $sws->Tournament()->Tiebreaks[5]->Value() . PHP_EOL; +echo "Average Elo: " . $sws->Tournament()->AverageElo . PHP_EOL; +foreach ($sws->Tournament()->Ranking as $player) { + echo str_pad($player->Name . '(' . $player->Elo($sws->Tournament()->PriorityElo) . ') ', 35) . implode_pad(' ', $player->Tiebreaks, 5, ' ') . PHP_EOL; } function implode_pad($glue, $collection, $padlength, $padstring): string