HeartbeatEntityQuery.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?php
  2. use Drupal\Core\Entity\Query\QueryInterface;
  3. /**
  4. * Created by IntelliJ IDEA.
  5. * User: logicp
  6. * Date: 5/28/17
  7. * Time: 1:37 PM
  8. */
  9. class HeartbeatEntityQuery implements QueryInterface {
  10. /**
  11. * Adds a tag to a query.
  12. *
  13. * Tags are strings that identify a query. A query may have any number of
  14. * tags. Tags are used to mark a query so that alter hooks may decide if they
  15. * wish to take action. Tags should be all lower-case and contain only
  16. * letters, numbers, and underscore, and start with a letter. That is, they
  17. * should follow the same rules as PHP identifiers in general.
  18. *
  19. * @param $tag
  20. * The tag to add.
  21. *
  22. * @return \Drupal\Core\Database\Query\AlterableInterface
  23. * The called object.
  24. */
  25. public function addTag($tag)
  26. {
  27. // TODO: Implement addTag() method.
  28. }
  29. /**
  30. * Determines if a given query has a given tag.
  31. *
  32. * @param $tag
  33. * The tag to check.
  34. *
  35. * @return
  36. * TRUE if this query has been marked with this tag, FALSE otherwise.
  37. */
  38. public function hasTag($tag)
  39. {
  40. // TODO: Implement hasTag() method.
  41. }
  42. /**
  43. * Determines if a given query has all specified tags.
  44. *
  45. * @param $tags
  46. * A variable number of arguments, one for each tag to check.
  47. *
  48. * @return
  49. * TRUE if this query has been marked with all specified tags, FALSE
  50. * otherwise.
  51. */
  52. public function hasAllTags()
  53. {
  54. // TODO: Implement hasAllTags() method.
  55. }
  56. /**
  57. * Determines if a given query has any specified tag.
  58. *
  59. * @param $tags
  60. * A variable number of arguments, one for each tag to check.
  61. *
  62. * @return
  63. * TRUE if this query has been marked with at least one of the specified
  64. * tags, FALSE otherwise.
  65. */
  66. public function hasAnyTag()
  67. {
  68. // TODO: Implement hasAnyTag() method.
  69. }
  70. /**
  71. * Adds additional metadata to the query.
  72. *
  73. * Often, a query may need to provide additional contextual data to alter
  74. * hooks. Alter hooks may then use that information to decide if and how
  75. * to take action.
  76. *
  77. * @param $key
  78. * The unique identifier for this piece of metadata. Must be a string that
  79. * follows the same rules as any other PHP identifier.
  80. * @param $object
  81. * The additional data to add to the query. May be any valid PHP variable.
  82. *
  83. * @return \Drupal\Core\Database\Query\AlterableInterface
  84. * The called object.
  85. */
  86. public function addMetaData($key, $object)
  87. {
  88. // TODO: Implement addMetaData() method.
  89. }
  90. /**
  91. * Retrieves a given piece of metadata.
  92. *
  93. * @param $key
  94. * The unique identifier for the piece of metadata to retrieve.
  95. *
  96. * @return
  97. * The previously attached metadata object, or NULL if one doesn't exist.
  98. */
  99. public function getMetaData($key)
  100. {
  101. // TODO: Implement getMetaData() method.
  102. }
  103. /**
  104. * Gets the ID of the entity type for this query.
  105. *
  106. * @return string
  107. */
  108. public function getEntityTypeId()
  109. {
  110. // TODO: Implement getEntityTypeId() method.
  111. }
  112. /**
  113. * Add a condition to the query or a condition group.
  114. *
  115. * For example, to find all entities containing both the Turkish 'merhaba'
  116. * and the Polish 'siema' within a 'greetings' text field:
  117. * @code
  118. * $entity_ids = \Drupal::entityQuery($entity_type)
  119. * ->condition('greetings', 'merhaba', '=', 'tr')
  120. * ->condition('greetings.value', 'siema', '=', 'pl')
  121. * ->execute();
  122. * @endcode
  123. *
  124. * @param $field
  125. * Name of the field being queried. It must contain a field name, optionally
  126. * followed by a column name. The column can be the reference property,
  127. * usually "entity", for reference fields and that can be followed
  128. * similarly by a field name and so on. Additionally, the target entity type
  129. * can be specified by appending the ":target_entity_type_id" to "entity".
  130. * Some examples:
  131. * - nid
  132. * - tags.value
  133. * - tags
  134. * - tags.entity.name
  135. * - tags.entity:taxonomy_term.name
  136. * - uid.entity.name
  137. * - uid.entity:user.name
  138. * "tags" "is the same as "tags.value" as value is the default column.
  139. * If two or more conditions have the same field names they apply to the
  140. * same delta within that field. In order to limit the condition to a
  141. * specific item a numeric delta should be added between the field name and
  142. * the column name.
  143. * @code
  144. * ->condition('tags.5.value', 'news')
  145. * @endcode
  146. * This will require condition to be satisfied on a specific delta of the
  147. * field. The condition above will require the 6th value of the field to
  148. * match the provided value. Further, it's possible to create a condition on
  149. * the delta itself by using '%delta'. For example,
  150. * @code
  151. * ->condition('tags.%delta', 5)
  152. * @endcode
  153. * will find only entities which have at least six tags. Finally, the
  154. * condition on the delta itself accompanied with a condition on the value
  155. * will require the value to appear in the specific delta range. For
  156. * example,
  157. * @code
  158. * ->condition('tags.%delta', 0, '>'))
  159. * ->condition('tags.%delta.value', 'news'))
  160. * @endcode
  161. * will only find the "news" tag if it is not the first value. It should be
  162. * noted that conditions on specific deltas and delta ranges are only
  163. * supported when querying content entities.
  164. * @param $value
  165. * The value for $field. In most cases, this is a scalar and it's treated as
  166. * case-insensitive. For more complex operators, it is an array. The meaning
  167. * of each element in the array is dependent on $operator.
  168. * @param $operator
  169. * Possible values:
  170. * - '=', '<>', '>', '>=', '<', '<=', 'STARTS_WITH', 'CONTAINS',
  171. * 'ENDS_WITH': These operators expect $value to be a literal of the
  172. * same type as the column.
  173. * - 'IN', 'NOT IN': These operators expect $value to be an array of
  174. * literals of the same type as the column.
  175. * - 'BETWEEN': This operator expects $value to be an array of two literals
  176. * of the same type as the column.
  177. * @param $langcode
  178. * Language code (optional). If omitted, any translation satisfies the
  179. * condition. However, if two or more conditions omit the langcode within
  180. * one condition group then they are presumed to apply to the same
  181. * translation. If within one condition group one condition has a langcode
  182. * and another does not they are not presumed to apply to the same
  183. * translation.
  184. *
  185. * @return \Drupal\Core\Entity\Query\QueryInterface
  186. * @see \Drupal\Core\Entity\Query\andConditionGroup
  187. * @see \Drupal\Core\Entity\Query\orConditionGroup
  188. */
  189. public function condition($field, $value = NULL, $operator = NULL, $langcode = NULL)
  190. {
  191. // TODO: Implement condition() method.
  192. }
  193. /**
  194. * Queries for a non-empty value on a field.
  195. *
  196. * @param $field
  197. * Name of a field.
  198. * @param $langcode
  199. * Language code (optional).
  200. * @return \Drupal\Core\Entity\Query\QueryInterface
  201. */
  202. public function exists($field, $langcode = NULL)
  203. {
  204. // TODO: Implement exists() method.
  205. }
  206. /**
  207. * Queries for an empty field.
  208. *
  209. * @param $field
  210. * Name of a field.
  211. * @param $langcode
  212. * Language code (optional).
  213. * @return \Drupal\Core\Entity\Query\QueryInterface
  214. */
  215. public function notExists($field, $langcode = NULL)
  216. {
  217. // TODO: Implement notExists() method.
  218. }
  219. /**
  220. * Enables a pager for the query.
  221. *
  222. * @param $limit
  223. * An integer specifying the number of elements per page. If passed a false
  224. * value (FALSE, 0, NULL), the pager is disabled.
  225. * @param $element
  226. * An optional integer to distinguish between multiple pagers on one page.
  227. * If not provided, one is automatically calculated.
  228. *
  229. * @return \Drupal\Core\Entity\Query\QueryInterface
  230. * The called object.
  231. */
  232. public function pager($limit = 10, $element = NULL)
  233. {
  234. // TODO: Implement pager() method.
  235. }
  236. /**
  237. * @param null $start
  238. * @param null $length
  239. * @return \Drupal\Core\Entity\Query\QueryInterface
  240. * The called object.
  241. */
  242. public function range($start = NULL, $length = NULL)
  243. {
  244. // TODO: Implement range() method.
  245. }
  246. /**
  247. * @param $field
  248. * Name of a field.
  249. * @param string $direction
  250. * @param $langcode
  251. * Language code (optional).
  252. * @return \Drupal\Core\Entity\Query\QueryInterface
  253. * The called object.
  254. */
  255. public function sort($field, $direction = 'ASC', $langcode = NULL)
  256. {
  257. // TODO: Implement sort() method.
  258. }
  259. /**
  260. * Makes this a count query.
  261. *
  262. * For count queries, execute() returns the number entities found.
  263. *
  264. * @return \Drupal\Core\Entity\Query\QueryInterface
  265. * The called object.
  266. */
  267. public function count()
  268. {
  269. // TODO: Implement count() method.
  270. }
  271. /**
  272. * Enables sortable tables for this query.
  273. *
  274. * @param $headers
  275. * An array of headers of the same structure as described in
  276. * template_preprocess_table(). Use a 'specifier' in place of a 'field' to
  277. * specify what to sort on. This can be an entity or a field as described
  278. * in condition().
  279. *
  280. * @return \Drupal\Core\Entity\Query\QueryInterface
  281. * The called object.
  282. */
  283. public function tableSort(&$headers)
  284. {
  285. // TODO: Implement tableSort() method.
  286. }
  287. /**
  288. * @return \Drupal\Core\Entity\Query\QueryInterface
  289. * The called object.
  290. */
  291. public function accessCheck($access_check = TRUE)
  292. {
  293. // TODO: Implement accessCheck() method.
  294. }
  295. /**
  296. * Execute the query.
  297. *
  298. * @return int|array
  299. * Returns an integer for count queries or an array of ids. The values of
  300. * the array are always entity ids. The keys will be revision ids if the
  301. * entity supports revision and entity ids if not.
  302. */
  303. public function execute()
  304. {
  305. // TODO: Implement execute() method.
  306. }
  307. /**
  308. * Creates a new group of conditions ANDed together.
  309. *
  310. * For example, consider a drawing entity type with a 'figures' multi-value
  311. * field containing 'shape' and 'color' columns. To find all drawings
  312. * containing both a red triangle and a blue circle:
  313. * @code
  314. * $query = \Drupal::entityQuery('drawing');
  315. * $group = $query->andConditionGroup()
  316. * ->condition('figures.color', 'red')
  317. * ->condition('figures.shape', 'triangle');
  318. * $query->condition($group);
  319. * $group = $query->andConditionGroup()
  320. * ->condition('figures.color', 'blue')
  321. * ->condition('figures.shape', 'circle');
  322. * $query->condition($group);
  323. * $entity_ids = $query->execute();
  324. * @endcode
  325. *
  326. * @return \Drupal\Core\Entity\Query\ConditionInterface
  327. */
  328. public function andConditionGroup()
  329. {
  330. // TODO: Implement andConditionGroup() method.
  331. }
  332. /**
  333. * Creates a new group of conditions ORed together.
  334. *
  335. * For example, consider a map entity with an 'attributes' field
  336. * containing 'building_type' and 'color' columns. To find all green and
  337. * red bikesheds:
  338. * @code
  339. * $query = \Drupal::entityQuery('map');
  340. * $group = $query->orConditionGroup()
  341. * ->condition('attributes.color', 'red')
  342. * ->condition('attributes.color', 'green');
  343. * $entity_ids = $query
  344. * ->condition('attributes.building_type', 'bikeshed')
  345. * ->condition($group)
  346. * ->execute();
  347. * @endcode
  348. * Note that this particular example can be simplified:
  349. * @code
  350. * $entity_ids = $query
  351. * ->condition('attributes.color', array('red', 'green'))
  352. * ->condition('attributes.building_type', 'bikeshed')
  353. * ->execute();
  354. * @endcode
  355. *
  356. * @return \Drupal\Core\Entity\Query\ConditionInterface
  357. */
  358. public function orConditionGroup()
  359. {
  360. // TODO: Implement orConditionGroup() method.
  361. }
  362. /**
  363. * Queries the current revision.
  364. *
  365. * @return $this
  366. */
  367. public function currentRevision()
  368. {
  369. // TODO: Implement currentRevision() method.
  370. }
  371. /**
  372. * Queries all the revisions.
  373. *
  374. * @return $this
  375. */
  376. public function allRevisions()
  377. {
  378. // TODO: Implement allRevisions() method.
  379. }
  380. }