Top.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Search\Block\Adminhtml\Dashboard;
  7. /**
  8. * Dashboard last search keywords block
  9. * @api
  10. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  11. * @since 100.0.2
  12. */
  13. class Top extends \Magento\Backend\Block\Dashboard\Grid
  14. {
  15. /**
  16. * @var \Magento\Search\Model\ResourceModel\Query\Collection
  17. */
  18. protected $_collection;
  19. /**
  20. * @var \Magento\Search\Model\ResourceModel\Query\CollectionFactory
  21. */
  22. protected $_queriesFactory;
  23. /**
  24. * @var \Magento\Framework\Module\Manager
  25. */
  26. protected $_moduleManager;
  27. /**
  28. * @var string
  29. */
  30. protected $_template = 'Magento_Backend::dashboard/grid.phtml';
  31. /**
  32. * @param \Magento\Backend\Block\Template\Context $context
  33. * @param \Magento\Backend\Helper\Data $backendHelper
  34. * @param \Magento\Framework\Module\Manager $moduleManager
  35. * @param \Magento\Search\Model\ResourceModel\Query\CollectionFactory $queriesFactory
  36. * @param array $data
  37. */
  38. public function __construct(
  39. \Magento\Backend\Block\Template\Context $context,
  40. \Magento\Backend\Helper\Data $backendHelper,
  41. \Magento\Framework\Module\Manager $moduleManager,
  42. \Magento\Search\Model\ResourceModel\Query\CollectionFactory $queriesFactory,
  43. array $data = []
  44. ) {
  45. $this->_moduleManager = $moduleManager;
  46. $this->_queriesFactory = $queriesFactory;
  47. parent::__construct($context, $backendHelper, $data);
  48. }
  49. /**
  50. * @return void
  51. */
  52. protected function _construct()
  53. {
  54. parent::_construct();
  55. $this->setId('topSearchGrid');
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. protected function _prepareCollection()
  61. {
  62. $this->_collection = $this->_queriesFactory->create();
  63. if ($this->getRequest()->getParam('store')) {
  64. $storeIds = $this->getRequest()->getParam('store');
  65. } elseif ($this->getRequest()->getParam('website')) {
  66. $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
  67. } elseif ($this->getRequest()->getParam('group')) {
  68. $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
  69. } else {
  70. $storeIds = '';
  71. }
  72. $this->_collection->setPopularQueryFilter($storeIds);
  73. $this->setCollection($this->_collection);
  74. return parent::_prepareCollection();
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. protected function _prepareColumns()
  80. {
  81. $this->addColumn(
  82. 'search_query',
  83. [
  84. 'header' => __('Search Term'),
  85. 'sortable' => false,
  86. 'index' => 'query_text',
  87. 'renderer' => \Magento\Backend\Block\Dashboard\Searches\Renderer\Searchquery::class,
  88. 'header_css_class' => 'col-search-query',
  89. 'column_css_class' => 'col-search-query'
  90. ]
  91. );
  92. $this->addColumn(
  93. 'num_results',
  94. ['header' => __('Results'), 'sortable' => false, 'index' => 'num_results', 'type' => 'number']
  95. );
  96. $this->addColumn(
  97. 'popularity',
  98. ['header' => __('Uses'), 'sortable' => false, 'index' => 'popularity', 'type' => 'number']
  99. );
  100. $this->setFilterVisibility(false);
  101. $this->setPagerVisibility(false);
  102. return parent::_prepareColumns();
  103. }
  104. /**
  105. * {@inheritdoc}
  106. */
  107. public function getRowUrl($row)
  108. {
  109. return $this->getUrl('search/term/edit', ['id' => $row->getId()]);
  110. }
  111. }