From ce6e501043020935077f67fa88686fbb23e7e371 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Tue, 12 Feb 2019 18:05:19 +0100 Subject: [PATCH] Implemented reading out round dates --- src/Sws.php | 5 ++++- src/Tournament.php | 1 + tests/ReadSws_test.php | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Sws.php b/src/Sws.php index c3b667c..0a06741 100644 --- a/src/Sws.php +++ b/src/Sws.php @@ -472,7 +472,10 @@ class Sws extends SwsModel // Round dates for ($i = 0; $i < $sws->getTournament()->getNoOfRounds(); $i++) { $length = 4; - $sws->setBinaryData('Round_' . $i . '_date', self::ReadData('Date', substr($swscontents, $offset, $length))); + $round = new Round(); + $round->setRoundNo($i); + $round->setDate(self::ReadData('Date', substr($swscontents, $offset, $length))); + $sws->getTournament()->addRound($round); $offset += $length; } diff --git a/src/Tournament.php b/src/Tournament.php index 45fec88..2ea6d80 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -172,6 +172,7 @@ class Tournament extends TournamentModel return false; } $games = $this->getRounds()[$round]->getGames(); + if(is_null($games)) return false; foreach ($games as $roundgame) { if ($roundgame->getWhite() == $game->getWhite() && $roundgame->getBlack() == $game->getBlack() && diff --git a/tests/ReadSws_test.php b/tests/ReadSws_test.php index 84c29ad..582578b 100644 --- a/tests/ReadSws_test.php +++ b/tests/ReadSws_test.php @@ -42,7 +42,7 @@ echo "End-Date: " . $sws->getTournament()->getEndDate()->format('d/m/Y') . P echo "System: " . $sws->getTournament()->getSystem()->getKey() . PHP_EOL; echo "Place: " . $sws->getTournament()->getOrganiserPlace() . PHP_EOL; echo "Unrated-Elo: " . $sws->getTournament()->getNonRatedElo() . PHP_EOL; -echo "Federatiop: " . $sws->getTournament()->getFederation() . PHP_EOL; +echo "Federation: " . $sws->getTournament()->getFederation() . PHP_EOL; echo "Organiser: " . $sws->getTournament()->getOrganiserClubNo() . PHP_EOL; echo "Fide Elo P1: " . $sws->getTournament()->getPlayerById(0)->getFideElo() . PHP_EOL; echo "Fide Elo P2: " . $sws->getTournament()->getPlayerById(1)->getFideElo() . PHP_EOL; @@ -56,3 +56,7 @@ echo "Name P3: " . $sws->getTournament()->getPlayerById(2)->getName() . PHP echo "Absent P1: " . $sws->getTournament()->getPlayerById(0)->getAbsent() . PHP_EOL; echo "Absent P2: " . $sws->getTournament()->getPlayerById(1)->getAbsent() . PHP_EOL; echo "Absent P3: " . $sws->getTournament()->getPlayerById(2)->getAbsent() . 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; +