Completed
Push — master ( 4a889f...9bbc4e )
by Fabien
54:29
created
Classes/DataHandler/CoreDataHandler.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@
 block discarded – undo
94 94
      *
95 95
      * @param Content $content
96 96
      * @param string $target
97
-     * @return bool
97
+     * @return boolean|null
98 98
      */
99 99
     public function processCopy(Content $content, $target)
100 100
     {
Please login to merge, or discard this patch.
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -18,140 +18,140 @@
 block discarded – undo
18 18
 class CoreDataHandler extends AbstractDataHandler
19 19
 {
20 20
 
21
-    /**
22
-     * @var array
23
-     */
24
-    protected $dataHandler;
25
-
26
-    /**
27
-     * Process Content with action "update".
28
-     *
29
-     * @param Content $content
30
-     * @throws \Exception
31
-     * @return bool
32
-     */
33
-    public function processUpdate(Content $content)
34
-    {
35
-
36
-        $values = [];
37
-
38
-        // Check the field to be updated exists
39
-        foreach ($content->toArray() as $fieldName => $value) {
40
-            if (!Tca::table($content->getDataType())->hasField($fieldName)) {
41
-                $message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType());
42
-                throw new \Exception($message, 1390668497);
43
-            }
44
-
45
-            // Flatten value if array given which is required for the DataHandler.
46
-            if (is_array($value)) {
47
-                $value = implode(',', $value);
48
-            }
49
-            $values[$fieldName] = $value;
50
-        }
51
-
52
-        $data[$content->getDataType()][$content->getUid()] = $values;
53
-
54
-        $dataHandler = $this->getDataHandler();
55
-        $dataHandler->start($data, array());
56
-        $dataHandler->process_datamap();
57
-        $this->errorMessages = $dataHandler->errorLog;
58
-
59
-        // Returns true is log does not contain errors.
60
-        return empty($dataHandler->errorLog);
61
-    }
62
-
63
-    /**
64
-     * Process Content with action "remove".
65
-     *
66
-     * @param Content $content
67
-     * @return bool
68
-     */
69
-    public function processRemove(Content $content)
70
-    {
71
-
72
-        // Build command
73
-        $cmd[$content->getDataType()][$content->getUid()]['delete'] = 1;
74
-
75
-        /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
76
-        $dataHandler = $this->getDataHandler();
77
-        $dataHandler->start([], $cmd);
78
-        $dataHandler->process_datamap();
79
-        $dataHandler->process_cmdmap();
80
-        $this->errorMessages = $dataHandler->errorLog;
81
-
82
-        // Returns true is log does not contain errors.
83
-        return empty($dataHandler->errorLog);
84
-    }
85
-
86
-    /**
87
-     * Process Content with action "copy".
88
-     *
89
-     * @param Content $content
90
-     * @param string $target
91
-     * @return bool
92
-     */
93
-    public function processCopy(Content $content, $target)
94
-    {
95
-        // TODO: Implement processCopy() method.
96
-    }
97
-
98
-    /**
99
-     * Process Content with action "move".
100
-     * The $target corresponds to the pid to move the records to.
101
-     * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor.
102
-     *
103
-     * @param Content $content
104
-     * @param int $target corresponds
105
-     * @return bool
106
-     */
107
-    public function processMove(Content $content, $target)
108
-    {
109
-
110
-        // Build command
111
-        $cmd[$content->getDataType()][$content->getUid()]['move'] = $target;
112
-
113
-        /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
114
-        $dataHandler = $this->getDataHandler();
115
-        $dataHandler->start([], $cmd);
116
-        $dataHandler->process_datamap();
117
-        $dataHandler->process_cmdmap();
118
-        $this->errorMessages = $dataHandler->errorLog;
119
-
120
-        // Returns true is log does not contain errors.
121
-        return empty($dataHandler->errorLog);
122
-    }
123
-
124
-    /**
125
-     * Process Content with action "localize".
126
-     *
127
-     * @param Content $content
128
-     * @param int $language
129
-     * @return bool
130
-     */
131
-    public function processLocalize(Content $content, $language)
132
-    {
133
-
134
-        $command[$content->getDataType()][$content->getUid()]['localize'] = $language;
135
-
136
-        $dataHandler = $this->getDataHandler();
137
-        $dataHandler->start([], $command);
138
-        $dataHandler->process_datamap();
139
-        $dataHandler->process_cmdmap();
140
-        $this->errorMessages = $dataHandler->errorLog;
141
-
142
-        // Returns true is log does not contain errors.
143
-        return empty($dataHandler->errorLog);
144
-    }
145
-
146
-    /**
147
-     * @return \TYPO3\CMS\Core\DataHandling\DataHandler
148
-     */
149
-    protected function getDataHandler()
150
-    {
151
-        if (!$this->dataHandler) {
152
-            $this->dataHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
153
-        }
154
-        return $this->dataHandler;
155
-    }
21
+	/**
22
+	 * @var array
23
+	 */
24
+	protected $dataHandler;
25
+
26
+	/**
27
+	 * Process Content with action "update".
28
+	 *
29
+	 * @param Content $content
30
+	 * @throws \Exception
31
+	 * @return bool
32
+	 */
33
+	public function processUpdate(Content $content)
34
+	{
35
+
36
+		$values = [];
37
+
38
+		// Check the field to be updated exists
39
+		foreach ($content->toArray() as $fieldName => $value) {
40
+			if (!Tca::table($content->getDataType())->hasField($fieldName)) {
41
+				$message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType());
42
+				throw new \Exception($message, 1390668497);
43
+			}
44
+
45
+			// Flatten value if array given which is required for the DataHandler.
46
+			if (is_array($value)) {
47
+				$value = implode(',', $value);
48
+			}
49
+			$values[$fieldName] = $value;
50
+		}
51
+
52
+		$data[$content->getDataType()][$content->getUid()] = $values;
53
+
54
+		$dataHandler = $this->getDataHandler();
55
+		$dataHandler->start($data, array());
56
+		$dataHandler->process_datamap();
57
+		$this->errorMessages = $dataHandler->errorLog;
58
+
59
+		// Returns true is log does not contain errors.
60
+		return empty($dataHandler->errorLog);
61
+	}
62
+
63
+	/**
64
+	 * Process Content with action "remove".
65
+	 *
66
+	 * @param Content $content
67
+	 * @return bool
68
+	 */
69
+	public function processRemove(Content $content)
70
+	{
71
+
72
+		// Build command
73
+		$cmd[$content->getDataType()][$content->getUid()]['delete'] = 1;
74
+
75
+		/** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
76
+		$dataHandler = $this->getDataHandler();
77
+		$dataHandler->start([], $cmd);
78
+		$dataHandler->process_datamap();
79
+		$dataHandler->process_cmdmap();
80
+		$this->errorMessages = $dataHandler->errorLog;
81
+
82
+		// Returns true is log does not contain errors.
83
+		return empty($dataHandler->errorLog);
84
+	}
85
+
86
+	/**
87
+	 * Process Content with action "copy".
88
+	 *
89
+	 * @param Content $content
90
+	 * @param string $target
91
+	 * @return bool
92
+	 */
93
+	public function processCopy(Content $content, $target)
94
+	{
95
+		// TODO: Implement processCopy() method.
96
+	}
97
+
98
+	/**
99
+	 * Process Content with action "move".
100
+	 * The $target corresponds to the pid to move the records to.
101
+	 * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor.
102
+	 *
103
+	 * @param Content $content
104
+	 * @param int $target corresponds
105
+	 * @return bool
106
+	 */
107
+	public function processMove(Content $content, $target)
108
+	{
109
+
110
+		// Build command
111
+		$cmd[$content->getDataType()][$content->getUid()]['move'] = $target;
112
+
113
+		/** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
114
+		$dataHandler = $this->getDataHandler();
115
+		$dataHandler->start([], $cmd);
116
+		$dataHandler->process_datamap();
117
+		$dataHandler->process_cmdmap();
118
+		$this->errorMessages = $dataHandler->errorLog;
119
+
120
+		// Returns true is log does not contain errors.
121
+		return empty($dataHandler->errorLog);
122
+	}
123
+
124
+	/**
125
+	 * Process Content with action "localize".
126
+	 *
127
+	 * @param Content $content
128
+	 * @param int $language
129
+	 * @return bool
130
+	 */
131
+	public function processLocalize(Content $content, $language)
132
+	{
133
+
134
+		$command[$content->getDataType()][$content->getUid()]['localize'] = $language;
135
+
136
+		$dataHandler = $this->getDataHandler();
137
+		$dataHandler->start([], $command);
138
+		$dataHandler->process_datamap();
139
+		$dataHandler->process_cmdmap();
140
+		$this->errorMessages = $dataHandler->errorLog;
141
+
142
+		// Returns true is log does not contain errors.
143
+		return empty($dataHandler->errorLog);
144
+	}
145
+
146
+	/**
147
+	 * @return \TYPO3\CMS\Core\DataHandling\DataHandler
148
+	 */
149
+	protected function getDataHandler()
150
+	{
151
+		if (!$this->dataHandler) {
152
+			$this->dataHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
153
+		}
154
+		return $this->dataHandler;
155
+	}
156 156
 
157 157
 }
Please login to merge, or discard this patch.
Classes/Domain/Model/Content.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -385,7 +385,7 @@
 block discarded – undo
385 385
     /**
386 386
      * Return the properties of this object.
387 387
      *
388
-     * @return array
388
+     * @return string[]
389 389
      */
390 390
     public function toFields()
391 391
     {
Please login to merge, or discard this patch.
Indentation   +445 added lines, -445 removed lines patch added patch discarded remove patch
@@ -23,450 +23,450 @@
 block discarded – undo
23 23
 class Content implements \ArrayAccess
24 24
 {
25 25
 
26
-    /**
27
-     * @var int
28
-     */
29
-    protected $uid;
30
-
31
-    /**
32
-     * @var string
33
-     */
34
-    protected $dataType;
35
-
36
-    /**
37
-     * Constructor for a Content object.
38
-     *
39
-     * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ...
40
-     * @param array $contentData
41
-     * @return \Fab\Vidi\Domain\Model\Content
42
-     * @throws \InvalidArgumentException
43
-     * @throws \Fab\Vidi\Exception\NotExistingClassException
44
-     */
45
-    public function __construct($dataType, array $contentData = array())
46
-    {
47
-
48
-        $this->dataType = $dataType;
49
-        $this->uid = empty($contentData['uid']) ? null : (int)$contentData['uid'];
50
-
51
-        /** @var \Fab\Vidi\Tca\TableService $table */
52
-        $table = Tca::table($dataType);
53
-
54
-        // Initialize the array containing the allowed fields to be filled-in.
55
-        $fields = array('pid');
56
-
57
-        // If a creation time stamp has been defined for this data type.
58
-        if ($table->getTimeCreationField()) {
59
-            $fields[] = $table->getTimeCreationField();
60
-        }
61
-
62
-        // If an update time stamp has been defined for this data type.
63
-        if ($table->getTimeModificationField()) {
64
-            $fields[] = $table->getTimeModificationField();
65
-        }
66
-
67
-        // Merge the other fields allowed for this data type.
68
-        $fields = array_merge($fields, $table->getFields());
69
-
70
-        // Fetch excluded fields from the grid.
71
-        if ($this->isBackendMode()) {
72
-            $fields = $this->filterForConfiguration($fields);
73
-            $fields = $this->filterForBackendUser($fields);
74
-        }
75
-
76
-        // Get column to be displayed
77
-        foreach ($fields as $fieldName) {
78
-            if (array_key_exists($fieldName, $contentData)) {
79
-                $propertyName = Field::name($fieldName)->of($dataType)->toPropertyName();
80
-                $this->$propertyName = $contentData[$fieldName];
81
-            }
82
-        }
83
-    }
84
-
85
-    /**
86
-     * Dispatches magic methods (findBy[Property]())
87
-     *
88
-     * @param string $methodName The name of the magic method
89
-     * @param string $arguments The arguments of the magic method
90
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException
91
-     * @return mixed
92
-     * @api
93
-     */
94
-    public function __call($methodName, $arguments)
95
-    {
96
-        $value = null;
97
-        if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
98
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
99
-
100
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
101
-            $field = Tca::table($this->dataType)->field($fieldName);
102
-
103
-            $value = $this->$propertyName;
104
-
105
-            // true means it is a relation and it is not yet resolved.
106
-            if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) {
107
-                $value = $this->resolveRelation($propertyName);
108
-            } elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) {
109
-
110
-                // Attempt to convert the value into a label for radio and select fields.
111
-                $label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value);
112
-                if ($label) {
113
-                    $value = $label;
114
-                }
115
-            }
116
-
117
-        } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
118
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
119
-            $this->$propertyName = $arguments[0];
120
-        }
121
-        return $value;
122
-    }
123
-
124
-    /**
125
-     * Tell whether the property has a relation.
126
-     *
127
-     * @param string $propertyName
128
-     * @return bool
129
-     */
130
-    protected function hasRelation($propertyName)
131
-    {
132
-        $fieldName = Property::name($propertyName)->of($this)->toFieldName();
133
-        return Tca::table($this->dataType)->field($fieldName)->hasRelation();
134
-    }
135
-
136
-    /**
137
-     * Try to "resolve" the property whether it has a relation.
138
-     * If the property has not relation it simply returns the same value.
139
-     *
140
-     * @throws \RuntimeException
141
-     * @param string $propertyName
142
-     * @return mixed
143
-     */
144
-    protected function resolveRelation($propertyName)
145
-    {
146
-
147
-        // Convert property name to field name and get the foreign data type.
148
-        $fieldName = Property::name($propertyName)->of($this)->toFieldName();
149
-        $foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType();
150
-
151
-        // Get the foreign repository instance form the factory
152
-        /** @var \Fab\Vidi\Domain\Repository\ContentRepository $foreignContentRepository */
153
-        $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName);
154
-
155
-        if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
156
-
157
-            // Fetch values from repository
158
-            $values = GeneralUtility::trimExplode(',', $this->$propertyName);
159
-            $this->$propertyName = $foreignContentRepository->findIn('uid', $values);
160
-        } elseif (Tca::table($this->dataType)->field($fieldName)->hasMany()) {
161
-            // Include relation many-to-many and one-to-many
162
-            // Tca::table($this->dataType)->field($fieldName)->hasRelationOneToMany()
163
-            // Tca::table($this->dataType)->field($fieldName)->hasRelationManyToMany()
164
-
165
-            $foreignFieldName = Tca::table($this->dataType)->field($fieldName)->getForeignField();
166
-            if (empty($foreignFieldName)) {
167
-                $message = sprintf('Missing "foreign_field" key for field "%s" in table "%s".',
168
-                    $fieldName,
169
-                    $this->dataType
170
-                );
171
-                throw new \RuntimeException($message, 1376149186);
172
-            }
173
-
174
-            // Fetch values from repository.
175
-            $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
176
-            $findByProperty = 'findBy' . ucfirst($foreignPropertyName);
177
-
178
-            // Date picker (type == group) are special fields because property path must contain the table name
179
-            // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
180
-            $propertyValue = $this->uid;
181
-            if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
182
-                $propertyValue = $this->dataType . '.' . $this->uid;
183
-            }
184
-
185
-            $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
186
-
187
-        } elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) {
188
-
189
-            $fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration();
190
-
191
-            // First case, we are on the "good side" of the relation, just query the repository
192
-            if (empty($fieldConfiguration['foreign_field'])) {
193
-                $this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName);
194
-            } else {
195
-                // Second case, we are the "bad side" of the relation, query the foreign repository
196
-                // e.g. in case of one-to-one relation.
197
-
198
-                // We must query the opposite side to get the identifier of the foreign object.
199
-                $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
200
-                $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
201
-                $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
202
-                $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
203
-
204
-                /** @var Content $foreignObject */
205
-                $this->$propertyName = $foreignContentRepository->$find($this->getUid());
206
-            }
207
-
208
-        }
209
-        return $this->$propertyName;
210
-    }
211
-
212
-    /**
213
-     * @return int
214
-     */
215
-    public function getUid()
216
-    {
217
-        return $this->uid;
218
-    }
219
-
220
-    /**
221
-     * @return string
222
-     */
223
-    public function getDataType()
224
-    {
225
-        return $this->dataType;
226
-    }
227
-
228
-    /**
229
-     * Whether a offset exists
230
-     *
231
-     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
232
-     * @param mixed $offset
233
-     * @return boolean true on success or false on failure.
234
-     * @throws \RuntimeException
235
-     * @throws \InvalidArgumentException
236
-     */
237
-    public function offsetExists($offset)
238
-    {
239
-        $offset = Field::name($offset)->of($this)->toPropertyName();
240
-        return isset($this->$offset);
241
-    }
242
-
243
-    /**
244
-     * Offset to retrieve
245
-     *
246
-     * @link http://php.net/manual/en/arrayaccess.offsetget.php
247
-     * @param mixed $offset
248
-     * @return mixed Can return all value types.
249
-     * @throws \RuntimeException
250
-     * @throws \InvalidArgumentException
251
-     */
252
-    public function offsetGet($offset)
253
-    {
254
-        $offset = Field::name($offset)->of($this)->toPropertyName();
255
-        $getter = 'get' . ucfirst($offset);
256
-        return $this->$getter();
257
-    }
258
-
259
-    /**
260
-     * Offset to set
261
-     *
262
-     * @link http://php.net/manual/en/arrayaccess.offsetset.php
263
-     * @param mixed $offset
264
-     * @param mixed $value
265
-     * @return $this
266
-     * @throws \RuntimeException
267
-     * @throws \InvalidArgumentException
268
-     */
269
-    public function offsetSet($offset, $value)
270
-    {
271
-        $offset = Field::name($offset)->of($this)->toPropertyName();
272
-        $setter = 'set' . ucfirst($offset);
273
-        $this->$setter($value);
274
-        return $this;
275
-    }
276
-
277
-    /**
278
-     * Offset to unset
279
-     *
280
-     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
281
-     * @param mixed $offset
282
-     * @throws NotImplementedException
283
-     * @return void
284
-     */
285
-    public function offsetUnset($offset)
286
-    {
287
-        $message = 'Un-setting value for Array object is not supported';
288
-        throw new NotImplementedException($message, 1376132306);
289
-    }
290
-
291
-    /**
292
-     * Convert this to array
293
-     *
294
-     * @return array
295
-     * @throws \InvalidArgumentException
296
-     */
297
-    public function toArray()
298
-    {
299
-        $result['uid'] = $this->uid;
300
-        $propertiesAndValues = json_decode(json_encode($this), true);
301
-
302
-        foreach ($propertiesAndValues as $propertyName => $value) {
303
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
304
-            $result[$fieldName] = $value;
305
-        }
306
-
307
-        return $result;
308
-    }
309
-
310
-    /**
311
-     * Convert this object to an array containing the resolved values.
312
-     *
313
-     * @param bool $resolveRelations
314
-     * @return array
315
-     * @throws \Exception
316
-     */
317
-    public function toValues($resolveRelations = true)
318
-    {
319
-        $result['uid'] = $this->uid;
320
-        $propertiesAndValues = json_decode(json_encode($this), true);
321
-
322
-        foreach ($propertiesAndValues as $propertyName => $value) {
323
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
324
-
325
-            $result[$fieldName] = $value;
326
-            if ($resolveRelations) {
327
-                $field = Tca::table($this->dataType)->field($fieldName);
328
-
329
-                $resolvedValue = '';
330
-                if ($field->getType() === FieldType::FILE) {
331
-
332
-                    if ($field->hasMany()) {
333
-                        $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
334
-
335
-                        $resolvedValue = [];
336
-                        foreach ($files as $file) {
337
-                            $resolvedValue[] = $file->getIdentifier();
338
-                        }
339
-                    } else {
340
-                        $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
341
-                        if (!empty($files)) {
342
-                            $resolvedValue = current($files)->getIdentifier();
343
-                        }
344
-                    }
345
-
346
-                    // Reset value
347
-                    $result[$fieldName] = $resolvedValue;
348
-
349
-                } elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) {
350
-                    $objects = $this[$fieldName];
351
-                    if (is_array($objects)) {
352
-                        $resolvedValue = [];
353
-                        foreach ($objects as $object) {
354
-                            /** @var $object Content */
355
-                            $labelField = Tca::table($object->getDataType())->getLabelField();
356
-                            $resolvedValue[] = $object[$labelField];
357
-                        }
358
-                    } elseif ($objects instanceof Content) {
359
-                        $labelField = Tca::table($objects->getDataType())->getLabelField();
360
-                        $resolvedValue = $objects[$labelField];
361
-                    }
362
-
363
-                    // Reset value
364
-                    $result[$fieldName] = $resolvedValue;
365
-                }
366
-            }
367
-        }
368
-
369
-        return $result;
370
-    }
371
-
372
-    /**
373
-     * Return the properties of this object.
374
-     *
375
-     * @return array
376
-     */
377
-    public function toProperties()
378
-    {
379
-        $result[] = 'uid';
380
-        $propertiesAndValues = json_decode(json_encode($this), true);
381
-
382
-        foreach ($propertiesAndValues as $propertyName => $value) {
383
-            $result[] = $propertyName;
384
-        }
385
-        return $result;
386
-    }
387
-
388
-    /**
389
-     * Return the properties of this object.
390
-     *
391
-     * @return array
392
-     */
393
-    public function toFields()
394
-    {
395
-        $result[] = 'uid';
396
-        $propertiesAndValues = json_decode(json_encode($this), true);
397
-
398
-        foreach ($propertiesAndValues as $propertyName => $value) {
399
-            $result[] = Property::name($propertyName)->of($this)->toFieldName();
400
-        }
401
-
402
-        return $result;
403
-    }
404
-
405
-    /**
406
-     * @return string
407
-     */
408
-    public function __toString()
409
-    {
410
-        $labelField = Tca::table($this->dataType)->getLabelField();
411
-        return $this[$labelField];
412
-    }
413
-
414
-    /**
415
-     * Remove fields according to BE User permission.
416
-     *
417
-     * @param $fields
418
-     * @return array
419
-     * @throws \Exception
420
-     */
421
-    protected function filterForBackendUser($fields)
422
-    {
423
-        if (!$this->getBackendUser()->isAdmin()) {
424
-            foreach ($fields as $key => $fieldName) {
425
-                if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) {
426
-                    unset($fields[$key]);
427
-                }
428
-            }
429
-        }
430
-        return $fields;
431
-    }
432
-
433
-    /**
434
-     * Remove fields according to Grid configuration.
435
-     *
436
-     * @param $fields
437
-     * @return array
438
-     */
439
-    protected function filterForConfiguration($fields)
440
-    {
441
-
442
-        $excludedFields = Tca::grid($this->dataType)->getExcludedFields();
443
-        foreach ($fields as $key => $field) {
444
-            if (in_array($field, $excludedFields)) {
445
-                unset($fields[$key]);
446
-            }
447
-        }
448
-
449
-        return $fields;
450
-    }
451
-
452
-    /**
453
-     * Returns an instance of the current Backend User.
454
-     *
455
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
456
-     */
457
-    protected function getBackendUser()
458
-    {
459
-        return $GLOBALS['BE_USER'];
460
-    }
461
-
462
-    /**
463
-     * Returns whether the current mode is Backend
464
-     *
465
-     * @return bool
466
-     */
467
-    protected function isBackendMode()
468
-    {
469
-        return TYPO3_MODE === 'BE';
470
-    }
26
+	/**
27
+	 * @var int
28
+	 */
29
+	protected $uid;
30
+
31
+	/**
32
+	 * @var string
33
+	 */
34
+	protected $dataType;
35
+
36
+	/**
37
+	 * Constructor for a Content object.
38
+	 *
39
+	 * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ...
40
+	 * @param array $contentData
41
+	 * @return \Fab\Vidi\Domain\Model\Content
42
+	 * @throws \InvalidArgumentException
43
+	 * @throws \Fab\Vidi\Exception\NotExistingClassException
44
+	 */
45
+	public function __construct($dataType, array $contentData = array())
46
+	{
47
+
48
+		$this->dataType = $dataType;
49
+		$this->uid = empty($contentData['uid']) ? null : (int)$contentData['uid'];
50
+
51
+		/** @var \Fab\Vidi\Tca\TableService $table */
52
+		$table = Tca::table($dataType);
53
+
54
+		// Initialize the array containing the allowed fields to be filled-in.
55
+		$fields = array('pid');
56
+
57
+		// If a creation time stamp has been defined for this data type.
58
+		if ($table->getTimeCreationField()) {
59
+			$fields[] = $table->getTimeCreationField();
60
+		}
61
+
62
+		// If an update time stamp has been defined for this data type.
63
+		if ($table->getTimeModificationField()) {
64
+			$fields[] = $table->getTimeModificationField();
65
+		}
66
+
67
+		// Merge the other fields allowed for this data type.
68
+		$fields = array_merge($fields, $table->getFields());
69
+
70
+		// Fetch excluded fields from the grid.
71
+		if ($this->isBackendMode()) {
72
+			$fields = $this->filterForConfiguration($fields);
73
+			$fields = $this->filterForBackendUser($fields);
74
+		}
75
+
76
+		// Get column to be displayed
77
+		foreach ($fields as $fieldName) {
78
+			if (array_key_exists($fieldName, $contentData)) {
79
+				$propertyName = Field::name($fieldName)->of($dataType)->toPropertyName();
80
+				$this->$propertyName = $contentData[$fieldName];
81
+			}
82
+		}
83
+	}
84
+
85
+	/**
86
+	 * Dispatches magic methods (findBy[Property]())
87
+	 *
88
+	 * @param string $methodName The name of the magic method
89
+	 * @param string $arguments The arguments of the magic method
90
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException
91
+	 * @return mixed
92
+	 * @api
93
+	 */
94
+	public function __call($methodName, $arguments)
95
+	{
96
+		$value = null;
97
+		if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
98
+			$propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
99
+
100
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
101
+			$field = Tca::table($this->dataType)->field($fieldName);
102
+
103
+			$value = $this->$propertyName;
104
+
105
+			// true means it is a relation and it is not yet resolved.
106
+			if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) {
107
+				$value = $this->resolveRelation($propertyName);
108
+			} elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) {
109
+
110
+				// Attempt to convert the value into a label for radio and select fields.
111
+				$label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value);
112
+				if ($label) {
113
+					$value = $label;
114
+				}
115
+			}
116
+
117
+		} elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
118
+			$propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
119
+			$this->$propertyName = $arguments[0];
120
+		}
121
+		return $value;
122
+	}
123
+
124
+	/**
125
+	 * Tell whether the property has a relation.
126
+	 *
127
+	 * @param string $propertyName
128
+	 * @return bool
129
+	 */
130
+	protected function hasRelation($propertyName)
131
+	{
132
+		$fieldName = Property::name($propertyName)->of($this)->toFieldName();
133
+		return Tca::table($this->dataType)->field($fieldName)->hasRelation();
134
+	}
135
+
136
+	/**
137
+	 * Try to "resolve" the property whether it has a relation.
138
+	 * If the property has not relation it simply returns the same value.
139
+	 *
140
+	 * @throws \RuntimeException
141
+	 * @param string $propertyName
142
+	 * @return mixed
143
+	 */
144
+	protected function resolveRelation($propertyName)
145
+	{
146
+
147
+		// Convert property name to field name and get the foreign data type.
148
+		$fieldName = Property::name($propertyName)->of($this)->toFieldName();
149
+		$foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType();
150
+
151
+		// Get the foreign repository instance form the factory
152
+		/** @var \Fab\Vidi\Domain\Repository\ContentRepository $foreignContentRepository */
153
+		$foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName);
154
+
155
+		if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
156
+
157
+			// Fetch values from repository
158
+			$values = GeneralUtility::trimExplode(',', $this->$propertyName);
159
+			$this->$propertyName = $foreignContentRepository->findIn('uid', $values);
160
+		} elseif (Tca::table($this->dataType)->field($fieldName)->hasMany()) {
161
+			// Include relation many-to-many and one-to-many
162
+			// Tca::table($this->dataType)->field($fieldName)->hasRelationOneToMany()
163
+			// Tca::table($this->dataType)->field($fieldName)->hasRelationManyToMany()
164
+
165
+			$foreignFieldName = Tca::table($this->dataType)->field($fieldName)->getForeignField();
166
+			if (empty($foreignFieldName)) {
167
+				$message = sprintf('Missing "foreign_field" key for field "%s" in table "%s".',
168
+					$fieldName,
169
+					$this->dataType
170
+				);
171
+				throw new \RuntimeException($message, 1376149186);
172
+			}
173
+
174
+			// Fetch values from repository.
175
+			$foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
176
+			$findByProperty = 'findBy' . ucfirst($foreignPropertyName);
177
+
178
+			// Date picker (type == group) are special fields because property path must contain the table name
179
+			// to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
180
+			$propertyValue = $this->uid;
181
+			if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
182
+				$propertyValue = $this->dataType . '.' . $this->uid;
183
+			}
184
+
185
+			$this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
186
+
187
+		} elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) {
188
+
189
+			$fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration();
190
+
191
+			// First case, we are on the "good side" of the relation, just query the repository
192
+			if (empty($fieldConfiguration['foreign_field'])) {
193
+				$this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName);
194
+			} else {
195
+				// Second case, we are the "bad side" of the relation, query the foreign repository
196
+				// e.g. in case of one-to-one relation.
197
+
198
+				// We must query the opposite side to get the identifier of the foreign object.
199
+				$foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
200
+				$foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
201
+				$foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
202
+				$find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
203
+
204
+				/** @var Content $foreignObject */
205
+				$this->$propertyName = $foreignContentRepository->$find($this->getUid());
206
+			}
207
+
208
+		}
209
+		return $this->$propertyName;
210
+	}
211
+
212
+	/**
213
+	 * @return int
214
+	 */
215
+	public function getUid()
216
+	{
217
+		return $this->uid;
218
+	}
219
+
220
+	/**
221
+	 * @return string
222
+	 */
223
+	public function getDataType()
224
+	{
225
+		return $this->dataType;
226
+	}
227
+
228
+	/**
229
+	 * Whether a offset exists
230
+	 *
231
+	 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
232
+	 * @param mixed $offset
233
+	 * @return boolean true on success or false on failure.
234
+	 * @throws \RuntimeException
235
+	 * @throws \InvalidArgumentException
236
+	 */
237
+	public function offsetExists($offset)
238
+	{
239
+		$offset = Field::name($offset)->of($this)->toPropertyName();
240
+		return isset($this->$offset);
241
+	}
242
+
243
+	/**
244
+	 * Offset to retrieve
245
+	 *
246
+	 * @link http://php.net/manual/en/arrayaccess.offsetget.php
247
+	 * @param mixed $offset
248
+	 * @return mixed Can return all value types.
249
+	 * @throws \RuntimeException
250
+	 * @throws \InvalidArgumentException
251
+	 */
252
+	public function offsetGet($offset)
253
+	{
254
+		$offset = Field::name($offset)->of($this)->toPropertyName();
255
+		$getter = 'get' . ucfirst($offset);
256
+		return $this->$getter();
257
+	}
258
+
259
+	/**
260
+	 * Offset to set
261
+	 *
262
+	 * @link http://php.net/manual/en/arrayaccess.offsetset.php
263
+	 * @param mixed $offset
264
+	 * @param mixed $value
265
+	 * @return $this
266
+	 * @throws \RuntimeException
267
+	 * @throws \InvalidArgumentException
268
+	 */
269
+	public function offsetSet($offset, $value)
270
+	{
271
+		$offset = Field::name($offset)->of($this)->toPropertyName();
272
+		$setter = 'set' . ucfirst($offset);
273
+		$this->$setter($value);
274
+		return $this;
275
+	}
276
+
277
+	/**
278
+	 * Offset to unset
279
+	 *
280
+	 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
281
+	 * @param mixed $offset
282
+	 * @throws NotImplementedException
283
+	 * @return void
284
+	 */
285
+	public function offsetUnset($offset)
286
+	{
287
+		$message = 'Un-setting value for Array object is not supported';
288
+		throw new NotImplementedException($message, 1376132306);
289
+	}
290
+
291
+	/**
292
+	 * Convert this to array
293
+	 *
294
+	 * @return array
295
+	 * @throws \InvalidArgumentException
296
+	 */
297
+	public function toArray()
298
+	{
299
+		$result['uid'] = $this->uid;
300
+		$propertiesAndValues = json_decode(json_encode($this), true);
301
+
302
+		foreach ($propertiesAndValues as $propertyName => $value) {
303
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
304
+			$result[$fieldName] = $value;
305
+		}
306
+
307
+		return $result;
308
+	}
309
+
310
+	/**
311
+	 * Convert this object to an array containing the resolved values.
312
+	 *
313
+	 * @param bool $resolveRelations
314
+	 * @return array
315
+	 * @throws \Exception
316
+	 */
317
+	public function toValues($resolveRelations = true)
318
+	{
319
+		$result['uid'] = $this->uid;
320
+		$propertiesAndValues = json_decode(json_encode($this), true);
321
+
322
+		foreach ($propertiesAndValues as $propertyName => $value) {
323
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
324
+
325
+			$result[$fieldName] = $value;
326
+			if ($resolveRelations) {
327
+				$field = Tca::table($this->dataType)->field($fieldName);
328
+
329
+				$resolvedValue = '';
330
+				if ($field->getType() === FieldType::FILE) {
331
+
332
+					if ($field->hasMany()) {
333
+						$files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
334
+
335
+						$resolvedValue = [];
336
+						foreach ($files as $file) {
337
+							$resolvedValue[] = $file->getIdentifier();
338
+						}
339
+					} else {
340
+						$files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
341
+						if (!empty($files)) {
342
+							$resolvedValue = current($files)->getIdentifier();
343
+						}
344
+					}
345
+
346
+					// Reset value
347
+					$result[$fieldName] = $resolvedValue;
348
+
349
+				} elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) {
350
+					$objects = $this[$fieldName];
351
+					if (is_array($objects)) {
352
+						$resolvedValue = [];
353
+						foreach ($objects as $object) {
354
+							/** @var $object Content */
355
+							$labelField = Tca::table($object->getDataType())->getLabelField();
356
+							$resolvedValue[] = $object[$labelField];
357
+						}
358
+					} elseif ($objects instanceof Content) {
359
+						$labelField = Tca::table($objects->getDataType())->getLabelField();
360
+						$resolvedValue = $objects[$labelField];
361
+					}
362
+
363
+					// Reset value
364
+					$result[$fieldName] = $resolvedValue;
365
+				}
366
+			}
367
+		}
368
+
369
+		return $result;
370
+	}
371
+
372
+	/**
373
+	 * Return the properties of this object.
374
+	 *
375
+	 * @return array
376
+	 */
377
+	public function toProperties()
378
+	{
379
+		$result[] = 'uid';
380
+		$propertiesAndValues = json_decode(json_encode($this), true);
381
+
382
+		foreach ($propertiesAndValues as $propertyName => $value) {
383
+			$result[] = $propertyName;
384
+		}
385
+		return $result;
386
+	}
387
+
388
+	/**
389
+	 * Return the properties of this object.
390
+	 *
391
+	 * @return array
392
+	 */
393
+	public function toFields()
394
+	{
395
+		$result[] = 'uid';
396
+		$propertiesAndValues = json_decode(json_encode($this), true);
397
+
398
+		foreach ($propertiesAndValues as $propertyName => $value) {
399
+			$result[] = Property::name($propertyName)->of($this)->toFieldName();
400
+		}
401
+
402
+		return $result;
403
+	}
404
+
405
+	/**
406
+	 * @return string
407
+	 */
408
+	public function __toString()
409
+	{
410
+		$labelField = Tca::table($this->dataType)->getLabelField();
411
+		return $this[$labelField];
412
+	}
413
+
414
+	/**
415
+	 * Remove fields according to BE User permission.
416
+	 *
417
+	 * @param $fields
418
+	 * @return array
419
+	 * @throws \Exception
420
+	 */
421
+	protected function filterForBackendUser($fields)
422
+	{
423
+		if (!$this->getBackendUser()->isAdmin()) {
424
+			foreach ($fields as $key => $fieldName) {
425
+				if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) {
426
+					unset($fields[$key]);
427
+				}
428
+			}
429
+		}
430
+		return $fields;
431
+	}
432
+
433
+	/**
434
+	 * Remove fields according to Grid configuration.
435
+	 *
436
+	 * @param $fields
437
+	 * @return array
438
+	 */
439
+	protected function filterForConfiguration($fields)
440
+	{
441
+
442
+		$excludedFields = Tca::grid($this->dataType)->getExcludedFields();
443
+		foreach ($fields as $key => $field) {
444
+			if (in_array($field, $excludedFields)) {
445
+				unset($fields[$key]);
446
+			}
447
+		}
448
+
449
+		return $fields;
450
+	}
451
+
452
+	/**
453
+	 * Returns an instance of the current Backend User.
454
+	 *
455
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
456
+	 */
457
+	protected function getBackendUser()
458
+	{
459
+		return $GLOBALS['BE_USER'];
460
+	}
461
+
462
+	/**
463
+	 * Returns whether the current mode is Backend
464
+	 *
465
+	 * @return bool
466
+	 */
467
+	protected function isBackendMode()
468
+	{
469
+		return TYPO3_MODE === 'BE';
470
+	}
471 471
 
