Mage_Newsletter_Model_Mysql4_Queue_Collection Class Reference

Inheritance diagram for Mage_Newsletter_Model_Mysql4_Queue_Collection:

Mage_Core_Model_Mysql4_Collection_Abstract Varien_Data_Collection_Db Varien_Data_Collection

List of all members.

Public Member Functions

 addTemplateInfo ()
 load ($printQuery=false, $logQuery=false)
 addSubscribersInfo ()
 addFieldToFilter ($field, $condition=null)
 addSubscriberFilter ($subscriberId)
 addOnlyForSendingFilter ()
 addOnlyUnsentFilter ()
 toOptionArray ()
 addStoreFilter ($storeIds)

Protected Member Functions

 _construct ()
 _addSubscriberInfoToSelect ()
 _getIdsFromLink ($field, $condition)

Protected Attributes

 $_addSubscribersFlag = false
 $_isStoreFilter = false


Detailed Description

Definition at line 35 of file Collection.php.


Member Function Documentation

_addSubscriberInfoToSelect (  )  [protected]

Definition at line 65 of file Collection.php.

00066     {
00067         $this->_addSubscribersFlag = true;
00068         $this->getSize(); // Executing of count query!
00069         $this->getSelect()
00070             ->joinLeft(array('link_total'=>$this->getTable('queue_link')),
00071                                      'main_table.queue_id=link_total.queue_id',
00072                                      array(
00073                                         new Zend_Db_Expr('COUNT(DISTINCT link_total.queue_link_id) AS subscribers_total')
00074                                      ))
00075             ->joinLeft(array('link_sent'=>$this->getTable('queue_link')),
00076                                      'main_table.queue_id=link_sent.queue_id and link_sent.letter_sent_at IS NOT NULL',
00077                                      array(
00078                                         new Zend_Db_Expr('COUNT(DISTINCT link_sent.queue_link_id) AS subscribers_sent')
00079                                      ))
00080             ->group('main_table.queue_id');
00081         return $this;
00082     }

_construct (  )  [protected]

Initializes collection

Reimplemented from Mage_Core_Model_Mysql4_Collection_Abstract.

Definition at line 46 of file Collection.php.

00047     {
00048         $this->_init('newsletter/queue');
00049     }

_getIdsFromLink ( field,
condition 
) [protected]

Definition at line 113 of file Collection.php.

00113                                                            {
00114         $select = $this->getConnection()->select()
00115             ->from($this->getTable('queue_link'), array('queue_id', 'COUNT(queue_link_id) as total'))
00116             ->group('queue_id')
00117             ->having($this->_getConditionSql('total', $condition));
00118 
00119         if($field == 'subscribers_sent') {
00120             $select->where('letter_sent_at IS NOT NULL');
00121         }
00122 
00123         $idList = $this->getConnection()->fetchCol($select);
00124 
00125         if(count($idList)) {
00126             return $idList;
00127         }
00128 
00129         return array(0);
00130     }

addFieldToFilter ( field,
condition = null 
)

Add field filter to collection

If $attribute is an array will add OR condition with following format: array( array('attribute'=>'firstname', 'like'=>'test'), array('attribute'=>'lastname', 'like'=>'test'), )

See also:
self._getConditionSql for $condition
Parameters:
string|array $attribute
null|string|array $condition
Returns:
Mage_Eav_Model_Entity_Collection_Abstract

Reimplemented from Varien_Data_Collection_Db.

Definition at line 103 of file Collection.php.

00104     {
00105         if(in_array($field, array('subscribers_total', 'subscribers_sent'))) {
00106             $this->addFieldToFilter('main_table.queue_id', array('in'=>$this->_getIdsFromLink($field, $condition)));
00107             return $this;
00108         } else {
00109             return parent::addFieldToFilter($field, $condition);
00110         }
00111     }

addOnlyForSendingFilter (  ) 

