CriteriaInterface.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Api;
  7. /**
  8. * Interface CriteriaInterface
  9. */
  10. interface CriteriaInterface
  11. {
  12. const PART_FIELDS = 'fields';
  13. const PART_FILTERS = 'filters';
  14. const PART_ORDERS = 'orders';
  15. const PART_CRITERIA_LIST = 'criteria_list';
  16. const PART_LIMIT = 'limit';
  17. const SORT_ORDER_ASC = 'ASC';
  18. const SORT_ORDER_DESC = 'DESC';
  19. /**
  20. * Get associated Mapper Interface name
  21. *
  22. * @return string
  23. */
  24. public function getMapperInterfaceName();
  25. /**
  26. * Add field to select
  27. *
  28. * @param string|array $field
  29. * @param string|null $alias
  30. * @return void
  31. */
  32. public function addField($field, $alias = null);
  33. /**
  34. * Add field filter to collection
  35. *
  36. * If $condition integer or string - exact value will be filtered ('eq' condition)
  37. *
  38. * If $condition is array - one of the following structures is expected:
  39. * <pre>
  40. * - ["from" => $fromValue, "to" => $toValue]
  41. * - ["eq" => $equalValue]
  42. * - ["neq" => $notEqualValue]
  43. * - ["like" => $likeValue]
  44. * - ["in" => [$inValues]]
  45. * - ["nin" => [$notInValues]]
  46. * - ["notnull" => $valueIsNotNull]
  47. * - ["null" => $valueIsNull]
  48. * - ["moreq" => $moreOrEqualValue]
  49. * - ["gt" => $greaterValue]
  50. * - ["lt" => $lessValue]
  51. * - ["gteq" => $greaterOrEqualValue]
  52. * - ["lteq" => $lessOrEqualValue]
  53. * - ["finset" => $valueInSet]
  54. * </pre>
  55. *
  56. * If non matched - sequential parallel arrays are expected and OR conditions
  57. * will be built using above mentioned structure.
  58. *
  59. * Example:
  60. * <pre>
  61. * $field = ['age', 'name'];
  62. * $condition = [42, ['like' => 'Mage']];
  63. * $type = 'or';
  64. * </pre>
  65. * The above would find where age equal to 42 OR name like %Mage%.
  66. *
  67. * @param string $name
  68. * @param string|array $field
  69. * @param string|int|array $condition
  70. * @param string $type
  71. * @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected.
  72. * @return void
  73. */
  74. public function addFilter($name, $field, $condition = null, $type = 'and');
  75. /**
  76. * self::setOrder() alias
  77. *
  78. * @param string $field
  79. * @param string $direction
  80. * @param bool $unShift
  81. * @return void
  82. */
  83. public function addOrder($field, $direction = self::SORT_ORDER_DESC, $unShift = false);
  84. /**
  85. * Set Query limit
  86. *
  87. * @param int $offset
  88. * @param int $size
  89. * @return void
  90. */
  91. public function setLimit($offset, $size);
  92. /**
  93. * Removes field from select
  94. *
  95. * @param string|null $field
  96. * @param bool $isAlias Alias identifier
  97. * @return void
  98. */
  99. public function removeField($field, $isAlias = false);
  100. /**
  101. * Removes all fields from select
  102. *
  103. * @return void
  104. */
  105. public function removeAllFields();
  106. /**
  107. * Removes filter by name
  108. *
  109. * @param string $name
  110. * @return void
  111. */
  112. public function removeFilter($name);
  113. /**
  114. * Removes all filters
  115. *
  116. * @return void
  117. */
  118. public function removeAllFilters();
  119. /**
  120. * Get Criteria objects added to current Composite Criteria
  121. *
  122. * @return \Magento\Framework\Api\CriteriaInterface[]
  123. */
  124. public function getCriteriaList();
  125. /**
  126. * Get list of filters
  127. *
  128. * @return string[]
  129. */
  130. public function getFilters();
  131. /**
  132. * Get ordering criteria
  133. *
  134. * @return string[]
  135. */
  136. public function getOrders();
  137. /**
  138. * Get limit
  139. * (['offset', 'page'])
  140. *
  141. * @return string[]
  142. */
  143. public function getLimit();
  144. /**
  145. * Retrieve criteria part
  146. *
  147. * @param string $name
  148. * @param mixed $default
  149. * @return mixed
  150. */
  151. public function getPart($name, $default = null);
  152. /**
  153. * Return all criteria parts as array
  154. *
  155. * @return array
  156. */
  157. public function toArray();
  158. /**
  159. * Reset criteria
  160. *
  161. * @return void
  162. */
  163. public function reset();
  164. }