예제 #1
0
 protected function doJob($arg)
 {
     $tomorrow = strtotime("+ 12 day", strtotime(date('Y-m-d H:i:s')));
     $mAppointment = Appointment::model()->findAll(array('condition' => 't.date_appointment < "' . date('Y-m-d H:i:s', $tomorrow) . '" AND t.date_appointment > "' . date('Y-m-d H:i:s') . '"', 'order' => 't.date_appointment ASC'));
     if (count($mAppointment) > 0) {
         foreach ($mAppointment as $eApp) {
             foreach ($eApp->bookings as $booking) {
                 if ($booking->email_reminded == 0) {
                     //send email notification to doctor
                     $modelEmailTemplate = EmailTemplates::model()->findByPk(8);
                     $dataEmail = array($booking->appointment->users->first_name . ' ' . $booking->appointment->users->last_name, $booking->user->first_name . ' ' . $booking->user->last_name, $booking->user->email, $booking->user->phone, date('l, d M Y, g:i A', strtotime($booking->appointment->date_appointment)), $booking->id, $booking->user->first_name . ' ' . $booking->user->last_name);
                     $pattern = array('{DOCTOR_NAME}', '{PATIENT_NAME}', '{PATIENT_EMAIL}', '{PATIENT_PHONE}', '{DATE_APPOINTMENT}', '{BOOKING_ID}', '{BOOKING_NAME}');
                     $message = str_replace($pattern, $dataEmail, $modelEmailTemplate->email_body);
                     $subject = $modelEmailTemplate->email_subject;
                     $data = array('subject' => $subject, 'params' => array('message' => $message), 'view' => 'message', 'to' => $booking->appointment->users->email, 'from' => Yii::app()->params['autoEmail']);
                     CmsEmail::mail($data);
                     //send email notification to patient
                     $modelEmailTemplate = EmailTemplates::model()->findByPk(7);
                     $dataEmail = array($booking->appointment->users->first_name . ' ' . $booking->appointment->users->last_name, $booking->user->first_name . ' ' . $booking->user->last_name, $booking->appointment->users->doctors->main_specialty, date('l, d M Y, g:i A', strtotime($booking->appointment->date_appointment)), $booking->id, $booking->appointment->address->address);
                     $pattern = array('{DOCTOR_NAME}', '{PATIENT_NAME}', '{DOCTOR_SPECIALTY}', '{DATE_APPOINTMENT}', '{BOOKING_ID}', '{DOCTOR_ADDRESS}');
                     $message = str_replace($pattern, $dataEmail, $modelEmailTemplate->email_body);
                     $subject = $modelEmailTemplate->email_subject;
                     $data = array('subject' => $subject, 'params' => array('message' => $message), 'view' => 'message', 'to' => $booking->user->email, 'from' => Yii::app()->params['autoEmail']);
                     CmsEmail::mail($data);
                     $booking->email_reminded = 1;
                     $booking->update(array('email_reminded'));
                     $this->index++;
                     //count email is sent for current cron job
                     if ($this->index >= $this->max) {
                         break;
                     }
                 }
             }
         }
     } else {
         return;
     }
 }
예제 #2
0
 /**
  * 
  * @param int $iEmailTemplateID
  * @param array $aSubject
  * @param array $aBody
  * @param string $sTo
  * @author bb  <*****@*****.**>
  * @copyright (c) 2013, bb 
  */
 public static function sendmailTranslate($iEmailTemplateID, $aSubject, $aBody, $sTo)
 {
     $modelEmailTemplate = new TranslateHelper('EmailTemplates', $iEmailTemplateID);
     $sSubject = $modelEmailTemplate->get('email_subject');
     if (is_array($aSubject)) {
         foreach ($aSubject as $key => $value) {
             $sSubject = str_replace($key, $value, $sSubject);
         }
     }
     $sBody = $modelEmailTemplate->get('email_body');
     if (is_array($aBody)) {
         foreach ($aBody as $key => $value) {
             $sBody = str_replace($key, $value, $sBody);
         }
     }
     $data = array('subject' => $sSubject, 'params' => array('message' => $sBody), 'view' => 'message', 'to' => $sTo, 'from' => Yii::app()->params['autoEmail']);
     return CmsEmail::mail($data);
 }