Mage_Newsletter_Model_Mysql4_Template Class Reference

Inheritance diagram for Mage_Newsletter_Model_Mysql4_Template:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 loadByCode (Mage_Newsletter_Model_Template $object, $templateCode)
 checkUsageInQueue (Mage_Newsletter_Model_Template $template)
 checkCodeUsage (Mage_Newsletter_Model_Template $template)

Protected Member Functions

 _construct ()
 _beforeSave (Mage_Core_Model_Abstract $object)


Detailed Description

Definition at line 34 of file Template.php.


Member Function Documentation

_beforeSave ( Mage_Core_Model_Abstract object  )  [protected]

Perform actions before object save

Parameters:
Mage_Core_Model_Abstract $object
Returns:
Mage_Newsletter_Model_Mysql4_Template

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 124 of file Template.php.

00125     {
00126         if ($this->checkCodeUsage($object)) {
00127             Mage::throwException(Mage::helper('newsletter')->__('Duplicate of template code'));
00128         }
00129 
00130         if (!$object->hasTemplateActual()) {
00131             $object->setTemplateActual(1);
00132         }
00133         if (!$object->hasAddedAt()) {
00134             $object->setAddedAt(Mage::getSingleton('core/date')->gmtDate());
00135         }
00136         $object->setModifiedAt(Mage::getSingleton('core/date')->gmtDate());
00137 
00138         return parent::_beforeSave($object);
00139     }

_construct (  )  [protected]

Initialize connection

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 40 of file Template.php.

00041     {
00042         $this->_init('newsletter/template', 'template_id');
00043     }

checkCodeUsage ( Mage_Newsletter_Model_Template template  ) 

Check usage of template code in other templates

Parameters:
Mage_Newsletter_Model_Template $template
Returns:
boolean

Definition at line 101 of file Template.php.

00102     {
00103         if ($template->getTemplateActual() != 0 || is_null($template->getTemplateActual())) {
00104             $select = $this->_getReadAdapter()->select()
00105                 ->from($this->getMainTable(), new Zend_Db_Expr('COUNT(template_id)'))
00106                 ->where('template_id!=?',$template->getId())
00107                 ->where('template_code=?',$template->getTemplateCode())
00108                 ->where('template_actual=?',1);
00109 
00110             $countOfCodes = $this->_getReadAdapter()->fetchOne($select);
00111 
00112             return $countOfCodes > 0;
00113         } else {
00114             return false;
00115         }
00116     }

checkUsageInQueue ( Mage_Newsletter_Model_Template template  ) 

Check usage of template in queue

Parameters:
Mage_Newsletter_Model_Template $template
Returns:
boolean

Definition at line 76 of file Template.php.

00077     {
00078         if ($template->getTemplateActual() !== 0 && !$template->getIsSystem()) {
00079             $select = $this->_getReadAdapter()->select()
00080                 ->from($this->getTable('newsletter/queue'), new Zend_Db_Expr('COUNT(queue_id)'))
00081                 ->where('template_id=?',$template->getId());
00082 
00083             $countOfQueue = $this->_getReadAdapter()->fetchOne($select);
00084 
00085             return $countOfQueue > 0;
00086         }
00087         elseif ($template->getIsSystem()) {
00088             return false;
00089         }
00090         else {
00091             return true;
00092         }
00093     }

loadByCode ( Mage_Newsletter_Model_Template object,
templateCode 
)

Load an object by template code

Parameters:
Mage_Newsletter_Model_Template $object
string $templateCode
Returns:
Mage_Newsletter_Model_Mysql4_Template

Definition at line 52 of file Template.php.

00053     {
00054         $read = $this->_getReadAdapter();
00055         if ($read && !is_null($templateCode)) {
00056             $select = $this->_getLoadSelect('template_code', $templateCode, $object)
00057                 ->where('template_actual=?', 1);
00058             $data = $read->fetchRow($select);
00059 
00060             if ($data) {
00061                 $object->setData($data);
00062             }
00063         }
00064 
00065         $this->_afterLoad($object);
00066 
00067         return $this;
00068     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:29 2009 for Magento by  doxygen 1.5.8