Completed
Push — master ( 993d95...ff08ba )
by Fabien
03:43
created
Classes/Persistence/PagerObjectFactory.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -23,48 +23,48 @@
 block discarded – undo
23 23
 class PagerObjectFactory implements SingletonInterface
24 24
 {
25 25
 
26
-    /**
27
-     * Gets a singleton instance of this class.
28
-     *
29
-     * @return \Fab\Vidi\Persistence\PagerObjectFactory
30
-     */
31
-    static public function getInstance()
32
-    {
33
-        return GeneralUtility::makeInstance('Fab\Vidi\Persistence\PagerObjectFactory');
34
-    }
26
+	/**
27
+	 * Gets a singleton instance of this class.
28
+	 *
29
+	 * @return \Fab\Vidi\Persistence\PagerObjectFactory
30
+	 */
31
+	static public function getInstance()
32
+	{
33
+		return GeneralUtility::makeInstance('Fab\Vidi\Persistence\PagerObjectFactory');
34
+	}
35 35
 
36
-    /**
37
-     * Returns a pager object.
38
-     *
39
-     * @return \Fab\Vidi\Persistence\Pager
40
-     */
41
-    public function getPager()
42
-    {
36
+	/**
37
+	 * Returns a pager object.
38
+	 *
39
+	 * @return \Fab\Vidi\Persistence\Pager
40
+	 */
41
+	public function getPager()
42
+	{
43 43
 
44
-        /** @var $pager \Fab\Vidi\Persistence\Pager */
45
-        $pager = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Pager');
44
+		/** @var $pager \Fab\Vidi\Persistence\Pager */
45
+		$pager = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Pager');
46 46
 
47
-        // Set items per page
48
-        if (GeneralUtility::_GET('length') !== NULL) {
49
-            $limit = (int)GeneralUtility::_GET('length');
50
-            $pager->setLimit($limit);
51
-        }
47
+		// Set items per page
48
+		if (GeneralUtility::_GET('length') !== NULL) {
49
+			$limit = (int)GeneralUtility::_GET('length');
50
+			$pager->setLimit($limit);
51
+		}
52 52
 
53
-        // Set offset
54
-        $offset = 0;
55
-        if (GeneralUtility::_GET('start') !== NULL) {
56
-            $offset = (int)GeneralUtility::_GET('start');
57
-        }
58
-        $pager->setOffset($offset);
53
+		// Set offset
54
+		$offset = 0;
55
+		if (GeneralUtility::_GET('start') !== NULL) {
56
+			$offset = (int)GeneralUtility::_GET('start');
57
+		}
58
+		$pager->setOffset($offset);
59 59
 
60
-        // set page
61
-        $page = 1;
62
-        if ($pager->getLimit() > 0) {
63
-            $page = round($pager->getOffset() / $pager->getLimit());
64
-        }
65
-        $pager->setPage($page);
60
+		// set page
61
+		$page = 1;
62
+		if ($pager->getLimit() > 0) {
63
+			$page = round($pager->getOffset() / $pager->getLimit());
64
+		}
65
+		$pager->setPage($page);
66 66
 
67
-        return $pager;
68
-    }
67
+		return $pager;
68
+	}
69 69
 
70 70
 }
Please login to merge, or discard this patch.
Classes/Persistence/ResultSetStorage.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -22,32 +22,32 @@
 block discarded – undo
22 22
 class ResultSetStorage implements SingletonInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    protected $resultSets = array();
25
+	/**
26
+	 * @var array
27
+	 */
28
+	protected $resultSets = array();
29 29
 
30
-    /**
31
-     * @param string $querySignature
32
-     * @return array
33
-     */
34
-    public function get($querySignature)
35
-    {
36
-        $resultSet = NULL;
37
-        if (isset($this->resultSets[$querySignature])) {
38
-            $resultSet = $this->resultSets[$querySignature];
39
-        }
40
-        return $resultSet;
41
-    }
30
+	/**
31
+	 * @param string $querySignature
32
+	 * @return array
33
+	 */
34
+	public function get($querySignature)
35
+	{
36
+		$resultSet = NULL;
37
+		if (isset($this->resultSets[$querySignature])) {
38
+			$resultSet = $this->resultSets[$querySignature];
39
+		}
40
+		return $resultSet;
41
+	}
42 42
 
43
-    /**
44
-     * @param $querySignature
45
-     * @param array $resultSet
46
-     * @internal param array $resultSets
47
-     */
48
-    public function set($querySignature, array $resultSet)
49
-    {
50
-        $this->resultSets[$querySignature] = $resultSet;
51
-    }
43
+	/**
44
+	 * @param $querySignature
45
+	 * @param array $resultSet
46
+	 * @internal param array $resultSets
47
+	 */
48
+	public function set($querySignature, array $resultSet)
49
+	{
50
+		$this->resultSets[$querySignature] = $resultSet;
51
+	}
52 52
 
53 53
 }
Please login to merge, or discard this patch.
Classes/Persistence/Storage/VidiDbBackend.php 1 patch
Indentation   +1207 added lines, -1207 removed lines patch added patch discarded remove patch
@@ -38,1211 +38,1211 @@
 block discarded – undo
38 38
 class VidiDbBackend