472 472
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     {
96 96
         $value = null;
97 97
         if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
98
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
98
+            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)).substr(substr($methodName, 3), 1);
99 99
 
100 100
             $fieldName = Property::name($propertyName)->of($this)->toFieldName();
101 101
             $field = Tca::table($this->dataType)->field($fieldName);
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             }
116 116
 
117 117
         } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
118
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
118
+            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)).substr(substr($methodName, 3), 1);
119 119
             $this->$propertyName = $arguments[0];
120 120
         }
121 121
         return $value;
@@ -173,13 +173,13 @@  discard block
 block discarded – undo
173 173
 
174 174
             // Fetch values from repository.
175 175
             $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
176
-            $findByProperty = 'findBy' . ucfirst($foreignPropertyName);
176
+            $findByProperty = 'findBy'.ucfirst($foreignPropertyName);
177 177
 
178 178
             // Date picker (type == group) are special fields because property path must contain the table name
179 179
             // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
180 180
             $propertyValue = $this->uid;
181 181
             if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
182
-                $propertyValue = $this->dataType . '.' . $this->uid;
182
+                $propertyValue = $this->dataType.'.'.$this->uid;
183 183
             }
184 184
 
185 185
             $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
                 $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
200 200
                 $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
201 201
                 $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
202
-                $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
202
+                $find = 'findOneBy'.GeneralUtility::underscoredToUpperCamelCase($foreignField);
203 203
 
204 204
                 /** @var Content $foreignObject */
205 205
                 $this->$propertyName = $foreignContentRepository->$find($this->getUid());
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
     public function offsetGet($offset)
253 253
     {
254 254
         $offset = Field::name($offset)->of($this)->toPropertyName();
255
-        $getter = 'get' . ucfirst($offset);
255
+        $getter = 'get'.ucfirst($offset);
256 256
         return $this->$getter();
257 257
     }
258 258
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
     public function offsetSet($offset, $value)
270 270
     {
271 271
         $offset = Field::name($offset)->of($this)->toPropertyName();
272
-        $setter = 'set' . ucfirst($offset);
272
+        $setter = 'set'.ucfirst($offset);
273 273
         $this->$setter($value);
274 274
         return $this;
275 275
     }
Please login to merge, or discard this patch.
Classes/Grid/GridAnalyserService.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      *
82 82
      * @param string $tableName
83 83
      * @param string $fieldName
84
-     * @return array
84
+     * @return string[]
85 85
      */
86 86
     protected function checkRelationManyToMany($tableName, $fieldName)
87 87
     {
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      * @param string $tableName
116 116
      * @param string $fieldName
117 117
      * @param string $relationType
118
-     * @return array
118
+     * @return string[]
119 119
      */
120 120
     protected function checkRelationOf($tableName, $fieldName, $relationType)
121 121
     {
Please login to merge, or discard this patch.
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -16,114 +16,114 @@
 block discarded – undo
16 16
 class GridAnalyserService
17 17
 {
18 18
 
19
-    /**
20
-     * Check relation for table.
21
-     *
22
-     * @param $tableName
23
-     * @return array
24
-     */
25
-    public function checkRelationForTable($tableName)
26
-    {
19
+	/**
20
+	 * Check relation for table.
21
+	 *
22
+	 * @param $tableName
23
+	 * @return array
24
+	 */
25
+	public function checkRelationForTable($tableName)
26
+	{
27 27
 
28
-        $relations = [];
29
-        $table = Tca::table($tableName);
28
+		$relations = [];
29
+		$table = Tca::table($tableName);
30 30
 
31
-        $missingOppositionRelationMessage = <<<EOF
31
+		$missingOppositionRelationMessage = <<<EOF
32 32
 
33 33
   WARNING! Could not define relation precisely. This is not necessarily a problem
34 34
   if the opposite relation is not required in a Grid. But consider adding the opposite
35 35
   TCA configuration if so.
36 36
 EOF;
37 37
 
38
-        foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) {
39
-
40
-            if ($table->hasField($fieldName)) {
41
-                if ($table->field($fieldName)->hasMany()) {
42
-                    if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
43
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values');
44
-                        $relations = array_merge($relations, $_relations);
45
-                    } elseif ($table->field($fieldName)->hasRelationManyToMany()) {
46
-                        $_relations = $this->checkRelationManyToMany($tableName, $fieldName);
47
-                        $relations = array_merge($relations, $_relations);
48
-
49
-                    } elseif ($table->field($fieldName)->hasRelationOneToMany()) {
50
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many');
51
-                        $relations = array_merge($relations, $_relations);
52
-                    } else {
53
-                        $relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage);
54
-                    }
55
-                    $relations[] = '';
56
-                } elseif ($table->field($fieldName)->hasOne()) {
57
-
58
-                    if ($table->field($fieldName)->hasRelationOneToOne()) {
59
-                        $relations[] = sprintf('* one-to-one "%s"', $fieldName);
60
-                    } elseif ($table->field($fieldName)->hasRelationManyToOne()) {
61
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one');
62
-                        $relations = array_merge($relations, $_relations);
63
-                    } else {
64
-                        $relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage);
65
-                    }
66
-                    $relations[] = '';
67
-                }
68
-            }
69
-        }
70
-        return $relations;
71
-    }
72
-
73
-    /**
74
-     * Convenience method for printing out relation many-to-many.
75
-     *
76
-     * @param string $tableName
77
-     * @param string $fieldName
78
-     * @return array
79
-     */
80
-    protected function checkRelationManyToMany($tableName, $fieldName)
81
-    {
82
-
83
-        $output = [];
84
-
85
-        $table = Tca::table($tableName);
86
-        $output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName);
87
-
88
-        $foreignTable = $table->field($fieldName)->getForeignTable();
89
-        $manyToManyTable = $table->field($fieldName)->getManyToManyTable();
90
-        $foreignField = $table->field($fieldName)->getForeignField();
91
-
92
-        if (!$foreignField) {
93
-            $output[] = sprintf('  ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName);
94
-        } elseif (!$foreignTable) {
95
-            $output[] = sprintf('  ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName);
96
-        } elseif (!$manyToManyTable) {
97
-            $output[] = sprintf('  ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName);
98
-        } else {
99
-            $output[] = sprintf('  %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField);
100
-        }
101
-
102
-        $output[] = '';
103
-        return $output;
104
-    }
105
-
106
-    /**
107
-     * Convenience method for printing out relation.
108
-     *
109
-     * @param string $tableName
110
-     * @param string $fieldName
111
-     * @param string $relationType
112
-     * @return array
113
-     */
114
-    protected function checkRelationOf($tableName, $fieldName, $relationType)
115
-    {
116
-
117
-        $output = [];
118
-
119
-        $table = Tca::table($tableName);
120
-        $output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType);
121
-
122
-        $foreignTable = $table->field($fieldName)->getForeignTable();
123
-        $foreignField = $table->field($fieldName)->getForeignField();
124
-        $output[] = sprintf('  %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField);
125
-        $output[] = '';
126
-
127
-        return $output;
128
-    }
38
+		foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) {
39
+
40
+			if ($table->hasField($fieldName)) {
41
+				if ($table->field($fieldName)->hasMany()) {
42
+					if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
43
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values');
44
+						$relations = array_merge($relations, $_relations);
45
+					} elseif ($table->field($fieldName)->hasRelationManyToMany()) {
46
+						$_relations = $this->checkRelationManyToMany($tableName, $fieldName);
47
+						$relations = array_merge($relations, $_relations);
48
+
49
+					} elseif ($table->field($fieldName)->hasRelationOneToMany()) {
50
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many');
51
+						$relations = array_merge($relations, $_relations);
52
+					} else {
53
+						$relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage);
54
+					}
55
+					$relations[] = '';
56
+				} elseif ($table->field($fieldName)->hasOne()) {
57
+
58
+					if ($table->field($fieldName)->hasRelationOneToOne()) {
59
+						$relations[] = sprintf('* one-to-one "%s"', $fieldName);
60
+					} elseif ($table->field($fieldName)->hasRelationManyToOne()) {
61
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one');
62
+						$relations = array_merge($relations, $_relations);
63
+					} else {
64
+						$relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage);
65
+					}
66
+					$relations[] = '';
67
+				}
68
+			}
69
+		}
70
+		return $relations;
71
+	}
72
+
73
+	/**
74
+	 * Convenience method for printing out relation many-to-many.
75
+	 *
76
+	 * @param string $tableName
77
+	 * @param string $fieldName
78
+	 * @return array
79
+	 */
80
+	protected function checkRelationManyToMany($tableName, $fieldName)
81
+	{
82
+
83
+		$output = [];
84
+
85
+		$table = Tca::table($tableName);
86
+		$output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName);
87
+
88
+		$foreignTable = $table->field($fieldName)->getForeignTable();
89
+		$manyToManyTable = $table->field($fieldName)->getManyToManyTable();
90
+		$foreignField = $table->field($fieldName)->getForeignField();
91
+
92
+		if (!$foreignField) {
93
+			$output[] = sprintf('  ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName);
94
+		} elseif (!$foreignTable) {
95
+			$output[] = sprintf('  ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName);
96
+		} elseif (!$manyToManyTable) {
97
+			$output[] = sprintf('  ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName);
98
+		} else {
99
+			$output[] = sprintf('  %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField);
100
+		}
101
+
102
+		$output[] = '';
103
+		return $output;
104
+	}
105
+
106
+	/**
107
+	 * Convenience method for printing out relation.
108
+	 *
109
+	 * @param string $tableName
110
+	 * @param string $fieldName
111
+	 * @param string $relationType
112
+	 * @return array
113
+	 */
114
+	protected function checkRelationOf($tableName, $fieldName, $relationType)
115
+	{
116
+
117
+		$output = [];
118
+
119
+		$table = Tca::table($tableName);
120
+		$output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType);
121
+
122
+		$foreignTable = $table->field($fieldName)->getForeignTable();
123
+		$foreignField = $table->field($fieldName)->getForeignField();
124
+		$output[] = sprintf('  %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField);
125
+		$output[] = '';
126
+
127
+		return $output;
128
+	}
129 129
 }
Please login to merge, or discard this patch.
Classes/Language/LanguageService.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -109,7 +109,7 @@
 block discarded – undo
109 109
      *
110 110
      * @param Content $object
111 111
      * @param int $language
112
-     * @return string
112
+     * @return boolean
113 113
      */
114 114
     public function hasLocalization(Content $object, $language)
115 115
     {
Please login to merge, or discard this patch.
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -19,178 +19,178 @@
 block discarded – undo
19 19
 class LanguageService implements SingletonInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @var array
24
-     */
25
-    protected $languages;
26
-
27
-    /**
28
-     * @var array
29
-     */
30
-    protected $defaultIcon;
31
-
32
-    /**
33
-     * Store the localized records to boost up performance.
34
-     *
35
-     * @var array
36
-     */
37
-    protected $localizedRecordStorage;
38
-
39
-    /**
40
-     * Returns available language records.
41
-     * The method stores the records in the property to speed up the process as the method can be often called.
42
-     *
43
-     * @return array
44
-     */
45
-    public function getLanguages()
46
-    {
47
-        if ($this->languages === null) {
48
-
49
-            $tableName = 'sys_language';
50
-
51
-            $clause = '1 = 1';
52
-            $clause .= BackendUtility::deleteClause($tableName);
53
-            $clause .= BackendUtility::BEenableFields($tableName);
54
-            $this->languages = $this->getDatabaseConnection()->exec_SELECTgetRows('*', $tableName, $clause);
55
-        }
56
-        return $this->languages;
57
-    }
58
-
59
-    /**
60
-     * Returns a localized record according to a Content object and a language identifier.
61
-     * Notice! This method does not overlay anything but simply returns the raw localized record.
62
-     *
63
-     * @param Content $object
64
-     * @param int $language
65
-     * @return Content
66
-     */
67
-    public function getLocalizedContent(Content $object, $language)
68
-    {
69
-
70
-        // We want to cache data per Content object. Retrieve the Object hash.
71
-        $objectHash = spl_object_hash($object);
72
-
73
-        // Initialize the storage
74
-        if (empty($this->localizedRecordStorage[$objectHash])) {
75
-            $this->localizedRecordStorage[$objectHash] = [];
76
-        }
77
-
78
-        if (empty($this->localizedRecordStorage[$objectHash][$language])) {
79
-
80
-            $clause = sprintf('%s = %s AND %s = %s',
81
-                Tca::table($object)->getLanguageParentField(), // e.g. l10n_parent
82
-                $object->getUid(),
83
-                Tca::table($object)->getLanguageField(), // e.g. sys_language_uid
84
-                $language
85
-            );
86
-
87
-            $clause .= BackendUtility::deleteClause($object->getDataType());
88
-            $localizedRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $object->getDataType(), $clause);
89
-
90
-            if ($localizedRecord) {
91
-                $localizedContent = GeneralUtility::makeInstance(\Fab\Vidi\Domain\Model\Content::class, $object->getDataType(), $localizedRecord);
92
-                $this->localizedRecordStorage[$objectHash][$language] = $localizedContent;
93
-            } else {
94
-                $this->localizedRecordStorage[$objectHash][$language] = []; // We want an array at least, even if empty.
95
-            }
96
-        }
97
-
98
-        return $this->localizedRecordStorage[$objectHash][$language];
99
-    }
100
-
101
-    /**
102
-     * Tell whether the given Content object has a localization.
103
-     *
104
-     * @param Content $object
105
-     * @param int $language
106
-     * @return string
107
-     */
108
-    public function hasLocalization(Content $object, $language)
109
-    {
110
-        $localizedRecord = $this->getLocalizedContent($object, $language);
111
-        return !empty($localizedRecord);
112
-    }
113
-
114
-    /**
115
-     * Returns a localized field according to a Content object and a language identifier.
116
-     * Notice! If there is not translation, simply returns an empty string.
117
-     *
118
-     * @param Content $object
119
-     * @param int $language
120
-     * @param string $fieldName
121
-     * @return string
122
-     */
123
-    public function getLocalizedFieldName(Content $object, $language, $fieldName)
124
-    {
125
-        $localizedRecord = $this->getLocalizedContent($object, $language);
126
-        return empty($localizedRecord) ? '' : $localizedRecord[$fieldName];
127
-    }
128
-
129
-    /**
130
-     * Returns the default language configured by TSConfig.
131
-     *
132
-     * @return array
133
-     */
134
-    public function getDefaultFlag()
135
-    {
136
-
137
-        if ($this->defaultIcon === null) {
138
-
139
-            $defaultFlag = ''; // default value
140
-
141
-            $tsConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig(0, 'mod.SHARED');
142
-
143
-            // Fallback non sprite-configuration
144
-            if (($pos = strrpos($tsConfig['properties']['defaultLanguageFlag'], '.')) !== false) {
145
-                $defaultFlag = substr($tsConfig['properties']['defaultLanguageFlag'], 0, $pos);
146
-            }
147
-
148
-            $this->defaultIcon = $defaultFlag;
149
-        }
150
-
151
-        return $this->defaultIcon;
152
-    }
153
-
154
-    /**
155
-     * Returns whether the system includes language records.
156
-     *
157
-     * @return bool
158
-     */
159
-    public function hasLanguages()
160
-    {
161
-        $languages = $this->getLanguages();
162
-        return !empty($languages);
163
-    }
164
-
165
-    /**
166
-     * Tell whether the given language exists.
167
-     *
168
-     * @param int $language
169
-     * @return bool
170
-     */
171
-    public function languageExists($language)
172
-    {
173
-        $languages = $this->getLanguages();
174
-
175
-        $LanguageExists = false;
176
-        foreach ($languages as $_language) {
177
-            if ((int)$_language['uid'] === (int)$language) {
178
-                $LanguageExists = true;
179
-                break;
180
-            }
181
-        }
182
-
183
-        return $LanguageExists;
184
-    }
185
-
186
-    /**
187
-     * Returns a pointer to the database.
188
-     *
189
-     * @return \Fab\Vidi\Database\DatabaseConnection
190
-     */
191
-    protected function getDatabaseConnection()
192
-    {
193
-        return $GLOBALS['TYPO3_DB'];
194
-    }
22
+	/**
23
+	 * @var array
24
+	 */
25
+	protected $languages;
26
+
27
+	/**
28
+	 * @var array
29
+	 */
30
+	protected $defaultIcon;
31
+
32
+	/**
33
+	 * Store the localized records to boost up performance.
34
+	 *
35
+	 * @var array
36
+	 */
37
+	protected $localizedRecordStorage;
38
+
39
+	/**
40
+	 * Returns available language records.
41
+	 * The method stores the records in the property to speed up the process as the method can be often called.
42
+	 *
43
+	 * @return array
44
+	 */
45
+	public function getLanguages()
46
+	{
47
+		if ($this->languages === null) {
48
+
49
+			$tableName = 'sys_language';
50
+
51
+			$clause = '1 = 1';
52
+			$clause .= BackendUtility::deleteClause($tableName);
53
+			$clause .= BackendUtility::BEenableFields($tableName);
54
+			$this->languages = $this->getDatabaseConnection()->exec_SELECTgetRows('*', $tableName, $clause);
55
+		}
56
+		return $this->languages;
57
+	}
58
+
59
+	/**
60
+	 * Returns a localized record according to a Content object and a language identifier.
61
+	 * Notice! This method does not overlay anything but simply returns the raw localized record.
62
+	 *
63
+	 * @param Content $object
64
+	 * @param int $language
65
+	 * @return Content
66
+	 */
67
+	public function getLocalizedContent(Content $object, $language)
68
+	{
69
+
70
+		// We want to cache data per Content object. Retrieve the Object hash.
71
+		$objectHash = spl_object_hash($object);
72
+
73
+		// Initialize the storage
74
+		if (empty($this->localizedRecordStorage[$objectHash])) {
75
+			$this->localizedRecordStorage[$objectHash] = [];
76
+		}
77
+
78
+		if (empty($this->localizedRecordStorage[$objectHash][$language])) {
79
+
80
+			$clause = sprintf('%s = %s AND %s = %s',
81
+				Tca::table($object)->getLanguageParentField(), // e.g. l10n_parent
82
+				$object->getUid(),
83
+				Tca::table($object)->getLanguageField(), // e.g. sys_language_uid
84
+				$language
85
+			);
86
+
87
+			$clause .= BackendUtility::deleteClause($object->getDataType());
88
+			$localizedRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $object->getDataType(), $clause);
89
+
90
+			if ($localizedRecord) {
91
+				$localizedContent = GeneralUtility::makeInstance(\Fab\Vidi\Domain\Model\Content::class, $object->getDataType(), $localizedRecord);
92
+				$this->localizedRecordStorage[$objectHash][$language] = $localizedContent;
93
+			} else {
94
+				$this->localizedRecordStorage[$objectHash][$language] = []; // We want an array at least, even if empty.
95
+			}
96
+		}
97
+
98
+		return $this->localizedRecordStorage[$objectHash][$language];
99
+	}
100
+
101
+	/**
102
+	 * Tell whether the given Content object has a localization.
103
+	 *
104
+	 * @param Content $object
105
+	 * @param int $language
106
+	 * @return string
107
+	 */
108
+	public function hasLocalization(Content $object, $language)
109
+	{
110
+		$localizedRecord = $this->getLocalizedContent($object, $language);
111
+		return !empty($localizedRecord);
112
+	}
113
+
114
+	/**
115
+	 * Returns a localized field according to a Content object and a language identifier.
116
+	 * Notice! If there is not translation, simply returns an empty string.
117
+	 *
118
+	 * @param Content $object
119
+	 * @param int $language
120
+	 * @param string $fieldName
121
+	 * @return string
122
+	 */
123
+	public function getLocalizedFieldName(Content $object, $language, $fieldName)
124
+	{
125
+		$localizedRecord = $this->getLocalizedContent($object, $language);
126
+		return empty($localizedRecord) ? '' : $localizedRecord[$fieldName];
127
+	}
128
+
129
+	/**
130
+	 * Returns the default language configured by TSConfig.
131
+	 *
132
+	 * @return array
133
+	 */
134
+	public function getDefaultFlag()
135
+	{
136
+
137
+		if ($this->defaultIcon === null) {
138
+
139
+			$defaultFlag = ''; // default value
140
+
141
+			$tsConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig(0, 'mod.SHARED');
142
+
143
+			// Fallback non sprite-configuration
144
+			if (($pos = strrpos($tsConfig['properties']['defaultLanguageFlag'], '.')) !== false) {
145
+				$defaultFlag = substr($tsConfig['properties']['defaultLanguageFlag'], 0, $pos);
146
+			}
147
+
148
+			$this->defaultIcon = $defaultFlag;
149
+		}
150
+
151
+		return $this->defaultIcon;
152
+	}
153
+
154
+	/**
155
+	 * Returns whether the system includes language records.
156
+	 *
157
+	 * @return bool
158
+	 */
159
+	public function hasLanguages()
160
+	{
161
+		$languages = $this->getLanguages();
162
+		return !empty($languages);
163
+	}
164
+
165
+	/**
166
+	 * Tell whether the given language exists.
167
+	 *
168
+	 * @param int $language
169
+	 * @return bool
170
+	 */
171
+	public function languageExists($language)
172
+	{
173
+		$languages = $this->getLanguages();
174
+
175
+		$LanguageExists = false;
176
+		foreach ($languages as $_language) {
177
+			if ((int)$_language['uid'] === (int)$language) {
178
+				$LanguageExists = true;
179
+				break;
180
+			}
181
+		}
182
+
183
+		return $LanguageExists;
184
+	}
185
+
186
+	/**
187
+	 * Returns a pointer to the database.
188
+	 *
189
+	 * @return \Fab\Vidi\Database\DatabaseConnection
190
+	 */
191
+	protected function getDatabaseConnection()
192
+	{
193
+		return $GLOBALS['TYPO3_DB'];
194
+	}
195 195
 
196 196
 }
