/**
  * @test
  */
 public function shouldCreateViaRequestHandler()
 {
     $id = $this->getUniqueProgressId();
     // given
     $handler = new RequestHandlerMock();
     // when
     $handler->handle("Car/1/read", array('LudoDBProgressID' => $id));
     $progress = new LudoDBProgress($id);
     // then
     $this->assertEquals($id, $progress->getId());
 }
예제 #2
0
 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;
 }
 private function runAndRemoveProgressBar($data)
 {
     if (!empty($data) && is_array($data) && isset($data['LudoDBProgressID'])) {
         $pr = LudoDBProgress::getInstance();
         $pr->save($data['LudoDBProgressID']);
         unset($data['LudoDBProgressID']);
     }
     return $data;
 }
예제 #4
0
 /**
  * Return LudoDBProgress Instance
  * @return LudoDBProgress
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new LudoDBProgress();
     }
     return self::$instance;
 }