QueryInterface.php 11.7 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
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
139
140
141
	 */
	public function getSource();

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
142
	/**
143
	 * Executes the query and returns the result.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
144
	 *
145
146
	 * @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
147
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
148
	 */
149
	public function execute($returnRawQueryResult = FALSE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
150
151
152
153

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

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

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

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

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

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

	/**
	 * Performs a logical negation of the given constraint
	 *
	 * @param object $constraint Constraint to negate
	 * @return object
221
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
222
223
224
225
	 */
	public function logicalNot($constraint);

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

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

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

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

324
325
326
327
	/**
	 * Returns the type this query cares for.
	 *
	 * @return string
328
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
329
330
331
332
333
334
335
336
	 * @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
	 */
Thomas Maroschik's avatar
Thomas Maroschik committed
342
	public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\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
349
	 * @todo decide whether this can be deprecated somewhen
	 * @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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
	 * @api
	 */
	public function getLimit();

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

	/**
	 * Gets the constraint for this query.
	 *
	 * @return mixed the constraint, or null if none
	 * @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);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
407
}