QueryInterface.php 12.4 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
6
7
8
9
10
11
12
13
14
15
16
17
18
/***************************************************************
 *  Copyright notice
 *
 *  This class is a backport of the corresponding class of TYPO3 Flow.
 *  All credits go to the TYPO3 Flow team.
 *  All rights reserved.
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  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
21
22
23
24
25
26
27
28
29
 *  from the author is found in LICENSE.txt distributed with these scripts.
 *
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
30
31
32
/**
 * A persistence query interface
 *
33
 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
34
 */
Helmut Hummel's avatar
Helmut Hummel committed
35
interface QueryInterface {
36

37
38
	/**
	 * The '=' comparison operator.
39
	 *
40
	 * @api
41
	 */
42
	const OPERATOR_EQUAL_TO = 1;
43

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

51
52
	/**
	 * The '!=' comparison operator.
53
	 *
54
	 * @api
55
	 */
56
	const OPERATOR_NOT_EQUAL_TO = 2;
57

58
59
60
61
62
63
64
	/**
	 * For NULL we have to use 'IS NOT' instead of '!='
	 *
	 * @api
	 */
	const OPERATOR_NOT_EQUAL_TO_NULL = 202;

65
66
	/**
	 * The '<' comparison operator.
67
	 *
68
	 * @api
69
	 */
70
	const OPERATOR_LESS_THAN = 3;
71

72
73
	/**
	 * The '<=' comparison operator.
74
	 *
75
	 * @api
76
	 */
77
	const OPERATOR_LESS_THAN_OR_EQUAL_TO = 4;
78

79
80
	/**
	 * The '>' comparison operator.
81
	 *
82
	 * @api
83
	 */
84
	const OPERATOR_GREATER_THAN = 5;
85

86
87
	/**
	 * The '>=' comparison operator.
88
	 *
89
	 * @api
90
	 */
91
	const OPERATOR_GREATER_THAN_OR_EQUAL_TO = 6;
92

93
94
	/**
	 * The 'like' comparison operator.
95
	 *
96
	 * @api
97
	 */
98
	const OPERATOR_LIKE = 7;
99

100
	/**
101
	 * The 'contains' comparison operator for collections.
102
	 *
103
	 * @api
104
	 */
105
	const OPERATOR_CONTAINS = 8;
106

107
108
	/**
	 * The 'in' comparison operator.
109
	 *
110
	 * @api
111
	 */
112
	const OPERATOR_IN = 9;
113

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
114
	/**
115
	 * The 'is NULL' comparison operator.
116
	 *
117
	 * @api
118
	 */
119
120
	const OPERATOR_IS_NULL = 10;

121
	/**
122
	 * The 'is empty' comparison operator for collections.
123
	 *
124
	 * @api
125
	 */
126
127
	const OPERATOR_IS_EMPTY = 11;

128
	/**
129
	 * Constants representing the direction when ordering result sets.
130
	 */
131
132
133
	const ORDER_ASCENDING = 'ASC';
	const ORDER_DESCENDING = 'DESC';

134
135
136
	/**
	 * Gets the node-tuple source for this query.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
137
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-NULL
138
139
	 * @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.
140
141
142
	 */
	public function getSource();

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
143
	/**
144
	 * Executes the query and returns the result.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
145
	 *
146
147
	 * @param $returnRawQueryResult boolean avoids the object mapping by the persistence
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $returnRawQueryResult is TRUE
148
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
149
	 */
150
	public function execute($returnRawQueryResult = FALSE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
151
152
153
154

	/**
	 * Sets the property names to order the result by. Expected like this:
	 * array(
155
156
	 *  '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
157
158
159
	 * )
	 *
	 * @param array $orderings The property names to order by
Thomas Maroschik's avatar
Thomas Maroschik committed
160
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
161
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
162
163
164
165
166
	 */
	public function setOrderings(array $orderings);

	/**
	 * Sets the maximum size of the result set to limit. Returns $this to allow
167
	 * for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
168
169
	 *
	 * @param integer $limit
Thomas Maroschik's avatar
Thomas Maroschik committed
170
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
171
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
172
173
174
175
176
	 */
	public function setLimit($limit);

	/**
	 * Sets the start offset of the result set to offset. Returns $this to
177
	 * allow for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
178
179
	 *
	 * @param integer $offset
Thomas Maroschik's avatar
Thomas Maroschik committed
180
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
181
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
182
183
184
185
186
	 */
	public function setOffset($offset);

	/**
	 * The constraint used to limit the result set. Returns $this to allow
187
	 * for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
188
189
	 *
	 * @param object $constraint Some constraint, depending on the backend
Thomas Maroschik's avatar
Thomas Maroschik committed
190
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
191
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
192
193
194
195
	 */
	public function matching($constraint);

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

	/**
207
208
209
	 * 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
210
	 *
211
	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
212
	 * @return object
213
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
214
	 */
215
	public function logicalOr($constraint1);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
216
217
218
219

	/**
	 * Performs a logical negation of the given constraint
	 *
220
221
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint Constraint to negate
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
222
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
223
	 */
224
	public function logicalNot(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
225
226

	/**
227
228
229
230
231
	 * 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
232
233
234
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
235
	 * @param boolean $caseSensitive Whether the equality test should be done case-sensitive for strings
236
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
237
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
238
239
240
241
	 */
	public function equals($propertyName, $operand, $caseSensitive = TRUE);

	/**
242
243
244
	 * 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
245
246
	 *
	 * @param string $propertyName The name of the property to compare against
247
248
	 * @param string $operand The value to compare with
	 * @param boolean $caseSensitive Whether the matching should be done case-sensitive
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
249
	 * @return object
250
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a non-string property
251
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
252
	 */
253
	public function like($propertyName, $operand, $caseSensitive = TRUE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
254

255
256
257
258
	/**
	 * Returns a "contains" criterion used for matching objects against a query.
	 * It matches if the multivalued property contains the given operand.
	 *
259
260
261
	 * If NULL is given as $operand, there will never be a match!
	 *
	 * @param string $propertyName The name of the multivalued property to compare against
262
263
	 * @param mixed $operand The value to compare with
	 * @return object
264
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
265
266
267
268
269
270
271
272
273
274
275
	 * @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
276
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property
277
278
279
280
	 * @api
	 */
	public function in($propertyName, $operand);

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
281
282
283
284
285
286
	/**
	 * 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
287
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
288
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
289
290
291
292
293
294
295
296
297
	 */
	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
298
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
299
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
300
301
302
303
304
305
306
307
308
	 */
	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
309
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
310
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
311
312
313
314
315
316
317
318
319
	 */
	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
320
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
321
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
322
323
324
	 */
	public function greaterThanOrEqual($propertyName, $operand);

325
326
327
328
329
330
331
332
333
334
335
336
	/**
	 * 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
337
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
338
	 * @return void
339
340
	 * @todo decide whether this can be deprecated somewhen
	 * @api This method is not part of TYPO3Flow API
341
	 */
342
	public function setQuerySettings(Generic\QuerySettingsInterface $querySettings);
343
344
345
346

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

353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
	/**
	 * Returns the query result count.
	 *
	 * @return integer The query result count
	 * @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.
	 *
376
	 * @return integer
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
	 * @api
	 */
	public function getLimit();

	/**
	 * Returns the start offset of the result set.
	 *
	 * @return integer
	 * @api
	 */
	public function getOffset();

	/**
	 * Gets the constraint for this query.
	 *
392
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface|NULL the constraint, or null if none
393
394
395
396
397
398
399
400
401
402
403
404
405
406
	 * @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
	 * @return boolean
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
	 * @api
	 */
	public function isEmpty($propertyName);
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421

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