06fd7f56207ebfd1ca1c676020440102d4f7a6b1
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / QueryInterface.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * This class is a backport of the corresponding class of TYPO3 Flow.
8 * All credits go to the TYPO3 Flow team.
9 * All rights reserved.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the text file GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * A persistence query interface
32 *
33 * @api
34 */
35 interface QueryInterface {
36
37 /**
38 * The '=' comparison operator.
39 *
40 * @api
41 */
42 const OPERATOR_EQUAL_TO = 1;
43
44 /**
45 * The '!=' comparison operator.
46 *
47 * @api
48 */
49 const OPERATOR_NOT_EQUAL_TO = 2;
50
51 /**
52 * The '<' comparison operator.
53 *
54 * @api
55 */
56 const OPERATOR_LESS_THAN = 3;
57
58 /**
59 * The '<=' comparison operator.
60 *
61 * @api
62 */
63 const OPERATOR_LESS_THAN_OR_EQUAL_TO = 4;
64
65 /**
66 * The '>' comparison operator.
67 *
68 * @api
69 */
70 const OPERATOR_GREATER_THAN = 5;
71
72 /**
73 * The '>=' comparison operator.
74 *
75 * @api
76 */
77 const OPERATOR_GREATER_THAN_OR_EQUAL_TO = 6;
78
79 /**
80 * The 'like' comparison operator.
81 *
82 * @api
83 */
84 const OPERATOR_LIKE = 7;
85
86 /**
87 * The 'contains' comparison operator for collections.
88 *
89 * @api
90 */
91 const OPERATOR_CONTAINS = 8;
92
93 /**
94 * The 'in' comparison operator.
95 *
96 * @api
97 */
98 const OPERATOR_IN = 9;
99
100 /**
101 * The 'is NULL' comparison operator.
102 *
103 * @api
104 */
105 const OPERATOR_IS_NULL = 10;
106
107 /**
108 * The 'is empty' comparison operator for collections.
109 *
110 * @api
111 */
112 const OPERATOR_IS_EMPTY = 11;
113
114 /**
115 * Constants representing the direction when ordering result sets.
116 */
117 const ORDER_ASCENDING = 'ASC';
118 const ORDER_DESCENDING = 'DESC';
119
120 /**
121 * Gets the node-tuple source for this query.
122 *
123 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-NULL
124 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
125 */
126 public function getSource();
127
128 /**
129 * Executes the query and returns the result.
130 *
131 * @param $returnRawQueryResult boolean avoids the object mapping by the persistence
132 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $returnRawQueryResult is TRUE
133 * @api
134 */
135 public function execute($returnRawQueryResult = FALSE);
136
137 /**
138 * Sets the property names to order the result by. Expected like this:
139 * array(
140 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
141 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
142 * )
143 *
144 * @param array $orderings The property names to order by
145 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
146 * @api
147 */
148 public function setOrderings(array $orderings);
149
150 /**
151 * Sets the maximum size of the result set to limit. Returns $this to allow
152 * for chaining (fluid interface).
153 *
154 * @param integer $limit
155 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
156 * @api
157 */
158 public function setLimit($limit);
159
160 /**
161 * Sets the start offset of the result set to offset. Returns $this to
162 * allow for chaining (fluid interface).
163 *
164 * @param integer $offset
165 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
166 * @api
167 */
168 public function setOffset($offset);
169
170 /**
171 * The constraint used to limit the result set. Returns $this to allow
172 * for chaining (fluid interface).
173 *
174 * @param object $constraint Some constraint, depending on the backend
175 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
176 * @api
177 */
178 public function matching($constraint);
179
180 /**
181 * Performs a logical conjunction of the two given constraints. The method
182 * takes one or more constraints and concatenates them with a boolean AND.
183 * It also accepts a single array of constraints to be concatenated.
184 *
185 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
186 * @return object
187 * @api
188 */
189 public function logicalAnd($constraint1);
190
191 /**
192 * Performs a logical disjunction of the two given constraints. The method
193 * takes one or more constraints and concatenates them with a boolean OR.
194 * It also accepts a single array of constraints to be concatenated.
195 *
196 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
197 * @return object
198 * @api
199 */
200 public function logicalOr($constraint1);
201
202 /**
203 * Performs a logical negation of the given constraint
204 *
205 * @param object $constraint Constraint to negate
206 * @return object
207 * @api
208 */
209 public function logicalNot($constraint);
210
211 /**
212 * Returns an equals criterion used for matching objects against a query.
213 *
214 * It matches if the $operand equals the value of the property named
215 * $propertyName. If $operand is NULL a strict check for NULL is done. For
216 * strings the comparison can be done with or without case-sensitivity.
217 *
218 * @param string $propertyName The name of the property to compare against
219 * @param mixed $operand The value to compare with
220 * @param boolean $caseSensitive Whether the equality test should be done case-sensitive for strings
221 * @return object
222 * @api
223 */
224 public function equals($propertyName, $operand, $caseSensitive = TRUE);
225
226 /**
227 * Returns a like criterion used for matching objects against a query.
228 * Matches if the property named $propertyName is like the $operand, using
229 * standard SQL wildcards.
230 *
231 * @param string $propertyName The name of the property to compare against
232 * @param string $operand The value to compare with
233 * @param boolean $caseSensitive Whether the matching should be done case-sensitive
234 * @return object
235 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a non-string property
236 * @api
237 */
238 public function like($propertyName, $operand, $caseSensitive = TRUE);
239
240 /**
241 * Returns a "contains" criterion used for matching objects against a query.
242 * It matches if the multivalued property contains the given operand.
243 *
244 * If NULL is given as $operand, there will never be a match!
245 *
246 * @param string $propertyName The name of the multivalued property to compare against
247 * @param mixed $operand The value to compare with
248 * @return object
249 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
250 * @api
251 */
252 public function contains($propertyName, $operand);
253
254 /**
255 * Returns an "in" criterion used for matching objects against a query. It
256 * matches if the property's value is contained in the multivalued operand.
257 *
258 * @param string $propertyName The name of the property to compare against
259 * @param mixed $operand The value to compare with, multivalued
260 * @return object
261 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property
262 * @api
263 */
264 public function in($propertyName, $operand);
265
266 /**
267 * Returns a less than criterion used for matching objects against a query
268 *
269 * @param string $propertyName The name of the property to compare against
270 * @param mixed $operand The value to compare with
271 * @return object
272 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
273 * @api
274 */
275 public function lessThan($propertyName, $operand);
276
277 /**
278 * Returns a less or equal than criterion used for matching objects against a query
279 *
280 * @param string $propertyName The name of the property to compare against
281 * @param mixed $operand The value to compare with
282 * @return object
283 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
284 * @api
285 */
286 public function lessThanOrEqual($propertyName, $operand);
287
288 /**
289 * Returns a greater than criterion used for matching objects against a query
290 *
291 * @param string $propertyName The name of the property to compare against
292 * @param mixed $operand The value to compare with
293 * @return object
294 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
295 * @api
296 */
297 public function greaterThan($propertyName, $operand);
298
299 /**
300 * Returns a greater than or equal criterion used for matching objects against a query
301 *
302 * @param string $propertyName The name of the property to compare against
303 * @param mixed $operand The value to compare with
304 * @return object
305 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
306 * @api
307 */
308 public function greaterThanOrEqual($propertyName, $operand);
309
310 /**
311 * Returns the type this query cares for.
312 *
313 * @return string
314 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
315 * @api
316 */
317 public function getType();
318
319 /**
320 * Sets the Query Settings. These Query settings must match the settings expected by
321 * the specific Storage Backend.
322 *
323 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
324 * @return void
325 * @todo decide whether this can be deprecated somewhen
326 * @api This method is not part of TYPO3Flow API
327 */
328 public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings);
329
330 /**
331 * Returns the Query Settings.
332 *
333 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
334 * @todo decide whether this can be deprecated somewhen
335 * @api This method is not part of TYPO3Flow API
336 */
337 public function getQuerySettings();
338
339 /**
340 * Returns the query result count.
341 *
342 * @return integer The query result count
343 * @api
344 */
345 public function count();
346
347 /**
348 * Gets the property names to order the result by, like this:
349 * array(
350 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
351 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
352 * )
353 *
354 * @return array
355 * @api
356 */
357 public function getOrderings();
358
359 /**
360 * Returns the maximum size of the result set to limit.
361 *
362 * @return integer
363 * @api
364 */
365 public function getLimit();
366
367 /**
368 * Returns the start offset of the result set.
369 *
370 * @return integer
371 * @api
372 */
373 public function getOffset();
374
375 /**
376 * Gets the constraint for this query.
377 *
378 * @return mixed the constraint, or null if none
379 * @api
380 */
381 public function getConstraint();
382
383 /**
384 * Returns an "isEmpty" criterion used for matching objects against a query.
385 * It matches if the multivalued property contains no values or is NULL.
386 *
387 * @param string $propertyName The name of the multivalued property to compare against
388 * @return boolean
389 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
390 * @api
391 */
392 public function isEmpty($propertyName);
393 }