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 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; } }
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 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; }