39 39
 {
40 40
 
41
-    const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull';
42
-    const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull';
43
-
44
-    /**
45
-     * The TYPO3 database object
46
-     *
47
-     * @var \TYPO3\CMS\Core\Database\DatabaseConnection
48
-     */
49
-    protected $databaseHandle;
50
-
51
-    /**
52
-     * The TYPO3 page repository. Used for language and workspace overlay
53
-     *
54
-     * @var PageRepository
55
-     */
56
-    protected $pageRepository;
57
-
58
-    /**
59
-     * A first-level TypoScript configuration cache
60
-     *
61
-     * @var array
62
-     */
63
-    protected $pageTSConfigCache = array();
64
-
65
-    /**
66
-     * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
67
-     * @inject
68
-     */
69
-    protected $configurationManager;
70
-
71
-    /**
72
-     * @var \TYPO3\CMS\Extbase\Service\CacheService
73
-     * @inject
74
-     */
75
-    protected $cacheService;
76
-
77
-    /**
78
-     * @var \TYPO3\CMS\Core\Cache\CacheManager
79
-     * @inject
80
-     */
81
-    protected $cacheManager;
82
-
83
-    /**
84
-     * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
85
-     */
86
-    protected $tableColumnCache;
87
-
88
-    /**
89
-     * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
90
-     * @inject
91
-     */
92
-    protected $environmentService;
93
-
94
-    /**
95
-     * @var \Fab\Vidi\Persistence\Query
96
-     */
97
-    protected $query;
98
-
99
-    /**
100
-     * Store some info related to table name and its aliases.
101
-     *
102
-     * @var array
103
-     */
104
-    protected $tableNameAliases = array(
105
-        'aliases' => array(),
106
-        'aliasIncrement' => array(),
107
-    );
108
-
109
-    /**
110
-     * Use to store the current foreign table name alias.
111
-     *
112
-     * @var string
113
-     */
114
-    protected $currentChildTableNameAlias = '';
115
-
116
-    /**
117
-     * The default object type being returned.
118
-     *
119
-     * @var string
120
-     */
121
-    protected $objectType = 'Fab\Vidi\Domain\Model\Content';
122
-
123
-    /**
124
-     * Constructor. takes the database handle from $GLOBALS['TYPO3_DB']
125
-     */
126
-    public function __construct(QueryInterface $query)
127
-    {
128
-        $this->query = $query;
129
-        $this->databaseHandle = $GLOBALS['TYPO3_DB'];
130
-    }
131
-
132
-    /**
133
-     * Lifecycle method
134
-     *
135
-     * @return void
136
-     */
137
-    public function initializeObject()
138
-    {
139
-        $this->tableColumnCache = $this->cacheManager->getCache('extbase_typo3dbbackend_tablecolumns');
140
-    }
141
-
142
-    /**
143
-     * @param array $identifier
144
-     * @return string
145
-     */
146
-    protected function parseIdentifier(array $identifier)
147
-    {
148
-        $fieldNames = array_keys($identifier);
149
-        $suffixedFieldNames = array();
150
-        foreach ($fieldNames as $fieldName) {
151
-            $suffixedFieldNames[] = $fieldName . '=?';
152
-        }
153
-        return implode(' AND ', $suffixedFieldNames);
154
-    }
155
-
156
-    /**
157
-     * Returns the result of the query
158
-     */
159
-    public function fetchResult()
160
-    {
161
-
162
-        $parameters = array();
163
-        $statementParts = $this->parseQuery($this->query, $parameters);
164
-        $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that.
165
-
166
-        $sql = $this->buildQuery($statementParts);
167
-        $tableName = '';
168
-        if (is_array($statementParts) && !empty($statementParts['tables'][0])) {
169
-            $tableName = $statementParts['tables'][0];
170
-        }
171
-        $this->replacePlaceholders($sql, $parameters, $tableName);
172
-        #print $sql; exit(); // @debug
173
-
174
-        $result = $this->databaseHandle->sql_query($sql);
175
-        $this->checkSqlErrors($sql);
176
-        $rows = $this->getRowsFromResult($result);
177
-        $this->databaseHandle->sql_free_result($result);
178
-
179
-        return $rows;
180
-    }
181
-
182
-    /**
183
-     * Returns the number of tuples matching the query.
184
-     *
185
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException
186
-     * @return int The number of matching tuples
187
-     */
188
-    public function countResult()
189
-    {
190
-
191
-        $parameters = array();
192
-        $statementParts = $this->parseQuery($this->query, $parameters);
193
-        $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that.
194
-        // Reset $statementParts for valid table return
195
-        reset($statementParts);
196
-
197
-        // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints
198
-        if (!empty($statementParts['limit'])) {
199
-            $statement = $this->buildQuery($statementParts);
200
-            $this->replacePlaceholders($statement, $parameters, current($statementParts['tables']));
201
-            #print $statement; exit(); // @debug
202
-            $result = $this->databaseHandle->sql_query($statement);
203
-            $this->checkSqlErrors($statement);
204
-            $count = $this->databaseHandle->sql_num_rows($result);
205
-        } else {
206
-            $statementParts['fields'] = array('COUNT(*)');
207
-            // having orderings without grouping is not compatible with non-MySQL DBMS
208
-            $statementParts['orderings'] = array();
209
-            if (isset($statementParts['keywords']['distinct'])) {
210
-                unset($statementParts['keywords']['distinct']);
211
-                $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid';
212
-                $statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.' . $distinctField . ')');
213
-            }
214
-
215
-            $statement = $this->buildQuery($statementParts);
216
-            $this->replacePlaceholders($statement, $parameters, current($statementParts['tables']));
217
-
218
-            #print $statement; exit(); // @debug
219
-            $result = $this->databaseHandle->sql_query($statement);
220
-            $this->checkSqlErrors($statement);
221
-            $count = 0;
222
-            if ($result) {
223
-                $row = $this->databaseHandle->sql_fetch_assoc($result);
224
-                $count = current($row);
225
-            }
226
-        }
227
-        $this->databaseHandle->sql_free_result($result);
228
-        return (int)$count;
229
-    }
230
-
231
-    /**
232
-     * Parses the query and returns the SQL statement parts.
233
-     *
234
-     * @param QueryInterface $query The query
235
-     * @param array &$parameters
236
-     * @return array The SQL statement parts
237
-     */
238
-    public function parseQuery(QueryInterface $query, array &$parameters)
239
-    {
240
-        $statementParts = array();
241
-        $statementParts['keywords'] = array();
242
-        $statementParts['tables'] = array();
243
-        $statementParts['unions'] = array();
244
-        $statementParts['fields'] = array();
245
-        $statementParts['where'] = array();
246
-        $statementParts['additionalWhereClause'] = array();
247
-        $statementParts['orderings'] = array();
248
-        $statementParts['limit'] = array();
249
-        $source = $query->getSource();
250
-        $this->parseSource($source, $statementParts);
251
-        $this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters);
252
-        $this->parseOrderings($query->getOrderings(), $source, $statementParts);
253
-        $this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts);
254
-        $tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions']));
255
-        foreach ($tableNames as $tableNameOrAlias) {
256
-            if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) {
257
-                $this->addAdditionalWhereClause($query->getQuerySettings(), $tableNameOrAlias, $statementParts);
258
-            }
259
-        }
260
-
261
-        return $statementParts;
262
-    }
263
-
264
-    /**
265
-     * Fiddle with the statement structure to handle recursive MM relations.
266
-     * For the recursive MM query to work, we must invert some values.
267
-     * Let see if that is the best way of doing that...
268
-     *
269
-     * @param array $statementParts
270
-     * @return array
271
-     */
272
-    public function processStatementStructureForRecursiveMMRelation(array $statementParts)
273
-    {
274
-
275
-        if ($this->hasRecursiveMMRelation()) {
276
-            $tableName = $this->query->getType();
277
-
278
-            // In order the MM query to work for a recursive MM query, we must invert some values.
279
-            // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name)
280
-            $values = array();
281
-            foreach ($statementParts['fields'] as $key => $value) {
282
-                $values[$key] = str_replace($tableName, $tableName . '0', $value);
283
-            }
284
-            $statementParts['fields'] = $values;
285
-
286
-            // Same comment as above.
287
-            $values = array();
288
-            foreach ($statementParts['where'] as $key => $value) {
289
-                $values[$key] = str_replace($tableName . '0', $tableName, $value);
290
-            }
291
-            $statementParts['where'] = $values;
292
-
293
-            // We must be more restrictive by transforming the "left" union by "inner"
294
-            $values = array();
295
-            foreach ($statementParts['unions'] as $key => $value) {
296
-                $values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value);
297
-            }
298
-            $statementParts['unions'] = $values;
299
-        }
300
-
301
-        return $statementParts;
302
-    }
303
-
304
-    /**
305
-     * Tell whether there is a recursive MM relation.
306
-     *
307
-     * @return bool
308
-     */
309
-    public function hasRecursiveMMRelation()
310
-    {
311
-        return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]);
312
-
313
-    }
314
-
315
-    /**
316
-     * Returns the statement, ready to be executed.
317
-     *
318
-     * @param array $statementParts The SQL statement parts
319
-     * @return string The SQL statement
320
-     */
321
-    public function buildQuery(array $statementParts)
322
-    {
323
-
324
-        // Add more statement to the UNION part.
325
-        if (!empty($statementParts['unions'])) {
326
-            foreach ($statementParts['unions'] as $tableName => $unionPart) {
327
-                if (!empty($statementParts['additionalWhereClause'][$tableName])) {
328
-                    $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]);
329
-                }
330
-            }
331
-        }
332
-
333
-        $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']);
334
-        if (!empty($statementParts['where'])) {
335
-            $statement .= ' WHERE ' . implode('', $statementParts['where']);
336
-            if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) {
337
-                $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
338
-            }
339
-        } elseif (!empty($statementParts['additionalWhereClause'])) {
340
-            $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
341
-        }
342
-        if (!empty($statementParts['orderings'])) {
343
-            $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']);
344
-        }
345
-        if (!empty($statementParts['limit'])) {
346
-            $statement .= ' LIMIT ' . $statementParts['limit'];
347
-        }
348
-
349
-        return $statement;
350
-    }
351
-
352
-    /**
353
-     * Transforms a Query Source into SQL and parameter arrays
354
-     *
355
-     * @param SourceInterface $source The source
356
-     * @param array &$sql
357
-     * @return void
358
-     */
359
-    protected function parseSource(SourceInterface $source, array &$sql)
360
-    {
361
-        if ($source instanceof SelectorInterface) {
362
-            $tableName = $source->getNodeTypeName();
363
-            $sql['fields'][$tableName] = $tableName . '.*';
364
-            $sql['tables'][$tableName] = $tableName;
365
-            if ($this->query->getDistinct()) {
366
-                $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct();
367
-                $sql['keywords']['distinct'] = 'DISTINCT';
368
-            }
369
-        } elseif ($source instanceof JoinInterface) {
370
-            $this->parseJoin($source, $sql);
371
-        }
372
-    }
373
-
374
-    /**
375
-     * Transforms a Join into SQL and parameter arrays
376
-     *
377
-     * @param JoinInterface $join The join
378
-     * @param array &$sql The query parts
379
-     * @return void
380
-     */
381
-    protected function parseJoin(JoinInterface $join, array &$sql)
382
-    {
383
-        $leftSource = $join->getLeft();
384
-        $leftTableName = $leftSource->getSelectorName();
385
-        // $sql['fields'][$leftTableName] = $leftTableName . '.*';
386
-        $rightSource = $join->getRight();
387
-        if ($rightSource instanceof JoinInterface) {
388
-            $rightTableName = $rightSource->getLeft()->getSelectorName();
389
-        } else {
390
-            $rightTableName = $rightSource->getSelectorName();
391
-            $sql['fields'][$leftTableName] = $rightTableName . '.*';
392
-        }
393
-        $sql['tables'][$leftTableName] = $leftTableName;
394
-        $sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName;
395
-        $joinCondition = $join->getJoinCondition();
396
-        if ($joinCondition instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\EquiJoinCondition) {
397
-            $column1Name = $joinCondition->getProperty1Name();
398
-            $column2Name = $joinCondition->getProperty2Name();
399
-            $sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name;
400
-        }
401
-        if ($rightSource instanceof JoinInterface) {
402
-            $this->parseJoin($rightSource, $sql);
403
-        }
404
-    }
405
-
406
-    /**
407
-     * Transforms a constraint into SQL and parameter arrays
408
-     *
409
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint The constraint
410
-     * @param SourceInterface $source The source
411
-     * @param array &$sql The query parts
412
-     * @param array &$parameters The parameters that will replace the markers
413
-     * @return void
414
-     */
415
-    protected function parseConstraint(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint = NULL, SourceInterface $source, array &$sql, array &$parameters)
416
-    {
417
-        if ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface) {
418
-            $sql['where'][] = '(';
419
-            $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
420
-            $sql['where'][] = ' AND ';
421
-            $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
422
-            $sql['where'][] = ')';
423
-        } elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface) {
424
-            $sql['where'][] = '(';
425
-            $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
426
-            $sql['where'][] = ' OR ';
427
-            $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
428
-            $sql['where'][] = ')';
429
-        } elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface) {
430
-            $sql['where'][] = 'NOT (';
431
-            $this->parseConstraint($constraint->getConstraint(), $source, $sql, $parameters);
432
-            $sql['where'][] = ')';
433
-        } elseif ($constraint instanceof ComparisonInterface) {
434
-            $this->parseComparison($constraint, $source, $sql, $parameters);
435
-        }
436
-    }
437
-
438
-    /**
439
-     * Parse a Comparison into SQL and parameter arrays.
440
-     *
441
-     * @param ComparisonInterface $comparison The comparison to parse
442
-     * @param SourceInterface $source The source
443
-     * @param array &$sql SQL query parts to add to
444
-     * @param array &$parameters Parameters to bind to the SQL
445
-     * @throws Exception\RepositoryException
446
-     * @return void
447
-     */
448
-    protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$sql, array &$parameters)
449
-    {
450
-        $operand1 = $comparison->getOperand1();
451
-        $operator = $comparison->getOperator();
452
-        $operand2 = $comparison->getOperand2();
453
-        if ($operator === QueryInterface::OPERATOR_IN) {
454
-            $items = array();
455
-            $hasValue = FALSE;
456
-            foreach ($operand2 as $value) {
457
-                $value = $this->getPlainValue($value);
458
-                if ($value !== NULL) {
459
-                    $items[] = $value;
460
-                    $hasValue = TRUE;
461
-                }
462
-            }
463
-            if ($hasValue === FALSE) {
464
-                $sql['where'][] = '1<>1';
465
-            } else {
466
-                $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters, NULL);
467
-                $parameters[] = $items;
468
-            }
469
-        } elseif ($operator === QueryInterface::OPERATOR_CONTAINS) {
470
-            if ($operand2 === NULL) {
471
-                $sql['where'][] = '1<>1';
472
-            } else {
473
-                throw new \Exception('Not implemented! Contact extension author.', 1412931227);
474
-                # @todo re-implement me if necessary.
475
-                #$tableName = $this->query->getType();
476
-                #$propertyName = $operand1->getPropertyName();
477
-                #while (strpos($propertyName, '.') !== FALSE) {
478
-                #	$this->addUnionStatement($tableName, $propertyName, $sql);
479
-                #}
480
-                #$columnName = $propertyName;
481
-                #$columnMap = $propertyName;
482
-                #$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : NULL;
483
-                #if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
484
-                #	$relationTableName = $columnMap->getRelationTableName();
485
-                #	$sql['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)';
486
-                #	$parameters[] = intval($this->getPlainValue($operand2));
487
-                #} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) {
488
-                #	$parentKeyFieldName = $columnMap->getParentKeyFieldName();
489
-                #	if (isset($parentKeyFieldName)) {
490
-                #		$childTableName = $columnMap->getChildTableName();
491
-                #		$sql['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)';
492
-                #		$parameters[] = intval($this->getPlainValue($operand2));
493
-                #	} else {
494
-                #		$sql['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')';
495
-                #		$parameters[] = intval($this->getPlainValue($operand2));
496
-                #	}
497
-                #} else {
498
-                #	throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745);
499
-                #}
500
-            }
501
-        } else {
502
-            if ($operand2 === NULL) {
503
-                if ($operator === QueryInterface::OPERATOR_EQUAL_TO) {
504
-                    $operator = self::OPERATOR_EQUAL_TO_NULL;
505
-                } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) {
506
-                    $operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
507
-                }
508
-            }
509
-            $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters);
510
-            $parameters[] = $this->getPlainValue($operand2);
511
-        }
512
-    }
513
-
514
-    /**
515
-     * Returns a plain value, i.e. objects are flattened out if possible.
516
-     *
517
-     * @param mixed $input
518
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException
519
-     * @return mixed
520
-     */
521
-    protected function getPlainValue($input)
522
-    {
523
-        if (is_array($input)) {
524
-            throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932);
525
-        }
526
-        if ($input instanceof \DateTime) {
527
-            return $input->format('U');
528
-        } elseif (is_object($input)) {
529
-            if ($input instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
530
-                $realInput = $input->_loadRealInstance();
531
-            } else {
532
-                $realInput = $input;
533
-            }
534
-            if ($realInput instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
535
-                return $realInput->getUid();
536
-            } else {
537
-                throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934);
538
-            }
539
-        } elseif (is_bool($input)) {
540
-            return $input === TRUE ? 1 : 0;
541
-        } else {
542
-            return $input;
543
-        }
544
-    }
545
-
546
-    /**
547
-     * Parse a DynamicOperand into SQL and parameter arrays.
548
-     *
549
-     * @param DynamicOperandInterface $operand
550
-     * @param string $operator One of the JCR_OPERATOR_* constants
551
-     * @param SourceInterface $source The source
552
-     * @param array &$sql The query parts
553
-     * @param array &$parameters The parameters that will replace the markers
554
-     * @param string $valueFunction an optional SQL function to apply to the operand value
555
-     * @return void
556
-     */
557
-    protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$sql, array &$parameters, $valueFunction = NULL)
558
-    {
559
-        if ($operand instanceof LowerCaseInterface) {
560
-            $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER');
561
-        } elseif ($operand instanceof UpperCaseInterface) {
562
-            $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'UPPER');
563
-        } elseif ($operand instanceof PropertyValueInterface) {
564
-            $propertyName = $operand->getPropertyName();
565
-
566
-            // Reset value.
567
-            $this->currentChildTableNameAlias = '';
568
-
569
-            if ($source instanceof SelectorInterface) {
570
-                $tableName = $this->query->getType();
571
-                while (strpos($propertyName, '.') !== FALSE) {
572
-                    $this->addUnionStatement($tableName, $propertyName, $sql);
573
-                }
574
-            } elseif ($source instanceof JoinInterface) {
575
-                $tableName = $source->getJoinCondition()->getSelector1Name();
576
-            }
577
-
578
-            $columnName = $propertyName;
579
-            $operator = $this->resolveOperator($operator);
580
-            $constraintSQL = '';
581
-            if ($valueFunction === NULL) {
582
-                $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?';
583
-            } else {
584
-                $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?';
585
-            }
586
-
587
-            if (isset($tableName) && !empty($this->currentChildTableNameAlias)) {
588
-                $constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL);
589
-            }
590
-            $sql['where'][] = $constraintSQL;
591
-        }
592
-    }
593
-
594
-    /**
595
-     * @param string &$tableName
596
-     * @param array &$propertyPath
597
-     * @param array &$sql
598
-     * @throws Exception
599
-     * @throws Exception\InvalidRelationConfigurationException
600
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\MissingColumnMapException
601
-     */
602
-    protected function addUnionStatement(&$tableName, &$propertyPath, array &$sql)
603
-    {
604
-
605
-        $table = Tca::table($tableName);
606
-
607
-        $explodedPropertyPath = explode('.', $propertyPath, 2);
608
-        $fieldName = $explodedPropertyPath[0];
609
-
610
-        // Field of type "group" are special because property path must contain the table name
611
-        // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
612
-        if ($table->field($fieldName)->isGroup()) {
613
-            $parts = explode('.', $propertyPath, 3);
614
-            $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1];
615
-            $explodedPropertyPath[1] = $parts[2];
616
-            $fieldName = $explodedPropertyPath[0];
617
-        }
618
-
619
-        $parentKeyFieldName = $table->field($fieldName)->getForeignField();
620
-        $childTableName = $table->field($fieldName)->getForeignTable();
621
-
622
-        if ($childTableName === NULL) {
623
-            throw new Exception\InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925);
624
-        }
625
-
626
-        if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one"
627
-            // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons.
628
-            // $parentKeyFieldName === NULL does the trick somehow. Before condition was if (isset($parentKeyFieldName))
629
-            if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === NULL) {
630
-                $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid';
631
-            } else {
632
-                $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
633
-            }
634
-        } elseif ($table->field($fieldName)->hasRelationManyToMany()) {
635
-            $relationTableName = $table->field($fieldName)->getManyToManyTable();
636
-
637
-            $parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
638
-            $childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
639
-
640
-            // MM table e.g sys_category_record_mm
641
-            $relationTableNameAlias = $this->generateAlias($relationTableName);
642
-            $join = sprintf(
643
-                'LEFT JOIN %s AS %s ON %s.uid=%s.%s', $relationTableName,
644
-                $relationTableNameAlias,
645
-                $tableName,
646
-                $relationTableNameAlias,
647
-                $parentKeyFieldName
648
-            );
649
-            $sql['unions'][$relationTableNameAlias] = $join;
650
-
651
-            // Foreign table e.g sys_category
652
-            $childTableNameAlias = $this->generateAlias($childTableName);
653
-            $this->currentChildTableNameAlias = $childTableNameAlias;
654
-            $join = sprintf(
655
-                'LEFT JOIN %s AS %s ON %s.%s=%s.uid',
656
-                $childTableName,
657
-                $childTableNameAlias,
658
-                $relationTableNameAlias,
659
-                $childKeyFieldName,
660
-                $childTableNameAlias
661
-            );
662
-            $sql['unions'][$childTableNameAlias] = $join;
663
-
664
-            // Find a possible table name for a MM condition.
665
-            $tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition();
666
-            if ($tableNameCondition) {
667
-
668
-                // If we can find a source file name,  we can then retrieve more MM conditions from the TCA such as a field name.
669
-                $sourceFileName = $this->query->getSourceFieldName();
670
-                if (empty($sourceFileName)) {
671
-                    $additionalMMConditions = array(
672
-                        'tablenames' => $tableNameCondition,
673
-                    );
674
-                } else {
675
-                    $additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition();
676
-                }
677
-
678
-                foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) {
679
-                    $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
680
-                    $sql['unions'][$relationTableNameAlias] .= $additionalJoin;
681
-
682
-                    $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
683
-                    $sql['unions'][$childTableNameAlias] .= $additionalJoin;
684
-                }
685
-
686
-            }
687
-
688
-
689
-        } elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations
690
-            $childTableNameAlias = $this->generateAlias($childTableName);
691
-            $this->currentChildTableNameAlias = $childTableNameAlias;
692
-
693
-            if (isset($parentKeyFieldName)) {
694
-                $join = sprintf(
695
-                    'LEFT JOIN %s AS %s ON %s.uid=%s.%s',
696
-                    $childTableName,
697
-                    $childTableNameAlias,
698
-                    $tableName,
699
-                    $childTableNameAlias,
700
-                    $parentKeyFieldName
701
-                );
702
-                $sql['unions'][$childTableNameAlias] = $join;
703
-            } else {
704
-                $join = sprintf(
705
-                    'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))',
706
-                    $childTableName,
707
-                    $childTableNameAlias,
708
-                    $childTableNameAlias,
709
-                    $tableName,
710
-                    $fieldName
711
-                );
712
-                $sql['unions'][$childTableNameAlias] = $join;
713
-            }
714
-        } else {
715
-            throw new Exception('Could not determine type of relation.', 1252502725);
716
-        }
717
-
718
-        // TODO check if there is another solution for this
719
-        $sql['keywords']['distinct'] = 'DISTINCT';
720
-        $propertyPath = $explodedPropertyPath[1];
721
-        $tableName = $childTableName;
722
-    }
723
-
724
-    /**
725
-     * Returns the SQL operator for the given JCR operator type.
726
-     *
727
-     * @param string $operator One of the JCR_OPERATOR_* constants
728
-     * @throws Exception
729
-     * @return string an SQL operator
730
-     */
731
-    protected function resolveOperator($operator)
732
-    {
733
-        switch ($operator) {
734
-            case self::OPERATOR_EQUAL_TO_NULL:
735
-                $operator = 'IS';
736
-                break;
737
-            case self::OPERATOR_NOT_EQUAL_TO_NULL:
738
-                $operator = 'IS NOT';
739
-                break;
740
-            case QueryInterface::OPERATOR_IN:
741
-                $operator = 'IN';
742
-                break;
743
-            case QueryInterface::OPERATOR_EQUAL_TO:
744
-                $operator = '=';
745
-                break;
746
-            case QueryInterface::OPERATOR_NOT_EQUAL_TO:
747
-                $operator = '!=';
748
-                break;
749
-            case QueryInterface::OPERATOR_LESS_THAN:
750
-                $operator = '<';
751
-                break;
752
-            case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO:
753
-                $operator = '<=';
754
-                break;
755
-            case QueryInterface::OPERATOR_GREATER_THAN:
756
-                $operator = '>';
757
-                break;
758
-            case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO:
759
-                $operator = '>=';
760
-                break;
761
-            case QueryInterface::OPERATOR_LIKE:
762
-                $operator = 'LIKE';
763
-                break;
764
-            default:
765
-                throw new Exception('Unsupported operator encountered.', 1242816073);
766
-        }
767
-        return $operator;
768
-    }
769
-
770
-    /**
771
-     * Replace query placeholders in a query part by the given
772
-     * parameters.
773
-     *
774
-     * @param string &$sqlString The query part with placeholders
775
-     * @param array $parameters The parameters
776
-     * @param string $tableName
777
-     *
778
-     * @throws Exception
779
-     */
780
-    protected function replacePlaceholders(&$sqlString, array $parameters, $tableName = 'foo')
781
-    {
782
-        // TODO profile this method again
783
-        if (substr_count($sqlString, '?') !== count($parameters)) {
784
-            throw new Exception('The number of question marks to replace must be equal to the number of parameters.', 1242816074);
785
-        }
786
-        $offset = 0;
787
-        foreach ($parameters as $parameter) {
788
-            $markPosition = strpos($sqlString, '?', $offset);
789
-            if ($markPosition !== FALSE) {
790
-                if ($parameter === NULL) {
791
-                    $parameter = 'NULL';
792
-                } elseif (is_array($parameter) || $parameter instanceof \ArrayAccess || $parameter instanceof \Traversable) {
793
-                    $items = array();
794
-                    foreach ($parameter as $item) {
795
-                        $items[] = $this->databaseHandle->fullQuoteStr($item, $tableName);
796
-                    }
797
-                    $parameter = '(' . implode(',', $items) . ')';
798
-                } else {
799
-                    $parameter = $this->databaseHandle->fullQuoteStr($parameter, $tableName);
800
-                }
801
-                $sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, ($markPosition + 1));
802
-            }
803
-            $offset = $markPosition + strlen($parameter);
804
-        }
805
-    }
806
-
807
-    /**
808
-     * Adds additional WHERE statements according to the query settings.
809
-     *
810
-     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
811
-     * @param string $tableNameOrAlias The table name to add the additional where clause for
812
-     * @param array &$statementParts
813
-     * @return void
814
-     */
815
-    protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts)
816
-    {
817
-        $this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts);
818
-        if ($querySettings->getRespectSysLanguage()) {
819
-            $this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings);
820
-        }
821
-        if ($querySettings->getRespectStoragePage()) {
822
-            $this->addPageIdStatement($tableNameOrAlias, $statementParts, $querySettings->getStoragePageIds());
823
-        }
824
-    }
825
-
826
-    /**
827
-     * Adds enableFields and deletedClause to the query if necessary
828
-     *
829
-     * @param QuerySettingsInterface $querySettings
830
-     * @param string $tableNameOrAlias The database table name
831
-     * @param array &$statementParts The query parts
832
-     * @return void
833
-     */
834
-    protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts)
835
-    {
836
-        $statement = '';
837
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
838
-        if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
839
-            $ignoreEnableFields = $querySettings->getIgnoreEnableFields();
840
-            $enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored();
841
-            $includeDeleted = $querySettings->getIncludeDeleted();
842
-            if ($this->environmentService->isEnvironmentInFrontendMode()) {
843
-                $statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted);
844
-            } else {
845
-                // TYPO3_MODE === 'BE'
846
-                $statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted);
847
-            }
848
-
849
-            // Remove the prefixing "AND" if any.
850
-            if (!empty($statement)) {
851
-                $statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement;
852
-                $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement;
853
-            }
854
-        }
855
-    }
856
-
857
-    /**
858
-     * Returns constraint statement for frontend context
859
-     *
860
-     * @param string $tableNameOrAlias
861
-     * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
862
-     * @param array $enableFieldsToBeIgnored If $ignoreEnableFields is true, this array specifies enable fields to be ignored. If it is NULL or an empty array (default) all enable fields are ignored.
863
-     * @param boolean $includeDeleted A flag indicating whether deleted records should be included
864
-     * @return string
865
-     * @throws Exception\InconsistentQuerySettingsException
866
-     */
867
-    protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored = array(), $includeDeleted)
868
-    {
869
-        $statement = '';
870
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
871
-        if ($ignoreEnableFields && !$includeDeleted) {
872
-            if (count($enableFieldsToBeIgnored)) {
873
-                // array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented
874
-                $statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored));
875
-            } else {
876
-                $statement .= $this->getPageRepository()->deleteClause($tableName);
877
-            }
878
-        } elseif (!$ignoreEnableFields && !$includeDeleted) {
879
-            $statement .= $this->getPageRepository()->enableFields($tableName);
880
-        } elseif (!$ignoreEnableFields && $includeDeleted) {
881
-            throw new Exception\InconsistentQuerySettingsException('Query setting "ignoreEnableFields=FALSE" can not be used together with "includeDeleted=TRUE" in frontend context.', 1327678173);
882
-        }
883
-        return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
884
-    }
885
-
886
-    /**
887
-     * Returns constraint statement for backend context
888
-     *
889
-     * @param string $tableNameOrAlias
890
-     * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
891
-     * @param boolean $includeDeleted A flag indicating whether deleted records should be included
892
-     * @return string
893
-     */
894
-    protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted)
895
-    {
896
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
897
-        $statement = '';
898
-        if (!$ignoreEnableFields) {
899
-            $statement .= BackendUtility::BEenableFields($tableName);
900
-        }
901
-
902
-        // If the table is found to have "workspace" support, add the corresponding fields in the statement.
903
-        if (Tca::table($tableName)->hasWorkspaceSupport()) {
904
-            if ($this->getBackendUser()->workspace === 0) {
905
-                $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE);
906
-            } else {
907
-                // Show only records of live and of the current workspace
908
-                // In case we are in a Versioning preview
909
-                $statement .= ' AND (' .
910
-                    $tableName . '.t3ver_wsid=0 OR ' .
911
-                    $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace .
912
-                    ')';
913
-            }
914
-
915
-            // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0
916
-            $statement .= ' AND ' . $tableName . '.pid<>-1';
917
-        }
918
-
919
-        if (!$includeDeleted) {
920
-            $statement .= BackendUtility::deleteClause($tableName);
921
-        }
922
-
923
-        return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
924
-    }
925
-
926
-    /**
927
-     * Builds the language field statement
928
-     *
929
-     * @param string $tableNameOrAlias The database table name
930
-     * @param array &$statementParts The query parts
931
-     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
932
-     * @throws Exception
933
-     * @return void
934
-     */
935
-    protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings)
936
-    {
937
-
938
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
939
-        if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
940
-            if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) {
941
-                // Select all entries for the current language
942
-                $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)';
943
-                // If any language is set -> get those entries which are not translated yet
944
-                // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode
945
-                if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
946
-                    && $querySettings->getLanguageUid() > 0
947
-                ) {
948
-                    $additionalWhereClause .= ' OR (' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' .
949
-                        ' AND ' . $tableName . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] .
950
-                        ' FROM ' . $tableName .
951
-                        ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' .
952
-                        ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0';
953
-
954
-                    // Add delete clause to ensure all entries are loaded
955
-                    if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) {
956
-                        $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0';
957
-                    }
958
-                    $additionalWhereClause .= '))';
959
-                    throw new Exception('Not tested code! It will fail', 1412928284);
960
-                }
961
-                $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')';
962
-            }
963
-        }
964
-    }
965
-
966
-    /**
967
-     * Builds the page ID checking statement
968
-     *
969
-     * @param string $tableNameOrAlias The database table name
970
-     * @param array &$statementParts The query parts
971
-     * @param array $storagePageIds list of storage page ids
972
-     * @throws Exception\InconsistentQuerySettingsException
973
-     * @return void
974
-     */
975
-    protected function addPageIdStatement($tableNameOrAlias, array &$statementParts, array $storagePageIds)
976
-    {
977
-
978
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
979
-        $tableColumns = $this->tableColumnCache->get($tableName);
980
-        if ($tableColumns === FALSE) {
981
-            $tableColumns = $this->databaseHandle->admin_get_fields($tableName);
982
-            $this->tableColumnCache->set($tableName, $tableColumns);
983
-        }
984
-        if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('pid', $tableColumns)) {
985
-            $rootLevel = (int)$GLOBALS['TCA'][$tableName]['ctrl']['rootLevel'];
986
-            if ($rootLevel) {
987
-                if ($rootLevel === 1) {
988
-                    $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $tableNameOrAlias . '.pid = 0';
989
-                }
990
-            } else {
991
-                if (empty($storagePageIds)) {
992
-                    throw new Exception\InconsistentQuerySettingsException('Missing storage page ids.', 1365779762);
993
-                }
994
-                $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $tableNameOrAlias . '.pid IN (' . implode(', ', $storagePageIds) . ')';
995
-            }
996
-        }
997
-    }
998
-
999
-    /**
1000
-     * Transforms orderings into SQL.
1001
-     *
1002
-     * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
1003
-     * @param SourceInterface $source The source
1004
-     * @param array &$sql The query parts
1005
-     * @throws Exception\UnsupportedOrderException
1006
-     * @return void
1007
-     */
1008
-    protected function parseOrderings(array $orderings, SourceInterface $source, array &$sql)
1009
-    {
1010
-        foreach ($orderings as $fieldNameAndPath => $order) {
1011
-            switch ($order) {
1012
-                case QueryInterface::ORDER_ASCENDING:
1013
-                    $order = 'ASC';
1014
-                    break;
1015
-                case QueryInterface::ORDER_DESCENDING:
1016
-                    $order = 'DESC';
1017
-                    break;
1018
-                default:
1019
-                    throw new Exception\UnsupportedOrderException('Unsupported order encountered.', 1242816074);
1020
-            }
1021
-
1022
-            $tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType());
1023
-            $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName);
1024
-            $sql['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order);
1025
-        }
1026
-    }
1027
-
1028
-    /**
1029
-     * Transforms limit and offset into SQL
1030
-     *
1031
-     * @param int $limit
1032
-     * @param int $offset
1033
-     * @param array &$sql
1034
-     * @return void
1035
-     */
1036
-    protected function parseLimitAndOffset($limit, $offset, array &$sql)
1037
-    {
1038
-        if ($limit !== NULL && $offset !== NULL) {
1039
-            $sql['limit'] = intval($offset) . ', ' . intval($limit);
1040
-        } elseif ($limit !== NULL) {
1041
-            $sql['limit'] = intval($limit);
1042
-        }
1043
-    }
1044
-
1045
-    /**
1046
-     * Transforms a Resource from a database query to an array of rows.
1047
-     *
1048
-     * @param resource $result The result
1049
-     * @return array The result as an array of rows (tuples)
1050
-     */
1051
-    protected function getRowsFromResult($result)
1052
-    {
1053
-        $rows = array();
1054
-        while ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
1055
-            if (is_array($row)) {
1056
-
1057
-                // Get language uid from querySettings.
1058
-                // Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed)
1059
-                $overlaidRow = $this->doLanguageAndWorkspaceOverlay($this->query->getSource(), $row, $this->query->getQuerySettings());
1060
-                $contentObject = GeneralUtility::makeInstance($this->objectType, $this->query->getType(), $overlaidRow);
1061
-                $rows[] = $contentObject;
1062
-            }
1063
-        }
1064
-
1065
-        return $rows;
1066
-    }
1067
-
1068
-    /**
1069
-     * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
1070
-     * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
1071
-     *
1072
-     * @param SourceInterface $source The source (selector od join)
1073
-     * @param array $row
1074
-     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
1075
-     * @return array
1076
-     */
1077
-    protected function doLanguageAndWorkspaceOverlay(SourceInterface $source, array $row, $querySettings)
1078
-    {
1079
-
1080
-        /** @var SelectorInterface $source */
1081
-        $tableName = $source->getSelectorName();
1082
-
1083
-        $pageRepository = $this->getPageRepository();
1084
-        if (is_object($GLOBALS['TSFE'])) {
1085
-            $languageMode = $GLOBALS['TSFE']->sys_language_mode;
1086
-            if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) {
1087
-                $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace;
1088
-            }
1089
-        } else {
1090
-            $languageMode = '';
1091
-            $workspaceUid = $this->getBackendUser()->workspace;
1092
-            $pageRepository->versioningWorkspaceId = $workspaceUid;
1093
-            if ($this->getBackendUser()->workspace !== 0) {
1094
-                $pageRepository->versioningPreview = 1;
1095
-            }
1096
-        }
1097
-
1098
-        // If current row is a translation select its parent
1099
-        if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
1100
-            && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
1101
-        ) {
1102
-            if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']])
1103
-                && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
1104
-            ) {
1105
-                $row = $this->databaseHandle->exec_SELECTgetSingleRow(
1106
-                    $tableName . '.*',
1107
-                    $tableName,
1108
-                    $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] .
1109
-                    ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0'
1110
-                );
1111
-            }
1112
-        }
1113
-
1114
-        // Retrieve the original uid
1115
-        // @todo It looks for me this code will never be used! "_ORIG_uid" is something from extbase. Adjust me or remove me in 0.4 + 2 version!
1116
-        $pageRepository->versionOL($tableName, $row, TRUE);
1117
-        if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) {
1118
-            $row['uid'] = $row['_ORIG_uid'];
1119
-        }
1120
-
1121
-        // Special case for table "pages"
1122
-        if ($tableName == 'pages') {
1123
-            $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
1124
-        } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
1125
-            && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== ''
1126
-        ) {
1127
-            if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
1128
-                $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : '';
1129
-                $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
1130
-            }
1131
-        }
1132
-
1133
-        return $row;
1134
-    }
1135
-
1136
-    /**
1137
-     * Return a resolved table name given a possible table name alias.
1138
-     *
1139
-     * @param string $tableNameOrAlias
1140
-     * @return string
1141
-     */
1142
-    protected function resolveTableNameAlias($tableNameOrAlias)
1143
-    {
1144
-        $resolvedTableName = $tableNameOrAlias;
1145
-        if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) {
1146
-            $resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias];
1147
-        }
1148
-        return $resolvedTableName;
1149
-    }
1150
-
1151
-    /**
1152
-     * Generate a unique table name alias for the given table name.
1153
-     *
1154
-     * @param string $tableName
1155
-     * @return string
1156
-     */
1157
-    protected function generateAlias($tableName)
1158
-    {
1159
-
1160
-        if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) {
1161
-            $this->tableNameAliases['aliasIncrement'][$tableName] = 0;
1162
-        }
1163
-
1164
-        $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName];
1165
-        $tableNameAlias = $tableName . $numberOfAliases;
1166
-
1167
-        $this->tableNameAliases['aliasIncrement'][$tableName]++;
1168
-        $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName;
1169
-
1170
-        return $tableNameAlias;
1171
-    }
1172
-
1173
-    /**
1174
-     * Replace the table names by its table name alias within the given statement.
1175
-     *
1176
-     * @param string $tableName
1177
-     * @param string $tableNameAlias
1178
-     * @param string $statement
1179
-     * @return string
1180
-     */
1181
-    protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement)
1182
-    {
1183
-        if ($statement && $tableName !== $tableNameAlias) {
1184
-            $statement = str_replace($tableName, $tableNameAlias, $statement);
1185
-        }
1186
-        return $statement;
1187
-    }
1188
-
1189
-    /**
1190
-     * Returns an instance of the current Backend User.
1191
-     *
1192
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1193
-     */
1194
-    protected function getBackendUser()
1195
-    {
1196
-        return $GLOBALS['BE_USER'];
1197
-    }
1198
-
1199
-    /**
1200
-     * Tell whether a Backend User is logged in.
1201
-     *
1202
-     * @return bool
1203
-     */
1204
-    protected function isBackendUserLogged()
1205
-    {
1206
-        return is_object($GLOBALS['BE_USER']);
1207
-    }
1208
-
1209
-    /**
1210
-     * @return PageRepository
1211
-     */
1212
-    protected function getPageRepository()
1213
-    {
1214
-        if (!$this->pageRepository instanceof PageRepository) {
1215
-            if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($GLOBALS['TSFE'])) {
1216
-                $this->pageRepository = $GLOBALS['TSFE']->sys_page;
1217
-            } else {
1218
-                $this->pageRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
1219
-            }
1220
-        }
1221
-
1222
-        return $this->pageRepository;
1223
-    }
1224
-
1225
-    /**
1226
-     * @return \Fab\Vidi\Resolver\FieldPathResolver
1227
-     */
1228
-    protected function getFieldPathResolver()
1229
-    {
1230
-        return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
1231
-    }
1232
-
1233
-    /**
1234
-     * Checks if there are SQL errors in the last query, and if yes, throw an exception.
1235
-     *
1236
-     * @return void
1237
-     * @param string $sql The SQL statement
1238
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException
1239
-     */
1240
-    protected function checkSqlErrors($sql = '')
1241
-    {
1242
-        $error = $this->databaseHandle->sql_error();
1243
-        if ($error !== '') {
1244
-            $error .= $sql ? ': ' . $sql : '';
1245
-            throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($error, 1247602160);
1246
-        }
1247
-    }
41
+	const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull';
42
+	const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull';
43
+
44
+	/**
45
+	 * The TYPO3 database object
46
+	 *
47
+	 * @var \TYPO3\CMS\Core\Database\DatabaseConnection
48
+	 */
49
+	protected $databaseHandle;
50
+
51
+	/**
52
+	 * The TYPO3 page repository. Used for language and workspace overlay
53
+	 *
54
+	 * @var PageRepository
55
+	 */
56
+	protected $pageRepository;
57
+
58
+	/**
59
+	 * A first-level TypoScript configuration cache
60
+	 *
61
+	 * @var array
62
+	 */
63
+	protected $pageTSConfigCache = array();
64
+
65
+	/**
66
+	 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
67
+	 * @inject
68
+	 */
69
+	protected $configurationManager;
70
+
71
+	/**
72
+	 * @var \TYPO3\CMS\Extbase\Service\CacheService
73
+	 * @inject
74
+	 */
75
+	protected $cacheService;
76
+
77
+	/**
78
+	 * @var \TYPO3\CMS\Core\Cache\CacheManager
79
+	 * @inject
80
+	 */
81
+	protected $cacheManager;
82
+
83
+	/**
84
+	 * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
85
+	 */
86
+	protected $tableColumnCache;
87
+
88
+	/**
89
+	 * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
90
+	 * @inject
91
+	 */
92
+	protected $environmentService;
93
+
94
+	/**
95
+	 * @var \Fab\Vidi\Persistence\Query
96
+	 */
97
+	protected $query;
98
+
99
+	/**
100
+	 * Store some info related to table name and its aliases.
101
+	 *
102
+	 * @var array
103
+	 */
104
+	protected $tableNameAliases = array(
105
+		'aliases' => array(),
106
+		'aliasIncrement' => array(),
107
+	);
108
+
109
+	/**
110
+	 * Use to store the current foreign table name alias.
111
+	 *
112
+	 * @var string
113
+	 */
114
+	protected $currentChildTableNameAlias = '';
115
+
116
+	/**
117
+	 * The default object type being returned.
118
+	 *
119
+	 * @var string
120
+	 */
121
+	protected $objectType = 'Fab\Vidi\Domain\Model\Content';
122
+
123
+	/**
124
+	 * Constructor. takes the database handle from $GLOBALS['TYPO3_DB']
125
+	 */
126
+	public function __construct(QueryInterface $query)
127
+	{
128
+		$this->query = $query;
129
+		$this->databaseHandle = $GLOBALS['TYPO3_DB'];
130
+	}
131
+
132
+	/**
133
+	 * Lifecycle method
134
+	 *
135
+	 * @return void
136
+	 */
137
+	public function initializeObject()
138
+	{
139
+		$this->tableColumnCache = $this->cacheManager->getCache('extbase_typo3dbbackend_tablecolumns');
140
+	}
141
+
142
+	/**
143
+	 * @param array $identifier
144
+	 * @return string
145
+	 */
146
+	protected function parseIdentifier(array $identifier)
147
+	{
148
+		$fieldNames = array_keys($identifier);
149
+		$suffixedFieldNames = array();
150
+		foreach ($fieldNames as $fieldName) {
151
+			$suffixedFieldNames[] = $fieldName . '=?';
152
+		}
153
+		return implode(' AND ', $suffixedFieldNames);
154
+	}
155
+
156
+	/**
157
+	 * Returns the result of the query
158
+	 */
159
+	public function fetchResult()
160
+	{
161
+
162
+		$parameters = array();
163
+		$statementParts = $this->parseQuery($this->query, $parameters);
164
+		$statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that.
165
+
166
+		$sql = $this->buildQuery($statementParts);
167
+		$tableName = '';
168
+		if (is_array($statementParts) && !empty($statementParts['tables'][0])) {
169
+			$tableName = $statementParts['tables'][0];
170
+		}
171
+		$this->replacePlaceholders($sql, $parameters, $tableName);
172
+		#print $sql; exit(); // @debug
173
+
174
+		$result = $this->databaseHandle->sql_query($sql);
175
+		$this->checkSqlErrors($sql);
176
+		$rows = $this->getRowsFromResult($result);
177
+		$this->databaseHandle->sql_free_result($result);
178
+
179
+		return $rows;
180
+	}
181
+
182
+	/**
183
+	 * Returns the number of tuples matching the query.
184
+	 *
185
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException
186
+	 * @return int The number of matching tuples
187
+	 */
188
+	public function countResult()
189
+	{
190
+
191
+		$parameters = array();
192
+		$statementParts = $this->parseQuery($this->query, $parameters);
193
+		$statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that.
194
+		// Reset $statementParts for valid table return
195
+		reset($statementParts);
196
+
197
+		// if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints
198
+		if (!empty($statementParts['limit'])) {
199
+			$statement = $this->buildQuery($statementParts);
200
+			$this->replacePlaceholders($statement, $parameters, current($statementParts['tables']));
201
+			#print $statement; exit(); // @debug
202
+			$result = $this->databaseHandle->sql_query($statement);
203
+			$this->checkSqlErrors($statement);
204
+			$count = $this->databaseHandle->sql_num_rows($result);
205
+		} else {
206
+			$statementParts['fields'] = array('COUNT(*)');
207
+			// having orderings without grouping is not compatible with non-MySQL DBMS
208
+			$statementParts['orderings'] = array();
209
+			if (isset($statementParts['keywords']['distinct'])) {
210
+				unset($statementParts['keywords']['distinct']);
211
+				$distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid';
212
+				$statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.' . $distinctField . ')');
213
+			}
214
+
215
+			$statement = $this->buildQuery($statementParts);
216
+			$this->replacePlaceholders($statement, $parameters, current($statementParts['tables']));
217
+
218
+			#print $statement; exit(); // @debug
219
+			$result = $this->databaseHandle->sql_query($statement);
220
+			$this->checkSqlErrors($statement);
221
+			$count = 0;
222
+			if ($result) {
223
+				$row = $this->databaseHandle->sql_fetch_assoc($result);
224
+				$count = current($row);
225
+			}
226
+		}
227
+		$this->databaseHandle->sql_free_result($result);
228
+		return (int)$count;
229
+	}
230
+
231
+	/**
232
+	 * Parses the query and returns the SQL statement parts.
233
+	 *
234
+	 * @param QueryInterface $query The query
235
+	 * @param array &$parameters
236
+	 * @return array The SQL statement parts
237
+	 */
238
+	public function parseQuery(QueryInterface $query, array &$parameters)
239
+	{
240
+		$statementParts = array();
241
+		$statementParts['keywords'] = array();
242
+		$statementParts['tables'] = array();
243
+		$statementParts['unions'] = array();
244
+		$statementParts['fields'] = array();
245
+		$statementParts['where'] = array();
246
+		$statementParts['additionalWhereClause'] = array();
247
+		$statementParts['orderings'] = array();
248
+		$statementParts['limit'] = array();
249
+		$source = $query->getSource();
250
+		$this->parseSource($source, $statementParts);
251
+		$this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters);
252
+		$this->parseOrderings($query->getOrderings(), $source, $statementParts);
253
+		$this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts);
254
+		$tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions']));
255
+		foreach ($tableNames as $tableNameOrAlias) {
256
+			if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) {
257
+				$this->addAdditionalWhereClause($query->getQuerySettings(), $tableNameOrAlias, $statementParts);
258
+			}
259
+		}
260
+
261
+		return $statementParts;
262
+	}
263
+
264
+	/**
265
+	 * Fiddle with the statement structure to handle recursive MM relations.
266
+	 * For the recursive MM query to work, we must invert some values.
267
+	 * Let see if that is the best way of doing that...
268
+	 *
269
+	 * @param array $statementParts
270
+	 * @return array
271
+	 */
272
+	public function processStatementStructureForRecursiveMMRelation(array $statementParts)
273
+	{
274
+
275
+		if ($this->hasRecursiveMMRelation()) {
276
+			$tableName = $this->query->getType();
277
+
278
+			// In order the MM query to work for a recursive MM query, we must invert some values.
279
+			// tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name)
280
+			$values = array();
281
+			foreach ($statementParts['fields'] as $key => $value) {
282
+				$values[$key] = str_replace($tableName, $tableName . '0', $value);
283
+			}
284
+			$statementParts['fields'] = $values;
285
+
286
+			// Same comment as above.
287
+			$values = array();
288
+			foreach ($statementParts['where'] as $key => $value) {
289
+				$values[$key] = str_replace($tableName . '0', $tableName, $value);
290
+			}
291
+			$statementParts['where'] = $values;
292
+
293
+			// We must be more restrictive by transforming the "left" union by "inner"
294
+			$values = array();
295
+			foreach ($statementParts['unions'] as $key => $value) {
296
+				$values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value);
297
+			}
298
+			$statementParts['unions'] = $values;
299
+		}
300
+
301
+		return $statementParts;
302
+	}
303
+
304
+	/**
305
+	 * Tell whether there is a recursive MM relation.
306
+	 *
307
+	 * @return bool
308
+	 */
309
+	public function hasRecursiveMMRelation()
310
+	{
311
+		return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]);
312
+
313
+	}
314
+
315
+	/**
316
+	 * Returns the statement, ready to be executed.
317
+	 *
318
+	 * @param array $statementParts The SQL statement parts
319
+	 * @return string The SQL statement
320
+	 */
321
+	public function buildQuery(array $statementParts)
322
+	{
323
+
324
+		// Add more statement to the UNION part.
325
+		if (!empty($statementParts['unions'])) {
326
+			foreach ($statementParts['unions'] as $tableName => $unionPart) {
327
+				if (!empty($statementParts['additionalWhereClause'][$tableName])) {
328
+					$statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]);
329
+				}
330
+			}
331
+		}
332
+
333
+		$statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']);
334
+		if (!empty($statementParts['where'])) {
335
+			$statement .= ' WHERE ' . implode('', $statementParts['where']);
336
+			if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) {
337
+				$statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
338
+			}
339
+		} elseif (!empty($statementParts['additionalWhereClause'])) {
340
+			$statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
341
+		}
342
+		if (!empty($statementParts['orderings'])) {
343
+			$statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']);
344
+		}
345
+		if (!empty($statementParts['limit'])) {
346
+			$statement .= ' LIMIT ' . $statementParts['limit'];
347
+		}
348
+
349
+		return $statement;
350
+	}
351
+
352
+	/**
353
+	 * Transforms a Query Source into SQL and parameter arrays
354
+	 *
355
+	 * @param SourceInterface $source The source
356
+	 * @param array &$sql
357
+	 * @return void
358
+	 */
359
+	protected function parseSource(SourceInterface $source, array &$sql)
360
+	{
361
+		if ($source instanceof SelectorInterface) {
362
+			$tableName = $source->getNodeTypeName();
363
+			$sql['fields'][$tableName] = $tableName . '.*';
364
+			$sql['tables'][$tableName] = $tableName;
365
+			if ($this->query->getDistinct()) {
366
+				$sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct();
367
+				$sql['keywords']['distinct'] = 'DISTINCT';
368
+			}
369
+		} elseif ($source instanceof JoinInterface) {
370
+			$this->parseJoin($source, $sql);
371
+		}
372
+	}
373
+
374
+	/**
375
+	 * Transforms a Join into SQL and parameter arrays
376
+	 *
377
+	 * @param JoinInterface $join The join
378
+	 * @param array &$sql The query parts
379
+	 * @return void
380
+	 */
381
+	protected function parseJoin(JoinInterface $join, array &$sql)
382
+	{
383
+		$leftSource = $join->getLeft();
384
+		$leftTableName = $leftSource->getSelectorName();
385
+		// $sql['fields'][$leftTableName] = $leftTableName . '.*';
386
+		$rightSource = $join->getRight();
387
+		if ($rightSource instanceof JoinInterface) {
388
+			$rightTableName = $rightSource->getLeft()->getSelectorName();
389
+		} else {
390
+			$rightTableName = $rightSource->getSelectorName();
391
+			$sql['fields'][$leftTableName] = $rightTableName . '.*';
392
+		}
393
+		$sql['tables'][$leftTableName] = $leftTableName;
394
+		$sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName;
395
+		$joinCondition = $join->getJoinCondition();
396
+		if ($joinCondition instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\EquiJoinCondition) {
397
+			$column1Name = $joinCondition->getProperty1Name();
398
+			$column2Name = $joinCondition->getProperty2Name();
399
+			$sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name;
400
+		}
401
+		if ($rightSource instanceof JoinInterface) {
402
+			$this->parseJoin($rightSource, $sql);
403
+		}
404
+	}
405
+
406
+	/**
407
+	 * Transforms a constraint into SQL and parameter arrays
408
+	 *
409
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint The constraint
410
+	 * @param SourceInterface $source The source
411
+	 * @param array &$sql The query parts
412
+	 * @param array &$parameters The parameters that will replace the markers
413
+	 * @return void
414
+	 */
415
+	protected function parseConstraint(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint = NULL, SourceInterface $source, array &$sql, array &$parameters)
416
+	{
417
+		if ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface) {
418
+			$sql['where'][] = '(';
419
+			$this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
420
+			$sql['where'][] = ' AND ';
421
+			$this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
422
+			$sql['where'][] = ')';
423
+		} elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface) {
424
+			$sql['where'][] = '(';
425
+			$this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
426
+			$sql['where'][] = ' OR ';
427
+			$this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
428
+			$sql['where'][] = ')';
429
+		} elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface) {
430
+			$sql['where'][] = 'NOT (';
431
+			$this->parseConstraint($constraint->getConstraint(), $source, $sql, $parameters);
432
+			$sql['where'][] = ')';
433
+		} elseif ($constraint instanceof ComparisonInterface) {
434
+			$this->parseComparison($constraint, $source, $sql, $parameters);
435
+		}
436
+	}
437
+
438
+	/**
439
+	 * Parse a Comparison into SQL and parameter arrays.
440
+	 *
441
+	 * @param ComparisonInterface $comparison The comparison to parse
442
+	 * @param SourceInterface $source The source
443
+	 * @param array &$sql SQL query parts to add to
444
+	 * @param array &$parameters Parameters to bind to the SQL
445
+	 * @throws Exception\RepositoryException
446
+	 * @return void
447
+	 */
448
+	protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$sql, array &$parameters)
449
+	{
450
+		$operand1 = $comparison->getOperand1();
451
+		$operator = $comparison->getOperator();
452
+		$operand2 = $comparison->getOperand2();
453
+		if ($operator === QueryInterface::OPERATOR_IN) {
454
+			$items = array();
455
+			$hasValue = FALSE;
456
+			foreach ($operand2 as $value) {
457
+				$value = $this->getPlainValue($value);
458
+				if ($value !== NULL) {
459
+					$items[] = $value;
460
+					$hasValue = TRUE;
461
+				}
462
+			}
463
+			if ($hasValue === FALSE) {
464
+				$sql['where'][] = '1<>1';
465
+			} else {
466
+				$this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters, NULL);
467
+				$parameters[] = $items;
468
+			}
469
+		} elseif ($operator === QueryInterface::OPERATOR_CONTAINS) {
470
+			if ($operand2 === NULL) {
471
+				$sql['where'][] = '1<>1';
472
+			} else {
473
+				throw new \Exception('Not implemented! Contact extension author.', 1412931227);
474
+				# @todo re-implement me if necessary.
475
+				#$tableName = $this->query->getType();
476
+				#$propertyName = $operand1->getPropertyName();
477
+				#while (strpos($propertyName, '.') !== FALSE) {
478
+				#	$this->addUnionStatement($tableName, $propertyName, $sql);
479
+				#}
480
+				#$columnName = $propertyName;
481
+				#$columnMap = $propertyName;
482
+				#$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : NULL;
483
+				#if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
484
+				#	$relationTableName = $columnMap->getRelationTableName();
485
+				#	$sql['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)';
486
+				#	$parameters[] = intval($this->getPlainValue($operand2));
487
+				#} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) {
488
+				#	$parentKeyFieldName = $columnMap->getParentKeyFieldName();
489
+				#	if (isset($parentKeyFieldName)) {
490
+				#		$childTableName = $columnMap->getChildTableName();
491
+				#		$sql['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)';
492
+				#		$parameters[] = intval($this->getPlainValue($operand2));
493
+				#	} else {
494
+				#		$sql['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')';
495
+				#		$parameters[] = intval($this->getPlainValue($operand2));
496
+				#	}
497
+				#} else {
498
+				#	throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745);
499
+				#}
500
+			}
501
+		} else {
502
+			if ($operand2 === NULL) {
503
+				if ($operator === QueryInterface::OPERATOR_EQUAL_TO) {
504
+					$operator = self::OPERATOR_EQUAL_TO_NULL;
505
+				} elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) {
506
+					$operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
507
+				}
508
+			}
509
+			$this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters);
510
+			$parameters[] = $this->getPlainValue($operand2);
511
+		}
512
+	}
513
+
514
+	/**
515
+	 * Returns a plain value, i.e. objects are flattened out if possible.
516
+	 *
517
+	 * @param mixed $input
518
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException
519
+	 * @return mixed
520
+	 */
521
+	protected function getPlainValue($input)
522
+	{
523
+		if (is_array($input)) {
524
+			throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932);
525
+		}
526
+		if ($input instanceof \DateTime) {
527
+			return $input->format('U');
528
+		} elseif (is_object($input)) {
529
+			if ($input instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
530
+				$realInput = $input->_loadRealInstance();
531
+			} else {
532
+				$realInput = $input;
533
+			}
534
+			if ($realInput instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
535
+				return $realInput->getUid();
536
+			} else {
537
+				throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934);
538
+			}
539
+		} elseif (is_bool($input)) {
540
+			return $input === TRUE ? 1 : 0;
541
+		} else {
542
+			return $input;
543
+		}
544
+	}
545
+
546
+	/**
547
+	 * Parse a DynamicOperand into SQL and parameter arrays.
548
+	 *
549
+	 * @param DynamicOperandInterface $operand
550
+	 * @param string $operator One of the JCR_OPERATOR_* constants
551
+	 * @param SourceInterface $source The source
552
+	 * @param array &$sql The query parts
553
+	 * @param array &$parameters The parameters that will replace the markers
554
+	 * @param string $valueFunction an optional SQL function to apply to the operand value
555
+	 * @return void
556
+	 */
557
+	protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$sql, array &$parameters, $valueFunction = NULL)
558
+	{
559
+		if ($operand instanceof LowerCaseInterface) {
560
+			$this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER');
561
+		} elseif ($operand instanceof UpperCaseInterface) {
562
+			$this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'UPPER');
563
+		} elseif ($operand instanceof PropertyValueInterface) {
564
+			$propertyName = $operand->getPropertyName();
565
+
566
+			// Reset value.
567
+			$this->currentChildTableNameAlias = '';
568
+
569
+			if ($source instanceof SelectorInterface) {
570
+				$tableName = $this->query->getType();
571
+				while (strpos($propertyName, '.') !== FALSE) {
572
+					$this->addUnionStatement($tableName, $propertyName, $sql);
573
+				}
574
+			} elseif ($source instanceof JoinInterface) {
575
+				$tableName = $source->getJoinCondition()->getSelector1Name();
576
+			}
577
+
578
+			$columnName = $propertyName;
579
+			$operator = $this->resolveOperator($operator);
580
+			$constraintSQL = '';
581
+			if ($valueFunction === NULL) {
582
+				$constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?';
583
+			} else {
584
+				$constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?';
585
+			}
586
+
587
+			if (isset($tableName) && !empty($this->currentChildTableNameAlias)) {
588
+				$constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL);
589
+			}
590
+			$sql['where'][] = $constraintSQL;
591
+		}
592
+	}
593
+
594
+	/**
595
+	 * @param string &$tableName
596
+	 * @param array &$propertyPath
597
+	 * @param array &$sql
598
+	 * @throws Exception
599
+	 * @throws Exception\InvalidRelationConfigurationException
600
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\MissingColumnMapException
601
+	 */
602
+	protected function addUnionStatement(&$tableName, &$propertyPath, array &$sql)
603
+	{
604
+
605
+		$table = Tca::table($tableName);
606
+
607
+		$explodedPropertyPath = explode('.', $propertyPath, 2);
608
+		$fieldName = $explodedPropertyPath[0];
609
+
610
+		// Field of type "group" are special because property path must contain the table name
611
+		// to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
612
+		if ($table->field($fieldName)->isGroup()) {
613
+			$parts = explode('.', $propertyPath, 3);
614
+			$explodedPropertyPath[0] = $parts[0] . '.' . $parts[1];
615
+			$explodedPropertyPath[1] = $parts[2];
616
+			$fieldName = $explodedPropertyPath[0];
617
+		}
618
+
619
+		$parentKeyFieldName = $table->field($fieldName)->getForeignField();
620
+		$childTableName = $table->field($fieldName)->getForeignTable();
621
+
622
+		if ($childTableName === NULL) {
623
+			throw new Exception\InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925);
624
+		}
625
+
626
+		if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one"
627
+			// sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons.
628
+			// $parentKeyFieldName === NULL does the trick somehow. Before condition was if (isset($parentKeyFieldName))
629
+			if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === NULL) {
630
+				$sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid';
631
+			} else {
632
+				$sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
633
+			}
634
+		} elseif ($table->field($fieldName)->hasRelationManyToMany()) {
635
+			$relationTableName = $table->field($fieldName)->getManyToManyTable();
636
+
637
+			$parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
638
+			$childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
639
+
640
+			// MM table e.g sys_category_record_mm
641
+			$relationTableNameAlias = $this->generateAlias($relationTableName);
642
+			$join = sprintf(
643
+				'LEFT JOIN %s AS %s ON %s.uid=%s.%s', $relationTableName,
644
+				$relationTableNameAlias,
645
+				$tableName,
646
+				$relationTableNameAlias,
647
+				$parentKeyFieldName
648
+			);
649
+			$sql['unions'][$relationTableNameAlias] = $join;
650
+
651
+			// Foreign table e.g sys_category
652
+			$childTableNameAlias = $this->generateAlias($childTableName);
653
+			$this->currentChildTableNameAlias = $childTableNameAlias;
654
+			$join = sprintf(
655
+				'LEFT JOIN %s AS %s ON %s.%s=%s.uid',
656
+				$childTableName,
657
+				$childTableNameAlias,
658
+				$relationTableNameAlias,
659
+				$childKeyFieldName,
660
+				$childTableNameAlias
661
+			);
662
+			$sql['unions'][$childTableNameAlias] = $join;
663
+
664
+			// Find a possible table name for a MM condition.
665
+			$tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition();
666
+			if ($tableNameCondition) {
667
+
668
+				// If we can find a source file name,  we can then retrieve more MM conditions from the TCA such as a field name.
669
+				$sourceFileName = $this->query->getSourceFieldName();
670
+				if (empty($sourceFileName)) {
671
+					$additionalMMConditions = array(
672
+						'tablenames' => $tableNameCondition,
673
+					);
674
+				} else {
675
+					$additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition();
676
+				}
677
+
678
+				foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) {
679
+					$additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
680
+					$sql['unions'][$relationTableNameAlias] .= $additionalJoin;
681
+
682
+					$additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
683
+					$sql['unions'][$childTableNameAlias] .= $additionalJoin;
684
+				}
685
+
686
+			}
687
+
688
+
689
+		} elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations
690
+			$childTableNameAlias = $this->generateAlias($childTableName);
691
+			$this->currentChildTableNameAlias = $childTableNameAlias;
692
+
693
+			if (isset($parentKeyFieldName)) {
694
+				$join = sprintf(
695
+					'LEFT JOIN %s AS %s ON %s.uid=%s.%s',
696
+					$childTableName,
697
+					$childTableNameAlias,
698
+					$tableName,
699
+					$childTableNameAlias,
700
+					$parentKeyFieldName
701
+				);
702
+				$sql['unions'][$childTableNameAlias] = $join;
703
+			} else {
704
+				$join = sprintf(
705
+					'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))',
706
+					$childTableName,
707
+					$childTableNameAlias,
708
+					$childTableNameAlias,
709
+					$tableName,
710
+					$fieldName
711
+				);
712
+				$sql['unions'][$childTableNameAlias] = $join;
713
+			}
714
+		} else {
715
+			throw new Exception('Could not determine type of relation.', 1252502725);
716
+		}
717
+
718
+		// TODO check if there is another solution for this
719
+		$sql['keywords']['distinct'] = 'DISTINCT';
720
+		$propertyPath = $explodedPropertyPath[1];
721
+		$tableName = $childTableName;
722
+	}
723
+
724
+	/**
725
+	 * Returns the SQL operator for the given JCR operator type.
726
+	 *
727
+	 * @param string $operator One of the JCR_OPERATOR_* constants
728
+	 * @throws Exception
729
+	 * @return string an SQL operator
730
+	 */
731
+	protected function resolveOperator($operator)
732
+	{
733
+		switch ($operator) {
734
+			case self::OPERATOR_EQUAL_TO_NULL:
735
+				$operator = 'IS';
736
+				break;
737
+			case self::OPERATOR_NOT_EQUAL_TO_NULL:
738
+				$operator = 'IS NOT';
739
+				break;
740
+			case QueryInterface::OPERATOR_IN:
741
+				$operator = 'IN';
742
+				break;
743
+			case QueryInterface::OPERATOR_EQUAL_TO:
744
+				$operator = '=';
745
+				break;
746
+			case QueryInterface::OPERATOR_NOT_EQUAL_TO:
747
+				$operator = '!=';
748
+				break;
749
+			case QueryInterface::OPERATOR_LESS_THAN:
750
+				$operator = '<';
751
+				break;
752
+			case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO:
753
+				$operator = '<=';
754
+				break;
755
+			case QueryInterface::OPERATOR_GREATER_THAN:
756
+				$operator = '>';
757
+				break;
758
+			case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO:
759
+				$operator = '>=';
760
+				break;
761
+			case QueryInterface::OPERATOR_LIKE:
762
+				$operator = 'LIKE';
763
+				break;
764
+			default:
765
+				throw new Exception('Unsupported operator encountered.', 1242816073);
766
+		}
767
+		return $operator;
768
+	}
769
+
770
+	/**
771
+	 * Replace query placeholders in a query part by the given
772
+	 * parameters.
773
+	 *
774
+	 * @param string &$sqlString The query part with placeholders
775
+	 * @param array $parameters The parameters
776
+	 * @param string $tableName
777
+	 *
778
+	 * @throws Exception
779
+	 */
780
+	protected function replacePlaceholders(&$sqlString, array $parameters, $tableName = 'foo')
781
+	{
782
+		// TODO profile this method again
783
+		if (substr_count($sqlString, '?') !== count($parameters)) {
784
+			throw new Exception('The number of question marks to replace must be equal to the number of parameters.', 1242816074);
785
+		}
786
+		$offset = 0;
787
+		foreach ($parameters as $parameter) {
788
+			$markPosition = strpos($sqlString, '?', $offset);
789
+			if ($markPosition !== FALSE) {
790
+				if ($parameter === NULL) {
791
+					$parameter = 'NULL';
792
+				} elseif (is_array($parameter) || $parameter instanceof \ArrayAccess || $parameter instanceof \Traversable) {
793
+					$items = array();
794
+					foreach ($parameter as $item) {
795
+						$items[] = $this->databaseHandle->fullQuoteStr($item, $tableName);
796
+					}
797
+					$parameter = '(' . implode(',', $items) . ')';
798
+				} else {
799
+					$parameter = $this->databaseHandle->fullQuoteStr($parameter, $tableName);
800
+				}
801
+				$sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, ($markPosition + 1));
802
+			}
803
+			$offset = $markPosition + strlen($parameter);
804
+		}
805
+	}
806
+
807
+	/**
808
+	 * Adds additional WHERE statements according to the query settings.
809
+	 *
810
+	 * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
811
+	 * @param string $tableNameOrAlias The table name to add the additional where clause for
812
+	 * @param array &$statementParts
813
+	 * @return void
814
+	 */
815
+	protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts)
816
+	{
817
+		$this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts);
818
+		if ($querySettings->getRespectSysLanguage()) {
819
+			$this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings);
820
+		}
821
+		if ($querySettings->getRespectStoragePage()) {
822
+			$this->addPageIdStatement($tableNameOrAlias, $statementParts, $querySettings->getStoragePageIds());
823
+		}
824
+	}
825
+
826
+	/**
827
+	 * Adds enableFields and deletedClause to the query if necessary
828
+	 *
829
+	 * @param QuerySettingsInterface $querySettings
830
+	 * @param string $tableNameOrAlias The database table name
831
+	 * @param array &$statementParts The query parts
832
+	 * @return void
833
+	 */
834
+	protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts)
835
+	{
836
+		$statement = '';
837
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
838
+		if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
839
+			$ignoreEnableFields = $querySettings->getIgnoreEnableFields();
840
+			$enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored();
841
+			$includeDeleted = $querySettings->getIncludeDeleted();
842
+			if ($this->environmentService->isEnvironmentInFrontendMode()) {
843
+				$statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted);
844
+			} else {
845
+				// TYPO3_MODE === 'BE'
846
+				$statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted);
847
+			}
848
+
849
+			// Remove the prefixing "AND" if any.
850
+			if (!empty($statement)) {
851
+				$statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement;
852
+				$statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement;
853
+			}
854
+		}
855
+	}
856
+
857
+	/**
858
+	 * Returns constraint statement for frontend context
859
+	 *
860
+	 * @param string $tableNameOrAlias
861
+	 * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
862
+	 * @param array $enableFieldsToBeIgnored If $ignoreEnableFields is true, this array specifies enable fields to be ignored. If it is NULL or an empty array (default) all enable fields are ignored.
863
+	 * @param boolean $includeDeleted A flag indicating whether deleted records should be included
864
+	 * @return string
865
+	 * @throws Exception\InconsistentQuerySettingsException
866
+	 */
867
+	protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored = array(), $includeDeleted)
868
+	{
869
+		$statement = '';
870
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
871
+		if ($ignoreEnableFields && !$includeDeleted) {
872
+			if (count($enableFieldsToBeIgnored)) {
873
+				// array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented
874
+				$statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored));
875
+			} else {
876
+				$statement .= $this->getPageRepository()->deleteClause($tableName);
877
+			}
878
+		} elseif (!$ignoreEnableFields && !$includeDeleted) {
879
+			$statement .= $this->getPageRepository()->enableFields($tableName);
880
+		} elseif (!$ignoreEnableFields && $includeDeleted) {
881
+			throw new Exception\InconsistentQuerySettingsException('Query setting "ignoreEnableFields=FALSE" can not be used together with "includeDeleted=TRUE" in frontend context.', 1327678173);
882
+		}
883
+		return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
884
+	}
885
+
886
+	/**
887
+	 * Returns constraint statement for backend context
888
+	 *
889
+	 * @param string $tableNameOrAlias
890
+	 * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
891
+	 * @param boolean $includeDeleted A flag indicating whether deleted records should be included
892
+	 * @return string
893
+	 */
894
+	protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted)
895
+	{
896
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
897
+		$statement = '';
898
+		if (!$ignoreEnableFields) {
899
+			$statement .= BackendUtility::BEenableFields($tableName);
900
+		}
901
+
902
+		// If the table is found to have "workspace" support, add the corresponding fields in the statement.
903
+		if (Tca::table($tableName)->hasWorkspaceSupport()) {
904
+			if ($this->getBackendUser()->workspace === 0) {
905
+				$statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE);
906
+			} else {
907
+				// Show only records of live and of the current workspace
908
+				// In case we are in a Versioning preview
909
+				$statement .= ' AND (' .
910
+					$tableName . '.t3ver_wsid=0 OR ' .
911
+					$tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace .
912
+					')';
913
+			}
914
+
915
+			// Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0
916
+			$statement .= ' AND ' . $tableName . '.pid<>-1';
917
+		}
918
+
919
+		if (!$includeDeleted) {
920
+			$statement .= BackendUtility::deleteClause($tableName);
921
+		}
922
+
923
+		return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
924
+	}
925
+
926
+	/**
927
+	 * Builds the language field statement
928
+	 *
929
+	 * @param string $tableNameOrAlias The database table name
930
+	 * @param array &$statementParts The query parts
931
+	 * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
932
+	 * @throws Exception
933
+	 * @return void
934
+	 */
935
+	protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings)
936
+	{
937
+
938
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
939
+		if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
940
+			if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) {
941
+				// Select all entries for the current language
942
+				$additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)';
943
+				// If any language is set -> get those entries which are not translated yet
944
+				// They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode
945
+				if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
946
+					&& $querySettings->getLanguageUid() > 0
947
+				) {
948
+					$additionalWhereClause .= ' OR (' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' .
949
+						' AND ' . $tableName . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] .
950
+						' FROM ' . $tableName .
951
+						' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' .
952
+						' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0';
953
+
954
+					// Add delete clause to ensure all entries are loaded
955
+					if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) {
956
+						$additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0';
957
+					}
958
+					$additionalWhereClause .= '))';
959
+					throw new Exception('Not tested code! It will fail', 1412928284);
960
+				}
961
+				$statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')';
962
+			}
963
+		}
964
+	}
965
+
966
+	/**
967
+	 * Builds the page ID checking statement
968
+	 *
969
+	 * @param string $tableNameOrAlias The database table name
970
+	 * @param array &$statementParts The query parts
971
+	 * @param array $storagePageIds list of storage page ids
972
+	 * @throws Exception\InconsistentQuerySettingsException
973
+	 * @return void
974
+	 */
975
+	protected function addPageIdStatement($tableNameOrAlias, array &$statementParts, array $storagePageIds)
976
+	{
977
+
978
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
979
+		$tableColumns = $this->tableColumnCache->get($tableName);
980
+		if ($tableColumns === FALSE) {
981
+			$tableColumns = $this->databaseHandle->admin_get_fields($tableName);
982
+			$this->tableColumnCache->set($tableName, $tableColumns);
983
+		}
984
+		if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('pid', $tableColumns)) {
985
+			$rootLevel = (int)$GLOBALS['TCA'][$tableName]['ctrl']['rootLevel'];
986
+			if ($rootLevel) {
987
+				if ($rootLevel === 1) {
988
+					$statementParts['additionalWhereClause'][$tableNameOrAlias][] = $tableNameOrAlias . '.pid = 0';
989
+				}
990
+			} else {
991
+				if (empty($storagePageIds)) {
992
+					throw new Exception\InconsistentQuerySettingsException('Missing storage page ids.', 1365779762);
993
+				}
994
+				$statementParts['additionalWhereClause'][$tableNameOrAlias][] = $tableNameOrAlias . '.pid IN (' . implode(', ', $storagePageIds) . ')';
995
+			}
996
+		}
997
+	}
998
+
999
+	/**
1000
+	 * Transforms orderings into SQL.
1001
+	 *
1002
+	 * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
1003
+	 * @param SourceInterface $source The source
1004
+	 * @param array &$sql The query parts
1005
+	 * @throws Exception\UnsupportedOrderException
1006
+	 * @return void
1007
+	 */
1008
+	protected function parseOrderings(array $orderings, SourceInterface $source, array &$sql)
1009
+	{
1010
+		foreach ($orderings as $fieldNameAndPath => $order) {
1011
+			switch ($order) {
1012
+				case QueryInterface::ORDER_ASCENDING:
1013
+					$order = 'ASC';
1014
+					break;
1015
+				case QueryInterface::ORDER_DESCENDING:
1016
+					$order = 'DESC';
1017
+					break;
1018
+				default:
1019
+					throw new Exception\UnsupportedOrderException('Unsupported order encountered.', 1242816074);
1020
+			}
1021
+
1022
+			$tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType());
1023
+			$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName);
1024
+			$sql['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order);
1025
+		}
1026
+	}
1027
+
1028
+	/**
1029
+	 * Transforms limit and offset into SQL
1030
+	 *
1031
+	 * @param int $limit
1032
+	 * @param int $offset
1033
+	 * @param array &$sql
1034
+	 * @return void
1035
+	 */
1036
+	protected function parseLimitAndOffset($limit, $offset, array &$sql)
1037
+	{
1038
+		if ($limit !== NULL && $offset !== NULL) {
1039
+			$sql['limit'] = intval($offset) . ', ' . intval($limit);
1040
+		} elseif ($limit !== NULL) {
1041
+			$sql['limit'] = intval($limit);
1042
+		}
1043
+	}
1044
+
1045
+	/**
1046
+	 * Transforms a Resource from a database query to an array of rows.
1047
+	 *
1048
+	 * @param resource $result The result
1049
+	 * @return array The result as an array of rows (tuples)
1050
+	 */
1051
+	protected function getRowsFromResult($result)
1052
+	{
1053
+		$rows = array();
1054
+		while ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
1055
+			if (is_array($row)) {
1056
+
1057
+				// Get language uid from querySettings.
1058
+				// Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed)
1059
+				$overlaidRow = $this->doLanguageAndWorkspaceOverlay($this->query->getSource(), $row, $this->query->getQuerySettings());
1060
+				$contentObject = GeneralUtility::makeInstance($this->objectType, $this->query->getType(), $overlaidRow);
1061
+				$rows[] = $contentObject;
1062
+			}
1063
+		}
1064
+
1065
+		return $rows;
1066
+	}
1067
+
1068
+	/**
1069
+	 * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
1070
+	 * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
1071
+	 *
1072
+	 * @param SourceInterface $source The source (selector od join)
1073
+	 * @param array $row
1074
+	 * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
1075
+	 * @return array
1076
+	 */
1077
+	protected function doLanguageAndWorkspaceOverlay(SourceInterface $source, array $row, $querySettings)
1078
+	{
1079
+
1080
+		/** @var SelectorInterface $source */
1081
+		$tableName = $source->getSelectorName();
1082
+
1083
+		$pageRepository = $this->getPageRepository();
1084
+		if (is_object($GLOBALS['TSFE'])) {
1085
+			$languageMode = $GLOBALS['TSFE']->sys_language_mode;
1086
+			if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) {
1087
+				$pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace;
1088
+			}
1089
+		} else {
1090
+			$languageMode = '';
1091
+			$workspaceUid = $this->getBackendUser()->workspace;
1092
+			$pageRepository->versioningWorkspaceId = $workspaceUid;
1093
+			if ($this->getBackendUser()->workspace !== 0) {
1094
+				$pageRepository->versioningPreview = 1;
1095
+			}
1096
+		}
1097
+
1098
+		// If current row is a translation select its parent
1099
+		if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
1100
+			&& isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
1101
+		) {
1102
+			if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']])
1103
+				&& $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
1104
+			) {
1105
+				$row = $this->databaseHandle->exec_SELECTgetSingleRow(
1106
+					$tableName . '.*',
1107
+					$tableName,
1108
+					$tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] .
1109
+					' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0'
1110
+				);
1111
+			}
1112
+		}
1113
+
1114
+		// Retrieve the original uid
1115
+		// @todo It looks for me this code will never be used! "_ORIG_uid" is something from extbase. Adjust me or remove me in 0.4 + 2 version!
1116
+		$pageRepository->versionOL($tableName, $row, TRUE);
1117
+		if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) {
1118
+			$row['uid'] = $row['_ORIG_uid'];
1119
+		}
1120
+
1121
+		// Special case for table "pages"
1122
+		if ($tableName == 'pages') {
1123
+			$row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
1124
+		} elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
1125
+			&& $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== ''
1126
+		) {
1127
+			if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
1128
+				$overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : '';
1129
+				$row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
1130
+			}
1131
+		}
1132
+
1133
+		return $row;
1134
+	}
1135
+
1136
+	/**
1137
+	 * Return a resolved table name given a possible table name alias.
1138
+	 *
1139
+	 * @param string $tableNameOrAlias
1140
+	 * @return string
1141
+	 */
1142
+	protected function resolveTableNameAlias($tableNameOrAlias)
1143
+	{
1144
+		$resolvedTableName = $tableNameOrAlias;
1145
+		if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) {
1146
+			$resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias];
1147
+		}
1148
+		return $resolvedTableName;
1149
+	}
1150
+
1151
+	/**
1152
+	 * Generate a unique table name alias for the given table name.
1153
+	 *
1154
+	 * @param string $tableName
1155
+	 * @return string
1156
+	 */
1157
+	protected function generateAlias($tableName)
1158
+	{
1159
+
1160
+		if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) {
1161
+			$this->tableNameAliases['aliasIncrement'][$tableName] = 0;
1162
+		}
1163
+
1164
+		$numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName];
1165
+		$tableNameAlias = $tableName . $numberOfAliases;
1166
+
1167
+		$this->tableNameAliases['aliasIncrement'][$tableName]++;
1168
+		$this->tableNameAliases['aliases'][$tableNameAlias] = $tableName;
1169
+
1170
+		return $tableNameAlias;
1171
+	}
1172
+
1173
+	/**
1174
+	 * Replace the table names by its table name alias within the given statement.
1175
+	 *
1176
+	 * @param string $tableName
1177
+	 * @param string $tableNameAlias
1178
+	 * @param string $statement
1179
+	 * @return string
1180
+	 */
1181
+	protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement)
1182
+	{
1183
+		if ($statement && $tableName !== $tableNameAlias) {
1184
+			$statement = str_replace($tableName, $tableNameAlias, $statement);
1185
+		}
1186
+		return $statement;
1187
+	}
1188
+
1189
+	/**
1190
+	 * Returns an instance of the current Backend User.
1191
+	 *
1192
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1193
+	 */
1194
+	protected function getBackendUser()
1195
+	{
1196
+		return $GLOBALS['BE_USER'];
1197
+	}
1198
+
1199
+	/**
1200
+	 * Tell whether a Backend User is logged in.
1201
+	 *
1202
+	 * @return bool
1203
+	 */
1204
+	protected function isBackendUserLogged()
1205
+	{
1206
+		return is_object($GLOBALS['BE_USER']);
1207
+	}
1208
+
1209
+	/**
1210
+	 * @return PageRepository
1211
+	 */
1212
+	protected function getPageRepository()
1213
+	{
1214
+		if (!$this->pageRepository instanceof PageRepository) {
1215
+			if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($GLOBALS['TSFE'])) {
1216
+				$this->pageRepository = $GLOBALS['TSFE']->sys_page;
1217
+			} else {
1218
+				$this->pageRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
1219
+			}
1220
+		}
1221
+
1222
+		return $this->pageRepository;
1223
+	}
1224
+
1225
+	/**
1226
+	 * @return \Fab\Vidi\Resolver\FieldPathResolver
1227
+	 */
1228
+	protected function getFieldPathResolver()
1229
+	{
1230
+		return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
1231
+	}
1232
+
1233
+	/**
1234
+	 * Checks if there are SQL errors in the last query, and if yes, throw an exception.
1235
+	 *
1236
+	 * @return void
1237
+	 * @param string $sql The SQL statement
1238
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException
1239
+	 */
1240
+	protected function checkSqlErrors($sql = '')
1241
+	{
1242
+		$error = $this->databaseHandle->sql_error();
1243
+		if ($error !== '') {
1244
+			$error .= $sql ? ': ' . $sql : '';
1245
+			throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($error, 1247602160);
1246
+		}
1247
+	}
1248 1248
 }
