QueryInterface.php 11.5 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
	/**
	 * 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

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
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
125
126
127
	 */
	public function getSource();

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
128
	/**
129
	 * Executes the query and returns the result.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
130
	 *
131
132
	 * @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
133
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
134
	 */
135
	public function execute($returnRawQueryResult = FALSE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
136
137
138
139

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

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

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

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

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

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

	/**
	 * Performs a logical negation of the given constraint
	 *
	 * @param object $constraint Constraint to negate
	 * @return object
207
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
208
209
210
211
	 */
	public function logicalNot($constraint);

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

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

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

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
266
267
268
269
270
271
	/**
	 * 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
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
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
274
275
276
277
278
279
280
281
282
	 */
	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
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
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
285
286
287
288
289
290
291
292
293
	 */
	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
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
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
296
297
298
299
300
301
302
303
304
	 */
	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
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
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
307
308
309
	 */
	public function greaterThanOrEqual($propertyName, $operand);

310
311
312
313
	/**
	 * Returns the type this query cares for.
	 *
	 * @return string
314
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
315
316
317
318
319
320
321
322
	 * @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
	 */
Thomas Maroschik's avatar
Thomas Maroschik committed
328
	public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\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
335
	 * @todo decide whether this can be deprecated somewhen
	 * @api This method is not part of  TYPO3Flow API
336
337
	 */
	public function getQuerySettings();
338

339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
	/**
	 * 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.
	 *
362
	 * @return integer
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
	 * @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
393
}