_moduleManager = $moduleManager; $this->_queriesFactory = $queriesFactory; parent::__construct($context, $backendHelper, $data); } /** * @return void */ protected function _construct() { parent::_construct(); $this->setId('lastSearchGrid'); } /** * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ protected function _prepareCollection() { $this->_collection = $this->_queriesFactory->create(); $this->_collection->setRecentQueryFilter(); if ($this->getRequest()->getParam('store')) { $this->_collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store')); } elseif ($this->getRequest()->getParam('website')) { $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', ['in' => $storeIds]); } elseif ($this->getRequest()->getParam('group')) { $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', ['in' => $storeIds]); } $this->setCollection($this->_collection); return parent::_prepareCollection(); } /** * @return $this * @throws \Exception */ protected function _prepareColumns() { $this->addColumn( 'search_query', [ 'header' => __('Search Term'), 'sortable' => false, 'index' => 'query_text', 'renderer' => \Magento\Backend\Block\Dashboard\Searches\Renderer\Searchquery::class, 'header_css_class' => 'col-search-query', 'column_css_class' => 'col-search-query' ] ); $this->addColumn( 'num_results', ['header' => __('Results'), 'sortable' => false, 'index' => 'num_results', 'type' => 'number'] ); $this->addColumn( 'popularity', ['header' => __('Uses'), 'sortable' => false, 'index' => 'popularity', 'type' => 'number'] ); $this->setFilterVisibility(false); $this->setPagerVisibility(false); return parent::_prepareColumns(); } /** * @inheritdoc */ public function getRowUrl($row) { return $this->getUrl('search/term/edit', ['id' => $row->getId()]); } }