123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- /**
- * Adminhtml reviews grid
- *
- * @method int getProductId() getProductId()
- * @method \Magento\Review\Block\Adminhtml\Grid setProductId() setProductId(int $productId)
- * @method int getCustomerId() getCustomerId()
- * @method \Magento\Review\Block\Adminhtml\Grid setCustomerId() setCustomerId(int $customerId)
- * @method \Magento\Review\Block\Adminhtml\Grid setMassactionIdFieldOnlyIndexValue()
- * setMassactionIdFieldOnlyIndexValue(bool $onlyIndex)
- *
- * @author Magento Core Team <core@magentocommerce.com>
- */
- namespace Magento\Review\Block\Adminhtml;
- class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
- {
- /**
- * Review action pager
- *
- * @var \Magento\Review\Helper\Action\Pager
- */
- protected $_reviewActionPager = null;
- /**
- * Review data
- *
- * @var \Magento\Review\Helper\Data
- */
- protected $_reviewData = null;
- /**
- * Core registry
- *
- * @var \Magento\Framework\Registry
- */
- protected $_coreRegistry = null;
- /**
- * Review collection model factory
- *
- * @var \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory
- */
- protected $_productsFactory;
- /**
- * Review model factory
- *
- * @var \Magento\Review\Model\ReviewFactory
- */
- protected $_reviewFactory;
- /**
- * @param \Magento\Backend\Block\Template\Context $context
- * @param \Magento\Backend\Helper\Data $backendHelper
- * @param \Magento\Review\Model\ReviewFactory $reviewFactory
- * @param \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory $productsFactory
- * @param \Magento\Review\Helper\Data $reviewData
- * @param \Magento\Review\Helper\Action\Pager $reviewActionPager
- * @param \Magento\Framework\Registry $coreRegistry
- * @param array $data
- */
- public function __construct(
- \Magento\Backend\Block\Template\Context $context,
- \Magento\Backend\Helper\Data $backendHelper,
- \Magento\Review\Model\ReviewFactory $reviewFactory,
- \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory $productsFactory,
- \Magento\Review\Helper\Data $reviewData,
- \Magento\Review\Helper\Action\Pager $reviewActionPager,
- \Magento\Framework\Registry $coreRegistry,
- array $data = []
- ) {
- $this->_productsFactory = $productsFactory;
- $this->_coreRegistry = $coreRegistry;
- $this->_reviewData = $reviewData;
- $this->_reviewActionPager = $reviewActionPager;
- $this->_reviewFactory = $reviewFactory;
- parent::__construct($context, $backendHelper, $data);
- }
- /**
- * Initialize grid
- *
- * @return void
- */
- protected function _construct()
- {
- parent::_construct();
- $this->setId('reviwGrid');
- $this->setDefaultSort('created_at');
- }
- /**
- * Save search results
- *
- * @return \Magento\Backend\Block\Widget\Grid
- */
- protected function _afterLoadCollection()
- {
- /** @var $actionPager \Magento\Review\Helper\Action\Pager */
- $actionPager = $this->_reviewActionPager;
- $actionPager->setStorageId('reviews');
- $actionPager->setItems($this->getCollection()->getResultingIds());
- return parent::_afterLoadCollection();
- }
- /**
- * Prepare collection
- *
- * @return \Magento\Review\Block\Adminhtml\Grid
- */
- protected function _prepareCollection()
- {
- /** @var $model \Magento\Review\Model\Review */
- $model = $this->_reviewFactory->create();
- /** @var $collection \Magento\Review\Model\ResourceModel\Review\Product\Collection */
- $collection = $this->_productsFactory->create();
- if ($this->getProductId() || $this->getRequest()->getParam('productId', false)) {
- $productId = $this->getProductId();
- if (!$productId) {
- $productId = $this->getRequest()->getParam('productId');
- }
- $this->setProductId($productId);
- $collection->addEntityFilter($this->getProductId());
- }
- if ($this->getCustomerId() || $this->getRequest()->getParam('customerId', false)) {
- $customerId = $this->getCustomerId();
- if (!$customerId) {
- $customerId = $this->getRequest()->getParam('customerId');
- }
- $this->setCustomerId($customerId);
- $collection->addCustomerFilter($this->getCustomerId());
- }
- if ($this->_coreRegistry->registry('usePendingFilter') === true) {
- $collection->addStatusFilter($model->getPendingStatus());
- }
- $collection->addStoreData();
- $this->setCollection($collection);
- return parent::_prepareCollection();
- }
- /**
- * Prepare grid columns
- *
- * @return \Magento\Backend\Block\Widget\Grid
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- protected function _prepareColumns()
- {
- $this->addColumn(
- 'review_id',
- [
- 'header' => __('ID'),
- 'filter_index' => 'rt.review_id',
- 'index' => 'review_id',
- 'header_css_class' => 'col-id',
- 'column_css_class' => 'col-id'
- ]
- );
- $this->addColumn(
- 'created_at',
- [
- 'header' => __('Created'),
- 'type' => 'datetime',
- 'filter_index' => 'rt.created_at',
- 'index' => 'review_created_at',
- 'header_css_class' => 'col-date',
- 'column_css_class' => 'col-date'
- ]
- );
- if (!$this->_coreRegistry->registry('usePendingFilter')) {
- $this->addColumn(
- 'status',
- [
- 'header' => __('Status'),
- 'type' => 'options',
- 'options' => $this->_reviewData->getReviewStatuses(),
- 'filter_index' => 'rt.status_id',
- 'index' => 'status_id'
- ]
- );
- }
- $this->addColumn(
- 'title',
- [
- 'header' => __('Title'),
- 'filter_index' => 'rdt.title',
- 'index' => 'title',
- 'type' => 'text',
- 'truncate' => 50,
- 'escape' => true
- ]
- );
- $this->addColumn(
- 'nickname',
- [
- 'header' => __('Nickname'),
- 'filter_index' => 'rdt.nickname',
- 'index' => 'nickname',
- 'type' => 'text',
- 'truncate' => 50,
- 'escape' => true,
- 'header_css_class' => 'col-name',
- 'column_css_class' => 'col-name'
- ]
- );
- $this->addColumn(
- 'detail',
- [
- 'header' => __('Review'),
- 'index' => 'detail',
- 'filter_index' => 'rdt.detail',
- 'type' => 'text',
- 'truncate' => 50,
- 'nl2br' => true,
- 'escape' => true
- ]
- );
- /**
- * Check is single store mode
- */
- if (!$this->_storeManager->isSingleStoreMode()) {
- $this->addColumn(
- 'visible_in',
- ['header' => __('Visibility'), 'index' => 'stores', 'type' => 'store', 'store_view' => true]
- );
- }
- $this->addColumn(
- 'type',
- [
- 'header' => __('Type'),
- 'type' => 'select',
- 'index' => 'type',
- 'filter' => \Magento\Review\Block\Adminhtml\Grid\Filter\Type::class,
- 'renderer' => \Magento\Review\Block\Adminhtml\Grid\Renderer\Type::class
- ]
- );
- $this->addColumn(
- 'name',
- ['header' => __('Product'), 'type' => 'text', 'index' => 'name', 'escape' => true]
- );
- $this->addColumn(
- 'sku',
- [
- 'header' => __('SKU'),
- 'type' => 'text',
- 'index' => 'sku',
- 'escape' => true
- ]
- );
- $this->addColumn(
- 'action',
- [
- 'header' => __('Action'),
- 'type' => 'action',
- 'getter' => 'getReviewId',
- 'actions' => [
- [
- 'caption' => __('Edit'),
- 'url' => [
- 'base' => 'review/product/edit',
- 'params' => [
- 'productId' => $this->getProductId(),
- 'customerId' => $this->getCustomerId(),
- 'ret' => $this->_coreRegistry->registry('usePendingFilter') ? 'pending' : null,
- ],
- ],
- 'field' => 'id',
- ],
- ],
- 'filter' => false,
- 'sortable' => false
- ]
- );
- $block = $this->getLayout()->getBlock('grid.bottom.links');
- if ($block) {
- $this->setChild('grid.bottom.links', $block);
- }
- return parent::_prepareColumns();
- }
- /**
- * Prepare grid mass actions
- *
- * @return void
- */
- protected function _prepareMassaction()
- {
- $this->setMassactionIdField('review_id');
- $this->setMassactionIdFilter('rt.review_id');
- $this->setMassactionIdFieldOnlyIndexValue(true);
- $this->getMassactionBlock()->setFormFieldName('reviews');
- $this->getMassactionBlock()->addItem(
- 'delete',
- [
- 'label' => __('Delete'),
- 'url' => $this->getUrl(
- '*/*/massDelete',
- ['ret' => $this->_coreRegistry->registry('usePendingFilter') ? 'pending' : 'index']
- ),
- 'confirm' => __('Are you sure?')
- ]
- );
- $statuses = $this->_reviewData->getReviewStatusesOptionArray();
- array_unshift($statuses, ['label' => '', 'value' => '']);
- $this->getMassactionBlock()->addItem(
- 'update_status',
- [
- 'label' => __('Update Status'),
- 'url' => $this->getUrl(
- '*/*/massUpdateStatus',
- ['ret' => $this->_coreRegistry->registry('usePendingFilter') ? 'pending' : 'index']
- ),
- 'additional' => [
- 'status' => [
- 'name' => 'status',
- 'type' => 'select',
- 'class' => 'required-entry',
- 'label' => __('Status'),
- 'values' => $statuses,
- ],
- ]
- ]
- );
- }
- /**
- * Get row url
- *
- * @param \Magento\Review\Model\Review|\Magento\Framework\DataObject $row
- * @return string
- */
- public function getRowUrl($row)
- {
- return $this->getUrl(
- 'review/product/edit',
- [
- 'id' => $row->getReviewId(),
- 'productId' => $this->getProductId(),
- 'customerId' => $this->getCustomerId(),
- 'ret' => $this->_coreRegistry->registry('usePendingFilter') ? 'pending' : null
- ]
- );
- }
- /**
- * Get grid url
- *
- * @return string
- */
- public function getGridUrl()
- {
- if ($this->getProductId() || $this->getCustomerId()) {
- return $this->getUrl(
- 'review/product' . ($this->_coreRegistry->registry('usePendingFilter') ? 'pending' : ''),
- ['productId' => $this->getProductId(), 'customerId' => $this->getCustomerId()]
- );
- } else {
- return $this->getCurrentUrl();
- }
- }
- }
|