public function getByTypeAndDate($type, \DateTime $date)
 {
     Enums::assert($type, Scholarship::$scholarshipTypes);
     try {
         return $this->createQueryBuilder('s')->select('s')->where('s.startDate <= ?1')->andWhere('s.endDate >= ?2')->andWhere('s.scholarshipType = ?3')->setMaxResults(1)->setParameters([1 => $date, 2 => $date, 3 => $type])->getQuery()->getSingleResult();
     } catch (NoResultException $e) {
         return null;
     }
 }
 /**
  * @param EGGame $game
  * @param $phase
  * @param \DateTime $day
  * @return array of "[user => User entity, score => float, isWin => bool, percentile => float]"
  */
 public function getContestPlaysForDay(EGGame $game, $phase, \DateTime $day)
 {
     Enums::assert($phase, EGPlaySession::$phases);
     $median = $this->getMedianScoreForDay($game, $phase, $day);
     if (!$median) {
         return [];
     }
     $q = $this->getEntityManager()->createQuery('SELECT gs, u FROM GotChosenSiteBundle:EGPlaySession gs
          JOIN gs.player u
          WHERE gs.game = :gameId
             AND gs.phase = :phase
             AND gs.isCompleted = 1
             AND gs.endDate >= :dateStart
             AND gs.endDate <= :dateEnd
          ORDER BY gs.score DESC');
     // AND gs.score > :median
     $q->setParameter('gameId', $game->getId());
     $q->setParameter('phase', $phase);
     $q->setParameter('dateStart', $day->format('Y-m-d 00:00:00'));
     $q->setParameter('dateEnd', $day->format('Y-m-d 23:59:59'));
     //$q->setParameter('median', $median);
     /** @var EGPlaySession[] $winningSessions */
     $winningSessions = $q->execute();
     $sessionCount = count($winningSessions);
     // so, reworking now.
     // we need *ALL* winning records, not just unique users.
     $users = [];
     $count = 0;
     foreach ($winningSessions as $session) {
         $user = $session->getPlayer();
         $score = $session->getScore();
         $isWin = $sessionCount == 1 || $score > $median;
         $users[] = ['user' => $user, 'score' => $score, 'isWin' => $isWin];
         if ($isWin) {
             $count++;
         }
     }
     // get percentiles from records that will receive points
     $count = max(1, $count - 1);
     $index = 0;
     foreach ($users as &$rec) {
         if ($rec['isWin']) {
             $rec['percentile'] = 1.0 - 0.5 * $index / $count;
             // ranges from 1.0 to 0.5
             $index++;
         } else {
             $rec['percentile'] = 0;
         }
     }
     return $users;
 }
 public function getTotalPlaySessions(User $player, Scholarship $scholarship, $phase = null)
 {
     if ($phase !== null) {
         Enums::assert($phase, EGPlaySession::$phases);
         $phaseCond = 'AND gs.phase = :phase';
     } else {
         $phaseCond = '';
     }
     $start = $scholarship->getStartDate();
     $end = $scholarship->getEndDate();
     $q = $this->getEntityManager()->createQuery('SELECT COUNT(gs.id) FROM GotChosenSiteBundle:EGPlaySession gs
          WHERE gs.player = :user
              AND gs.isCompleted = 1
              AND gs.endDate >= :dateStart
              AND gs.endDate <= :dateEnd ' . $phaseCond);
     $q->setParameter('user', $player->getId());
     $q->setParameter('dateStart', $start->format('Y-m-d H:i:s'));
     $q->setParameter('dateEnd', $end->format('Y-m-d H:i:s'));
     if ($phase !== null) {
         $q->setParameter('phase', $phase);
     }
     $count = (int) $q->getSingleScalarResult();
     return $count;
 }
Esempio n. 4
0
 /**
  * @param $visibility
  * @return $this
  */
 public function setVisibility($visibility)
 {
     Enums::assert($visibility, self::$visibilities);
     $this->visibility = $visibility;
     return $this;
 }
 public function setScholarshipType($scholarshipType)
 {
     Enums::assert($scholarshipType, self::$scholarship_types);
     $this->scholarshipType = $scholarshipType;
     return $this;
 }
 /**
  * Set phase
  *
  * @param integer $phase
  * @return EGPlaySession
  */
 public function setPhase($phase)
 {
     Enums::assert($phase, self::$phases);
     $this->phase = $phase;
     return $this;
 }
 /**
  * Set fieldType
  *
  * @param string $fieldType
  * @return ProfileProperty
  */
 public function setFieldType($fieldType)
 {
     Enums::assert($fieldType, self::$fieldTypes);
     $this->fieldType = $fieldType;
     return $this;
 }
 /**
  * Set status
  *
  * @param integer $status
  * @return MassMailQueue
  */
 public function setStatus($status)
 {
     Enums::assert($status, self::$statuses);
     $this->status = $status;
     return $this;
 }