Mage_Newsletter_Model_Mysql4_Subscriber_Collection Class Reference

Inheritance diagram for Mage_Newsletter_Model_Mysql4_Subscriber_Collection:

Varien_Data_Collection_Db Varien_Data_Collection

List of all members.

Public Member Functions

 __construct ()
 useQueue (Mage_Newsletter_Model_Queue $queue)
 getAllIds ()
 useOnlyUnsent ()
 showCustomerInfo ()
 addSubscriberTypeField ()
 showStoreInfo ()
 addFieldToFilter ($field, $condition=null)
 _getFieldTableAlias ($field)
 getSelectCountSql ()
 useOnlyCustomers ()
 useOnlySubscribed ()
 load ($printQuery=false, $logQuery=false)

Protected Attributes

 $_subscriberTable
 $_queueLinkTable
 $_storeTable
 $_queueJoinedFlag = false
 $_showCustomersInfo = false
 $_countFilterPart = array()


Detailed Description

Definition at line 36 of file Collection.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor

Configures collection

Reimplemented from Varien_Data_Collection.

Definition at line 85 of file Collection.php.

00086     {
00087         parent::__construct(Mage::getSingleton('core/resource')->getConnection('newsletter_read'));
00088         $this->_subscriberTable = Mage::getSingleton('core/resource')->getTableName('newsletter/subscriber');
00089         $this->_queueLinkTable = Mage::getSingleton('core/resource')->getTableName('newsletter/queue_link');
00090         $this->_storeTable = Mage::getSingleton('core/resource')->getTableName('core/store');
00091         $this->_select->from(array('main_table'=>$this->_subscriberTable));
00092         $this->setItemObjectClass(Mage::getConfig()->getModelClassName('newsletter/subscriber'));
00093     }


Member Function Documentation

_getFieldTableAlias ( field  ) 

Definition at line 208 of file Collection.php.

00209     {
00210         if (strpos($field,'customer') === 0) {
00211            return $field .'_table.value';
00212         }
00213 
00214         if($field=='type') {
00215             return new Zend_Db_Expr('IF(main_table.customer_id = 0, 1, 2)');
00216         }
00217 
00218         if(in_array($field, array('website_id','group_id'))) {
00219             return 'store.' . $field;
00220         }
00221 
00222         return 'main_table.' . $field;
00223     }

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 199 of file Collection.php.

00200     {
00201         if(!is_null($condition)) {
00202             $this->_select->where($this->_getConditionSql($this->_getFieldTableAlias($field), $condition));
00203             $this->_countFilterPart[] = $this->_getConditionSql($this->_getFieldTableAlias($field), $condition);
00204         }
00205         return $this;
00206     }

addSubscriberTypeField (  ) 

Definition at line 175 of file Collection.php.

00176     {
00177         $this->getSelect()
00178             ->from(null, array('type'=>new Zend_Db_Expr('IF(main_table.customer_id = 0, 1, 2)')));
00179         return $this;
00180     }

getAllIds (  ) 

Retrive all ids for collection

Todo:
: In future we need to extend all newslatter classes from abstract classes
Returns:
array

Definition at line 114 of file Collection.php.

00115     {
00116         $idsSelect = clone $this->getSelect();
00117         $idsSelect->reset(Zend_Db_Select::ORDER);
00118         $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00119         $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00120         $idsSelect->reset(Zend_Db_Select::COLUMNS);
00121         $idsSelect->from(null,
00122             'main_table.subscriber_id'
00123         );
00124         return $this->getConnection()->fetchCol($idsSelect);
00125     }

getSelectCountSql (  ) 

Get SQL for get record count

Returns:
Varien_Db_Select

Reimplemented from Varien_Data_Collection_Db.

Definition at line 225 of file Collection.php.

00226     {
00227         $this->_renderFilters();
00228 
00229         $countSelect = clone $this->_select;
00230 
00231         $countSelect->reset(Zend_Db_Select::HAVING);
00232         $countSelect->reset(Zend_Db_Select::ORDER);
00233         $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00234         $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00235 
00236         foreach ($this->_countFilterPart as $where) {
00237             $countSelect->where($where);
00238         }
00239 
00240 
00241         // TODO: $ql->from('table',new Zend_Db_Expr('COUNT(*)'));
00242         $sql = $countSelect->__toString();
00243         $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(*) from ', $sql);
00244 
00245         return $sql;
00246     }