Please login to merge, or discard this patch.
Classes/Persistence/Order.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -20,45 +20,45 @@
 block discarded – undo
20 20
 class Order
21 21
 {
22 22
 
23
-    /**
24
-     * The orderings
25
-     *
26
-     * @var array
27
-     */
28
-    protected $orderings = array();
23
+	/**
24
+	 * The orderings
25
+	 *
26
+	 * @var array
27
+	 */
28
+	protected $orderings = array();
29 29
 
30
-    /**
31
-     * Constructs a new Order
32
-     *
33
-     * @para array $orders
34
-     * @param array $orders
35
-     */
36
-    public function __construct($orders = array())
37
-    {
38
-        foreach ($orders as $order => $direction) {
39
-            $this->addOrdering($order, $direction);
40
-        }
41
-    }
30
+	/**
31
+	 * Constructs a new Order
32
+	 *
33
+	 * @para array $orders
34
+	 * @param array $orders
35
+	 */
36
+	public function __construct($orders = array())
37
+	{
38
+		foreach ($orders as $order => $direction) {
39
+			$this->addOrdering($order, $direction);
40
+		}
41
+	}
42 42
 
43
-    /**
44
-     * Add ordering
45
-     *
46
-     * @param string $order The order
47
-     * @param string $direction ASC / DESC
48
-     * @return void
49
-     */
50
-    public function addOrdering($order, $direction)
51
-    {
52
-        $this->orderings[$order] = $direction;
53
-    }
43
+	/**
44
+	 * Add ordering
45
+	 *
46
+	 * @param string $order The order
47
+	 * @param string $direction ASC / DESC
48
+	 * @return void
49
+	 */
50
+	public function addOrdering($order, $direction)
51
+	{
52
+		$this->orderings[$order] = $direction;
53
+	}
54 54
 
55
-    /**
56
-     * Returns the order
57
-     *
58
-     * @return array The order
59
-     */
60
-    public function getOrderings()
61
-    {
62
-        return $this->orderings;
63
-    }
55
+	/**
56
+	 * Returns the order
57
+	 *
58
+	 * @return array The order
59
+	 */
60
+	public function getOrderings()
61
+	{
62
+		return $this->orderings;
63
+	}
64 64
 }
Please login to merge, or discard this patch.
Classes/Persistence/QuerySettings.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -24,19 +24,19 @@
 block discarded – undo
24 24
 class QuerySettings extends Typo3QuerySettings
25 25
 {
26 26
 
27
-    /**
28
-     * Flag if the storage page should be respected for the query.
29
-     *
30
-     * @var boolean
31
-     */
32
-    protected $respectStoragePage = FALSE;
27
+	/**
28
+	 * Flag if the storage page should be respected for the query.
29
+	 *
30
+	 * @var boolean
31
+	 */
32
+	protected $respectStoragePage = FALSE;
33 33
 
34
-    /**
35
-     * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
36
-     * initializeObject is responsible for handling that.
37
-     */
38
-    public function initializeObject()
39
-    {
40
-        parent::initializeObject();
41
-    }
34
+	/**
35
+	 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
36
+	 * initializeObject is responsible for handling that.
37
+	 */
38
+	public function initializeObject()
39
+	{
40
+		parent::initializeObject();
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Classes/Persistence/Matcher.php 1 patch
Indentation   +286 added lines, -286 removed lines patch added patch discarded remove patch
@@ -20,290 +20,290 @@
 block discarded – undo
20 20
 class Matcher
21 21
 {
22 22
 
23
-    /**
24
-     * The logical OR
25
-     */
26
-    const LOGICAL_OR = 'logicalOr';
27
-
28
-    /**
29
-     * The logical AND
30
-     */
31
-    const LOGICAL_AND = 'logicalAnd';
32
-
33
-    /**
34
-     * @var string
35
-     */
36
-    protected $dataType = '';
37
-
38
-    /**
39
-     * @var string
40
-     */
41
-    protected $searchTerm = '';
42
-
43
-    /**
44
-     * @var array
45
-     */
46
-    protected $supportedOperators = array('equals', 'in', 'like');
47
-
48
-    /**
49
-     * Associative values used for "equals" operator ($fieldName => $value)
50
-     *
51
-     * @var array
52
-     */
53
-    protected $equalsCriteria = array();
54
-
55
-    /**
56
-     * Associative values used for "in" operator ($fieldName => $value)
57
-     *
58
-     * @var array
59
-     */
60
-    protected $inCriteria = array();
61
-
62
-    /**
63
-     * Associative values used for "like" operator ($fieldName => $value)
64
-     *
65
-     * @var array
66
-     */
67
-    protected $likeCriteria = array();
68
-
69
-    /**
70
-     * Default logical operator for like.
71
-     *
72
-     * @var string
73
-     */
74
-    protected $defaultLogicalSeparator = self::LOGICAL_AND;
75
-
76
-    /**
77
-     * Default logical operator for equals.
78
-     *
79
-     * @var string
80
-     */
81
-    protected $logicalSeparatorForEquals = self::LOGICAL_AND;
82
-
83
-    /**
84
-     * Default logical operator for equals.
85
-     *
86
-     * @var string
87
-     */
88
-    protected $logicalSeparatorForIn = self::LOGICAL_AND;
89
-
90
-    /**
91
-     * Default logical operator for like.
92
-     *
93
-     * @var string
94
-     */
95
-    protected $logicalSeparatorForLike = self::LOGICAL_AND;
96
-
97
-    /**
98
-     * Default logical operator for the search term.
99
-     *
100
-     * @var string
101
-     */
102
-    protected $logicalSeparatorForSearchTerm = self::LOGICAL_OR;
103
-
104
-    /**
105
-     * Constructs a new Matcher
106
-     *
107
-     * @param array $matches associative array($field => $value)
108
-     * @param string $dataType which corresponds to an entry of the TCA (table name).
109
-     * @return \Fab\Vidi\Persistence\Matcher
110
-     */
111
-    public function __construct($matches = array(), $dataType = '')
112
-    {
113
-        $this->dataType = $dataType;
114
-        $this->matches = $matches;
115
-    }
116
-
117
-    /**
118
-     * @param string $searchTerm
119
-     * @return \Fab\Vidi\Persistence\Matcher
120
-     */
121
-    public function setSearchTerm($searchTerm)
122
-    {
123
-        $this->searchTerm = $searchTerm;
124
-        return $this;
125
-    }
126
-
127
-    /**
128
-     * @return string
129
-     */
130
-    public function getSearchTerm()
131
-    {
132
-        return $this->searchTerm;
133
-    }
134
-
135
-    /**
136
-     * @return array
137
-     */
138
-    public function getEqualsCriteria()
139
-    {
140
-        return $this->equalsCriteria;
141
-    }
142
-
143
-    /**
144
-     * @param $fieldNameAndPath
145
-     * @param $operand
146
-     * @return $this
147
-     */
148
-    public function equals($fieldNameAndPath, $operand)
149
-    {
150
-        $this->equalsCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand);
151
-        return $this;
152
-    }
153
-
154
-    /**
155
-     * @return array
156
-     */
157
-    public function getLikeCriteria()
158
-    {
159
-        return $this->likeCriteria;
160
-    }
161
-
162
-    /**
163
-     * @param $fieldNameAndPath
164
-     * @param $operand
165
-     * @return $this
166
-     */
167
-    public function in($fieldNameAndPath, $operand)
168
-    {
169
-        $this->inCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand);
170
-        return $this;
171
-    }
172
-
173
-    /**
174
-     * @return array
175
-     */
176
-    public function getInCriteria()
177
-    {
178
-        return $this->inCriteria;
179
-    }
180
-
181
-    /**
182
-     * @param $fieldNameAndPath
183
-     * @param $operand
184
-     * @param bool $addWildCard
185
-     * @return $this
186
-     */
187
-    public function like($fieldNameAndPath, $operand, $addWildCard = TRUE)
188
-    {
189
-        $wildCardSymbol = $addWildCard ? '%' : '';
190
-        $this->likeCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $wildCardSymbol . $operand . $wildCardSymbol);
191
-        return $this;
192
-    }
193
-
194
-    /**
195
-     * @return array
196
-     */
197
-    public function getDefaultLogicalSeparator()
198
-    {
199
-        return $this->defaultLogicalSeparator;
200
-    }
201
-
202
-    /**
203
-     * @param string $defaultLogicalSeparator
204
-     * @return $this
205
-     */
206
-    public function setDefaultLogicalSeparator($defaultLogicalSeparator)
207
-    {
208
-        $this->defaultLogicalSeparator = $defaultLogicalSeparator;
209
-        return $this;
210
-    }
211
-
212
-    /**
213
-     * @return string
214
-     */
215
-    public function getLogicalSeparatorForEquals()
216
-    {
217
-        return $this->logicalSeparatorForEquals;
218
-    }
219
-
220
-    /**
221
-     * @param string $logicalSeparatorForEquals
222
-     * @return $this
223
-     */
224
-    public function setLogicalSeparatorForEquals($logicalSeparatorForEquals)
225
-    {
226
-        $this->logicalSeparatorForEquals = $logicalSeparatorForEquals;
227
-        return $this;
228
-    }
229
-
230
-    /**
231
-     * @return string
232
-     */
233
-    public function getLogicalSeparatorForIn()
234
-    {
235
-        return $this->logicalSeparatorForIn;
236
-    }
237
-
238
-    /**
239
-     * @param string $logicalSeparatorForIn
240
-     * @return $this
241
-     */
242
-    public function setLogicalSeparatorForIn($logicalSeparatorForIn)
243
-    {
244
-        $this->logicalSeparatorForIn = $logicalSeparatorForIn;
245
-        return $this;
246
-    }
247
-
248
-    /**
249
-     * @return string
250
-     */
251
-    public function getLogicalSeparatorForLike()
252
-    {
253
-        return $this->logicalSeparatorForLike;
254
-    }
255
-
256
-    /**
257
-     * @param string $logicalSeparatorForLike
258
-     * @return $this
259
-     */
260
-    public function setLogicalSeparatorForLike($logicalSeparatorForLike)
261
-    {
262
-        $this->logicalSeparatorForLike = $logicalSeparatorForLike;
263
-        return $this;
264
-    }
265
-
266
-    /**
267
-     * @return string
268
-     */
269
-    public function getLogicalSeparatorForSearchTerm()
270
-    {
271
-        return $this->logicalSeparatorForSearchTerm;
272
-    }
273
-
274
-    /**
275
-     * @param string $logicalSeparatorForSearchTerm
276
-     * @return $this
277
-     */
278
-    public function setLogicalSeparatorForSearchTerm($logicalSeparatorForSearchTerm)
279
-    {
280
-        $this->logicalSeparatorForSearchTerm = $logicalSeparatorForSearchTerm;
281
-        return $this;
282
-    }
283
-
284
-    /**
285
-     * @return array
286
-     */
287
-    public function getSupportedOperators()
288
-    {
289
-        return $this->supportedOperators;
290
-    }
291
-
292
-    /**
293
-     * @return string
294
-     */
295
-    public function getDataType()
296
-    {
297
-        return $this->dataType;
298
-    }
299
-
300
-    /**
301
-     * @param string $dataType
302
-     * @return $this
303
-     */
304
-    public function setDataType($dataType)
305
-    {
306
-        $this->dataType = $dataType;
307
-        return $this;
308
-    }
23
+	/**
24
+	 * The logical OR
25
+	 */
26
+	const LOGICAL_OR = 'logicalOr';
27
+
28
+	/**
29
+	 * The logical AND
30
+	 */
31
+	const LOGICAL_AND = 'logicalAnd';
32
+
33
+	/**
34
+	 * @var string
35
+	 */
36
+	protected $dataType = '';
37
+
38
+	/**
39
+	 * @var string
40
+	 */
41
+	protected $searchTerm = '';
42
+
43
+	/**
44
+	 * @var array
45
+	 */
46
+	protected $supportedOperators = array('equals', 'in', 'like');
47
+
48
+	/**
49
+	 * Associative values used for "equals" operator ($fieldName => $value)
50
+	 *
51
+	 * @var array
52
+	 */
53
+	protected $equalsCriteria = array();
54
+
55
+	/**
56
+	 * Associative values used for "in" operator ($fieldName => $value)
57
+	 *
58
+	 * @var array
59
+	 */
60
+	protected $inCriteria = array();
61
+
62
+	/**
63
+	 * Associative values used for "like" operator ($fieldName => $value)
64
+	 *
65
+	 * @var array
66
+	 */
67
+	protected $likeCriteria = array();
68
+
69
+	/**
70
+	 * Default logical operator for like.
71
+	 *
72
+	 * @var string
73
+	 */
74
+	protected $defaultLogicalSeparator = self::LOGICAL_AND;
75
+
76
+	/**
77
+	 * Default logical operator for equals.
78
+	 *
79
+	 * @var string
80
+	 */
81
+	protected $logicalSeparatorForEquals = self::LOGICAL_AND;
82
+
83
+	/**
84
+	 * Default logical operator for equals.
85
+	 *
86
+	 * @var string
87
+	 */
88
+	protected $logicalSeparatorForIn = self::LOGICAL_AND;
89
+
90
+	/**
91
+	 * Default logical operator for like.
92
+	 *
93
+	 * @var string
94
+	 */
95
+	protected $logicalSeparatorForLike = self::LOGICAL_AND;
96
+
97
+	/**
98
+	 * Default logical operator for the search term.
99
+	 *
100
+	 * @var string
101
+	 */
102
+	protected $logicalSeparatorForSearchTerm = self::LOGICAL_OR;
103
+
104
+	/**
105
+	 * Constructs a new Matcher
106
+	 *
107
+	 * @param array $matches associative array($field => $value)
108
+	 * @param string $dataType which corresponds to an entry of the TCA (table name).
109
+	 * @return \Fab\Vidi\Persistence\Matcher
110
+	 */
111
+	public function __construct($matches = array(), $dataType = '')
112
+	{
113
+		$this->dataType = $dataType;
114
+		$this->matches = $matches;
115
+	}
116
+
117
+	/**
118
+	 * @param string $searchTerm
119
+	 * @return \Fab\Vidi\Persistence\Matcher
120
+	 */
121
+	public function setSearchTerm($searchTerm)
122
+	{
123
+		$this->searchTerm = $searchTerm;
124
+		return $this;
125
+	}
126
+
127
+	/**
128
+	 * @return string
129
+	 */
130
+	public function getSearchTerm()
131
+	{
132
+		return $this->searchTerm;
133
+	}
134
+
135
+	/**
136
+	 * @return array
137
+	 */
138
+	public function getEqualsCriteria()
139
+	{
140
+		return $this->equalsCriteria;
141
+	}
142
+
143
+	/**
144
+	 * @param $fieldNameAndPath
145
+	 * @param $operand
146
+	 * @return $this
147
+	 */
148
+	public function equals($fieldNameAndPath, $operand)
149
+	{
150
+		$this->equalsCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand);
151
+		return $this;
152
+	}
153
+
154
+	/**
155
+	 * @return array
156
+	 */
157
+	public function getLikeCriteria()
158
+	{
159
+		return $this->likeCriteria;
160
+	}
161
+
162
+	/**
163
+	 * @param $fieldNameAndPath
164
+	 * @param $operand
165
+	 * @return $this
166
+	 */
167
+	public function in($fieldNameAndPath, $operand)
168
+	{
169
+		$this->inCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand);
170
+		return $this;
171
+	}
172
+
173
+	/**
174
+	 * @return array
175
+	 */
176
+	public function getInCriteria()
177
+	{
178
+		return $this->inCriteria;
179
+	}
180
+
181
+	/**
182
+	 * @param $fieldNameAndPath
183
+	 * @param $operand
184
+	 * @param bool $addWildCard
185
+	 * @return $this
186
+	 */
187
+	public function like($fieldNameAndPath, $operand, $addWildCard = TRUE)
188
+	{
189
+		$wildCardSymbol = $addWildCard ? '%' : '';
190
+		$this->likeCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $wildCardSymbol . $operand . $wildCardSymbol);
191
+		return $this;
192
+	}
193
+
194
+	/**
195
+	 * @return array
196
+	 */
197
+	public function getDefaultLogicalSeparator()
198
+	{
199
+		return $this->defaultLogicalSeparator;
200
+	}
201
+
202
+	/**
203
+	 * @param string $defaultLogicalSeparator
204
+	 * @return $this
205
+	 */
206
+	public function setDefaultLogicalSeparator($defaultLogicalSeparator)
207
+	{
208
+		$this->defaultLogicalSeparator = $defaultLogicalSeparator;
209
+		return $this;
210
+	}
211
+
212
+	/**
213
+	 * @return string
214
+	 */
215
+	public function getLogicalSeparatorForEquals()
216
+	{
217
+		return $this->logicalSeparatorForEquals;
218
+	}
219
+
220
+	/**
221
+	 * @param string $logicalSeparatorForEquals
222
+	 * @return $this
223
+	 */
224
+	public function setLogicalSeparatorForEquals($logicalSeparatorForEquals)
225
+	{
226
+		$this->logicalSeparatorForEquals = $logicalSeparatorForEquals;
227
+		return $this;
228
+	}
229
+
230
+	/**
231
+	 * @return string
232
+	 */
233
+	public function getLogicalSeparatorForIn()
234
+	{
235
+		return $this->logicalSeparatorForIn;
236
+	}
237
+
238
+	/**
239
+	 * @param string $logicalSeparatorForIn
240
+	 * @return $this
241
+	 */
242
+	public function setLogicalSeparatorForIn($logicalSeparatorForIn)
243
+	{
244
+		$this->logicalSeparatorForIn = $logicalSeparatorForIn;
245
+		return $this;
246
+	}
247
+
248
+	/**
249
+	 * @return string
250
+	 */
251
+	public function getLogicalSeparatorForLike()
252
+	{
253
+		return $this->logicalSeparatorForLike;
254
+	}
255
+
256
+	/**
257
+	 * @param string $logicalSeparatorForLike
258
+	 * @return $this
259
+	 */
260
+	public function setLogicalSeparatorForLike($logicalSeparatorForLike)
261
+	{
262
+		$this->logicalSeparatorForLike = $logicalSeparatorForLike;
263
+		return $this;
264
+	}
265
+
266
+	/**
267
+	 * @return string
268
+	 */
269
+	public function getLogicalSeparatorForSearchTerm()
270
+	{
271
+		return $this->logicalSeparatorForSearchTerm;
272
+	}
273
+
274
+	/**
275
+	 * @param string $logicalSeparatorForSearchTerm
276
+	 * @return $this
277
+	 */
278
+	public function setLogicalSeparatorForSearchTerm($logicalSeparatorForSearchTerm)
279
+	{
280
+		$this->logicalSeparatorForSearchTerm = $logicalSeparatorForSearchTerm;
281
+		return $this;
282
+	}
283
+
284
+	/**
285
+	 * @return array
286
+	 */
287
+	public function getSupportedOperators()
288
+	{
289
+		return $this->supportedOperators;
290
+	}
291
+
292
+	/**
293
+	 * @return string
294
+	 */
295
+	public function getDataType()
296
+	{
297
+		return $this->dataType;
298
+	}
299
+
300
+	/**
301
+	 * @param string $dataType
302
+	 * @return $this
303
+	 */
304
+	public function setDataType($dataType)
305
+	{
306
+		$this->dataType = $dataType;
307
+		return $this;
308
+	}
309 309
 }
Please login to merge, or discard this patch.
Classes/Persistence/OrderObjectFactory.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -24,43 +24,43 @@
 block discarded – undo
24 24
 class OrderObjectFactory implements SingletonInterface
25 25
 {
26 26
 
27
-    /**
28
-     * Gets a singleton instance of this class.
29
-     *
30
-     * @return \Fab\Vidi\Persistence\OrderObjectFactory
31
-     */
32
-    static public function getInstance()
33
-    {
34
-        return GeneralUtility::makeInstance('Fab\Vidi\Persistence\OrderObjectFactory');
35
-    }
27
+	/**
28
+	 * Gets a singleton instance of this class.
29
+	 *
30
+	 * @return \Fab\Vidi\Persistence\OrderObjectFactory
31
+	 */
32
+	static public function getInstance()
33
+	{
34
+		return GeneralUtility::makeInstance('Fab\Vidi\Persistence\OrderObjectFactory');
35
+	}
36 36
 
37
-    /**
38
-     * Returns an order object.
39
-     *
40
-     * @param string $dataType
41
-     * @return \Fab\Vidi\Persistence\Order
42
-     */
43
-    public function getOrder($dataType = '')
44
-    {
37
+	/**
38
+	 * Returns an order object.
39
+	 *
40
+	 * @param string $dataType
41
+	 * @return \Fab\Vidi\Persistence\Order
42
+	 */
43
+	public function getOrder($dataType = '')
44
+	{
45 45
 
46
-        // Default ordering
47
-        $order = Tca::table($dataType)->getDefaultOrderings();
46
+		// Default ordering
47
+		$order = Tca::table($dataType)->getDefaultOrderings();
48 48
 
49
-        // Retrieve a possible id of the column from the request
50
-        $orderings = GeneralUtility::_GP('order');
49
+		// Retrieve a possible id of the column from the request
50
+		$orderings = GeneralUtility::_GP('order');
51 51
 
52
-        if (is_array($orderings) && isset($orderings[0])) {
53
-            $columnPosition = $orderings[0]['column'];
54
-            $direction = $orderings[0]['dir'];
52
+		if (is_array($orderings) && isset($orderings[0])) {
53
+			$columnPosition = $orderings[0]['column'];
54
+			$direction = $orderings[0]['dir'];
55 55
 
56
-            if ($columnPosition > 0) {
57
-                $field = Tca::grid()->getFieldNameByPosition($columnPosition);
56
+			if ($columnPosition > 0) {
57
+				$field = Tca::grid()->getFieldNameByPosition($columnPosition);
58 58
 
59
-                $order = array(
60
-                    $field => strtoupper($direction)
61
-                );
62
-            }
63
-        }
64
-        return GeneralUtility::makeInstance('Fab\Vidi\Persistence\Order', $order);
65
-    }
59
+				$order = array(
60
+					$field => strtoupper($direction)
61
+				);
62
+			}
63
+		}
64
+		return GeneralUtility::makeInstance('Fab\Vidi\Persistence\Order', $order);
65
+	}
66 66
 }
