Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Top.php
Go to the documentation of this file.
1 <?php
7 
14 class Top extends \Magento\Backend\Block\Dashboard\Grid
15 {
19  protected $_collection;
20 
24  protected $_queriesFactory;
25 
29  protected $_moduleManager;
30 
34  protected $_template = 'Magento_Backend::dashboard/grid.phtml';
35 
43  public function __construct(
44  \Magento\Backend\Block\Template\Context $context,
45  \Magento\Backend\Helper\Data $backendHelper,
46  \Magento\Framework\Module\Manager $moduleManager,
47  \Magento\Search\Model\ResourceModel\Query\CollectionFactory $queriesFactory,
48  array $data = []
49  ) {
50  $this->_moduleManager = $moduleManager;
51  $this->_queriesFactory = $queriesFactory;
52  parent::__construct($context, $backendHelper, $data);
53  }
54 
58  protected function _construct()
59  {
60  parent::_construct();
61  $this->setId('topSearchGrid');
62  }
63 
67  protected function _prepareCollection()
68  {
69  $this->_collection = $this->_queriesFactory->create();
70 
71  if ($this->getRequest()->getParam('store')) {
72  $storeIds = $this->getRequest()->getParam('store');
73  } elseif ($this->getRequest()->getParam('website')) {
74  $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
75  } elseif ($this->getRequest()->getParam('group')) {
76  $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
77  } else {
78  $storeIds = '';
79  }
80 
81  $this->_collection->setPopularQueryFilter($storeIds);
82 
83  $this->setCollection($this->_collection);
84 
85  return parent::_prepareCollection();
86  }
87 
91  protected function _prepareColumns()
92  {
93  $this->addColumn(
94  'search_query',
95  [
96  'header' => __('Search Term'),
97  'sortable' => false,
98  'index' => 'query_text',
99  'renderer' => \Magento\Backend\Block\Dashboard\Searches\Renderer\Searchquery::class,
100  'header_css_class' => 'col-search-query',
101  'column_css_class' => 'col-search-query'
102  ]
103  );
104 
105  $this->addColumn(
106  'num_results',
107  ['header' => __('Results'), 'sortable' => false, 'index' => 'num_results', 'type' => 'number']
108  );
109 
110  $this->addColumn(
111  'popularity',
112  ['header' => __('Uses'), 'sortable' => false, 'index' => 'popularity', 'type' => 'number']
113  );
114 
115  $this->setFilterVisibility(false);
116  $this->setPagerVisibility(false);
117 
118  return parent::_prepareColumns();
119  }
120 
124  public function getRowUrl($row)
125  {
126  return $this->getUrl('search/term/edit', ['id' => $row->getId()]);
127  }
128 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\Framework\Module\Manager $moduleManager, \Magento\Search\Model\ResourceModel\Query\CollectionFactory $queriesFactory, array $data=[])
Definition: Top.php:43
setPagerVisibility($visible=true)
Definition: Grid.php:588
$this _collection
Definition: coupons.php:7
$moduleManager
Definition: products.php:75
getParam($paramName, $default=null)
Definition: Grid.php:729