Please login to merge, or discard this patch.
Classes/Persistence/Query.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
291 291
      * )
292 292
      *
293
-     * @return array
293
+     * @return integer
294 294
      * @api
295 295
      */
296 296
     public function getOrderings()
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
      * Returns a like criterion used for matching objects against a query
484 484
      *
485 485
      * @param string $propertyName The name of the property to compare against
486
-     * @param mixed $operand The value to compare with
486
+     * @param string $operand The value to compare with
487 487
      * @param boolean $caseSensitive Whether the matching should be done case-sensitive
488 488
      * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
489 489
      * @api
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -193,8 +193,8 @@
 block discarded – undo
193 193
             $configuration = $backendConfigurationManager->getTypoScriptSetup();
194 194
             $querySettings = array('respectSysLanguage');
195 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];
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 198
                     ObjectAccess::setProperty($this->querySettings, $setting, $value);
199 199
                 }
200 200
             }
Please login to merge, or discard this patch.
Indentation   +644 added lines, -644 removed lines patch added patch discarded remove patch
@@ -23,649 +23,649 @@
 block discarded – undo
23 23
 class Query implements QueryInterface
24 24
 {
25 25
 
26
-    /**
27
-     * An inner join.
28
-     */
29
-    const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner';
30
-
31
-    /**
32
-     * A left-outer join.
33
-     */
34
-    const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter';
35
-
36
-    /**
37
-     * A right-outer join.
38
-     */
39
-    const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter';
40
-
41
-    /**
42
-     * Charset of strings in QOM
43
-     */
44
-    const CHARSET = 'utf-8';
45
-
46
-    /**
47
-     * @var string
48
-     */
49
-    protected $sourceFieldName;
50
-
51
-    /**
52
-     * @var string
53
-     */
54
-    protected $type;
55
-
56
-    /**
57
-     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
58
-     */
59
-    protected $objectManager;
60
-
61
-    /**
62
-     * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
63
-     */
64
-    protected $persistenceManager;
65
-
66
-    /**
67
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
68
-     */
69
-    protected $qomFactory;
70
-
71
-    /**
72
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface
73
-     */
74
-    protected $source;
75
-
76
-    /**
77
-     * @var ConstraintInterface
78
-     */
79
-    protected $constraint;
80
-
81
-    /**
82
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
83
-     */
84
-    protected $statement;
85
-
86
-    /**
87
-     * @var int
88
-     */
89
-    protected $orderings = [];
90
-
91
-    /**
92
-     * @var int
93
-     */
94
-    protected $limit;
95
-
96
-    /**
97
-     * @var int
98
-     */
99
-    protected $offset;
100
-
101
-    /**
102
-     * Apply DISTINCT upon property.
103
-     *
104
-     * @var string
105
-     */
106
-    protected $distinct;
107
-
108
-    /**
109
-     * The query settings.
110
-     *
111
-     * @var \Fab\Vidi\Persistence\QuerySettings
112
-     * @inject
113
-     */
114
-    protected $querySettings;
115
-
116
-    /**
117
-     * Constructs a query object working on the given class name
118
-     *
119
-     * @param string $type
120
-     */
121
-    public function __construct($type)
122
-    {
123
-        $this->type = $type;
124
-    }
125
-
126
-    /**
127
-     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
128
-     * @return void
129
-     */
130
-    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
131
-    {
132
-        $this->objectManager = $objectManager;
133
-    }
134
-
135
-    /**
136
-     * Injects the persistence manager, used to fetch the CR session
137
-     *
138
-     * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
139
-     * @return void
140
-     */
141
-    public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
142
-    {
143
-        $this->persistenceManager = $persistenceManager;
144
-    }
145
-
146
-    /**
147
-     * Injects the Query Object Model Factory
148
-     *
149
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory
150
-     * @return void
151
-     */
152
-    public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory)
153
-    {
154
-        $this->qomFactory = $qomFactory;
155
-    }
156
-
157
-    /**
158
-     * Sets the Query Settings. These Query settings must match the settings expected by
159
-     * the specific Storage Backend.
160
-     *
161
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
162
-     * @return void
163
-     * @api This method is not part of FLOW3 API
164
-     */
165
-    public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings)
166
-    {
167
-        $this->querySettings = $querySettings;
168
-    }
169
-
170
-    /**
171
-     * Returns the Query Settings.
172
-     *
173
-     * @throws \Exception
174
-     * @return \Fab\Vidi\Persistence\QuerySettings $querySettings The Query Settings
175
-     * @api This method is not part of FLOW3 API
176
-     */
177
-    public function getQuerySettings()
178
-    {
179
-        if (!$this->querySettings instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface) {
180
-            throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('Tried to get the query settings without setting them before.', 1248689115);
181
-        }
182
-
183
-        // Apply possible settings to the query.
184
-        if ($this->isBackendMode()) {
185
-            /** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */
186
-            $backendConfigurationManager = $this->objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
187
-            $configuration = $backendConfigurationManager->getTypoScriptSetup();
188
-            $querySettings = array('respectSysLanguage');
189
-            foreach ($querySettings as $setting) {
190
-                if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) {
191
-                    $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting];
192
-                    ObjectAccess::setProperty($this->querySettings, $setting, $value);
193
-                }
194
-            }
195
-        }
196
-
197
-        return $this->querySettings;
198
-    }
199
-
200
-    /**
201
-     * Returns the type this query cares for.
202
-     *
203
-     * @return string
204
-     * @api
205
-     */
206
-    public function getType()
207
-    {
208
-        return $this->type;
209
-    }
210
-
211
-    /**
212
-     * Sets the source to fetch the result from
213
-     *
214
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
215
-     */
216
-    public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source)
217
-    {
218
-        $this->source = $source;
219
-    }
220
-
221
-    /**
222
-     * Returns the selectorn name or an empty string, if the source is not a selector
223
-     * TODO This has to be checked at another place
224
-     *
225
-     * @return string The selector name
226
-     */
227
-    protected function getSelectorName()
228
-    {
229
-        if ($this->getSource() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
230
-            return $this->source->getSelectorName();
231
-        } else {
232
-            return '';
233
-        }
234
-    }
235
-
236
-    /**
237
-     * Gets the node-tuple source for this query.
238
-     *
239
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-null
240
-     */
241
-    public function getSource()
242
-    {
243
-        if ($this->source === null) {
244
-            $this->source = $this->qomFactory->selector($this->getType());
245
-        }
246
-        return $this->source;
247
-    }
248
-
249
-    /**
250
-     * Executes the query against the database and returns the result
251
-     *
252
-     * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is true
253
-     * @api
254
-     */
255
-    public function execute($returnRawQueryResult = false)
256
-    {
257
-        /** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
258
-        $backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
259
-        return $backend->fetchResult();
260
-    }
261
-
262
-    /**
263
-     * Sets the property names to order the result by. Expected like this:
264
-     * array(
265
-     * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
266
-     * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
267
-     * )
268
-     * where 'foo' and 'bar' are property names.
269
-     *
270
-     * @param array $orderings The property names to order by
271
-     * @return QueryInterface
272
-     * @api
273
-     */
274
-    public function setOrderings(array $orderings)
275
-    {
276
-        $this->orderings = $orderings;
277
-        return $this;
278
-    }
279
-
280
-    /**
281
-     * Returns the property names to order the result by. Like this:
282
-     * array(
283
-     * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
284
-     * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
285
-     * )
286
-     *
287
-     * @return array
288
-     * @api
289
-     */
290
-    public function getOrderings()
291
-    {
292
-        return $this->orderings;
293
-    }
294
-
295
-    /**
296
-     * Sets the maximum size of the result set to limit. Returns $this to allow
297
-     * for chaining (fluid interface)
298
-     *
299
-     * @param integer $limit
300
-     * @throws \InvalidArgumentException
301
-     * @return QueryInterface
302
-     * @api
303
-     */
304
-    public function setLimit($limit)
305
-    {
306
-        if (!is_int($limit) || $limit < 1) {
307
-            throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870);
308
-        }
309
-        $this->limit = $limit;
310
-        return $this;
311
-    }
312
-
313
-    /**
314
-     * Resets a previously set maximum size of the result set. Returns $this to allow
315
-     * for chaining (fluid interface)
316
-     *
317
-     * @return QueryInterface
318
-     * @api
319
-     */
320
-    public function unsetLimit()
321
-    {
322
-        unset($this->limit);
323
-        return $this;
324
-    }
325
-
326
-    /**
327
-     * Returns the maximum size of the result set to limit.
328
-     *
329
-     * @return integer
330
-     * @api
331
-     */
332
-    public function getLimit()
333
-    {
334
-        return $this->limit;
335
-    }
336
-
337
-    /**
338
-     * Sets the start offset of the result set to offset. Returns $this to
339
-     * allow for chaining (fluid interface)
340
-     *
341
-     * @param integer $offset
342
-     * @throws \InvalidArgumentException
343
-     * @return QueryInterface
344
-     * @api
345
-     */
346
-    public function setOffset($offset)
347
-    {
348
-        if (!is_int($offset) || $offset < 0) {
349
-            throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872);
350
-        }
351
-        $this->offset = $offset;
352
-        return $this;
353
-    }
354
-
355
-    /**
356
-     * Returns the start offset of the result set.
357
-     *
358
-     * @return integer
359
-     * @api
360
-     */
361
-    public function getOffset()
362
-    {
363
-        return $this->offset;
364
-    }
365
-
366
-    /**
367
-     * The constraint used to limit the result set. Returns $this to allow
368
-     * for chaining (fluid interface)
369
-     *
370
-     * @param ConstraintInterface $constraint
371
-     * @return QueryInterface
372
-     * @api
373
-     */
374
-    public function matching($constraint)
375
-    {
376
-        $this->constraint = $constraint;
377
-        return $this;
378
-    }
379
-
380
-    /**
381
-     * Gets the constraint for this query.
382
-     *
383
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Constraint the constraint, or null if none
384
-     * @api
385
-     */
386
-    public function getConstraint()
387
-    {
388
-        return $this->constraint;
389
-    }
390
-
391
-    /**
392
-     * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND.
393
-     * It also scepts a single array of constraints to be concatenated.
394
-     *
395
-     * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
396
-     * @throws InvalidNumberOfConstraintsException
397
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface
398
-     * @api
399
-     */
400
-    public function logicalAnd($constraint1)
401
-    {
402
-        if (is_array($constraint1)) {
403
-            $resultingConstraint = array_shift($constraint1);
404
-            $constraints = $constraint1;
405
-        } else {
406
-            $constraints = func_get_args();
407
-            $resultingConstraint = array_shift($constraints);
408
-        }
409
-        if ($resultingConstraint === null) {
410
-            throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500);
411
-        }
412
-        foreach ($constraints as $constraint) {
413
-            $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint);
414
-        }
415
-        return $resultingConstraint;
416
-    }
417
-
418
-    /**
419
-     * Performs a logical disjunction of the two given constraints
420
-     *
421
-     * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
422
-     * @throws InvalidNumberOfConstraintsException
423
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface
424
-     * @api
425
-     */
426
-    public function logicalOr($constraint1)
427
-    {
428
-        if (is_array($constraint1)) {
429
-            $resultingConstraint = array_shift($constraint1);
430
-            $constraints = $constraint1;
431
-        } else {
432
-            $constraints = func_get_args();
433
-            $resultingConstraint = array_shift($constraints);
434
-        }
435
-        if ($resultingConstraint === null) {
436
-            throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501);
437
-        }
438
-        foreach ($constraints as $constraint) {
439
-            $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint);
440
-        }
441
-        return $resultingConstraint;
442
-    }
443
-
444
-    /**
445
-     * Performs a logical negation of the given constraint
446
-     *
447
-     * @param ConstraintInterface $constraint Constraint to negate
448
-     * @throws \RuntimeException
449
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
450
-     * @api
451
-     */
452
-    public function logicalNot(ConstraintInterface $constraint)
453
-    {
454
-        return $this->qomFactory->not($constraint);
455
-    }
456
-
457
-    /**
458
-     * Returns an equals criterion used for matching objects against a query
459
-     *
460
-     * @param string $propertyName The name of the property to compare against
461
-     * @param mixed $operand The value to compare with
462
-     * @param boolean $caseSensitive Whether the equality test should be done case-sensitive
463
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
464
-     * @api
465
-     */
466
-    public function equals($propertyName, $operand, $caseSensitive = true)
467
-    {
468
-        if (is_object($operand) || $caseSensitive) {
469
-            $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand);
470
-        } else {
471
-            $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::class)->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower'));
472
-        }
473
-        return $comparison;
474
-    }
475
-
476
-    /**
477
-     * Returns a like criterion used for matching objects against a query
478
-     *
479
-     * @param string $propertyName The name of the property to compare against
480
-     * @param mixed $operand The value to compare with
481
-     * @param boolean $caseSensitive Whether the matching should be done case-sensitive
482
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
483
-     * @api
484
-     */
485
-    public function like($propertyName, $operand, $caseSensitive = true)
486
-    {
487
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand);
488
-    }
489
-
490
-    /**
491
-     * Returns a "contains" criterion used for matching objects against a query.
492
-     * It matches if the multivalued property contains the given operand.
493
-     *
494
-     * @param string $propertyName The name of the (multivalued) property to compare against
495
-     * @param mixed $operand The value to compare with
496
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
497
-     * @api
498
-     */
499
-    public function contains($propertyName, $operand)
500
-    {
501
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand);
502
-    }
503
-
504
-    /**
505
-     * Returns an "in" criterion used for matching objects against a query. It
506
-     * matches if the property's value is contained in the multivalued operand.
507
-     *
508
-     * @param string $propertyName The name of the property to compare against
509
-     * @param mixed $operand The value to compare with, multivalued
510
-     * @throws UnexpectedTypeException
511
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
512
-     * @api
513
-     */
514
-    public function in($propertyName, $operand)
515
-    {
516
-        if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) {
517
-            throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095);
518
-        }
519
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand);
520
-    }
521
-
522
-    /**
523
-     * Returns a less than criterion used for matching objects against a query
524
-     *
525
-     * @param string $propertyName The name of the property to compare against
526
-     * @param mixed $operand The value to compare with
527
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
528
-     * @api
529
-     */
530
-    public function lessThan($propertyName, $operand)
531
-    {
532
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand);
533
-    }
534
-
535
-    /**
536
-     * Returns a less or equal than criterion used for matching objects against a query
537
-     *
538
-     * @param string $propertyName The name of the property to compare against
539
-     * @param mixed $operand The value to compare with
540
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
541
-     * @api
542
-     */
543
-    public function lessThanOrEqual($propertyName, $operand)
544
-    {
545
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand);
546
-    }
547
-
548
-    /**
549
-     * Returns a greater than criterion used for matching objects against a query
550
-     *
551
-     * @param string $propertyName The name of the property to compare against
552
-     * @param mixed $operand The value to compare with
553
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
554
-     * @api
555
-     */
556
-    public function greaterThan($propertyName, $operand)
557
-    {
558
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand);
559
-    }
560
-
561
-    /**
562
-     * Returns a greater than or equal criterion used for matching objects against a query
563
-     *
564
-     * @param string $propertyName The name of the property to compare against
565
-     * @param mixed $operand The value to compare with
566
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
567
-     * @api
568
-     */
569
-    public function greaterThanOrEqual($propertyName, $operand)
570
-    {
571
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand);
572
-    }
573
-
574
-    /**
575
-     * Returns the query result count.
576
-     *
577
-     * @return integer The query result count
578
-     * @api
579
-     */
580
-    public function count()
581
-    {
582
-        /** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
583
-        $backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
584
-        return $backend->countResult();
585
-    }
586
-
587
-    /**
588
-     * Returns an "isEmpty" criterion used for matching objects against a query.
589
-     * It matches if the multivalued property contains no values or is null.
590
-     *
591
-     * @param string $propertyName The name of the multivalued property to compare against
592
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
593
-     * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
594
-     * @api
595
-     */
596
-    public function isEmpty($propertyName)
597
-    {
598
-        throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
599
-    }
600
-
601
-    /**
602
-     * @return string
603
-     */
604
-    public function getDistinct()
605
-    {
606
-        return $this->distinct;
607
-    }
608
-
609
-    /**
610
-     * @param string $distinct
611
-     * @return $this
612
-     */
613
-    public function setDistinct($distinct)
614
-    {
615
-        $this->distinct = $distinct;
616
-        return $this;
617
-    }
618
-
619
-    /**
620
-     * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage
621
-     * backend (database).
622
-     *
623
-     * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement
624
-     * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement.
625
-     * @return QueryInterface
626
-     */
627
-    public function statement($statement, array $parameters = array())
628
-    {
629
-        $this->statement = $this->qomFactory->statement($statement, $parameters);
630
-        return $this;
631
-    }
632
-
633
-    /**
634
-     * Returns the statement of this query.
635
-     *
636
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
637
-     */
638
-    public function getStatement()
639
-    {
640
-        return $this->statement;
641
-    }
642
-
643
-    /**
644
-     * Returns whether the current mode is Backend.
645
-     *
646
-     * @return bool
647
-     */
648
-    protected function isBackendMode()
649
-    {
650
-        return TYPO3_MODE == 'BE';
651
-    }
652
-
653
-    /**
654
-     * @return string
655
-     */
656
-    public function getSourceFieldName()
657
-    {
658
-        return $this->sourceFieldName;
659
-    }
660
-
661
-    /**
662
-     * @param string $sourceFieldName
663
-     * @return $this
664
-     */
665
-    public function setSourceFieldName($sourceFieldName)
666
-    {
667
-        $this->sourceFieldName = $sourceFieldName;
668
-        return $this;
669
-    }
26
+	/**
27
+	 * An inner join.
28
+	 */
29
+	const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner';
30
+
31
+	/**
32
+	 * A left-outer join.
33
+	 */
34
+	const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter';
35
+
36
+	/**
37
+	 * A right-outer join.
38
+	 */
39
+	const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter';
40
+
41
+	/**
42
+	 * Charset of strings in QOM
43
+	 */
44
+	const CHARSET = 'utf-8';
45
+
46
+	/**
47
+	 * @var string
48
+	 */
49
+	protected $sourceFieldName;
50
+
51
+	/**
52
+	 * @var string
53
+	 */
54
+	protected $type;
55
+
56
+	/**
57
+	 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
58
+	 */
59
+	protected $objectManager;
60
+
61
+	/**
62
+	 * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
63
+	 */
64
+	protected $persistenceManager;
65
+
66
+	/**
67
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
68
+	 */
69
+	protected $qomFactory;
70
+
71
+	/**
72
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface
73
+	 */
74
+	protected $source;
75
+
76
+	/**
77
+	 * @var ConstraintInterface
78
+	 */
79
+	protected $constraint;
80
+
81
+	/**
82
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
83
+	 */
84
+	protected $statement;
85
+
86
+	/**
87
+	 * @var int
88
+	 */
89
+	protected $orderings = [];
90
+
91
+	/**
92
+	 * @var int
93
+	 */
94
+	protected $limit;
95
+
96
+	/**
97
+	 * @var int
98
+	 */
99
+	protected $offset;
100
+
101
+	/**
102
+	 * Apply DISTINCT upon property.
103
+	 *
104
+	 * @var string
105
+	 */
106
+	protected $distinct;
107
+
108
+	/**
109
+	 * The query settings.
110
+	 *
111
+	 * @var \Fab\Vidi\Persistence\QuerySettings
112
+	 * @inject
113
+	 */
114
+	protected $querySettings;
115
+
116
+	/**
117
+	 * Constructs a query object working on the given class name
118
+	 *
119
+	 * @param string $type
120
+	 */
121
+	public function __construct($type)
122
+	{
123
+		$this->type = $type;
124
+	}
125
+
126
+	/**
127
+	 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
128
+	 * @return void
129
+	 */
130
+	public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
131
+	{
132
+		$this->objectManager = $objectManager;
133
+	}
134
+
135
+	/**
136
+	 * Injects the persistence manager, used to fetch the CR session
137
+	 *
138
+	 * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
139
+	 * @return void
140
+	 */
141
+	public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
142
+	{
143
+		$this->persistenceManager = $persistenceManager;
144
+	}
145
+
146
+	/**
147
+	 * Injects the Query Object Model Factory
148
+	 *
149
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory
150
+	 * @return void
151
+	 */
152
+	public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory)
153
+	{
154
+		$this->qomFactory = $qomFactory;
155
+	}
156
+
157
+	/**
158
+	 * Sets the Query Settings. These Query settings must match the settings expected by
159
+	 * the specific Storage Backend.
160
+	 *
161
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
162
+	 * @return void
163
+	 * @api This method is not part of FLOW3 API
164
+	 */
165
+	public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings)
166
+	{
167
+		$this->querySettings = $querySettings;
168
+	}
169
+
170
+	/**
171
+	 * Returns the Query Settings.
172
+	 *
173
+	 * @throws \Exception
174
+	 * @return \Fab\Vidi\Persistence\QuerySettings $querySettings The Query Settings
175
+	 * @api This method is not part of FLOW3 API
176
+	 */
177
+	public function getQuerySettings()
178
+	{
179
+		if (!$this->querySettings instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface) {
180
+			throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('Tried to get the query settings without setting them before.', 1248689115);
181
+		}
182
+
183
+		// Apply possible settings to the query.
184
+		if ($this->isBackendMode()) {
185
+			/** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */
186
+			$backendConfigurationManager = $this->objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
187
+			$configuration = $backendConfigurationManager->getTypoScriptSetup();
188
+			$querySettings = array('respectSysLanguage');
189
+			foreach ($querySettings as $setting) {
190
+				if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) {
191
+					$value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting];
192
+					ObjectAccess::setProperty($this->querySettings, $setting, $value);
193
+				}
194
+			}
195
+		}
196
+
197
+		return $this->querySettings;
198
+	}
199
+
200
+	/**
201
+	 * Returns the type this query cares for.
202
+	 *
203
+	 * @return string
204
+	 * @api
205
+	 */
206
+	public function getType()
207
+	{
208
+		return $this->type;
209
+	}
210
+
211
+	/**
212
+	 * Sets the source to fetch the result from
213
+	 *
214
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
215
+	 */
216
+	public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source)
217
+	{
218
+		$this->source = $source;
219
+	}
220
+
221
+	/**
222
+	 * Returns the selectorn name or an empty string, if the source is not a selector
223
+	 * TODO This has to be checked at another place
224
+	 *
225
+	 * @return string The selector name
226
+	 */
227
+	protected function getSelectorName()
228
+	{
229
+		if ($this->getSource() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
230
+			return $this->source->getSelectorName();
231
+		} else {
232
+			return '';
233
+		}
234
+	}
235
+
236
+	/**
237
+	 * Gets the node-tuple source for this query.
238
+	 *
239
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-null
240
+	 */
241
+	public function getSource()
242
+	{
243
+		if ($this->source === null) {
244
+			$this->source = $this->qomFactory->selector($this->getType());
245
+		}
246
+		return $this->source;
247
+	}
248
+
249
+	/**
250
+	 * Executes the query against the database and returns the result
251
+	 *
252
+	 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is true
253
+	 * @api
254
+	 */
255
+	public function execute($returnRawQueryResult = false)
256
+	{
257
+		/** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
258
+		$backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
259
+		return $backend->fetchResult();
260
+	}
261
+
262
+	/**
263
+	 * Sets the property names to order the result by. Expected like this:
264
+	 * array(
265
+	 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
266
+	 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
267
+	 * )
268
+	 * where 'foo' and 'bar' are property names.
269
+	 *
270
+	 * @param array $orderings The property names to order by
271
+	 * @return QueryInterface
272
+	 * @api
273
+	 */
274
+	public function setOrderings(array $orderings)
275
+	{
276
+		$this->orderings = $orderings;
277
+		return $this;
278
+	}
279
+
280
+	/**
281
+	 * Returns the property names to order the result by. Like this:
282
+	 * array(
283
+	 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
284
+	 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
285
+	 * )
286
+	 *
287
+	 * @return array
288
+	 * @api
289
+	 */
290
+	public function getOrderings()
291
+	{
292
+		return $this->orderings;
293
+	}
294
+
295
+	/**
296
+	 * Sets the maximum size of the result set to limit. Returns $this to allow
297
+	 * for chaining (fluid interface)
298
+	 *
299
+	 * @param integer $limit
300
+	 * @throws \InvalidArgumentException
301
+	 * @return QueryInterface
302
+	 * @api
303
+	 */
304
+	public function setLimit($limit)
305
+	{
306
+		if (!is_int($limit) || $limit < 1) {
307
+			throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870);
308
+		}
309
+		$this->limit = $limit;
310
+		return $this;
311
+	}
312
+
313
+	/**
314
+	 * Resets a previously set maximum size of the result set. Returns $this to allow
315
+	 * for chaining (fluid interface)
316
+	 *
317
+	 * @return QueryInterface
318
+	 * @api
319
+	 */
320
+	public function unsetLimit()
321
+	{
322
+		unset($this->limit);
323
+		return $this;
324
+	}
325
+
326
+	/**
327
+	 * Returns the maximum size of the result set to limit.
328
+	 *
329
+	 * @return integer
330
+	 * @api
331
+	 */
332
+	public function getLimit()
333
+	{
334
+		return $this->limit;
335
+	}
336
+
337
+	/**
338
+	 * Sets the start offset of the result set to offset. Returns $this to
339
+	 * allow for chaining (fluid interface)
340
+	 *
341
+	 * @param integer $offset
342
+	 * @throws \InvalidArgumentException
343
+	 * @return QueryInterface
344
+	 * @api
345
+	 */
346
+	public function setOffset($offset)
347
+	{
348
+		if (!is_int($offset) || $offset < 0) {
349
+			throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872);
350
+		}
351
+		$this->offset = $offset;
352
+		return $this;
353
+	}
354
+
355
+	/**
356
+	 * Returns the start offset of the result set.
357
+	 *
358
+	 * @return integer
359
+	 * @api
360
+	 */
361
+	public function getOffset()
362
+	{
363
+		return $this->offset;
364
+	}
365
+
366
+	/**
367
+	 * The constraint used to limit the result set. Returns $this to allow
368
+	 * for chaining (fluid interface)
369
+	 *
370
+	 * @param ConstraintInterface $constraint
371
+	 * @return QueryInterface
372
+	 * @api
373
+	 */
374
+	public function matching($constraint)
375
+	{
376
+		$this->constraint = $constraint;
377
+		return $this;
378
+	}
379
+
380
+	/**
381
+	 * Gets the constraint for this query.
382
+	 *
383
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Constraint the constraint, or null if none
384
+	 * @api
385
+	 */
386
+	public function getConstraint()
387
+	{
388
+		return $this->constraint;
389
+	}
390
+
391
+	/**
392
+	 * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND.
393
+	 * It also scepts a single array of constraints to be concatenated.
394
+	 *
395
+	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
396
+	 * @throws InvalidNumberOfConstraintsException
397
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface
398
+	 * @api
399
+	 */
400
+	public function logicalAnd($constraint1)
401
+	{
402
+		if (is_array($constraint1)) {
403
+			$resultingConstraint = array_shift($constraint1);
404
+			$constraints = $constraint1;
405
+		} else {
406
+			$constraints = func_get_args();
407
+			$resultingConstraint = array_shift($constraints);
408
+		}
409
+		if ($resultingConstraint === null) {
410
+			throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500);
411
+		}
412
+		foreach ($constraints as $constraint) {
413
+			$resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint);
414
+		}
415
+		return $resultingConstraint;
416
+	}
417
+
418
+	/**
419
+	 * Performs a logical disjunction of the two given constraints
420
+	 *
421
+	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
422
+	 * @throws InvalidNumberOfConstraintsException
423
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface
424
+	 * @api
425
+	 */
426
+	public function logicalOr($constraint1)
427
+	{
428
+		if (is_array($constraint1)) {
429
+			$resultingConstraint = array_shift($constraint1);
430
+			$constraints = $constraint1;
431
+		} else {
432
+			$constraints = func_get_args();
433
+			$resultingConstraint = array_shift($constraints);
434
+		}
435
+		if ($resultingConstraint === null) {
436
+			throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501);
437
+		}
438
+		foreach ($constraints as $constraint) {
439
+			$resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint);
440
+		}
441
+		return $resultingConstraint;
442
+	}
443
+
444
+	/**
445
+	 * Performs a logical negation of the given constraint
446
+	 *
447
+	 * @param ConstraintInterface $constraint Constraint to negate
448
+	 * @throws \RuntimeException
449
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
450
+	 * @api
451
+	 */
452
+	public function logicalNot(ConstraintInterface $constraint)
453
+	{
454
+		return $this->qomFactory->not($constraint);
455
+	}
456
+
457
+	/**
458
+	 * Returns an equals criterion used for matching objects against a query
459
+	 *
460
+	 * @param string $propertyName The name of the property to compare against
461
+	 * @param mixed $operand The value to compare with
462
+	 * @param boolean $caseSensitive Whether the equality test should be done case-sensitive
463
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
464
+	 * @api
465
+	 */
466
+	public function equals($propertyName, $operand, $caseSensitive = true)
467
+	{
468
+		if (is_object($operand) || $caseSensitive) {
469
+			$comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand);
470
+		} else {
471
+			$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::class)->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower'));
472
+		}
473
+		return $comparison;
474
+	}
475
+
476
+	/**
477
+	 * Returns a like criterion used for matching objects against a query
478
+	 *
479
+	 * @param string $propertyName The name of the property to compare against
480
+	 * @param mixed $operand The value to compare with
481
+	 * @param boolean $caseSensitive Whether the matching should be done case-sensitive
482
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
483
+	 * @api
484
+	 */
485
+	public function like($propertyName, $operand, $caseSensitive = true)
486
+	{
487
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand);
488
+	}
489
+
490
+	/**
491
+	 * Returns a "contains" criterion used for matching objects against a query.
492
+	 * It matches if the multivalued property contains the given operand.
493
+	 *
494
+	 * @param string $propertyName The name of the (multivalued) property to compare against
495
+	 * @param mixed $operand The value to compare with
496
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
497
+	 * @api
498
+	 */
499
+	public function contains($propertyName, $operand)
500
+	{
501
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand);
502
+	}
503
+
504
+	/**
505
+	 * Returns an "in" criterion used for matching objects against a query. It
506
+	 * matches if the property's value is contained in the multivalued operand.
507
+	 *
508
+	 * @param string $propertyName The name of the property to compare against
509
+	 * @param mixed $operand The value to compare with, multivalued
510
+	 * @throws UnexpectedTypeException
511
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
512
+	 * @api
513
+	 */
514
+	public function in($propertyName, $operand)
515
+	{
516
+		if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) {
517
+			throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095);
518
+		}
519
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand);
520
+	}
521
+
522
+	/**
523
+	 * Returns a less than criterion used for matching objects against a query
524
+	 *
525
+	 * @param string $propertyName The name of the property to compare against
526
+	 * @param mixed $operand The value to compare with
527
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
528
+	 * @api
529
+	 */
530
+	public function lessThan($propertyName, $operand)
531
+	{
532
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand);
533
+	}
534
+
535
+	/**
536
+	 * Returns a less or equal than criterion used for matching objects against a query
537
+	 *
538
+	 * @param string $propertyName The name of the property to compare against
539
+	 * @param mixed $operand The value to compare with
540
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
541
+	 * @api
542
+	 */
543
+	public function lessThanOrEqual($propertyName, $operand)
544
+	{
545
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand);
546
+	}
547
+
548
+	/**
549
+	 * Returns a greater than criterion used for matching objects against a query
550
+	 *
551
+	 * @param string $propertyName The name of the property to compare against
552
+	 * @param mixed $operand The value to compare with
553
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
554
+	 * @api
555
+	 */
556
+	public function greaterThan($propertyName, $operand)
557
+	{
558
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand);
559
+	}
560
+
561
+	/**
562
+	 * Returns a greater than or equal criterion used for matching objects against a query
563
+	 *
564
+	 * @param string $propertyName The name of the property to compare against
565
+	 * @param mixed $operand The value to compare with
566
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
567
+	 * @api
568
+	 */
569
+	public function greaterThanOrEqual($propertyName, $operand)
570
+	{
571
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand);
572
+	}
573
+
574
+	/**
575
+	 * Returns the query result count.
576
+	 *
577
+	 * @return integer The query result count
578
+	 * @api
579
+	 */
580
+	public function count()
581
+	{
582
+		/** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
583
+		$backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
584
+		return $backend->countResult();
585
+	}
586
+
587
+	/**
588
+	 * Returns an "isEmpty" criterion used for matching objects against a query.
589
+	 * It matches if the multivalued property contains no values or is null.
590
+	 *
591
+	 * @param string $propertyName The name of the multivalued property to compare against
592
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
593
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
594
+	 * @api
595
+	 */
596
+	public function isEmpty($propertyName)
597
+	{
598
+		throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
599
+	}
600
+
601
+	/**
602
+	 * @return string
603
+	 */
604
+	public function getDistinct()
605
+	{
606
+		return $this->distinct;
607
+	}
608
+
609
+	/**
610
+	 * @param string $distinct
611
+	 * @return $this
612
+	 */
613
+	public function setDistinct($distinct)
614
+	{
615
+		$this->distinct = $distinct;
616
+		return $this;
617
+	}
618
+
619
+	/**
620
+	 * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage
621
+	 * backend (database).
622
+	 *
623
+	 * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement
624
+	 * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement.
625
+	 * @return QueryInterface
626
+	 */
627
+	public function statement($statement, array $parameters = array())
628
+	{
629
+		$this->statement = $this->qomFactory->statement($statement, $parameters);
630
+		return $this;
631
+	}
632
+
633
+	/**
634
+	 * Returns the statement of this query.
635
+	 *
636
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
637
+	 */
638
+	public function getStatement()
639
+	{
640
+		return $this->statement;
641
+	}
642
+
643
+	/**
644
+	 * Returns whether the current mode is Backend.
645
+	 *
646
+	 * @return bool
647
+	 */
648
+	protected function isBackendMode()
649
+	{
650
+		return TYPO3_MODE == 'BE';
651
+	}
652
+
653
+	/**
654
+	 * @return string
655
+	 */
656
+	public function getSourceFieldName()
657
+	{
658
+		return $this->sourceFieldName;
659
+	}
660
+
661
+	/**
662
+	 * @param string $sourceFieldName
663
+	 * @return $this
664
+	 */
665
+	public function setSourceFieldName($sourceFieldName)
666
+	{
667
+		$this->sourceFieldName = $sourceFieldName;
668
+		return $this;
669
+	}
670 670
 
671 671
 }