load ( printQuery = false,
logQuery = false 
)

Load subscribes to collection

Parameters:
boolean $printQuery
boolean $logQuery
Returns:
Varien_Data_Collection_Db

Reimplemented from Varien_Data_Collection_Db.

Definition at line 276 of file Collection.php.

00277     {
00278         if ($this->isLoaded()) {
00279             return $this;
00280         }
00281         parent::load($printQuery, $logQuery);
00282         return $this;
00283     }

showCustomerInfo (  ) 

Adds customer info to select

Returns:
Mage_Newsletter_Model_Mysql4_Subscriber_Collection

Definition at line 144 of file Collection.php.

00145     {
00146         $customer = Mage::getModel('customer/customer');
00147         /* @var $customer Mage_Customer_Model_Customer */
00148         $firstname  = $customer->getAttribute('firstname');
00149         $lastname   = $customer->getAttribute('lastname');
00150 
00151 //        $customersCollection = Mage::getModel('customer/customer')->getCollection();
00152 //        /* @var $customersCollection Mage_Customer_Model_Entity_Customer_Collection */
00153 //        $firstname = $customersCollection->getAttribute('firstname');
00154 //        $lastname  = $customersCollection->getAttribute('lastname');
00155 
00156         $this->getSelect()
00157             ->joinLeft(
00158                 array('customer_lastname_table'=>$lastname->getBackend()->getTable()),
00159                 'customer_lastname_table.entity_id=main_table.customer_id
00160                  AND customer_lastname_table.attribute_id = '.(int) $lastname->getAttributeId() . '
00161                  ',
00162                 array('customer_lastname'=>'value')
00163              )
00164              ->joinLeft(
00165                 array('customer_firstname_table'=>$firstname->getBackend()->getTable()),
00166                 'customer_firstname_table.entity_id=main_table.customer_id
00167                  AND customer_firstname_table.attribute_id = '.(int) $firstname->getAttributeId() . '
00168                  ',
00169                 array('customer_firstname'=>'value')
00170              );
00171 
00172         return $this;
00173     }

showStoreInfo (  ) 

Sets flag for customer info loading on load

Parameters:
boolean $show
Returns:
Mage_Newsletter_Model_Mysql4_Subscriber_Collection

Definition at line 188 of file Collection.php.

00189     {
00190         $this->getSelect()->join(
00191             array('store' => $this->_storeTable),
00192             'store.store_id = main_table.store_id',
00193             array('group_id', 'website_id')
00194         );
00195 
00196         return $this;
00197     }

useOnlyCustomers (  ) 

Load only subscribed customers

Definition at line 252 of file Collection.php.

00253     {
00254         $this->_select->where("main_table.customer_id > 0");
00255 
00256         return $this;
00257     }

useOnlySubscribed (  ) 

Show only with subscribed status

Definition at line 262 of file Collection.php.

00263     {
00264         $this->_select->where("main_table.subscriber_status = ?", Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
00265 
00266         return $this;
00267     }

useOnlyUnsent (  ) 

Set using of links to only unsendet letter subscribers.

Definition at line 130 of file Collection.php.

00131     {
00132         if($this->_queueJoinedFlag) {
00133             $this->_select->where("link.letter_sent_at IS NULL");
00134         }
00135 
00136         return $this;
00137     }

useQueue ( Mage_Newsletter_Model_Queue queue  ) 

Set loading mode subscribers by queue

Parameters:
Mage_Newsletter_Model_Queue $queue

Definition at line 100 of file Collection.php.

00101     {
00102         $this->_select->join(array('link'=>$this->_queueLinkTable), "link.subscriber_id = main_table.subscriber_id", array())
00103             ->where("link.queue_id = ? ", $queue->getId());
00104         $this->_queueJoinedFlag = true;
00105         return $this;
00106     }


Member Data Documentation

$_countFilterPart = array() [protected]

Definition at line 78 of file Collection.php.

$_queueJoinedFlag = false [protected]

Definition at line 64 of file Collection.php.

$_queueLinkTable [protected]

Definition at line 50 of file Collection.php.

$_showCustomersInfo = false [protected]

Definition at line 71 of file Collection.php.

$_storeTable [protected]

Definition at line 57 of file Collection.php.

$_subscriberTable [protected]

Definition at line 43 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