Public Member Functions | |
__construct () | |
load ($templateId) | |
loadByCode ($templateCode) | |
checkCodeUsage (Mage_Core_Model_Email_Template $template) | |
save (Mage_Core_Model_Email_Template $template) | |
delete ($templateId) | |
Protected Member Functions | |
_prepareSave (Mage_Core_Model_Email_Template $template) | |
Protected Attributes | |
$_templateTable | |
$_write | |
$_read |
Definition at line 34 of file Template.php.
__construct | ( | ) |
Constructor
Initializes resource
Definition at line 58 of file Template.php.
00059 { 00060 $this->_templateTable = Mage::getSingleton('core/resource')->getTableName('core/email_template'); 00061 $this->_read = Mage::getSingleton('core/resource')->getConnection('core_read'); 00062 $this->_write = Mage::getSingleton('core/resource')->getConnection('core_write'); 00063 }
_prepareSave | ( | Mage_Core_Model_Email_Template $ | template | ) | [protected] |
Prepares template for saving, validates input data
Mage_Core_Model_Email_Template | $template |
Definition at line 168 of file Template.php.
00169 { 00170 $data = array(); 00171 $data['template_code'] = $template->getTemplateCode(); 00172 $data['template_text'] = $template->getTemplateText(); 00173 $data['template_type'] = (int) $template->getTemplateType(); 00174 $data['template_subject'] = $template->getTemplateSubject(); 00175 $data['template_sender_name'] = $template->getTemplateSenderName(); 00176 $data['template_sender_email'] = $template->getTemplateSenderEmail(); 00177 00178 if(!$template->getAddedAt()) { 00179 $template->setAddedAt(Mage::getSingleton('core/date')->gmtDate()); 00180 $template->setModifiedAt(Mage::getSingleton('core/date')->gmtDate()); 00181 } 00182 00183 $data['modified_at'] = $template->getModifiedAt(); 00184 $data['added_at'] = $template->getAddedAt(); 00185 00186 if($this->checkCodeUsage($template)) { 00187 Mage::throwException(Mage::helper('core')->__('Duplicate Of Template Code')); 00188 } 00189 00190 $validators = array( 00191 'template_code' => array(Zend_Filter_Input::ALLOW_EMPTY => false), 00192 'template_type' => 'Alnum', 00193 #'template_sender_email' => 'EmailAddress', 00194 #'template_sender_name' => array(Zend_Filter_Input::ALLOW_EMPTY => false) 00195 ); 00196 00197 $validateInput = new Zend_Filter_Input(array(), $validators, $data); 00198 if(!$validateInput->isValid()) { 00199 $errorString = ''; 00200 00201 foreach($validateInput->getMessages() as $message) { 00202 if(is_array($message)) { 00203 foreach($message as $str) { 00204 $errorString.= $str . "\n"; 00205 } 00206 } else { 00207 $errorString.= $message . "\n"; 00208 } 00209 00210 } 00211 00212 Mage::throwException($errorString); 00213 } 00214 00215 return $data; 00216 }
checkCodeUsage | ( | Mage_Core_Model_Email_Template $ | template | ) |
Check usage of template code in other templates
Mage_Core_Model_Email_Template | $template |
Definition at line 118 of file Template.php.
00119 { 00120 if($template->getTemplateActual()!=0 || is_null($template->getTemplateActual())) { 00121 00122 $select = $this->_read->select() 00123 ->from($this->_templateTable, new Zend_Db_Expr('COUNT(template_id)')) 00124 ->where('template_id!=?',$template->getId()) 00125 ->where('template_code=?',$template->getTemplateCode()); 00126 00127 $countOfCodes = $this->_read->fetchOne($select); 00128 00129 return $countOfCodes > 0; 00130 } else { 00131 return false; 00132 } 00133 }
delete | ( | $ | templateId | ) |
Delete template record in DB.
int | $templateId |
Definition at line 224 of file Template.php.
00225 { 00226 $this->_write->beginTransaction(); 00227 try { 00228 $this->_write->delete($this->_templateTable, $this->_write->quoteInto('template_id=?', $templateId)); 00229 $this->_write->commit(); 00230 } 00231 catch(Exception $e) { 00232 $this->_write->rollBack(); 00233 Mage::throwException(Mage::helper('core')->__('Cannot Delete Email Template')); 00234 } 00235 00236 return $this; 00237 }
load | ( | $ | templateId | ) |
Load template from DB
int | $templateId |
Definition at line 71 of file Template.php.
00072 { 00073 $select = $this->_read->select() 00074 ->from($this->_templateTable) 00075 ->where('template_id=?', $templateId); 00076 00077 $result = $this->_read->fetchRow($select); 00078 00079 if (!$result) { 00080 return array(); 00081 } 00082 00083 return $result; 00084 }
loadByCode | ( | $ | templateCode | ) |
Load by template code from DB.
If $useSystem eq true, loading of system template
int | $templateId | |
boolean | $useSystem |
Definition at line 95 of file Template.php.
00096 { 00097 $select = $this->_read->select() 00098 ->from($this->_templateTable) 00099 ->where('template_code=?', $templateCode); 00100 00101 00102 $result = $this->_read->fetchRow($select); 00103 00104 if (!$result) { 00105 return array(); 00106 } 00107 00108 return $result; 00109 }
save | ( | Mage_Core_Model_Email_Template $ | template | ) |
Save template to DB
Mage_Core_Model_Email_Template | $template |
Definition at line 141 of file Template.php.
00142 { 00143 $this->_write->beginTransaction(); 00144 try { 00145 $data = $this->_prepareSave($template); 00146 if($template->getId()) { 00147 $this->_write->update($this->_templateTable, $data, 00148 $this->_write->quoteInto('template_id=?',$template->getId())); 00149 } else { 00150 $this->_write->insert($this->_templateTable, $data); 00151 $template->setId($this->_write->lastInsertId($this->_templateTable)); 00152 } 00153 00154 $this->_write->commit(); 00155 } 00156 catch (Exception $e) { 00157 $this->_write->rollBack(); 00158 throw $e; 00159 } 00160 }
$_read [protected] |
DB read connection
Definition at line 51 of file Template.php.
$_templateTable [protected] |
Definition at line 41 of file Template.php.
$_write [protected] |
DB write connection
Definition at line 46 of file Template.php.