Пример #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");
         }
     }
 }
Пример #2
0
 /**
  * Attempt to settle payments
  * @param AdminCronController $cron
  */
 public static function runCron(\AdminCronController $cron)
 {
     $paymentType = $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\PaymentType')->findOneBy(array('class' => get_called_class()));
     $cronIntervalVar = 'uclacashnetPaymentLastRun-id-' . $paymentType->getId();
     if (time() - (int) $cron->getVar($cronIntervalVar) > self::MIN_CRON_INTERVAL) {
         $cron->setVar($cronIntervalVar, time());
         $count = 0;
         $unsettledIds = $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Payment')->findIdByStatusAndTypeArray(\Jazzee\Entity\Payment::PENDING, $paymentType);
         $fakeInput = new \Foundation\Form\Input(array());
         foreach ($unsettledIds as $id) {
             $payment = $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Payment')->find($id);
             $result = $paymentType->getJazzeePaymentType($cron)->settlePayment($payment, $fakeInput);
             if ($result === true) {
                 $count++;
                 $cron->getEntityManager()->persist($payment);
                 foreach ($payment->getVariables() as $var) {
                     $cron->getEntityManager()->persist($var);
                 }
             } else {
                 $cron->log($result);
             }
             unset($payment);
         }
         if ($count) {
             $cron->log("Settled {$count} {$paymentType->getClass()} Payments.");
         }
     }
 }
Пример #3
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.");
         }
     }
 }
Пример #4
0
 /**
  * Reset lockout and kill password reset keys
  *
  * @param AdminCronController $cron
  */
 public static function runCron(AdminCronController $cron)
 {
     if (time() - (int) $cron->getVar('applyApplicantLastRun') > self::MIN_INTERVAL_APPLICANTS) {
         $cron->setVar('applyApplicantLastRun', time());
         $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Applicant')->resetFailedLoginCounters();
         $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Applicant')->resetUniqueIds();
     }
 }