QueryInterface.php 11.1 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
/*                                                                        *
 * This script belongs to the Extbase framework.                          *
 *                                                                        *
 * This class is a backport of the corresponding class of FLOW3.          *
 * All credits go to the v5 team.                                         *
 *                                                                        *
 * It is free software; you can redistribute it and/or modify it under    *
 * the terms of the GNU Lesser General Public License, either version 3   *
 * of the License, or (at your option) any later version.                 *
 *                                                                        *
 * The TYPO3 project - inspiring people to share!                         *
 *                                                                        */
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
16
17
18
/**
 * A persistence query interface
 *
19
 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
20
 */
Helmut Hummel's avatar
Helmut Hummel committed
21
interface QueryInterface {
22

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

29
30
31
	/**
	 * The '!=' comparison operator.
	 * @api
32
	 */
33
	const OPERATOR_NOT_EQUAL_TO = 2;
34

35
36
37
	/**
	 * The '<' comparison operator.
	 * @api
38
	 */
39
	const OPERATOR_LESS_THAN = 3;
40

41
42
43
	/**
	 * The '<=' comparison operator.
	 * @api
44
	 */
45
	const OPERATOR_LESS_THAN_OR_EQUAL_TO = 4;
46

47
48
49
	/**
	 * The '>' comparison operator.
	 * @api
50
	 */
51
	const OPERATOR_GREATER_THAN = 5;
52

53
54
55
	/**
	 * The '>=' comparison operator.
	 * @api
56
	 */
57
	const OPERATOR_GREATER_THAN_OR_EQUAL_TO = 6;
58

59
60
61
	/**
	 * The 'like' comparison operator.
	 * @api
62
	 */
63
	const OPERATOR_LIKE = 7;
64

65
	/**
66
	 * The 'contains' comparison operator for collections.
67
	 * @api
68
	 */
69
	const OPERATOR_CONTAINS = 8;
70

71
72
73
	/**
	 * The 'in' comparison operator.
	 * @api
74
	 */
75
	const OPERATOR_IN = 9;
76

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
77
	/**
78
79
	 * The 'is NULL' comparison operator.
	 * @api
80
	 */
81
82
	const OPERATOR_IS_NULL = 10;

83
	/**
84
85
	 * The 'is empty' comparison operator for collections.
	 * @api
86
	 */
87
88
	const OPERATOR_IS_EMPTY = 11;

89
	/**
90
	 * Constants representing the direction when ordering result sets.
91
	 */
92
93
94
	const ORDER_ASCENDING = 'ASC';
	const ORDER_DESCENDING = 'DESC';

95
96
97
	/**
	 * Gets the node-tuple source for this query.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
98
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-NULL
99
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
100
101
102
	 */
	public function getSource();

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
103
	/**
104
	 * Executes the query and returns the result.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
105
	 *
106
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE
107
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
108
109
110
111
112
113
	 */
	public function execute();

	/**
	 * Sets the property names to order the result by. Expected like this:
	 * array(
114
115
	 *  '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
116
117
118
	 * )
	 *
	 * @param array $orderings The property names to order by
Thomas Maroschik's avatar
Thomas Maroschik committed
119
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
120
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
121
122
123
124
125
	 */
	public function setOrderings(array $orderings);

	/**
	 * Sets the maximum size of the result set to limit. Returns $this to allow
126
	 * for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
127
128
	 *
	 * @param integer $limit
Thomas Maroschik's avatar
Thomas Maroschik committed
129
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
130
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
131
132
133
134
135
	 */
	public function setLimit($limit);

	/**
	 * Sets the start offset of the result set to offset. Returns $this to
136
	 * allow for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
137
138
	 *
	 * @param integer $offset
Thomas Maroschik's avatar
Thomas Maroschik committed
139
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
140
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
141
142
143
144
145
	 */
	public function setOffset($offset);

	/**
	 * The constraint used to limit the result set. Returns $this to allow
146
	 * for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
147
148
	 *
	 * @param object $constraint Some constraint, depending on the backend
Thomas Maroschik's avatar
Thomas Maroschik committed
149
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
150
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
151
152
153
154
	 */
	public function matching($constraint);

	/**
155
156
157
	 * 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
158
	 *
159
	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
160
	 * @return object
161
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
162
	 */
163
	public function logicalAnd($constraint1);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
164
165

	/**
166
167
168
	 * 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
169
	 *
170
	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
171
	 * @return object
172
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
173
	 */
174
	public function logicalOr($constraint1);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
175
176
177
178
179
180

	/**
	 * Performs a logical negation of the given constraint
	 *
	 * @param object $constraint Constraint to negate
	 * @return object
181
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
182
183
184
185
	 */
	public function logicalNot($constraint);

	/**
186
187
188
189
190
	 * 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
191
192
193
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
194
	 * @param boolean $caseSensitive Whether the equality test should be done case-sensitive for strings
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
195
	 * @return object
196
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
197
198
199
200
	 */
	public function equals($propertyName, $operand, $caseSensitive = TRUE);

	/**
201
202
203
	 * 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
204
205
	 *
	 * @param string $propertyName The name of the property to compare against
206
207
	 * @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
208
	 * @return object
209
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a non-string property
210
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
211
	 */
212
	public function like($propertyName, $operand, $caseSensitive = TRUE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
213

214
215
216
217
	/**
	 * Returns a "contains" criterion used for matching objects against a query.
	 * It matches if the multivalued property contains the given operand.
	 *
218
219
220
	 * If NULL is given as $operand, there will never be a match!
	 *
	 * @param string $propertyName The name of the multivalued property to compare against
221
222
	 * @param mixed $operand The value to compare with
	 * @return object
223
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
224
225
226
227
228
229
230
231
232
233
234
	 * @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
235
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property
236
237
238
239
	 * @api
	 */
	public function in($propertyName, $operand);

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
240
241
242
243
244
245
	/**
	 * 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
246
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
247
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
248
249
250
251
252
253
254
255
256
	 */
	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
257
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
258
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
259
260
261
262
263
264
265
266
267
	 */
	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
268
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
269
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
270
271
272
273
274
275
276
277
278
	 */
	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
279
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
280
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
281
282
283
	 */
	public function greaterThanOrEqual($propertyName, $operand);

284
285
286
287
	/**
	 * Returns the type this query cares for.
	 *
	 * @return string
288
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
289
290
291
292
293
294
295
296
	 * @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
297
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
298
	 * @return void
299
300
	 * @todo decide whether this can be deprecated somewhen
	 * @api This method is not part of TYPO3Flow API
301
	 */
Thomas Maroschik's avatar
Thomas Maroschik committed
302
	public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings);
303
304
305
306

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

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
	/**
	 * 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.
	 *
	 * @param integer
	 * @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
367
}
Thomas Maroschik's avatar
Thomas Maroschik committed
368

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
369
?>