classes/tasks/RegistrationExpiryReminder.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00020 // $Id$
00021 
00022 
00023 import('scheduledTask.ScheduledTask');
00024 
00025 class RegistrationExpiryReminder extends ScheduledTask {
00026 
00030    function RegistrationExpiryReminder() {
00031       $this->ScheduledTask();
00032    }
00033 
00034    function sendReminder ($registration, $conference, $schedConf, $emailKey) {
00035 
00036       $userDao =& DAORegistry::getDAO('UserDAO');
00037       $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
00038 
00039       $schedConfName = $schedConf->getSchedConfTitle();
00040       $schedConfId = $schedConf->getId();
00041       $user =& $userDao->getUser($registration->getUserId());
00042       if (!isset($user)) return false;
00043 
00044       $registrationType =& $registrationTypeDao->getRegistrationType($registration->getTypeId());
00045 
00046       $registrationName = $schedConf->getSetting('registrationName');
00047       $registrationEmail = $schedConf->getSetting('registrationEmail');
00048       $registrationPhone = $schedConf->getSetting('registrationPhone');
00049       $registrationFax = $schedConf->getSetting('registrationFax');
00050       $registrationMailingAddress = $schedConf->getSetting('registrationMailingAddress');
00051 
00052       $registrationContactSignature = $registrationName;
00053 
00054       if ($registrationMailingAddress != '') {
00055          $registrationContactSignature .= "\n" . $registrationMailingAddress;
00056       }
00057       if ($registrationPhone != '') {
00058          $registrationContactSignature .= "\n" . AppLocale::Translate('user.phone') . ': ' . $registrationPhone;
00059       }
00060       if ($registrationFax != '') {
00061          $registrationContactSignature .= "\n" . AppLocale::Translate('user.fax') . ': ' . $registrationFax;
00062       }
00063 
00064       $registrationContactSignature .= "\n" . AppLocale::Translate('user.email') . ': ' . $registrationEmail;
00065 
00066       $paramArray = array(
00067          'registrantName' => $user->getFullName(),
00068          'conferenceName' => $conferenceName,
00069          'schedConfName' => $schedConfName,
00070          'registrationType' => $registrationType->getSummaryString(),
00071          'expiryDate' => $registration->getDateEnd(),
00072          'username' => $user->getUsername(),
00073          'registrationContactSignature' => $registrationContactSignature 
00074       );
00075 
00076       import('mail.MailTemplate');
00077       $mail = new MailTemplate($emailKey, $conference->getPrimaryLocale());
00078       $mail->setFrom($registrationEmail, $registrationName);
00079       $mail->addRecipient($user->getEmail(), $user->getFullName());
00080       $mail->setSubject($mail->getSubject($conference->getPrimaryLocale()));
00081       $mail->setBody($mail->getBody($conference->getPrimaryLocale()));
00082       $mail->assignParams($paramArray);
00083       $mail->send();
00084    }
00085 
00086    function sendSchedConfReminders ($conference, $schedConf, $curDate) {
00087       $curYear = $curDate['year'];
00088       $curMonth = $curDate['month'];
00089       $curDay = $curDate['day'];
00090 
00091       // Check if expiry notification before months is enabled
00092       if ($schedConf->getSetting('enableRegistrationExpiryReminderBeforeMonths')) {
00093 
00094          $beforeMonths = $schedConf->getSetting('numMonthsBeforeRegistrationExpiryReminder');
00095          $beforeYears = (int)floor($beforeMonths/12);
00096          $beforeMonths = (int)fmod($beforeMonths,12);
00097 
00098          $expiryYear = $curYear + $beforeYears + (int)floor(($curMonth+$beforeMonths)/12);
00099          $expiryMonth = (int)fmod($curMonth+$beforeMonths,12);
00100          $expiryDay = $curDay;
00101 
00102          // Retrieve all registration that match expiry date
00103          $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00104          $dateEnd = $expiryYear . '-' . $expiryMonth . '-' . $expiryDay;
00105          $registration =& $registrationDao->getRegistrationByDateEnd($dateEnd, $schedConf->getId()); 
00106 
00107          while (!$registration->eof()) {
00108             $registration =& $registration->next();
00109             $this->sendReminder($registration, $conference, $schedConf, 'REGISTRATION_BEFORE_EXPIRY');
00110          }
00111       }
00112 
00113       // Check if expiry notification before weeks is enabled
00114       if ($schedConf->getSetting('enableRegistrationExpiryReminderBeforeWeeks')) {
00115 
00116          $beforeWeeks = $schedConf->getSetting('numWeeksBeforeRegistrationExpiryReminder');
00117          $beforeDays = $beforeWeeks * 7;
00118 
00119          $expiryMonth = $curMonth + (int)floor(($curDay+$beforeDays)/31);
00120          $expiryYear = $curYear + (int)floor($expiryMonth/12);
00121          $expiryDay = (int)fmod($curDay+$beforeDays,31);
00122          $expiryMonth = (int)fmod($expiryMonth,12);            
00123 
00124          // Retrieve all registration that match expiry date
00125          $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00126          $dateEnd = $expiryYear . '-' . $expiryMonth . '-' . $expiryDay;
00127          $registration =& $registrationDao->getRegistrationByDateEnd($dateEnd, $schedConf->getId()); 
00128 
00129          while (!$registration->eof()) {
00130             $registration =& $registration->next();
00131             $this->sendReminder($registration, $conference, $schedConf, 'REGISTRATION_BEFORE_EXPIRY');
00132          }
00133       }
00134 
00135       // Check if expiry notification after months is enabled
00136       if ($schedConf->getSetting('enableRegistrationExpiryReminderAfterMonths')) {
00137 
00138          $afterMonths = $schedConf->getSetting('numMonthsAfterRegistrationExpiryReminder');
00139          $afterYears = (int)floor($afterMonths/12);
00140          $afterMonths = (int)fmod($afterMonths,12);
00141 
00142          if (($curMonth - $afterMonths) <= 0) {
00143             $afterYears++;
00144             $expiryMonth = 12 + ($curMonth - $afterMonths);
00145          } else {
00146             $expiryMonth = $curMonth - $afterMonths;
00147          }
00148 
00149          $expiryYear = $curYear - $afterYears;
00150          $expiryDay = $curDay;
00151 
00152          // Retrieve all registration that match expiry date
00153          $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00154          $dateEnd = $expiryYear . '-' . $expiryMonth . '-' . $expiryDay;
00155          $registration =& $registrationDao->getRegistrationByDateEnd($dateEnd, $schedConf->getId()); 
00156 
00157          while (!$registration->eof()) {
00158             $registration =& $registration->next();
00159             // Ensure that user does not have another, valid registration
00160             if (!$registrationDao->isValidRegistrationByUser($registration->getUserId(), $schedConf->getId())) {
00161                $this->sendReminder($registration, $conference, $schedConf, 'REGISTRATION_AFTER_EXPIRY_LAST');
00162             }
00163          }
00164       }
00165 
00166       // Check if expiry notification after weeks is enabled
00167       if ($schedConf->getSetting('enableRegistrationExpiryReminderAfterWeeks')) {
00168 
00169          $afterWeeks = $schedConf->getSetting('numWeeksAfterRegistrationExpiryReminder');
00170          $afterDays = $afterWeeks * 7;
00171 
00172          if (($curDay - $afterDays) <= 0) {
00173             $afterMonths = 1;
00174             $expiryDay = 31 + ($curDay - $afterDays);
00175          } else {
00176             $afterMonths = 0;
00177             $expiryDay = $curDay - $afterDays;
00178          }
00179 
00180          if (($curMonth - $afterMonths) == 0) {
00181             $afterYears = 1;
00182             $expiryMonth = 12;
00183          } else {
00184             $afterYears = 0;
00185             $expiryMonth = $curMonth - $afterMonths;
00186          }
00187 
00188          $expiryYear = $curYear - $afterYears;
00189 
00190          // Retrieve all registration that match expiry date
00191          $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00192          $dateEnd = $expiryYear . '-' . $expiryMonth . '-' . $expiryDay;
00193          $registration =& $registrationDao->getRegistrationByDateEnd($dateEnd, $schedConf->getId()); 
00194 
00195          while (!$registration->eof()) {
00196             $registration =& $registration->next();
00197             // Ensure that user does not have another, valid registration
00198             if (!$registrationDao->isValidRegistrationByUser($registration->getUserId(), $schedConf->getId())) {
00199                $this->sendReminder($registration, $conference, $schedConf, 'REGISTRATION_AFTER_EXPIRY');
00200             }
00201          }
00202       }
00203    }
00204 
00205    function execute() {
00206       $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00207       $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00208       $schedConfs =& $schedConfDao->getEnabledSchedConfs();
00209       $conference = null;
00210 
00211       $todayDate = array(
00212                   'year' => date('Y'),
00213                   'month' => date('n'),
00214                   'day' => date('j')
00215                );
00216 
00217       while (!$schedConfs->eof()) {
00218          $schedConf =& $schedConfs->next();
00219 
00220          if(!$conference || $schedConf->getConferenceId() != $conference->getId()) {
00221             $conference =& $conferenceDao->getConference($schedConf->getConferenceId());
00222          }
00223 
00224          // Send reminders based on current date
00225          $this->sendSchedConfReminders($schedConf, $conference, $todayDate);
00226          unset($schedConf);
00227       }
00228 
00229       // If it is the first day of a month but previous month had only
00230       // 30 days then simulate 31st day for expiry dates that end on
00231       // that day.
00232       $shortMonths = array(2,4,6,8,10,12);
00233 
00234       if (($todayDate['day'] == 1) && in_array(($todayDate['month'] - 1), $shortMonths)) {
00235 
00236          $curDate['day'] = 31;
00237          $curDate['month'] = $todayDate['month'] - 1;
00238 
00239          if ($curDate['month'] == 12) {
00240             $curDate['year'] = $todayDate['year'] - 1;
00241          } else {
00242             $curDate['year'] = $todayDate['year'];
00243          }
00244 
00245          $schedConfs =& $schedConfDao->getEnabledSchedConfs();
00246 
00247          while (!$schedConfs->eof()) {
00248             $schedConf =& $schedConfs->next();
00249 
00250             if(!$conference || $schedConf->getConferenceId() != $conference->getId()) {
00251                $conference =& $conferenceDao->getConference($schedConf->getConferenceId());
00252             }
00253 
00254             // Send reminders for simulated 31st day of short month
00255             $this->sendSchedConfReminders($schedConf, $conference, $curDate);
00256             unset($schedConf);
00257          }
00258       }
00259 
00260       // If it is the first day of March, simulate 29th and 30th days for February
00261       // or just the 30th day in a leap year.
00262       if (($todayDate['day'] == 1) && ($todayDate['month'] == 3)) {
00263 
00264          $curDate['day'] = 30;
00265          $curDate['month'] = 2;
00266          $curDate['year'] = $todayDate['year'];
00267 
00268          $schedConfs =& $schedConfDao->getEnabledSchedConfs();
00269 
00270          while (!$schedConfs->eof()) {
00271             $schedConf =& $schedConfs->next();
00272 
00273             if(!$conference || $schedConf->getConferenceId() != $conference->getId()) {
00274                $conference =& $conferenceDao->getConference($schedConf->getConferenceId());
00275             }
00276 
00277             // Send reminders for simulated 30th day of February
00278             $this->sendSchedConfReminders($schedConf, $conference, $curDate);
00279             unset($schedConf);
00280          }
00281 
00282          // Check if it's a leap year
00283          if (date("L", mktime(0,0,0,0,0,$curDate['year'])) != '1') {
00284 
00285             $curDate['day'] = 29;
00286 
00287             $schedConfs =& $schedConfDao->getEnabledSchedConfs();
00288 
00289             while (!$schedConfs->eof()) {
00290                $schedConf =& $schedConfs->next();
00291 
00292                if(!$conference || $schedConf->getConferenceId() != $conference->getId()) {
00293                   $conference =& $conferenceDao->getConference($schedConf->getConferenceId());
00294                }
00295 
00296                // Send reminders for simulated 29th day of February
00297                $this->sendSchedConfReminders($schedConf, $conference, $curDate);
00298                unset($schedConf);
00299             }
00300          }
00301       }
00302    }
00303 }
00304 
00305 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7