Grid.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Reports\Block\Adminhtml\Review\Detail;
  7. /**
  8. * Adminhtml report reviews product grid block
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
  13. {
  14. /**
  15. * @var \Magento\Reports\Model\ResourceModel\Review\CollectionFactory
  16. */
  17. protected $_reviewsFactory;
  18. /**
  19. * @param \Magento\Backend\Block\Template\Context $context
  20. * @param \Magento\Backend\Helper\Data $backendHelper
  21. * @param \Magento\Reports\Model\ResourceModel\Review\CollectionFactory $reviewsFactory
  22. * @param array $data
  23. */
  24. public function __construct(
  25. \Magento\Backend\Block\Template\Context $context,
  26. \Magento\Backend\Helper\Data $backendHelper,
  27. \Magento\Reports\Model\ResourceModel\Review\CollectionFactory $reviewsFactory,
  28. array $data = []
  29. ) {
  30. $this->_reviewsFactory = $reviewsFactory;
  31. parent::__construct($context, $backendHelper, $data);
  32. }
  33. /**
  34. * @return void
  35. */
  36. protected function _construct()
  37. {
  38. parent::_construct();
  39. $this->setId('reviews_grid');
  40. }
  41. /**
  42. * Apply sorting and filtering to reports review collection
  43. *
  44. * @return $this
  45. */
  46. protected function _prepareCollection()
  47. {
  48. $collection = $this->_reviewsFactory->create()->addProductFilter((int)$this->getRequest()->getParam('id'));
  49. $this->setCollection($collection);
  50. parent::_prepareCollection();
  51. return $this;
  52. }
  53. /**
  54. * Initialize grid report review columns
  55. *
  56. * @return $this
  57. */
  58. protected function _prepareColumns()
  59. {
  60. $this->addColumn('nickname', ['header' => __('Customer'), 'width' => '100px', 'index' => 'nickname']);
  61. $this->addColumn('title', ['header' => __('Title'), 'width' => '150px', 'index' => 'title']);
  62. $this->addColumn('detail', ['header' => __('Detail'), 'index' => 'detail']);
  63. $this->addColumn(
  64. 'created_at',
  65. ['header' => __('Created'), 'index' => 'created_at', 'width' => '200px', 'type' => 'datetime']
  66. );
  67. $this->setFilterVisibility(false);
  68. $this->addExportType('*/*/exportProductDetailCsv', __('CSV'));
  69. $this->addExportType('*/*/exportProductDetailExcel', __('Excel XML'));
  70. return parent::_prepareColumns();
  71. }
  72. }