public static function getAllTemplates() { $models = EmailTemplates::model()->findAll(); if ($models) { return $models; } else { return false; } }
public static function bindEmailContent($emailTemplateId, $param, $to, $cc = null, $from = null) { $modelEmailTemplate = EmailTemplates::model()->findByPk($emailTemplateId); if (!empty($modelEmailTemplate)) { $message = $modelEmailTemplate->email_body; $subject = $modelEmailTemplate->email_subject; if (!empty($param)) { foreach ($param as $key => $value) { $message = str_replace($key, $value, $message); $subject = str_replace($key, $value, $subject); } } // Send a email to patient $data = array('subject' => $subject, 'message' => $message, 'to' => $to, 'cc' => $cc, 'from' => empty($from) ? Yii::app()->params['autoEmail'] : $from); self::sendMail($data); } }
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; } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = EmailTemplates::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * * @param int $iEmailTemplateID * @param array $aSubject * @param array $aBody * @param array $sTo * @example * $aSubject = array('{KEY_1}' =>'value1', '{KEY_2}'=>'value2', '{KEY_3}'=>'value3' ); $aBody = array('{KEY_1}' =>'value1', '{KEY_2}'=>'value2', '{KEY_3}'=>'value3' ); * @author bb <*****@*****.**> */ public static function sendmail($iEmailTemplateID, $aSubject = null, $aBody, $sTo, $sFrom = null, $sSubject = null) { $modelEmailTemplate = is_int($iEmailTemplateID) ? EmailTemplates::model()->findByPk($iEmailTemplateID) : EmailTemplates::model()->findByAttributes(array('slug' => $iEmailTemplateID)); if (empty($sSubject)) { $sSubject = $modelEmailTemplate->email_subject; if (is_array($aSubject) && count($aSubject) > 0) { foreach ($aSubject as $key => $value) { $sSubject = str_replace($key, $value, $sSubject); } } } $sBody = $modelEmailTemplate->email_body; if (is_array($aBody) && count($aBody) > 0) { foreach ($aBody as $key => $value) { $sBody = str_replace($key, $value, $sBody); } } $data = array('subject' => $sSubject, 'params' => array('message' => $sBody), 'view' => 'message', 'to' => $sTo, 'from' => empty($sFrom) ? Yii::app()->params['autoEmail'] : $sFrom); return CmsEmail::mail($data); }