Please login to merge, or discard this patch.
Classes/Persistence/Storage/VidiDbBackend.php 3 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
     /**
232 232
      * Parses the query and returns the SQL statement parts.
233 233
      *
234
-     * @param QueryInterface $query The query
234
+     * @param \Fab\Vidi\Persistence\Query $query The query
235 235
      * @param array &$parameters
236 236
      * @return array The SQL statement parts
237 237
      */
@@ -774,6 +774,7 @@  discard block
 block discarded – undo
774 774
      * @param string &$sqlString The query part with placeholders
775 775
      * @param array $parameters The parameters
776 776
      * @param string $tableName
777
+     * @param string $sqlString
777 778
      *
778 779
      * @throws Exception
779 780
      */
@@ -1071,7 +1072,7 @@  discard block
 block discarded – undo
1071 1072
      *
1072 1073
      * @param SourceInterface $source The source (selector od join)
1073 1074
      * @param array $row
1074
-     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
1075
+     * @param \Fab\Vidi\Persistence\QuerySettings $querySettings The TYPO3 CMS specific query settings
1075 1076
      * @return array
1076 1077
      */
1077 1078
     protected function doLanguageAndWorkspaceOverlay(SourceInterface $source, array $row, $querySettings)
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         $fieldNames = array_keys($identifier);
128 128
         $suffixedFieldNames = [];
129 129
         foreach ($fieldNames as $fieldName) {
130
-            $suffixedFieldNames[] = $fieldName . '=?';
130
+            $suffixedFieldNames[] = $fieldName.'=?';
131 131
         }
132 132
         return implode(' AND ', $suffixedFieldNames);
133 133
     }
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
             if (isset($statementParts['keywords']['distinct'])) {
189 189
                 unset($statementParts['keywords']['distinct']);
190 190
                 $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid';
191
-                $statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.' . $distinctField . ')');
191
+                $statementParts['fields'] = array('COUNT(DISTINCT '.reset($statementParts['tables']).'.'.$distinctField.')');
192 192
             }
193 193
 
194 194
             $statement = $this->buildQuery($statementParts);
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
             // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name)
259 259
             $values = [];
260 260
             foreach ($statementParts['fields'] as $key => $value) {
261
-                $values[$key] = str_replace($tableName, $tableName . '0', $value);
261
+                $values[$key] = str_replace($tableName, $tableName.'0', $value);
262 262
             }
263 263
             $statementParts['fields'] = $values;
264 264
 
265 265
             // Same comment as above.
266 266
             $values = [];
267 267
             foreach ($statementParts['where'] as $key => $value) {
268
-                $values[$key] = str_replace($tableName . '0', $tableName, $value);
268
+                $values[$key] = str_replace($tableName.'0', $tableName, $value);
269 269
             }
270 270
             $statementParts['where'] = $values;
271 271
 
@@ -304,25 +304,25 @@  discard block
 block discarded – undo
304 304
         if (!empty($statementParts['unions'])) {
305 305
             foreach ($statementParts['unions'] as $tableName => $unionPart) {
306 306
                 if (!empty($statementParts['additionalWhereClause'][$tableName])) {
307
-                    $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]);
307
+                    $statementParts['unions'][$tableName] .= ' AND '.implode(' AND ', $statementParts['additionalWhereClause'][$tableName]);
308 308
                 }
309 309
             }
310 310
         }
311 311
 
312
-        $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']);
312
+        $statement = 'SELECT '.implode(' ', $statementParts['keywords']).' '.implode(',', $statementParts['fields']).' FROM '.implode(' ', $statementParts['tables']).' '.implode(' ', $statementParts['unions']);
313 313
         if (!empty($statementParts['where'])) {
314
-            $statement .= ' WHERE ' . implode('', $statementParts['where']);
314
+            $statement .= ' WHERE '.implode('', $statementParts['where']);
315 315
             if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) {
316
-                $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
316
+                $statement .= ' AND '.implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
317 317
             }
318 318
         } elseif (!empty($statementParts['additionalWhereClause'])) {
319
-            $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
319
+            $statement .= ' WHERE '.implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
320 320
         }
321 321
         if (!empty($statementParts['orderings'])) {
322
-            $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']);
322
+            $statement .= ' ORDER BY '.implode(', ', $statementParts['orderings']);
323 323
         }
324 324
         if (!empty($statementParts['limit'])) {
325
-            $statement .= ' LIMIT ' . $statementParts['limit'];
325
+            $statement .= ' LIMIT '.$statementParts['limit'];
326 326
         }
327 327
 
328 328
         return $statement;
@@ -339,10 +339,10 @@  discard block
 block discarded – undo
339 339
     {
340 340
         if ($source instanceof SelectorInterface) {
341 341
             $tableName = $source->getNodeTypeName();
342
-            $sql['fields'][$tableName] = $tableName . '.*';
342
+            $sql['fields'][$tableName] = $tableName.'.*';
343 343
             $sql['tables'][$tableName] = $tableName;
344 344
             if ($this->query->getDistinct()) {
345
-                $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct();
345
+                $sql['fields'][$tableName] = $tableName.'.'.$this->query->getDistinct();
346 346
                 $sql['keywords']['distinct'] = 'DISTINCT';
347 347
             }
348 348
         } elseif ($source instanceof JoinInterface) {
@@ -367,15 +367,15 @@  discard block
 block discarded – undo
367 367
             $rightTableName = $rightSource->getLeft()->getSelectorName();
368 368
         } else {
369 369
             $rightTableName = $rightSource->getSelectorName();
370
-            $sql['fields'][$leftTableName] = $rightTableName . '.*';
370
+            $sql['fields'][$leftTableName] = $rightTableName.'.*';
371 371
         }
372 372
         $sql['tables'][$leftTableName] = $leftTableName;
373
-        $sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName;
373
+        $sql['unions'][$rightTableName] = 'LEFT JOIN '.$rightTableName;
374 374
         $joinCondition = $join->getJoinCondition();
375 375
         if ($joinCondition instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\EquiJoinCondition) {
376 376
             $column1Name = $joinCondition->getProperty1Name();
377 377
             $column2Name = $joinCondition->getProperty2Name();
378
-            $sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name;
378
+            $sql['unions'][$rightTableName] .= ' ON '.$joinCondition->getSelector1Name().'.'.$column1Name.' = '.$joinCondition->getSelector2Name().'.'.$column2Name;
379 379
         }
380 380
         if ($rightSource instanceof JoinInterface) {
381 381
             $this->parseJoin($rightSource, $sql);
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
             if ($realInput instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
514 514
                 return $realInput->getUid();
515 515
             } else {
516
-                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);
516
+                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);
517 517
             }
518 518
         } elseif (is_bool($input)) {
519 519
             return $input === true ? 1 : 0;
@@ -558,9 +558,9 @@  discard block
 block discarded – undo
558 558
             $operator = $this->resolveOperator($operator);
559 559
             $constraintSQL = '';
560 560
             if ($valueFunction === null) {
561
-                $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?';
561
+                $constraintSQL .= (!empty($tableName) ? $tableName.'.' : '').$columnName.' '.$operator.' ?';
562 562
             } else {
563
-                $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?';
563
+                $constraintSQL .= $valueFunction.'('.(!empty($tableName) ? $tableName.'.' : '').$columnName.') '.$operator.' ?';
564 564
             }
565 565
 
566 566
             if (isset($tableName) && !empty($this->currentChildTableNameAlias)) {
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
         // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
591 591
         $parts = explode('.', $propertyPath, 3);
592 592
         if ($table->field($fieldName)->isGroup() && count($parts) > 2) {
593
-            $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1];
593
+            $explodedPropertyPath[0] = $parts[0].'.'.$parts[1];
594 594
             $explodedPropertyPath[1] = $parts[2];
595 595
             $fieldName = $explodedPropertyPath[0];
596 596
         }
@@ -599,16 +599,16 @@  discard block
 block discarded – undo
599 599
         $childTableName = $table->field($fieldName)->getForeignTable();
600 600
 
601 601
         if ($childTableName === null) {
602
-            throw new Exception\InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925);
602
+            throw new Exception\InvalidRelationConfigurationException('The relation information for property "'.$fieldName.'" of class "'.$tableName.'" is missing.', 1353170925);
603 603
         }
604 604
 
605 605
         if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one"
606 606
             // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons.
607 607
             // $parentKeyFieldName === null does the trick somehow. Before condition was if (isset($parentKeyFieldName))
608 608
             if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === null) {
609
-                $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid';
609
+                $sql['unions'][$childTableName] = 'LEFT JOIN '.$childTableName.' ON '.$tableName.'.'.$fieldName.'='.$childTableName.'.uid';
610 610
             } else {
611
-                $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
611
+                $sql['unions'][$childTableName] = 'LEFT JOIN '.$childTableName.' ON '.$tableName.'.uid='.$childTableName.'.'.$parentKeyFieldName;
612 612
             }
613 613
         } elseif ($table->field($fieldName)->hasRelationManyToMany()) {
614 614
             $relationTableName = $table->field($fieldName)->getManyToManyTable();
@@ -773,11 +773,11 @@  discard block
 block discarded – undo
773 773
                     foreach ($parameter as $item) {
774 774
                         $items[] = $this->databaseHandle->fullQuoteStr($item, $tableName);
775 775
                     }
776
-                    $parameter = '(' . implode(',', $items) . ')';
776
+                    $parameter = '('.implode(',', $items).')';
777 777
                 } else {
778 778
                     $parameter = $this->databaseHandle->fullQuoteStr($parameter, $tableName);
779 779
                 }
780
-                $sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, ($markPosition + 1));
780
+                $sqlString = substr($sqlString, 0, $markPosition).$parameter.substr($sqlString, ($markPosition + 1));
781 781
             }
782 782
             $offset = $markPosition + strlen($parameter);
783 783
         }
@@ -878,18 +878,18 @@  discard block
 block discarded – undo
878 878
         // If the table is found to have "workspace" support, add the corresponding fields in the statement.
879 879
         if (Tca::table($tableName)->hasWorkspaceSupport()) {
880 880
             if ($this->getBackendUser()->workspace === 0) {
881
-                $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE);
881
+                $statement .= ' AND '.$tableName.'.t3ver_state<='.new VersionState(VersionState::DEFAULT_STATE);
882 882
             } else {
883 883
                 // Show only records of live and of the current workspace
884 884
                 // In case we are in a Versioning preview
885
-                $statement .= ' AND (' .
886
-                    $tableName . '.t3ver_wsid=0 OR ' .
887
-                    $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace .
885
+                $statement .= ' AND ('.
886
+                    $tableName.'.t3ver_wsid=0 OR '.
887
+                    $tableName.'.t3ver_wsid='.(int)$this->getBackendUser()->workspace.
888 888
                     ')';
889 889
             }
890 890
 
891 891
             // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0
892
-            $statement .= ' AND ' . $tableName . '.pid<>-1';
892
+            $statement .= ' AND '.$tableName.'.pid<>-1';
893 893
         }
894 894
 
895 895
         if (!$includeDeleted) {
@@ -915,25 +915,25 @@  discard block
 block discarded – undo
915 915
         if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
916 916
             if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) {
917 917
                 // Select all entries for the current language
918
-                $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)';
918
+                $additionalWhereClause = $tableNameOrAlias.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['languageField'].' IN ('.intval($querySettings->getLanguageUid()).',-1)';
919 919
                 // If any language is set -> get those entries which are not translated yet
920 920
                 // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode
921 921
                 if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
922 922
                     && $querySettings->getLanguageUid() > 0
923 923
                 ) {
924
-                    $additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' .
925
-                        ' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] .
926
-                        ' FROM ' . $tableName .
927
-                        ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' .
928
-                        ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0';
924
+                    $additionalWhereClause .= ' OR ('.$tableNameOrAlias.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['languageField'].'=0'.
925
+                        ' AND '.$tableNameOrAlias.'.uid NOT IN (SELECT '.$tableName.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'].
926
+                        ' FROM '.$tableName.
927
+                        ' WHERE '.$tableName.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'].'>0'.
928
+                        ' AND '.$tableName.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['languageField'].'>0';
929 929
 
930 930
                     // Add delete clause to ensure all entries are loaded
931 931
                     if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) {
932
-                        $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0';
932
+                        $additionalWhereClause .= ' AND '.$tableNameOrAlias.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['delete'].'=0';
933 933
                     }
934 934
                     $additionalWhereClause .= '))';
935 935
                 }
936
-                $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')';
936
+                $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '('.$additionalWhereClause.')';
937 937
             }
938 938
         }
939 939
     }
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
     protected function parseLimitAndOffset($limit, $offset, array &$sql)
979 979
     {
980 980
         if ($limit !== null && $offset !== null) {
981
-            $sql['limit'] = intval($offset) . ', ' . intval($limit);
981
+            $sql['limit'] = intval($offset).', '.intval($limit);
982 982
         } elseif ($limit !== null) {
983 983
             $sql['limit'] = intval($limit);
984 984
         }
@@ -1045,10 +1045,10 @@  discard block
 block discarded – undo
1045 1045
                 && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
1046 1046
             ) {
1047 1047
                 $row = $this->databaseHandle->exec_SELECTgetSingleRow(
1048
-                    $tableName . '.*',
1048
+                    $tableName.'.*',
1049 1049
                     $tableName,
1050
-                    $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] .
1051
-                    ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0'
1050
+                    $tableName.'.uid='.(int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']].
1051
+                    ' AND '.$tableName.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['languageField'].'=0'
1052 1052
                 );
1053 1053
             }
1054 1054
         }
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
         }
1108 1108
 
1109 1109
         $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName];
1110
-        $tableNameAlias = $tableName . $numberOfAliases;
1110
+        $tableNameAlias = $tableName.$numberOfAliases;
1111 1111
 
1112 1112
         $this->tableNameAliases['aliasIncrement'][$tableName]++;
