SearchData.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AdvancedSearch\Block;
  7. use Magento\Framework\View\Element\Template;
  8. use Magento\Search\Model\QueryFactoryInterface;
  9. use Magento\Search\Model\QueryInterface;
  10. use Magento\AdvancedSearch\Model\SuggestedQueriesInterface;
  11. abstract class SearchData extends Template implements SearchDataInterface
  12. {
  13. /**
  14. * @var QueryInterface
  15. */
  16. private $query;
  17. /**
  18. * @var string
  19. */
  20. protected $title;
  21. /**
  22. * @var SuggestedQueriesInterface
  23. */
  24. private $searchDataProvider;
  25. /**
  26. * @var string
  27. */
  28. protected $_template = 'Magento_AdvancedSearch::search_data.phtml';
  29. /**
  30. * @param Template\Context $context
  31. * @param SuggestedQueriesInterface $searchDataProvider
  32. * @param QueryFactoryInterface $queryFactory
  33. * @param string $title
  34. * @param array $data
  35. */
  36. public function __construct(
  37. Template\Context $context,
  38. SuggestedQueriesInterface $searchDataProvider,
  39. QueryFactoryInterface $queryFactory,
  40. $title,
  41. array $data = []
  42. ) {
  43. $this->searchDataProvider = $searchDataProvider;
  44. $this->query = $queryFactory->get();
  45. $this->title = $title;
  46. parent::__construct($context, $data);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function getItems()
  52. {
  53. return $this->searchDataProvider->getItems($this->query);
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function isShowResultsCount()
  59. {
  60. return $this->searchDataProvider->isResultsCountEnabled();
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getLink($queryText)
  66. {
  67. return $this->getUrl('*/*/') . '?q=' . urlencode($queryText);
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function getTitle()
  73. {
  74. return __($this->title);
  75. }
  76. }