Collection.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AdvancedSearch\Model\ResourceModel\Search\Grid;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class Collection extends \Magento\Search\Model\ResourceModel\Query\Collection
  12. {
  13. /**
  14. * Registry manager
  15. *
  16. * @var \Magento\Framework\Registry
  17. */
  18. protected $_registryManager;
  19. /**
  20. * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  21. * @param \Psr\Log\LoggerInterface $logger
  22. * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  23. * @param \Magento\Framework\Event\ManagerInterface $eventManager
  24. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  25. * @param \Magento\Framework\DB\Helper $resourceHelper
  26. * @param \Magento\Framework\Registry $registry
  27. * @param mixed $connection
  28. * @param mixed $resource
  29. */
  30. public function __construct(
  31. \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
  32. \Psr\Log\LoggerInterface $logger,
  33. \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
  34. \Magento\Framework\Event\ManagerInterface $eventManager,
  35. \Magento\Store\Model\StoreManagerInterface $storeManager,
  36. \Magento\Framework\DB\Helper $resourceHelper,
  37. \Magento\Framework\Registry $registry,
  38. \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
  39. $resource = null
  40. ) {
  41. $this->_registryManager = $registry;
  42. parent::__construct(
  43. $entityFactory,
  44. $logger,
  45. $fetchStrategy,
  46. $eventManager,
  47. $storeManager,
  48. $resourceHelper,
  49. $connection,
  50. $resource
  51. );
  52. }
  53. /**
  54. * Initialize select
  55. *
  56. * @return $this
  57. */
  58. protected function _initSelect()
  59. {
  60. parent::_initSelect();
  61. $queryId = $this->getQuery()->getId();
  62. if ($queryId) {
  63. $this->addFieldToFilter('query_id', ['nin' => $queryId]);
  64. }
  65. return $this;
  66. }
  67. /**
  68. * Retrieve a value from registry by a key
  69. *
  70. * @return \Magento\Search\Model\Query
  71. */
  72. public function getQuery()
  73. {
  74. return $this->_registryManager->registry('current_catalog_search');
  75. }
  76. }