1113 1113
         $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName;
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
     {
1187 1187
         $error = $this->databaseHandle->sql_error();
1188 1188
         if ($error !== '') {
1189
-            $error .= $sql ? ': ' . $sql : '';
1189
+            $error .= $sql ? ': '.$sql : '';
1190 1190
             throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($error, 1247602160);
1191 1191
         }
1192 1192
     }
Please login to merge, or discard this patch.
Indentation   +1158 added lines, -1158 removed lines patch added patch discarded remove patch
@@ -31,1162 +31,1162 @@
 block discarded – undo
31 31
 class VidiDbBackend
32 32
 {
33 33
 
34
-    const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull';
35
-    const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull';
36
-
37
-    /**
38
-     * The TYPO3 database object
39
-     *
40
-     * @var \Fab\Vidi\Database\DatabaseConnection
41
-     */
42
-    protected $databaseHandle;
43
-
44
-    /**
45
-     * The TYPO3 page repository. Used for language and workspace overlay
46
-     *
47
-     * @var PageRepository
48
-     */
49
-    protected $pageRepository;
50
-
51
-    /**
52
-     * A first-level TypoScript configuration cache
53
-     *
54
-     * @var array
55
-     */
56
-    protected $pageTSConfigCache = [];
57
-
58
-    /**
59
-     * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
60
-     * @inject
61
-     */
62
-    protected $configurationManager;
63
-
64
-    /**
65
-     * @var \TYPO3\CMS\Extbase\Service\CacheService
66
-     * @inject
67
-     */
68
-    protected $cacheService;
69
-
70
-    /**
71
-     * @var \TYPO3\CMS\Core\Cache\CacheManager
72
-     * @inject
73
-     */
74
-    protected $cacheManager;
75
-
76
-    /**
77
-     * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
78
-     * @inject
79
-     */
80
-    protected $environmentService;
81
-
82
-    /**
83
-     * @var \Fab\Vidi\Persistence\Query
84
-     */
85
-    protected $query;
86
-
87
-    /**
88
-     * Store some info related to table name and its aliases.
89
-     *
90
-     * @var array
91
-     */
92
-    protected $tableNameAliases = array(
93
-        'aliases' => [],
94
-        'aliasIncrement' => [],
95
-    );
96
-
97
-    /**
98
-     * Use to store the current foreign table name alias.
99
-     *
100
-     * @var string
101
-     */
102
-    protected $currentChildTableNameAlias = '';
103
-
104
-    /**
105
-     * The default object type being returned.
106
-     *
107
-     * @var string
108
-     */
109
-    protected $objectType = 'Fab\Vidi\Domain\Model\Content';
110
-
111
-    /**
112
-     * Constructor. takes the database handle from $GLOBALS['TYPO3_DB']
113
-     */
114
-    public function __construct(QueryInterface $query)
115
-    {
116
-        $this->query = $query;
117
-        $this->databaseHandle = $GLOBALS['TYPO3_DB'];
118
-    }
119
-
120
-    /**
121
-     * @param array $identifier
122
-     * @return string
123
-     */
124
-    protected function parseIdentifier(array $identifier)
125
-    {
126
-        $fieldNames = array_keys($identifier);
127
-        $suffixedFieldNames = [];
128
-        foreach ($fieldNames as $fieldName) {
129
-            $suffixedFieldNames[] = $fieldName . '=?';
130
-        }
131
-        return implode(' AND ', $suffixedFieldNames);
132
-    }
133
-
134
-    /**
135
-     * Returns the result of the query
136
-     */
137
-    public function fetchResult()
138
-    {
139
-
140
-        $parameters = [];
141
-        $statementParts = $this->parseQuery($this->query, $parameters);
142
-        $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that.
143
-
144
-        $sql = $this->buildQuery($statementParts);
145
-        $tableName = '';
146
-        if (is_array($statementParts) && !empty(reset($statementParts['tables']))) {
147
-            $tableName = reset($statementParts['tables']);
148
-        }
149
-        $this->replacePlaceholders($sql, $parameters, $tableName);
150
-        #print $sql; exit(); // @debug
151
-
152
-        $result = $this->databaseHandle->sql_query($sql);
153
-        $this->checkSqlErrors($sql);
154
-        $rows = $this->getRowsFromResult($result);
155
-        $this->databaseHandle->sql_free_result($result);
156
-
157
-        return $rows;
158
-    }
159
-
160
-    /**
161
-     * Returns the number of tuples matching the query.
162
-     *
163
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException
164
-     * @return int The number of matching tuples
165
-     */
166
-    public function countResult()
167
-    {
168
-
169
-        $parameters = [];
170
-        $statementParts = $this->parseQuery($this->query, $parameters);
171
-        $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that.
172
-        // Reset $statementParts for valid table return
173
-        reset($statementParts);
174
-
175
-        // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints
176
-        if (!empty($statementParts['limit'])) {
177
-            $statement = $this->buildQuery($statementParts);
178
-            $this->replacePlaceholders($statement, $parameters, current($statementParts['tables']));
179
-            #print $statement; exit(); // @debug
180
-            $result = $this->databaseHandle->sql_query($statement);
181
-            $this->checkSqlErrors($statement);
182
-            $count = $this->databaseHandle->sql_num_rows($result);
183
-        } else {
184
-            $statementParts['fields'] = array('COUNT(*)');
185
-            // having orderings without grouping is not compatible with non-MySQL DBMS
186
-            $statementParts['orderings'] = [];
187
-            if (isset($statementParts['keywords']['distinct'])) {
188
-                unset($statementParts['keywords']['distinct']);
189
-                $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid';
190
-                $statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.' . $distinctField . ')');
191
-            }
192
-
193
-            $statement = $this->buildQuery($statementParts);
194
-            $this->replacePlaceholders($statement, $parameters, current($statementParts['tables']));
195
-
196
-            #print $statement; exit(); // @debug
197
-            $result = $this->databaseHandle->sql_query($statement);
198
-            $this->checkSqlErrors($statement);
199
-            $count = 0;
200
-            if ($result) {
201
-                $row = $this->databaseHandle->sql_fetch_assoc($result);
202
-                $count = current($row);
203
-            }
204
-        }
205
-        $this->databaseHandle->sql_free_result($result);
206
-        return (int)$count;
207
-    }
208
-
209
-    /**
210
-     * Parses the query and returns the SQL statement parts.
211
-     *
212
-     * @param QueryInterface $query The query
213
-     * @param array &$parameters
214
-     * @return array The SQL statement parts
215
-     */
216
-    public function parseQuery(QueryInterface $query, array &$parameters)
217
-    {
218
-        $statementParts = [];
219
-        $statementParts['keywords'] = [];
220
-        $statementParts['tables'] = [];
221
-        $statementParts['unions'] = [];
222
-        $statementParts['fields'] = [];
223
-        $statementParts['where'] = [];
224
-        $statementParts['additionalWhereClause'] = [];
225
-        $statementParts['orderings'] = [];
226
-        $statementParts['limit'] = [];
227
-        $source = $query->getSource();
228
-        $this->parseSource($source, $statementParts);
229
-        $this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters);
230
-        $this->parseOrderings($query->getOrderings(), $source, $statementParts);
231
-        $this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts);
232
-        $tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions']));
233
-        foreach ($tableNames as $tableNameOrAlias) {
234
-            if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) {
235
-                $this->addAdditionalWhereClause($query->getQuerySettings(), $tableNameOrAlias, $statementParts);
236
-            }
237
-        }
238
-
239
-        return $statementParts;
240
-    }
241
-
242
-    /**
243
-     * Fiddle with the statement structure to handle recursive MM relations.
244
-     * For the recursive MM query to work, we must invert some values.
245
-     * Let see if that is the best way of doing that...
246
-     *
247
-     * @param array $statementParts
248
-     * @return array
249
-     */
250
-    public function processStatementStructureForRecursiveMMRelation(array $statementParts)
251
-    {
252
-
253
-        if ($this->hasRecursiveMMRelation()) {
254
-            $tableName = $this->query->getType();
255
-
256
-            // In order the MM query to work for a recursive MM query, we must invert some values.
257
-            // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name)
258
-            $values = [];
259
-            foreach ($statementParts['fields'] as $key => $value) {
260
-                $values[$key] = str_replace($tableName, $tableName . '0', $value);
261
-            }
262
-            $statementParts['fields'] = $values;
263
-
264
-            // Same comment as above.
265
-            $values = [];
266
-            foreach ($statementParts['where'] as $key => $value) {
267
-                $values[$key] = str_replace($tableName . '0', $tableName, $value);
268
-            }
269
-            $statementParts['where'] = $values;
270
-
271
-            // We must be more restrictive by transforming the "left" union by "inner"
272
-            $values = [];
273
-            foreach ($statementParts['unions'] as $key => $value) {
274
-                $values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value);
275
-            }
276
-            $statementParts['unions'] = $values;
277
-        }
278
-
279
-        return $statementParts;
280
-    }
281
-
282
-    /**
283
-     * Tell whether there is a recursive MM relation.
284
-     *
285
-     * @return bool
286
-     */
287
-    public function hasRecursiveMMRelation()
288
-    {
289
-        return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]);
290
-
291
-    }
292
-
293
-    /**
294
-     * Returns the statement, ready to be executed.
295
-     *
296
-     * @param array $statementParts The SQL statement parts
297
-     * @return string The SQL statement
298
-     */
299
-    public function buildQuery(array $statementParts)
300
-    {
301
-
302
-        // Add more statement to the UNION part.
303
-        if (!empty($statementParts['unions'])) {
304
-            foreach ($statementParts['unions'] as $tableName => $unionPart) {
305
-                if (!empty($statementParts['additionalWhereClause'][$tableName])) {
306
-                    $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]);
307
-                }
308
-            }
309
-        }
310
-
311
-        $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']);
312
-        if (!empty($statementParts['where'])) {
313
-            $statement .= ' WHERE ' . implode('', $statementParts['where']);
314
-            if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) {
315
-                $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
316
-            }
317
-        } elseif (!empty($statementParts['additionalWhereClause'])) {
318
-            $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
319
-        }
320
-        if (!empty($statementParts['orderings'])) {
321
-            $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']);
322
-        }
323
-        if (!empty($statementParts['limit'])) {
324
-            $statement .= ' LIMIT ' . $statementParts['limit'];
325
-        }
326
-
327
-        return $statement;
328
-    }
329
-
330
-    /**
331
-     * Transforms a Query Source into SQL and parameter arrays
332
-     *
333
-     * @param SourceInterface $source The source
334
-     * @param array &$sql
335
-     * @return void
336
-     */
337
-    protected function parseSource(SourceInterface $source, array &$sql)
338
-    {
339
-        if ($source instanceof SelectorInterface) {
340
-            $tableName = $source->getNodeTypeName();
341
-            $sql['fields'][$tableName] = $tableName . '.*';
342
-            $sql['tables'][$tableName] = $tableName;
343
-            if ($this->query->getDistinct()) {
344
-                $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct();
345
-                $sql['keywords']['distinct'] = 'DISTINCT';
346
-            }
347
-        } elseif ($source instanceof JoinInterface) {
348
-            $this->parseJoin($source, $sql);
349
-        }
350
-    }
351
-
352
-    /**
353
-     * Transforms a Join into SQL and parameter arrays
354
-     *
355
-     * @param JoinInterface $join The join
356
-     * @param array &$sql The query parts
357
-     * @return void
358
-     */
359
-    protected function parseJoin(JoinInterface $join, array &$sql)
360
-    {
361
-        $leftSource = $join->getLeft();
362
-        $leftTableName = $leftSource->getSelectorName();
363
-        // $sql['fields'][$leftTableName] = $leftTableName . '.*';
364
-        $rightSource = $join->getRight();
365
-        if ($rightSource instanceof JoinInterface) {
366
-            $rightTableName = $rightSource->getLeft()->getSelectorName();
367
-        } else {
368
-            $rightTableName = $rightSource->getSelectorName();
369
-            $sql['fields'][$leftTableName] = $rightTableName . '.*';
370
-        }
371
-        $sql['tables'][$leftTableName] = $leftTableName;
372
-        $sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName;
373
-        $joinCondition = $join->getJoinCondition();
374
-        if ($joinCondition instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\EquiJoinCondition) {
375
-            $column1Name = $joinCondition->getProperty1Name();
376
-            $column2Name = $joinCondition->getProperty2Name();
377
-            $sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name;
378
-        }
379
-        if ($rightSource instanceof JoinInterface) {
380
-            $this->parseJoin($rightSource, $sql);
381
-        }
382
-    }
383
-
384
-    /**
385
-     * Transforms a constraint into SQL and parameter arrays
386
-     *
387
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint The constraint
388
-     * @param SourceInterface $source The source
389
-     * @param array &$sql The query parts
390
-     * @param array &$parameters The parameters that will replace the markers
391
-     * @return void
392
-     */
393
-    protected function parseConstraint(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint = null, SourceInterface $source, array &$sql, array &$parameters)
394
-    {
395
-        if ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface) {
396
-            $sql['where'][] = '(';
397
-            $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
398
-            $sql['where'][] = ' AND ';
399
-            $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
400
-            $sql['where'][] = ')';
401
-        } elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface) {
402
-            $sql['where'][] = '(';
403
-            $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
404
-            $sql['where'][] = ' OR ';
405
-            $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
406
-            $sql['where'][] = ')';
407
-        } elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface) {
408
-            $sql['where'][] = 'NOT (';
409
-            $this->parseConstraint($constraint->getConstraint(), $source, $sql, $parameters);
410
-            $sql['where'][] = ')';
411
-        } elseif ($constraint instanceof ComparisonInterface) {
412
-            $this->parseComparison($constraint, $source, $sql, $parameters);
413
-        }
414
-    }
415
-
416
-    /**
417
-     * Parse a Comparison into SQL and parameter arrays.
418
-     *
419
-     * @param ComparisonInterface $comparison The comparison to parse
420
-     * @param SourceInterface $source The source
421
-     * @param array &$sql SQL query parts to add to
422
-     * @param array &$parameters Parameters to bind to the SQL
423
-     * @throws Exception\RepositoryException
424
-     * @return void
425
-     */
426
-    protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$sql, array &$parameters)
427
-    {
428
-        $operand1 = $comparison->getOperand1();
429
-        $operator = $comparison->getOperator();
430
-        $operand2 = $comparison->getOperand2();
431
-        if ($operator === QueryInterface::OPERATOR_IN) {
432
-            $items = [];
433
-            $hasValue = false;
434
-            foreach ($operand2 as $value) {
435
-                $value = $this->getPlainValue($value);
436
-                if ($value !== null) {
437
-                    $items[] = $value;
438
-                    $hasValue = true;
439
-                }
440
-            }
441
-            if ($hasValue === false) {
442
-                $sql['where'][] = '1<>1';
443
-            } else {
444
-                $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters, null);
445
-                $parameters[] = $items;
446
-            }
447
-        } elseif ($operator === QueryInterface::OPERATOR_CONTAINS) {
448
-            if ($operand2 === null) {
449
-                $sql['where'][] = '1<>1';
450
-            } else {
451
-                throw new \Exception('Not implemented! Contact extension author.', 1412931227);
452
-                # @todo re-implement me if necessary.
453
-                #$tableName = $this->query->getType();
454
-                #$propertyName = $operand1->getPropertyName();
455
-                #while (strpos($propertyName, '.') !== false) {
456
-                #	$this->addUnionStatement($tableName, $propertyName, $sql);
457
-                #}
458
-                #$columnName = $propertyName;
459
-                #$columnMap = $propertyName;
460
-                #$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : null;
461
-                #if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
462
-                #	$relationTableName = $columnMap->getRelationTableName();
463
-                #	$sql['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)';
464
-                #	$parameters[] = intval($this->getPlainValue($operand2));
465
-                #} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) {
466
-                #	$parentKeyFieldName = $columnMap->getParentKeyFieldName();
467
-                #	if (isset($parentKeyFieldName)) {
468
-                #		$childTableName = $columnMap->getChildTableName();
469
-                #		$sql['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)';
470
-                #		$parameters[] = intval($this->getPlainValue($operand2));
471
-                #	} else {
472
-                #		$sql['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')';
473
-                #		$parameters[] = intval($this->getPlainValue($operand2));
474
-                #	}
475
-                #} else {
476
-                #	throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745);
477
-                #}
478
-            }
479
-        } else {
480
-            if ($operand2 === null) {
481
-                if ($operator === QueryInterface::OPERATOR_EQUAL_TO) {
482
-                    $operator = self::OPERATOR_EQUAL_TO_NULL;
483
-                } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) {
484
-                    $operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
485
-                }
486
-            }
487
-            $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters);
488
-            $parameters[] = $this->getPlainValue($operand2);
489
-        }
490
-    }
491
-
492
-    /**
493
-     * Returns a plain value, i.e. objects are flattened out if possible.
494
-     *
495
-     * @param mixed $input
496
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException
497
-     * @return mixed
498
-     */
499
-    protected function getPlainValue($input)
500
-    {
501
-        if (is_array($input)) {
502
-            throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932);
503
-        }
504
-        if ($input instanceof \DateTime) {
505
-            return $input->format('U');
506
-        } elseif (is_object($input)) {
507
-            if ($input instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
508
-                $realInput = $input->_loadRealInstance();
509
-            } else {
510
-                $realInput = $input;
511
-            }
512
-            if ($realInput instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
513
-                return $realInput->getUid();
514
-            } else {
515
-                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);
516
-            }
517
-        } elseif (is_bool($input)) {
518
-            return $input === true ? 1 : 0;
519
-        } else {
520
-            return $input;
521
-        }
522
-    }
523
-
524
-    /**
525
-     * Parse a DynamicOperand into SQL and parameter arrays.
526
-     *
527
-     * @param DynamicOperandInterface $operand
528
-     * @param string $operator One of the JCR_OPERATOR_* constants
529
-     * @param SourceInterface $source The source
530
-     * @param array &$sql The query parts
531
-     * @param array &$parameters The parameters that will replace the markers
532
-     * @param string $valueFunction an optional SQL function to apply to the operand value
533
-     * @return void
534
-     */
535
-    protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$sql, array &$parameters, $valueFunction = null)
536
-    {
537
-        if ($operand instanceof LowerCaseInterface) {
538
-            $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER');
539
-        } elseif ($operand instanceof UpperCaseInterface) {
540
-            $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'UPPER');
541
-        } elseif ($operand instanceof PropertyValueInterface) {
542
-            $propertyName = $operand->getPropertyName();
543
-
544
-            // Reset value.
545
-            $this->currentChildTableNameAlias = '';
546
-
547
-            if ($source instanceof SelectorInterface) {
548
-                $tableName = $this->query->getType();
549
-                while (strpos($propertyName, '.') !== false) {
550
-                    $this->addUnionStatement($tableName, $propertyName, $sql);
551
-                }
552
-            } elseif ($source instanceof JoinInterface) {
553
-                $tableName = $source->getJoinCondition()->getSelector1Name();
554
-            }
555
-
556
-            $columnName = $propertyName;
557
-            $operator = $this->resolveOperator($operator);
558
-            $constraintSQL = '';
559
-            if ($valueFunction === null) {
560
-                $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?';
561
-            } else {
562
-                $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?';
563
-            }
564
-
565
-            if (isset($tableName) && !empty($this->currentChildTableNameAlias)) {
566
-                $constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL);
567
-            }
568
-            $sql['where'][] = $constraintSQL;
569
-        }
570
-    }
571
-
572
-    /**
573
-     * @param string &$tableName
574
-     * @param array &$propertyPath
575
-     * @param array &$sql
576
-     * @throws Exception
577
-     * @throws Exception\InvalidRelationConfigurationException
578
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\MissingColumnMapException
579
-     */
580
-    protected function addUnionStatement(&$tableName, &$propertyPath, array &$sql)
581
-    {
582
-
583
-        $table = Tca::table($tableName);
584
-
585
-        $explodedPropertyPath = explode('.', $propertyPath, 2);
586
-        $fieldName = $explodedPropertyPath[0];
587
-
588
-        // Field of type "group" are special because property path must contain the table name
589
-        // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
590
-        $parts = explode('.', $propertyPath, 3);
591
-        if ($table->field($fieldName)->isGroup() && count($parts) > 2) {
592
-            $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1];
593
-            $explodedPropertyPath[1] = $parts[2];
594
-            $fieldName = $explodedPropertyPath[0];
595
-        }
596
-
597
-        $parentKeyFieldName = $table->field($fieldName)->getForeignField();
598
-        $childTableName = $table->field($fieldName)->getForeignTable();
599
-
600
-        if ($childTableName === null) {
601
-            throw new Exception\InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925);
602
-        }
603
-
604
-        if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one"
605
-            // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons.
606
-            // $parentKeyFieldName === null does the trick somehow. Before condition was if (isset($parentKeyFieldName))
607
-            if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === null) {
608
-                $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid';
609
-            } else {
610
-                $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
611
-            }
612
-        } elseif ($table->field($fieldName)->hasRelationManyToMany()) {
613
-            $relationTableName = $table->field($fieldName)->getManyToManyTable();
614
-
615
-            $parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
616
-            $childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
617
-
618
-            // MM table e.g sys_category_record_mm
619
-            $relationTableNameAlias = $this->generateAlias($relationTableName);
620
-            $join = sprintf(
621
-                'LEFT JOIN %s AS %s ON %s.uid=%s.%s', $relationTableName,
622
-                $relationTableNameAlias,
623
-                $tableName,
624
-                $relationTableNameAlias,
625
-                $parentKeyFieldName
626
-            );
627
-            $sql['unions'][$relationTableNameAlias] = $join;
628
-
629
-            // Foreign table e.g sys_category
630
-            $childTableNameAlias = $this->generateAlias($childTableName);
631
-            $this->currentChildTableNameAlias = $childTableNameAlias;
632
-            $join = sprintf(
633
-                'LEFT JOIN %s AS %s ON %s.%s=%s.uid',
634
-                $childTableName,
635
-                $childTableNameAlias,
636
-                $relationTableNameAlias,
637
-                $childKeyFieldName,
638
-                $childTableNameAlias
639
-            );
640
-            $sql['unions'][$childTableNameAlias] = $join;
641
-
642
-            // Find a possible table name for a MM condition.
643
-            $tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition();
644
-            if ($tableNameCondition) {
645
-
646
-                // If we can find a source file name,  we can then retrieve more MM conditions from the TCA such as a field name.
647
-                $sourceFileName = $this->query->getSourceFieldName();
648
-                if (empty($sourceFileName)) {
649
-                    $additionalMMConditions = array(
650
-                        'tablenames' => $tableNameCondition,
651
-                    );
652
-                } else {
653
-                    $additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition();
654
-                }
655
-
656
-                foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) {
657
-                    $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
658
-                    $sql['unions'][$relationTableNameAlias] .= $additionalJoin;
659
-
660
-                    $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
661
-                    $sql['unions'][$childTableNameAlias] .= $additionalJoin;
662
-                }
663
-
664
-            }
665
-
666
-
667
-        } elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations
668
-            $childTableNameAlias = $this->generateAlias($childTableName);
669
-            $this->currentChildTableNameAlias = $childTableNameAlias;
670
-
671
-            if (isset($parentKeyFieldName)) {
672
-                $join = sprintf(
673
-                    'LEFT JOIN %s AS %s ON %s.uid=%s.%s',
674
-                    $childTableName,
675
-                    $childTableNameAlias,
676
-                    $tableName,
677
-                    $childTableNameAlias,
678
-                    $parentKeyFieldName
679
-                );
680
-                $sql['unions'][$childTableNameAlias] = $join;
681
-            } else {
682
-                $join = sprintf(
683
-                    'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))',
684
-                    $childTableName,
685
-                    $childTableNameAlias,
686
-                    $childTableNameAlias,
687
-                    $tableName,
688
-                    $fieldName
689
-                );
690
-                $sql['unions'][$childTableNameAlias] = $join;
691
-            }
692
-        } else {
693
-            throw new Exception('Could not determine type of relation.', 1252502725);
694
-        }
695
-
696
-        // TODO check if there is another solution for this
697
-        $sql['keywords']['distinct'] = 'DISTINCT';
698
-        $propertyPath = $explodedPropertyPath[1];
699
-        $tableName = $childTableName;
700
-    }
701
-
702
-    /**
703
-     * Returns the SQL operator for the given JCR operator type.
704
-     *
705
-     * @param string $operator One of the JCR_OPERATOR_* constants
706
-     * @throws Exception
707
-     * @return string an SQL operator
708
-     */
709
-    protected function resolveOperator($operator)
710
-    {
711
-        switch ($operator) {
712
-            case self::OPERATOR_EQUAL_TO_NULL:
713
-                $operator = 'IS';
714
-                break;
715
-            case self::OPERATOR_NOT_EQUAL_TO_NULL:
716
-                $operator = 'IS NOT';
717
-                break;
718
-            case QueryInterface::OPERATOR_IN:
719
-                $operator = 'IN';
720
-                break;
721
-            case QueryInterface::OPERATOR_EQUAL_TO:
722
-                $operator = '=';
723
-                break;
724
-            case QueryInterface::OPERATOR_NOT_EQUAL_TO:
725
-                $operator = '!=';
726
-                break;
727
-            case QueryInterface::OPERATOR_LESS_THAN:
728
-                $operator = '<';
729
-                break;
730
-            case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO:
731
-                $operator = '<=';
732
-                break;
733
-            case QueryInterface::OPERATOR_GREATER_THAN:
734
-                $operator = '>';
735
-                break;
736
-            case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO:
737
-                $operator = '>=';
738
-                break;
739
-            case QueryInterface::OPERATOR_LIKE:
740
-                $operator = 'LIKE';
741
-                break;
742
-            default:
743
-                throw new Exception('Unsupported operator encountered.', 1242816073);
744
-        }
745
-        return $operator;
746
-    }
747
-
748
-    /**
749
-     * Replace query placeholders in a query part by the given
750
-     * parameters.
751
-     *
752
-     * @param string &$sqlString The query part with placeholders
753
-     * @param array $parameters The parameters
754
-     * @param string $tableName
755
-     *
756
-     * @throws Exception
757
-     */
758
-    protected function replacePlaceholders(&$sqlString, array $parameters, $tableName = 'foo')
759
-    {
760
-        // TODO profile this method again
761
-        if (substr_count($sqlString, '?') !== count($parameters)) {
762
-            throw new Exception('The number of question marks to replace must be equal to the number of parameters.', 1242816074);
763
-        }
764
-        $offset = 0;
765
-        foreach ($parameters as $parameter) {
766
-            $markPosition = strpos($sqlString, '?', $offset);
767
-            if ($markPosition !== false) {
768
-                if ($parameter === null) {
769
-                    $parameter = 'null';
770
-                } elseif (is_array($parameter) || $parameter instanceof \ArrayAccess || $parameter instanceof \Traversable) {
771
-                    $items = [];
772
-                    foreach ($parameter as $item) {
773
-                        $items[] = $this->databaseHandle->fullQuoteStr($item, $tableName);
774
-                    }
775
-                    $parameter = '(' . implode(',', $items) . ')';
776
-                } else {
777
-                    $parameter = $this->databaseHandle->fullQuoteStr($parameter, $tableName);
778
-                }
779
-                $sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, ($markPosition + 1));
780
-            }
781
-            $offset = $markPosition + strlen($parameter);
782
-        }
783
-    }
784
-
785
-    /**
786
-     * Adds additional WHERE statements according to the query settings.
787
-     *
788
-     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
789
-     * @param string $tableNameOrAlias The table name to add the additional where clause for
790
-     * @param array &$statementParts
791
-     * @return void
792
-     */
793
-    protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts)
794
-    {
795
-        $this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts);
796
-        if ($querySettings->getRespectSysLanguage()) {
797
-            $this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings);
798
-        }
799
-    }
800
-
801
-    /**
802
-     * Adds enableFields and deletedClause to the query if necessary
803
-     *
804
-     * @param QuerySettingsInterface $querySettings
805
-     * @param string $tableNameOrAlias The database table name
806
-     * @param array &$statementParts The query parts
807
-     * @return void
808
-     */
809
-    protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts)
810
-    {
811
-        $statement = '';
812
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
813
-        if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
814
-            $ignoreEnableFields = $querySettings->getIgnoreEnableFields();
815
-            $enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored();
816
-            $includeDeleted = $querySettings->getIncludeDeleted();
817
-            if ($this->environmentService->isEnvironmentInFrontendMode()) {
818
-                $statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted);
819
-            } else {
820
-                // TYPO3_MODE === 'BE'
821
-                $statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted);
822
-            }
823
-
824
-            // Remove the prefixing "AND" if any.
825
-            if (!empty($statement)) {
826
-                $statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement;
827
-                $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement;
828
-            }
829
-        }
830
-    }
831
-
832
-    /**
833
-     * Returns constraint statement for frontend context
834
-     *
835
-     * @param string $tableNameOrAlias
836
-     * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
837
-     * @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.
838
-     * @param boolean $includeDeleted A flag indicating whether deleted records should be included
839
-     * @return string
840
-     * @throws Exception\InconsistentQuerySettingsException
841
-     */
842
-    protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored = [], $includeDeleted)
843
-    {
844
-        $statement = '';
845
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
846
-        if ($ignoreEnableFields && !$includeDeleted) {
847
-            if (count($enableFieldsToBeIgnored)) {
848
-                // array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented
849
-                $statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored));
850
-            } else {
851
-                $statement .= $this->getPageRepository()->deleteClause($tableName);
852
-            }
853
-        } elseif (!$ignoreEnableFields && !$includeDeleted) {
854
-            $statement .= $this->getPageRepository()->enableFields($tableName);
855
-        } elseif (!$ignoreEnableFields && $includeDeleted) {
856
-            throw new Exception\InconsistentQuerySettingsException('Query setting "ignoreEnableFields=false" can not be used together with "includeDeleted=true" in frontend context.', 1327678173);
857
-        }
858
-        return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
859
-    }
860
-
861
-    /**
862
-     * Returns constraint statement for backend context
863
-     *
864
-     * @param string $tableNameOrAlias
865
-     * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
866
-     * @param boolean $includeDeleted A flag indicating whether deleted records should be included
867
-     * @return string
868
-     */
869
-    protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted)
870
-    {
871
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
872
-        $statement = '';
873
-        if (!$ignoreEnableFields) {
874
-            $statement .= BackendUtility::BEenableFields($tableName);
875
-        }
876
-
877
-        // If the table is found to have "workspace" support, add the corresponding fields in the statement.
878
-        if (Tca::table($tableName)->hasWorkspaceSupport()) {
879
-            if ($this->getBackendUser()->workspace === 0) {
880
-                $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE);
881
-            } else {
882
-                // Show only records of live and of the current workspace
883
-                // In case we are in a Versioning preview
884
-                $statement .= ' AND (' .
885
-                    $tableName . '.t3ver_wsid=0 OR ' .
886
-                    $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace .
887
-                    ')';
888
-            }
889
-
890
-            // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0
891
-            $statement .= ' AND ' . $tableName . '.pid<>-1';
892
-        }
893
-
894
-        if (!$includeDeleted) {
895
-            $statement .= BackendUtility::deleteClause($tableName);
896
-        }
897
-
898
-        return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
899
-    }
900
-
901
-    /**
902
-     * Builds the language field statement
903
-     *
904
-     * @param string $tableNameOrAlias The database table name
905
-     * @param array &$statementParts The query parts
906
-     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
907
-     * @throws Exception
908
-     * @return void
909
-     */
910
-    protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings)
911
-    {
912
-
913
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
914
-        if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
915
-            if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) {
916
-                // Select all entries for the current language
917
-                $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)';
918
-                // If any language is set -> get those entries which are not translated yet
919
-                // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode
920
-                if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
921
-                    && $querySettings->getLanguageUid() > 0
922
-                ) {
923
-                    $additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' .
924
-                        ' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] .
925
-                        ' FROM ' . $tableName .
926
-                        ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' .
927
-                        ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0';
928
-
929
-                    // Add delete clause to ensure all entries are loaded
930
-                    if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) {
931
-                        $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0';
932
-                    }
933
-                    $additionalWhereClause .= '))';
934
-                }
935
-                $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')';
936
-            }
937
-        }
938
-    }
939
-
940
-    /**
941
-     * Transforms orderings into SQL.
942
-     *
943
-     * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
944
-     * @param SourceInterface $source The source
945
-     * @param array &$sql The query parts
946
-     * @throws Exception\UnsupportedOrderException
947
-     * @return void
948
-     */
949
-    protected function parseOrderings(array $orderings, SourceInterface $source, array &$sql)
950
-    {
951
-        foreach ($orderings as $fieldNameAndPath => $order) {
952
-            switch ($order) {
953
-                case QueryInterface::ORDER_ASCENDING:
954
-                    $order = 'ASC';
955
-                    break;
956
-                case QueryInterface::ORDER_DESCENDING:
957
-                    $order = 'DESC';
958
-                    break;
959
-                default:
960
-                    throw new Exception\UnsupportedOrderException('Unsupported order encountered.', 1456845126);
961
-            }
962
-
963
-            $tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType());
964
-            $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName);
965
-            $sql['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order);
966
-        }
967
-    }
968
-
969
-    /**
970
-     * Transforms limit and offset into SQL
971
-     *
972
-     * @param int $limit
973
-     * @param int $offset
974
-     * @param array &$sql
975
-     * @return void
976
-     */
977
-    protected function parseLimitAndOffset($limit, $offset, array &$sql)
978
-    {
979
-        if ($limit !== null && $offset !== null) {
980
-            $sql['limit'] = intval($offset) . ', ' . intval($limit);
981
-        } elseif ($limit !== null) {
982
-            $sql['limit'] = intval($limit);
983
-        }
984
-    }
985
-
986
-    /**
987
-     * Transforms a Resource from a database query to an array of rows.
988
-     *
989
-     * @param resource $result The result
990
-     * @return array The result as an array of rows (tuples)
991
-     */
992
-    protected function getRowsFromResult($result)
993
-    {
994
-        $rows = [];
995
-        while ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
996
-            if (is_array($row)) {
997
-
998
-                // Get language uid from querySettings.
999
-                // Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed)
1000
-                $overlaidRow = $this->doLanguageAndWorkspaceOverlay($this->query->getSource(), $row, $this->query->getQuerySettings());
1001
-                $contentObject = GeneralUtility::makeInstance($this->objectType, $this->query->getType(), $overlaidRow);
1002
-                $rows[] = $contentObject;
1003
-            }
1004
-        }
1005
-
1006
-        return $rows;
1007
-    }
1008
-
1009
-    /**
1010
-     * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
1011
-     * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
1012
-     *
1013
-     * @param SourceInterface $source The source (selector od join)
1014
-     * @param array $row
1015
-     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
1016
-     * @return array
1017
-     */
1018
-    protected function doLanguageAndWorkspaceOverlay(SourceInterface $source, array $row, $querySettings)
1019
-    {
1020
-
1021
-        /** @var SelectorInterface $source */
1022
-        $tableName = $source->getSelectorName();
1023
-
1024
-        $pageRepository = $this->getPageRepository();
1025
-        if (is_object($GLOBALS['TSFE'])) {
1026
-            $languageMode = $GLOBALS['TSFE']->sys_language_mode;
1027
-            if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) {
1028
-                $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace;
1029
-            }
1030
-        } else {
1031
-            $languageMode = '';
1032
-            $workspaceUid = $this->getBackendUser()->workspace;
1033
-            $pageRepository->versioningWorkspaceId = $workspaceUid;
1034
-            if ($this->getBackendUser()->workspace !== 0) {
1035
-                $pageRepository->versioningPreview = 1;
1036
-            }
1037
-        }
1038
-
1039
-        // If current row is a translation select its parent
1040
-        if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
1041
-            && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
1042
-        ) {
1043
-            if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']])
1044
-                && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
1045
-            ) {
1046
-                $row = $this->databaseHandle->exec_SELECTgetSingleRow(
1047
-                    $tableName . '.*',
1048
-                    $tableName,
1049
-                    $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] .
1050
-                    ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0'
1051
-                );
1052
-            }
1053
-        }
1054
-
1055
-        // Retrieve the original uid; Used for Workspaces!
1056
-        if (TYPO3_MODE !== 'BE') {
1057
-            $pageRepository->versionOL($tableName, $row, true, true);
1058
-        } else {
1059
-            \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($tableName, $row);
1060
-        }
1061
-        if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) {
1062
-            $row['uid'] = $row['_ORIG_uid'];
1063
-        }
1064
-
1065
-        // Special case for table "pages"
1066
-        if ($tableName == 'pages') {
1067
-            $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
1068
-        } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
1069
-            && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== ''
1070
-        ) {
1071
-            if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
1072
-                $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : '';
1073
-                $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
1074
-            }
1075
-        }
1076
-
1077
-        return $row;
1078
-    }
1079
-
1080
-    /**
1081
-     * Return a resolved table name given a possible table name alias.
1082
-     *
1083
-     * @param string $tableNameOrAlias
1084
-     * @return string
1085
-     */
1086
-    protected function resolveTableNameAlias($tableNameOrAlias)
1087
-    {
1088
-        $resolvedTableName = $tableNameOrAlias;
1089
-        if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) {
1090
-            $resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias];
1091
-        }
1092
-        return $resolvedTableName;
1093
-    }
1094
-
1095
-    /**
1096
-     * Generate a unique table name alias for the given table name.
1097
-     *
1098
-     * @param string $tableName
1099
-     * @return string
1100
-     */
1101
-    protected function generateAlias($tableName)
1102
-    {
1103
-
1104
-        if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) {
1105
-            $this->tableNameAliases['aliasIncrement'][$tableName] = 0;
1106
-        }
1107
-
1108
-        $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName];
1109
-        $tableNameAlias = $tableName . $numberOfAliases;
1110
-
1111
-        $this->tableNameAliases['aliasIncrement'][$tableName]++;
1112
-        $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName;
1113
-
1114
-        return $tableNameAlias;
1115
-    }
1116
-
1117
-    /**
1118
-     * Replace the table names by its table name alias within the given statement.
1119
-     *
1120
-     * @param string $tableName
1121
-     * @param string $tableNameAlias
1122
-     * @param string $statement
1123
-     * @return string
1124
-     */
1125
-    protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement)
1126
-    {
1127
-        if ($statement && $tableName !== $tableNameAlias) {
1128
-            $statement = str_replace($tableName, $tableNameAlias, $statement);
1129
-        }
1130
-        return $statement;
1131
-    }
1132
-
1133
-    /**
1134
-     * Returns an instance of the current Backend User.
1135
-     *
1136
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1137
-     */
1138
-    protected function getBackendUser()
1139
-    {
1140
-        return $GLOBALS['BE_USER'];
1141
-    }
1142
-
1143
-    /**
1144
-     * Tell whether a Backend User is logged in.
1145
-     *
1146
-     * @return bool
1147
-     */
1148
-    protected function isBackendUserLogged()
1149
-    {
1150
-        return is_object($GLOBALS['BE_USER']);
1151
-    }
1152
-
1153
-    /**
1154
-     * @return PageRepository|object
1155
-     */
1156
-    protected function getPageRepository()
1157
-    {
1158
-        if (!$this->pageRepository instanceof PageRepository) {
1159
-            if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($GLOBALS['TSFE'])) {
1160
-                $this->pageRepository = $GLOBALS['TSFE']->sys_page;
1161
-            } else {
1162
-                $this->pageRepository = GeneralUtility::makeInstance(PageRepository::class);
1163
-            }
1164
-        }
1165
-
1166
-        return $this->pageRepository;
1167
-    }
1168
-
1169
-    /**
1170
-     * @return \Fab\Vidi\Resolver\FieldPathResolver|object
1171
-     */
1172
-    protected function getFieldPathResolver()
1173
-    {
1174
-        return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\FieldPathResolver::class);
1175
-    }
1176
-
1177
-    /**
1178
-     * Checks if there are SQL errors in the last query, and if yes, throw an exception.
1179
-     *
1180
-     * @return void
1181
-     * @param string $sql The SQL statement
1182
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException
1183
-     */
1184
-    protected function checkSqlErrors($sql = '')
1185
-    {
1186
-        $error = $this->databaseHandle->sql_error();
1187
-        if ($error !== '') {
1188
-            $error .= $sql ? ': ' . $sql : '';
1189
-            throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($error, 1247602160);
1190
-        }
1191
-    }
34
+	const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull';
35
+	const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull';
36
+
37
+	/**
38
+	 * The TYPO3 database object
39
+	 *
40
+	 * @var \Fab\Vidi\Database\DatabaseConnection
41
+	 */
42
+	protected $databaseHandle;
43
+
44
+	/**
45
+	 * The TYPO3 page repository. Used for language and workspace overlay
46
+	 *
47
+	 * @var PageRepository
48
+	 */
49
+	protected $pageRepository;
50
+
51
+	/**
52
+	 * A first-level TypoScript configuration cache
53
+	 *
54
+	 * @var array
55
+	 */
56
+	protected $pageTSConfigCache = [];
57
+
58
+	/**
59
+	 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
60
+	 * @inject
61
+	 */
62
+	protected $configurationManager;
63
+
64
+	/**
65
+	 * @var \TYPO3\CMS\Extbase\Service\CacheService
66
+	 * @inject
67
+	 */
68
+	protected $cacheService;
69
+
70
+	/**
71
+	 * @var \TYPO3\CMS\Core\Cache\CacheManager
72
+	 * @inject
73
+	 */
74
+	protected $cacheManager;
75
+
76
+	/**
77
+	 * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
78
+	 * @inject
79
+	 */
80
+	protected $environmentService;
81
+
82
+	/**
83
+	 * @var \Fab\Vidi\Persistence\Query
84
+	 */
85
+	protected $query;
86
+
87
+	/**
88
+	 * Store some info related to table name and its aliases.
89
+	 *
90
+	 * @var array
91
+	 */
92
+	protected $tableNameAliases = array(
93
+		'aliases' => [],
94
+		'aliasIncrement' => [],
95
+	);
96
+
97
+	/**
98
+	 * Use to store the current foreign table name alias.
99
+	 *
100
+	 * @var string
101
+	 */
102
+	protected $currentChildTableNameAlias = '';
103
+
104
+	/**
105
+	 * The default object type being returned.
106
+	 *
107
+	 * @var string
108
+	 */
109
+	protected $objectType = 'Fab\Vidi\Domain\Model\Content';
110
+
111
+	/**
112
+	 * Constructor. takes the database handle from $GLOBALS['TYPO3_DB']
113
+	 */
114
+	public function __construct(QueryInterface $query)
115
+	{
116
+		$this->query = $query;
117
+		$this->databaseHandle = $GLOBALS['TYPO3_DB'];
118
+	}
119
+
120
+	/**
121
+	 * @param array $identifier
122
+	 * @return string
123
+	 */
124
+	protected function parseIdentifier(array $identifier)
125
+	{
126
+		$fieldNames = array_keys($identifier);
127
+		$suffixedFieldNames = [];
128
+		foreach ($fieldNames as $fieldName) {
129
+			$suffixedFieldNames[] = $fieldName . '=?';
130
+		}
131
+		return implode(' AND ', $suffixedFieldNames);
132
+	}
133
+
134
+	/**
135
+	 * Returns the result of the query
136
+	 */
137
+	public function fetchResult()
138
+	{
139
+
140
+		$parameters = [];
141
+		$statementParts = $this->parseQuery($this->query, $parameters);
142
+		$statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that.
143
+
144
+		$sql = $this->buildQuery($statementParts);
145
+		$tableName = '';
146
+		if (is_array($statementParts) && !empty(reset($statementParts['tables']))) {
147
+			$tableName = reset($statementParts['tables']);
148
+		}
149
+		$this->replacePlaceholders($sql, $parameters, $tableName);
150
+		#print $sql; exit(); // @debug
151
+
152
+		$result = $this->databaseHandle->sql_query($sql);
153
+		$this->checkSqlErrors($sql);
154
+		$rows = $this->getRowsFromResult($result);
155
+		$this->databaseHandle->sql_free_result($result);
156
+
157
+		return $rows;
158
+	}
159
+
160
+	/**
161
+	 * Returns the number of tuples matching the query.
162
+	 *
163
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException
164
+	 * @return int The number of matching tuples
165
+	 */
166
+	public function countResult()
167
+	{
168
+
169
+		$parameters = [];
170
+		$statementParts = $this->parseQuery($this->query, $parameters);
171
+		$statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that.
172
+		// Reset $statementParts for valid table return
173
+		reset($statementParts);
174
+
175
+		// if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints
176
+		if (!empty($statementParts['limit'])) {
177
+			$statement = $this->buildQuery($statementParts);
178
+			$this->replacePlaceholders($statement, $parameters, current($statementParts['tables']));
179
+			#print $statement; exit(); // @debug
180
+			$result = $this->databaseHandle->sql_query($statement);
181
+			$this->checkSqlErrors($statement);
182
+			$count = $this->databaseHandle->sql_num_rows($result);
183
+		} else {
184
+			$statementParts['fields'] = array('COUNT(*)');
185
+			// having orderings without grouping is not compatible with non-MySQL DBMS
186
+			$statementParts['orderings'] = [];
187
+			if (isset($statementParts['keywords']['distinct'])) {
188
+				unset($statementParts['keywords']['distinct']);
189
+				$distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid';
190
+				$statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.' . $distinctField . ')');
191
+			}
192
+
193
+			$statement = $this->buildQuery($statementParts);
194
+			$this->replacePlaceholders($statement, $parameters, current($statementParts['tables']));
195
+
196
+			#print $statement; exit(); // @debug
197
+			$result = $this->databaseHandle->sql_query($statement);
198
+			$this->checkSqlErrors($statement);
199
+			$count = 0;
200
+			if ($result) {
201
+				$row = $this->databaseHandle->sql_fetch_assoc($result);
202
+				$count = current($row);
203
+			}
204
+		}
205
+		$this->databaseHandle->sql_free_result($result);
206
+		return (int)$count;
207
+	}
208
+
209
+	/**
210
+	 * Parses the query and returns the SQL statement parts.
211
+	 *
212
+	 * @param QueryInterface $query The query
213
+	 * @param array &$parameters
214
+	 * @return array The SQL statement parts
215
+	 */
216
+	public function parseQuery(QueryInterface $query, array &$parameters)
217
+	{
218
+		$statementParts = [];
219
+		$statementParts['keywords'] = [];
220
+		$statementParts['tables'] = [];
221
+		$statementParts['unions'] = [];
222
+		$statementParts['fields'] = [];
223
+		$statementParts['where'] = [];
224
+		$statementParts['additionalWhereClause'] = [];
225
+		$statementParts['orderings'] = [];
226
+		$statementParts['limit'] = [];
227
+		$source = $query->getSource();
228
+		$this->parseSource($source, $statementParts);
229
+		$this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters);
230
+		$this->parseOrderings($query->getOrderings(), $source, $statementParts);
231
+		$this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts);
232
+		$tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions']));
233
+		foreach ($tableNames as $tableNameOrAlias) {
234
+			if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) {
235
+				$this->addAdditionalWhereClause($query->getQuerySettings(), $tableNameOrAlias, $statementParts);
236
+			}
237
+		}
238
+
239
+		return $statementParts;
240
+	}
241
+
242
+	/**
243
+	 * Fiddle with the statement structure to handle recursive MM relations.
244
+	 * For the recursive MM query to work, we must invert some values.
245
+	 * Let see if that is the best way of doing that...
246
+	 *
247
+	 * @param array $statementParts
248
+	 * @return array
249
+	 */
250
+	public function processStatementStructureForRecursiveMMRelation(array $statementParts)
251
+	{
252
+
253
+		if ($this->hasRecursiveMMRelation()) {
254
+			$tableName = $this->query->getType();
255
+
256
+			// In order the MM query to work for a recursive MM query, we must invert some values.
257
+			// tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name)
258
+			$values = [];
259
+			foreach ($statementParts['fields'] as $key => $value) {
260
+				$values[$key] = str_replace($tableName, $tableName . '0', $value);
261
+			}
262
+			$statementParts['fields'] = $values;
263
+
264
+			// Same comment as above.
265
+			$values = [];
266
+			foreach ($statementParts['where'] as $key => $value) {
267
+				$values[$key] = str_replace($tableName . '0', $tableName, $value);
268
+			}
269
+			$statementParts['where'] = $values;
270
+
271
+			// We must be more restrictive by transforming the "left" union by "inner"
272
+			$values = [];
273
+			foreach ($statementParts['unions'] as $key => $value) {
274
+				$values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value);
275
+			}
276
+			$statementParts['unions'] = $values;
277
+		}
278
+
279
+		return $statementParts;
280
+	}
281
+
282
+	/**
283
+	 * Tell whether there is a recursive MM relation.
284
+	 *
285
+	 * @return bool
286
+	 */
287
+	public function hasRecursiveMMRelation()
288
+	{
289
+		return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]);
290
+
291
+	}
292
+
293
+	/**
294
+	 * Returns the statement, ready to be executed.
295
+	 *
296
+	 * @param array $statementParts The SQL statement parts
297
+	 * @return string The SQL statement
298
+	 */
299
+	public function buildQuery(array $statementParts)
300
+	{
301
+
302
+		// Add more statement to the UNION part.
303
+		if (!empty($statementParts['unions'])) {
304
+			foreach ($statementParts['unions'] as $tableName => $unionPart) {
305
+				if (!empty($statementParts['additionalWhereClause'][$tableName])) {
306
+					$statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]);
307
+				}
308
+			}
309
+		}
310
+
311
+		$statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']);
312
+		if (!empty($statementParts['where'])) {
313
+			$statement .= ' WHERE ' . implode('', $statementParts['where']);
314
+			if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) {
315
+				$statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
316
+			}
317
+		} elseif (!empty($statementParts['additionalWhereClause'])) {
318
+			$statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
319
+		}
320
+		if (!empty($statementParts['orderings'])) {
321
+			$statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']);
322
+		}
323
+		if (!empty($statementParts['limit'])) {
324
+			$statement .= ' LIMIT ' . $statementParts['limit'];
325
+		}
326
+
327
+		return $statement;
328
+	}
329
+
330
+	/**
331
+	 * Transforms a Query Source into SQL and parameter arrays
332
+	 *
333
+	 * @param SourceInterface $source The source
334
+	 * @param array &$sql
335
+	 * @return void
336
+	 */
337
+	protected function parseSource(SourceInterface $source, array &$sql)
338
+	{
339
+		if ($source instanceof SelectorInterface) {
340
+			$tableName = $source->getNodeTypeName();
341
+			$sql['fields'][$tableName] = $tableName . '.*';
342
+			$sql['tables'][$tableName] = $tableName;
343
+			if ($this->query->getDistinct()) {
344
+				$sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct();
345
+				$sql['keywords']['distinct'] = 'DISTINCT';
346
+			}
347
+		} elseif ($source instanceof JoinInterface) {
348
+			$this->parseJoin($source, $sql);
349
+		}
350
+	}
351
+
352
+	/**
353
+	 * Transforms a Join into SQL and parameter arrays
354
+	 *
355
+	 * @param JoinInterface $join The join
356
+	 * @param array &$sql The query parts
357
+	 * @return void
358
+	 */
359
+	protected function parseJoin(JoinInterface $join, array &$sql)
360
+	{
361
+		$leftSource = $join->getLeft();
362
+		$leftTableName = $leftSource->getSelectorName();
363
+		// $sql['fields'][$leftTableName] = $leftTableName . '.*';
364
+		$rightSource = $join->getRight();
365
+		if ($rightSource instanceof JoinInterface) {
366
+			$rightTableName = $rightSource->getLeft()->getSelectorName();
367
+		} else {
368
+			$rightTableName = $rightSource->getSelectorName();
369
+			$sql['fields'][$leftTableName] = $rightTableName . '.*';
370
+		}
371
+		$sql['tables'][$leftTableName] = $leftTableName;
372
+		$sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName;
373
+		$joinCondition = $join->getJoinCondition();
374
+		if ($joinCondition instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\EquiJoinCondition) {
375
+			$column1Name = $joinCondition->getProperty1Name();
376
+			$column2Name = $joinCondition->getProperty2Name();
377
+			$sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name;
378
+		}
379
+		if ($rightSource instanceof JoinInterface) {
380
+			$this->parseJoin($rightSource, $sql);
381
+		}
382
+	}
383
+
384
+	/**
385
+	 * Transforms a constraint into SQL and parameter arrays
386
+	 *
387
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint The constraint
388
+	 * @param SourceInterface $source The source
389
+	 * @param array &$sql The query parts
390
+	 * @param array &$parameters The parameters that will replace the markers
391
+	 * @return void
392
+	 */
393
+	protected function parseConstraint(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint = null, SourceInterface $source, array &$sql, array &$parameters)
394
+	{
395
+		if ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface) {
396
+			$sql['where'][] = '(';
397
+			$this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
398
+			$sql['where'][] = ' AND ';
399
+			$this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
400
+			$sql['where'][] = ')';
401
+		} elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface) {
402
+			$sql['where'][] = '(';
403
+			$this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
404
+			$sql['where'][] = ' OR ';
405
+			$this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
406
+			$sql['where'][] = ')';
407
+		} elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface) {
408
+			$sql['where'][] = 'NOT (';
409
+			$this->parseConstraint($constraint->getConstraint(), $source, $sql, $parameters);
410
+			$sql['where'][] = ')';
411
+		} elseif ($constraint instanceof ComparisonInterface) {
412
+			$this->parseComparison($constraint, $source, $sql, $parameters);
413
+		}
414
+	}
415
+
416
+	/**
417
+	 * Parse a Comparison into SQL and parameter arrays.
418
+	 *
419
+	 * @param ComparisonInterface $comparison The comparison to parse
420
+	 * @param SourceInterface $source The source
421
+	 * @param array &$sql SQL query parts to add to
422
+	 * @param array &$parameters Parameters to bind to the SQL
423
+	 * @throws Exception\RepositoryException
424
+	 * @return void
425
+	 */
426
+	protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$sql, array &$parameters)
427
+	{
428
+		$operand1 = $comparison->getOperand1();
429
+		$operator = $comparison->getOperator();
430
+		$operand2 = $comparison->getOperand2();
431
+		if ($operator === QueryInterface::OPERATOR_IN) {
432
+			$items = [];
433
+			$hasValue = false;
434
+			foreach ($operand2 as $value) {
435
+				$value = $this->getPlainValue($value);
436
+				if ($value !== null) {
437
+					$items[] = $value;
438
+					$hasValue = true;
439
+				}
440
+			}
441
+			if ($hasValue === false) {
442
+				$sql['where'][] = '1<>1';
443
+			} else {
444
+				$this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters, null);
445
+				$parameters[] = $items;
446
+			}
447
+		} elseif ($operator === QueryInterface::OPERATOR_CONTAINS) {
448
+			if ($operand2 === null) {
449
+				$sql['where'][] = '1<>1';
450
+			} else {
451
+				throw new \Exception('Not implemented! Contact extension author.', 1412931227);
452
+				# @todo re-implement me if necessary.
453
+				#$tableName = $this->query->getType();
454
+				#$propertyName = $operand1->getPropertyName();
455
+				#while (strpos($propertyName, '.') !== false) {
456
+				#	$this->addUnionStatement($tableName, $propertyName, $sql);
457
+				#}
458
+				#$columnName = $propertyName;
459
+				#$columnMap = $propertyName;
460
+				#$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : null;
461
+				#if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
462
+				#	$relationTableName = $columnMap->getRelationTableName();
463
+				#	$sql['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)';
464
+				#	$parameters[] = intval($this->getPlainValue($operand2));
465
+				#} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) {
466
+				#	$parentKeyFieldName = $columnMap->getParentKeyFieldName();
467
+				#	if (isset($parentKeyFieldName)) {
468
+				#		$childTableName = $columnMap->getChildTableName();
469
+				#		$sql['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)';
470
+				#		$parameters[] = intval($this->getPlainValue($operand2));
471
+				#	} else {
472
+				#		$sql['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')';
473
+				#		$parameters[] = intval($this->getPlainValue($operand2));
474
+				#	}
475
+				#} else {
476
+				#	throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745);
477
+				#}
478
+			}
479
+		} else {
480
+			if ($operand2 === null) {
481
+				if ($operator === QueryInterface::OPERATOR_EQUAL_TO) {
482
+					$operator = self::OPERATOR_EQUAL_TO_NULL;
483
+				} elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) {
484
+					$operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
485
+				}
486
+			}
487
+			$this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters);
488
+			$parameters[] = $this->getPlainValue($operand2);
489
+		}
490
+	}
491
+
492
+	/**
493
+	 * Returns a plain value, i.e. objects are flattened out if possible.
494
+	 *
495
+	 * @param mixed $input
496
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException
497
+	 * @return mixed
498
+	 */
499
+	protected function getPlainValue($input)
500
+	{
501
+		if (is_array($input)) {
502
+			throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932);
503
+		}
504
+		if ($input instanceof \DateTime) {
505
+			return $input->format('U');
506
+		} elseif (is_object($input)) {
507
+			if ($input instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
508
+				$realInput = $input->_loadRealInstance();
509
+			} else {
510
+				$realInput = $input;
511
+			}
512
+			if ($realInput instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
513
+				return $realInput->getUid();
514
+			} else {
515
+				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);
516
+			}
517
+		} elseif (is_bool($input)) {
518
+			return $input === true ? 1 : 0;
519
+		} else {
520
+			return $input;
521
+		}
522
+	}
523
+
524
+	/**
525
+	 * Parse a DynamicOperand into SQL and parameter arrays.
526
+	 *
527
+	 * @param DynamicOperandInterface $operand
528
+	 * @param string $operator One of the JCR_OPERATOR_* constants
529
+	 * @param SourceInterface $source The source
530
+	 * @param array &$sql The query parts
531
+	 * @param array &$parameters The parameters that will replace the markers
532
+	 * @param string $valueFunction an optional SQL function to apply to the operand value
533
+	 * @return void
534
+	 */
535
+	protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$sql, array &$parameters, $valueFunction = null)
536
+	{
537
+		if ($operand instanceof LowerCaseInterface) {
538
+			$this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER');
539
+		} elseif ($operand instanceof UpperCaseInterface) {
540
+			$this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'UPPER');
541
+		} elseif ($operand instanceof PropertyValueInterface) {
542
+			$propertyName = $operand->getPropertyName();
543
+
544
+			// Reset value.
545
+			$this->currentChildTableNameAlias = '';
546
+
547
+			if ($source instanceof SelectorInterface) {
548
+				$tableName = $this->query->getType();
549
+				while (strpos($propertyName, '.') !== false) {
550
+					$this->addUnionStatement($tableName, $propertyName, $sql);
551
+				}
552
+			} elseif ($source instanceof JoinInterface) {
553
+				$tableName = $source->getJoinCondition()->getSelector1Name();
554
+			}
555
+
556
+			$columnName = $propertyName;
557
+			$operator = $this->resolveOperator($operator);
558
+			$constraintSQL = '';
559
+			if ($valueFunction === null) {
560
+				$constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?';
561
+			} else {
562
+				$constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?';
563
+			}
564
+
565
+			if (isset($tableName) && !empty($this->currentChildTableNameAlias)) {
566
+				$constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL);
567
+			}
568
+			$sql['where'][] = $constraintSQL;
569
+		}
570
+	}
571
+
572
+	/**
573
+	 * @param string &$tableName
574
+	 * @param array &$propertyPath
575
+	 * @param array &$sql
576
+	 * @throws Exception
577
+	 * @throws Exception\InvalidRelationConfigurationException
578
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\MissingColumnMapException
579
+	 */
580
+	protected function addUnionStatement(&$tableName, &$propertyPath, array &$sql)
581
+	{
582
+
583
+		$table = Tca::table($tableName);
584
+
585
+		$explodedPropertyPath = explode('.', $propertyPath, 2);
586
+		$fieldName = $explodedPropertyPath[0];
587
+
588
+		// Field of type "group" are special because property path must contain the table name
589
+		// to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
590
+		$parts = explode('.', $propertyPath, 3);
591
+		if ($table->field($fieldName)->isGroup() && count($parts) > 2) {
592
+			$explodedPropertyPath[0] = $parts[0] . '.' . $parts[1];
593
+			$explodedPropertyPath[1] = $parts[2];
594
+			$fieldName = $explodedPropertyPath[0];
595
+		}
596
+
597
+		$parentKeyFieldName = $table->field($fieldName)->getForeignField();
598
+		$childTableName = $table->field($fieldName)->getForeignTable();
599
+
600
+		if ($childTableName === null) {
601
+			throw new Exception\InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925);
602
+		}
603
+
604
+		if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one"
605
+			// sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons.
606
+			// $parentKeyFieldName === null does the trick somehow. Before condition was if (isset($parentKeyFieldName))
607
+			if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === null) {
608
+				$sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid';
609
+			} else {
610
+				$sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
611
+			}
612
+		} elseif ($table->field($fieldName)->hasRelationManyToMany()) {
613
+			$relationTableName = $table->field($fieldName)->getManyToManyTable();
614
+
615
+			$parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
616
+			$childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
617
+
618
+			// MM table e.g sys_category_record_mm
619
+			$relationTableNameAlias = $this->generateAlias($relationTableName);
620
+			$join = sprintf(
621
+				'LEFT JOIN %s AS %s ON %s.uid=%s.%s', $relationTableName,
622
+				$relationTableNameAlias,
623
+				$tableName,
624
+				$relationTableNameAlias,
625
+				$parentKeyFieldName
626
+			);
627
+			$sql['unions'][$relationTableNameAlias] = $join;
628
+
629
+			// Foreign table e.g sys_category
630
+			$childTableNameAlias = $this->generateAlias($childTableName);
631
+			$this->currentChildTableNameAlias = $childTableNameAlias;
632
+			$join = sprintf(
633
+				'LEFT JOIN %s AS %s ON %s.%s=%s.uid',
634
+				$childTableName,
635
+				$childTableNameAlias,
636
+				$relationTableNameAlias,
637
+				$childKeyFieldName,
638
+				$childTableNameAlias
639
+			);
640
+			$sql['unions'][$childTableNameAlias] = $join;
641
+
642
+			// Find a possible table name for a MM condition.
643
+			$tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition();
644
+			if ($tableNameCondition) {
645
+
646
+				// If we can find a source file name,  we can then retrieve more MM conditions from the TCA such as a field name.
647
+				$sourceFileName = $this->query->getSourceFieldName();
648
+				if (empty($sourceFileName)) {
649
+					$additionalMMConditions = array(
650
+						'tablenames' => $tableNameCondition,
651
+					);
652
+				} else {
653
+					$additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition();
654
+				}
655
+
656
+				foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) {
657
+					$additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
658
+					$sql['unions'][$relationTableNameAlias] .= $additionalJoin;
659
+
660
+					$additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
661
+					$sql['unions'][$childTableNameAlias] .= $additionalJoin;
662
+				}
663
+
664
+			}
665
+
666
+
667
+		} elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations
668
+			$childTableNameAlias = $this->generateAlias($childTableName);
669
+			$this->currentChildTableNameAlias = $childTableNameAlias;
670
+
671
+			if (isset($parentKeyFieldName)) {
672
+				$join = sprintf(
673
+					'LEFT JOIN %s AS %s ON %s.uid=%s.%s',
674
+					$childTableName,
675
+					$childTableNameAlias,
676
+					$tableName,
677
+					$childTableNameAlias,
678
+					$parentKeyFieldName
679
+				);
680
+				$sql['unions'][$childTableNameAlias] = $join;
681
+			} else {
682
+				$join = sprintf(
683
+					'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))',
684
+					$childTableName,
685
+					$childTableNameAlias,
686
+					$childTableNameAlias,
687
+					$tableName,
688
+					$fieldName
689
+				);
690
+				$sql['unions'][$childTableNameAlias] = $join;
691
+			}
692
+		} else {
693
+			throw new Exception('Could not determine type of relation.', 1252502725);
694
+		}
695
+
696
+		// TODO check if there is another solution for this
697
+		$sql['keywords']['distinct'] = 'DISTINCT';
698
+		$propertyPath = $explodedPropertyPath[1];
699
+		$tableName = $childTableName;
700
+	}
701
+
702
+	/**
703
+	 * Returns the SQL operator for the given JCR operator type.
704
+	 *
705
+	 * @param string $operator One of the JCR_OPERATOR_* constants
706
+	 * @throws Exception
707
+	 * @return string an SQL operator
708
+	 */
709
+	protected function resolveOperator($operator)
710
+	{
711
+		switch ($operator) {
712
+			case self::OPERATOR_EQUAL_TO_NULL:
713
+				$operator = 'IS';
714
+				break;
715
+			case self::OPERATOR_NOT_EQUAL_TO_NULL:
716
+				$operator = 'IS NOT';
717
+				break;
718
+			case QueryInterface::OPERATOR_IN:
719
+				$operator = 'IN';
720
+				break;
721
+			case QueryInterface::OPERATOR_EQUAL_TO:
722
+				$operator = '=';
723
+				break;
724
+			case QueryInterface::OPERATOR_NOT_EQUAL_TO:
725
+				$operator = '!=';
726
+				break;
727
+			case QueryInterface::OPERATOR_LESS_THAN:
728
+				$operator = '<';
729
+				break;
730
+			case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO:
731
+				$operator = '<=';
732
+				break;
733
+			case QueryInterface::OPERATOR_GREATER_THAN:
734
+				$operator = '>';
735
+				break;
736
+			case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO:
737
+				$operator = '>=';
738
+				break;
739
+			case QueryInterface::OPERATOR_LIKE:
740
+				$operator = 'LIKE';
741
+				break;
742
+			default:
743
+				throw new Exception('Unsupported operator encountered.', 1242816073);
744
+		}
745
+		return $operator;
746
+	}
747
+
748
+	/**
749
+	 * Replace query placeholders in a query part by the given
750
+	 * parameters.
751
+	 *
752
+	 * @param string &$sqlString The query part with placeholders
753
+	 * @param array $parameters The parameters
754
+	 * @param string $tableName
755
+	 *
756
+	 * @throws Exception
757
+	 */
758
+	protected function replacePlaceholders(&$sqlString, array $parameters, $tableName = 'foo')
759
+	{
760
+		// TODO profile this method again
761
+		if (substr_count($sqlString, '?') !== count($parameters)) {
762
+			throw new Exception('The number of question marks to replace must be equal to the number of parameters.', 1242816074);
763
+		}
764
+		$offset = 0;
765
+		foreach ($parameters as $parameter) {
766
+			$markPosition = strpos($sqlString, '?', $offset);
767
+			if ($markPosition !== false) {
768
+				if ($parameter === null) {
769
+					$parameter = 'null';
770
+				} elseif (is_array($parameter) || $parameter instanceof \ArrayAccess || $parameter instanceof \Traversable) {
771
+					$items = [];
772
+					foreach ($parameter as $item) {
773
+						$items[] = $this->databaseHandle->fullQuoteStr($item, $tableName);
774
+					}
775
+					$parameter = '(' . implode(',', $items) . ')';
776
+				} else {
777
+					$parameter = $this->databaseHandle->fullQuoteStr($parameter, $tableName);
778
+				}
779
+				$sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, ($markPosition + 1));
780
+			}
781
+			$offset = $markPosition + strlen($parameter);
782
+		}
783
+	}
784
+
785
+	/**
786
+	 * Adds additional WHERE statements according to the query settings.
787
+	 *
788
+	 * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
789
+	 * @param string $tableNameOrAlias The table name to add the additional where clause for
790
+	 * @param array &$statementParts
791
+	 * @return void
792
+	 */
793
+	protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts)
794
+	{
795
+		$this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts);
796
+		if ($querySettings->getRespectSysLanguage()) {
797
+			$this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings);
798
+		}
799
+	}
800
+
801
+	/**
802
+	 * Adds enableFields and deletedClause to the query if necessary
803
+	 *
804
+	 * @param QuerySettingsInterface $querySettings
805
+	 * @param string $tableNameOrAlias The database table name
806
+	 * @param array &$statementParts The query parts
807
+	 * @return void
808
+	 */
809
+	protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts)
810
+	{
811
+		$statement = '';
812
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
813
+		if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
814
+			$ignoreEnableFields = $querySettings->getIgnoreEnableFields();
815
+			$enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored();
816
+			$includeDeleted = $querySettings->getIncludeDeleted();
817
+			if ($this->environmentService->isEnvironmentInFrontendMode()) {
818
+				$statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted);
819
+			} else {
820
+				// TYPO3_MODE === 'BE'
821
+				$statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted);
822
+			}
823
+
824
+			// Remove the prefixing "AND" if any.
825
+			if (!empty($statement)) {
826
+				$statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement;
827
+				$statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement;
828
+			}
829
+		}
830
+	}
831
+
832
+	/**
833
+	 * Returns constraint statement for frontend context
834
+	 *
835
+	 * @param string $tableNameOrAlias
836
+	 * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
837
+	 * @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.
838
+	 * @param boolean $includeDeleted A flag indicating whether deleted records should be included
839
+	 * @return string
840
+	 * @throws Exception\InconsistentQuerySettingsException
841
+	 */
842
+	protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored = [], $includeDeleted)
843
+	{
844
+		$statement = '';
845
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
846
+		if ($ignoreEnableFields && !$includeDeleted) {
847
+			if (count($enableFieldsToBeIgnored)) {
848
+				// array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented
849
+				$statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored));
850
+			} else {
851
+				$statement .= $this->getPageRepository()->deleteClause($tableName);
852
+			}
853
+		} elseif (!$ignoreEnableFields && !$includeDeleted) {
854
+			$statement .= $this->getPageRepository()->enableFields($tableName);
855
+		} elseif (!$ignoreEnableFields && $includeDeleted) {
856
+			throw new Exception\InconsistentQuerySettingsException('Query setting "ignoreEnableFields=false" can not be used together with "includeDeleted=true" in frontend context.', 1327678173);
857
+		}
858
+		return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
859
+	}
860
+
861
+	/**
862
+	 * Returns constraint statement for backend context
863
+	 *
864
+	 * @param string $tableNameOrAlias
865
+	 * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
866
+	 * @param boolean $includeDeleted A flag indicating whether deleted records should be included
867
+	 * @return string
868
+	 */
869
+	protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted)
870
+	{
871
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
872
+		$statement = '';
873
+		if (!$ignoreEnableFields) {
874
+			$statement .= BackendUtility::BEenableFields($tableName);
875
+		}
876
+
877
+		// If the table is found to have "workspace" support, add the corresponding fields in the statement.
878
+		if (Tca::table($tableName)->hasWorkspaceSupport()) {
879
+			if ($this->getBackendUser()->workspace === 0) {
880
+				$statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE);
881
+			} else {
882
+				// Show only records of live and of the current workspace
883
+				// In case we are in a Versioning preview
884
+				$statement .= ' AND (' .
885
+					$tableName . '.t3ver_wsid=0 OR ' .
886
+					$tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace .
887
+					')';
888
+			}
889
+
890
+			// Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0
891
+			$statement .= ' AND ' . $tableName . '.pid<>-1';
892
+		}
893
+
894
+		if (!$includeDeleted) {
895
+			$statement .= BackendUtility::deleteClause($tableName);
896
+		}
897
+
898
+		return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
899
+	}
900
+
901
+	/**
902
+	 * Builds the language field statement
903
+	 *
904
+	 * @param string $tableNameOrAlias The database table name
905
+	 * @param array &$statementParts The query parts
906
+	 * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
907
+	 * @throws Exception
908
+	 * @return void
909
+	 */
910
+	protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings)
911
+	{
912
+
913
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
914
+		if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
915
+			if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) {
916
+				// Select all entries for the current language
917
+				$additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)';
918
+				// If any language is set -> get those entries which are not translated yet
919
+				// They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode
920
+				if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
921
+					&& $querySettings->getLanguageUid() > 0
922
+				) {
923
+					$additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' .
924
+						' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] .
925
+						' FROM ' . $tableName .
926
+						' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' .
927
+						' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0';
928
+
929
+					// Add delete clause to ensure all entries are loaded
930
+					if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) {
931
+						$additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0';
932
+					}
933
+					$additionalWhereClause .= '))';
934
+				}
935
+				$statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')';
936
+			}
937
+		}
938
+	}
939
+
940
+	/**
941
+	 * Transforms orderings into SQL.
942
+	 *
943
+	 * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
944
+	 * @param SourceInterface $source The source
945
+	 * @param array &$sql The query parts
946
+	 * @throws Exception\UnsupportedOrderException
947
+	 * @return void
948
+	 */
949
+	protected function parseOrderings(array $orderings, SourceInterface $source, array &$sql)
950
+	{
951
+		foreach ($orderings as $fieldNameAndPath => $order) {
952
+			switch ($order) {
953
+				case QueryInterface::ORDER_ASCENDING:
954
+					$order = 'ASC';
955
+					break;
956
+				case QueryInterface::ORDER_DESCENDING:
957
+					$order = 'DESC';
958
+					break;
959
+				default:
960
+					throw new Exception\UnsupportedOrderException('Unsupported order encountered.', 1456845126);
961
+			}
962
+
963
+			$tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType());
964
+			$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName);
965
+			$sql['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order);
966
+		}
967
+	}
968
+
969
+	/**
970
+	 * Transforms limit and offset into SQL
971
+	 *
972
+	 * @param int $limit
973
+	 * @param int $offset
974
+	 * @param array &$sql
975
+	 * @return void
976
+	 */
977
+	protected function parseLimitAndOffset($limit, $offset, array &$sql)
978
+	{
979
+		if ($limit !== null && $offset !== null) {
980
+			$sql['limit'] = intval($offset) . ', ' . intval($limit);
981
+		} elseif ($limit !== null) {
982
+			$sql['limit'] = intval($limit);
983
+		}
984
+	}
985
+
986
+	/**
987
+	 * Transforms a Resource from a database query to an array of rows.
988
+	 *
989
+	 * @param resource $result The result
990
+	 * @return array The result as an array of rows (tuples)
991
+	 */
992
+	protected function getRowsFromResult($result)
993
+	{
994
+		$rows = [];
995
+		while ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
996
+			if (is_array($row)) {
997
+
998
+				// Get language uid from querySettings.
999
+				// Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed)
1000
+				$overlaidRow = $this->doLanguageAndWorkspaceOverlay($this->query->getSource(), $row, $this->query->getQuerySettings());
1001
+				$contentObject = GeneralUtility::makeInstance($this->objectType, $this->query->getType(), $overlaidRow);
1002
+				$rows[] = $contentObject;
1003
+			}
1004
+		}
1005
+
1006
+		return $rows;
1007
+	}
1008
+
1009
+	/**
1010
+	 * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
1011
+	 * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
1012
+	 *
1013
+	 * @param SourceInterface $source The source (selector od join)
1014
+	 * @param array $row
1015
+	 * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
1016
+	 * @return array
1017
+	 */
1018
+	protected function doLanguageAndWorkspaceOverlay(SourceInterface $source, array $row, $querySettings)
1019
+	{
1020
+
1021
+		/** @var SelectorInterface $source */
1022
+		$tableName = $source->getSelectorName();
1023
+
1024
+		$pageRepository = $this->getPageRepository();
1025
+		if (is_object($GLOBALS['TSFE'])) {
1026
+			$languageMode = $GLOBALS['TSFE']->sys_language_mode;
1027
+			if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) {
1028
+				$pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace;
1029
+			}
1030
+		} else {
1031
+			$languageMode = '';
1032
+			$workspaceUid = $this->getBackendUser()->workspace;
1033
+			$pageRepository->versioningWorkspaceId = $workspaceUid;
1034
+			if ($this->getBackendUser()->workspace !== 0) {
1035
+				$pageRepository->versioningPreview = 1;
1036
+			}
1037
+		}
1038
+
1039
+		// If current row is a translation select its parent
1040
+		if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
1041
+			&& isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
1042
+		) {
1043
+			if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']])
1044
+				&& $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
1045
+			) {
1046
+				$row = $this->databaseHandle->exec_SELECTgetSingleRow(
1047
+					$tableName . '.*',
1048
+					$tableName,
1049
+					$tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] .
1050
+					' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0'
1051
+				);
1052
+			}
1053
+		}
1054
+
1055
+		// Retrieve the original uid; Used for Workspaces!
1056
+		if (TYPO3_MODE !== 'BE') {
1057
+			$pageRepository->versionOL($tableName, $row, true, true);
1058
+		} else {
1059
+			\TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($tableName, $row);
1060
+		}
1061
+		if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) {
1062
+			$row['uid'] = $row['_ORIG_uid'];
1063
+		}
1064
+
1065
+		// Special case for table "pages"
1066
+		if ($tableName == 'pages') {
1067
+			$row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
1068
+		} elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
1069
+			&& $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== ''
1070
+		) {
1071
+			if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
1072
+				$overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : '';
1073
+				$row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
1074
+			}
1075
+		}
1076
+
1077
+		return $row;
1078
+	}
1079
+
1080
+	/**
1081
+	 * Return a resolved table name given a possible table name alias.
1082
+	 *
1083
+	 * @param string $tableNameOrAlias
1084
+	 * @return string
1085
+	 */
1086
+	protected function resolveTableNameAlias($tableNameOrAlias)
1087
+	{
1088
+		$resolvedTableName = $tableNameOrAlias;
1089
+		if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) {
1090
+			$resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias];
1091
+		}
1092
+		return $resolvedTableName;
1093
+	}
1094
+
1095
+	/**
1096
+	 * Generate a unique table name alias for the given table name.
1097
+	 *
1098
+	 * @param string $tableName
1099
+	 * @return string
1100
+	 */
1101
+	protected function generateAlias($tableName)
1102
+	{
1103
+
1104
+		if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) {
1105
+			$this->tableNameAliases['aliasIncrement'][$tableName] = 0;
1106
+		}
1107
+
1108
+		$numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName];
1109
+		$tableNameAlias = $tableName . $numberOfAliases;
1110
+
1111
+		$this->tableNameAliases['aliasIncrement'][$tableName]++;
1112
+		$this->tableNameAliases['aliases'][$tableNameAlias] = $tableName;
1113
+
1114
+		return $tableNameAlias;
1115
+	}
1116
+
1117
+	/**
1118
+	 * Replace the table names by its table name alias within the given statement.
1119
+	 *
1120
+	 * @param string $tableName
1121
+	 * @param string $tableNameAlias
1122
+	 * @param string $statement
1123
+	 * @return string
1124
+	 */
1125
+	protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement)
1126
+	{
1127
+		if ($statement && $tableName !== $tableNameAlias) {
1128
+			$statement = str_replace($tableName, $tableNameAlias, $statement);
1129
+		}
1130
+		return $statement;
1131
+	}
1132
+
1133
+	/**
1134
+	 * Returns an instance of the current Backend User.
1135
+	 *
1136
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1137
+	 */
1138
+	protected function getBackendUser()
1139
+	{
1140
+		return $GLOBALS['BE_USER'];
1141
+	}
1142
+
1143
+	/**
1144
+	 * Tell whether a Backend User is logged in.
1145
+	 *
1146
+	 * @return bool
1147
+	 */
1148
+	protected function isBackendUserLogged()
1149
+	{
1150
+		return is_object($GLOBALS['BE_USER']);
1151
+	}
1152
+
1153
+	/**
1154
+	 * @return PageRepository|object
1155
+	 */
1156
+	protected function getPageRepository()
1157
+	{
1158
+		if (!$this->pageRepository instanceof PageRepository) {
1159
+			if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($GLOBALS['TSFE'])) {
1160
+				$this->pageRepository = $GLOBALS['TSFE']->sys_page;
1161
+			} else {
1162
+				$this->pageRepository = GeneralUtility::makeInstance(PageRepository::class);
1163
+			}
1164
+		}
1165
+
1166
+		return $this->pageRepository;
1167
+	}
1168
+
1169
+	/**
1170
+	 * @return \Fab\Vidi\Resolver\FieldPathResolver|object
1171
+	 */
1172
+	protected function getFieldPathResolver()
1173
+	{
1174
+		return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\FieldPathResolver::class);
1175
+	}
1176
+
1177
+	/**
1178
+	 * Checks if there are SQL errors in the last query, and if yes, throw an exception.
1179
+	 *
1180
+	 * @return void
1181
+	 * @param string $sql The SQL statement
1182
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException
1183
+	 */
1184
+	protected function checkSqlErrors($sql = '')
1185
+	{
1186
+		$error = $this->databaseHandle->sql_error();
1187
+		if ($error !== '') {
1188
+			$error .= $sql ? ': ' . $sql : '';
1189
+			throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($error, 1247602160);
1190
+		}
1191
+	}
1192 1192
 }
