Beispiel #1
0
 /**
  * Get by competitor
  *
  * @param Competitor $competitor
  * @param boolean    $activeOnly
  *
  * @return array
  */
 public function getPicturesByCompetitor(Competitor $competitor, $activeOnly = true)
 {
     $qb = $this->repository->createQueryBuilder('p');
     $qb->where('p.competitor = :competitorId')->setParameter('competitorId', $competitor->getId());
     if ($activeOnly) {
         $qb->andWhere('p.status = :status')->setParameter('status', 'ACTIVE');
     }
     $allPictures = $qb->addOrderBy('p.addedAt', 'DESC')->getQuery()->getResult();
     $pictures = [];
     foreach ($allPictures as $picture) {
         $pictures[] = ['picture' => $picture, 'rank' => $this->getRankForPicture($picture)];
     }
     return $pictures;
 }
Beispiel #2
0
 /**
  * Creates a new competitor by given user data
  *
  * @param array $userData
  *
  * @return Competitor
  */
 public function createNewCompetitorForData($userData)
 {
     $competitor = new Competitor();
     $competitor->setUserId($userData['userId']);
     $competitor->setService($userData['service']);
     $competitor->setUsername($userData['username']);
     $competitor->setRealname($userData['realname']);
     $competitor->setEmail($userData['email']);
     $competitor->setPicture($userData['picture']);
     $this->entityManger->persist($competitor);
     $this->entityManger->flush();
     return $competitor;
 }
Beispiel #3
0
 /**
  * Get a random combination by competition
  * which the currently logged in competitor has not rated on
  *
  * @param Competition $competition
  * @param Session $session
  * @param Competitor $competitor
  *
  * @return Combination
  */
 public function getRandomCombinationByCompetition(Competition $competition, Session $session, $competitor)
 {
     $combination = null;
     $amount = 1;
     $competitionId = $competition->getId();
     $combinationSession = $session->get('hotornot-combinations');
     if (empty($combinationSession)) {
         $combinationSession = [];
     }
     $competitorId = 0;
     if ($competitor instanceof Competitor && $competitor->hasRole('ROLE_OAUTH_USER')) {
         $competitorId = $competitor->getId();
     }
     // get all the combinations the current user has not voted on
     $possibleCombinations = $this->getUnratedCombinationIds($competitionId, $competitorId);
     if (!empty($possibleCombinations)) {
         // check if the session contains an entry
         // with the last combination and display it
         if (array_key_exists($competitionId, $combinationSession)) {
             $combinationData = $combinationSession[$competitionId];
             if (in_array($combinationData['id'], $possibleCombinations)) {
                 $combination = $this->getCombinationById($combinationData['id']);
                 return $combination;
             }
         }
         // randomly select one entry from possible combinations
         $combinationId = $possibleCombinations[array_rand($possibleCombinations)];
         // get the combination
         $combination = $this->getCombinationById($combinationId);
     }
     if (empty($combination)) {
         // unset last displayed combination
         unset($combinationSession[$competitionId]);
     } else {
         // set the last displayed combination
         $combinationSession[$competitionId] = ['id' => $combination->getId(), 'reversed' => 1 === rand(0, 1)];
     }
     // update the session
     $session->set('hotornot-combinations', $combinationSession);
     return $combination;
 }
Beispiel #4
0
 /**
  * Get votes for a given competitor
  *
  * @param Competitor $competitor
  * @param integer    $limit
  *
  * @return array
  */
 public function getVotesForCompetitor(Competitor $competitor, $limit = 50)
 {
     return $this->repository->createQueryBuilder('v')->where('v.competitor = :competitorId')->setParameter('competitorId', $competitor->getId())->addOrderBy('v.votedAt', 'DESC')->setMaxResults($limit)->getQuery()->getResult();
 }