Mage_Newsletter_Model_Queue Class Reference

Inheritance diagram for Mage_Newsletter_Model_Queue:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 getSubscribersCollection ()
 addTemplateData ($data)
 sendPerSubscriber ($count=20, array $additionalVariables=array())
 getDataForSave ()
 addSubscribersToQueue (array $subscriberIds)
 setSaveTemplateFlag ($value)
 getSaveTemplateFlag ()
 setSaveStoresFlag ($value)
 getSaveStoresFlag ()
 setStores (array $storesIds)
 getStores ()
 getTemplate ()

Public Attributes

const STATUS_NEVER = 0
const STATUS_SENDING = 1
const STATUS_CANCEL = 2
const STATUS_SENT = 3
const STATUS_PAUSE = 4

Protected Member Functions

 _construct ()

Protected Attributes

 $_template
 $_subscribersCollection = null
 $_saveTemplateFlag = false
 $_saveStoresFlag = false
 $_stores = false


Detailed Description

Definition at line 34 of file Queue.php.


Member Function Documentation

_construct (  )  [protected]

Enter description here...

Reimplemented from Varien_Object.

Definition at line 62 of file Queue.php.

00063     {
00064         $this->_init('newsletter/queue');
00065     }

addSubscribersToQueue ( array subscriberIds  ) 

Definition at line 150 of file Queue.php.

00151     {
00152         $this->_getResource()->addSubscribersToQueue($this, $subscriberIds);
00153         return $this;
00154     }

addTemplateData ( data  ) 

Add template data to queue.

Deprecated:
Parameters:
Varien_Object $data
Returns:
Mage_Newsletter_Model_Queue

Definition at line 89 of file Queue.php.

00090     {
00091         $template = $this->getTemplate();
00092         if ($data->getTemplateId() && $data->getTemplateId() != $template->getId()) {
00093             $template->load($data->getTemplateId());
00094         }
00095 
00096         return $this;
00097     }

getDataForSave (  ) 

Definition at line 141 of file Queue.php.

00141                                      {
00142         $data = array();
00143         $data['template_id'] = $this->getTemplateId();
00144         $data['queue_status'] = $this->getQueueStatus();
00145         $data['queue_start_at'] = $this->getQueueStartAt();
00146         $data['queue_finish_at'] = $this->getQueueFinishAt();
00147         return $data;
00148     }

getSaveStoresFlag (  ) 

Definition at line 173 of file Queue.php.

00174     {
00175         return $this->_saveStoresFlag;
00176     }

getSaveTemplateFlag (  ) 

Definition at line 162 of file Queue.php.

00163     {
00164         return $this->_saveTemplateFlag;
00165     }

getStores (  ) 

Definition at line 185 of file Queue.php.

00186     {
00187         if(!$this->_stores) {
00188             $this->_stores = $this->_getResource()->getStores($this);
00189         }
00190 
00191         return $this->_stores;
00192     }

getSubscribersCollection (  ) 

Returns subscribers collection for this queue

Returns:
Varien_Data_Collection_Db

Definition at line 72 of file Queue.php.

00073     {
00074         if (is_null($this->_subscribersCollection)) {
00075             $this->_subscribersCollection = Mage::getResourceModel('newsletter/subscriber_collection')
00076                 ->useQueue($this);
00077         }
00078 
00079         return $this->_subscribersCollection;
00080     }

getTemplate (  ) 

Retrieve Newsletter Template object

Returns:
Mage_Newsletter_Model_Template

Definition at line 199 of file Queue.php.

00200     {
00201         if (is_null($this->_template)) {
00202             $this->_template = Mage::getModel('newsletter/template')
00203                 ->load($this->getTemplateId());
00204         }
00205         return $this->_template;
00206     }

sendPerSubscriber ( count = 20,
array additionalVariables = array() 
)

Send messages to subscribers for this queue

Parameters:
int $count
array $additionalVariables

Definition at line 105 of file Queue.php.

00106     {
00107         if($this->getQueueStatus()!=self::STATUS_SENDING && ($this->getQueueStatus()!=self::STATUS_NEVER && $this->getQueueStartAt()) ) {
00108             return $this;
00109         }
00110 
00111         if($this->getSubscribersCollection()->getSize()==0) {
00112             return $this;
00113         }
00114 
00115         $collection = $this->getSubscribersCollection()
00116             ->useOnlyUnsent()
00117             ->showCustomerInfo()
00118             ->setPageSize($count)
00119             ->setCurPage(1)
00120             ->load();
00121 
00122         if(!$this->getTemplate()) {
00123             $this->addTemplateData($this);
00124             if(!$this->getTemplate()->isPreprocessed()) {
00125                 $this->getTemplate()->preproccess();
00126             }
00127         }
00128 
00129         foreach($collection->getItems() as $item) {
00130             $this->getTemplate()->send($item, array('subscriber'=>$item), null, $this);
00131         }
00132 
00133         if(count($collection->getItems()) < $count-1 || count($collection->getItems()) == 0) {
00134             $this->setQueueFinishAt(now());
00135             $this->setQueueStatus(self::STATUS_SENT);
00136             $this->save();
00137         }
00138         return $this;
00139     }

setSaveStoresFlag ( value  ) 

Definition at line 167 of file Queue.php.

00168     {
00169         $this->_saveStoresFlag = (boolean)$value;
00170         return $this;
00171     }

setSaveTemplateFlag ( value  ) 

Definition at line 156 of file Queue.php.

00157     {
00158         $this->_saveTemplateFlag = (boolean)$value;
00159         return $this;
00160     }

setStores ( array storesIds  ) 

Definition at line 178 of file Queue.php.

00179     {
00180         $this->setSaveStoresFlag(true);
00181         $this->_stores = $storesIds;
00182         return $this;
00183     }


Member Data Documentation

$_saveStoresFlag = false [protected]

Definition at line 51 of file Queue.php.

$_saveTemplateFlag = false [protected]

Definition at line 49 of file Queue.php.

$_stores = false [protected]

Definition at line 53 of file Queue.php.

$_subscribersCollection = null [protected]

Definition at line 47 of file Queue.php.

$_template [protected]

Definition at line 41 of file Queue.php.

const STATUS_CANCEL = 2

Definition at line 57 of file Queue.php.

const STATUS_NEVER = 0

Definition at line 55 of file Queue.php.

const STATUS_PAUSE = 4

Definition at line 59 of file Queue.php.

const STATUS_SENDING = 1

Definition at line 56 of file Queue.php.

const STATUS_SENT = 3

Definition at line 58 of file Queue.php.


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

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