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
39
	/**
	 * The '=' comparison operator.
	 * @api
40
	 */
41
	const OPERATOR_EQUAL_TO = 1;
42

43
44
45
	/**
	 * The '!=' comparison operator.
	 * @api
46
	 */
47
	const OPERATOR_NOT_EQUAL_TO = 2;
48

49
50
51
	/**
	 * The '<' comparison operator.
	 * @api
52
	 */
53
	const OPERATOR_LESS_THAN = 3;
54

55
56
57
	/**
	 * The '<=' comparison operator.
	 * @api
58
	 */
59
	const OPERATOR_LESS_THAN_OR_EQUAL_TO = 4;
60

61
62
63
	/**
	 * The '>' comparison operator.
	 * @api
64
	 */
65
	const OPERATOR_GREATER_THAN = 5;
66

67
68
69
	/**
	 * The '>=' comparison operator.
	 * @api
70
	 */
71
	const OPERATOR_GREATER_THAN_OR_EQUAL_TO = 6;
72

73
74
75
	/**
	 * The 'like' comparison operator.
	 * @api
76
	 */
77
	const OPERATOR_LIKE = 7;
78

79
	/**
80
	 * The 'contains' comparison operator for collections.
81
	 * @api
82
	 */
83
	const OPERATOR_CONTAINS = 8;
84

85
86
87
	/**
	 * The 'in' comparison operator.
	 * @api
88
	 */
89
	const OPERATOR_IN = 9;
90

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
91
	/**
92
93
	 * The 'is NULL' comparison operator.
	 * @api
94
	 */
95
96
	const OPERATOR_IS_NULL = 10;

97
	/**
98
99
	 * The 'is empty' comparison operator for collections.
	 * @api
100
	 */
101
102
	const OPERATOR_IS_EMPTY = 11;

103
	/**
104
	 * Constants representing the direction when ordering result sets.
105
	 */
106
107
108
	const ORDER_ASCENDING = 'ASC';
	const ORDER_DESCENDING = 'DESC';

109
110
111
	/**
	 * Gets the node-tuple source for this query.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
112
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-NULL
113
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
114
115
116
	 */
	public function getSource();

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
117
	/**
118
	 * Executes the query and returns the result.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
119
	 *
120
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE
121
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
122
123
124
125
126
127
	 */
	public function execute();

	/**
	 * Sets the property names to order the result by. Expected like this:
	 * array(
128
129
	 *  '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
130
131
132
	 * )
	 *
	 * @param array $orderings The property names to order by
Thomas Maroschik's avatar
Thomas Maroschik committed
133
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
134
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
135
136
137
138
139
	 */
	public function setOrderings(array $orderings);

	/**
	 * Sets the maximum size of the result set to limit. Returns $this to allow
140
	 * for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
141
142
	 *
	 * @param integer $limit
Thomas Maroschik's avatar
Thomas Maroschik committed
143
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
144
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
145
146
147
148
149
	 */
	public function setLimit($limit);

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

	/**
	 * The constraint used to limit the result set. Returns $this to allow
160
	 * for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
161
162
	 *
	 * @param object $constraint Some constraint, depending on the backend
Thomas Maroschik's avatar
Thomas Maroschik committed
163
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
164
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
165
166
167
168
	 */
	public function matching($constraint);

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

	/**
180
181
182
	 * 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
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 logicalOr($constraint1);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
189
190
191
192
193
194

	/**
	 * Performs a logical negation of the given constraint
	 *
	 * @param object $constraint Constraint to negate
	 * @return object
195
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
196
197
198
199
	 */
	public function logicalNot($constraint);

	/**
200
201
202
203
204
	 * 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
205
206
207
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
208
	 * @param boolean $caseSensitive Whether the equality test should be done case-sensitive for strings
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
209
	 * @return object
210
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
211
212
213
214
	 */
	public function equals($propertyName, $operand, $caseSensitive = TRUE);

	/**
215
216
217
	 * 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
218
219
	 *
	 * @param string $propertyName The name of the property to compare against
220
221
	 * @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
222
	 * @return object
223
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a non-string property
224
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
225
	 */
226
	public function like($propertyName, $operand, $caseSensitive = TRUE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
227

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

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
254
255
256
257
258
259
	/**
	 * 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
260
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
261
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
262
263
264
265
266
267
268
269
270
	 */
	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
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 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
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 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
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
	 */
	public function greaterThanOrEqual($propertyName, $operand);

298
299
300
301
	/**
	 * Returns the type this query cares for.
	 *
	 * @return string
302
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
303
304
305
306
307
308
309
310
	 * @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
311
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
312
	 * @return void
313
314
	 * @todo decide whether this can be deprecated somewhen
	 * @api This method is not part of TYPO3Flow API
315
	 */
Thomas Maroschik's avatar
Thomas Maroschik committed
316
	public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings);
317
318
319
320

	/**
	 * Returns the Query Settings.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
321
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
322
323
	 * @todo decide whether this can be deprecated somewhen
	 * @api This method is not part of  TYPO3Flow API
324
325
	 */
	public function getQuerySettings();
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
	/**
	 * 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
381
}
Thomas Maroschik's avatar
Thomas Maroschik committed
382

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