*/ class Mage_Adminhtml_Block_Newsletter_Subscriber_Grid extends Mage_Adminhtml_Block_Widget_Grid { /** * Constructor * * Set main configuration of grid */ public function __construct() { parent::__construct(); $this->setId('subscriberGrid'); $this->setUseAjax(true); $this->setDefaultSort('subscriber_id', 'desc'); } /** * Prepare collection for grid * * @return Mage_Adminhtml_Block_Widget_Grid */ protected function _prepareCollection() { $collection = Mage::getResourceSingleton('newsletter/subscriber_collection'); /* @var $collection Mage_Newsletter_Model_Mysql4_Subscriber_Collection */ $collection ->showCustomerInfo(true) ->addSubscriberTypeField() ->showStoreInfo(); if($this->getRequest()->getParam('queue', false)) { $collection->useQueue(Mage::getModel('newsletter/queue') ->load($this->getRequest()->getParam('queue'))); } $this->setCollection($collection); return parent::_prepareCollection(); } protected function _prepareColumns() { $this->addColumn('subscriber_id', array( 'header' => Mage::helper('newsletter')->__('ID'), 'index' => 'subscriber_id' )); $this->addColumn('email', array( 'header' => Mage::helper('newsletter')->__('Email'), 'index' => 'subscriber_email' )); $this->addColumn('type', array( 'header' => Mage::helper('newsletter')->__('Type'), 'index' => 'type', 'type' => 'options', 'options' => array( 1 => Mage::helper('newsletter')->__('Guest'), 2 => Mage::helper('newsletter')->__('Customer') ) )); $this->addColumn('firstname', array( 'header' => Mage::helper('newsletter')->__('Customer First Name'), 'index' => 'customer_firstname', 'default' => '----' )); $this->addColumn('lastname', array( 'header' => Mage::helper('newsletter')->__('Customer Last Name'), 'index' => 'customer_lastname', 'default' => '----' )); $this->addColumn('status', array( 'header' => Mage::helper('newsletter')->__('Status'), 'index' => 'subscriber_status', 'type' => 'options', 'options' => array( Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE => Mage::helper('newsletter')->__('Not Activated'), Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED => Mage::helper('newsletter')->__('Subscribed'), Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED => Mage::helper('newsletter')->__('Unsubscribed'), Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED => Mage::helper('newsletter')->__('Unconfirmed'), ) )); $this->addColumn('website', array( 'header' => Mage::helper('newsletter')->__('Website'), 'index' => 'website_id', 'type' => 'options', 'options' => $this->_getWebsiteOptions() )); $this->addColumn('group', array( 'header' => Mage::helper('newsletter')->__('Store'), 'index' => 'group_id', 'type' => 'options', 'options' => $this->_getStoreGroupOptions() )); $this->addColumn('store', array( 'header' => Mage::helper('newsletter')->__('Store View'), 'index' => 'store_id', 'type' => 'options', 'options' => $this->_getStoreOptions() )); $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV')); $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML')); return parent::_prepareColumns(); } /** * Convert OptionsValue array to Options array * * @param array $optionsArray * @return array */ protected function _getOptions($optionsArray) { $options = array(); foreach ($optionsArray as $option) { $options[$option['value']] = $option['label']; } return $options; } /** * Retrieve Website Options array * * @return array */ protected function _getWebsiteOptions() { return Mage::getModel('adminhtml/system_store')->getWebsiteOptionHash(); } /** * Retrieve Store Group Options array * * @return array */ protected function _getStoreGroupOptions() { return Mage::getModel('adminhtml/system_store')->getStoreGroupOptionHash(); } /** * Retrieve Store Options array * * @return array */ protected function _getStoreOptions() { return Mage::getModel('adminhtml/system_store')->getStoreOptionHash(); } protected function _prepareMassaction() { $this->setMassactionIdField('subscriber_id'); $this->getMassactionBlock()->setFormFieldName('subscriber'); $this->getMassactionBlock()->addItem('unsubscribe', array( 'label' => Mage::helper('newsletter')->__('Unsubscribe'), 'url' => $this->getUrl('*/*/massUnsubscribe') )); $this->getMassactionBlock()->addItem('delete', array( 'label' => Mage::helper('newsletter')->__('Delete'), 'url' => $this->getUrl('*/*/massDelete') )); return $this; } }