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_Review_Grid extends Mage_Adminhtml_Block_Widget_Grid
35: {
36:
37: public function __construct()
38: {
39: parent::__construct();
40: $this->setId('reviwGrid');
41: $this->setDefaultSort('created_at');
42: }
43:
44: protected function _prepareCollection()
45: {
46: $model = Mage::getModel('review/review');
47: $collection = $model->getProductCollection();
48:
49: if ($this->getProductId() || $this->getRequest()->getParam('productId', false)) {
50: $productId = $this->getProductId();
51: if (!$productId) {
52: $productId = $this->getRequest()->getParam('productId');
53: }
54: $this->setProductId($productId);
55: $collection->addEntityFilter($this->getProductId());
56: }
57:
58: if ($this->getCustomerId() || $this->getRequest()->getParam('customerId', false)) {
59: $customerId = $this->getCustomerId();
60: if (!$customerId){
61: $customerId = $this->getRequest()->getParam('customerId');
62: }
63: $this->setCustomerId($customerId);
64: $collection->addCustomerFilter($this->getCustomerId());
65: }
66:
67: if (Mage::registry('usePendingFilter') === true) {
68: $collection->addStatusFilter($model->getPendingStatus());
69: }
70:
71: $collection->addStoreData();
72:
73: $this->setCollection($collection);
74: return parent::_prepareCollection();
75: }
76:
77: protected function _prepareColumns()
78: {
79: $statuses = Mage::getModel('review/review')
80: ->getStatusCollection()
81: ->load()
82: ->toOptionArray();
83:
84: $tmpArr = array();
85: foreach( $statuses as $key => $status ) {
86: $tmpArr[$status['value']] = $status['label'];
87: }
88:
89: $statuses = $tmpArr;
90:
91: $this->addColumn('review_id', array(
92: 'header' => Mage::helper('review')->__('ID'),
93: 'align' => 'right',
94: 'width' => '50px',
95: 'filter_index' => 'rt.review_id',
96: 'index' => 'review_id',
97: ));
98:
99: $this->addColumn('created_at', array(
100: 'header' => Mage::helper('review')->__('Created On'),
101: 'align' => 'left',
102: 'type' => 'datetime',
103: 'width' => '100px',
104: 'filter_index' => 'rt.created_at',
105: 'index' => 'review_created_at',
106: ));
107:
108: if( !Mage::registry('usePendingFilter') ) {
109: $this->addColumn('status', array(
110: 'header' => Mage::helper('review')->__('Status'),
111: 'align' => 'left',
112: 'type' => 'options',
113: 'options' => $statuses,
114: 'width' => '100px',
115: 'filter_index' => 'rt.status_id',
116: 'index' => 'status_id',
117: ));
118: }
119:
120: $this->addColumn('title', array(
121: 'header' => Mage::helper('review')->__('Title'),
122: 'align' => 'left',
123: 'width' => '100px',
124: 'filter_index' => 'rdt.title',
125: 'index' => 'title',
126: 'type' => 'text',
127: 'truncate' => 50,
128: 'escape' => true,
129: ));
130:
131: $this->addColumn('nickname', array(
132: 'header' => Mage::helper('review')->__('Nickname'),
133: 'align' => 'left',
134: 'width' => '100px',
135: 'filter_index' => 'rdt.nickname',
136: 'index' => 'nickname',
137: 'type' => 'text',
138: 'truncate' => 50,
139: 'escape' => true,
140: ));
141:
142: $this->addColumn('detail', array(
143: 'header' => Mage::helper('review')->__('Review'),
144: 'align' => 'left',
145: 'index' => 'detail',
146: 'filter_index' => 'rdt.detail',
147: 'type' => 'text',
148: 'truncate' => 50,
149: 'nl2br' => true,
150: 'escape' => true,
151: ));
152:
153: 154: 155:
156: if (!Mage::app()->isSingleStoreMode()) {
157: $this->addColumn('visible_in', array(
158: 'header' => Mage::helper('review')->__('Visible In'),
159: 'index' => 'stores',
160: 'type' => 'store',
161: 'store_view' => true,
162: ));
163: }
164:
165: $this->addColumn('type', array(
166: 'header' => Mage::helper('review')->__('Type'),
167: 'type' => 'select',
168: 'index' => 'type',
169: 'filter' => 'adminhtml/review_grid_filter_type',
170: 'renderer' => 'adminhtml/review_grid_renderer_type'
171: ));
172:
173: $this->addColumn('name', array(
174: 'header' => Mage::helper('review')->__('Product Name'),
175: 'align' =>'left',
176: 'type' => 'text',
177: 'index' => 'name',
178: 'escape' => true
179: ));
180:
181: $this->addColumn('sku', array(
182: 'header' => Mage::helper('review')->__('Product SKU'),
183: 'align' => 'right',
184: 'type' => 'text',
185: 'width' => '50px',
186: 'index' => 'sku',
187: 'escape' => true
188: ));
189:
190: $this->addColumn('action',
191: array(
192: 'header' => Mage::helper('adminhtml')->__('Action'),
193: 'width' => '50px',
194: 'type' => 'action',
195: 'getter' => 'getReviewId',
196: 'actions' => array(
197: array(
198: 'caption' => Mage::helper('adminhtml')->__('Edit'),
199: 'url' => array(
200: 'base'=>'*/catalog_product_review/edit',
201: 'params'=> array(
202: 'productId' => $this->getProductId(),
203: 'customerId' => $this->getCustomerId(),
204: 'ret' => ( Mage::registry('usePendingFilter') ) ? 'pending' : null
205: )
206: ),
207: 'field' => 'id'
208: )
209: ),
210: 'filter' => false,
211: 'sortable' => false
212: ));
213:
214: $this->addRssList('rss/catalog/review', Mage::helper('catalog')->__('Pending Reviews RSS'));
215:
216: return parent::_prepareColumns();
217: }
218:
219: protected function _prepareMassaction()
220: {
221: $this->setMassactionIdField('review_id');
222: $this->setMassactionIdFilter('rt.review_id');
223: $this->setMassactionIdFieldOnlyIndexValue(true);
224: $this->getMassactionBlock()->setFormFieldName('reviews');
225:
226: $this->getMassactionBlock()->addItem('delete', array(
227: 'label'=> Mage::helper('review')->__('Delete'),
228: 'url' => $this->getUrl(
229: '*/*/massDelete',
230: array('ret' => Mage::registry('usePendingFilter') ? 'pending' : 'index')
231: ),
232: 'confirm' => Mage::helper('review')->__('Are you sure?')
233: ));
234:
235: $statuses = Mage::getModel('review/review')
236: ->getStatusCollection()
237: ->load()
238: ->toOptionArray();
239: array_unshift($statuses, array('label'=>'', 'value'=>''));
240: $this->getMassactionBlock()->addItem('update_status', array(
241: 'label' => Mage::helper('review')->__('Update Status'),
242: 'url' => $this->getUrl(
243: '*/*/massUpdateStatus',
244: array('ret' => Mage::registry('usePendingFilter') ? 'pending' : 'index')
245: ),
246: 'additional' => array(
247: 'status' => array(
248: 'name' => 'status',
249: 'type' => 'select',
250: 'class' => 'required-entry',
251: 'label' => Mage::helper('review')->__('Status'),
252: 'values' => $statuses
253: )
254: )
255: ));
256: }
257:
258: public function getRowUrl($row)
259: {
260: return $this->getUrl('*/catalog_product_review/edit', array(
261: 'id' => $row->getReviewId(),
262: 'productId' => $this->getProductId(),
263: 'customerId' => $this->getCustomerId(),
264: 'ret' => ( Mage::registry('usePendingFilter') ) ? 'pending' : null,
265: ));
266: }
267:
268: public function getGridUrl()
269: {
270: if( $this->getProductId() || $this->getCustomerId() ) {
271: return $this->getUrl(
272: '*/catalog_product_review/' . (Mage::registry('usePendingFilter') ? 'pending' : ''),
273: array(
274: 'productId' => $this->getProductId(),
275: 'customerId' => $this->getCustomerId(),
276: )
277: );
278: } else {
279: return $this->getCurrentUrl();
280: }
281: }
282: }
283: