QueryInterface.php 11.6 KB
Newer Older
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
1
<?php
Thomas Maroschik's avatar
Thomas Maroschik committed
2
3
namespace TYPO3\CMS\Extbase\Persistence;

4
5
/**
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
16
17
18
/**
 * A persistence query interface
 *
19
 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
20
 */
Helmut Hummel's avatar
Helmut Hummel committed
21
interface QueryInterface {
22

23
24
	/**
	 * The '=' comparison operator.
25
	 *
26
	 * @api
27
	 */
28
	const OPERATOR_EQUAL_TO = 1;
29

30
31
32
33
34
35
36
	/**
	 * For NULL we have to use 'IS' instead of '='
	 *
	 * @api
	 */
	const OPERATOR_EQUAL_TO_NULL = 101;

37
38
	/**
	 * The '!=' comparison operator.
39
	 *
40
	 * @api
41
	 */
42
	const OPERATOR_NOT_EQUAL_TO = 2;
43

44
45
46
47
48
49
50
	/**
	 * For NULL we have to use 'IS NOT' instead of '!='
	 *
	 * @api
	 */
	const OPERATOR_NOT_EQUAL_TO_NULL = 202;

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

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
100
	/**
101
	 * The 'is NULL' comparison operator.
102
	 *
103
	 * @api
104
	 */
105
106
	const OPERATOR_IS_NULL = 10;

107
	/**
108
	 * The 'is empty' comparison operator for collections.
109
	 *
110
	 * @api
111
	 */
112
113
	const OPERATOR_IS_EMPTY = 11;

114
	/**
115
	 * Constants representing the direction when ordering result sets.
116
	 */
117
118
119
	const ORDER_ASCENDING = 'ASC';
	const ORDER_DESCENDING = 'DESC';

120
121
122
	/**
	 * Gets the node-tuple source for this query.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
123
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-NULL
124
125
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0. It is deprecated only in the interface to be more
	 * in sync with Flow in future and will stay in Generic Persistence.
126
127
128
	 */
	public function getSource();

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
129
	/**
130
	 * Executes the query and returns the result.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
131
	 *
132
	 * @param bool $returnRawQueryResult avoids the object mapping by the persistence
133
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $returnRawQueryResult is TRUE
134
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
135
	 */
136
	public function execute($returnRawQueryResult = FALSE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
137
138
139
140

	/**
	 * Sets the property names to order the result by. Expected like this:
	 * array(
141
142
	 *  'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
	 *  'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
143
144
145
	 * )
	 *
	 * @param array $orderings The property names to order by
Thomas Maroschik's avatar
Thomas Maroschik committed
146
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
147
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
148
149
150
151
152
	 */
	public function setOrderings(array $orderings);

	/**
	 * Sets the maximum size of the result set to limit. Returns $this to allow
153
	 * for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
154
	 *
155
	 * @param int $limit
Thomas Maroschik's avatar
Thomas Maroschik committed
156
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
157
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
158
159
160
161
162
	 */
	public function setLimit($limit);

	/**
	 * Sets the start offset of the result set to offset. Returns $this to
163
	 * allow for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
164
	 *
165
	 * @param int $offset
Thomas Maroschik's avatar
Thomas Maroschik committed
166
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
167
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
168
169
170
171
172
	 */
	public function setOffset($offset);

	/**
	 * The constraint used to limit the result set. Returns $this to allow
173
	 * for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
174
175
	 *
	 * @param object $constraint Some constraint, depending on the backend
Thomas Maroschik's avatar
Thomas Maroschik committed
176
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
177
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
178
179
180
181
	 */
	public function matching($constraint);

	/**
182
183
184
	 * Performs a logical conjunction of the two given constraints. The method
	 * takes one or more constraints and concatenates them with a boolean AND.
	 * It also accepts a single array of constraints to be concatenated.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
185
	 *
186
	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
187
	 * @return object
188
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
189
	 */
190
	public function logicalAnd($constraint1);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
191
192

	/**
193
194
195
	 * Performs a logical disjunction of the two given constraints. The method
	 * takes one or more constraints and concatenates them with a boolean OR.
	 * It also accepts a single array of constraints to be concatenated.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
196
	 *
197
	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
198
	 * @return object
199
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
200
	 */
201
	public function logicalOr($constraint1);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
202
203
204
205

	/**
	 * Performs a logical negation of the given constraint
	 *
206
207
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint Constraint to negate
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
208
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
209
	 */
210
	public function logicalNot(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
211
212

	/**
213
214
215
216
217
	 * Returns an equals criterion used for matching objects against a query.
	 *
	 * It matches if the $operand equals the value of the property named
	 * $propertyName. If $operand is NULL a strict check for NULL is done. For
	 * strings the comparison can be done with or without case-sensitivity.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
218
219
220
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
221
	 * @param bool $caseSensitive Whether the equality test should be done case-sensitive for strings
222
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
223
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
224
225
226
227
	 */
	public function equals($propertyName, $operand, $caseSensitive = TRUE);

	/**
228
229
230
	 * Returns a like criterion used for matching objects against a query.
	 * Matches if the property named $propertyName is like the $operand, using
	 * standard SQL wildcards.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
231
232
	 *
	 * @param string $propertyName The name of the property to compare against
233
	 * @param string $operand The value to compare with
234
	 * @param bool $caseSensitive Whether the matching should be done case-sensitive
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
235
	 * @return object
236
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a non-string property
237
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
238
	 */
239
	public function like($propertyName, $operand, $caseSensitive = TRUE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
240

241
242
243
244
	/**
	 * Returns a "contains" criterion used for matching objects against a query.
	 * It matches if the multivalued property contains the given operand.
	 *
245
246
247
	 * If NULL is given as $operand, there will never be a match!
	 *
	 * @param string $propertyName The name of the multivalued property to compare against
248
249
	 * @param mixed $operand The value to compare with
	 * @return object
250
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
251
252
253
254
255
256
257
258
259
260
261
	 * @api
	 */
	public function contains($propertyName, $operand);

	/**
	 * Returns an "in" criterion used for matching objects against a query. It
	 * matches if the property's value is contained in the multivalued operand.
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with, multivalued
	 * @return object
262
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property
263
264
265
266
	 * @api
	 */
	public function in($propertyName, $operand);

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
267
268
269
270
271
272
	/**
	 * Returns a less than criterion used for matching objects against a query
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
	 * @return object
273
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
274
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
275
276
277
278
279
280
281
282
283
	 */
	public function lessThan($propertyName, $operand);

	/**
	 * Returns a less or equal than criterion used for matching objects against a query
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
	 * @return object
284
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
285
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
286
287
288
289
290
291
292
293
294
	 */
	public function lessThanOrEqual($propertyName, $operand);

	/**
	 * Returns a greater than criterion used for matching objects against a query
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
	 * @return object
295
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
296
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
297
298
299
300
301
302
303
304
305
	 */
	public function greaterThan($propertyName, $operand);

	/**
	 * Returns a greater than or equal criterion used for matching objects against a query
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
	 * @return object
306
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
307
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
308
309
310
	 */
	public function greaterThanOrEqual($propertyName, $operand);

311
312
313
314
315
316
317
318
319
320
321
322
	/**
	 * Returns the type this query cares for.
	 *
	 * @return string
	 * @api
	 */
	public function getType();

	/**
	 * Sets the Query Settings. These Query settings must match the settings expected by
	 * the specific Storage Backend.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
323
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
324
	 * @return void
325
326
	 * @todo decide whether this can be deprecated somewhen
	 * @api This method is not part of TYPO3Flow API
327
	 */
328
	public function setQuerySettings(Generic\QuerySettingsInterface $querySettings);
329
330
331
332

	/**
	 * Returns the Query Settings.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
333
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
334
	 * @todo decide whether this can be deprecated eventually
335
	 * @api This method is not part of  TYPO3Flow API
336
337
	 */
	public function getQuerySettings();
338

339
340
341
	/**
	 * Returns the query result count.
	 *
342
	 * @return int The query result count
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
	 * @api
	 */
	public function count();

	/**
	 * Gets the property names to order the result by, like this:
	 * array(
	 *  'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
	 *  'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
	 * )
	 *
	 * @return array
	 * @api
	 */
	public function getOrderings();

	/**
	 * Returns the maximum size of the result set to limit.
	 *
362
	 * @return int
363
364
365
366
367
368
369
	 * @api
	 */
	public function getLimit();

	/**
	 * Returns the start offset of the result set.
	 *
370
	 * @return int
371
372
373
374
375
376
377
	 * @api
	 */
	public function getOffset();

	/**
	 * Gets the constraint for this query.
	 *
378
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface|NULL the constraint, or null if none
379
380
381
382
383
384
385
386
387
	 * @api
	 */
	public function getConstraint();

	/**
	 * Returns an "isEmpty" criterion used for matching objects against a query.
	 * It matches if the multivalued property contains no values or is NULL.
	 *
	 * @param string $propertyName The name of the multivalued property to compare against
388
	 * @return bool
389
390
391
392
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
	 * @api
	 */
	public function isEmpty($propertyName);
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407

	/**
	 * Sets the source to fetch the result from
	 *
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
	 */
	public function setSource(Generic\Qom\SourceInterface $source);

	/**
	 * Returns the statement of this query.
	 *
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
	 */
	public function getStatement();

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
408
}