From bdaa2b31cdde24dc3da39dc89a2bb1acb283c847 Mon Sep 17 00:00:00 2001 From: DHTMLGoodies Date: Thu, 17 Aug 2017 14:31:25 +0200 Subject: [PATCH] updates --- PgnParser.php | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/PgnParser.php b/PgnParser.php index abb3f36..27f3430 100755 --- a/PgnParser.php +++ b/PgnParser.php @@ -150,6 +150,20 @@ class PgnParser return $this->getGameByIndex(0); } + public function getGameByIndexShort($index) + { + $games = $this->getUnparsedGames(); + if (count($games) && count($games) > $index) { + $game = $this->getParsedGame($games[$index]); + $game["moves"] = $this->toShortVersion($game["moves"]); + return $game; + } + return null; + + } + + + public function getGameByIndex($index) { $games = $this->getUnparsedGames(); @@ -185,29 +199,20 @@ class PgnParser return $ret; } - private function getParsedGameShort($unParsedGame) + + private function toShortVersion($branch) { - $this->pgnGameParser->setPgn($unParsedGame); - $ret = $this->pgnGameParser->getParsedData(); - if ($this->fullParsing()) { - $ret = $this->gameParser->getParsedGame($ret, true); - $moves = &$ret["moves"]; - $moves = $this->toShortVersion($moves); - } - return $ret; - } - - - private function toShortVersion($branch){ foreach ($branch as &$move) { $move["n"] = $move["from"] . $move["to"]; - unset($move["m"]); + + #$move["n"] = $move["from"] . $move["to"]; + #unset($move["m"]); unset($move["fen"]); unset($move["from"]); unset($move["to"]); - if(isset($move["variations"])){ + if (isset($move["variations"])) { $move["v"] = array(); - foreach($move["variations"] as $variation){ + foreach ($move["variations"] as $variation) { $move["v"][] = $this->toShortVersion($variation); } } @@ -216,7 +221,9 @@ class PgnParser return $branch; } - private function getParsedGame($unParsedGame) + + private + function getParsedGame($unParsedGame) { $this->pgnGameParser->setPgn($unParsedGame); $ret = $this->pgnGameParser->getParsedData();