Add filter by only ready fot sending item

Returns:
Mage_Newsletter_Model_Mysql4_Queue_Collection

Definition at line 155 of file Collection.php.

00156     {
00157         $this->getSelect()
00158             ->where('main_table.queue_status in (?)', array(Mage_Newsletter_Model_Queue::STATUS_SENDING,
00159                                                             Mage_Newsletter_Model_Queue::STATUS_NEVER))
00160             ->where('main_table.queue_start_at < ?', Mage::getSingleton('core/date')->gmtdate())
00161             ->where('main_table.queue_start_at IS NOT NULL');
00162 
00163         return $this;
00164     }

addOnlyUnsentFilter (  ) 

Add filter by only not sent items

Returns:
Mage_Newsletter_Model_Mysql4_Queue_Collection

Definition at line 171 of file Collection.php.

00172     {
00173         $this->getSelect()
00174             ->where('main_table.queue_status = ?',  Mage_Newsletter_Model_Queue::STATUS_NEVER);
00175 
00176         return $this;
00177     }

addStoreFilter ( storeIds  ) 

Filter collection by specified store ids

Parameters:
array|int $storeIds
Returns:
Mage_Newsletter_Model_Mysql4_Queue_Collection

Definition at line 190 of file Collection.php.

00191     {
00192         if (!$this->_isStoreFilter) {
00193             $this->getSelect()->joinInner(array('store_link' => $this->getTable('queue_store_link')),
00194                 'main_table.queue_id = store_link.queue_id', array()
00195             )->where('store_link.store_id IN (?)', $storeIds);
00196             $this->_isStoreFilter = true;
00197         }
00198         return $this;
00199     }

addSubscriberFilter ( subscriberId  ) 

Set filter for queue by subscriber.

Parameters:
int $subscriberId
Returns:
Mage_Newsletter_Model_Mysql4_Queue_Collection

Definition at line 138 of file Collection.php.

00139     {
00140         $this->getSelect()
00141             ->join(array('link'=>$this->getTable('queue_link')),
00142                                      'main_table.queue_id=link.queue_id',
00143                                      array('letter_sent_at')
00144                                      )
00145             ->where('link.subscriber_id = ?', $subscriberId);
00146 
00147         return $this;
00148     }

addSubscribersInfo (  ) 

Joines subscribers information

Returns:
Mage_Newsletter_Model_Mysql4_Queue_Collection

Definition at line 97 of file Collection.php.

00098     {
00099         $this->_addSubscribersFlag = true;
00100         return $this;
00101     }

addTemplateInfo (  ) 

Joines templates information

Returns:
Mage_Newsletter_Model_Mysql4_Queue_Collection

Definition at line 57 of file Collection.php.

00057                                       {
00058         $this->getSelect()->joinLeft(array('template'=>$this->getTable('template')),
00059             'template.template_id=main_table.template_id',
00060             array('template_subject','template_sender_name','template_sender_email'));
00061         $this->_joinedTables['template'] = true;
00062         return $this;
00063     }

load ( printQuery = false,
logQuery = false 
)

Load data

Returns:
Varien_Data_Collection_Db

Reimplemented from Mage_Core_Model_Mysql4_Collection_Abstract.

Definition at line 84 of file Collection.php.

00084                                                              {
00085         if($this->_addSubscribersFlag && !$this->isLoaded()) {
00086             $this->_addSubscriberInfoToSelect();
00087         }
00088 
00089         return parent::load($printQuery, $logQuery);
00090     }

toOptionArray (  ) 

Reimplemented from Varien_Data_Collection.

Definition at line 179 of file Collection.php.

00180     {
00181         return $this->_toOptionArray('queue_id', 'template_subject');
00182     }


Member Data Documentation

$_addSubscribersFlag = false [protected]

Definition at line 37 of file Collection.php.

$_isStoreFilter = false [protected]

Definition at line 41 of file Collection.php.


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