Public Member Functions | |
validate () | |
loadByCode ($templateCode) | |
isValidForSend () | |
isPlain () | |
isPreprocessed () | |
getTemplateTextPreprocessed () | |
getProcessedTemplate (array $variables=array(), $usePreprocess=false) | |
getInclude ($templateCode, array $variables) | |
getMail () | |
send ($subscriber, array $variables=array(), $name=null, Mage_Newsletter_Model_Queue $queue=null) | |
preprocess () | |
getProcessedTemplateSubject (array $variables) | |
getTemplateText () | |
Public Attributes | |
const | TYPE_TEXT = 1 |
const | TYPE_HTML = 2 |
Protected Member Functions | |
_construct () | |
_beforeSave () | |
Protected Attributes | |
$_preprocessFlag = false | |
$_mail |
Definition at line 34 of file Template.php.
_beforeSave | ( | ) | [protected] |
Processing object before save data
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 107 of file Template.php.
00108 { 00109 $this->validate(); 00110 $this->getTemplateTextPreprocessed(); 00111 return parent::_beforeSave(); 00112 }
_construct | ( | ) | [protected] |
Initialize resource model
Reimplemented from Varien_Object.
Definition at line 60 of file Template.php.
00061 { 00062 $this->_init('newsletter/template'); 00063 }
getInclude | ( | $ | templateCode, | |
array $ | variables | |||
) |
Retrieve included template
string | $templateCode | |
array | $variables |
Definition at line 206 of file Template.php.
00207 { 00208 return Mage::getModel('newsletter/template') 00209 ->loadByCode($templateCode) 00210 ->getProcessedTemplate($variables); 00211 }
getMail | ( | ) |
Retrieve mail object instance
Definition at line 218 of file Template.php.
00219 { 00220 if (is_null($this->_mail)) { 00221 $this->_mail = new Zend_Mail('utf-8'); 00222 } 00223 return $this->_mail; 00224 }
Retrieve processed template
array | $variables | |
bool | $usePreprocess |
Definition at line 180 of file Template.php.
00181 { 00182 $processor = Mage::getModel('core/email_template_filter'); 00183 00184 if (!$this->_preprocessFlag) { 00185 $variables['this'] = $this; 00186 } 00187 00188 $processor 00189 ->setIncludeProcessor(array($this, 'getInclude')) 00190 ->setVariables($variables); 00191 00192 if ($usePreprocess && $this->isPreprocessed()) { 00193 return $processor->filter($this->getTemplateTextPreprocessed()); 00194 } 00195 00196 return $processor->filter($this->getTemplateText()); 00197 }
getProcessedTemplateSubject | ( | array $ | variables | ) |
Retrieve processed template subject
array | $variables |
Definition at line 324 of file Template.php.
00325 { 00326 $processor = new Varien_Filter_Template(); 00327 00328 if (!$this->_preprocessFlag) { 00329 $variables['this'] = $this; 00330 } 00331 00332 $processor->setVariables($variables); 00333 return $processor->filter($this->getTemplateSubject()); 00334 }
getTemplateText | ( | ) |
Retrieve template text wrapper
Definition at line 341 of file Template.php.
00342 { 00343 if (!$this->getData('template_text') && !$this->getId()) { 00344 $this->setData('template_text', 00345 Mage::helper('newsletter')->__('<!-- This tag is for unsubscribe link --> Follow this link to unsubscribe <a href="{{var subscriber.getUnsubscriptionLink()}}">{{var subscriber.getUnsubscriptionLink()}}</a>') 00346 ); 00347 } 00348 00349 return $this->getData('template_text'); 00350 }
getTemplateTextPreprocessed | ( | ) |
Check Template Text Preprocessed
Definition at line 164 of file Template.php.
00165 { 00166 if ($this->_preprocessFlag) { 00167 $this->setTemplateTextPreprocessed($this->getProcessedTemplate()); 00168 } 00169 00170 return $this->getData('template_text_preprocessed'); 00171 }
isPlain | ( | ) |
isPreprocessed | ( | ) |
Check is Preprocessed
Definition at line 154 of file Template.php.
00155 { 00156 return strlen($this->getTemplateTextPreprocessed()) > 0; 00157 }
isValidForSend | ( | ) |
Return true if this template can be used for sending queue as main template
Definition at line 131 of file Template.php.
00132 { 00133 return !Mage::getStoreConfigFlag('system/smtp/disable') 00134 && $this->getTemplateSenderName() 00135 && $this->getTemplateSenderEmail() 00136 && $this->getTemplateSubject(); 00137 }
loadByCode | ( | $ | templateCode | ) |
Load template by code
string | $templateCode |
Definition at line 120 of file Template.php.
00121 { 00122 $this->_getResource()->loadByCode($this, $templateCode); 00123 return $this; 00124 }
preprocess | ( | ) |
Prepare Process (with save)
Definition at line 310 of file Template.php.
00311 { 00312 $this->_preprocessFlag = true; 00313 $this->save(); 00314 $this->_preprocessFlag = false; 00315 return $this; 00316 }
send | ( | $ | subscriber, | |
array $ | variables = array() , |
|||
$ | name = null , |
|||
Mage_Newsletter_Model_Queue $ | queue = null | |||
) |
Send mail to subscriber
Mage_Newsletter_Model_Subscriber|string | $subscriber subscriber Model or E-mail | |
array | $variables template variables | |
string|null | $name receiver name (if subscriber model not specified) | |
Mage_Newsletter_Model_Queue|null | $queue queue model, used for problems reporting. |
Definition at line 236 of file Template.php.
00237 { 00238 if (!$this->isValidForSend()) { 00239 return false; 00240 } 00241 00242 $email = ''; 00243 if ($subscriber instanceof Mage_Newsletter_Model_Subscriber) { 00244 $email = $subscriber->getSubscriberEmail(); 00245 if (is_null($name) && ($subscriber->hasCustomerFirstname() || $subscriber->hasCustomerLastname()) ) { 00246 $name = $subscriber->getCustomerFirstname() . ' ' . $subscriber->getCustomerLastname(); 00247 } 00248 } 00249 else { 00250 $email = (string) $subscriber; 00251 } 00252 00253 if (Mage::getStoreConfigFlag(Mage_Newsletter_Model_Subscriber::XML_PATH_SENDING_SET_RETURN_PATH)) { 00254 $this->getMail()->setReturnPath($this->getTemplateSenderEmail()); 00255 } 00256 00257 ini_set('SMTP', Mage::getStoreConfig('system/smtp/host')); 00258 ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port')); 00259 00260 $mail = $this->getMail(); 00261 $mail->addTo($email, $name); 00262 $text = $this->getProcessedTemplate($variables, true); 00263 00264 if ($this->isPlain()) { 00265 $mail->setBodyText($text); 00266 } 00267 else { 00268 $mail->setBodyHTML($text); 00269 } 00270 00271 $mail->setSubject($this->getProcessedTemplateSubject($variables)); 00272 $mail->setFrom($this->getTemplateSenderEmail(), $this->getTemplateSenderName()); 00273 00274 try { 00275 $mail->send(); 00276 $this->_mail = null; 00277 if (!is_null($queue)) { 00278 $subscriber->received($queue); 00279 } 00280 } 00281 catch (Exception $e) { 00282 if ($subscriber instanceof Mage_Newsletter_Model_Subscriber) { 00283 // If letter sent for subscriber, we create a problem report entry 00284 $problem = Mage::getModel('newsletter/problem'); 00285 $problem->addSubscriberData($subscriber); 00286 if (!is_null($queue)) { 00287 $problem->addQueueData($queue); 00288 } 00289 $problem->addErrorData($e); 00290 $problem->save(); 00291 00292 if (!is_null($queue)) { 00293 $subscriber->received($queue); 00294 } 00295 } else { 00296 // Otherwise throw error to upper level 00297 throw $e; 00298 } 00299 return false; 00300 } 00301 00302 return true; 00303 }
validate | ( | ) |
Validate Newsletter template
Mage_Core_Exception |
Definition at line 71 of file Template.php.
00072 { 00073 $validators = array( 00074 'template_code' => array(Zend_Filter_Input::ALLOW_EMPTY => false), 00075 'template_type' => 'Alnum', 00076 'template_sender_email' => 'EmailAddress', 00077 'template_sender_name' => array(Zend_Filter_Input::ALLOW_EMPTY => false) 00078 ); 00079 $data = array(); 00080 foreach (array_keys($validators) as $validateField) { 00081 $data[$validateField] = $this->getDataUsingMethod($validateField); 00082 } 00083 00084 $validateInput = new Zend_Filter_Input(array(), $validators, $data); 00085 if (!$validateInput->isValid()) { 00086 $errorMessages = array(); 00087 foreach ($validateInput->getMessages() as $messages) { 00088 if (is_array($messages)) { 00089 foreach ($messages as $message) { 00090 $errorMessages[] = $message; 00091 } 00092 } 00093 else { 00094 $errorMessages[] = $messages; 00095 } 00096 } 00097 00098 Mage::throwException(join("\n", $errorMessages)); 00099 } 00100 }
$_mail [protected] |
Definition at line 54 of file Template.php.
$_preprocessFlag = false [protected] |
Definition at line 47 of file Template.php.
const TYPE_HTML = 2 |
Definition at line 40 of file Template.php.
const TYPE_TEXT = 1 |
Types of template
Definition at line 39 of file Template.php.