public function recalcFeedbackPoints(User $user, Scholarship $scholarship, $month)
 {
     $em = $this->getEntityManager();
     $conn = $em->getConnection();
     /** @var EGPlayerStatsRepository $statsRepo */
     $statsRepo = $em->getRepository('GotChosenSiteBundle:EGPlayerStats');
     // grab all the rated games with their highest ratings
     $stmt = $conn->prepare('SELECT f.game_id, MAX(f.developerRating) max_rating
          FROM EGFeedback f
          WHERE f.user_id = :user
              AND f.createdDate >= :start
              AND f.createdDate < :end
              AND f.ratedDate IS NOT NULL
          GROUP BY f.game_id
          ORDER BY max_rating DESC');
     $stmt->bindValue('user', $user->getId(), \PDO::PARAM_INT);
     $stmt->bindValue('start', $month . '-01 00:00:00', \PDO::PARAM_STR);
     $stmt->bindValue('end', Dates::nextMonth($month) . '-01 00:00:00', \PDO::PARAM_STR);
     $stmt->execute();
     $totalFeedback = 0;
     $count = 0;
     while ($row = $stmt->fetch()) {
         $totalFeedback += $row['max_rating'];
         $count++;
         // stop at 100 feedback or 20 games
         if ($totalFeedback >= 100 || $count >= 20) {
             break;
         }
     }
     $totalFeedback = min($totalFeedback, 100);
     $pstats = $statsRepo->getOrCreate($user, $scholarship, $month);
     $pstats->setFeedbackPoints($totalFeedback);
     $pstats->updateTotalPoints();
     $em->flush();
 }
 /**
  * @param User $user
  * @return ReportCard
  */
 public function getForUser(User $user)
 {
     $uid = (string) $user->getId();
     if ($this->cache->contains($uid)) {
         return $this->cache->fetch($uid);
     }
     /** @var EGPlayerStatsRepository $statsRepo */
     $statsRepo = $this->em->getRepository('GotChosenSiteBundle:EGPlayerStats');
     /** @var EGGameResultRepository $resultsRepo */
     $resultsRepo = $this->em->getRepository('GotChosenSiteBundle:EGGameResult');
     /** @var Scholarship $egScholarship */
     $egScholarship = $this->em->getRepository('GotChosenSiteBundle:Scholarship')->getCurrentEvoGames();
     $playerStats = $statsRepo->getOrCreate($user, $egScholarship, date('Y-m'));
     $card = new ReportCard();
     $card->rank = $playerStats->getRank();
     $card->maxRank = $statsRepo->getTotalPlayers(date('Y-m'));
     $card->qualifierPlays = $statsRepo->getTotalPlaySessions($user, $egScholarship, EGPlaySession::PHASE_QUALIFIER);
     $card->contestPlays = $statsRepo->getTotalPlaySessions($user, $egScholarship, EGPlaySession::PHASE_CONTEST);
     $card->wins = $resultsRepo->getTotalWins($user, date('Y-m'));
     $card->feedbacksRated = min(20, $playerStats->getFeedbacksRated());
     $card->pointsWinning = $playerStats->getGameplayPoints();
     $card->pointsBonus = $playerStats->getBonusPoints();
     $card->pointsFeedback = $playerStats->getFeedbackPoints();
     $card->pointsTotal = $playerStats->getTotalPoints();
     $this->cache->save($uid, $card);
     return $card;
 }
 protected function sendConfirmation($mailer, User $user)
 {
     $templating = $this->getContainer()->get('templating');
     $body = $templating->render('GotChosenSiteBundle:Emails:disabled_user.txt.twig', array('user' => $user));
     $message = \Swift_Message::newInstance()->setSubject('GotChosen: User account for e-mail "' . $user->getEmail() . '" has been cancelled')->setFrom('*****@*****.**', 'GotChosen')->setTo($user->getEmail())->setBody($body);
     $mailer->send($message);
 }
 /**
  * @param User $user
  * @param $month
  * @return integer
  */
 public function getTotalWins(User $user, $month)
 {
     $this->assertMonth($month);
     $q = $this->getEntityManager()->createQuery('SELECT SUM(gr.wins) FROM GotChosenSiteBundle:EGGameResult gr
          WHERE gr.statsMonth = :month AND gr.user = :user');
     $q->setParameter('month', $month);
     $q->setParameter('user', $user->getId());
     return $q->getSingleScalarResult() ?: 0;
     // This function was returning NULL instead of 0
 }
 /**
  * Retrieves play sessions for the given user, optionally filtered by month.
  *
  * @param User $player
  * @param null|string $month In the form of YYYY-MM
  * @return array
  */
 public function findPlaySessions(User $player, $month = null)
 {
     $q = $this->getEntityManager()->createQueryBuilder();
     $q->select('ps', 'g')->from('GotChosenSiteBundle:EGPlaySession', 'ps')->join('ps.game', 'g')->where('ps.player = :user')->setParameter('user', $player->getId())->andWhere('ps.isCompleted = 1');
     if ($month && preg_match('/^\\d{4}-\\d{2}$/', $month)) {
         $q->andWhere('ps.endDate >= :start')->setParameter('start', $month . '-01 00:00:00')->andWhere('ps.endDate < :end')->setParameter('end', Dates::nextMonth($month) . '-01 00:00:00');
     }
     $q->orderBy('ps.endDate');
     return $q->getQuery()->getResult();
 }
 /**
  * @param User $user
  * @param ProfileProperty[] $requiredProps
  * @return bool
  */
 private function canBypassForm(User $user, array $requiredProps)
 {
     foreach ($requiredProps as $key => $prop) {
         // don't think we need to do anything with types (yet)
         // but we have the ProfileProperty in case an "empty" value is something else for some properties.
         //$type = $prop->getFieldType();
         $value = $user->getPropertyValue($key, '');
         if (empty($value)) {
             return false;
         }
     }
     return true;
 }
 /**
  * @param User $sponsor
  * @param Scholarship $sship40k
  * @return EntrySponsor[]
  */
 public function getSponsoring(User $sponsor, Scholarship $sship40k)
 {
     $em = $this->getEntityManager();
     $q = $em->createQuery('SELECT es, e, u FROM GotChosenSiteBundle:EntrySponsor es
          JOIN es.user sponsor
          JOIN es.entry e
          JOIN e.user u
          JOIN e.scholarship s
          WHERE s.id = ?1 AND sponsor.id = ?2');
     $q->setParameter(1, $sship40k->getId());
     $q->setParameter(2, $sponsor->getId());
     return $q->getResult();
 }
 protected function sendConfirmation($mailer, User $user)
 {
     $router = $this->getContainer()->get('router');
     $templating = $this->getContainer()->get('templating');
     $router->setContext(new RequestContext('', 'GET', 'www.gotchosen.com', 'https'));
     $params = ['token' => $user->getConfirmationToken()];
     $url = $router->generate('fos_user_resetting_reset', $params, true);
     $rendered = $templating->render('FOSUserBundle:Resetting:email.txt.twig', array('user' => $user, 'confirmationUrl' => $url));
     // Render the email, use the first line as the subject, and the rest as the body
     $renderedLines = explode("\n", trim($rendered));
     $subject = $renderedLines[0];
     $body = implode("\n", array_slice($renderedLines, 1));
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom('*****@*****.**', 'GotChosen')->setTo($user->getEmail())->setBody($body);
     $mailer->send($message);
     $user->setPasswordRequestedAt(new \DateTime());
     $this->getContainer()->get('fos_user.user_manager')->updateUser($user);
 }
 /**
  * Determines if this property can be seen by the given $viewer.
  * If $viewer is the property's owner, or an administrator, returns true. Otherwise it will compare
  * this property's visible networks with the networks of the viewer, and if at least one matches,
  * this method will return true.
  *
  * @param User $viewer
  * @param array $viewerNetworkIds
  * @return bool
  */
 public function isVisibleBy(User $viewer = null, $viewerNetworkIds = null)
 {
     $visibility = $this->getVisibility();
     // if public, true right away. if not public and the viewer is a guest, false right away.
     if ($visibility == self::VISIBLE_PUBLIC) {
         return true;
     } else {
         if (!$viewer) {
             return false;
         }
     }
     // if we are viewing our own profile, true.
     if ($viewer && $viewer->getId() == $this->getUser()->getId()) {
         return true;
     }
     // if we are an admin, true.
     // however we name these... ROLE_ADMIN is part of symfony, Administrators may be a new thing.
     $viewerRoles = $viewer ? $viewer->getRoles() : [];
     if (in_array('ROLE_SUPER_ADMIN', $viewerRoles) || in_array('Administrator', $viewerRoles)) {
         return true;
     }
     // handle private (false except for owner/admin, handled above), and all registered users.
     if ($visibility == self::VISIBLE_PRIVATE) {
         return false;
     } else {
         if ($visibility == self::VISIBLE_MEMBERS) {
             return $viewer ? true : false;
         }
     }
     // handle custom network-based visibility.
     // if a list of the viewer's network ids is passed, use that to save on processing time.
     if ($viewerNetworkIds === null) {
         $viewerNetworkIds = [];
         foreach ($viewer->getNetworks() as $vnet) {
             $viewerNetworkIds[] = $vnet->getNetwork()->getId();
         }
     }
     return $this->hasIntersectingNetworks($viewerNetworkIds);
 }
 public function userHasGame(User $user)
 {
     $gameRepo = $this->em->getRepository('GotChosenSiteBundle:EGGame');
     $game = $gameRepo->findOneBy(['user' => $user->getId()]);
     return !is_null($game);
 }
 public function handleDeleteForm(User $user, Request $request, UserRepository $userRepo)
 {
     $builder = $this->createFormBuilder();
     $builder->add('current_password', 'password', array('label' => 'form.current_password', 'translation_domain' => 'FOSUserBundle', 'mapped' => false, 'constraints' => new UserPassword()));
     $form = $builder->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $user->setEnabled(false);
         $user->setStatus(User::STATUS_DISABLED_USER);
         /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
         $userManager = $this->container->get('fos_user.user_manager');
         $userManager->updateUser($user);
         $body = $this->renderView('GotChosenSiteBundle:Emails:disabled_user.txt.twig', array('user' => $user));
         $msg = \Swift_Message::newInstance()->setSubject('GotChosen: User account for e-mail "' . $user->getEmail() . '" has been cancelled')->setFrom('*****@*****.**', 'GotChosen')->setTo($user->getEmail())->setBody($body);
         $this->mailer()->send($msg);
         $this->get('security.context')->setToken(null);
         $this->get('request')->getSession()->invalidate();
         $response = $this->redirectRoute('fos_user_security_login');
         $dispatcher = $this->get('event_dispatcher');
         $dispatcher->dispatch(GCSiteEvents::USER_ACCOUNT_DISABLED, new FilterUserResponseEvent($user, $request, $response));
         $this->flash('info', 'Your account has been deleted.');
         return $response;
     }
     return $form;
 }
 public static function makePreview(User $toUser, $template, $subject, array $params)
 {
     $mq = new MassMailQueue();
     $mq->setType(self::TYPE_PREVIEW);
     $mq->setFilterSpec(['userId' => $toUser->getId()]);
     $mq->setTemplate($template);
     $mq->setSubject($subject);
     $mq->setParameters($params);
     return $mq;
 }
 public function getProperties(User $user, $includeGroups = false)
 {
     $gSelect = "";
     $gJoin = "";
     if ($includeGroups) {
         $gSelect = "g, ";
         $gJoin = "JOIN p.groups g";
     }
     $q = $this->getEntityManager()->createQuery("SELECT up, p, {$gSelect} vn FROM GotChosenSiteBundle:UserProfile up\n             JOIN up.property p\n             {$gJoin}\n             LEFT JOIN up.visibleNetworks vn\n             WHERE up.user = ?1");
     $q->setParameter(1, $user->getId());
     return $q->getResult();
 }
 protected function sendConfirmationEmailMessage(User $user, $customTarget)
 {
     $params = ['token' => $user->getConfirmationToken()];
     if ($customTarget) {
         $params['_target'] = $customTarget;
     }
     $url = $this->generateUrl('fos_user_registration_confirm', $params, true);
     $rendered = $this->renderView('FOSUserBundle:Registration:email.txt.twig', array('user' => $user, 'confirmationUrl' => $url));
     // Render the email, use the first line as the subject, and the rest as the body
     $renderedLines = explode("\n", trim($rendered));
     $subject = $renderedLines[0];
     $body = implode("\n", array_slice($renderedLines, 1));
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom('*****@*****.**', 'GotChosen - automated message, do not reply')->setTo($user->getEmail())->setBody($body);
     $this->get('mailer')->send($message);
 }