1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Block_Newsletter_Subscriber_Grid extends Mage_Adminhtml_Block_Widget_Grid
35: {
36: 37: 38: 39: 40:
41: public function __construct()
42: {
43: parent::__construct();
44: $this->setId('subscriberGrid');
45: $this->setUseAjax(true);
46: $this->setDefaultSort('subscriber_id', 'desc');
47: }
48:
49: 50: 51: 52: 53:
54: protected function _prepareCollection()
55: {
56: $collection = Mage::getResourceSingleton('newsletter/subscriber_collection');
57:
58: $collection
59: ->showCustomerInfo(true)
60: ->addSubscriberTypeField()
61: ->showStoreInfo();
62:
63: if($this->getRequest()->getParam('queue', false)) {
64: $collection->useQueue(Mage::getModel('newsletter/queue')
65: ->load($this->getRequest()->getParam('queue')));
66: }
67:
68: $this->setCollection($collection);
69:
70: return parent::_prepareCollection();
71: }
72:
73: protected function _prepareColumns()
74: {
75:
76: $this->addColumn('subscriber_id', array(
77: 'header' => Mage::helper('newsletter')->__('ID'),
78: 'index' => 'subscriber_id'
79: ));
80:
81: $this->addColumn('email', array(
82: 'header' => Mage::helper('newsletter')->__('Email'),
83: 'index' => 'subscriber_email'
84: ));
85:
86: $this->addColumn('type', array(
87: 'header' => Mage::helper('newsletter')->__('Type'),
88: 'index' => 'type',
89: 'type' => 'options',
90: 'options' => array(
91: 1 => Mage::helper('newsletter')->__('Guest'),
92: 2 => Mage::helper('newsletter')->__('Customer')
93: )
94: ));
95:
96: $this->addColumn('firstname', array(
97: 'header' => Mage::helper('newsletter')->__('Customer First Name'),
98: 'index' => 'customer_firstname',
99: 'default' => '----'
100: ));
101:
102: $this->addColumn('lastname', array(
103: 'header' => Mage::helper('newsletter')->__('Customer Last Name'),
104: 'index' => 'customer_lastname',
105: 'default' => '----'
106: ));
107:
108: $this->addColumn('status', array(
109: 'header' => Mage::helper('newsletter')->__('Status'),
110: 'index' => 'subscriber_status',
111: 'type' => 'options',
112: 'options' => array(
113: Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE => Mage::helper('newsletter')->__('Not Activated'),
114: Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED => Mage::helper('newsletter')->__('Subscribed'),
115: Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED => Mage::helper('newsletter')->__('Unsubscribed'),
116: Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED => Mage::helper('newsletter')->__('Unconfirmed'),
117: )
118: ));
119:
120: $this->addColumn('website', array(
121: 'header' => Mage::helper('newsletter')->__('Website'),
122: 'index' => 'website_id',
123: 'type' => 'options',
124: 'options' => $this->_getWebsiteOptions()
125: ));
126:
127: $this->addColumn('group', array(
128: 'header' => Mage::helper('newsletter')->__('Store'),
129: 'index' => 'group_id',
130: 'type' => 'options',
131: 'options' => $this->_getStoreGroupOptions()
132: ));
133:
134: $this->addColumn('store', array(
135: 'header' => Mage::helper('newsletter')->__('Store View'),
136: 'index' => 'store_id',
137: 'type' => 'options',
138: 'options' => $this->_getStoreOptions()
139: ));
140:
141: $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
142: $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
143: return parent::_prepareColumns();
144: }
145:
146: 147: 148: 149: 150: 151:
152: protected function _getOptions($optionsArray)
153: {
154: $options = array();
155: foreach ($optionsArray as $option) {
156: $options[$option['value']] = $option['label'];
157: }
158: return $options;
159: }
160:
161: 162: 163: 164: 165:
166: protected function _getWebsiteOptions()
167: {
168: return Mage::getModel('adminhtml/system_store')->getWebsiteOptionHash();
169: }
170:
171: 172: 173: 174: 175:
176: protected function _getStoreGroupOptions()
177: {
178: return Mage::getModel('adminhtml/system_store')->getStoreGroupOptionHash();
179: }
180:
181: 182: 183: 184: 185:
186: protected function _getStoreOptions()
187: {
188: return Mage::getModel('adminhtml/system_store')->getStoreOptionHash();
189: }
190:
191: protected function _prepareMassaction()
192: {
193: $this->setMassactionIdField('subscriber_id');
194: $this->getMassactionBlock()->setFormFieldName('subscriber');
195:
196: $this->getMassactionBlock()->addItem('unsubscribe', array(
197: 'label' => Mage::helper('newsletter')->__('Unsubscribe'),
198: 'url' => $this->getUrl('*/*/massUnsubscribe')
199: ));
200:
201: $this->getMassactionBlock()->addItem('delete', array(
202: 'label' => Mage::helper('newsletter')->__('Delete'),
203: 'url' => $this->getUrl('*/*/massDelete')
204: ));
205:
206: return $this;
207: }
208: }
209: