QueryInterface.php 11.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
19
20
21
22
23
24
25
26
27
28
29
/***************************************************************
 *  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.
 *  A copy is found in the textfile GPL.txt and important notices to the license
 *  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
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE
132
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
133
134
135
136
137
138
	 */
	public function execute();

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

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

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

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

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

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

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

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

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

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

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

309
310
311
312
	/**
	 * Returns the type this query cares for.
	 *
	 * @return string
313
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
314
315
316
317
318
319
320
321
	 * @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
322
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
323
	 * @return void
324
325
	 * @todo decide whether this can be deprecated somewhen
	 * @api This method is not part of TYPO3Flow API
326
	 */
Thomas Maroschik's avatar
Thomas Maroschik committed
327
	public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings);
328
329
330
331

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

338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
	/**
	 * 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.
	 *
361
	 * @return integer
362
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
	 * @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
392
}