Please login to merge, or discard this patch.
Classes/Persistence/Query.php 1 patch
Indentation   +644 added lines, -644 removed lines patch added patch discarded remove patch
@@ -29,649 +29,649 @@
 block discarded – undo
29 29
 class Query implements QueryInterface
30 30
 {
31 31
 
32
-    /**
33
-     * An inner join.
34
-     */
35
-    const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner';
36
-
37
-    /**
38
-     * A left-outer join.
39
-     */
40
-    const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter';
41
-
42
-    /**
43
-     * A right-outer join.
44
-     */
45
-    const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter';
46
-
47
-    /**
48
-     * Charset of strings in QOM
49
-     */
50
-    const CHARSET = 'utf-8';
51
-
52
-    /**
53
-     * @var string
54
-     */
55
-    protected $sourceFieldName;
56
-
57
-    /**
58
-     * @var string
59
-     */
60
-    protected $type;
61
-
62
-    /**
63
-     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
64
-     */
65
-    protected $objectManager;
66
-
67
-    /**
68
-     * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
69
-     */
70
-    protected $persistenceManager;
71
-
72
-    /**
73
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
74
-     */
75
-    protected $qomFactory;
76
-
77
-    /**
78
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface
79
-     */
80
-    protected $source;
81
-
82
-    /**
83
-     * @var ConstraintInterface
84
-     */
85
-    protected $constraint;
86
-
87
-    /**
88
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
89
-     */
90
-    protected $statement;
91
-
92
-    /**
93
-     * @var int
94
-     */
95
-    protected $orderings = array();
96
-
97
-    /**
98
-     * @var int
99
-     */
100
-    protected $limit;
101
-
102
-    /**
103
-     * @var int
104
-     */
105
-    protected $offset;
106
-
107
-    /**
108
-     * Apply DISTINCT upon property.
109
-     *
110
-     * @var string
111
-     */
112
-    protected $distinct;
113
-
114
-    /**
115
-     * The query settings.
116
-     *
117
-     * @var \Fab\Vidi\Persistence\QuerySettings
118
-     * @inject
119
-     */
120
-    protected $querySettings;
121
-
122
-    /**
123
-     * Constructs a query object working on the given class name
124
-     *
125
-     * @param string $type
126
-     */
127
-    public function __construct($type)
128
-    {
129
-        $this->type = $type;
130
-    }
131
-
132
-    /**
133
-     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
134
-     * @return void
135
-     */
136
-    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
137
-    {
138
-        $this->objectManager = $objectManager;
139
-    }
140
-
141
-    /**
142
-     * Injects the persistence manager, used to fetch the CR session
143
-     *
144
-     * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
145
-     * @return void
146
-     */
147
-    public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
148
-    {
149
-        $this->persistenceManager = $persistenceManager;
150
-    }
151
-
152
-    /**
153
-     * Injects the Query Object Model Factory
154
-     *
155
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory
156
-     * @return void
157
-     */
158
-    public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory)
159
-    {
160
-        $this->qomFactory = $qomFactory;
161
-    }
162
-
163
-    /**
164
-     * Sets the Query Settings. These Query settings must match the settings expected by
165
-     * the specific Storage Backend.
166
-     *
167
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
168
-     * @return void
169
-     * @api This method is not part of FLOW3 API
170
-     */
171
-    public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings)
172
-    {
173
-        $this->querySettings = $querySettings;
174
-    }
175
-
176
-    /**
177
-     * Returns the Query Settings.
178
-     *
179
-     * @throws \Exception
180
-     * @return \Fab\Vidi\Persistence\QuerySettings $querySettings The Query Settings
181
-     * @api This method is not part of FLOW3 API
182
-     */
183
-    public function getQuerySettings()
184
-    {
185
-        if (!$this->querySettings instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface) {
186
-            throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('Tried to get the query settings without setting them before.', 1248689115);
187
-        }
188
-
189
-        // Apply possible settings to the query.
190
-        if ($this->isBackendMode()) {
191
-            /** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */
192
-            $backendConfigurationManager = $this->objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
193
-            $configuration = $backendConfigurationManager->getTypoScriptSetup();
194
-            $querySettings = array('respectSysLanguage');
195
-            foreach ($querySettings as $setting) {
196
-                if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) {
197
-                    $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting];
198
-                    ObjectAccess::setProperty($this->querySettings, $setting, $value);
199
-                }
200
-            }
201
-        }
202
-
203
-        return $this->querySettings;
204
-    }
205
-
206
-    /**
207
-     * Returns the type this query cares for.
208
-     *
209
-     * @return string
210
-     * @api
211
-     */
212
-    public function getType()
213
-    {
214
-        return $this->type;
215
-    }
216
-
217
-    /**
218
-     * Sets the source to fetch the result from
219
-     *
220
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
221
-     */
222
-    public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source)
223
-    {
224
-        $this->source = $source;
225
-    }
226
-
227
-    /**
228
-     * Returns the selectorn name or an empty string, if the source is not a selector
229
-     * TODO This has to be checked at another place
230
-     *
231
-     * @return string The selector name
232
-     */
233
-    protected function getSelectorName()
234
-    {
235
-        if ($this->getSource() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
236
-            return $this->source->getSelectorName();
237
-        } else {
238
-            return '';
239
-        }
240
-    }
241
-
242
-    /**
243
-     * Gets the node-tuple source for this query.
244
-     *
245
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-null
246
-     */
247
-    public function getSource()
248
-    {
249
-        if ($this->source === NULL) {
250
-            $this->source = $this->qomFactory->selector($this->getType());
251
-        }
252
-        return $this->source;
253
-    }
254
-
255
-    /**
256
-     * Executes the query against the database and returns the result
257
-     *
258
-     * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE
259
-     * @api
260
-     */
261
-    public function execute($returnRawQueryResult = FALSE)
262
-    {
263
-        /** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
264
-        $backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
265
-        return $backend->fetchResult();
266
-    }
267
-
268
-    /**
269
-     * Sets the property names to order the result by. Expected like this:
270
-     * array(
271
-     * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
272
-     * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
273
-     * )
274
-     * where 'foo' and 'bar' are property names.
275
-     *
276
-     * @param array $orderings The property names to order by
277
-     * @return QueryInterface
278
-     * @api
279
-     */
280
-    public function setOrderings(array $orderings)
281
-    {
282
-        $this->orderings = $orderings;
283
-        return $this;
284
-    }
285
-
286
-    /**
287
-     * Returns the property names to order the result by. Like this:
288
-     * array(
289
-     * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
290
-     * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
291
-     * )
292
-     *
293
-     * @return array
294
-     * @api
295
-     */
296
-    public function getOrderings()
297
-    {
298
-        return $this->orderings;
299
-    }
300
-
301
-    /**
302
-     * Sets the maximum size of the result set to limit. Returns $this to allow
303
-     * for chaining (fluid interface)
304
-     *
305
-     * @param integer $limit
306
-     * @throws \InvalidArgumentException
307
-     * @return QueryInterface
308
-     * @api
309
-     */
310
-    public function setLimit($limit)
311
-    {
312
-        if (!is_int($limit) || $limit < 1) {
313
-            throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870);
314
-        }
315
-        $this->limit = $limit;
316
-        return $this;
317
-    }
318
-
319
-    /**
320
-     * Resets a previously set maximum size of the result set. Returns $this to allow
321
-     * for chaining (fluid interface)
322
-     *
323
-     * @return QueryInterface
324
-     * @api
325
-     */
326
-    public function unsetLimit()
327
-    {
328
-        unset($this->limit);
329
-        return $this;
330
-    }
331
-
332
-    /**
333
-     * Returns the maximum size of the result set to limit.
334
-     *
335
-     * @return integer
336
-     * @api
337
-     */
338
-    public function getLimit()
339
-    {
340
-        return $this->limit;
341
-    }
342
-
343
-    /**
344
-     * Sets the start offset of the result set to offset. Returns $this to
345
-     * allow for chaining (fluid interface)
346
-     *
347
-     * @param integer $offset
348
-     * @throws \InvalidArgumentException
349
-     * @return QueryInterface
350
-     * @api
351
-     */
352
-    public function setOffset($offset)
353
-    {
354
-        if (!is_int($offset) || $offset < 0) {
355
-            throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872);
356
-        }
357
-        $this->offset = $offset;
358
-        return $this;
359
-    }
360
-
361
-    /**
362
-     * Returns the start offset of the result set.
363
-     *
364
-     * @return integer
365
-     * @api
366
-     */
367
-    public function getOffset()
368
-    {
369
-        return $this->offset;
370
-    }
371
-
372
-    /**
373
-     * The constraint used to limit the result set. Returns $this to allow
374
-     * for chaining (fluid interface)
375
-     *
376
-     * @param ConstraintInterface $constraint
377
-     * @return QueryInterface
378
-     * @api
379
-     */
380
-    public function matching($constraint)
381
-    {
382
-        $this->constraint = $constraint;
383
-        return $this;
384
-    }
385
-
386
-    /**
387
-     * Gets the constraint for this query.
388
-     *
389
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Constraint the constraint, or null if none
390
-     * @api
391
-     */
392
-    public function getConstraint()
393
-    {
394
-        return $this->constraint;
395
-    }
396
-
397
-    /**
398
-     * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND.
399
-     * It also scepts a single array of constraints to be concatenated.
400
-     *
401
-     * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
402
-     * @throws InvalidNumberOfConstraintsException
403
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface
404
-     * @api
405
-     */
406
-    public function logicalAnd($constraint1)
407
-    {
408
-        if (is_array($constraint1)) {
409
-            $resultingConstraint = array_shift($constraint1);
410
-            $constraints = $constraint1;
411
-        } else {
412
-            $constraints = func_get_args();
413
-            $resultingConstraint = array_shift($constraints);
414
-        }
415
-        if ($resultingConstraint === NULL) {
416
-            throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500);
417
-        }
418
-        foreach ($constraints as $constraint) {
419
-            $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint);
420
-        }
421
-        return $resultingConstraint;
422
-    }
423
-
424
-    /**
425
-     * Performs a logical disjunction of the two given constraints
426
-     *
427
-     * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
428
-     * @throws InvalidNumberOfConstraintsException
429
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface
430
-     * @api
431
-     */
432
-    public function logicalOr($constraint1)
433
-    {
434
-        if (is_array($constraint1)) {
435
-            $resultingConstraint = array_shift($constraint1);
436
-            $constraints = $constraint1;
437
-        } else {
438
-            $constraints = func_get_args();
439
-            $resultingConstraint = array_shift($constraints);
440
-        }
441
-        if ($resultingConstraint === NULL) {
442
-            throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501);
443
-        }
444
-        foreach ($constraints as $constraint) {
445
-            $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint);
446
-        }
447
-        return $resultingConstraint;
448
-    }
449
-
450
-    /**
451
-     * Performs a logical negation of the given constraint
452
-     *
453
-     * @param ConstraintInterface $constraint Constraint to negate
454
-     * @throws \RuntimeException
455
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
456
-     * @api
457
-     */
458
-    public function logicalNot(ConstraintInterface $constraint)
459
-    {
460
-        return $this->qomFactory->not($constraint);
461
-    }
462
-
463
-    /**
464
-     * Returns an equals criterion used for matching objects against a query
465
-     *
466
-     * @param string $propertyName The name of the property to compare against
467
-     * @param mixed $operand The value to compare with
468
-     * @param boolean $caseSensitive Whether the equality test should be done case-sensitive
469
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
470
-     * @api
471
-     */
472
-    public function equals($propertyName, $operand, $caseSensitive = TRUE)
473
-    {
474
-        if (is_object($operand) || $caseSensitive) {
475
-            $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand);
476
-        } else {
477
-            $comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter')->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower'));
478
-        }
479
-        return $comparison;
480
-    }
481
-
482
-    /**
483
-     * Returns a like criterion used for matching objects against a query
484
-     *
485
-     * @param string $propertyName The name of the property to compare against
486
-     * @param mixed $operand The value to compare with
487
-     * @param boolean $caseSensitive Whether the matching should be done case-sensitive
488
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
489
-     * @api
490
-     */
491
-    public function like($propertyName, $operand, $caseSensitive = TRUE)
492
-    {
493
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand);
494
-    }
495
-
496
-    /**
497
-     * Returns a "contains" criterion used for matching objects against a query.
498
-     * It matches if the multivalued property contains the given operand.
499
-     *
500
-     * @param string $propertyName The name of the (multivalued) property to compare against
501
-     * @param mixed $operand The value to compare with
502
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
503
-     * @api
504
-     */
505
-    public function contains($propertyName, $operand)
506
-    {
507
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand);
508
-    }
509
-
510
-    /**
511
-     * Returns an "in" criterion used for matching objects against a query. It
512
-     * matches if the property's value is contained in the multivalued operand.
513
-     *
514
-     * @param string $propertyName The name of the property to compare against
515
-     * @param mixed $operand The value to compare with, multivalued
516
-     * @throws UnexpectedTypeException
517
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
518
-     * @api
519
-     */
520
-    public function in($propertyName, $operand)
521
-    {
522
-        if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) {
523
-            throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095);
524
-        }
525
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand);
526
-    }
527
-
528
-    /**
529
-     * Returns a less than criterion used for matching objects against a query
530
-     *
531
-     * @param string $propertyName The name of the property to compare against
532
-     * @param mixed $operand The value to compare with
533
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
534
-     * @api
535
-     */
536
-    public function lessThan($propertyName, $operand)
537
-    {
538
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand);
539
-    }
540
-
541
-    /**
542
-     * Returns a less or equal than criterion used for matching objects against a query
543
-     *
544
-     * @param string $propertyName The name of the property to compare against
545
-     * @param mixed $operand The value to compare with
546
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
547
-     * @api
548
-     */
549
-    public function lessThanOrEqual($propertyName, $operand)
550
-    {
551
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand);
552
-    }
553
-
554
-    /**
555
-     * Returns a greater than criterion used for matching objects against a query
556
-     *
557
-     * @param string $propertyName The name of the property to compare against
558
-     * @param mixed $operand The value to compare with
559
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
560
-     * @api
561
-     */
562
-    public function greaterThan($propertyName, $operand)
563
-    {
564
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand);
565
-    }
566
-
567
-    /**
568
-     * Returns a greater than or equal criterion used for matching objects against a query
569
-     *
570
-     * @param string $propertyName The name of the property to compare against
571
-     * @param mixed $operand The value to compare with
572
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
573
-     * @api
574
-     */
575
-    public function greaterThanOrEqual($propertyName, $operand)
576
-    {
577
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand);
578
-    }
579
-
580
-    /**
581
-     * Returns the query result count.
582
-     *
583
-     * @return integer The query result count
584
-     * @api
585
-     */
586
-    public function count()
587
-    {
588
-        /** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
589
-        $backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
590
-        return $backend->countResult();
591
-    }
592
-
593
-    /**
594
-     * Returns an "isEmpty" criterion used for matching objects against a query.
595
-     * It matches if the multivalued property contains no values or is NULL.
596
-     *
597
-     * @param string $propertyName The name of the multivalued property to compare against
598
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
599
-     * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
600
-     * @api
601
-     */
602
-    public function isEmpty($propertyName)
603
-    {
604
-        throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
605
-    }
606
-
607
-    /**
608
-     * @return string
609
-     */
610
-    public function getDistinct()
611
-    {
612
-        return $this->distinct;
613
-    }
614
-
615
-    /**
616
-     * @param string $distinct
617
-     * @return $this
618
-     */
619
-    public function setDistinct($distinct)
620
-    {
621
-        $this->distinct = $distinct;
622
-        return $this;
623
-    }
624
-
625
-    /**
626
-     * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage
627
-     * backend (database).
628
-     *
629
-     * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement
630
-     * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement.
631
-     * @return QueryInterface
632
-     */
633
-    public function statement($statement, array $parameters = array())
634
-    {
635
-        $this->statement = $this->qomFactory->statement($statement, $parameters);
636
-        return $this;
637
-    }
638
-
639
-    /**
640
-     * Returns the statement of this query.
641
-     *
642
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
643
-     */
644
-    public function getStatement()
645
-    {
646
-        return $this->statement;
647
-    }
648
-
649
-    /**
650
-     * Returns whether the current mode is Backend.
651
-     *
652
-     * @return bool
653
-     */
654
-    protected function isBackendMode()
655
-    {
656
-        return TYPO3_MODE == 'BE';
657
-    }
658
-
659
-    /**
660
-     * @return string
661
-     */
662
-    public function getSourceFieldName()
663
-    {
664
-        return $this->sourceFieldName;
665
-    }
666
-
667
-    /**
668
-     * @param string $sourceFieldName
669
-     * @return $this
670
-     */
671
-    public function setSourceFieldName($sourceFieldName)
672
-    {
673
-        $this->sourceFieldName = $sourceFieldName;
674
-        return $this;
675
-    }
32
+	/**
33
+	 * An inner join.
34
+	 */
35
+	const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner';
36
+
37
+	/**
38
+	 * A left-outer join.
39
+	 */
40
+	const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter';
41
+
42
+	/**
43
+	 * A right-outer join.
44
+	 */
45
+	const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter';
46
+
47
+	/**
48
+	 * Charset of strings in QOM
49
+	 */
50
+	const CHARSET = 'utf-8';
51
+
52
+	/**
53
+	 * @var string
54
+	 */
55
+	protected $sourceFieldName;
56
+
57
+	/**
58
+	 * @var string
59
+	 */
60
+	protected $type;
61
+
62
+	/**
63
+	 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
64
+	 */
65
+	protected $objectManager;
66
+
67
+	/**
68
+	 * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
69
+	 */
70
+	protected $persistenceManager;
71
+
72
+	/**
73
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
74
+	 */
75
+	protected $qomFactory;
76
+
77
+	/**
78
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface
79
+	 */
80
+	protected $source;
81
+
82
+	/**
83
+	 * @var ConstraintInterface
84
+	 */
85
+	protected $constraint;
86
+
87
+	/**
88
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
89
+	 */
90
+	protected $statement;
91
+
92
+	/**
93
+	 * @var int
94
+	 */
95
+	protected $orderings = array();
96
+
97
+	/**
98
+	 * @var int
99
+	 */
100
+	protected $limit;
101
+
102
+	/**
103
+	 * @var int
104
+	 */
105
+	protected $offset;
106
+
107
+	/**
108
+	 * Apply DISTINCT upon property.
109
+	 *
110
+	 * @var string
111
+	 */
112
+	protected $distinct;
113
+
114
+	/**
115
+	 * The query settings.
116
+	 *
117
+	 * @var \Fab\Vidi\Persistence\QuerySettings
118
+	 * @inject
119
+	 */
120
+	protected $querySettings;
121
+
122
+	/**
123
+	 * Constructs a query object working on the given class name
124
+	 *
125
+	 * @param string $type
126
+	 */
127
+	public function __construct($type)
128
+	{
129
+		$this->type = $type;
130
+	}
131
+
132
+	/**
133
+	 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
134
+	 * @return void
135
+	 */
136
+	public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
137
+	{
138
+		$this->objectManager = $objectManager;
139
+	}
140
+
141
+	/**
142
+	 * Injects the persistence manager, used to fetch the CR session
143
+	 *
144
+	 * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
145
+	 * @return void
146
+	 */
147
+	public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
148
+	{
149
+		$this->persistenceManager = $persistenceManager;
150
+	}
151
+
152
+	/**
153
+	 * Injects the Query Object Model Factory
154
+	 *
155
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory
156
+	 * @return void
157
+	 */
158
+	public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory)
159
+	{
160
+		$this->qomFactory = $qomFactory;
161
+	}
162
+
163
+	/**
164
+	 * Sets the Query Settings. These Query settings must match the settings expected by
165
+	 * the specific Storage Backend.
166
+	 *
167
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
168
+	 * @return void
169
+	 * @api This method is not part of FLOW3 API
170
+	 */
171
+	public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings)
172
+	{
173
+		$this->querySettings = $querySettings;
174
+	}
175
+
176
+	/**
177
+	 * Returns the Query Settings.
178
+	 *
179
+	 * @throws \Exception
180
+	 * @return \Fab\Vidi\Persistence\QuerySettings $querySettings The Query Settings
181
+	 * @api This method is not part of FLOW3 API
182
+	 */
183
+	public function getQuerySettings()
184
+	{
185
+		if (!$this->querySettings instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface) {
186
+			throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('Tried to get the query settings without setting them before.', 1248689115);
187
+		}
188
+
189
+		// Apply possible settings to the query.
190
+		if ($this->isBackendMode()) {
191
+			/** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */
192
+			$backendConfigurationManager = $this->objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
193
+			$configuration = $backendConfigurationManager->getTypoScriptSetup();
194
+			$querySettings = array('respectSysLanguage');
195
+			foreach ($querySettings as $setting) {
196
+				if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) {
197
+					$value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting];
198
+					ObjectAccess::setProperty($this->querySettings, $setting, $value);
199
+				}
200
+			}
201
+		}
202
+
203
+		return $this->querySettings;
204
+	}
205
+
206
+	/**
207
+	 * Returns the type this query cares for.
208
+	 *
209
+	 * @return string
210
+	 * @api
211
+	 */
212
+	public function getType()
213
+	{
214
+		return $this->type;
215
+	}
216
+
217
+	/**
218
+	 * Sets the source to fetch the result from
219
+	 *
220
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
221
+	 */
222
+	public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source)
223
+	{
224
+		$this->source = $source;
225
+	}
226
+
227
+	/**
228
+	 * Returns the selectorn name or an empty string, if the source is not a selector
229
+	 * TODO This has to be checked at another place
230
+	 *
231
+	 * @return string The selector name
232
+	 */
233
+	protected function getSelectorName()
234
+	{
235
+		if ($this->getSource() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
236
+			return $this->source->getSelectorName();
237
+		} else {
238
+			return '';
239
+		}
240
+	}
241
+
242
+	/**
243
+	 * Gets the node-tuple source for this query.
244
+	 *
245
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-null
246
+	 */
247
+	public function getSource()
248
+	{
249
+		if ($this->source === NULL) {
250
+			$this->source = $this->qomFactory->selector($this->getType());
251
+		}
252
+		return $this->source;
253
+	}
254
+
255
+	/**
256
+	 * Executes the query against the database and returns the result
257
+	 *
258
+	 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE
259
+	 * @api
260
+	 */
261
+	public function execute($returnRawQueryResult = FALSE)
262
+	{
263
+		/** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
264
+		$backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
265
+		return $backend->fetchResult();
266
+	}
267
+
268
+	/**
269
+	 * Sets the property names to order the result by. Expected like this:
270
+	 * array(
271
+	 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
272
+	 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
273
+	 * )
274
+	 * where 'foo' and 'bar' are property names.
275
+	 *
276
+	 * @param array $orderings The property names to order by
277
+	 * @return QueryInterface
278
+	 * @api
279
+	 */
280
+	public function setOrderings(array $orderings)
281
+	{
282
+		$this->orderings = $orderings;
283
+		return $this;
284
+	}
285
+
286
+	/**
287
+	 * Returns the property names to order the result by. Like this:
288
+	 * array(
289
+	 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
290
+	 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
291
+	 * )
292
+	 *
293
+	 * @return array
294
+	 * @api
295
+	 */
296
+	public function getOrderings()
297
+	{
298
+		return $this->orderings;
299
+	}
300
+
301
+	/**
302
+	 * Sets the maximum size of the result set to limit. Returns $this to allow
303
+	 * for chaining (fluid interface)
304
+	 *
305
+	 * @param integer $limit
306
+	 * @throws \InvalidArgumentException
307
+	 * @return QueryInterface
308
+	 * @api
309
+	 */
310
+	public function setLimit($limit)
311
+	{
312
+		if (!is_int($limit) || $limit < 1) {
313
+			throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870);
314
+		}
315
+		$this->limit = $limit;
316
+		return $this;
317
+	}
318
+
319
+	/**
320
+	 * Resets a previously set maximum size of the result set. Returns $this to allow
321
+	 * for chaining (fluid interface)
322
+	 *
323
+	 * @return QueryInterface
324
+	 * @api
325
+	 */
326
+	public function unsetLimit()
327
+	{
328
+		unset($this->limit);
329
+		return $this;
330
+	}
331
+
332
+	/**
333
+	 * Returns the maximum size of the result set to limit.
334
+	 *
335
+	 * @return integer
336
+	 * @api
337
+	 */
338
+	public function getLimit()
339
+	{
340
+		return $this->limit;
341
+	}
342
+
343
+	/**
344
+	 * Sets the start offset of the result set to offset. Returns $this to
345
+	 * allow for chaining (fluid interface)
346
+	 *
347
+	 * @param integer $offset
348
+	 * @throws \InvalidArgumentException
349
+	 * @return QueryInterface
350
+	 * @api
351
+	 */
352
+	public function setOffset($offset)
353
+	{
354
+		if (!is_int($offset) || $offset < 0) {
355
+			throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872);
356
+		}
357
+		$this->offset = $offset;
358
+		return $this;
359
+	}
360
+
361
+	/**
362
+	 * Returns the start offset of the result set.
363
+	 *
364
+	 * @return integer
365
+	 * @api
366
+	 */
367
+	public function getOffset()
368
+	{
369
+		return $this->offset;
370
+	}
371
+
372
+	/**
373
+	 * The constraint used to limit the result set. Returns $this to allow
374
+	 * for chaining (fluid interface)
375
+	 *
376
+	 * @param ConstraintInterface $constraint
377
+	 * @return QueryInterface
378
+	 * @api
379
+	 */
380
+	public function matching($constraint)
381
+	{
382
+		$this->constraint = $constraint;
383
+		return $this;
384
+	}
385
+
386
+	/**
387
+	 * Gets the constraint for this query.
388
+	 *
389
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Constraint the constraint, or null if none
390
+	 * @api
391
+	 */
392
+	public function getConstraint()
393
+	{
394
+		return $this->constraint;
395
+	}
396
+
397
+	/**
398
+	 * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND.
399
+	 * It also scepts a single array of constraints to be concatenated.
400
+	 *
401
+	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
402
+	 * @throws InvalidNumberOfConstraintsException
403
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface
404
+	 * @api
405
+	 */
406
+	public function logicalAnd($constraint1)
407
+	{
408
+		if (is_array($constraint1)) {
409
+			$resultingConstraint = array_shift($constraint1);
410
+			$constraints = $constraint1;
411
+		} else {
412
+			$constraints = func_get_args();
413
+			$resultingConstraint = array_shift($constraints);
414
+		}
415
+		if ($resultingConstraint === NULL) {
416
+			throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500);
417
+		}
418
+		foreach ($constraints as $constraint) {
419
+			$resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint);
420
+		}
421
+		return $resultingConstraint;
422
+	}
423
+
424
+	/**
425
+	 * Performs a logical disjunction of the two given constraints
426
+	 *
427
+	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
428
+	 * @throws InvalidNumberOfConstraintsException
429
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface
430
+	 * @api
431
+	 */
432
+	public function logicalOr($constraint1)
433
+	{
434
+		if (is_array($constraint1)) {
435
+			$resultingConstraint = array_shift($constraint1);
436
+			$constraints = $constraint1;
437
+		} else {
438
+			$constraints = func_get_args();
439
+			$resultingConstraint = array_shift($constraints);
440
+		}
441
+		if ($resultingConstraint === NULL) {
442
+			throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501);
443
+		}
444
+		foreach ($constraints as $constraint) {
445
+			$resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint);
446
+		}
447
+		return $resultingConstraint;
448
+	}
449
+
450
+	/**
451
+	 * Performs a logical negation of the given constraint
452
+	 *
453
+	 * @param ConstraintInterface $constraint Constraint to negate
454
+	 * @throws \RuntimeException
455
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
456
+	 * @api
457
+	 */
458
+	public function logicalNot(ConstraintInterface $constraint)
459
+	{
460
+		return $this->qomFactory->not($constraint);
461
+	}
462
+
463
+	/**
464
+	 * Returns an equals criterion used for matching objects against a query
465
+	 *
466
+	 * @param string $propertyName The name of the property to compare against
467
+	 * @param mixed $operand The value to compare with
468
+	 * @param boolean $caseSensitive Whether the equality test should be done case-sensitive
469
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
470
+	 * @api
471
+	 */
472
+	public function equals($propertyName, $operand, $caseSensitive = TRUE)
473
+	{
474
+		if (is_object($operand) || $caseSensitive) {
475
+			$comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand);
476
+		} else {
477
+			$comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter')->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower'));
478
+		}
479
+		return $comparison;
480
+	}
481
+
482
+	/**
483
+	 * Returns a like criterion used for matching objects against a query
484
+	 *
485
+	 * @param string $propertyName The name of the property to compare against
486
+	 * @param mixed $operand The value to compare with
487
+	 * @param boolean $caseSensitive Whether the matching should be done case-sensitive
488
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
489
+	 * @api
490
+	 */
491
+	public function like($propertyName, $operand, $caseSensitive = TRUE)
492
+	{
493
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand);
494
+	}
495
+
496
+	/**
497
+	 * Returns a "contains" criterion used for matching objects against a query.
498
+	 * It matches if the multivalued property contains the given operand.
499
+	 *
500
+	 * @param string $propertyName The name of the (multivalued) property to compare against
501
+	 * @param mixed $operand The value to compare with
502
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
503
+	 * @api
504
+	 */
505
+	public function contains($propertyName, $operand)
506
+	{
507
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand);
508
+	}
509
+
510
+	/**
511
+	 * Returns an "in" criterion used for matching objects against a query. It
512
+	 * matches if the property's value is contained in the multivalued operand.
513
+	 *
514
+	 * @param string $propertyName The name of the property to compare against
515
+	 * @param mixed $operand The value to compare with, multivalued
516
+	 * @throws UnexpectedTypeException
517
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
518
+	 * @api
519
+	 */
520
+	public function in($propertyName, $operand)
521
+	{
522
+		if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) {
523
+			throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095);
524
+		}
525
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand);
526
+	}
527
+
528
+	/**
529
+	 * Returns a less than criterion used for matching objects against a query
530
+	 *
531
+	 * @param string $propertyName The name of the property to compare against
532
+	 * @param mixed $operand The value to compare with
533
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
534
+	 * @api
535
+	 */
536
+	public function lessThan($propertyName, $operand)
537
+	{
538
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand);
539
+	}
540
+
541
+	/**
542
+	 * Returns a less or equal than criterion used for matching objects against a query
543
+	 *
544
+	 * @param string $propertyName The name of the property to compare against
545
+	 * @param mixed $operand The value to compare with
546
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
547
+	 * @api
548
+	 */
549
+	public function lessThanOrEqual($propertyName, $operand)
550
+	{
551
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand);
552
+	}
553
+
554
+	/**
555
+	 * Returns a greater than criterion used for matching objects against a query
556
+	 *
557
+	 * @param string $propertyName The name of the property to compare against
558
+	 * @param mixed $operand The value to compare with
559
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
560
+	 * @api
561
+	 */
562
+	public function greaterThan($propertyName, $operand)
563
+	{
564
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand);
565
+	}
566
+
567
+	/**
568
+	 * Returns a greater than or equal criterion used for matching objects against a query
569
+	 *
570
+	 * @param string $propertyName The name of the property to compare against
571
+	 * @param mixed $operand The value to compare with
572
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
573
+	 * @api
574
+	 */
575
+	public function greaterThanOrEqual($propertyName, $operand)
576
+	{
577
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand);
578
+	}
579
+
580
+	/**
581
+	 * Returns the query result count.
582
+	 *
583
+	 * @return integer The query result count
584
+	 * @api
585
+	 */
586
+	public function count()
587
+	{
588
+		/** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
589
+		$backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
590
+		return $backend->countResult();
591
+	}
592
+
593
+	/**
594
+	 * Returns an "isEmpty" criterion used for matching objects against a query.
595
+	 * It matches if the multivalued property contains no values or is NULL.
596
+	 *
597
+	 * @param string $propertyName The name of the multivalued property to compare against
598
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
599
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
600
+	 * @api
601
+	 */
602
+	public function isEmpty($propertyName)
603
+	{
604
+		throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
605
+	}
606
+
607
+	/**
608
+	 * @return string
609
+	 */
610
+	public function getDistinct()
611
+	{
612
+		return $this->distinct;
613
+	}
614
+
615
+	/**
616
+	 * @param string $distinct
617
+	 * @return $this
618
+	 */
619
+	public function setDistinct($distinct)
620
+	{
621
+		$this->distinct = $distinct;
622
+		return $this;
623
+	}
624
+
625
+	/**
626
+	 * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage
627
+	 * backend (database).
628
+	 *
629
+	 * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement
630
+	 * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement.
631
+	 * @return QueryInterface
632
+	 */
633
+	public function statement($statement, array $parameters = array())
634
+	{
635
+		$this->statement = $this->qomFactory->statement($statement, $parameters);
636
+		return $this;
637
+	}
638
+
639
+	/**
640
+	 * Returns the statement of this query.
641
+	 *
642
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
643
+	 */
644
+	public function getStatement()
645
+	{
646
+		return $this->statement;
647
+	}
648
+
649
+	/**
650
+	 * Returns whether the current mode is Backend.
651
+	 *
652
+	 * @return bool
653
+	 */
654
+	protected function isBackendMode()
655
+	{
656
+		return TYPO3_MODE == 'BE';
657
+	}
658
+
659
+	/**
660
+	 * @return string
661
+	 */
662
+	public function getSourceFieldName()
663
+	{
664
+		return $this->sourceFieldName;
665
+	}
666
+
667
+	/**
668
+	 * @param string $sourceFieldName
669
+	 * @return $this
670
+	 */
671
+	public function setSourceFieldName($sourceFieldName)
672
+	{
673
+		$this->sourceFieldName = $sourceFieldName;
674
+		return $this;
675
+	}
676 676
 
677 677
 }
