Ejemplo n.º 1
0
 /**
  * Check for duplicate applicants
  *
  * @param AdminCronController $cron
  */
 public static function runCron(AdminCronController $cron)
 {
     if (time() - (int) $cron->getVar('applicantsDuplicatesLastRun') > self::MIN_INTERVAL) {
         $cron->setVar('applicantsDuplicatesLastRun', time());
         $duplicates = 0;
         foreach ($cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Cycle')->findAll() as $cycle) {
             foreach ($cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Applicant')->findByCycle($cycle) as $applicant) {
                 foreach ($cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Applicant')->findDuplicates($applicant) as $duplicateApplicant) {
                     if (!$cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Duplicate')->findBy(array('applicant' => $applicant->getId(), 'duplicate' => $duplicateApplicant->getId()))) {
                         $duplicates++;
                         $duplicate = new \Jazzee\Entity\Duplicate();
                         $duplicate->setApplicant($applicant);
                         $duplicate->setDuplicate($duplicateApplicant);
                         $cron->getEntityManager()->persist($duplicate);
                     }
                 }
             }
         }
         $cron->getEntityManager()->flush();
         if ($duplicates) {
             $cron->log("Found {$duplicates} new duplicate applicants");
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Check for new messages in each program and email the administrator
  *
  * @param AdminCronController $cron
  */
 public static function runCron(AdminCronController $cron)
 {
     $threads = $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Thread')->findAll();
     if (time() - (int) $cron->getVar('applicantsMessagesApplicantsLastRun') > self::MIN_INTERVAL_APPLICANTS) {
         $lastRun = new DateTime();
         $lastRun->setTimeStamp((int) $cron->getVar('applicantsMessagesApplicantsLastRun'));
         $cron->setVar('applicantsMessagesApplicantsLastRun', time());
         $applicants = array();
         foreach ($threads as $thread) {
             if ($thread->hasUnreadMessage(\Jazzee\Entity\Message::PROGRAM)) {
                 $createdAt = $thread->getLastUnreadMessage(\Jazzee\Entity\Message::PROGRAM)->getCreatedAt();
                 $diff = $createdAt->diff(new DateTime('now'));
                 //if created since our last run or it is a multiplier fo 7 days old in te hour it was crated
                 //don't send messages to applicants who have logged in since the message was created
                 if (($createdAt > $lastRun or $diff->days > 5 and $diff->days % 7 == 0 and $diff->h == 0) and $thread->getApplicant()->getLastLogin() < $createdAt) {
                     if (!array_key_exists($thread->getApplicant()->getId(), $applicants)) {
                         $applicants[$thread->getApplicant()->getId()] = array('applicant' => $thread->getApplicant(), 'count' => 0);
                     }
                     $applicants[$thread->getApplicant()->getId()]['count']++;
                 }
             }
         }
         foreach ($applicants as $arr) {
             try {
                 $message = $cron->newMailMessage();
                 $message->AddAddress($arr['applicant']->getEmail(), $arr['applicant']->getFullName());
                 $message->Subject = 'New Message from ' . $arr['applicant']->getApplication()->getCycle()->getName() . ' ' . $arr['applicant']->getApplication()->getProgram()->getName();
                 $body = 'You have ' . $arr['count'] . ' unread message(s) from the ' . $arr['applicant']->getApplication()->getCycle()->getName() . ' ' . $arr['applicant']->getApplication()->getProgram()->getName() . ' program.' . "\nYou can review your message(s) by logging into the application at: " . $cron->absoluteApplyPath('apply/' . $arr['applicant']->getApplication()->getProgram()->getShortName() . '/' . $arr['applicant']->getApplication()->getCycle()->getName() . '/applicant/login');
                 $body .= "\nOnce you have logged into the application choose support in the upper right hand corner of the screen.";
                 $message->Body = $body;
                 $message->Send();
             } catch (phpmailerException $e) {
                 $cron->log("Attempting to send message reminder to applicant #{$arr['applicant']->getId()} resulted in a mail exception: " . $e->getMessage());
             }
         }
         if ($count = count($applicants)) {
             $cron->log("Sent {$count} reminder messages to applicants.");
         }
     }
     if (time() - (int) $cron->getVar('applicantsMessagesProgramsLastRun') > self::MIN_INTERVAL_PROGRAMS) {
         $lastRun = new DateTime();
         $lastRun->setTimeStamp((int) $cron->getVar('applicantsMessagesProgramsLastRun'));
         $cron->setVar('applicantsMessagesProgramsLastRun', time());
         $applications = array();
         foreach ($threads as $thread) {
             if ($thread->hasUnreadMessage(\Jazzee\Entity\Message::APPLICANT)) {
                 if (!array_key_exists($thread->getApplicant()->getApplication()->getId(), $applications)) {
                     $applications[$thread->getApplicant()->getApplication()->getId()] = array('application' => $thread->getApplicant()->getApplication(), 'count' => 0);
                 }
                 $applications[$thread->getApplicant()->getApplication()->getId()]['count']++;
             }
         }
         foreach ($applications as $arr) {
             try {
                 $message = $cron->newMailMessage();
                 $message->AddAddress($arr['application']->getContactEmail(), $arr['application']->getContactName());
                 $message->Subject = 'New Applicant Messages for ' . $arr['application']->getCycle()->getName() . ' ' . $arr['application']->getProgram()->getName();
                 $body = 'There are ' . $arr['count'] . ' unread messages for the ' . $arr['application']->getCycle()->getName() . ' ' . $arr['application']->getProgram()->getName() . ' program.' . "\nYou can review them at: " . $cron->absolutePath('applicants/messages');
                 $message->Body = $body;
                 $message->Send();
             } catch (phpmailerException $e) {
                 $cron->log("Attempting to send message reminder to {$arr['application']->getCycle()->getName()} {$arr['application']->getProgram()->getName()} resulted in a mail exception: " . $e->getMessage());
             }
         }
         if ($count = count($applications)) {
             $cron->log("Sent {$count} reminder messages to programs.");
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Match unmatched scores as a cron task
  * @param AdminCronController $cron
  */
 public static function runCron(\AdminCronController $cron)
 {
     $pageType = $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\PageType')->findOneBy(array('class' => '\\Jazzee\\Page\\ETSMatch'));
     $allETSMatchPages = $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Page')->findBy(array('type' => $pageType->getId()));
     $count = array('\\Jazzee\\Entity\\GREScore' => 0, '\\Jazzee\\Entity\\TOEFLScore' => 0);
     $scores = array('\\Jazzee\\Entity\\GREScore' => $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\GREScore')->findAllArray(), '\\Jazzee\\Entity\\TOEFLScore' => $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\TOEFLScore')->findAllArray());
     foreach ($allETSMatchPages as $page) {
         //get all the answers without a matching score.
         $answers = $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Answer')->findUnmatchedScores($page);
         $elements = array();
         $elements['testType'] = $page->getElementByFixedId(self::FID_TEST_TYPE);
         $elements['registrationNumber'] = $page->getElementByFixedId(self::FID_REGISTRATION_NUMBER);
         $elements['testDate'] = $page->getElementByFixedId(self::FID_TEST_DATE);
         $unmatchedScores = array('\\Jazzee\\Entity\\GREScore' => array(), '\\Jazzee\\Entity\\TOEFLScore' => array());
         foreach ($answers as $arr) {
             $answerElements = array();
             foreach ($arr['elements'] as $eArr) {
                 $answerElements[$eArr['element_id']] = array($eArr);
             }
             $value = $elements['testType']->getJazzeeElement()->formatApplicantArray($answerElements[$elements['testType']->getId()]);
             $value = $value['values'][0]['value'];
             if ($value == 'GRE/GRE Subject') {
                 $testType = '\\Jazzee\\Entity\\GREScore';
             } else {
                 if ($value == 'TOEFL') {
                     $testType = '\\Jazzee\\Entity\\TOEFLScore';
                 } else {
                     throw new \Jazzee\Exception("Unknown test type: {$value} when trying to match a score");
                 }
             }
             $value = $elements['registrationNumber']->getJazzeeElement()->formatApplicantArray($answerElements[$elements['registrationNumber']->getId()]);
             $registrationNumber = $value['values'][0]['value'];
             $value = $elements['testDate']->getJazzeeElement()->formatApplicantArray($answerElements[$elements['testDate']->getId()]);
             $testDate = $value['values'][0]['value'];
             $testMonth = date('m', strtotime($testDate));
             $testYear = date('Y', strtotime($testDate));
             $unmatchedScores[$testType][$registrationNumber . $testMonth . $testYear] = $arr['id'];
         }
         foreach ($unmatchedScores as $scoreEntityType => $arr) {
             foreach ($arr as $uniqueId => $answerId) {
                 if (array_key_exists($uniqueId, $scores[$scoreEntityType])) {
                     $count[$scoreEntityType] += $cron->getEntityManager()->getRepository($scoreEntityType)->matchScore($answerId, $scores[$scoreEntityType][$uniqueId]);
                 }
             }
         }
     }
     if ($count['\\Jazzee\\Entity\\GREScore']) {
         $cron->log("Found {$count['\\Jazzee\\Entity\\GREScore']} new GRE score matches");
     }
     if ($count['\\Jazzee\\Entity\\TOEFLScore']) {
         $cron->log("Found {$count['\\Jazzee\\Entity\\TOEFLScore']} new TOEFL score matches");
     }
 }