protected function execute(InputInterface $input, OutputInterface $output) { // The 4 games from production that we'll be basing our test games off of. $gameData = [['secretKey' => '095611a0c2c735355e099c15c836f157', 'swfFile' => 'https://s3.amazonaws.com/ProdContent/evogames/games/2014/02/18/5303c96091eed.unity3d'], ['secretKey' => '6529e08a1ded1e6da6e73421a4e75de7', 'swfFile' => 'https://s3.amazonaws.com/ProdContent/evogames/games/2014/02/21/5307e1ac341e0.unity3d'], ['secretKey' => 'c6d117f7c54467adefc7a6fad4d1847c', 'swfFile' => 'https://s3.amazonaws.com/ProdContent/evogames/games/2014/02/22/5309585bf3b35.unity3d'], ['secretKey' => 'df8f22de661514c530d76e80b22d3d98', 'swfFile' => 'https://s3.amazonaws.com/ProdContent/evogames/games/2014/02/23/530abf78b9e5e.unity3d']]; $em = $this->getContainer()->get('doctrine')->getManager(); $userManager = $this->getContainer()->get('fos_user.user_manager'); $gsRepo = $em->getRepository('GotChosenSiteBundle:EGGameStats'); // The usernames for the 10 users that we'll be basing our test games off of. foreach (range(11, 20) as $n) { $userData[] = $userManager->findUserByUsername("spattersontest{$n}"); } $start = date_create('first day of this month')->setTime(0, 0, 0); $end = date_create('last day of this month')->setTime(23, 59, 59); $newContest = new Scholarship(); $newContest->setScholarshipName("Evolution Games Contest")->setScholarshipType(Scholarship::TYPE_EVOGAMES)->setStartDate($start)->setEndDate($end)->setDrawingComplete(false); $em->persist($newContest); $em->flush(); for ($i = 0; $i < 10; $i++) { $thisGame = $gameData[$i % 4]; $user = $userData[$i]; $gameName = $user->getUsername() . ": Test Game " . $i + 1; $game = new EGGame(); $game->setUser($user)->setSecretKey($thisGame['secretKey'])->setSwfFile($thisGame['swfFile'])->setGameName($gameName)->setGameSynopsis("Test Game Synopsis")->setStudioName("Test Studio")->setStudioProfile("Test Studio Profile")->setType(EGGame::TYPE_UNITY)->setStatus(EGGame::STATUS_ACTIVE); $em->persist($game); $em->flush(); $mapping = EGGameScholarships::make($game, $newContest, EGGameScholarships::TYPE_CONTEST); $em->persist($mapping); $game->addScholarship($mapping); // add game stats record if needed $gsRepo->getOrCreate($game, $start->format('Y-m')); $em->flush(); } }
public function getOrCreate(EGGame $game, User $user, $month) { $this->assertMonth($month); $result = $this->findOneBy(['game' => $game->getId(), 'user' => $user->getId(), 'statsMonth' => $month]); if ($result !== null) { return $result; } $result = new EGGameResult(); $result->setGame($game)->setUser($user)->setStatsMonth($month)->setPlays(0)->setWins(0)->setLosses(0); $this->getEntityManager()->persist($result); return $result; }
public function getOrCreate(EGGame $game, $month) { $this->assertMonth($month); $stats = $this->findOneBy(['game' => $game->getId(), 'statsMonth' => $month]); if ($stats !== null) { return $stats; } $stats = new EGGameStats(); $stats->setGame($game)->setStatsMonth($month)->setRank(0)->setMonthPlays(0)->setMonthRatedFeedbacks(0)->setMonthVotes(0)->setLastUpdated(new \DateTime()); $this->getEntityManager()->persist($stats); return $stats; }
public function fetchHighestFeedback(EGGame $game, User $user, $month) { $q = $this->getEntityManager()->createQuery('SELECT MAX(f.developerRating) FROM GotChosenSiteBundle:EGFeedback f WHERE f.game = :game AND f.user = :user AND f.createdDate >= :start AND f.createdDate < :end'); $q->setParameter('game', $game->getId()); $q->setParameter('user', $user->getId()); $q->setParameter('start', $month . '-01 00:00:00'); $q->setParameter('end', Dates::nextMonth($month) . '-01 00:00:00'); try { return (int) $q->getSingleScalarResult(); } catch (QueryException $e) { return 0; } }
public function getVotesRemaining(EGGame $game, $ipAddress, $sessionId, \DateTime $day) { $q = $this->getEntityManager()->createQuery('SELECT COUNT(v.id) FROM GotChosenSiteBundle:EGVote v WHERE v.game = ?1 AND v.ipAddress = ?2 AND v.createdDate BETWEEN ?3 AND ?4 AND v.sessionId = ?5'); $q->setParameter(1, $game->getId()); $q->setParameter(2, $ipAddress); $q->setParameter(3, $day->format('Y-m-d 00:00:00')); $q->setParameter(4, $day->format('Y-m-d 23:59:59')); $q->setParameter(5, $sessionId); $sessionCount = $q->getSingleScalarResult(); if ($sessionCount == 0) { $q = $this->getEntityManager()->createQuery('SELECT COUNT(v.id) FROM GotChosenSiteBundle:EGVote v WHERE v.game = ?1 AND v.ipAddress = ?2 AND v.createdDate BETWEEN ?3 AND ?4'); $q->setParameter(1, $game->getId()); $q->setParameter(2, $ipAddress); $q->setParameter(3, $day->format('Y-m-d 00:00:00')); $q->setParameter(4, $day->format('Y-m-d 23:59:59')); $dayCount = $q->getSingleScalarResult(); return max(0, EGVote::MAX_PER_DAY - $dayCount); } else { return 0; } }
/** * @param Request $request * @throws AccessDeniedException * @return array * * @Route("/evolution-games/submit", name="eg_submit") * @Template */ public function submitAction(Request $request) { return $this->redirectRoute('eg_scholarship'); /** @var User $user */ $user = $this->getUser(); if ($user === null || !$user->hasRole('ROLE_USER')) { $this->flash('error', 'You must be registered and logged in to submit a game.'); throw new AccessDeniedException(); } $game = $this->repo('EGGame')->findOneBy(['user' => $user->getId()]); if ($game) { return $this->redirectRoute('eg_manage'); } // studio name, studio profile, game synopsis, game name, screenshot, avatar, upload game, terms checkbox $fb = $this->createFormBuilder(); $fb->add('studioName', 'text', ['label' => 'Studio Name', 'constraints' => [new NotBlank()]])->add('studioProfile', 'textarea', ['label' => 'Studio Profile', 'constraints' => [new NotBlank()]])->add('gameSynopsis', 'textarea', ['label' => 'Game Synopsis', 'constraints' => [new NotBlank()]])->add('gameName', 'text', ['label' => 'Game Name', 'constraints' => [new NotBlank()]])->add('gameGenre', 'entity', ['class' => 'GotChosenSiteBundle:EGGameGenre', 'property' => 'name'])->add('accept', 'checkbox', ['label' => 'I Accept the Rules', 'widget_checkbox_label' => 'label', 'error_type' => 'block', 'constraints' => [new NotBlank()]]); $form = $fb->getForm(); $form->handleRequest($request); if ($form->isValid()) { /** * Todo: * * 1. Can't use existing game names? * 2. Can't use existing studio names? */ $game = new EGGame(); $game->setUser($user); $game->setStudioName($form->get('studioName')->getData()); $game->setStudioProfile($form->get('studioProfile')->getData()); $game->setGameSynopsis($form->get('gameSynopsis')->getData()); $game->setGameName($form->get('gameName')->getData()); $game->setGenre($form->get('gameGenre')->getData()); $this->em()->persist($game); $this->em()->flush(); $this->flash('success', "Your game was submitted successfully."); return $this->redirectRoute('eg_manage'); } return ['form' => $form->createView()]; }
public function isInQualifier(EGGame $game, Scholarship $scholarship) { $q = $this->getEntityManager()->createQuery('SELECT g FROM GotChosenSiteBundle:EGGame g LEFT JOIN g.scholarships gs WHERE g.id = :game AND (gs.scholarship IS NULL OR gs.scholarship != :sship)'); $q->setParameter('game', $game->getId()); $q->setParameter('sship', $scholarship->getId()); $res = $q->getResult(); return count($res) > 0; }