Please login to merge, or discard this patch.
Classes/Processor/ContentObjectProcessor.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
     /**
32 32
      * @param ProcessContentDataSignalArguments $signalArguments
33
-     * @return array
33
+     * @return ProcessContentDataSignalArguments[]
34 34
      */
35 35
     public function processRelations(ProcessContentDataSignalArguments $signalArguments)
36 36
     {
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
     /**
52 52
      * @param \Fab\Vidi\Domain\Model\Content $object
53
-     * @param $fieldNameAndPath
53
+     * @param string $fieldNameAndPath
54 54
      * @param array $contentData
55 55
      * @param string $savingBehavior
56 56
      * @return array
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@
 block discarded – undo
71 71
                 $relatedValues = $this->getRelatedValues($object, $fieldNameAndPath, $fieldName);
72 72
 
73 73
                 foreach ($values as $value) {
74
-                    $appendOrRemove = $savingBehavior . 'Relations';
74
+                    $appendOrRemove = $savingBehavior.'Relations';
75 75
                     $relatedValues = $this->$appendOrRemove($value, $relatedValues);
76 76
                 }
77 77
 
Please login to merge, or discard this patch.
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -22,121 +22,121 @@
 block discarded – undo
22 22
 class ContentObjectProcessor implements SingletonInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @param ProcessContentDataSignalArguments $signalArguments
27
-     * @return array
28
-     */
29
-    public function processRelations(ProcessContentDataSignalArguments $signalArguments)
30
-    {
31
-
32
-        $contentObject = $signalArguments->getContentObject();
33
-        $fieldNameAndPath = $signalArguments->getFieldNameAndPath();
34
-        $contentData = $signalArguments->getContentData();
35
-        $savingBehavior = $signalArguments->getSavingBehavior();
36
-
37
-        if ($savingBehavior !== SavingBehavior::REPLACE) {
38
-            $contentData = $this->appendOrRemoveRelations($contentObject, $fieldNameAndPath, $contentData, $savingBehavior);
39
-            $signalArguments->setContentData($contentData);
40
-        }
41
-
42
-        return array($signalArguments);
43
-    }
44
-
45
-    /**
46
-     * @param \Fab\Vidi\Domain\Model\Content $object
47
-     * @param $fieldNameAndPath
48
-     * @param array $contentData
49
-     * @param string $savingBehavior
50
-     * @return array
51
-     */
52
-    protected function appendOrRemoveRelations(Content $object, $fieldNameAndPath, array $contentData, $savingBehavior)
53
-    {
54
-
55
-        foreach ($contentData as $fieldName => $values) {
56
-
57
-            $resolvedObject = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath);
58
-
59
-            if (Tca::table($resolvedObject)->field($fieldName)->hasMany()) {
60
-
61
-                // true means CSV values must be converted to array.
62
-                if (!is_array($values)) {
63
-                    $values = GeneralUtility::trimExplode(',', $values);
64
-                }
65
-                $relatedValues = $this->getRelatedValues($object, $fieldNameAndPath, $fieldName);
66
-
67
-                foreach ($values as $value) {
68
-                    $appendOrRemove = $savingBehavior . 'Relations';
69
-                    $relatedValues = $this->$appendOrRemove($value, $relatedValues);
70
-                }
71
-
72
-                $contentData[$fieldName] = $relatedValues;
73
-            }
74
-        }
75
-        return $contentData;
76
-    }
77
-
78
-    /**
79
-     * @param $value
80
-     * @param array $relatedValues
81
-     * @return array
82
-     */
83
-    protected function appendRelations($value, array $relatedValues)
84
-    {
85
-        if (!in_array($value, $relatedValues)) {
86
-            $relatedValues[] = $value;
87
-        }
88
-        return $relatedValues;
89
-    }
90
-
91
-    /**
92
-     * @param $value
93
-     * @param array $relatedValues
94
-     * @return array
95
-     */
96
-    protected function removeRelations($value, array $relatedValues)
97
-    {
98
-        if (in_array($value, $relatedValues)) {
99
-            $key = array_search($value, $relatedValues);
100
-            unset($relatedValues[$key]);
101
-        }
102
-        return $relatedValues;
103
-    }
104
-
105
-    /**
106
-     * @param \Fab\Vidi\Domain\Model\Content $object
107
-     * @param string $fieldNameAndPath
108
-     * @param string $fieldName
109
-     * @return array
110
-     */
111
-    protected function getRelatedValues(Content $object, $fieldNameAndPath, $fieldName)
112
-    {
113
-
114
-        $values = [];
115
-        $relatedContentObjects = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, $fieldName);
116
-
117
-        if (is_array($relatedContentObjects)) {
118
-            /** @var Content $relatedContentObject */
119
-            foreach ($relatedContentObjects as $relatedContentObject) {
120
-                $values[] = $relatedContentObject->getUid();
121
-            }
122
-        }
123
-
124
-        return $values;
125
-    }
126
-
127
-    /**
128
-     * @return \Fab\Vidi\Resolver\ContentObjectResolver|object
129
-     */
130
-    protected function getContentObjectResolver()
131
-    {
132
-        return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\ContentObjectResolver::class);
133
-    }
134
-
135
-    /**
136
-     * @return \Fab\Vidi\Resolver\FieldPathResolver|object
137
-     */
138
-    protected function getFieldPathResolver()
139
-    {
140
-        return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\FieldPathResolver::class);
141
-    }
25
+	/**
26
+	 * @param ProcessContentDataSignalArguments $signalArguments
27
+	 * @return array
28
+	 */
29
+	public function processRelations(ProcessContentDataSignalArguments $signalArguments)
30
+	{
31
+
32
+		$contentObject = $signalArguments->getContentObject();
33
+		$fieldNameAndPath = $signalArguments->getFieldNameAndPath();
34
+		$contentData = $signalArguments->getContentData();
35
+		$savingBehavior = $signalArguments->getSavingBehavior();
36
+
37
+		if ($savingBehavior !== SavingBehavior::REPLACE) {
38
+			$contentData = $this->appendOrRemoveRelations($contentObject, $fieldNameAndPath, $contentData, $savingBehavior);
39
+			$signalArguments->setContentData($contentData);
40
+		}
41
+
42
+		return array($signalArguments);
43
+	}
44
+
45
+	/**
46
+	 * @param \Fab\Vidi\Domain\Model\Content $object
47
+	 * @param $fieldNameAndPath
48
+	 * @param array $contentData
49
+	 * @param string $savingBehavior
50
+	 * @return array
51
+	 */
52
+	protected function appendOrRemoveRelations(Content $object, $fieldNameAndPath, array $contentData, $savingBehavior)
53
+	{
54
+
55
+		foreach ($contentData as $fieldName => $values) {
56
+
57
+			$resolvedObject = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath);
58
+
59
+			if (Tca::table($resolvedObject)->field($fieldName)->hasMany()) {
60
+
61
+				// true means CSV values must be converted to array.
62
+				if (!is_array($values)) {
63
+					$values = GeneralUtility::trimExplode(',', $values);
64
+				}
65
+				$relatedValues = $this->getRelatedValues($object, $fieldNameAndPath, $fieldName);
66
+
67
+				foreach ($values as $value) {
68
+					$appendOrRemove = $savingBehavior . 'Relations';
69
+					$relatedValues = $this->$appendOrRemove($value, $relatedValues);
70
+				}
71
+
72
+				$contentData[$fieldName] = $relatedValues;
73
+			}
74
+		}
75
+		return $contentData;
76
+	}
77
+
78
+	/**
79
+	 * @param $value
80
+	 * @param array $relatedValues
81
+	 * @return array
82
+	 */
83
+	protected function appendRelations($value, array $relatedValues)
84
+	{
85
+		if (!in_array($value, $relatedValues)) {
86
+			$relatedValues[] = $value;
87
+		}
88
+		return $relatedValues;
89
+	}
90
+
91
+	/**
92
+	 * @param $value
93
+	 * @param array $relatedValues
94
+	 * @return array
95
+	 */
96
+	protected function removeRelations($value, array $relatedValues)
97
+	{
98
+		if (in_array($value, $relatedValues)) {
99
+			$key = array_search($value, $relatedValues);
100
+			unset($relatedValues[$key]);
101
+		}
102
+		return $relatedValues;
103
+	}
104
+
105
+	/**
106
+	 * @param \Fab\Vidi\Domain\Model\Content $object
107
+	 * @param string $fieldNameAndPath
108
+	 * @param string $fieldName
109
+	 * @return array
110
+	 */
111
+	protected function getRelatedValues(Content $object, $fieldNameAndPath, $fieldName)
112
+	{
113
+
114
+		$values = [];
115
+		$relatedContentObjects = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, $fieldName);
116
+
117
+		if (is_array($relatedContentObjects)) {
118
+			/** @var Content $relatedContentObject */
119
+			foreach ($relatedContentObjects as $relatedContentObject) {
120
+				$values[] = $relatedContentObject->getUid();
121
+			}
122
+		}
123
+
124
+		return $values;
125
+	}
126
+
127
+	/**
128
+	 * @return \Fab\Vidi\Resolver\ContentObjectResolver|object
129
+	 */
130
+	protected function getContentObjectResolver()
131
+	{
132
+		return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\ContentObjectResolver::class);
133
+	}
134
+
135
+	/**
136
+	 * @return \Fab\Vidi\Resolver\FieldPathResolver|object
137
+	 */
138
+	protected function getFieldPathResolver()
139
+	{
140
+		return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\FieldPathResolver::class);
141
+	}
142 142
 }
