/** * @param int $season */ public function apiRetrieveGamesBySeason($season) { $curl = new Curl(); $entityManager = $this->getEntityManager(); /** @var ClubRepository $clubRepository */ $clubRepository = $entityManager->getRepository('Application\\Entity\\Club'); // Loop through year days $date = $season - 1 . '-10-26'; //$date = '2016-01-06'; // End date $end_date = $season . '-06-31'; //$end_date = '2016-01-14'; while (strtotime($date) <= strtotime($end_date)) { $date = date("Ymd", strtotime("+1 day", strtotime($date))); $result = $curl->get(URL_NBA_API, array('date' => $date)); if (isset($result['status']) && $result['status'] == Curl::STATUS_OK && sizeof($result['event'])) { foreach ($result['event'] as $gameData) { $eventId = $gameData['event_id']; if (!$this->gameAlreadyExists($eventId)) { $dateTimeStart = DateTime::createFromFormat('Y-m-d', substr($gameData['start_date_time'], 0, 10)); $homeTeam = $clubRepository->findOneByApiId($gameData['home_team']['team_id']); $awayTeam = $clubRepository->findOneByApiId($gameData['away_team']['team_id']); $homeScore = $gameData['home_points_scored'] == -1 ? 0 : $gameData['home_points_scored']; $awayScore = $gameData['away_points_scored'] == -1 ? 0 : $gameData['away_points_scored']; $game = new Game(); $game->setSlug($eventId)->setDate($dateTimeStart)->setEquipeHome($homeTeam)->setEquipeAway($awayTeam)->setScoreHome($homeScore)->setScoreAway($awayScore); $entityManager->persist($game); } } //$entityManager->flush(); } } $entityManager->flush(); debug('Finished'); }
public function createGame($em) { $game = new Game(); $date = new \Datetime(); $game->setDateadd($date); $game->setDateupd($date); $game->setActive(1); $em->persist($game); $em->flush(); }
public function newAction() { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $game = new Game(); $currentGame = $game->getCurrentGame($em); $user = new User(); $currentUser = $user->loadUserById($em, 1); $this->createCard($em, $currentGame, $currentUser); $this->layout('layout/empty'); echo "OK"; }
/** * Start a new or existing game and redirect to it. * * @return \Zend\Http\Response */ public function startAction() { $id = (int) $this->params()->fromRoute('id'); $gameRepo = $this->getObjectManager()->getRepository(Game::class); $user = $this->getUser(); $game = null; if (null != $id) { $game = $gameRepo->findOneBy(['id' => $id, 'user' => $user->getId(), 'finishedAt' => null]); } if (!$game instanceof Game) { $game = new Game(); $game->setUser($user); $word = Word::getRandomWord($this->getObjectManager()); $game->setWord($word->getWord()); } $game->setLastActionAt(new DateTime()); $this->getObjectManager()->persist($user); $this->getObjectManager()->persist($game); $this->getObjectManager()->flush(); // put the game's id into the session $container = new Container('game'); $container->gameId = $game->getId(); return $this->redirect()->toRoute('application/default', ['controller' => 'game', 'action' => 'play']); }
public function endAction() { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $game = new Game(); $game->setActive(false); }
public function addGame(Game $game) { $game->setUser($this); $this->games->add($game); }