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!
 */
16

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
17
18
19
/**
 * A persistence query interface
 *
20
 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
21
 */
Helmut Hummel's avatar
Helmut Hummel committed
22
interface QueryInterface {
23

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

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

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

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

52
53
	/**
	 * The '<' comparison operator.
54
	 *
55
	 * @api
56
	 */
57
	const OPERATOR_LESS_THAN = 3;
58

59
60
	/**
	 * The '<=' comparison operator.
61
	 *
62
	 * @api
63
	 */
64
	const OPERATOR_LESS_THAN_OR_EQUAL_TO = 4;
65

66
67
	/**
	 * The '>' comparison operator.
68
	 *
69
	 * @api
70
	 */
71
	const OPERATOR_GREATER_THAN = 5;
72

73
74
	/**
	 * The '>=' comparison operator.
75
	 *
76
	 * @api
77
	 */
78
	const OPERATOR_GREATER_THAN_OR_EQUAL_TO = 6;
79

80
81
	/**
	 * The 'like' comparison operator.
82
	 *
83
	 * @api
84
	 */
85
	const OPERATOR_LIKE = 7;
86

87
	/**
88
	 * The 'contains' comparison operator for collections.
89
	 *
90
	 * @api
91
	 */
92
	const OPERATOR_CONTAINS = 8;
93

94
95
	/**
	 * The 'in' comparison operator.
96
	 *
97
	 * @api
98
	 */
99
	const OPERATOR_IN = 9;
100

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

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

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

121
122
123
	/**
	 * Gets the node-tuple source for this query.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
124
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-NULL
125
126
	 * @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.
127
128
129
	 */
	public function getSource();

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

	/**
	 * Sets the property names to order the result by. Expected like this:
	 * array(
142
143
	 *  '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
144
145
146
	 * )
	 *
	 * @param array $orderings The property names to order by
Thomas Maroschik's avatar
Thomas Maroschik committed
147
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
148
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
149
150
151
152
153
	 */
	public function setOrderings(array $orderings);

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

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

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

	/**
183
184
185
	 * 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
186
	 *
187
	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
188
	 * @return object
189
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
190
	 */
191
	public function logicalAnd($constraint1);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
192
193

	/**
194
195
196
	 * 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
197
	 *
198
	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
199
	 * @return object
200
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
201
	 */
202
	public function logicalOr($constraint1);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
203
204
205
206

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

	/**
214
215
216
217
218
	 * 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
219
220
221
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
222
	 * @param bool $caseSensitive Whether the equality test should be done case-sensitive for strings
223
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
224
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
225
226
227
228
	 */
	public function equals($propertyName, $operand, $caseSensitive = TRUE);

	/**
229
230
231
	 * 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
232
233
	 *
	 * @param string $propertyName The name of the property to compare against
234
	 * @param string $operand The value to compare with
235
	 * @param bool $caseSensitive Whether the matching should be done case-sensitive
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
236
	 * @return object
237
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a non-string property
238
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
239
	 */
240
	public function like($propertyName, $operand, $caseSensitive = TRUE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
241

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

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
268
269
270
271
272
273
	/**
	 * 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
274
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
275
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
276
277
278
279
280
281
282
283
284
	 */
	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
285
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
286
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
287
288
289
290
291
292
293
294
295
	 */
	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
296
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
297
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
298
299
300
301
302
303
304
305
306
	 */
	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
307
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
308
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
309
310
311
	 */
	public function greaterThanOrEqual($propertyName, $operand);

312
313
314
315
316
317
318
319
320
321
322
323
	/**
	 * 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
324
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
325
	 * @return void
326
327
	 * @todo decide whether this can be deprecated somewhen
	 * @api This method is not part of TYPO3Flow API
328
	 */
329
	public function setQuerySettings(Generic\QuerySettingsInterface $querySettings);
330
331
332
333

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

340
341
342
	/**
	 * Returns the query result count.
	 *
343
	 * @return int The query result count
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
	 * @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.
	 *
363
	 * @return int
364
365
366
367
368
369
370
	 * @api
	 */
	public function getLimit();

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

	/**
	 * Gets the constraint for this query.
	 *
379
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface|NULL the constraint, or null if none
380
381
382
383
384
385
386
387
388
	 * @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
389
	 * @return bool
390
391
392
393
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
	 * @api
	 */
	public function isEmpty($propertyName);
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408

	/**
	 * 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
409
}