/** * Prepares template for saving, validates input data * * @param Mage_Newsletter_Model_Template $template * @return array */ protected function _prepareSave(Mage_Newsletter_Model_Template $template) { $data = array(); $data['template_code'] = $template->getTemplateCode(); $data['template_text'] = $template->getTemplateText(); $data['template_text_preprocessed'] = $template->getTemplateTextPreprocessed(); $data['template_type'] = (int) $template->getTemplateType(); $data['template_subject'] = $template->getTemplateSubject(); $data['template_sender_name'] = $template->getTemplateSenderName(); $data['template_sender_email'] = $template->getTemplateSenderEmail(); $data['template_actual'] = !is_null($template->getTemplateActual()) && $template->getTemplateActual() == 0 ? 0 : 1; if (!$template->getAddedAt()) { $template->setAddedAt(Mage::getSingleton('core/date')->gmtDate()); $template->setModifiedAt(Mage::getSingleton('core/date')->gmtDate()); } $data['modified_at'] = $template->getModifiedAt(); $data['added_at'] = $template->getAddedAt(); if ($this->checkCodeUsage($template)) { Mage::throwException(Mage::helper('newsletter')->__('Duplicate of template code')); } $validators = array('template_code' => array(Zend_Filter_Input::ALLOW_EMPTY => false), 'template_type' => 'Alnum', 'template_sender_email' => 'EmailAddress', 'template_sender_name' => array(Zend_Filter_Input::ALLOW_EMPTY => false)); $validateInput = new Zend_Filter_Input(array(), $validators, $data); if (!$validateInput->isValid()) { $errorString = ''; foreach ($validateInput->getMessages() as $message) { if (is_array($message)) { foreach ($message as $str) { $errorString .= $str . "\n"; } } else { $errorString .= $message . "\n"; } } Mage::throwException($errorString); } return $data; }