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 getNumEntrants(Scholarship $scholarship) { $em = $this->getEntityManager(); $q = $em->createQuery('SELECT COUNT(e) FROM GotChosenSiteBundle:ScholarshipEntry e ' . 'WHERE e.scholarship = ?1'); $q->setParameter(1, $scholarship->getId()); return $q->getSingleScalarResult(); }
protected function execute(InputInterface $input, OutputInterface $output) { /* * Create a new EG Scholarship * Add Contest games based on the Top 10 by rank from qualifier games associated with statsMonth * Ensure new Contest games have EGGameStats entries for the contest */ $round = $input->getOption('round'); $month = $input->getOption('month'); // VALUE_REQUIRED only means that --round with no value is unacceptable. // it still allows --round to be left off entirely (hence why it's called an "option") if ($round === null || !is_numeric($round)) { throw new \RuntimeException('round must be given and numeric'); } if ($month !== null && !preg_match('/^\\d{4}-\\d{2}$/', $month)) { throw new \RuntimeException('month must be in yyyy-MM format'); } /** @var EntityManager $em */ $em = $this->getContainer()->get('doctrine')->getManager(); /** @var EGGameRepository $gameRepo */ $gameRepo = $em->getRepository('GotChosenSiteBundle:EGGame'); /** @var ScholarshipRepository $ssRepo */ $ssRepo = $em->getRepository('GotChosenSiteBundle:Scholarship'); /** @var EGGameStatsRepository $gsRepo */ $gsRepo = $em->getRepository('GotChosenSiteBundle:EGGameStats'); $prevContest = $ssRepo->getCurrentEvoGames(); $title = "Evolution Games Contest: Round {$round}"; $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($title)->setScholarshipType(Scholarship::TYPE_EVOGAMES)->setStartDate($start)->setEndDate($end)->setDrawingComplete(false); $em->persist($newContest); $em->flush(); $output->writeln('Created Scholarship:'); $output->writeln($title); $output->writeln('Start Date: ' . $start->format('Y-m-d H:i:s')); $output->writeln('End Date: ' . $end->format('Y-m-d H:i:s')); $output->writeln(''); $output->writeln('Adding Games:'); // add games /** @var EGGame[] $games */ $games = $gameRepo->findQualifierGamesByRank($prevContest, $month, 10); $i = 1; foreach ($games as $game) { $output->writeln("{$i}. " . $game->getGameName()); $i++; // create scholarship mapping $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(); }
private function flashAndRedirect(Scholarship $scholarship) { $sname = $scholarship->getScholarshipName(); if (strtolower(substr($sname, -strlen(' scholarship'))) != ' scholarship') { $sname .= ' Scholarship'; } if ($scholarship->isVideo()) { $this->flash('success', 'You are almost there. To complete your application, please use the form below to submit your video entry.'); return $this->redirectRoute('vs_submit'); } else { $this->flash('success', 'You have successfully applied for the ' . $sname); } return $this->redirectRoute('user_my_profile'); }
/** * @param bool $defaultEmpty If true, instead of returning null, returns a fake Scholarship with ID 0 * @return Scholarship|mixed */ public function getCurrentEvoGames($defaultEmpty = true) { $s = $this->getCurrentOfType(Scholarship::TYPE_EVOGAMES); if ($s) { return $s; } if (!$defaultEmpty) { return null; } return Scholarship::createFake(Scholarship::TYPE_EVOGAMES); }
public function findChampionshipGames(Scholarship $scholarship) { $q = $this->getEntityManager()->createQuery('SELECT g FROM GotChosenSiteBundle:EGGame g ' . 'LEFT JOIN g.scholarships gs ' . 'WHERE gs.scholarship = :sship AND gs.scholarshipType = :scholarshipType'); $q->setParameter('sship', $scholarship->getId()); $q->setParameter('scholarshipType', EGGameScholarships::TYPE_CHAMPIONSHIP); return $q->execute(); }
public function getChampionshipLeaders(Scholarship $scholarship, $month, $limit = 10) { $this->assertMonth($month); $em = $this->getEntityManager(); $q = $em->createQuery('SELECT s, u FROM GotChosenSiteBundle:EGPlayerStats s JOIN s.player u WHERE s.scholarship = :sship AND s.statsMonth = :month ORDER BY s.rank'); $q->setParameter('sship', $scholarship->getId()); $q->setParameter('month', $month); $q->setMaxResults($limit); return $q->getResult(); }
public function getScholarshipEntry(Scholarship $sship) { /** @var ScholarshipEntry[] $entries */ $entries = $this->getScholarshipEntries(); foreach ($entries as $entry) { if ($entry->getScholarship()->getId() == $sship->getId()) { return $entry; } } return null; }