public static function make(Scholarship $scholarship, User $user)
 {
     $entry = new ScholarshipEntry();
     $entry->setScholarship($scholarship);
     $entry->setUser($user);
     return $entry;
 }
 public function countSponsors(ScholarshipEntry $entry)
 {
     $em = $this->getEntityManager();
     $q = $em->createQuery('SELECT COUNT(es) FROM GotChosenSiteBundle:EntrySponsor es
          JOIN es.entry e
          WHERE e.id = ?1');
     $q->setParameter(1, $entry->getId());
     return $q->getSingleScalarResult();
 }
 private function doApply(User $user, Scholarship $scholarship)
 {
     // add the scholarship entry, enable relevant notifications
     // 40K: scholarship news, sponsor notifications
     // monthly: scholarship news
     // eg: eg scholarship notifications, eg news
     $entry = ScholarshipEntry::make($scholarship, $user);
     $this->em()->persist($entry);
     /** @var NotificationTypeRepository $ntrepo */
     $ntrepo = $this->repo('NotificationType');
     $scholarshipInfo = $ntrepo->findOneBy(['name' => 'Scholarship Information']);
     $sponsorNotifications = $ntrepo->findOneBy(['name' => 'Sponsor Notifications']);
     $type = $scholarship->getScholarshipType();
     if ($type === Scholarship::TYPE_40K) {
         if ($scholarshipInfo) {
             $this->maybeAddSubscription($user, $scholarshipInfo);
         }
         if ($sponsorNotifications) {
             $this->maybeAddSubscription($user, $sponsorNotifications);
         }
     } else {
         if ($type === Scholarship::TYPE_MONTHLY) {
             if ($scholarshipInfo) {
                 $this->maybeAddSubscription($user, $scholarshipInfo);
             }
         } else {
             if ($type === Scholarship::TYPE_EVOGAMES) {
                 // Give the user tokens equal to number of days into the contest x 5
                 $days = $scholarship->getStartDate()->diff(new \DateTime('now'))->days + 1;
                 $tokens = $days * 5;
                 $user->setTokens($tokens);
             } else {
             }
         }
     }
     $this->em()->flush();
 }