public function save($request) { $ret = array(); $filePath = $this->getFilePath($request); if (!file_exists($filePath)) { throw new Exception("File not found {$filePath}", 400); } $parser = new PgnParser($filePath); $games = $parser->getGames(); $dbId = $this->getDatabaseId($request); $count = count($games); $pr = LudoDBProgress::getInstance(); $pr->setSteps($count + 1, "Initializing import"); $c = 0; foreach ($games as $game) { $c++; $pr->increment(1, "Importing game " . $c . " of " . $count); $ret[] = $this->importGame($game, $dbId); } $pr->increment(1, "Finished with import"); return $ret; }
public function listOfGames($noCache = false) { if ($this->isGameListInCache() && !$noCache) { return $this->getGameListFromCache(); } $parser = new PgnParser($this->pgnFile, false); $games = $parser->getGames(); $ret = array(); $count = 0; $tokens = preg_split("/[\\/\\.]/s", $this->pgnFile); array_pop($tokens); $idPrefix = array_pop($tokens); foreach ($games as $game) { $game['last_moves'] = $this->getLastMoves($game['moves']); unset($game['moves']); unset($game['metadata']); $game["gameIndex"] = $count; $game["id"] = $idPrefix . '-' . $count; $ret[] = $game; $count++; } $this->saveGameListInCache($ret); return $ret; }
* User: Alf Magne * Date: 23.01.13 * Time: 14:52 * To change this template use File | Settings | File Templates. */ ini_set('display_errors', 'on'); date_default_timezone_set("Europe/Berlin"); require_once __DIR__ . "/../autoload.php"; LudoDB::setHost('127.0.0.1'); LudoDB::setUser('root'); LudoDB::setPassword('administrator'); LudoDB::setDb('PHPUnit'); // Construct database tables $tables = array('Move', 'Game', 'Fen', 'Metadata', 'MetadataValue'); foreach ($tables as $table) { $inst = new $table(); $inst->drop()->yesImSure(); $inst->createTable(); } $profiling = new XHPProfiling('PGN to parser to DB'); $parser = new PgnParser("../../pgn/profiling.pgn"); $games = $parser->getGames(); foreach ($games as $gameData) { $game = new Game(); $game->setDatabaseId(100); $game->setFen($gameData['metadata']['fen']); $game->setMetadata($gameData['metadata']); $game->setMoves($gameData['moves']); $game->commit(); } echo $profiling->end();
private function getGameWithVariation() { $parser = new PgnParser("pgn/test.pgn"); $games = $parser->getGames(); return $games[0]; }