Please login to merge, or discard this patch.
Classes/Persistence/Pager.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -22,168 +22,168 @@
 block discarded – undo
22 22
 class Pager
23 23
 {
24 24
 
25
-    /**
26
-     * Total amount of entries
27
-     *
28
-     * @var integer
29
-     */
30
-    protected $count;
31
-
32
-    /**
33
-     * Current offset
34
-     *
35
-     * @var integer
36
-     */
37
-    protected $offset;
38
-
39
-    /**
40
-     * Current page index
41
-     *
42
-     * @var integer
43
-     */
44
-    protected $page;
45
-
46
-    /**
47
-     * Number of items per page
48
-     *
49
-     * @var integer
50
-     */
51
-    protected $limit = 10;
52
-
53
-    /**
54
-     * Constructs a new Pager
55
-     */
56
-    public function __construct()
57
-    {
58
-        $this->page = 1;
59
-    }
60
-
61
-    /**
62
-     * Returns the total amount of entries
63
-     *
64
-     * @return int
65
-     */
66
-    public function getCount()
67
-    {
68
-        return $this->count;
69
-    }
70
-
71
-    /**
72
-     * Sets the total amount of entries
73
-     *
74
-     * @param int $count
75
-     */
76
-    public function setCount($count)
77
-    {
78
-        $this->count = $count;
79
-    }
80
-
81
-    /**
82
-     * Returns the current page index
83
-     *
84
-     * @return int
85
-     */
86
-    public function getPage()
87
-    {
88
-        return $this->page;
89
-    }
90
-
91
-    /**
92
-     * Sets the current page index
93
-     *
94
-     * @param int $page
95
-     */
96
-    public function setPage($page)
97
-    {
98
-        $this->page = $page;
99
-    }
100
-
101
-    /**
102
-     * Returns the current limit index
103
-     *
104
-     * @return int
105
-     */
106
-    public function getLimit()
107
-    {
108
-        return $this->limit;
109
-    }
110
-
111
-    /**
112
-     * Sets the current limit index
113
-     *
114
-     * @param int $limit
115
-     */
116
-    public function setLimit($limit)
117
-    {
118
-        $this->limit = $limit;
119
-    }
120
-
121
-    /**
122
-     * @return Array Items to display
123
-     */
124
-    public function getDisplayItems()
125
-    {
126
-        $last = $this->getLastPage();
127
-        if ($last == 1) {
128
-            return null;
129
-        }
130
-        $values = Array();
131
-        for ($i = 1; $i <= $last; $i++) {
132
-            $values[] = Array('key' => $i, 'value' => $i);
133
-        }
134
-        return $values;
135
-    }
136
-
137
-    /**
138
-     * @return int The last page index
139
-     */
140
-    public function getLastPage()
141
-    {
142
-        $last = intval($this->count / $this->limit);
143
-        if ($this->count % $this->limit > 0) {
144
-            $last++;
145
-        }
146
-        return $last;
147
-    }
148
-
149
-    /**
150
-     * @return int The previous page index. Minimum value is 1
151
-     */
152
-    public function getPreviousPage()
153
-    {
154
-        $prev = $this->page - 1;
155
-        if ($prev < 1) {
156
-            $prev = 1;
157
-        }
158
-        return $prev;
159
-    }
160
-
161
-    /**
162
-     * @return int The next page index. Maximum valus is the last page
163
-     */
164
-    public function getNextPage()
165
-    {
166
-        $next = $this->page + 1;
167
-        $last = $this->getLastPage();
168
-        if ($next > $last) {
169
-            $next = $last;
170
-        }
171
-        return $next;
172
-    }
173
-
174
-    /**
175
-     * @return int
176
-     */
177
-    public function getOffset()
178
-    {
179
-        return $this->offset;
180
-    }
181
-
182
-    /**
183
-     * @param int $offset
184
-     */
185
-    public function setOffset($offset)
186
-    {
187
-        $this->offset = $offset;
188
-    }
25
+	/**
26
+	 * Total amount of entries
27
+	 *
28
+	 * @var integer
29
+	 */
30
+	protected $count;
31
+
32
+	/**
33
+	 * Current offset
34
+	 *
35
+	 * @var integer
36
+	 */
37
+	protected $offset;
38
+
39
+	/**
40
+	 * Current page index
41
+	 *
42
+	 * @var integer
43
+	 */
44
+	protected $page;
45
+
46
+	/**
47
+	 * Number of items per page
48
+	 *
49
+	 * @var integer
50
+	 */
51
+	protected $limit = 10;
52
+
53
+	/**
54
+	 * Constructs a new Pager
55
+	 */
56
+	public function __construct()
57
+	{
58
+		$this->page = 1;
59
+	}
60
+
61
+	/**
62
+	 * Returns the total amount of entries
63
+	 *
64
+	 * @return int
65
+	 */
66
+	public function getCount()
67
+	{
68
+		return $this->count;
69
+	}
70
+
71
+	/**
72
+	 * Sets the total amount of entries
73
+	 *
74
+	 * @param int $count
75
+	 */
76
+	public function setCount($count)
77
+	{
78
+		$this->count = $count;
79
+	}
80
+
81
+	/**
82
+	 * Returns the current page index
83
+	 *
84
+	 * @return int
85
+	 */
86
+	public function getPage()
87
+	{
88
+		return $this->page;
89
+	}
90
+
91
+	/**
92
+	 * Sets the current page index
93
+	 *
94
+	 * @param int $page
95
+	 */
96
+	public function setPage($page)
97
+	{
98
+		$this->page = $page;
99
+	}
100
+
101
+	/**
102
+	 * Returns the current limit index
103
+	 *
104
+	 * @return int
105
+	 */
106
+	public function getLimit()
107
+	{
108
+		return $this->limit;
109
+	}
110
+
111
+	/**
112
+	 * Sets the current limit index
113
+	 *
114
+	 * @param int $limit
115
+	 */
116
+	public function setLimit($limit)
117
+	{
118
+		$this->limit = $limit;
119
+	}
120
+
121
+	/**
122
+	 * @return Array Items to display
123
+	 */
124
+	public function getDisplayItems()
125
+	{
126
+		$last = $this->getLastPage();
127
+		if ($last == 1) {
128
+			return null;
129
+		}
130
+		$values = Array();
131
+		for ($i = 1; $i <= $last; $i++) {
132
+			$values[] = Array('key' => $i, 'value' => $i);
133
+		}
134
+		return $values;
135
+	}
136
+
137
+	/**
138
+	 * @return int The last page index
139
+	 */
140
+	public function getLastPage()
141
+	{
142
+		$last = intval($this->count / $this->limit);
143
+		if ($this->count % $this->limit > 0) {
144
+			$last++;
145
+		}
146
+		return $last;
147
+	}
148
+
149
+	/**
150
+	 * @return int The previous page index. Minimum value is 1
151
+	 */
152
+	public function getPreviousPage()
153
+	{
154
+		$prev = $this->page - 1;
155
+		if ($prev < 1) {
156
+			$prev = 1;
157
+		}
158
+		return $prev;
159
+	}
160
+
161
+	/**
162
+	 * @return int The next page index. Maximum valus is the last page
163
+	 */
164
+	public function getNextPage()
165
+	{
166
+		$next = $this->page + 1;
167
+		$last = $this->getLastPage();
168
+		if ($next > $last) {
169
+			$next = $last;
170
+		}
171
+		return $next;
172
+	}
173
+
174
+	/**
175
+	 * @return int
176
+	 */
177
+	public function getOffset()
178
+	{
179
+		return $this->offset;
180
+	}
181
+
182
+	/**
183
+	 * @param int $offset
184
+	 */
185
+	public function setOffset($offset)
186
+	{
187
+		$this->offset = $offset;
188
+	}
189 189
 }
Please login to merge, or discard this patch.