Please login to merge, or discard this patch.
Classes/Processor/MarkerProcessor.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
     /**
39 39
      * @param ProcessContentDataSignalArguments $signalArguments
40
-     * @return array
40
+     * @return ProcessContentDataSignalArguments[]
41 41
      */
42 42
     public function processMarkers(ProcessContentDataSignalArguments $signalArguments)
43 43
     {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      * @param string $updateValue
73 73
      * @param string $currentValue
74 74
      * @param int $counter
75
-     * @param $creationTime
75
+     * @param integer $creationTime
76 76
      * @return string
77 77
      */
78 78
     protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime)
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@
 block discarded – undo
105 105
             $replace = $structure[2];
106 106
 
107 107
             // Perhaps needs to be improved here if $search contains "/" precisely.
108
-            $updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue);
108
+            $updateValue = preg_replace('/'.$search.'/isU', $replace, $currentValue);
109 109
         }
110 110
         return $updateValue;
111 111
     }
Please login to merge, or discard this patch.
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -20,114 +20,114 @@
 block discarded – undo
20 20
 class MarkerProcessor implements SingletonInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @var array
25
-     */
26
-    protected $wellKnownMarkers = array(
27
-        '{*}',
28
-        '{counter}',
29
-        '{date}',
30
-        '{creation_date}'
31
-    );
32
-
33
-    /**
34
-     * @param ProcessContentDataSignalArguments $signalArguments
35
-     * @return array
36
-     */
37
-    public function processMarkers(ProcessContentDataSignalArguments $signalArguments)
38
-    {
39
-
40
-        $contentData = $signalArguments->getContentData();
41
-        $creationTime = $this->getCreationTime($signalArguments);
42
-
43
-        // Process markers
44
-        foreach ($signalArguments->getContentData() as $fieldName => $updateValue) {
45
-            if (is_scalar($updateValue)) {
46
-
47
-                $currentValue = $this->getContentObjectResolver()->getValue(
48
-                    $signalArguments->getContentObject(),
49
-                    $signalArguments->getFieldNameAndPath(),
50
-                    $fieldName,
51
-                    $signalArguments->getLanguage()
52
-                );
53
-                $counter = $signalArguments->getCounter();
54
-
55
-                $updateValue = $this->searchAndReplace($updateValue, $currentValue);
56
-                $updateValue = $this->replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime);
57
-
58
-                $contentData[$fieldName] = $updateValue;
59
-            }
60
-        }
61
-
62
-        $signalArguments->setContentData($contentData);
63
-        return array($signalArguments);
64
-    }
65
-
66
-    /**
67
-     * @param string $updateValue
68
-     * @param string $currentValue
69
-     * @param int $counter
70
-     * @param $creationTime
71
-     * @return string
72
-     */
73
-    protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime)
74
-    {
75
-
76
-        // Replaces values.
77
-        $replaces = array(
78
-            $currentValue,
79
-            $counter,
80
-            date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']),
81
-            date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $creationTime),
82
-        );
83
-
84
-        // Replace me!
85
-        return str_replace($this->wellKnownMarkers, $replaces, $updateValue);
86
-    }
87
-
88
-    /**
89
-     * @param string $updateValue
90
-     * @param string $currentValue
91
-     * @return string
92
-     */
93
-    protected function searchAndReplace($updateValue, $currentValue)
94
-    {
95
-
96
-        if (strpos($updateValue, 's/') !== false) {
97
-            $structure = explode('/', $updateValue);
98
-            $search = $structure[1];
99
-            $replace = $structure[2];
100
-
101
-            // Perhaps needs to be improved here if $search contains "/" precisely.
102
-            $updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue);
103
-        }
104
-        return $updateValue;
105
-    }
106
-
107
-    /**
108
-     * @param ProcessContentDataSignalArguments $signalArguments
109
-     * @return int
110
-     */
111
-    protected function getCreationTime(ProcessContentDataSignalArguments $signalArguments)
112
-    {
113
-        $creationTime = 0;
114
-        $creationTimeField = Tca::table($signalArguments->getContentObject()->getDataType())->getTimeCreationField();
115
-        if ($creationTimeField) {
116
-            $creationTime = $this->getContentObjectResolver()->getValue(
117
-                $signalArguments->getContentObject(),
118
-                $signalArguments->getFieldNameAndPath(),
119
-                $creationTimeField
120
-            );
121
-        }
122
-        return $creationTime;
123
-    }
124
-
125
-    /**
126
-     * @return ContentObjectResolver
127
-     */
128
-    protected function getContentObjectResolver()
129
-    {
130
-        return GeneralUtility::makeInstance(ContentObjectResolver::class);
131
-    }
23
+	/**
24
+	 * @var array
25
+	 */
26
+	protected $wellKnownMarkers = array(
27
+		'{*}',
28
+		'{counter}',
29
+		'{date}',
30
+		'{creation_date}'
31
+	);
32
+
33
+	/**
34
+	 * @param ProcessContentDataSignalArguments $signalArguments
35
+	 * @return array
36
+	 */
37
+	public function processMarkers(ProcessContentDataSignalArguments $signalArguments)
38
+	{
39
+
40
+		$contentData = $signalArguments->getContentData();
41
+		$creationTime = $this->getCreationTime($signalArguments);
42
+
43
+		// Process markers
44
+		foreach ($signalArguments->getContentData() as $fieldName => $updateValue) {
45
+			if (is_scalar($updateValue)) {
46
+
47
+				$currentValue = $this->getContentObjectResolver()->getValue(
48
+					$signalArguments->getContentObject(),
49
+					$signalArguments->getFieldNameAndPath(),
50
+					$fieldName,
51
+					$signalArguments->getLanguage()
52
+				);
53
+				$counter = $signalArguments->getCounter();
54
+
55
+				$updateValue = $this->searchAndReplace($updateValue, $currentValue);
56
+				$updateValue = $this->replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime);
57
+
58
+				$contentData[$fieldName] = $updateValue;
59
+			}
60
+		}
61
+
62
+		$signalArguments->setContentData($contentData);
63
+		return array($signalArguments);
64
+	}
65
+
66
+	/**
67
+	 * @param string $updateValue
68
+	 * @param string $currentValue
69
+	 * @param int $counter
70
+	 * @param $creationTime
71
+	 * @return string
72
+	 */
73
+	protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime)
74
+	{
75
+
76
+		// Replaces values.
77
+		$replaces = array(
78
+			$currentValue,
79
+			$counter,
80
+			date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']),
81
+			date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $creationTime),
82
+		);
83
+
84
+		// Replace me!
85
+		return str_replace($this->wellKnownMarkers, $replaces, $updateValue);
86
+	}
87
+
88
+	/**
89
+	 * @param string $updateValue
90
+	 * @param string $currentValue
91
+	 * @return string
92
+	 */
93
+	protected function searchAndReplace($updateValue, $currentValue)
94
+	{
95
+
96
+		if (strpos($updateValue, 's/') !== false) {
97
+			$structure = explode('/', $updateValue);
98
+			$search = $structure[1];
99
+			$replace = $structure[2];
100
+
101
+			// Perhaps needs to be improved here if $search contains "/" precisely.
102
+			$updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue);
103
+		}
104
+		return $updateValue;
105
+	}
106
+
107
+	/**
108
+	 * @param ProcessContentDataSignalArguments $signalArguments
109
+	 * @return int
110
+	 */
111
+	protected function getCreationTime(ProcessContentDataSignalArguments $signalArguments)
112
+	{
113
+		$creationTime = 0;
114
+		$creationTimeField = Tca::table($signalArguments->getContentObject()->getDataType())->getTimeCreationField();
115
+		if ($creationTimeField) {
116
+			$creationTime = $this->getContentObjectResolver()->getValue(
117
+				$signalArguments->getContentObject(),
118
+				$signalArguments->getFieldNameAndPath(),
119
+				$creationTimeField
120
+			);
121
+		}
122
+		return $creationTime;
123
+	}
124
+
125
+	/**
126
+	 * @return ContentObjectResolver
127
+	 */
128
+	protected function getContentObjectResolver()
129
+	{
130
+		return GeneralUtility::makeInstance(ContentObjectResolver::class);
131
+	}
132 132
 
