SelectContainer.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogSearch\Model\Search\SelectContainer;
  7. use Magento\Framework\DB\Select;
  8. use Magento\Framework\Search\Request\FilterInterface;
  9. /**
  10. * This class is a container for all data that is required for creating select query by search request
  11. *
  12. * @deprecated 101.0.0
  13. * @see \Magento\ElasticSearch
  14. */
  15. class SelectContainer
  16. {
  17. /**
  18. * @var array FilterInterface[]
  19. */
  20. private $nonCustomAttributesFilters;
  21. /**
  22. * @var array FilterInterface[]
  23. */
  24. private $customAttributesFilters;
  25. /**
  26. * @var FilterInterface
  27. */
  28. private $visibilityFilter;
  29. /**
  30. * @var bool
  31. */
  32. private $isFullTextSearchRequired;
  33. /**
  34. * @var bool
  35. */
  36. private $isShowOutOfStockEnabled;
  37. /**
  38. * @var Select
  39. */
  40. private $select;
  41. /**
  42. * @var string
  43. */
  44. private $usedIndex;
  45. /**
  46. * @var array
  47. */
  48. private $dimensions;
  49. /**
  50. * @param Select $select
  51. * @param array $nonCustomAttributesFilters
  52. * @param array $customAttributesFilters
  53. * @param array $dimensions
  54. * @param bool $isFullTextSearchRequired
  55. * @param bool $isShowOutOfStockEnabled
  56. * @param string $usedIndex
  57. * @param FilterInterface|null $visibilityFilter
  58. */
  59. public function __construct(
  60. Select $select,
  61. array $nonCustomAttributesFilters,
  62. array $customAttributesFilters,
  63. array $dimensions,
  64. bool $isFullTextSearchRequired,
  65. bool $isShowOutOfStockEnabled,
  66. $usedIndex,
  67. FilterInterface $visibilityFilter = null
  68. ) {
  69. $this->nonCustomAttributesFilters = $nonCustomAttributesFilters;
  70. $this->customAttributesFilters = $customAttributesFilters;
  71. $this->visibilityFilter = $visibilityFilter;
  72. $this->isFullTextSearchRequired = $isFullTextSearchRequired;
  73. $this->isShowOutOfStockEnabled = $isShowOutOfStockEnabled;
  74. $this->select = $select;
  75. $this->usedIndex = $usedIndex;
  76. $this->dimensions = $dimensions;
  77. }
  78. /**
  79. * @return array
  80. */
  81. public function getNonCustomAttributesFilters()
  82. {
  83. return $this->nonCustomAttributesFilters;
  84. }
  85. /**
  86. * @return array
  87. */
  88. public function getCustomAttributesFilters()
  89. {
  90. return $this->customAttributesFilters;
  91. }
  92. /**
  93. * @return bool
  94. */
  95. public function hasCustomAttributesFilters()
  96. {
  97. return count($this->customAttributesFilters) > 0;
  98. }
  99. /**
  100. * @return bool
  101. */
  102. public function hasVisibilityFilter()
  103. {
  104. return $this->visibilityFilter !== null;
  105. }
  106. /**
  107. * Returns a null or copy of FilterInterface
  108. * This is done to ensure that SelectContainer is immutable
  109. *
  110. * @return FilterInterface
  111. */
  112. public function getVisibilityFilter()
  113. {
  114. return $this->visibilityFilter === null ? null : clone $this->visibilityFilter;
  115. }
  116. /**
  117. * @return bool
  118. */
  119. public function isFullTextSearchRequired()
  120. {
  121. return $this->isFullTextSearchRequired;
  122. }
  123. /**
  124. * @return bool
  125. */
  126. public function isShowOutOfStockEnabled()
  127. {
  128. return $this->isShowOutOfStockEnabled;
  129. }
  130. /**
  131. * @return string
  132. */
  133. public function getUsedIndex()
  134. {
  135. return $this->usedIndex;
  136. }
  137. /**
  138. * @return array
  139. */
  140. public function getDimensions()
  141. {
  142. return $this->dimensions;
  143. }
  144. /**
  145. * Returns a copy of Select
  146. * This is done to ensure that SelectContainer is immutable
  147. *
  148. * @return Select
  149. */
  150. public function getSelect()
  151. {
  152. return clone $this->select;
  153. }
  154. /**
  155. * Returns new instance of SelectContainer on update
  156. * This is done to ensure that SelectContainer is immutable
  157. *
  158. * @param Select $select
  159. * @return SelectContainer
  160. */
  161. public function updateSelect(Select $select)
  162. {
  163. $data = [
  164. clone $select,
  165. $this->nonCustomAttributesFilters,
  166. $this->customAttributesFilters,
  167. $this->dimensions,
  168. $this->isFullTextSearchRequired,
  169. $this->isShowOutOfStockEnabled,
  170. $this->usedIndex
  171. ];
  172. if ($this->visibilityFilter !== null) {
  173. $data[] = clone $this->visibilityFilter;
  174. }
  175. return new self(...$data);
  176. }
  177. }