PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Block/Review/Grid.php

https://gitlab.com/blingbang2016/shop
PHP | 267 lines | 207 code | 26 blank | 34 comment | 12 complexity | a577ae0f0c52b3cec4486cc1ba068d8d MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Adminhtml
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Adminhtml reviews grid
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Review_Grid extends Mage_Adminhtml_Block_Widget_Grid
  34. {
  35. public function __construct()
  36. {
  37. parent::__construct();
  38. $this->setId('reviwGrid');
  39. $this->setDefaultSort('created_at');
  40. }
  41. protected function _prepareCollection()
  42. {
  43. $model = Mage::getModel('review/review');
  44. $collection = $model->getProductCollection();
  45. if ($this->getProductId() || $this->getRequest()->getParam('productId', false)) {
  46. $productId = $this->getProductId();
  47. if (!$productId) {
  48. $productId = $this->getRequest()->getParam('productId');
  49. }
  50. $this->setProductId($productId);
  51. $collection->addEntityFilter($this->getProductId());
  52. }
  53. if ($this->getCustomerId() || $this->getRequest()->getParam('customerId', false)) {
  54. $customerId = $this->getCustomerId();
  55. if (!$customerId){
  56. $customerId = $this->getRequest()->getParam('customerId');
  57. }
  58. $this->setCustomerId($customerId);
  59. $collection->addCustomerFilter($this->getCustomerId());
  60. }
  61. if (Mage::registry('usePendingFilter') === true) {
  62. $collection->addStatusFilter($model->getPendingStatus());
  63. }
  64. $collection->addStoreData();
  65. $this->setCollection($collection);
  66. return parent::_prepareCollection();
  67. }
  68. protected function _prepareColumns()
  69. {
  70. $this->addColumn('review_id', array(
  71. 'header' => Mage::helper('review')->__('ID'),
  72. 'align' => 'right',
  73. 'width' => '50px',
  74. 'filter_index' => 'rt.review_id',
  75. 'index' => 'review_id',
  76. ));
  77. $this->addColumn('created_at', array(
  78. 'header' => Mage::helper('review')->__('Created On'),
  79. 'align' => 'left',
  80. 'type' => 'datetime',
  81. 'width' => '100px',
  82. 'filter_index' => 'rt.created_at',
  83. 'index' => 'review_created_at',
  84. ));
  85. if( !Mage::registry('usePendingFilter') ) {
  86. $this->addColumn('status', array(
  87. 'header' => Mage::helper('review')->__('Status'),
  88. 'align' => 'left',
  89. 'type' => 'options',
  90. 'options' => Mage::helper('review')->getReviewStatuses(),
  91. 'width' => '100px',
  92. 'filter_index' => 'rt.status_id',
  93. 'index' => 'status_id',
  94. ));
  95. }
  96. $this->addColumn('title', array(
  97. 'header' => Mage::helper('review')->__('Title'),
  98. 'align' => 'left',
  99. 'width' => '100px',
  100. 'filter_index' => 'rdt.title',
  101. 'index' => 'title',
  102. 'type' => 'text',
  103. 'truncate' => 50,
  104. 'escape' => true,
  105. ));
  106. $this->addColumn('nickname', array(
  107. 'header' => Mage::helper('review')->__('Nickname'),
  108. 'align' => 'left',
  109. 'width' => '100px',
  110. 'filter_index' => 'rdt.nickname',
  111. 'index' => 'nickname',
  112. 'type' => 'text',
  113. 'truncate' => 50,
  114. 'escape' => true,
  115. ));
  116. $this->addColumn('detail', array(
  117. 'header' => Mage::helper('review')->__('Review'),
  118. 'align' => 'left',
  119. 'index' => 'detail',
  120. 'filter_index' => 'rdt.detail',
  121. 'type' => 'text',
  122. 'truncate' => 50,
  123. 'nl2br' => true,
  124. 'escape' => true,
  125. ));
  126. /**
  127. * Check is single store mode
  128. */
  129. if (!Mage::app()->isSingleStoreMode()) {
  130. $this->addColumn('visible_in', array(
  131. 'header' => Mage::helper('review')->__('Visible In'),
  132. 'index' => 'stores',
  133. 'type' => 'store',
  134. 'store_view' => true,
  135. ));
  136. }
  137. $this->addColumn('type', array(
  138. 'header' => Mage::helper('review')->__('Type'),
  139. 'type' => 'select',
  140. 'index' => 'type',
  141. 'filter' => 'adminhtml/review_grid_filter_type',
  142. 'renderer' => 'adminhtml/review_grid_renderer_type'
  143. ));
  144. $this->addColumn('name', array(
  145. 'header' => Mage::helper('review')->__('Product Name'),
  146. 'align' =>'left',
  147. 'type' => 'text',
  148. 'index' => 'name',
  149. 'escape' => true
  150. ));
  151. $this->addColumn('sku', array(
  152. 'header' => Mage::helper('review')->__('Product SKU'),
  153. 'align' => 'right',
  154. 'type' => 'text',
  155. 'width' => '50px',
  156. 'index' => 'sku',
  157. 'escape' => true
  158. ));
  159. $this->addColumn('action',
  160. array(
  161. 'header' => Mage::helper('adminhtml')->__('Action'),
  162. 'width' => '50px',
  163. 'type' => 'action',
  164. 'getter' => 'getReviewId',
  165. 'actions' => array(
  166. array(
  167. 'caption' => Mage::helper('adminhtml')->__('Edit'),
  168. 'url' => array(
  169. 'base'=>'*/catalog_product_review/edit',
  170. 'params'=> array(
  171. 'productId' => $this->getProductId(),
  172. 'customerId' => $this->getCustomerId(),
  173. 'ret' => ( Mage::registry('usePendingFilter') ) ? 'pending' : null
  174. )
  175. ),
  176. 'field' => 'id'
  177. )
  178. ),
  179. 'filter' => false,
  180. 'sortable' => false
  181. ));
  182. $this->addRssList('rss/catalog/review', Mage::helper('catalog')->__('Pending Reviews RSS'));
  183. return parent::_prepareColumns();
  184. }
  185. protected function _prepareMassaction()
  186. {
  187. $this->setMassactionIdField('review_id');
  188. $this->setMassactionIdFilter('rt.review_id');
  189. $this->setMassactionIdFieldOnlyIndexValue(true);
  190. $this->getMassactionBlock()->setFormFieldName('reviews');
  191. $this->getMassactionBlock()->addItem('delete', array(
  192. 'label'=> Mage::helper('review')->__('Delete'),
  193. 'url' => $this->getUrl(
  194. '*/*/massDelete',
  195. array('ret' => Mage::registry('usePendingFilter') ? 'pending' : 'index')
  196. ),
  197. 'confirm' => Mage::helper('review')->__('Are you sure?')
  198. ));
  199. $statuses = Mage::helper('review')->getReviewStatusesOptionArray();
  200. array_unshift($statuses, array('label'=>'', 'value'=>''));
  201. $this->getMassactionBlock()->addItem('update_status', array(
  202. 'label' => Mage::helper('review')->__('Update Status'),
  203. 'url' => $this->getUrl(
  204. '*/*/massUpdateStatus',
  205. array('ret' => Mage::registry('usePendingFilter') ? 'pending' : 'index')
  206. ),
  207. 'additional' => array(
  208. 'status' => array(
  209. 'name' => 'status',
  210. 'type' => 'select',
  211. 'class' => 'required-entry',
  212. 'label' => Mage::helper('review')->__('Status'),
  213. 'values' => $statuses
  214. )
  215. )
  216. ));
  217. }
  218. public function getRowUrl($row)
  219. {
  220. return $this->getUrl('*/catalog_product_review/edit', array(
  221. 'id' => $row->getReviewId(),
  222. 'productId' => $this->getProductId(),
  223. 'customerId' => $this->getCustomerId(),
  224. 'ret' => ( Mage::registry('usePendingFilter') ) ? 'pending' : null,
  225. ));
  226. }
  227. public function getGridUrl()
  228. {
  229. if( $this->getProductId() || $this->getCustomerId() ) {
  230. return $this->getUrl(
  231. '*/catalog_product_review/' . (Mage::registry('usePendingFilter') ? 'pending' : ''),
  232. array(
  233. 'productId' => $this->getProductId(),
  234. 'customerId' => $this->getCustomerId(),
  235. )
  236. );
  237. } else {
  238. return $this->getCurrentUrl();
  239. }
  240. }
  241. }