133 133
 }
Please login to merge, or discard this patch.
Classes/Service/ContentService.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@
 block discarded – undo
88 88
     /**
89 89
      * Signal that is called after the content objects have been found.
90 90
      *
91
-     * @param array $contentObjects
91
+     * @param \Fab\Vidi\Domain\Model\Content[] $contentObjects
92 92
      * @param \Fab\Vidi\Persistence\Matcher $matcher
93 93
      * @param Order $order
94 94
      * @param int $limit
Please login to merge, or discard this patch.
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -23,127 +23,127 @@
 block discarded – undo
23 23
 class ContentService
24 24
 {
25 25
 
26
-    /**
27
-     * @var string
28
-     */
29
-    protected $dataType;
30
-
31
-    /**
32
-     * @var \Fab\Vidi\Domain\Model\Content[]
33
-     */
34
-    protected $objects = [];
35
-
36
-    /**
37
-     * @var int
38
-     */
39
-    protected $numberOfObjects = 0;
40
-
41
-    /**
42
-     * Constructor
43
-     *
44
-     * @param string $dataType
45
-     */
46
-    public function __construct($dataType = '')
47
-    {
48
-        if (empty($dataType)) {
49
-            $dataType = $this->getModuleLoader()->getDataType();
50
-        }
51
-        $this->dataType = $dataType;
52
-    }
53
-
54
-    /**
55
-     * Fetch the files given an object assuming
56
-     *
57
-     * @param Matcher $matcher
58
-     * @param Order $order The order
59
-     * @param int $limit
60
-     * @param int $offset
61
-     * @return $this
62
-     */
63
-    public function findBy(Matcher $matcher, Order $order = null, $limit = null, $offset = null)
64
-    {
65
-
66
-        // Query the repository.
67
-        $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order, $limit, $offset);
68
-        $signalResult = $this->emitAfterFindContentObjectsSignal($objects, $matcher, $order, $limit, $offset);
69
-
70
-        // Reset objects variable after possible signal / slot processing.
71
-        $this->objects = $signalResult->getContentObjects();
72
-
73
-        // Count number of content objects.
74
-        if ($signalResult->getHasBeenProcessed()) {
75
-            $this->numberOfObjects = $signalResult->getNumberOfObjects();
76
-        } else {
77
-            $this->numberOfObjects = ContentRepositoryFactory::getInstance($this->dataType)->countBy($matcher);
78
-        }
79
-
80
-        return $this;
81
-    }
82
-
83
-    /**
84
-     * Signal that is called after the content objects have been found.
85
-     *
86
-     * @param array $contentObjects
87
-     * @param \Fab\Vidi\Persistence\Matcher $matcher
88
-     * @param Order $order
89
-     * @param int $limit
90
-     * @param int $offset
91
-     * @return AfterFindContentObjectsSignalArguments
92
-     * @signal
93
-     */
94
-    protected function emitAfterFindContentObjectsSignal($contentObjects, Matcher $matcher, Order $order = null, $limit = 0, $offset = 0)
95
-    {
96
-
97
-        /** @var AfterFindContentObjectsSignalArguments $signalArguments */
98
-        $signalArguments = GeneralUtility::makeInstance(AfterFindContentObjectsSignalArguments::class);
99
-        $signalArguments->setDataType($this->dataType)
100
-            ->setContentObjects($contentObjects)
101
-            ->setMatcher($matcher)
102
-            ->setOrder($order)
103
-            ->setLimit($limit)
104
-            ->setOffset($offset)
105
-            ->setHasBeenProcessed(false);
106
-
107
-        $signalResult = $this->getSignalSlotDispatcher()->dispatch(ContentService::class, 'afterFindContentObjects', array($signalArguments));
108
-        return $signalResult[0];
109
-    }
110
-
111
-    /**
112
-     * Get the Vidi Module Loader.
113
-     *
114
-     * @return ModuleLoader|object
115
-     */
116
-    protected function getModuleLoader()
117
-    {
118
-        return GeneralUtility::makeInstance(ModuleLoader::class);
119
-    }
120
-
121
-    /**
122
-     * Get the SignalSlot dispatcher.
123
-     *
124
-     * @return Dispatcher|object
125
-     */
126
-    protected function getSignalSlotDispatcher()
127
-    {
128
-        /** @var ObjectManager $objectManager */
129
-        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
130
-        return $objectManager->get(Dispatcher::class);
131
-    }
132
-
133
-    /**
134
-     * @return \Fab\Vidi\Domain\Model\Content[]
135
-     */
136
-    public function getObjects()
137
-    {
138
-        return $this->objects;
139
-    }
140
-
141
-    /**
142
-     * @return int
143
-     */
144
-    public function getNumberOfObjects()
145
-    {
146
-        return $this->numberOfObjects;
147
-    }
26
+	/**
27
+	 * @var string
28
+	 */
29
+	protected $dataType;
30
+
31
+	/**
32
+	 * @var \Fab\Vidi\Domain\Model\Content[]
33
+	 */
34
+	protected $objects = [];
35
+
36
+	/**
37
+	 * @var int
38
+	 */
39
+	protected $numberOfObjects = 0;
40
+
41
+	/**
42
+	 * Constructor
43
+	 *
44
+	 * @param string $dataType
45
+	 */
46
+	public function __construct($dataType = '')
47
+	{
48
+		if (empty($dataType)) {
49
+			$dataType = $this->getModuleLoader()->getDataType();
50
+		}
51
+		$this->dataType = $dataType;
52
+	}
53
+
54
+	/**
55
+	 * Fetch the files given an object assuming
56
+	 *
57
+	 * @param Matcher $matcher
58
+	 * @param Order $order The order
59
+	 * @param int $limit
60
+	 * @param int $offset
61
+	 * @return $this
62
+	 */
63
+	public function findBy(Matcher $matcher, Order $order = null, $limit = null, $offset = null)
64
+	{
65
+
66
+		// Query the repository.
67
+		$objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order, $limit, $offset);
68
+		$signalResult = $this->emitAfterFindContentObjectsSignal($objects, $matcher, $order, $limit, $offset);
69
+
70
+		// Reset objects variable after possible signal / slot processing.
71
+		$this->objects = $signalResult->getContentObjects();
72
+
73
+		// Count number of content objects.
74
+		if ($signalResult->getHasBeenProcessed()) {
75
+			$this->numberOfObjects = $signalResult->getNumberOfObjects();
76
+		} else {
77
+			$this->numberOfObjects = ContentRepositoryFactory::getInstance($this->dataType)->countBy($matcher);
78
+		}
79
+
80
+		return $this;
81
+	}
82
+
83
+	/**
84
+	 * Signal that is called after the content objects have been found.
85
+	 *
86
+	 * @param array $contentObjects
87
+	 * @param \Fab\Vidi\Persistence\Matcher $matcher
88
+	 * @param Order $order
89
+	 * @param int $limit
90
+	 * @param int $offset
91
+	 * @return AfterFindContentObjectsSignalArguments
92
+	 * @signal
93
+	 */
94
+	protected function emitAfterFindContentObjectsSignal($contentObjects, Matcher $matcher, Order $order = null, $limit = 0, $offset = 0)
95
+	{
96
+
97
+		/** @var AfterFindContentObjectsSignalArguments $signalArguments */
98
+		$signalArguments = GeneralUtility::makeInstance(AfterFindContentObjectsSignalArguments::class);
99
+		$signalArguments->setDataType($this->dataType)
100
+			->setContentObjects($contentObjects)
101
+			->setMatcher($matcher)
102
+			->setOrder($order)
103
+			->setLimit($limit)
104
+			->setOffset($offset)
105
+			->setHasBeenProcessed(false);
106
+
107
+		$signalResult = $this->getSignalSlotDispatcher()->dispatch(ContentService::class, 'afterFindContentObjects', array($signalArguments));
108
+		return $signalResult[0];
109
+	}
110
+
111
+	/**
112
+	 * Get the Vidi Module Loader.
113
+	 *
114
+	 * @return ModuleLoader|object
115
+	 */
116
+	protected function getModuleLoader()
117
+	{
118
+		return GeneralUtility::makeInstance(ModuleLoader::class);
119
+	}
120
+
121
+	/**
122
+	 * Get the SignalSlot dispatcher.
123
+	 *
124
+	 * @return Dispatcher|object
125
+	 */
126
+	protected function getSignalSlotDispatcher()
127
+	{
128
+		/** @var ObjectManager $objectManager */
129
+		$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
130
+		return $objectManager->get(Dispatcher::class);
131
+	}
132
+
133
+	/**
134
+	 * @return \Fab\Vidi\Domain\Model\Content[]
135
+	 */
136
+	public function getObjects()
137
+	{
138
+		return $this->objects;
139
+	}
140
+
141
+	/**
142
+	 * @return int
143
+	 */
144
+	public function getNumberOfObjects()
145
+	{
146
+		return $this->numberOfObjects;
147
+	}
148 148
 
149 149
 }
Please login to merge, or discard this patch.