Completed
Pull Request — master (#107)
by
unknown
03:27
created
Classes/Controller/Backend/ContentController.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -740,11 +740,11 @@
 block discarded – undo
740 740
      * Signal that is called for post-processing content data send to the server for update.
741 741
      *
742 742
      * @param Content $contentObject
743
-     * @param $fieldNameAndPath
743
+     * @param string $fieldNameAndPath
744 744
      * @param $contentData
745
-     * @param $counter
746
-     * @param $savingBehavior
747
-     * @param $language
745
+     * @param integer $counter
746
+     * @param string $savingBehavior
747
+     * @param integer $language
748 748
      * @return ProcessContentDataSignalArguments
749 749
      * @signal
750 750
      */
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,6 @@
 block discarded – undo
16 16
 
17 17
 use Fab\Vidi\Tca\FieldType;
18 18
 use Fab\Vidi\View\Grid\Row;
19
-use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
20 19
 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 20
 use TYPO3\CMS\Core\Utility\HttpUtility;
22 21
 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
Please login to merge, or discard this patch.
Indentation   +764 added lines, -764 removed lines patch added patch discarded remove patch
@@ -37,769 +37,769 @@
 block discarded – undo
37 37
 class ContentController extends ActionController
38 38
 {
39 39
 
40
-    /**
41
-     * @var \TYPO3\CMS\Core\Page\PageRenderer
42
-     * @inject
43
-     */
44
-    protected $pageRenderer;
45
-
46
-    /**
47
-     * @var \Fab\Vidi\Domain\Repository\SelectionRepository
48
-     * @inject
49
-     */
50
-    protected $selectionRepository;
51
-
52
-    /**
53
-     * Initialize every action.
54
-     */
55
-    public function initializeAction()
56
-    {
57
-        $this->pageRenderer->addInlineLanguageLabelFile('EXT:vidi/Resources/Private/Language/locallang.xlf');
58
-
59
-        // Configure property mapping to retrieve the file object.
60
-        if ($this->arguments->hasArgument('columns')) {
61
-
62
-            /** @var \Fab\Vidi\TypeConverter\CsvToArrayConverter $typeConverter */
63
-            $typeConverter = $this->objectManager->get('Fab\Vidi\TypeConverter\CsvToArrayConverter');
64
-
65
-            $propertyMappingConfiguration = $this->arguments->getArgument('columns')->getPropertyMappingConfiguration();
66
-            $propertyMappingConfiguration->setTypeConverter($typeConverter);
67
-        }
68
-    }
69
-
70
-    /**
71
-     * List action for this controller.
72
-     *
73
-     * @return void
74
-     */
75
-    public function indexAction()
76
-    {
77
-        $dataType = $this->getModuleLoader()->getDataType();
78
-        $selections = $this->selectionRepository->findByDataTypeForCurrentBackendUser($dataType);
79
-        $this->view->assign('selections', $selections);
80
-
81
-        $columns = Tca::grid()->getFields();
82
-        $this->view->assign('columns', $columns);
83
-        $this->view->assign('numberOfColumns', count($columns));
84
-    }
85
-
86
-    /**
87
-     * List Row action for this controller. Output a json list of contents
88
-     *
89
-     * @param array $columns corresponds to columns to be rendered.
90
-     * @param array $matches
91
-     * @validate $columns Fab\Vidi\Domain\Validator\ColumnsValidator
92
-     * @validate $matches Fab\Vidi\Domain\Validator\MatchesValidator
93
-     * @return void
94
-     */
95
-    public function listAction(array $columns = array(), $matches = array())
96
-    {
97
-        // Initialize some objects related to the query.
98
-        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
99
-        $order = OrderObjectFactory::getInstance()->getOrder();
100
-        $pager = PagerObjectFactory::getInstance()->getPager();
101
-
102
-        // Fetch objects via the Content Service.
103
-        $contentService = $this->getContentService()->findBy($matcher, $order, $pager->getLimit(), $pager->getOffset());
104
-        $pager->setCount($contentService->getNumberOfObjects());
105
-
106
-        // Assign values.
107
-        $this->view->assign('columns', $columns);
108
-        $this->view->assign('objects', $contentService->getObjects());
109
-        $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects());
110
-        $this->view->assign('pager', $pager);
111
-        $this->view->assign('response', $this->response);
112
-    }
113
-
114
-    /**
115
-     * Retrieve Content objects first according to matching criteria and then "update" them.
116
-     * Important to notice the field name can contains a path, e.g. metadata.title and therefore must be analysed.
117
-     *
118
-     * Possible values for $matches:
119
-     * -----------------------------
120
-     *
121
-     * $matches = array(uid => 1), will be taken as $query->equals
122
-     * $matches = array(uid => 1,2,3), will be taken as $query->in
123
-     * $matches = array(field_name1 => bar, field_name2 => bax), will be separated by AND.
124
-     *
125
-     * Possible values for $content:
126
-     * -----------------------------
127
-     *
128
-     * $content = array(field_name => bar)
129
-     * $content = array(field_name => array(value1, value2)) <-- will be CSV converted by "value1,value2"
130
-     *
131
-     * @param string $fieldNameAndPath
132
-     * @param array $content
133
-     * @param array $matches
134
-     * @param string $savingBehavior
135
-     * @param int $language
136
-     * @param array $columns
137
-     * @return string
138
-     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
139
-     */
140
-    public function updateAction($fieldNameAndPath, array $content, array $matches = array(), $savingBehavior = SavingBehavior::REPLACE, $language = 0, $columns = array())
141
-    {
142
-
143
-        // Instantiate the Matcher object according different rules.
144
-        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
145
-        $order = OrderObjectFactory::getInstance()->getOrder();
146
-
147
-        // Fetch objects via the Content Service.
148
-        $contentService = $this->getContentService()->findBy($matcher, $order);
149
-
150
-        // Get the real field that is going to be updated.
151
-        $updatedFieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
152
-
153
-        // Get result object for storing data along the processing.
154
-        $result = $this->getJsonResult();
155
-        $result->setNumberOfObjects($contentService->getNumberOfObjects());
156
-
157
-        foreach ($contentService->getObjects() as $index => $object) {
158
-
159
-            $identifier = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, 'uid', $language);
160
-
161
-            // It could be the identifier is not found because the translation
162
-            // of the record does not yet exist when mass-editing
163
-            if ((int)$identifier <= 0) {
164
-                continue;
165
-            }
166
-
167
-            $dataType = $this->getContentObjectResolver()->getDataType($object, $fieldNameAndPath);
168
-
169
-            $signalResult = $this->emitProcessContentDataSignal($object, $fieldNameAndPath, $content, $index + 1, $savingBehavior, $language);
170
-            $contentData = $signalResult->getContentData();
171
-
172
-            // Add identifier to content data, required by TCEMain.
173
-            $contentData['uid'] = $identifier;
174
-
175
-            /** @var Content $dataObject */
176
-            $dataObject = GeneralUtility::makeInstance('Fab\Vidi\Domain\Model\Content', $dataType, $contentData);
177
-
178
-            // Properly update object.
179
-            ContentRepositoryFactory::getInstance($dataType)->update($dataObject);
180
-
181
-            // Get the possible error messages and store them.
182
-            $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
183
-            $result->addErrorMessages($errorMessages);
184
-
185
-            // We only want to see the detail result if there is one object updated.
186
-            // Required for inline editing + it will display some useful info on the GUI in the flash messages.
187
-            if ($contentService->getNumberOfObjects() === 1) {
188
-
189
-                // Fetch the updated object from repository.
190
-                $updatedObject = ContentRepositoryFactory::getInstance()->findByUid($object->getUid());
191
-
192
-                // Re-fetch the updated result.
193
-                $updatedResult = $this->getContentObjectResolver()->getValue($updatedObject, $fieldNameAndPath, $updatedFieldName, $language);
194
-                if (is_array($updatedResult)) {
195
-                    $_updatedResult = array(); // reset result set.
196
-
197
-                    /** @var Content $contentObject */
198
-                    foreach ($updatedResult as $contentObject) {
199
-                        $labelField = Tca::table($contentObject)->getLabelField();
200
-                        $values = array(
201
-                            'uid' => $contentObject->getUid(),
202
-                            'name' => $contentObject[$labelField],
203
-                        );
204
-                        $_updatedResult[] = $values;
205
-                    }
206
-
207
-                    $updatedResult = $_updatedResult;
208
-                }
209
-
210
-                $labelField = Tca::table($object)->getLabelField();
211
-
212
-                $processedObjectData = array(
213
-                    'uid' => $object->getUid(),
214
-                    'name' => $object[$labelField],
215
-                    'updatedField' => $fieldNameAndPath,
216
-                    'updatedValue' => $updatedResult,
217
-                );
218
-                $result->setProcessedObject($processedObjectData);
219
-
220
-                if (!empty($columns)) {
221
-                    /** @var Row $row */
222
-                    $row = GeneralUtility::makeInstance('Fab\Vidi\View\Grid\Row', $columns);
223
-                    $result->setRow($row->render($updatedObject));
224
-                }
225
-            }
226
-        }
227
-
228
-        // Set the result and render the JSON view.
229
-        $this->getJsonView()->setResult($result);
230
-        return $this->getJsonView()->render();
231
-    }
232
-
233
-    /**
234
-     * Set the sorting of a record giving the previous object.
235
-     *
236
-     * @param array $matches
237
-     * @param int $previousIdentifier
238
-     * @return string
239
-     */
240
-    public function sortAction(array $matches = array(), $previousIdentifier = NULL)
241
-    {
242
-
243
-        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
244
-
245
-        // Fetch objects via the Content Service.
246
-        $contentService = $this->getContentService()->findBy($matcher);
247
-
248
-        // Compute the label field name of the table.
249
-        $tableTitleField = Tca::table()->getLabelField();
250
-
251
-        // Get result object for storing data along the processing.
252
-        $result = $this->getJsonResult();
253
-        $result->setNumberOfObjects($contentService->getNumberOfObjects());
254
-
255
-        foreach ($contentService->getObjects() as $object) {
256
-
257
-            // Store the first object, so that the "action" message can be more explicit when deleting only one record.
258
-            if ($contentService->getNumberOfObjects() === 1) {
259
-                $tableTitleValue = $object[$tableTitleField];
260
-                $processedObjectData = array(
261
-                    'uid' => $object->getUid(),
262
-                    'name' => $tableTitleValue,
263
-                );
264
-                $result->setProcessedObject($processedObjectData);
265
-            }
266
-
267
-            // The $target corresponds to the pid to move the records to.
268
-            // It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor.
269
-            $target = is_null($previousIdentifier) ? $object->getPid() : (-(int)$previousIdentifier);
270
-
271
-            // Work out the object.
272
-            ContentRepositoryFactory::getInstance()->move($object, $target);
273
-
274
-            // Get the possible error messages and store them.
275
-            $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
276
-            $result->addErrorMessages($errorMessages);
277
-        }
278
-
279
-        // Set the result and render the JSON view.
280
-        $this->getJsonView()->setResult($result);
281
-        return $this->getJsonView()->render();
282
-    }
283
-
284
-    /**
285
-     * Returns an editing form for a given field name of a Content object.
286
-     * Argument $fieldNameAndPath corresponds to the field name to be edited.
287
-     * Important to notice it can contains a path, e.g. metadata.title and therefore must be analysed.
288
-     *
289
-     * Possible values for $matches, refer to method "updateAction".
290
-     *
291
-     * @param string $fieldNameAndPath
292
-     * @param array $matches
293
-     * @param bool $hasRecursiveSelection
294
-     * @throws \Exception
295
-     */
296
-    public function editAction($fieldNameAndPath, array $matches = array(), $hasRecursiveSelection = FALSE)
297
-    {
298
-
299
-        // Instantiate the Matcher object according different rules.
300
-        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
301
-
302
-        // Fetch objects via the Content Service.
303
-        $contentService = $this->getContentService()->findBy($matcher);
304
-
305
-        $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
306
-        $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
307
-
308
-        $fieldType = Tca::table($dataType)->field($fieldName)->getType();
309
-        $this->view->assign('fieldType', ucfirst($fieldType));
310
-        $this->view->assign('dataType', $dataType);
311
-        $this->view->assign('fieldName', $fieldName);
312
-        $this->view->assign('matches', $matches);
313
-        $this->view->assign('fieldNameAndPath', $fieldNameAndPath);
314
-        $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects());
315
-        $this->view->assign('hasRecursiveSelection', $hasRecursiveSelection);
316
-        $this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary??
317
-
318
-        // Fetch content and its relations.
319
-        if ($fieldType === FieldType::MULTISELECT) {
320
-
321
-            $object = ContentRepositoryFactory::getInstance()->findOneBy($matcher);
322
-            $identifier = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, 'uid');
323
-            $dataType = $this->getContentObjectResolver()->getDataType($object, $fieldNameAndPath);
324
-
325
-            $content = ContentRepositoryFactory::getInstance($dataType)->findByUid($identifier);
326
-
327
-            // Makes sure the object was retrieved. Security!
328
-            if (!$content) {
329
-                $message = sprintf('I could not retrieved content object of type "%s" with identifier %s.', $dataType, $identifier);
330
-                throw new \Exception($message, 1402350182);
331
-            }
332
-
333
-            $relatedDataType = Tca::table($dataType)->field($fieldName)->getForeignTable();
334
-
335
-            // Initialize the matcher object.
336
-            /** @var \Fab\Vidi\Persistence\Matcher $matcher */
337
-            $matcher = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Matcher', array(), $relatedDataType);
338
-
339
-            // Default ordering for related data type.
340
-            $defaultOrderings = Tca::table($relatedDataType)->getDefaultOrderings();
341
-            /** @var \Fab\Vidi\Persistence\Order $order */
342
-            $defaultOrder = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Order', $defaultOrderings);
343
-
344
-            // Fetch related contents
345
-            $relatedContents = ContentRepositoryFactory::getInstance($relatedDataType)->findBy($matcher, $defaultOrder);
346
-
347
-            if (Tca::table($dataType)->field($fieldName)->isRenderModeTree()) {
348
-
349
-                $fieldConfiguration = Tca::table($dataType)->field($fieldName)->getConfiguration();
350
-                $parentField = $fieldConfiguration['treeConfig']['parentField'];
351
-
352
-                $flatTree = array();
353
-                foreach ($relatedContents as $node) {
354
-                    $flatTree[$node->getUid()] = array(
355
-                        'item' => $node,
356
-                        'parent' => $node[$parentField] ? $node[$parentField]['uid'] : NULL,
357
-                    );
358
-                }
359
-
360
-                $tree = array();
361
-
362
-                // If leaves are selected without its parents selected, those are shown as parent
363
-                foreach ($flatTree as $id => &$flatNode) {
364
-                    if (!isset($flatTree[$flatNode['parent']])) {
365
-                        $flatNode['parent'] = NULL;
366
-                    }
367
-                }
368
-
369
-                foreach ($flatTree as $id => &$node) {
370
-                    if ($node['parent'] === NULL) {
371
-                        $tree[$id] = &$node;
372
-                    } else {
373
-                        $flatTree[$node['parent']]['children'][$id] = &$node;
374
-                    }
375
-                }
376
-
377
-                $relatedContents = $tree;
378
-            }
379
-
380
-            $this->view->assign('content', $content);
381
-            $this->view->assign('relatedContents', $relatedContents);
382
-            $this->view->assign('relatedDataType', $relatedDataType);
383
-            $this->view->assign('relatedContentTitle', Tca::table($relatedDataType)->getTitle());
384
-            $this->view->assign(
385
-                'renderMode',
386
-                Tca::table($dataType)->field($fieldName)->isRenderModeTree() ? FieldType::TREE : NULL
387
-            );
388
-        }
389
-    }
390
-
391
-    /**
392
-     * Retrieve Content objects first according to matching criteria and then "delete" them.
393
-     *
394
-     * Possible values for $matches, refer to method "updateAction".
395
-     *
396
-     * @param array $matches
397
-     * @return string
398
-     */
399
-    public function deleteAction(array $matches = array())
400
-    {
401
-
402
-        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
403
-
404
-        // Fetch objects via the Content Service.
405
-        $contentService = $this->getContentService()->findBy($matcher);
406
-
407
-        // Compute the label field name of the table.
408
-        $tableTitleField = Tca::table()->getLabelField();
409
-
410
-        // Get result object for storing data along the processing.
411
-        $result = $this->getJsonResult();
412
-        $result->setNumberOfObjects($contentService->getNumberOfObjects());
413
-
414
-        foreach ($contentService->getObjects() as $object) {
415
-
416
-            // Store the first object, so that the delete message can be more explicit when deleting only one record.
417
-            if ($contentService->getNumberOfObjects() === 1) {
418
-                $tableTitleValue = $object[$tableTitleField];
419
-                $processedObjectData = array(
420
-                    'uid' => $object->getUid(),
421
-                    'name' => $tableTitleValue,
422
-                );
423
-                $result->setProcessedObject($processedObjectData);
424
-            }
425
-
426
-            // Properly delete object.
427
-            ContentRepositoryFactory::getInstance()->remove($object);
428
-
429
-            // Get the possible error messages and store them.
430
-            $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
431
-            $result->addErrorMessages($errorMessages);
432
-        }
433
-
434
-        // Set the result and render the JSON view.
435
-        $this->getJsonView()->setResult($result);
436
-        return $this->getJsonView()->render();
437
-    }
438
-
439
-    /**
440
-     * Retrieve Content objects first according to matching criteria and then "copy" them.
441
-     *
442
-     * Possible values for $matches, refer to method "updateAction".
443
-     *
444
-     * @param string $target
445
-     * @param array $matches
446
-     * @throws \Exception
447
-     * @return string
448
-     */
449
-    public function copyAction($target, array $matches = array())
450
-    {
451
-        // @todo
452
-        throw new \Exception('Not yet implemented', 1410192546);
453
-    }
454
-
455
-    /**
456
-     * Retrieve Content objects from the Clipboard then "copy" them according to the target.
457
-     *
458
-     * @param string $target
459
-     * @throws \Exception
460
-     * @return string
461
-     */
462
-    public function copyClipboardAction($target)
463
-    {
464
-
465
-        // Retrieve matcher object from clipboard.
466
-        $matcher = $this->getClipboardService()->getMatcher();
467
-
468
-        // Fetch objects via the Content Service.
469
-        $contentService = $this->getContentService()->findBy($matcher);
470
-
471
-        // Compute the label field name of the table.
472
-        $tableTitleField = Tca::table()->getLabelField();
473
-
474
-        // Get result object for storing data along the processing.
475
-        $result = $this->getJsonResult();
476
-        $result->setNumberOfObjects($contentService->getNumberOfObjects());
477
-
478
-        foreach ($contentService->getObjects() as $object) {
479
-
480
-            // Store the first object, so that the "action" message can be more explicit when deleting only one record.
481
-            if ($contentService->getNumberOfObjects() === 1) {
482
-                $tableTitleValue = $object[$tableTitleField];
483
-                $processedObjectData = array(
484
-                    'uid' => $object->getUid(),
485
-                    'name' => $tableTitleValue,
486
-                );
487
-                $result->setProcessedObject($processedObjectData);
488
-            }
489
-
490
-            // Work out the object.
491
-            ContentRepositoryFactory::getInstance()->copy($object, $target);
492
-
493
-            // Get the possible error messages and store them.
494
-            $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
495
-            $result->addErrorMessages($errorMessages);
496
-        }
497
-
498
-        // Flush Clipboard if told so.
499
-        if (GeneralUtility::_GP('flushClipboard')) {
500
-            $this->getClipboardService()->flush();
501
-        }
502
-
503
-        // Set the result and render the JSON view.
504
-        $this->getJsonView()->setResult($result);
505
-        return $this->getJsonView()->render();
506
-    }
507
-
508
-    /**
509
-     * Retrieve Content objects first according to matching criteria and then "move" them.
510
-     *
511
-     * Possible values for $matches, refer to method "updateAction".
512
-     *
513
-     * @param string $target
514
-     * @param array $matches
515
-     * @return string
516
-     */
517
-    public function moveAction($target, array $matches = array())
518
-    {
519
-
520
-        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
521
-
522
-        // Fetch objects via the Content Service.
523
-        $contentService = $this->getContentService()->findBy($matcher);
524
-
525
-        // Compute the label field name of the table.
526
-        $tableTitleField = Tca::table()->getLabelField();
527
-
528
-        // Get result object for storing data along the processing.
529
-        $result = $this->getJsonResult();
530
-        $result->setNumberOfObjects($contentService->getNumberOfObjects());
531
-
532
-        foreach ($contentService->getObjects() as $object) {
533
-
534
-            // Store the first object, so that the "action" message can be more explicit when deleting only one record.
535
-            if ($contentService->getNumberOfObjects() === 1) {
536
-                $tableTitleValue = $object[$tableTitleField];
537
-                $processedObjectData = array(
538
-                    'uid' => $object->getUid(),
539
-                    'name' => $tableTitleValue,
540
-                );
541
-                $result->setProcessedObject($processedObjectData);
542
-            }
543
-
544
-            // Work out the object.
545
-            ContentRepositoryFactory::getInstance()->move($object, $target);
546
-
547
-            // Get the possible error messages and store them.
548
-            $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
549
-            $result->addErrorMessages($errorMessages);
550
-        }
551
-
552
-        // Set the result and render the JSON view.
553
-        $this->getJsonView()->setResult($result);
554
-        return $this->getJsonView()->render();
555
-    }
556
-
557
-    /**
558
-     * Retrieve Content objects from the Clipboard then "move" them according to the target.
559
-     *
560
-     * @param string $target
561
-     * @return string
562
-     */
563
-    public function moveClipboardAction($target)
564
-    {
565
-
566
-        // Retrieve matcher object from clipboard.
567
-        $matcher = $this->getClipboardService()->getMatcher();
568
-
569
-        // Fetch objects via the Content Service.
570
-        $contentService = $this->getContentService()->findBy($matcher);
571
-
572
-        // Compute the label field name of the table.
573
-        $tableTitleField = Tca::table()->getLabelField();
574
-
575
-        // Get result object for storing data along the processing.
576
-        $result = $this->getJsonResult();
577
-        $result->setNumberOfObjects($contentService->getNumberOfObjects());
578
-
579
-        foreach ($contentService->getObjects() as $object) {
580
-
581
-            // Store the first object, so that the "action" message can be more explicit when deleting only one record.
582
-            if ($contentService->getNumberOfObjects() === 1) {
583
-                $tableTitleValue = $object[$tableTitleField];
584
-                $processedObjectData = array(
585
-                    'uid' => $object->getUid(),
586
-                    'name' => $tableTitleValue,
587
-                );
588
-                $result->setProcessedObject($processedObjectData);
589
-            }
590
-
591
-            // Work out the object.
592
-            ContentRepositoryFactory::getInstance()->move($object, $target);
593
-
594
-            // Get the possible error messages and store them.
595
-            $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
596
-            $result->addErrorMessages($errorMessages);
597
-        }
598
-
599
-        // Flush Clipboard if told so.
600
-        if (GeneralUtility::_GP('flushClipboard')) {
601
-            $this->getClipboardService()->flush();
602
-        }
603
-
604
-        // Set the result and render the JSON view.
605
-        $this->getJsonView()->setResult($result);
606
-        return $this->getJsonView()->render();
607
-    }
608
-
609
-    /**
610
-     * Retrieve Content objects first according to matching criteria and then "localize" them.
611
-     *
612
-     * Possible values for $matches, refer to method "updateAction".
613
-     *
614
-     * @param string $fieldNameAndPath
615
-     * @param array $matches
616
-     * @param int $language
617
-     * @return string
618
-     * @throws \Exception
619
-     */
620
-    public function localizeAction($fieldNameAndPath, array $matches = array(), $language = 0)
621
-    {
622
-
623
-        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
624
-
625
-        // Fetch objects via the Content Service.
626
-        $contentService = $this->getContentService()->findBy($matcher);
627
-
628
-        // Get result object for storing data along the processing.
629
-        $result = $this->getJsonResult();
630
-        $result->setNumberOfObjects($contentService->getNumberOfObjects());
631
-
632
-        foreach ($contentService->getObjects() as $object) {
633
-
634
-            $identifier = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, 'uid');
635
-            $dataType = $this->getContentObjectResolver()->getDataType($object, $fieldNameAndPath);
636
-
637
-            // Fetch the source object to be localized.
638
-            /** @var Content $content */
639
-            $content = ContentRepositoryFactory::getInstance($dataType)->findByIdentifier($identifier);
640
-
641
-            // Makes sure the object was retrieved. Security!
642
-            if (!$content) {
643
-                $message = sprintf('Something went wrong when retrieving content "%s" with identifier "%s".', $dataType, $identifier);
644
-                throw new \Exception($message, 1412343097);
645
-            }
646
-
647
-            // Handover the localization to the Repository.
648
-            ContentRepositoryFactory::getInstance($dataType)->localize($content, $language);
649
-
650
-            // Get the possible error messages and store them.
651
-            $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
652
-
653
-            // Redirect to TCEForm so that the BE User can do its job!
654
-            if ($contentService->getNumberOfObjects() === 1) {
655
-
656
-                if (!empty($errorMessages)) {
657
-                    $message = sprintf('Something went wrong when localizing content "%s" with identifier "%s". <br/>%s',
658
-                        $dataType,
659
-                        $identifier,
660
-                        implode('<br/>', $errorMessages)
661
-                    );
662
-                    throw new \Exception($message, 1412343098);
663
-                }
664
-
665
-                $localizedContent = $this->getLanguageService()->getLocalizedContent($content, $language);
666
-                if (empty($localizedContent)) {
667
-                    $message = sprintf('Oups! I could not retrieve localized content of type "%s" with identifier "%s"',
668
-                        $content->getDataType(),
669
-                        $content->getUid()
670
-                    );
671
-                    throw new \Exception($message, 1412343099);
672
-                }
673
-
674
-                /** @var \Fab\Vidi\View\Uri\EditUri $uri */
675
-                $uriRenderer = GeneralUtility::makeInstance('Fab\Vidi\View\Uri\EditUri');
676
-                $uri = $uriRenderer->render($localizedContent);
677
-                HttpUtility::redirect($uri);
678
-                break; // no need to further continue
679
-            }
680
-
681
-            $result->addErrorMessages($errorMessages);
682
-        }
683
-
684
-        // Set the result and render the JSON view.
685
-        $this->getJsonView()->setResult($result);
686
-        return $this->getJsonView()->render();
687
-    }
688
-
689
-    /**
690
-     * Get the Vidi Module Loader.
691
-     *
692
-     * @return \Fab\Vidi\Service\ContentService
693
-     */
694
-    protected function getContentService()
695
-    {
696
-        return GeneralUtility::makeInstance('Fab\Vidi\Service\ContentService');
697
-    }
698
-
699
-    /**
700
-     * @return \Fab\Vidi\Resolver\ContentObjectResolver
701
-     */
702
-    protected function getContentObjectResolver()
703
-    {
704
-        return GeneralUtility::makeInstance('Fab\Vidi\Resolver\ContentObjectResolver');
705
-    }
706
-
707
-    /**
708
-     * @return \Fab\Vidi\Resolver\FieldPathResolver
709
-     */
710
-    protected function getFieldPathResolver()
711
-    {
712
-        return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
713
-    }
714
-
715
-    /**
716
-     * Return a special view for handling JSON
717
-     * Goal is to have this view injected but require more configuration.
718
-     *
719
-     * @return JsonView
720
-     */
721
-    protected function getJsonView()
722
-    {
723
-        if (!$this->view instanceof JsonView) {
724
-            /** @var JsonView $view */
725
-            $this->view = $this->objectManager->get('Fab\Vidi\Mvc\JsonView');
726
-            $this->view->setResponse($this->response);
727
-        }
728
-        return $this->view;
729
-    }
730
-
731
-    /**
732
-     * @return JsonResult
733
-     */
734
-    protected function getJsonResult()
735
-    {
736
-        return GeneralUtility::makeInstance('Fab\Vidi\Mvc\JsonResult');
737
-    }
738
-
739
-    /**
740
-     * Signal that is called for post-processing content data send to the server for update.
741
-     *
742
-     * @param Content $contentObject
743
-     * @param $fieldNameAndPath
744
-     * @param $contentData
745
-     * @param $counter
746
-     * @param $savingBehavior
747
-     * @param $language
748
-     * @return ProcessContentDataSignalArguments
749
-     * @signal
750
-     */
751
-    protected function emitProcessContentDataSignal(Content $contentObject, $fieldNameAndPath, $contentData, $counter, $savingBehavior, $language)
752
-    {
753
-
754
-        /** @var \Fab\Vidi\Signal\ProcessContentDataSignalArguments $signalArguments */
755
-        $signalArguments = GeneralUtility::makeInstance('Fab\Vidi\Signal\ProcessContentDataSignalArguments');
756
-        $signalArguments->setContentObject($contentObject)
757
-            ->setFieldNameAndPath($fieldNameAndPath)
758
-            ->setContentData($contentData)
759
-            ->setCounter($counter)
760
-            ->setSavingBehavior($savingBehavior)
761
-            ->setLanguage($language);
762
-
763
-        $signalResult = $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\Controller\Backend\ContentController', 'processContentData', array($signalArguments));
764
-        return $signalResult[0];
765
-    }
766
-
767
-    /**
768
-     * Get the SignalSlot dispatcher.
769
-     *
770
-     * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
771
-     */
772
-    protected function getSignalSlotDispatcher()
773
-    {
774
-        return $this->objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
775
-    }
776
-
777
-    /**
778
-     * Get the Clipboard service.
779
-     *
780
-     * @return \Fab\Vidi\Service\ClipboardService
781
-     */
782
-    protected function getClipboardService()
783
-    {
784
-        return GeneralUtility::makeInstance('Fab\Vidi\Service\ClipboardService');
785
-    }
786
-
787
-    /**
788
-     * @return \Fab\Vidi\Language\LanguageService
789
-     */
790
-    protected function getLanguageService()
791
-    {
792
-        return GeneralUtility::makeInstance('Fab\Vidi\Language\LanguageService');
793
-    }
794
-
795
-    /**
796
-     * Get the Vidi Module Loader.
797
-     *
798
-     * @return \Fab\Vidi\Module\ModuleLoader
799
-     */
800
-    protected function getModuleLoader()
801
-    {
802
-        return GeneralUtility::makeInstance('Fab\Vidi\Module\ModuleLoader');
803
-    }
40
+	/**
41
+	 * @var \TYPO3\CMS\Core\Page\PageRenderer
42
+	 * @inject
43
+	 */
44
+	protected $pageRenderer;
45
+
46
+	/**
47
+	 * @var \Fab\Vidi\Domain\Repository\SelectionRepository
48
+	 * @inject
49
+	 */
50
+	protected $selectionRepository;
51
+
52
+	/**
53
+	 * Initialize every action.
54
+	 */
55
+	public function initializeAction()
56
+	{
57
+		$this->pageRenderer->addInlineLanguageLabelFile('EXT:vidi/Resources/Private/Language/locallang.xlf');
58
+
59
+		// Configure property mapping to retrieve the file object.
60
+		if ($this->arguments->hasArgument('columns')) {
61
+
62
+			/** @var \Fab\Vidi\TypeConverter\CsvToArrayConverter $typeConverter */
63
+			$typeConverter = $this->objectManager->get('Fab\Vidi\TypeConverter\CsvToArrayConverter');
64
+
65
+			$propertyMappingConfiguration = $this->arguments->getArgument('columns')->getPropertyMappingConfiguration();
66
+			$propertyMappingConfiguration->setTypeConverter($typeConverter);
67
+		}
68
+	}
69
+
70
+	/**
71
+	 * List action for this controller.
72
+	 *
73
+	 * @return void
74
+	 */
75
+	public function indexAction()
76
+	{
77
+		$dataType = $this->getModuleLoader()->getDataType();
78
+		$selections = $this->selectionRepository->findByDataTypeForCurrentBackendUser($dataType);
79
+		$this->view->assign('selections', $selections);
80
+
81
+		$columns = Tca::grid()->getFields();
82
+		$this->view->assign('columns', $columns);
83
+		$this->view->assign('numberOfColumns', count($columns));
84
+	}
85
+
86
+	/**
87
+	 * List Row action for this controller. Output a json list of contents
88
+	 *
89
+	 * @param array $columns corresponds to columns to be rendered.
90
+	 * @param array $matches
91
+	 * @validate $columns Fab\Vidi\Domain\Validator\ColumnsValidator
92
+	 * @validate $matches Fab\Vidi\Domain\Validator\MatchesValidator
93
+	 * @return void
94
+	 */
95
+	public function listAction(array $columns = array(), $matches = array())
96
+	{
97
+		// Initialize some objects related to the query.
98
+		$matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
99
+		$order = OrderObjectFactory::getInstance()->getOrder();
100
+		$pager = PagerObjectFactory::getInstance()->getPager();
101
+
102
+		// Fetch objects via the Content Service.
103
+		$contentService = $this->getContentService()->findBy($matcher, $order, $pager->getLimit(), $pager->getOffset());
104
+		$pager->setCount($contentService->getNumberOfObjects());
105
+
106
+		// Assign values.
107
+		$this->view->assign('columns', $columns);
108
+		$this->view->assign('objects', $contentService->getObjects());
109
+		$this->view->assign('numberOfObjects', $contentService->getNumberOfObjects());
110
+		$this->view->assign('pager', $pager);
111
+		$this->view->assign('response', $this->response);
112
+	}
113
+
114
+	/**
115
+	 * Retrieve Content objects first according to matching criteria and then "update" them.
116
+	 * Important to notice the field name can contains a path, e.g. metadata.title and therefore must be analysed.
117
+	 *
118
+	 * Possible values for $matches:
119
+	 * -----------------------------
120
+	 *
121
+	 * $matches = array(uid => 1), will be taken as $query->equals
122
+	 * $matches = array(uid => 1,2,3), will be taken as $query->in
123
+	 * $matches = array(field_name1 => bar, field_name2 => bax), will be separated by AND.
124
+	 *
125
+	 * Possible values for $content:
126
+	 * -----------------------------
127
+	 *
128
+	 * $content = array(field_name => bar)
129
+	 * $content = array(field_name => array(value1, value2)) <-- will be CSV converted by "value1,value2"
130
+	 *
131
+	 * @param string $fieldNameAndPath
132
+	 * @param array $content
133
+	 * @param array $matches
134
+	 * @param string $savingBehavior
135
+	 * @param int $language
136
+	 * @param array $columns
137
+	 * @return string
138
+	 * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
139
+	 */
140
+	public function updateAction($fieldNameAndPath, array $content, array $matches = array(), $savingBehavior = SavingBehavior::REPLACE, $language = 0, $columns = array())
141
+	{
142
+
143
+		// Instantiate the Matcher object according different rules.
144
+		$matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
145
+		$order = OrderObjectFactory::getInstance()->getOrder();
146
+
147
+		// Fetch objects via the Content Service.
148
+		$contentService = $this->getContentService()->findBy($matcher, $order);
149
+
150
+		// Get the real field that is going to be updated.
151
+		$updatedFieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
152
+
153
+		// Get result object for storing data along the processing.
154
+		$result = $this->getJsonResult();
155
+		$result->setNumberOfObjects($contentService->getNumberOfObjects());
156
+
157
+		foreach ($contentService->getObjects() as $index => $object) {
158
+
159
+			$identifier = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, 'uid', $language);
160
+
161
+			// It could be the identifier is not found because the translation
162
+			// of the record does not yet exist when mass-editing
163
+			if ((int)$identifier <= 0) {
164
+				continue;
165
+			}
166
+
167
+			$dataType = $this->getContentObjectResolver()->getDataType($object, $fieldNameAndPath);
168
+
169
+			$signalResult = $this->emitProcessContentDataSignal($object, $fieldNameAndPath, $content, $index + 1, $savingBehavior, $language);
170
+			$contentData = $signalResult->getContentData();
171
+
172
+			// Add identifier to content data, required by TCEMain.
173
+			$contentData['uid'] = $identifier;
174
+
175
+			/** @var Content $dataObject */
176
+			$dataObject = GeneralUtility::makeInstance('Fab\Vidi\Domain\Model\Content', $dataType, $contentData);
177
+
178
+			// Properly update object.
179
+			ContentRepositoryFactory::getInstance($dataType)->update($dataObject);
180
+
181
+			// Get the possible error messages and store them.
182
+			$errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
183
+			$result->addErrorMessages($errorMessages);
184
+
185
+			// We only want to see the detail result if there is one object updated.
186
+			// Required for inline editing + it will display some useful info on the GUI in the flash messages.
187
+			if ($contentService->getNumberOfObjects() === 1) {
188
+
189
+				// Fetch the updated object from repository.
190
+				$updatedObject = ContentRepositoryFactory::getInstance()->findByUid($object->getUid());
191
+
192
+				// Re-fetch the updated result.
193
+				$updatedResult = $this->getContentObjectResolver()->getValue($updatedObject, $fieldNameAndPath, $updatedFieldName, $language);
194
+				if (is_array($updatedResult)) {
195
+					$_updatedResult = array(); // reset result set.
196
+
197
+					/** @var Content $contentObject */
198
+					foreach ($updatedResult as $contentObject) {
199
+						$labelField = Tca::table($contentObject)->getLabelField();
200
+						$values = array(
201
+							'uid' => $contentObject->getUid(),
202
+							'name' => $contentObject[$labelField],
203
+						);
204
+						$_updatedResult[] = $values;
205
+					}
206
+
207
+					$updatedResult = $_updatedResult;
208
+				}
209
+
210
+				$labelField = Tca::table($object)->getLabelField();
211
+
212
+				$processedObjectData = array(
213
+					'uid' => $object->getUid(),
214
+					'name' => $object[$labelField],
215
+					'updatedField' => $fieldNameAndPath,
216
+					'updatedValue' => $updatedResult,
217
+				);
218
+				$result->setProcessedObject($processedObjectData);
219
+
220
+				if (!empty($columns)) {
221
+					/** @var Row $row */
222
+					$row = GeneralUtility::makeInstance('Fab\Vidi\View\Grid\Row', $columns);
223
+					$result->setRow($row->render($updatedObject));
224
+				}
225
+			}
226
+		}
227
+
228
+		// Set the result and render the JSON view.
229
+		$this->getJsonView()->setResult($result);
230
+		return $this->getJsonView()->render();
231
+	}
232
+
233
+	/**
234
+	 * Set the sorting of a record giving the previous object.
235
+	 *
236
+	 * @param array $matches
237
+	 * @param int $previousIdentifier
238
+	 * @return string
239
+	 */
240
+	public function sortAction(array $matches = array(), $previousIdentifier = NULL)
241
+	{
242
+
243
+		$matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
244
+
245
+		// Fetch objects via the Content Service.
246
+		$contentService = $this->getContentService()->findBy($matcher);
247
+
248
+		// Compute the label field name of the table.
249
+		$tableTitleField = Tca::table()->getLabelField();
250
+
251
+		// Get result object for storing data along the processing.
252
+		$result = $this->getJsonResult();
253
+		$result->setNumberOfObjects($contentService->getNumberOfObjects());
254
+
255
+		foreach ($contentService->getObjects() as $object) {
256
+
257
+			// Store the first object, so that the "action" message can be more explicit when deleting only one record.
258
+			if ($contentService->getNumberOfObjects() === 1) {
259
+				$tableTitleValue = $object[$tableTitleField];
260
+				$processedObjectData = array(
261
+					'uid' => $object->getUid(),
262
+					'name' => $tableTitleValue,
263
+				);
264
+				$result->setProcessedObject($processedObjectData);
265
+			}
266
+
267
+			// The $target corresponds to the pid to move the records to.
268
+			// It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor.
269
+			$target = is_null($previousIdentifier) ? $object->getPid() : (-(int)$previousIdentifier);
270
+
271
+			// Work out the object.
272
+			ContentRepositoryFactory::getInstance()->move($object, $target);
273
+
274
+			// Get the possible error messages and store them.
275
+			$errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
276
+			$result->addErrorMessages($errorMessages);
277
+		}
278
+
279
+		// Set the result and render the JSON view.
280
+		$this->getJsonView()->setResult($result);
281
+		return $this->getJsonView()->render();
282
+	}
283
+
284
+	/**
285
+	 * Returns an editing form for a given field name of a Content object.
286
+	 * Argument $fieldNameAndPath corresponds to the field name to be edited.
287
+	 * Important to notice it can contains a path, e.g. metadata.title and therefore must be analysed.
288
+	 *
289
+	 * Possible values for $matches, refer to method "updateAction".
290
+	 *
291
+	 * @param string $fieldNameAndPath
292
+	 * @param array $matches
293
+	 * @param bool $hasRecursiveSelection
294
+	 * @throws \Exception
295
+	 */
296
+	public function editAction($fieldNameAndPath, array $matches = array(), $hasRecursiveSelection = FALSE)
297
+	{
298
+
299
+		// Instantiate the Matcher object according different rules.
300
+		$matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
301
+
302
+		// Fetch objects via the Content Service.
303
+		$contentService = $this->getContentService()->findBy($matcher);
304
+
305
+		$dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
306
+		$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
307
+
308
+		$fieldType = Tca::table($dataType)->field($fieldName)->getType();
309
+		$this->view->assign('fieldType', ucfirst($fieldType));
310
+		$this->view->assign('dataType', $dataType);
311
+		$this->view->assign('fieldName', $fieldName);
312
+		$this->view->assign('matches', $matches);
313
+		$this->view->assign('fieldNameAndPath', $fieldNameAndPath);
314
+		$this->view->assign('numberOfObjects', $contentService->getNumberOfObjects());
315
+		$this->view->assign('hasRecursiveSelection', $hasRecursiveSelection);
316
+		$this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary??
317
+
318
+		// Fetch content and its relations.
319
+		if ($fieldType === FieldType::MULTISELECT) {
320
+
321
+			$object = ContentRepositoryFactory::getInstance()->findOneBy($matcher);
322
+			$identifier = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, 'uid');
323
+			$dataType = $this->getContentObjectResolver()->getDataType($object, $fieldNameAndPath);
324
+
325
+			$content = ContentRepositoryFactory::getInstance($dataType)->findByUid($identifier);
326
+
327
+			// Makes sure the object was retrieved. Security!
328
+			if (!$content) {
329
+				$message = sprintf('I could not retrieved content object of type "%s" with identifier %s.', $dataType, $identifier);
330
+				throw new \Exception($message, 1402350182);
331
+			}
332
+
333
+			$relatedDataType = Tca::table($dataType)->field($fieldName)->getForeignTable();
334
+
335
+			// Initialize the matcher object.
336
+			/** @var \Fab\Vidi\Persistence\Matcher $matcher */
337
+			$matcher = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Matcher', array(), $relatedDataType);
338
+
339
+			// Default ordering for related data type.
340
+			$defaultOrderings = Tca::table($relatedDataType)->getDefaultOrderings();
341
+			/** @var \Fab\Vidi\Persistence\Order $order */
342
+			$defaultOrder = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Order', $defaultOrderings);
343
+
344
+			// Fetch related contents
345
+			$relatedContents = ContentRepositoryFactory::getInstance($relatedDataType)->findBy($matcher, $defaultOrder);
346
+
347
+			if (Tca::table($dataType)->field($fieldName)->isRenderModeTree()) {
348
+
349
+				$fieldConfiguration = Tca::table($dataType)->field($fieldName)->getConfiguration();
350
+				$parentField = $fieldConfiguration['treeConfig']['parentField'];
351
+
352
+				$flatTree = array();
353
+				foreach ($relatedContents as $node) {
354
+					$flatTree[$node->getUid()] = array(
355
+						'item' => $node,
356
+						'parent' => $node[$parentField] ? $node[$parentField]['uid'] : NULL,
357
+					);
358
+				}
359
+
360
+				$tree = array();
361
+
362
+				// If leaves are selected without its parents selected, those are shown as parent
363
+				foreach ($flatTree as $id => &$flatNode) {
364
+					if (!isset($flatTree[$flatNode['parent']])) {
365
+						$flatNode['parent'] = NULL;
366
+					}
367
+				}
368
+
369
+				foreach ($flatTree as $id => &$node) {
370
+					if ($node['parent'] === NULL) {
371
+						$tree[$id] = &$node;
372
+					} else {
373
+						$flatTree[$node['parent']]['children'][$id] = &$node;
374
+					}
375
+				}
376
+
377
+				$relatedContents = $tree;
378
+			}
379
+
380
+			$this->view->assign('content', $content);
381
+			$this->view->assign('relatedContents', $relatedContents);
382
+			$this->view->assign('relatedDataType', $relatedDataType);
383
+			$this->view->assign('relatedContentTitle', Tca::table($relatedDataType)->getTitle());
384
+			$this->view->assign(
385
+				'renderMode',
386
+				Tca::table($dataType)->field($fieldName)->isRenderModeTree() ? FieldType::TREE : NULL
387
+			);
388
+		}
389
+	}
390
+
391
+	/**
392
+	 * Retrieve Content objects first according to matching criteria and then "delete" them.
393
+	 *
394
+	 * Possible values for $matches, refer to method "updateAction".
395
+	 *
396
+	 * @param array $matches
397
+	 * @return string
398
+	 */
399
+	public function deleteAction(array $matches = array())
400
+	{
401
+
402
+		$matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
403
+
404
+		// Fetch objects via the Content Service.
405
+		$contentService = $this->getContentService()->findBy($matcher);
406
+
407
+		// Compute the label field name of the table.
408
+		$tableTitleField = Tca::table()->getLabelField();
409
+
410
+		// Get result object for storing data along the processing.
411
+		$result = $this->getJsonResult();
412
+		$result->setNumberOfObjects($contentService->getNumberOfObjects());
413
+
414
+		foreach ($contentService->getObjects() as $object) {
415
+
416
+			// Store the first object, so that the delete message can be more explicit when deleting only one record.
417
+			if ($contentService->getNumberOfObjects() === 1) {
418
+				$tableTitleValue = $object[$tableTitleField];
419
+				$processedObjectData = array(
420
+					'uid' => $object->getUid(),
421
+					'name' => $tableTitleValue,
422
+				);
423
+				$result->setProcessedObject($processedObjectData);
424
+			}
425
+
426
+			// Properly delete object.
427
+			ContentRepositoryFactory::getInstance()->remove($object);
428
+
429
+			// Get the possible error messages and store them.
430
+			$errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
431
+			$result->addErrorMessages($errorMessages);
432
+		}
433
+
434
+		// Set the result and render the JSON view.
435
+		$this->getJsonView()->setResult($result);
436
+		return $this->getJsonView()->render();
437
+	}
438
+
439
+	/**
440
+	 * Retrieve Content objects first according to matching criteria and then "copy" them.
441
+	 *
442
+	 * Possible values for $matches, refer to method "updateAction".
443
+	 *
444
+	 * @param string $target
445
+	 * @param array $matches
446
+	 * @throws \Exception
447
+	 * @return string
448
+	 */
449
+	public function copyAction($target, array $matches = array())
450
+	{
451
+		// @todo
452
+		throw new \Exception('Not yet implemented', 1410192546);
453
+	}
454
+
455
+	/**
456
+	 * Retrieve Content objects from the Clipboard then "copy" them according to the target.
457
+	 *
458
+	 * @param string $target
459
+	 * @throws \Exception
460
+	 * @return string
461
+	 */
462
+	public function copyClipboardAction($target)
463
+	{
464
+
465
+		// Retrieve matcher object from clipboard.
466
+		$matcher = $this->getClipboardService()->getMatcher();
467
+
468
+		// Fetch objects via the Content Service.
469
+		$contentService = $this->getContentService()->findBy($matcher);
470
+
471
+		// Compute the label field name of the table.
472
+		$tableTitleField = Tca::table()->getLabelField();
473
+
474
+		// Get result object for storing data along the processing.
475
+		$result = $this->getJsonResult();
476
+		$result->setNumberOfObjects($contentService->getNumberOfObjects());
477
+
478
+		foreach ($contentService->getObjects() as $object) {
479
+
480
+			// Store the first object, so that the "action" message can be more explicit when deleting only one record.
481
+			if ($contentService->getNumberOfObjects() === 1) {
482
+				$tableTitleValue = $object[$tableTitleField];
483
+				$processedObjectData = array(
484
+					'uid' => $object->getUid(),
485
+					'name' => $tableTitleValue,
486
+				);
487
+				$result->setProcessedObject($processedObjectData);
488
+			}
489
+
490
+			// Work out the object.
491
+			ContentRepositoryFactory::getInstance()->copy($object, $target);
492
+
493
+			// Get the possible error messages and store them.
494
+			$errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
495
+			$result->addErrorMessages($errorMessages);
496
+		}
497
+
498
+		// Flush Clipboard if told so.
499
+		if (GeneralUtility::_GP('flushClipboard')) {
500
+			$this->getClipboardService()->flush();
501
+		}
502
+
503
+		// Set the result and render the JSON view.
504
+		$this->getJsonView()->setResult($result);
505
+		return $this->getJsonView()->render();
506
+	}
507
+
508
+	/**
509
+	 * Retrieve Content objects first according to matching criteria and then "move" them.
510
+	 *
511
+	 * Possible values for $matches, refer to method "updateAction".
512
+	 *
513
+	 * @param string $target
514
+	 * @param array $matches
515
+	 * @return string
516
+	 */
517
+	public function moveAction($target, array $matches = array())
518
+	{
519
+
520
+		$matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
521
+
522
+		// Fetch objects via the Content Service.
523
+		$contentService = $this->getContentService()->findBy($matcher);
524
+
525
+		// Compute the label field name of the table.
526
+		$tableTitleField = Tca::table()->getLabelField();
527
+
528
+		// Get result object for storing data along the processing.
529
+		$result = $this->getJsonResult();
530
+		$result->setNumberOfObjects($contentService->getNumberOfObjects());
531
+
532
+		foreach ($contentService->getObjects() as $object) {
533
+
534
+			// Store the first object, so that the "action" message can be more explicit when deleting only one record.
535
+			if ($contentService->getNumberOfObjects() === 1) {
536
+				$tableTitleValue = $object[$tableTitleField];
537
+				$processedObjectData = array(
538
+					'uid' => $object->getUid(),
539
+					'name' => $tableTitleValue,
540
+				);
541
+				$result->setProcessedObject($processedObjectData);
542
+			}
543
+
544
+			// Work out the object.
545
+			ContentRepositoryFactory::getInstance()->move($object, $target);
546
+
547
+			// Get the possible error messages and store them.
548
+			$errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
549
+			$result->addErrorMessages($errorMessages);
550
+		}
551
+
552
+		// Set the result and render the JSON view.
553
+		$this->getJsonView()->setResult($result);
554
+		return $this->getJsonView()->render();
555
+	}
556
+
557
+	/**
558
+	 * Retrieve Content objects from the Clipboard then "move" them according to the target.
559
+	 *
560
+	 * @param string $target
561
+	 * @return string
562
+	 */
563
+	public function moveClipboardAction($target)
564
+	{
565
+
566
+		// Retrieve matcher object from clipboard.
567
+		$matcher = $this->getClipboardService()->getMatcher();
568
+
569
+		// Fetch objects via the Content Service.
570
+		$contentService = $this->getContentService()->findBy($matcher);
571
+
572
+		// Compute the label field name of the table.
573
+		$tableTitleField = Tca::table()->getLabelField();
574
+
575
+		// Get result object for storing data along the processing.
576
+		$result = $this->getJsonResult();
577
+		$result->setNumberOfObjects($contentService->getNumberOfObjects());
578
+
579
+		foreach ($contentService->getObjects() as $object) {
580
+
581
+			// Store the first object, so that the "action" message can be more explicit when deleting only one record.
582
+			if ($contentService->getNumberOfObjects() === 1) {
583
+				$tableTitleValue = $object[$tableTitleField];
584
+				$processedObjectData = array(
585
+					'uid' => $object->getUid(),
586
+					'name' => $tableTitleValue,
587
+				);
588
+				$result->setProcessedObject($processedObjectData);
589
+			}
590
+
591
+			// Work out the object.
592
+			ContentRepositoryFactory::getInstance()->move($object, $target);
593
+
594
+			// Get the possible error messages and store them.
595
+			$errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
596
+			$result->addErrorMessages($errorMessages);
597
+		}
598
+
599
+		// Flush Clipboard if told so.
600
+		if (GeneralUtility::_GP('flushClipboard')) {
601
+			$this->getClipboardService()->flush();
602
+		}
603
+
604
+		// Set the result and render the JSON view.
605
+		$this->getJsonView()->setResult($result);
606
+		return $this->getJsonView()->render();
607
+	}
608
+
609
+	/**
610
+	 * Retrieve Content objects first according to matching criteria and then "localize" them.
611
+	 *
612
+	 * Possible values for $matches, refer to method "updateAction".
613
+	 *
614
+	 * @param string $fieldNameAndPath
615
+	 * @param array $matches
616
+	 * @param int $language
617
+	 * @return string
618
+	 * @throws \Exception
619
+	 */
620
+	public function localizeAction($fieldNameAndPath, array $matches = array(), $language = 0)
621
+	{
622
+
623
+		$matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
624
+
625
+		// Fetch objects via the Content Service.
626
+		$contentService = $this->getContentService()->findBy($matcher);
627
+
628
+		// Get result object for storing data along the processing.
629
+		$result = $this->getJsonResult();
630
+		$result->setNumberOfObjects($contentService->getNumberOfObjects());
631
+
632
+		foreach ($contentService->getObjects() as $object) {
633
+
634
+			$identifier = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, 'uid');
635
+			$dataType = $this->getContentObjectResolver()->getDataType($object, $fieldNameAndPath);
636
+
637
+			// Fetch the source object to be localized.
638
+			/** @var Content $content */
639
+			$content = ContentRepositoryFactory::getInstance($dataType)->findByIdentifier($identifier);
640
+
641
+			// Makes sure the object was retrieved. Security!
642
+			if (!$content) {
643
+				$message = sprintf('Something went wrong when retrieving content "%s" with identifier "%s".', $dataType, $identifier);
644
+				throw new \Exception($message, 1412343097);
645
+			}
646
+
647
+			// Handover the localization to the Repository.
648
+			ContentRepositoryFactory::getInstance($dataType)->localize($content, $language);
649
+
650
+			// Get the possible error messages and store them.
651
+			$errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
652
+
653
+			// Redirect to TCEForm so that the BE User can do its job!
654
+			if ($contentService->getNumberOfObjects() === 1) {
655
+
656
+				if (!empty($errorMessages)) {
657
+					$message = sprintf('Something went wrong when localizing content "%s" with identifier "%s". <br/>%s',
658
+						$dataType,
659
+						$identifier,
660
+						implode('<br/>', $errorMessages)
661
+					);
662
+					throw new \Exception($message, 1412343098);
663
+				}
664
+
665
+				$localizedContent = $this->getLanguageService()->getLocalizedContent($content, $language);
666
+				if (empty($localizedContent)) {
667
+					$message = sprintf('Oups! I could not retrieve localized content of type "%s" with identifier "%s"',
668
+						$content->getDataType(),
669
+						$content->getUid()
670
+					);
671
+					throw new \Exception($message, 1412343099);
672
+				}
673
+
674
+				/** @var \Fab\Vidi\View\Uri\EditUri $uri */
675
+				$uriRenderer = GeneralUtility::makeInstance('Fab\Vidi\View\Uri\EditUri');
676
+				$uri = $uriRenderer->render($localizedContent);
677
+				HttpUtility::redirect($uri);
678
+				break; // no need to further continue
679
+			}
680
+
681
+			$result->addErrorMessages($errorMessages);
682
+		}
683
+
684
+		// Set the result and render the JSON view.
685
+		$this->getJsonView()->setResult($result);
686
+		return $this->getJsonView()->render();
687
+	}
688
+
689
+	/**
690
+	 * Get the Vidi Module Loader.
691
+	 *
692
+	 * @return \Fab\Vidi\Service\ContentService
693
+	 */
694
+	protected function getContentService()
695
+	{
696
+		return GeneralUtility::makeInstance('Fab\Vidi\Service\ContentService');
697
+	}
698
+
699
+	/**
700
+	 * @return \Fab\Vidi\Resolver\ContentObjectResolver
701
+	 */
702
+	protected function getContentObjectResolver()
703
+	{
704
+		return GeneralUtility::makeInstance('Fab\Vidi\Resolver\ContentObjectResolver');
705
+	}
706
+
707
+	/**
708
+	 * @return \Fab\Vidi\Resolver\FieldPathResolver
709
+	 */
710
+	protected function getFieldPathResolver()
711
+	{
712
+		return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
713
+	}
714
+
715
+	/**
716
+	 * Return a special view for handling JSON
717
+	 * Goal is to have this view injected but require more configuration.
718
+	 *
719
+	 * @return JsonView
720
+	 */
721
+	protected function getJsonView()
722
+	{
723
+		if (!$this->view instanceof JsonView) {
724
+			/** @var JsonView $view */
725
+			$this->view = $this->objectManager->get('Fab\Vidi\Mvc\JsonView');
726
+			$this->view->setResponse($this->response);
727
+		}
728
+		return $this->view;
729
+	}
730
+
731
+	/**
732
+	 * @return JsonResult
733
+	 */
734
+	protected function getJsonResult()
735
+	{
736
+		return GeneralUtility::makeInstance('Fab\Vidi\Mvc\JsonResult');
737
+	}
738
+
739
+	/**
740
+	 * Signal that is called for post-processing content data send to the server for update.
741
+	 *
742
+	 * @param Content $contentObject
743
+	 * @param $fieldNameAndPath
744
+	 * @param $contentData
745
+	 * @param $counter
746
+	 * @param $savingBehavior
747
+	 * @param $language
748
+	 * @return ProcessContentDataSignalArguments
749
+	 * @signal
750
+	 */
751
+	protected function emitProcessContentDataSignal(Content $contentObject, $fieldNameAndPath, $contentData, $counter, $savingBehavior, $language)
752
+	{
753
+
754
+		/** @var \Fab\Vidi\Signal\ProcessContentDataSignalArguments $signalArguments */
755
+		$signalArguments = GeneralUtility::makeInstance('Fab\Vidi\Signal\ProcessContentDataSignalArguments');
756
+		$signalArguments->setContentObject($contentObject)
757
+			->setFieldNameAndPath($fieldNameAndPath)
758
+			->setContentData($contentData)
759
+			->setCounter($counter)
760
+			->setSavingBehavior($savingBehavior)
761
+			->setLanguage($language);
762
+
763
+		$signalResult = $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\Controller\Backend\ContentController', 'processContentData', array($signalArguments));
764
+		return $signalResult[0];
765
+	}
766
+
767
+	/**
768
+	 * Get the SignalSlot dispatcher.
769
+	 *
770
+	 * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
771
+	 */
772
+	protected function getSignalSlotDispatcher()
773
+	{
774
+		return $this->objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
775
+	}
776
+
777
+	/**
778
+	 * Get the Clipboard service.
779
+	 *
780
+	 * @return \Fab\Vidi\Service\ClipboardService
781
+	 */
782
+	protected function getClipboardService()
783
+	{
784
+		return GeneralUtility::makeInstance('Fab\Vidi\Service\ClipboardService');
785
+	}
786
+
787
+	/**
788
+	 * @return \Fab\Vidi\Language\LanguageService
789
+	 */
790
+	protected function getLanguageService()
791
+	{
792
+		return GeneralUtility::makeInstance('Fab\Vidi\Language\LanguageService');
793
+	}
794
+
795
+	/**
796
+	 * Get the Vidi Module Loader.
797
+	 *
798
+	 * @return \Fab\Vidi\Module\ModuleLoader
799
+	 */
800
+	protected function getModuleLoader()
801
+	{
802
+		return GeneralUtility::makeInstance('Fab\Vidi\Module\ModuleLoader');
803
+	}
804 804
 
805 805
 }
Please login to merge, or discard this patch.
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
@@ -24,140 +24,140 @@
 block discarded – undo
24 24
 class CoreDataHandler extends AbstractDataHandler
25 25
 {
26 26
 
27
-    /**
28
-     * @var array
29
-     */
30
-    protected $dataHandler;
31
-
32
-    /**
33
-     * Process Content with action "update".
34
-     *
35
-     * @param Content $content
36
-     * @throws \Exception
37
-     * @return bool
38
-     */
39
-    public function processUpdate(Content $content)
40
-    {
41
-
42
-        $values = array();
43
-
44
-        // Check the field to be updated exists
45
-        foreach ($content->toArray() as $fieldName => $value) {
46
-            if (!Tca::table($content->getDataType())->hasField($fieldName)) {
47
-                $message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType());
48
-                throw new \Exception($message, 1390668497);
49
-            }
50
-
51
-            // Flatten value if array given which is required for the DataHandler.
52
-            if (is_array($value)) {
53
-                $value = implode(',', $value);
54
-            }
55
-            $values[$fieldName] = $value;
56
-        }
57
-
58
-        $data[$content->getDataType()][$content->getUid()] = $values;
59
-
60
-        $dataHandler = $this->getDataHandler();
61
-        $dataHandler->start($data, array());
62
-        $dataHandler->process_datamap();
63
-        $this->errorMessages = $dataHandler->errorLog;
64
-
65
-        // Returns TRUE is log does not contain errors.
66
-        return empty($dataHandler->errorLog);
67
-    }
68
-
69
-    /**
70
-     * Process Content with action "remove".
71
-     *
72
-     * @param Content $content
73
-     * @return bool
74
-     */
75
-    public function processRemove(Content $content)
76
-    {
77
-
78
-        // Build command
79
-        $cmd[$content->getDataType()][$content->getUid()]['delete'] = 1;
80
-
81
-        /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
82
-        $dataHandler = $this->getDataHandler();
83
-        $dataHandler->start(array(), $cmd);
84
-        $dataHandler->process_datamap();
85
-        $dataHandler->process_cmdmap();
86
-        $this->errorMessages = $dataHandler->errorLog;
87
-
88
-        // Returns TRUE is log does not contain errors.
89
-        return empty($dataHandler->errorLog);
90
-    }
91
-
92
-    /**
93
-     * Process Content with action "copy".
94
-     *
95
-     * @param Content $content
96
-     * @param string $target
97
-     * @return bool
98
-     */
99
-    public function processCopy(Content $content, $target)
100
-    {
101
-        // TODO: Implement processCopy() method.
102
-    }
103
-
104
-    /**
105
-     * Process Content with action "move".
106
-     * The $target corresponds to the pid to move the records to.
107
-     * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor.
108
-     *
109
-     * @param Content $content
110
-     * @param int $target corresponds
111
-     * @return bool
112
-     */
113
-    public function processMove(Content $content, $target)
114
-    {
115
-
116
-        // Build command
117
-        $cmd[$content->getDataType()][$content->getUid()]['move'] = $target;
118
-
119
-        /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
120
-        $dataHandler = $this->getDataHandler();
121
-        $dataHandler->start(array(), $cmd);
122
-        $dataHandler->process_datamap();
123
-        $dataHandler->process_cmdmap();
124
-        $this->errorMessages = $dataHandler->errorLog;
125
-
126
-        // Returns TRUE is log does not contain errors.
127
-        return empty($dataHandler->errorLog);
128
-    }
129
-
130
-    /**
131
-     * Process Content with action "localize".
132
-     *
133
-     * @param Content $content
134
-     * @param int $language
135
-     * @return bool
136
-     */
137
-    public function processLocalize(Content $content, $language)
138
-    {
139
-
140
-        $command[$content->getDataType()][$content->getUid()]['localize'] = $language;
141
-
142
-        $dataHandler = $this->getDataHandler();
143
-        $dataHandler->start(array(), $command);
144
-        $dataHandler->process_datamap();
145
-        $dataHandler->process_cmdmap();
146
-        $this->errorMessages = $dataHandler->errorLog;
147
-
148
-        // Returns TRUE is log does not contain errors.
149
-        return empty($dataHandler->errorLog);
150
-    }
151
-
152
-    /**
153
-     * @return \TYPO3\CMS\Core\DataHandling\DataHandler
154
-     */
155
-    protected function getDataHandler()
156
-    {
157
-        if (!$this->dataHandler) {
158
-            $this->dataHandler = GeneralUtility::makeInstance('TYPO3\CMS\Core\DataHandling\DataHandler');
159
-        }
160
-        return $this->dataHandler;
161
-    }
27
+	/**
28
+	 * @var array
29
+	 */
30
+	protected $dataHandler;
31
+
32
+	/**
33
+	 * Process Content with action "update".
34
+	 *
35
+	 * @param Content $content
36
+	 * @throws \Exception
37
+	 * @return bool
38
+	 */
39
+	public function processUpdate(Content $content)
40
+	{
41
+
42
+		$values = array();
43
+
44
+		// Check the field to be updated exists
45
+		foreach ($content->toArray() as $fieldName => $value) {
46
+			if (!Tca::table($content->getDataType())->hasField($fieldName)) {
47
+				$message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType());
48
+				throw new \Exception($message, 1390668497);
49
+			}
50
+
51
+			// Flatten value if array given which is required for the DataHandler.
52
+			if (is_array($value)) {
53
+				$value = implode(',', $value);
54
+			}
55
+			$values[$fieldName] = $value;
56
+		}
57
+
58
+		$data[$content->getDataType()][$content->getUid()] = $values;
59
+
60
+		$dataHandler = $this->getDataHandler();
61
+		$dataHandler->start($data, array());
62
+		$dataHandler->process_datamap();
63
+		$this->errorMessages = $dataHandler->errorLog;
64
+
65
+		// Returns TRUE is log does not contain errors.
66
+		return empty($dataHandler->errorLog);
67
+	}
68
+
69
+	/**
70
+	 * Process Content with action "remove".
71
+	 *
72
+	 * @param Content $content
73
+	 * @return bool
74
+	 */
75
+	public function processRemove(Content $content)
76
+	{
77
+
78
+		// Build command
79
+		$cmd[$content->getDataType()][$content->getUid()]['delete'] = 1;
80
+
81
+		/** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
82
+		$dataHandler = $this->getDataHandler();
83
+		$dataHandler->start(array(), $cmd);
84
+		$dataHandler->process_datamap();
85
+		$dataHandler->process_cmdmap();
86
+		$this->errorMessages = $dataHandler->errorLog;
87
+
88
+		// Returns TRUE is log does not contain errors.
89
+		return empty($dataHandler->errorLog);
90
+	}
91
+
92
+	/**
93
+	 * Process Content with action "copy".
94
+	 *
95
+	 * @param Content $content
96
+	 * @param string $target
97
+	 * @return bool
98
+	 */
99
+	public function processCopy(Content $content, $target)
100
+	{
101
+		// TODO: Implement processCopy() method.
102
+	}
103
+
104
+	/**
105
+	 * Process Content with action "move".
106
+	 * The $target corresponds to the pid to move the records to.
107
+	 * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor.
108
+	 *
109
+	 * @param Content $content
110
+	 * @param int $target corresponds
111
+	 * @return bool
112
+	 */
113
+	public function processMove(Content $content, $target)
114
+	{
115
+
116
+		// Build command
117
+		$cmd[$content->getDataType()][$content->getUid()]['move'] = $target;
118
+
119
+		/** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
120
+		$dataHandler = $this->getDataHandler();
121
+		$dataHandler->start(array(), $cmd);
122
+		$dataHandler->process_datamap();
123
+		$dataHandler->process_cmdmap();
124
+		$this->errorMessages = $dataHandler->errorLog;
125
+
126
+		// Returns TRUE is log does not contain errors.
127
+		return empty($dataHandler->errorLog);
128
+	}
129
+
130
+	/**
131
+	 * Process Content with action "localize".
132
+	 *
133
+	 * @param Content $content
134
+	 * @param int $language
135
+	 * @return bool
136
+	 */
137
+	public function processLocalize(Content $content, $language)
138
+	{
139
+
140
+		$command[$content->getDataType()][$content->getUid()]['localize'] = $language;
141
+
142
+		$dataHandler = $this->getDataHandler();
143
+		$dataHandler->start(array(), $command);
144
+		$dataHandler->process_datamap();
145
+		$dataHandler->process_cmdmap();
146
+		$this->errorMessages = $dataHandler->errorLog;
147
+
148
+		// Returns TRUE is log does not contain errors.
149
+		return empty($dataHandler->errorLog);
150
+	}
151
+
152
+	/**
153
+	 * @return \TYPO3\CMS\Core\DataHandling\DataHandler
154
+	 */
155
+	protected function getDataHandler()
156
+	{
157
+		if (!$this->dataHandler) {
158
+			$this->dataHandler = GeneralUtility::makeInstance('TYPO3\CMS\Core\DataHandling\DataHandler');
159
+		}
160
+		return $this->dataHandler;
161
+	}
162 162
 
163 163
 }
Please login to merge, or discard this patch.
Classes/Domain/Model/Content.php 2 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   +436 added lines, -436 removed lines patch added patch discarded remove patch
@@ -29,441 +29,441 @@
 block discarded – undo
29 29
 class Content implements \ArrayAccess
30 30
 {
31 31
 
32
-    /**
33
-     * @var int
34
-     */
35
-    protected $uid;
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    protected $dataType;
41
-
42
-    /**
43
-     * Constructor for a Content object.
44
-     *
45
-     * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ...
46
-     * @param array $contentData
47
-     * @return \Fab\Vidi\Domain\Model\Content
48
-     */
49
-    public function __construct($dataType, array $contentData = array())
50
-    {
51
-
52
-        $this->dataType = $dataType;
53
-        $this->uid = empty($contentData['uid']) ? NULL : (int)$contentData['uid'];
54
-
55
-        /** @var \Fab\Vidi\Tca\TableService $table */
56
-        $table = Tca::table($dataType);
57
-
58
-        // Initialize the array containing the allowed fields to be filled-in.
59
-        $fields = array('pid');
60
-
61
-        // If a creation time stamp has been defined for this data type.
62
-        if ($table->getTimeCreationField()) {
63
-            $fields[] = $table->getTimeCreationField();
64
-        }
65
-
66
-        // If an update time stamp has been defined for this data type.
67
-        if ($table->getTimeModificationField()) {
68
-            $fields[] = $table->getTimeModificationField();
69
-        }
70
-
71
-        // Merge the other fields allowed for this data type.
72
-        $fields = array_merge($fields, $table->getFields());
73
-
74
-        // Fetch excluded fields from the grid.
75
-        if ($this->isBackendMode()) {
76
-            $fields = $this->filterForConfiguration($fields);
77
-            $fields = $this->filterForBackendUser($fields);
78
-        }
79
-
80
-        // Get column to be displayed
81
-        foreach ($fields as $fieldName) {
82
-            if (array_key_exists($fieldName, $contentData)) {
83
-                $propertyName = Field::name($fieldName)->of($dataType)->toPropertyName();
84
-                $this->$propertyName = $contentData[$fieldName];
85
-            }
86
-        }
87
-    }
88
-
89
-    /**
90
-     * Dispatches magic methods (findBy[Property]())
91
-     *
92
-     * @param string $methodName The name of the magic method
93
-     * @param string $arguments The arguments of the magic method
94
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException
95
-     * @return mixed
96
-     * @api
97
-     */
98
-    public function __call($methodName, $arguments)
99
-    {
100
-        $value = NULL;
101
-        if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
102
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
103
-
104
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
105
-            $field = Tca::table($this->dataType)->field($fieldName);
106
-
107
-            $value = $this->$propertyName;
108
-
109
-            // TRUE means it is a relation and it is not yet resolved.
110
-            if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) {
111
-                $value = $this->resolveRelation($propertyName);
112
-            } elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) {
113
-
114
-                // Attempt to convert the value into a label for radio and select fields.
115
-                $label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value);
116
-                if ($label) {
117
-                    $value = $label;
118
-                }
119
-            }
120
-
121
-        } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
122
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
123
-            $this->$propertyName = $arguments[0];
124
-        }
125
-        return $value;
126
-    }
127
-
128
-    /**
129
-     * Tell whether the property has a relation.
130
-     *
131
-     * @param string $propertyName
132
-     * @return bool
133
-     */
134
-    protected function hasRelation($propertyName)
135
-    {
136
-        $fieldName = Property::name($propertyName)->of($this)->toFieldName();
137
-        return Tca::table($this->dataType)->field($fieldName)->hasRelation();
138
-    }
139
-
140
-    /**
141
-     * Try to "resolve" the property whether it has a relation.
142
-     * If the property has not relation it simply returns the same value.
143
-     *
144
-     * @throws \RuntimeException
145
-     * @param string $propertyName
146
-     * @return mixed
147
-     */
148
-    protected function resolveRelation($propertyName)
149
-    {
150
-
151
-        // Convert property name to field name and get the foreign data type.
152
-        $fieldName = Property::name($propertyName)->of($this)->toFieldName();
153
-        $foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType();
154
-
155
-        // Get the foreign repository instance form the factory
156
-        /** @var \Fab\Vidi\Domain\Repository\ContentRepository $foreignContentRepository */
157
-        $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName);
158
-
159
-        if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
160
-
161
-            // Fetch values from repository
162
-            $values = GeneralUtility::trimExplode(',', $this->$propertyName);
163
-            $this->$propertyName = $foreignContentRepository->findIn('uid', $values);
164
-        } elseif (Tca::table($this->dataType)->field($fieldName)->hasMany()) {
165
-            // Include relation many-to-many and one-to-many
166
-            // Tca::table($this->dataType)->field($fieldName)->hasRelationOneToMany()
167
-            // Tca::table($this->dataType)->field($fieldName)->hasRelationManyToMany()
168
-
169
-            $foreignFieldName = Tca::table($this->dataType)->field($fieldName)->getForeignField();
170
-            if (empty($foreignFieldName)) {
171
-                $message = sprintf('Missing "foreign_field" key for field "%s" in table "%s".',
172
-                    $fieldName,
173
-                    $this->dataType
174
-                );
175
-                throw new \RuntimeException($message, 1376149186);
176
-            }
177
-
178
-            // Fetch values from repository.
179
-            $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
180
-            $findByProperty = 'findBy' . ucfirst($foreignPropertyName);
181
-
182
-            // Date picker (type == group) are special fields because property path must contain the table name
183
-            // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
184
-            $propertyValue = $this->uid;
185
-            if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
186
-                $propertyValue = $this->dataType . '.' . $this->uid;
187
-            }
188
-
189
-            $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
190
-
191
-        } elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) {
192
-
193
-            $fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration();
194
-
195
-            // First case, we are on the "good side" of the relation, just query the repository
196
-            if (empty($fieldConfiguration['foreign_field'])) {
197
-                $this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName);
198
-            } else {
199
-                // Second case, we are the "bad side" of the relation, query the foreign repository
200
-                // e.g. in case of one-to-one relation.
201
-
202
-                // We must query the opposite side to get the identifier of the foreign object.
203
-                $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
204
-                $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
205
-                $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
206
-                $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
207
-
208
-                /** @var Content $foreignObject */
209
-                $this->$propertyName = $foreignContentRepository->$find($this->getUid());
210
-            }
211
-
212
-        }
213
-        return $this->$propertyName;
214
-    }
215
-
216
-    /**
217
-     * @return int
218
-     */
219
-    public function getUid()
220
-    {
221
-        return $this->uid;
222
-    }
223
-
224
-    /**
225
-     * @return string
226
-     */
227
-    public function getDataType()
228
-    {
229
-        return $this->dataType;
230
-    }
231
-
232
-    /**
233
-     * Whether a offset exists
234
-     *
235
-     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
236
-     * @param mixed $offset
237
-     * @return boolean true on success or false on failure.
238
-     */
239
-    public function offsetExists($offset)
240
-    {
241
-        $offset = Field::name($offset)->of($this)->toPropertyName();
242
-        return isset($this->$offset);
243
-    }
244
-
245
-    /**
246
-     * Offset to retrieve
247
-     *
248
-     * @link http://php.net/manual/en/arrayaccess.offsetget.php
249
-     * @param mixed $offset
250
-     * @return mixed Can return all value types.
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
-     */
267
-    public function offsetSet($offset, $value)
268
-    {
269
-        $offset = Field::name($offset)->of($this)->toPropertyName();
270
-        $setter = 'set' . ucfirst($offset);
271
-        $this->$setter($value);
272
-        return $this;
273
-    }
274
-
275
-    /**
276
-     * Offset to unset
277
-     *
278
-     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
279
-     * @param mixed $offset
280
-     * @throws NotImplementedException
281
-     * @return void
282
-     */
283
-    public function offsetUnset($offset)
284
-    {
285
-        $message = 'Un-setting value for Array object is not supported';
286
-        throw new NotImplementedException($message, 1376132306);
287
-    }
288
-
289
-    /**
290
-     * Convert this to array
291
-     *
292
-     * @return array
293
-     */
294
-    public function toArray()
295
-    {
296
-        $result['uid'] = $this->uid;
297
-        $propertiesAndValues = json_decode(json_encode($this), TRUE);
298
-
299
-        foreach ($propertiesAndValues as $propertyName => $value) {
300
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
301
-            $result[$fieldName] = $value;
302
-        }
303
-
304
-        return $result;
305
-    }
306
-
307
-    /**
308
-     * Convert this object to an array containing the resolved values.
309
-     *
310
-     * @param bool $resolveRelations
311
-     * @return array
312
-     * @throws \Exception
313
-     */
314
-    public function toValues($resolveRelations = TRUE)
315
-    {
316
-        $result['uid'] = $this->uid;
317
-        $propertiesAndValues = json_decode(json_encode($this), TRUE);
318
-
319
-        foreach ($propertiesAndValues as $propertyName => $value) {
320
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
321
-
322
-            $result[$fieldName] = $value;
323
-            if ($resolveRelations) {
324
-                $field = Tca::table($this->dataType)->field($fieldName);
325
-
326
-                $resolvedValue = '';
327
-                if ($field->getType() === FieldType::FILE) {
328
-
329
-                    if ($field->hasMany()) {
330
-                        $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
331
-
332
-                        $resolvedValue = array();
333
-                        foreach ($files as $file) {
334
-                            $resolvedValue[] = $file->getIdentifier();
335
-                        }
336
-                    } else {
337
-                        $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
338
-                        if (!empty($files)) {
339
-                            $resolvedValue = current($files)->getIdentifier();
340
-                        }
341
-                    }
342
-
343
-                    // Reset value
344
-                    $result[$fieldName] = $resolvedValue;
345
-
346
-                } elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) {
347
-                    $objects = $this[$fieldName];
348
-                    if (is_array($objects)) {
349
-                        $resolvedValue = array();
350
-                        foreach ($objects as $object) {
351
-                            /** @var $object Content */
352
-                            $labelField = Tca::table($object->getDataType())->getLabelField();
353
-                            $resolvedValue[] = $object[$labelField];
354
-                        }
355
-                    } elseif ($objects instanceof Content) {
356
-                        $labelField = Tca::table($objects->getDataType())->getLabelField();
357
-                        $resolvedValue = $objects[$labelField];
358
-                    }
359
-
360
-                    // Reset value
361
-                    $result[$fieldName] = $resolvedValue;
362
-                }
363
-            }
364
-        }
365
-
366
-        return $result;
367
-    }
368
-
369
-    /**
370
-     * Return the properties of this object.
371
-     *
372
-     * @return array
373
-     */
374
-    public function toProperties()
375
-    {
376
-        $result[] = 'uid';
377
-        $propertiesAndValues = json_decode(json_encode($this), TRUE);
378
-
379
-        foreach ($propertiesAndValues as $propertyName => $value) {
380
-            $result[] = $propertyName;
381
-        }
382
-        return $result;
383
-    }
384
-
385
-    /**
386
-     * Return the properties of this object.
387
-     *
388
-     * @return array
389
-     */
390
-    public function toFields()
391
-    {
392
-        $result[] = 'uid';
393
-        $propertiesAndValues = json_decode(json_encode($this), TRUE);
394
-
395
-        foreach ($propertiesAndValues as $propertyName => $value) {
396
-            $result[] = Property::name($propertyName)->of($this)->toFieldName();
397
-        }
398
-
399
-        return $result;
400
-    }
401
-
402
-    /**
403
-     * @return string
404
-     */
405
-    public function __toString()
406
-    {
407
-        $labelField = Tca::table($this->dataType)->getLabelField();
408
-        return $this[$labelField];
409
-    }
410
-
411
-    /**
412
-     * Remove fields according to BE User permission.
413
-     *
414
-     * @param $fields
415
-     * @return array
416
-     * @throws \Exception
417
-     */
418
-    protected function filterForBackendUser($fields)
419
-    {
420
-        if (!$this->getBackendUser()->isAdmin()) {
421
-            foreach ($fields as $key => $fieldName) {
422
-                if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) {
423
-                    unset($fields[$key]);
424
-                }
425
-            }
426
-        }
427
-        return $fields;
428
-    }
429
-
430
-    /**
431
-     * Remove fields according to Grid configuration.
432
-     *
433
-     * @param $fields
434
-     * @return array
435
-     */
436
-    protected function filterForConfiguration($fields)
437
-    {
438
-
439
-        $excludedFields = Tca::grid($this->dataType)->getExcludedFields();
440
-        foreach ($fields as $key => $field) {
441
-            if (in_array($field, $excludedFields)) {
442
-                unset($fields[$key]);
443
-            }
444
-        }
445
-
446
-        return $fields;
447
-    }
448
-
449
-    /**
450
-     * Returns an instance of the current Backend User.
451
-     *
452
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
453
-     */
454
-    protected function getBackendUser()
455
-    {
456
-        return $GLOBALS['BE_USER'];
457
-    }
458
-
459
-    /**
460
-     * Returns whether the current mode is Backend
461
-     *
462
-     * @return bool
463
-     */
464
-    protected function isBackendMode()
465
-    {
466
-        return TYPO3_MODE == 'BE';
467
-    }
32
+	/**
33
+	 * @var int
34
+	 */
35
+	protected $uid;
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	protected $dataType;
41
+
42
+	/**
43
+	 * Constructor for a Content object.
44
+	 *
45
+	 * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ...
46
+	 * @param array $contentData
47
+	 * @return \Fab\Vidi\Domain\Model\Content
48
+	 */
49
+	public function __construct($dataType, array $contentData = array())
50
+	{
51
+
52
+		$this->dataType = $dataType;
53
+		$this->uid = empty($contentData['uid']) ? NULL : (int)$contentData['uid'];
54
+
55
+		/** @var \Fab\Vidi\Tca\TableService $table */
56
+		$table = Tca::table($dataType);
57
+
58
+		// Initialize the array containing the allowed fields to be filled-in.
59
+		$fields = array('pid');
60
+
61
+		// If a creation time stamp has been defined for this data type.
62
+		if ($table->getTimeCreationField()) {
63
+			$fields[] = $table->getTimeCreationField();
64
+		}
65
+
66
+		// If an update time stamp has been defined for this data type.
67
+		if ($table->getTimeModificationField()) {
68
+			$fields[] = $table->getTimeModificationField();
69
+		}
70
+
71
+		// Merge the other fields allowed for this data type.
72
+		$fields = array_merge($fields, $table->getFields());
73
+
74
+		// Fetch excluded fields from the grid.
75
+		if ($this->isBackendMode()) {
76
+			$fields = $this->filterForConfiguration($fields);
77
+			$fields = $this->filterForBackendUser($fields);
78
+		}
79
+
80
+		// Get column to be displayed
81
+		foreach ($fields as $fieldName) {
82
+			if (array_key_exists($fieldName, $contentData)) {
83
+				$propertyName = Field::name($fieldName)->of($dataType)->toPropertyName();
84
+				$this->$propertyName = $contentData[$fieldName];
85
+			}
86
+		}
87
+	}
88
+
89
+	/**
90
+	 * Dispatches magic methods (findBy[Property]())
91
+	 *
92
+	 * @param string $methodName The name of the magic method
93
+	 * @param string $arguments The arguments of the magic method
94
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException
95
+	 * @return mixed
96
+	 * @api
97
+	 */
98
+	public function __call($methodName, $arguments)
99
+	{
100
+		$value = NULL;
101
+		if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
102
+			$propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
103
+
104
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
105
+			$field = Tca::table($this->dataType)->field($fieldName);
106
+
107
+			$value = $this->$propertyName;
108
+
109
+			// TRUE means it is a relation and it is not yet resolved.
110
+			if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) {
111
+				$value = $this->resolveRelation($propertyName);
112
+			} elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) {
113
+
114
+				// Attempt to convert the value into a label for radio and select fields.
115
+				$label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value);
116
+				if ($label) {
117
+					$value = $label;
118
+				}
119
+			}
120
+
121
+		} elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
122
+			$propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
123
+			$this->$propertyName = $arguments[0];
124
+		}
125
+		return $value;
126
+	}
127
+
128
+	/**
129
+	 * Tell whether the property has a relation.
130
+	 *
131
+	 * @param string $propertyName
132
+	 * @return bool
133
+	 */
134
+	protected function hasRelation($propertyName)
135
+	{
136
+		$fieldName = Property::name($propertyName)->of($this)->toFieldName();
137
+		return Tca::table($this->dataType)->field($fieldName)->hasRelation();
138
+	}
139
+
140
+	/**
141
+	 * Try to "resolve" the property whether it has a relation.
142
+	 * If the property has not relation it simply returns the same value.
143
+	 *
144
+	 * @throws \RuntimeException
145
+	 * @param string $propertyName
146
+	 * @return mixed
147
+	 */
148
+	protected function resolveRelation($propertyName)
149
+	{
150
+
151
+		// Convert property name to field name and get the foreign data type.
152
+		$fieldName = Property::name($propertyName)->of($this)->toFieldName();
153
+		$foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType();
154
+
155
+		// Get the foreign repository instance form the factory
156
+		/** @var \Fab\Vidi\Domain\Repository\ContentRepository $foreignContentRepository */
157
+		$foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName);
158
+
159
+		if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
160
+
161
+			// Fetch values from repository
162
+			$values = GeneralUtility::trimExplode(',', $this->$propertyName);
163
+			$this->$propertyName = $foreignContentRepository->findIn('uid', $values);
164
+		} elseif (Tca::table($this->dataType)->field($fieldName)->hasMany()) {
165
+			// Include relation many-to-many and one-to-many
166
+			// Tca::table($this->dataType)->field($fieldName)->hasRelationOneToMany()
167
+			// Tca::table($this->dataType)->field($fieldName)->hasRelationManyToMany()
168
+
169
+			$foreignFieldName = Tca::table($this->dataType)->field($fieldName)->getForeignField();
170
+			if (empty($foreignFieldName)) {
171
+				$message = sprintf('Missing "foreign_field" key for field "%s" in table "%s".',
172
+					$fieldName,
173
+					$this->dataType
174
+				);
175
+				throw new \RuntimeException($message, 1376149186);
176
+			}
177
+
178
+			// Fetch values from repository.
179
+			$foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
180
+			$findByProperty = 'findBy' . ucfirst($foreignPropertyName);
181
+
182
+			// Date picker (type == group) are special fields because property path must contain the table name
183
+			// to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
184
+			$propertyValue = $this->uid;
185
+			if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
186
+				$propertyValue = $this->dataType . '.' . $this->uid;
187
+			}
188
+
189
+			$this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
190
+
191
+		} elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) {
192
+
193
+			$fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration();
194
+
195
+			// First case, we are on the "good side" of the relation, just query the repository
196
+			if (empty($fieldConfiguration['foreign_field'])) {
197
+				$this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName);
198
+			} else {
199
+				// Second case, we are the "bad side" of the relation, query the foreign repository
200
+				// e.g. in case of one-to-one relation.
201
+
202
+				// We must query the opposite side to get the identifier of the foreign object.
203
+				$foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
204
+				$foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
205
+				$foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
206
+				$find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
207
+
208
+				/** @var Content $foreignObject */
209
+				$this->$propertyName = $foreignContentRepository->$find($this->getUid());
210
+			}
211
+
212
+		}
213
+		return $this->$propertyName;
214
+	}
215
+
216
+	/**
217
+	 * @return int
218
+	 */
219
+	public function getUid()
220
+	{
221
+		return $this->uid;
222
+	}
223
+
224
+	/**
225
+	 * @return string
226
+	 */
227
+	public function getDataType()
228
+	{
229
+		return $this->dataType;
230
+	}
231
+
232
+	/**
233
+	 * Whether a offset exists
234
+	 *
235
+	 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
236
+	 * @param mixed $offset
237
+	 * @return boolean true on success or false on failure.
238
+	 */
239
+	public function offsetExists($offset)
240
+	{
241
+		$offset = Field::name($offset)->of($this)->toPropertyName();
242
+		return isset($this->$offset);
243
+	}
244
+
245
+	/**
246
+	 * Offset to retrieve
247
+	 *
248
+	 * @link http://php.net/manual/en/arrayaccess.offsetget.php
249
+	 * @param mixed $offset
250
+	 * @return mixed Can return all value types.
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
+	 */
267
+	public function offsetSet($offset, $value)
268
+	{
269
+		$offset = Field::name($offset)->of($this)->toPropertyName();
270
+		$setter = 'set' . ucfirst($offset);
271
+		$this->$setter($value);
272
+		return $this;
273
+	}
274
+
275
+	/**
276
+	 * Offset to unset
277
+	 *
278
+	 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
279
+	 * @param mixed $offset
280
+	 * @throws NotImplementedException
281
+	 * @return void
282
+	 */
283
+	public function offsetUnset($offset)
284
+	{
285
+		$message = 'Un-setting value for Array object is not supported';
286
+		throw new NotImplementedException($message, 1376132306);
287
+	}
288
+
289
+	/**
290
+	 * Convert this to array
291
+	 *
292
+	 * @return array
293
+	 */
294
+	public function toArray()
295
+	{
296
+		$result['uid'] = $this->uid;
297
+		$propertiesAndValues = json_decode(json_encode($this), TRUE);
298
+
299
+		foreach ($propertiesAndValues as $propertyName => $value) {
300
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
301
+			$result[$fieldName] = $value;
302
+		}
303
+
304
+		return $result;
305
+	}
306
+
307
+	/**
308
+	 * Convert this object to an array containing the resolved values.
309
+	 *
310
+	 * @param bool $resolveRelations
311
+	 * @return array
312
+	 * @throws \Exception
313
+	 */
314
+	public function toValues($resolveRelations = TRUE)
315
+	{
316
+		$result['uid'] = $this->uid;
317
+		$propertiesAndValues = json_decode(json_encode($this), TRUE);
318
+
319
+		foreach ($propertiesAndValues as $propertyName => $value) {
320
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
321
+
322
+			$result[$fieldName] = $value;
323
+			if ($resolveRelations) {
324
+				$field = Tca::table($this->dataType)->field($fieldName);
325
+
326
+				$resolvedValue = '';
327
+				if ($field->getType() === FieldType::FILE) {
328
+
329
+					if ($field->hasMany()) {
330
+						$files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
331
+
332
+						$resolvedValue = array();
333
+						foreach ($files as $file) {
334
+							$resolvedValue[] = $file->getIdentifier();
335
+						}
336
+					} else {
337
+						$files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
338
+						if (!empty($files)) {
339
+							$resolvedValue = current($files)->getIdentifier();
340
+						}
341
+					}
342
+
343
+					// Reset value
344
+					$result[$fieldName] = $resolvedValue;
345
+
346
+				} elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) {
347
+					$objects = $this[$fieldName];
348
+					if (is_array($objects)) {
349
+						$resolvedValue = array();
350
+						foreach ($objects as $object) {
351
+							/** @var $object Content */
352
+							$labelField = Tca::table($object->getDataType())->getLabelField();
353
+							$resolvedValue[] = $object[$labelField];
354
+						}
355
+					} elseif ($objects instanceof Content) {
356
+						$labelField = Tca::table($objects->getDataType())->getLabelField();
357
+						$resolvedValue = $objects[$labelField];
358
+					}
359
+
360
+					// Reset value
361
+					$result[$fieldName] = $resolvedValue;
362
+				}
363
+			}
364
+		}
365
+
366
+		return $result;
367
+	}
368
+
369
+	/**
370
+	 * Return the properties of this object.
371
+	 *
372
+	 * @return array
373
+	 */
374
+	public function toProperties()
375
+	{
376
+		$result[] = 'uid';
377
+		$propertiesAndValues = json_decode(json_encode($this), TRUE);
378
+
379
+		foreach ($propertiesAndValues as $propertyName => $value) {
380
+			$result[] = $propertyName;
381
+		}
382
+		return $result;
383
+	}
384
+
385
+	/**
386
+	 * Return the properties of this object.
387
+	 *
388
+	 * @return array
389
+	 */
390
+	public function toFields()
391
+	{
392
+		$result[] = 'uid';
393
+		$propertiesAndValues = json_decode(json_encode($this), TRUE);
394
+
395
+		foreach ($propertiesAndValues as $propertyName => $value) {
396
+			$result[] = Property::name($propertyName)->of($this)->toFieldName();
397
+		}
398
+
399
+		return $result;
400
+	}
401
+
402
+	/**
403
+	 * @return string
404
+	 */
405
+	public function __toString()
406
+	{
407
+		$labelField = Tca::table($this->dataType)->getLabelField();
408
+		return $this[$labelField];
409
+	}
410
+
411
+	/**
412
+	 * Remove fields according to BE User permission.
413
+	 *
414
+	 * @param $fields
415
+	 * @return array
416
+	 * @throws \Exception
417
+	 */
418
+	protected function filterForBackendUser($fields)
419
+	{
420
+		if (!$this->getBackendUser()->isAdmin()) {
421
+			foreach ($fields as $key => $fieldName) {
422
+				if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) {
423
+					unset($fields[$key]);
424
+				}
425
+			}
426
+		}
427
+		return $fields;
428
+	}
429
+
430
+	/**
431
+	 * Remove fields according to Grid configuration.
432
+	 *
433
+	 * @param $fields
434
+	 * @return array
435
+	 */
436
+	protected function filterForConfiguration($fields)
437
+	{
438
+
439
+		$excludedFields = Tca::grid($this->dataType)->getExcludedFields();
440
+		foreach ($fields as $key => $field) {
441
+			if (in_array($field, $excludedFields)) {
442
+				unset($fields[$key]);
443
+			}
444
+		}
445
+
446
+		return $fields;
447
+	}
448
+
449
+	/**
450
+	 * Returns an instance of the current Backend User.
451
+	 *
452
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
453
+	 */
454
+	protected function getBackendUser()
455
+	{
456
+		return $GLOBALS['BE_USER'];
457
+	}
458
+
459
+	/**
460
+	 * Returns whether the current mode is Backend
461
+	 *
462
+	 * @return bool
463
+	 */
464
+	protected function isBackendMode()
465
+	{
466
+		return TYPO3_MODE == 'BE';
467
+	}
468 468
 
469 469
 }
Please login to merge, or discard this patch.
Classes/Domain/Repository/ContentRepository.php 2 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      * Update a content with new information.
272 272
      *
273 273
      * @param Content $content
274
-     * @param $language
274
+     * @param integer $language
275 275
      * @return bool
276 276
      */
277 277
     public function localize($content, $language)
@@ -352,6 +352,7 @@  discard block
 block discarded – undo
352 352
      * Copy a content within this repository.
353 353
      *
354 354
      * @param Content $content
355
+     * @param string $target
355 356
      * @return bool
356 357
      */
357 358
     public function copy($content, $target)
@@ -504,7 +505,7 @@  discard block
 block discarded – undo
504 505
     /**
505 506
      * Sets the default query settings to be used in this repository
506 507
      *
507
-     * @param QuerySettingsInterface $defaultQuerySettings The query settings to be used by default
508
+     * @param \Fab\Vidi\Persistence\QuerySettings $defaultQuerySettings The query settings to be used by default
508 509
      * @throws \BadMethodCallException
509 510
      * @return void
510 511
      * @api
Please login to merge, or discard this patch.
Indentation   +819 added lines, -819 removed lines patch added patch discarded remove patch
@@ -34,824 +34,824 @@
 block discarded – undo
34 34
 class ContentRepository implements RepositoryInterface
35 35
 {
36 36
 
37
-    /**
38
-     * Tell whether it is a raw result (array) or object being returned.
39
-     *
40
-     * @var bool
41
-     */
42
-    protected $rawResult = FALSE;
43
-
44
-    /**
45
-     * The data type to be returned, e.g fe_users, fe_groups, tt_content, etc...
46
-     *
47
-     * @var string
48
-     */
49
-    protected $dataType;
50
-
51
-    /**
52
-     * The source field is useful in the context of MM relations to know who is the caller
53
-     * e.g findByItems which eventually corresponds to a field name.
54
-     *
55
-     * @var string
56
-     */
57
-    protected $sourceFieldName = '';
58
-
59
-    /**
60
-     * @var array
61
-     */
62
-    protected $errorMessages = array();
63
-
64
-    /**
65
-     * @var QuerySettingsInterface
66
-     */
67
-    protected $defaultQuerySettings;
68
-
69
-    /**
70
-     * Constructor
71
-     *
72
-     * @param string $dataType
73
-     */
74
-    public function __construct($dataType)
75
-    {
76
-        $this->dataType = $dataType;
77
-    }
78
-
79
-    /**
80
-     * Returns all objects of this repository.
81
-     *
82
-     * @return Content[]
83
-     */
84
-    public function findAll()
85
-    {
86
-        $query = $this->createQuery();
87
-        return $query->execute();
88
-    }
89
-
90
-    /**
91
-     * Returns all "distinct" values for a given property.
92
-     *
93
-     * @param string $propertyName
94
-     * @param Matcher $matcher
95
-     * @return Content[]
96
-     */
97
-    public function findDistinctValues($propertyName, Matcher $matcher = NULL)
98
-    {
99
-        $query = $this->createQuery();
100
-        $query->setDistinct($propertyName);
101
-
102
-        // Remove empty values from selection.
103
-        $constraint = $query->logicalNot($query->equals($propertyName, ''));
104
-
105
-        // Add some additional constraints from the Matcher object.
106
-        $matcherConstraint = NULL;
107
-        if (!is_null($matcher)) {
108
-            $matcherConstraint = $this->computeConstraints($query, $matcher);
109
-        }
110
-
111
-        // Assemble the final constraints or not.
112
-        if ($matcherConstraint) {
113
-            $query->logicalAnd($matcherConstraint, $constraint);
114
-            $query->matching($query->logicalAnd($matcherConstraint, $constraint));
115
-        } else {
116
-            $query->matching($constraint);
117
-        }
118
-
119
-        return $query->execute();
120
-    }
121
-
122
-    /**
123
-     * Returns all "distinct" values for a given property.
124
-     *
125
-     * @param string $propertyName
126
-     * @param Matcher $matcher
127
-     * @return int
128
-     */
129
-    public function countDistinctValues($propertyName, Matcher $matcher = NULL)
130
-    {
131
-        $query = $this->createQuery();
132
-        $query->setDistinct($propertyName);
133
-
134
-        // Remove empty values from selection.
135
-        $constraint = $query->logicalNot($query->equals($propertyName, ''));
136
-
137
-        // Add some additional constraints from the Matcher object.
138
-        $matcherConstraint = NULL;
139
-        if (!is_null($matcher)) {
140
-            $matcherConstraint = $this->computeConstraints($query, $matcher);
141
-        }
142
-
143
-        // Assemble the final constraints or not.
144
-        if ($matcherConstraint) {
145
-            $query->logicalAnd($matcherConstraint, $constraint);
146
-            $query->matching($query->logicalAnd($matcherConstraint, $constraint));
147
-        } else {
148
-            $query->matching($constraint);
149
-        }
150
-
151
-        return $query->count();
152
-    }
153
-
154
-    /**
155
-     * Finds an object matching the given identifier.
156
-     *
157
-     * @param int $uid The identifier of the object to find
158
-     * @return Content|NULL
159
-     * @api
160
-     */
161
-    public function findByUid($uid)
162
-    {
163
-        return $this->findByIdentifier($uid);
164
-    }
165
-
166
-    /**
167
-     * Finds all Contents given specified matches.
168
-     *
169
-     * @param string $propertyName
170
-     * @param array $values
171
-     * @return Content[]
172
-     */
173
-    public function findIn($propertyName, array $values)
174
-    {
175
-        $query = $this->createQuery();
176
-        $query->matching($query->in($propertyName, $values));
177
-        return $query->execute();
178
-    }
179
-
180
-    /**
181
-     * Finds all Contents given specified matches.
182
-     *
183
-     * @param Matcher $matcher
184
-     * @param Order $order The order
185
-     * @param int $limit
186
-     * @param int $offset
187
-     * @return Content[]
188
-     */
189
-    public function findBy(Matcher $matcher, Order $order = NULL, $limit = NULL, $offset = NULL)
190
-    {
191
-
192
-        $query = $this->createQuery();
193
-
194
-        if ($limit) {
195
-            $query->setLimit($limit);
196
-        }
197
-
198
-        if ($order) {
199
-            $query->setOrderings($order->getOrderings());
200
-
201
-            // Loops around the orderings adding if necessary a dummy condition
202
-            // to make sure the relations can be resolved when transforming the query to plain SQL.
203
-            foreach ($order->getOrderings() as $ordering => $direction) {
204
-                if ($this->hasForeignRelationIn($ordering)) {
205
-                    $relationalField = $this->getForeignRelationFrom($ordering);
206
-                    $matcher->like($relationalField . '.uid', '');
207
-                }
208
-            }
209
-        }
210
-
211
-        if ($offset) {
212
-            $query->setOffset($offset);
213
-        }
214
-
215
-        $constraints = $this->computeConstraints($query, $matcher);
216
-
217
-        if ($constraints) {
218
-            $query->matching($constraints);
219
-        }
220
-
221
-        return $query->execute();
222
-    }
223
-
224
-    /**
225
-     * Find one Content object given specified matches.
226
-     *
227
-     * @param Matcher $matcher
228
-     * @return Content
229
-     */
230
-    public function findOneBy(Matcher $matcher)
231
-    {
232
-
233
-        $query = $this->createQuery();
234
-
235
-        $constraints = $this->computeConstraints($query, $matcher);
236
-
237
-        if ($constraints) {
238
-            $query->matching($constraints);
239
-        }
240
-
241
-        $query->setLimit(1); // only take one!
242
-
243
-        $resultSet = $query->execute();
244
-        if ($resultSet) {
245
-            $resultSet = current($resultSet);
246
-        }
247
-        return $resultSet;
248
-    }
249
-
250
-    /**
251
-     * Count all Contents given specified matches.
252
-     *
253
-     * @param Matcher $matcher
254
-     * @return int
255
-     */
256
-    public function countBy(Matcher $matcher)
257
-    {
258
-
259
-        $query = $this->createQuery();
260
-
261
-        $constraints = $this->computeConstraints($query, $matcher);
262
-
263
-        if ($constraints) {
264
-            $query->matching($constraints);
265
-        }
266
-
267
-        return $query->count();
268
-    }
269
-
270
-    /**
271
-     * Update a content with new information.
272
-     *
273
-     * @param Content $content
274
-     * @param $language
275
-     * @return bool
276
-     */
277
-    public function localize($content, $language)
278
-    {
279
-
280
-        // Security check
281
-        $this->getContentValidator()->validate($content);
282
-        $this->getLanguageValidator()->validate($language);
283
-
284
-        $dataType = $content->getDataType();
285
-        $handler = $this->getDataHandlerFactory()->action(ProcessAction::LOCALIZE)->forType($dataType)->getDataHandler();
286
-
287
-        $handlerResult = $handler->processLocalize($content, $language);
288
-        $this->errorMessages = $handler->getErrorMessages();
289
-        return $handlerResult;
290
-    }
291
-
292
-    /**
293
-     * Update a content with new information.
294
-     *
295
-     * @param Content $content
296
-     * @return bool
297
-     */
298
-    public function update($content)
299
-    {
300
-
301
-        // Security check.
302
-        $this->getContentValidator()->validate($content);
303
-
304
-        $dataType = $content->getDataType();
305
-        $handler = $this->getDataHandlerFactory()->action(ProcessAction::UPDATE)->forType($dataType)->getDataHandler();
306
-
307
-        $handlerResult = $handler->processUpdate($content);
308
-        $this->errorMessages = $handler->getErrorMessages();
309
-        return $handlerResult;
310
-    }
311
-
312
-    /**
313
-     * Removes an object from this repository.
314
-     *
315
-     * @param Content $content
316
-     * @return boolean
317
-     */
318
-    public function remove($content)
319
-    {
320
-        $dataType = $content->getDataType();
321
-        $handler = $this->getDataHandlerFactory()->action(ProcessAction::REMOVE)->forType($dataType)->getDataHandler();
322
-
323
-        $handlerResult = $handler->processRemove($content);
324
-        $this->errorMessages = $handler->getErrorMessages();
325
-        return $handlerResult;
326
-    }
327
-
328
-    /**
329
-     * Move a content within this repository.
330
-     * The $target corresponds to the pid to move the records to.
331
-     * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor.
332
-     *
333
-     * @param Content $content
334
-     * @param string $target
335
-     * @return bool
336
-     */
337
-    public function move($content, $target)
338
-    {
339
-
340
-        // Security check.
341
-        $this->getContentValidator()->validate($content);
342
-
343
-        $dataType = $content->getDataType();
344
-        $handler = $this->getDataHandlerFactory()->action(ProcessAction::MOVE)->forType($dataType)->getDataHandler();
345
-
346
-        $handlerResult = $handler->processMove($content, $target);
347
-        $this->errorMessages = $handler->getErrorMessages();
348
-        return $handlerResult;
349
-    }
350
-
351
-    /**
352
-     * Copy a content within this repository.
353
-     *
354
-     * @param Content $content
355
-     * @return bool
356
-     */
357
-    public function copy($content, $target)
358
-    {
359
-
360
-        // Security check.
361
-        $this->getContentValidator()->validate($content);
362
-
363
-        $dataType = $content->getDataType();
364
-        $handler = $this->getDataHandlerFactory()->action(ProcessAction::COPY)->forType($dataType)->getDataHandler();
365
-
366
-        $handlerResult = $handler->processCopy($content, $target);
367
-        $this->errorMessages = $handler->getErrorMessages();
368
-        return $handlerResult;
369
-    }
370
-
371
-    /**
372
-     * Adds an object to this repository.
373
-     *
374
-     * @param object $object The object to add
375
-     * @throws \BadMethodCallException
376
-     * @return void
377
-     * @api
378
-     */
379
-    public function add($object)
380
-    {
381
-        throw new \BadMethodCallException('Repository does not support the add() method.', 1375805599);
382
-    }
383
-
384
-    /**
385
-     * Returns the total number objects of this repository.
386
-     *
387
-     * @return integer The object count
388
-     * @api
389
-     */
390
-    public function countAll()
391
-    {
392
-        $query = $this->createQuery();
393
-        return $query->count();
394
-    }
395
-
396
-    /**
397
-     * Removes all objects of this repository as if remove() was called for
398
-     * all of them.
399
-     *
400
-     * @return void
401
-     * @api
402
-     */
403
-    public function removeAll()
404
-    {
405
-        // TODO: Implement removeAll() method.
406
-    }
407
-
408
-    /**
409
-     * Finds an object matching the given identifier.
410
-     *
411
-     * @param mixed $identifier The identifier of the object to find
412
-     * @return Content|NULL
413
-     * @api
414
-     */
415
-    public function findByIdentifier($identifier)
416
-    {
417
-        $query = $this->createQuery();
418
-
419
-        $result = $query->matching($query->equals('uid', $identifier))
420
-            ->execute();
421
-
422
-        if (is_array($result)) {
423
-            $result = current($result);
424
-        }
425
-
426
-        return $result;
427
-    }
428
-
429
-    /**
430
-     * Dispatches magic methods (findBy[Property]())
431
-     *
432
-     * @param string $methodName The name of the magic method
433
-     * @param string $arguments The arguments of the magic method
434
-     * @throws UnsupportedMethodException
435
-     * @return mixed
436
-     * @api
437
-     */
438
-    public function __call($methodName, $arguments)
439
-    {
440
-        if (substr($methodName, 0, 6) === 'findBy' && strlen($methodName) > 7) {
441
-            $propertyName = strtolower(substr(substr($methodName, 6), 0, 1)) . substr(substr($methodName, 6), 1);
442
-            $result = $this->processMagicCall($propertyName, $arguments[0]);
443
-        } elseif (substr($methodName, 0, 9) === 'findOneBy' && strlen($methodName) > 10) {
444
-            $propertyName = strtolower(substr(substr($methodName, 9), 0, 1)) . substr(substr($methodName, 9), 1);
445
-            $result = $this->processMagicCall($propertyName, $arguments[0], 'one');
446
-        } elseif (substr($methodName, 0, 7) === 'countBy' && strlen($methodName) > 8) {
447
-            $propertyName = strtolower(substr(substr($methodName, 7), 0, 1)) . substr(substr($methodName, 7), 1);
448
-            $result = $this->processMagicCall($propertyName, $arguments[0], 'count');
449
-        } else {
450
-            throw new UnsupportedMethodException('The method "' . $methodName . '" is not supported by the repository.', 1360838010);
451
-        }
452
-        return $result;
453
-    }
454
-
455
-    /**
456
-     * Returns a query for objects of this repository
457
-     *
458
-     * @return Query
459
-     * @api
460
-     */
461
-    public function createQuery()
462
-    {
463
-        /** @var Query $query */
464
-        $query = $this->getObjectManager()->get('Fab\Vidi\Persistence\Query', $this->dataType);
465
-        $query->setSourceFieldName($this->sourceFieldName);
466
-
467
-        if ($this->defaultQuerySettings) {
468
-            $query->setQuerySettings($this->defaultQuerySettings);
469
-        } else {
470
-
471
-            // Initialize and pass the query settings at this level.
472
-            /** @var \Fab\Vidi\Persistence\QuerySettings $querySettings */
473
-            $querySettings = $this->getObjectManager()->get('Fab\Vidi\Persistence\QuerySettings');
474
-
475
-            // Default choice for the BE.
476
-            if ($this->isBackendMode()) {
477
-                $querySettings->setIgnoreEnableFields(TRUE);
478
-            }
479
-
480
-            $query->setQuerySettings($querySettings);
481
-        }
482
-
483
-        return $query;
484
-    }
485
-
486
-    /**
487
-     * Sets the property names to order the result by per default.
488
-     * Expected like this:
489
-     * array(
490
-     * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
491
-     * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
492
-     * )
493
-     *
494
-     * @param array $defaultOrderings The property names to order by
495
-     * @throws \BadMethodCallException
496
-     * @return void
497
-     * @api
498
-     */
499
-    public function setDefaultOrderings(array $defaultOrderings)
500
-    {
501
-        throw new \BadMethodCallException('Repository does not support the setDefaultOrderings() method.', 1375805598);
502
-    }
503
-
504
-    /**
505
-     * Sets the default query settings to be used in this repository
506
-     *
507
-     * @param QuerySettingsInterface $defaultQuerySettings The query settings to be used by default
508
-     * @throws \BadMethodCallException
509
-     * @return void
510
-     * @api
511
-     */
512
-    public function setDefaultQuerySettings(QuerySettingsInterface $defaultQuerySettings)
513
-    {
514
-        $this->defaultQuerySettings = $defaultQuerySettings;
515
-    }
516
-
517
-    /**
518
-     * @return array
519
-     */
520
-    public function getErrorMessages()
521
-    {
522
-        return $this->errorMessages;
523
-    }
524
-
525
-    /**
526
-     * @param string $sourceFieldName
527
-     * @return $this
528
-     */
529
-    public function setSourceFieldName($sourceFieldName)
530
-    {
531
-        $this->sourceFieldName = $sourceFieldName;
532
-        return $this;
533
-    }
534
-
535
-    /**
536
-     * @return string
537
-     */
538
-    public function getDataType()
539
-    {
540
-        return $this->dataType;
541
-    }
542
-
543
-    /**
544
-     * Tell whether the order has a foreign table in its expression, e.g. "metadata.title".
545
-     *
546
-     * @param string $ordering
547
-     * @return bool
548
-     */
549
-    protected function hasForeignRelationIn($ordering)
550
-    {
551
-        return strpos($ordering, '.') !== FALSE;
552
-    }
553
-
554
-    /**
555
-     * Extract the foreign relation of the ordering "metadata.title" -> "metadata"
556
-     *
557
-     * @param string $ordering
558
-     * @return string
559
-     */
560
-    protected function getForeignRelationFrom($ordering)
561
-    {
562
-        $parts = explode('.', $ordering);
563
-        return $parts[0];
564
-    }
565
-
566
-    /**
567
-     * Get the constraints
568
-     *
569
-     * @param Query $query
570
-     * @param Matcher $matcher
571
-     * @return ConstraintInterface|NULL
572
-     */
573
-    protected function computeConstraints(Query $query, Matcher $matcher)
574
-    {
575
-
576
-        $constraints = NULL;
577
-
578
-        $collectedConstraints = array();
579
-
580
-        // Search term
581
-        $constraint = $this->computeSearchTermConstraint($query, $matcher);
582
-        if ($constraint) {
583
-            $collectedConstraints[] = $constraint;
584
-        }
585
-
586
-        foreach ($matcher->getSupportedOperators() as $operator) {
587
-            $constraint = $this->computeConstraint($query, $matcher, $operator);
588
-            if ($constraint) {
589
-                $collectedConstraints[] = $constraint;
590
-            }
591
-        }
592
-
593
-        if (count($collectedConstraints) > 1) {
594
-            $logical = $matcher->getDefaultLogicalSeparator();
595
-            $constraints = $query->$logical($collectedConstraints);
596
-        } elseif (!empty($collectedConstraints)) {
597
-
598
-            // true means there is one constraint only and should become the result
599
-            $constraints = current($collectedConstraints);
600
-        }
601
-
602
-        // Trigger signal for post processing the computed constraints object.
603
-        $constraints = $this->emitPostProcessConstraintsSignal($query, $constraints);
604
-
605
-        return $constraints;
606
-    }
607
-
608
-    /**
609
-     * Computes the search constraint and returns it.
610
-     *
611
-     * @param Query $query
612
-     * @param Matcher $matcher
613
-     * @return ConstraintInterface|NULL
614
-     */
615
-    protected function computeSearchTermConstraint(Query $query, Matcher $matcher)
616
-    {
617
-
618
-        $result = NULL;
619
-
620
-        // Search term case
621
-        if ($matcher->getSearchTerm()) {
622
-
623
-            $fields = GeneralUtility::trimExplode(',', Tca::table($this->dataType)->getSearchFields(), TRUE);
624
-
625
-            $constraints = array();
626
-            $likeClause = sprintf('%%%s%%', $matcher->getSearchTerm());
627
-            foreach ($fields as $fieldNameAndPath) {
628
-                if ($this->isSuitableForLike($fieldNameAndPath, $matcher->getSearchTerm())) {
629
-
630
-                    $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType);
631
-                    $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType);
632
-
633
-                    if (Tca::table($dataType)->hasField($fieldName) && Tca::table($dataType)->field($fieldName)->hasRelation()) {
634
-                        $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable();
635
-                        $fieldNameAndPath = $fieldNameAndPath . '.' . Tca::table($foreignTable)->getLabelField();
636
-                    }
637
-                    $constraints[] = $query->like($fieldNameAndPath, $likeClause);
638
-                }
639
-            }
640
-            $logical = $matcher->getLogicalSeparatorForSearchTerm();
641
-            $result = $query->$logical($constraints);
642
-        }
643
-
644
-        return $result;
645
-    }
646
-
647
-    /**
648
-     * It does not make sense to have a "like" in presence of numerical field, e.g "uid".
649
-     * Tell whether the given value makes sense for a "like" clause.
650
-     *
651
-     * @param string $fieldNameAndPath
652
-     * @param string $value
653
-     * @return bool
654
-     */
655
-    protected function isSuitableForLike($fieldNameAndPath, $value)
656
-    {
657
-        $isSuitable = TRUE;
658
-
659
-        // TRUE means it is a string
660
-        if (!MathUtility::canBeInterpretedAsInteger($value)) {
661
-
662
-            $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType);
663
-            $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType);
664
-
665
-            if (Tca::table($dataType)->field($fieldName)->isNumerical()
666
-                && !Tca::table($dataType)->field($fieldName)->hasRelation()
667
-            ) {
668
-                $isSuitable = FALSE;
669
-            }
670
-        }
671
-
672
-        return $isSuitable;
673
-    }
674
-
675
-    /**
676
-     * Computes the constraint for matches and returns it.
677
-     *
678
-     * @param Query $query
679
-     * @param Matcher $matcher
680
-     * @param string $operator
681
-     * @return ConstraintInterface|NULL
682
-     */
683
-    protected function computeConstraint(Query $query, Matcher $matcher, $operator)
684
-    {
685
-        $result = NULL;
686
-
687
-        $operatorName = ucfirst($operator);
688
-        $getCriteria = sprintf('get%sCriteria', $operatorName);
689
-        $criteria = $matcher->$getCriteria();
690
-
691
-        if (!empty($criteria)) {
692
-            $constraints = array();
693
-
694
-            foreach ($criteria as $criterion) {
695
-
696
-                $fieldNameAndPath = $criterion['fieldNameAndPath'];
697
-                $operand = $criterion['operand'];
698
-
699
-                // Compute a few variables...
700
-                // $dataType is generally equals to $this->dataType but not always... if fieldName is a path.
701
-                $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType);
702
-                $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType);
703
-                $fieldPath = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath, $this->dataType);
704
-
705
-                if (Tca::table($dataType)->field($fieldName)->hasRelation()) {
706
-                    if (MathUtility::canBeInterpretedAsInteger($operand)) {
707
-                        $fieldNameAndPath = $fieldName . '.uid';
708
-                    } else {
709
-                        $foreignTableName = Tca::table($dataType)->field($fieldName)->getForeignTable();
710
-                        $foreignTable = Tca::table($foreignTableName);
711
-                        $fieldNameAndPath = $fieldName . '.' . $foreignTable->getLabelField();
712
-                    }
713
-
714
-                    // If different means we should restore the prepended path segment for proper SQL parser.
715
-                    // This is TRUE for a composite field, e.g items.sys_file_metadata for categories.
716
-                    if ($fieldName !== $fieldPath) {
717
-                        $fieldNameAndPath = $fieldPath . '.' . $fieldNameAndPath;
718
-                    }
719
-                }
720
-
721
-                $constraints[] = $query->$operator($fieldNameAndPath, $criterion['operand']);
722
-            }
723
-
724
-            $getLogicalSeparator = sprintf('getLogicalSeparatorFor%s', $operatorName);
725
-            $logical = $matcher->$getLogicalSeparator();
726
-            $result = $query->$logical($constraints);
727
-        }
728
-
729
-        return $result;
730
-    }
731
-
732
-    /**
733
-     * @return \TYPO3\CMS\Core\DataHandling\DataHandler
734
-     */
735
-    protected function getDataHandler()
736
-    {
737
-        if (!$this->dataHandler) {
738
-            $this->dataHandler = GeneralUtility::makeInstance('TYPO3\CMS\Core\DataHandling\DataHandler');
739
-        }
740
-        return $this->dataHandler;
741
-    }
742
-
743
-    /**
744
-     * Handle the magic call by properly creating a Query object and returning its result.
745
-     *
746
-     * @param string $propertyName
747
-     * @param string $value
748
-     * @param string $flag
749
-     * @return array
750
-     */
751
-    protected function processMagicCall($propertyName, $value, $flag = '')
752
-    {
753
-
754
-        $fieldName = Property::name($propertyName)->of($this->dataType)->toFieldName();
755
-
756
-        /** @var $matcher Matcher */
757
-        $matcher = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Matcher', array(), $this->getDataType());
758
-
759
-        $table = Tca::table($this->dataType);
760
-        if ($table->field($fieldName)->isGroup()) {
761
-
762
-            $valueParts = explode('.', $value, 2);
763
-            $fieldName = $fieldName . '.' . $valueParts[0];
764
-            $value = $valueParts[1];
765
-        }
766
-
767
-        $matcher->equals($fieldName, $value);
768
-
769
-        if ($flag == 'count') {
770
-            $result = $this->countBy($matcher);
771
-        } else {
772
-            $result = $this->findBy($matcher);
773
-        }
774
-        return $flag == 'one' && !empty($result) ? reset($result) : $result;
775
-    }
776
-
777
-    /**
778
-     * @return \Fab\Vidi\DataHandler\DataHandlerFactory
779
-     */
780
-    protected function getDataHandlerFactory()
781
-    {
782
-        return GeneralUtility::makeInstance('Fab\Vidi\DataHandler\DataHandlerFactory');
783
-    }
784
-
785
-    /**
786
-     * Returns whether the current mode is Backend
787
-     *
788
-     * @return bool
789
-     */
790
-    protected function isBackendMode()
791
-    {
792
-        return TYPO3_MODE == 'BE';
793
-    }
794
-
795
-    /**
796
-     * @return \Fab\Vidi\Resolver\FieldPathResolver
797
-     */
798
-    protected function getFieldPathResolver()
799
-    {
800
-        return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
801
-    }
802
-
803
-    /**
804
-     * @return \TYPO3\CMS\Extbase\Object\ObjectManager
805
-     */
806
-    protected function getObjectManager()
807
-    {
808
-        return GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
809
-    }
810
-
811
-    /**
812
-     * @return \Fab\Vidi\Domain\Validator\ContentValidator
813
-     */
814
-    protected function getContentValidator()
815
-    {
816
-        return GeneralUtility::makeInstance('Fab\Vidi\Domain\Validator\ContentValidator');
817
-    }
818
-
819
-    /**
820
-     * @return \Fab\Vidi\Domain\Validator\LanguageValidator
821
-     */
822
-    protected function getLanguageValidator()
823
-    {
824
-        return GeneralUtility::makeInstance('Fab\Vidi\Domain\Validator\LanguageValidator');
825
-    }
826
-
827
-    /**
828
-     * Signal that is called for post-processing the computed constraints object.
829
-     *
830
-     * @param Query $query
831
-     * @param ConstraintInterface|NULL $constraints
832
-     * @return ConstraintInterface|NULL $constraints
833
-     * @signal
834
-     */
835
-    protected function emitPostProcessConstraintsSignal(Query $query, $constraints)
836
-    {
837
-        $result = $this->getSignalSlotDispatcher()->dispatch(
838
-            'Fab\Vidi\Domain\Repository\ContentRepository',
839
-            'postProcessConstraintsObject',
840
-            array(
841
-                $query,
842
-                $constraints
843
-            )
844
-        );
845
-
846
-        return $result[1];
847
-    }
848
-
849
-    /**
850
-     * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
851
-     */
852
-    protected function getSignalSlotDispatcher()
853
-    {
854
-        return $this->getObjectManager()->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
855
-    }
37
+	/**
38
+	 * Tell whether it is a raw result (array) or object being returned.
39
+	 *
40
+	 * @var bool
41
+	 */
42
+	protected $rawResult = FALSE;
43
+
44
+	/**
45
+	 * The data type to be returned, e.g fe_users, fe_groups, tt_content, etc...
46
+	 *
47
+	 * @var string
48
+	 */
49
+	protected $dataType;
50
+
51
+	/**
52
+	 * The source field is useful in the context of MM relations to know who is the caller
53
+	 * e.g findByItems which eventually corresponds to a field name.
54
+	 *
55
+	 * @var string
56
+	 */
57
+	protected $sourceFieldName = '';
58
+
59
+	/**
60
+	 * @var array
61
+	 */
62
+	protected $errorMessages = array();
63
+
64
+	/**
65
+	 * @var QuerySettingsInterface
66
+	 */
67
+	protected $defaultQuerySettings;
68
+
69
+	/**
70
+	 * Constructor
71
+	 *
72
+	 * @param string $dataType
73
+	 */
74
+	public function __construct($dataType)
75
+	{
76
+		$this->dataType = $dataType;
77
+	}
78
+
79
+	/**
80
+	 * Returns all objects of this repository.
81
+	 *
82
+	 * @return Content[]
83
+	 */
84
+	public function findAll()
85
+	{
86
+		$query = $this->createQuery();
87
+		return $query->execute();
88
+	}
89
+
90
+	/**
91
+	 * Returns all "distinct" values for a given property.
92
+	 *
93
+	 * @param string $propertyName
94
+	 * @param Matcher $matcher
95
+	 * @return Content[]
96
+	 */
97
+	public function findDistinctValues($propertyName, Matcher $matcher = NULL)
98
+	{
99
+		$query = $this->createQuery();
100
+		$query->setDistinct($propertyName);
101
+
102
+		// Remove empty values from selection.
103
+		$constraint = $query->logicalNot($query->equals($propertyName, ''));
104
+
105
+		// Add some additional constraints from the Matcher object.
106
+		$matcherConstraint = NULL;
107
+		if (!is_null($matcher)) {
108
+			$matcherConstraint = $this->computeConstraints($query, $matcher);
109
+		}
110
+
111
+		// Assemble the final constraints or not.
112
+		if ($matcherConstraint) {
113
+			$query->logicalAnd($matcherConstraint, $constraint);
114
+			$query->matching($query->logicalAnd($matcherConstraint, $constraint));
115
+		} else {
116
+			$query->matching($constraint);
117
+		}
118
+
119
+		return $query->execute();
120
+	}
121
+
122
+	/**
123
+	 * Returns all "distinct" values for a given property.
124
+	 *
125
+	 * @param string $propertyName
126
+	 * @param Matcher $matcher
127
+	 * @return int
128
+	 */
129
+	public function countDistinctValues($propertyName, Matcher $matcher = NULL)
130
+	{
131
+		$query = $this->createQuery();
132
+		$query->setDistinct($propertyName);
133
+
134
+		// Remove empty values from selection.
135
+		$constraint = $query->logicalNot($query->equals($propertyName, ''));
136
+
137
+		// Add some additional constraints from the Matcher object.
138
+		$matcherConstraint = NULL;
139
+		if (!is_null($matcher)) {
140
+			$matcherConstraint = $this->computeConstraints($query, $matcher);
141
+		}
142
+
143
+		// Assemble the final constraints or not.
144
+		if ($matcherConstraint) {
145
+			$query->logicalAnd($matcherConstraint, $constraint);
146
+			$query->matching($query->logicalAnd($matcherConstraint, $constraint));
147
+		} else {
148
+			$query->matching($constraint);
149
+		}
150
+
151
+		return $query->count();
152
+	}
153
+
154
+	/**
155
+	 * Finds an object matching the given identifier.
156
+	 *
157
+	 * @param int $uid The identifier of the object to find
158
+	 * @return Content|NULL
159
+	 * @api
160
+	 */
161
+	public function findByUid($uid)
162
+	{
163
+		return $this->findByIdentifier($uid);
164
+	}
165
+
166
+	/**
167
+	 * Finds all Contents given specified matches.
168
+	 *
169
+	 * @param string $propertyName
170
+	 * @param array $values
171
+	 * @return Content[]
172
+	 */
173
+	public function findIn($propertyName, array $values)
174
+	{
175
+		$query = $this->createQuery();
176
+		$query->matching($query->in($propertyName, $values));
177
+		return $query->execute();
178
+	}
179
+
180
+	/**
181
+	 * Finds all Contents given specified matches.
182
+	 *
183
+	 * @param Matcher $matcher
184
+	 * @param Order $order The order
185
+	 * @param int $limit
186
+	 * @param int $offset
187
+	 * @return Content[]
188
+	 */
189
+	public function findBy(Matcher $matcher, Order $order = NULL, $limit = NULL, $offset = NULL)
190
+	{
191
+
192
+		$query = $this->createQuery();
193
+
194
+		if ($limit) {
195
+			$query->setLimit($limit);
196
+		}
197
+
198
+		if ($order) {
199
+			$query->setOrderings($order->getOrderings());
200
+
201
+			// Loops around the orderings adding if necessary a dummy condition
202
+			// to make sure the relations can be resolved when transforming the query to plain SQL.
203
+			foreach ($order->getOrderings() as $ordering => $direction) {
204
+				if ($this->hasForeignRelationIn($ordering)) {
205
+					$relationalField = $this->getForeignRelationFrom($ordering);
206
+					$matcher->like($relationalField . '.uid', '');
207
+				}
208
+			}
209
+		}
210
+
211
+		if ($offset) {
212
+			$query->setOffset($offset);
213
+		}
214
+
215
+		$constraints = $this->computeConstraints($query, $matcher);
216
+
217
+		if ($constraints) {
218
+			$query->matching($constraints);
219
+		}
220
+
221
+		return $query->execute();
222
+	}
223
+
224
+	/**
225
+	 * Find one Content object given specified matches.
226
+	 *
227
+	 * @param Matcher $matcher
228
+	 * @return Content
229
+	 */
230
+	public function findOneBy(Matcher $matcher)
231
+	{
232
+
233
+		$query = $this->createQuery();
234
+
235
+		$constraints = $this->computeConstraints($query, $matcher);
236
+
237
+		if ($constraints) {
238
+			$query->matching($constraints);
239
+		}
240
+
241
+		$query->setLimit(1); // only take one!
242
+
243
+		$resultSet = $query->execute();
244
+		if ($resultSet) {
245
+			$resultSet = current($resultSet);
246
+		}
247
+		return $resultSet;
248
+	}
249
+
250
+	/**
251
+	 * Count all Contents given specified matches.
252
+	 *
253
+	 * @param Matcher $matcher
254
+	 * @return int
255
+	 */
256
+	public function countBy(Matcher $matcher)
257
+	{
258
+
259
+		$query = $this->createQuery();
260
+
261
+		$constraints = $this->computeConstraints($query, $matcher);
262
+
263
+		if ($constraints) {
264
+			$query->matching($constraints);
265
+		}
266
+
267
+		return $query->count();
268
+	}
269
+
270
+	/**
271
+	 * Update a content with new information.
272
+	 *
273
+	 * @param Content $content
274
+	 * @param $language
275
+	 * @return bool
276
+	 */
277
+	public function localize($content, $language)
278
+	{
279
+
280
+		// Security check
281
+		$this->getContentValidator()->validate($content);
282
+		$this->getLanguageValidator()->validate($language);
283
+
284
+		$dataType = $content->getDataType();
285
+		$handler = $this->getDataHandlerFactory()->action(ProcessAction::LOCALIZE)->forType($dataType)->getDataHandler();
286
+
287
+		$handlerResult = $handler->processLocalize($content, $language);
288
+		$this->errorMessages = $handler->getErrorMessages();
289
+		return $handlerResult;
290
+	}
291
+
292
+	/**
293
+	 * Update a content with new information.
294
+	 *
295
+	 * @param Content $content
296
+	 * @return bool
297
+	 */
298
+	public function update($content)
299
+	{
300
+
301
+		// Security check.
302
+		$this->getContentValidator()->validate($content);
303
+
304
+		$dataType = $content->getDataType();
305
+		$handler = $this->getDataHandlerFactory()->action(ProcessAction::UPDATE)->forType($dataType)->getDataHandler();
306
+
307
+		$handlerResult = $handler->processUpdate($content);
308
+		$this->errorMessages = $handler->getErrorMessages();
309
+		return $handlerResult;
310
+	}
311
+
312
+	/**
313
+	 * Removes an object from this repository.
314
+	 *
315
+	 * @param Content $content
316
+	 * @return boolean
317
+	 */
318
+	public function remove($content)
319
+	{
320
+		$dataType = $content->getDataType();
321
+		$handler = $this->getDataHandlerFactory()->action(ProcessAction::REMOVE)->forType($dataType)->getDataHandler();
322
+
323
+		$handlerResult = $handler->processRemove($content);
324
+		$this->errorMessages = $handler->getErrorMessages();
325
+		return $handlerResult;
326
+	}
327
+
328
+	/**
329
+	 * Move a content within this repository.
330
+	 * The $target corresponds to the pid to move the records to.
331
+	 * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor.
332
+	 *
333
+	 * @param Content $content
334
+	 * @param string $target
335
+	 * @return bool
336
+	 */
337
+	public function move($content, $target)
338
+	{
339
+
340
+		// Security check.
341
+		$this->getContentValidator()->validate($content);
342
+
343
+		$dataType = $content->getDataType();
344
+		$handler = $this->getDataHandlerFactory()->action(ProcessAction::MOVE)->forType($dataType)->getDataHandler();
345
+
346
+		$handlerResult = $handler->processMove($content, $target);
347
+		$this->errorMessages = $handler->getErrorMessages();
348
+		return $handlerResult;
349
+	}
350
+
351
+	/**
352
+	 * Copy a content within this repository.
353
+	 *
354
+	 * @param Content $content
355
+	 * @return bool
356
+	 */
357
+	public function copy($content, $target)
358
+	{
359
+
360
+		// Security check.
361
+		$this->getContentValidator()->validate($content);
362
+
363
+		$dataType = $content->getDataType();
364
+		$handler = $this->getDataHandlerFactory()->action(ProcessAction::COPY)->forType($dataType)->getDataHandler();
365
+
366
+		$handlerResult = $handler->processCopy($content, $target);
367
+		$this->errorMessages = $handler->getErrorMessages();
368
+		return $handlerResult;
369
+	}
370
+
371
+	/**
372
+	 * Adds an object to this repository.
373
+	 *
374
+	 * @param object $object The object to add
375
+	 * @throws \BadMethodCallException
376
+	 * @return void
377
+	 * @api
378
+	 */
379
+	public function add($object)
380
+	{
381
+		throw new \BadMethodCallException('Repository does not support the add() method.', 1375805599);
382
+	}
383
+
384
+	/**
385
+	 * Returns the total number objects of this repository.
386
+	 *
387
+	 * @return integer The object count
388
+	 * @api
389
+	 */
390
+	public function countAll()
391
+	{
392
+		$query = $this->createQuery();
393
+		return $query->count();
394
+	}
395
+
396
+	/**
397
+	 * Removes all objects of this repository as if remove() was called for
398
+	 * all of them.
399
+	 *
400
+	 * @return void
401
+	 * @api
402
+	 */
403
+	public function removeAll()
404
+	{
405
+		// TODO: Implement removeAll() method.
406
+	}
407
+
408
+	/**
409
+	 * Finds an object matching the given identifier.
410
+	 *
411
+	 * @param mixed $identifier The identifier of the object to find
412
+	 * @return Content|NULL
413
+	 * @api
414
+	 */
415
+	public function findByIdentifier($identifier)
416
+	{
417
+		$query = $this->createQuery();
418
+
419
+		$result = $query->matching($query->equals('uid', $identifier))
420
+			->execute();
421
+
422
+		if (is_array($result)) {
423
+			$result = current($result);
424
+		}
425
+
426
+		return $result;
427
+	}
428
+
429
+	/**
430
+	 * Dispatches magic methods (findBy[Property]())
431
+	 *
432
+	 * @param string $methodName The name of the magic method
433
+	 * @param string $arguments The arguments of the magic method
434
+	 * @throws UnsupportedMethodException
435
+	 * @return mixed
436
+	 * @api
437
+	 */
438
+	public function __call($methodName, $arguments)
439
+	{
440
+		if (substr($methodName, 0, 6) === 'findBy' && strlen($methodName) > 7) {
441
+			$propertyName = strtolower(substr(substr($methodName, 6), 0, 1)) . substr(substr($methodName, 6), 1);
442
+			$result = $this->processMagicCall($propertyName, $arguments[0]);
443
+		} elseif (substr($methodName, 0, 9) === 'findOneBy' && strlen($methodName) > 10) {
444
+			$propertyName = strtolower(substr(substr($methodName, 9), 0, 1)) . substr(substr($methodName, 9), 1);
445
+			$result = $this->processMagicCall($propertyName, $arguments[0], 'one');
446
+		} elseif (substr($methodName, 0, 7) === 'countBy' && strlen($methodName) > 8) {
447
+			$propertyName = strtolower(substr(substr($methodName, 7), 0, 1)) . substr(substr($methodName, 7), 1);
448
+			$result = $this->processMagicCall($propertyName, $arguments[0], 'count');
449
+		} else {
450
+			throw new UnsupportedMethodException('The method "' . $methodName . '" is not supported by the repository.', 1360838010);
451
+		}
452
+		return $result;
453
+	}
454
+
455
+	/**
456
+	 * Returns a query for objects of this repository
457
+	 *
458
+	 * @return Query
459
+	 * @api
460
+	 */
461
+	public function createQuery()
462
+	{
463
+		/** @var Query $query */
464
+		$query = $this->getObjectManager()->get('Fab\Vidi\Persistence\Query', $this->dataType);
465
+		$query->setSourceFieldName($this->sourceFieldName);
466
+
467
+		if ($this->defaultQuerySettings) {
468
+			$query->setQuerySettings($this->defaultQuerySettings);
469
+		} else {
470
+
471
+			// Initialize and pass the query settings at this level.
472
+			/** @var \Fab\Vidi\Persistence\QuerySettings $querySettings */
473
+			$querySettings = $this->getObjectManager()->get('Fab\Vidi\Persistence\QuerySettings');
474
+
475
+			// Default choice for the BE.
476
+			if ($this->isBackendMode()) {
477
+				$querySettings->setIgnoreEnableFields(TRUE);
478
+			}
479
+
480
+			$query->setQuerySettings($querySettings);
481
+		}
482
+
483
+		return $query;
484
+	}
485
+
486
+	/**
487
+	 * Sets the property names to order the result by per default.
488
+	 * Expected like this:
489
+	 * array(
490
+	 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
491
+	 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
492
+	 * )
493
+	 *
494
+	 * @param array $defaultOrderings The property names to order by
495
+	 * @throws \BadMethodCallException
496
+	 * @return void
497
+	 * @api
498
+	 */
499
+	public function setDefaultOrderings(array $defaultOrderings)
500
+	{
501
+		throw new \BadMethodCallException('Repository does not support the setDefaultOrderings() method.', 1375805598);
502
+	}
503
+
504
+	/**
505
+	 * Sets the default query settings to be used in this repository
506
+	 *
507
+	 * @param QuerySettingsInterface $defaultQuerySettings The query settings to be used by default
508
+	 * @throws \BadMethodCallException
509
+	 * @return void
510
+	 * @api
511
+	 */
512
+	public function setDefaultQuerySettings(QuerySettingsInterface $defaultQuerySettings)
513
+	{
514
+		$this->defaultQuerySettings = $defaultQuerySettings;
515
+	}
516
+
517
+	/**
518
+	 * @return array
519
+	 */
520
+	public function getErrorMessages()
521
+	{
522
+		return $this->errorMessages;
523
+	}
524
+
525
+	/**
526
+	 * @param string $sourceFieldName
527
+	 * @return $this
528
+	 */
529
+	public function setSourceFieldName($sourceFieldName)
530
+	{
531
+		$this->sourceFieldName = $sourceFieldName;
532
+		return $this;
533
+	}
534
+
535
+	/**
536
+	 * @return string
537
+	 */
538
+	public function getDataType()
539
+	{
540
+		return $this->dataType;
541
+	}
542
+
543
+	/**
544
+	 * Tell whether the order has a foreign table in its expression, e.g. "metadata.title".
545
+	 *
546
+	 * @param string $ordering
547
+	 * @return bool
548
+	 */
549
+	protected function hasForeignRelationIn($ordering)
550
+	{
551
+		return strpos($ordering, '.') !== FALSE;
552
+	}
553
+
554
+	/**
555
+	 * Extract the foreign relation of the ordering "metadata.title" -> "metadata"
556
+	 *
557
+	 * @param string $ordering
558
+	 * @return string
559
+	 */
560
+	protected function getForeignRelationFrom($ordering)
561
+	{
562
+		$parts = explode('.', $ordering);
563
+		return $parts[0];
564
+	}
565
+
566
+	/**
567
+	 * Get the constraints
568
+	 *
569
+	 * @param Query $query
570
+	 * @param Matcher $matcher
571
+	 * @return ConstraintInterface|NULL
572
+	 */
573
+	protected function computeConstraints(Query $query, Matcher $matcher)
574
+	{
575
+
576
+		$constraints = NULL;
577
+
578
+		$collectedConstraints = array();
579
+
580
+		// Search term
581
+		$constraint = $this->computeSearchTermConstraint($query, $matcher);
582
+		if ($constraint) {
583
+			$collectedConstraints[] = $constraint;
584
+		}
585
+
586
+		foreach ($matcher->getSupportedOperators() as $operator) {
587
+			$constraint = $this->computeConstraint($query, $matcher, $operator);
588
+			if ($constraint) {
589
+				$collectedConstraints[] = $constraint;
590
+			}
591
+		}
592
+
593
+		if (count($collectedConstraints) > 1) {
594
+			$logical = $matcher->getDefaultLogicalSeparator();
595
+			$constraints = $query->$logical($collectedConstraints);
596
+		} elseif (!empty($collectedConstraints)) {
597
+
598
+			// true means there is one constraint only and should become the result
599
+			$constraints = current($collectedConstraints);
600
+		}
601
+
602
+		// Trigger signal for post processing the computed constraints object.
603
+		$constraints = $this->emitPostProcessConstraintsSignal($query, $constraints);
604
+
605
+		return $constraints;
606
+	}
607
+
608
+	/**
609
+	 * Computes the search constraint and returns it.
610
+	 *
611
+	 * @param Query $query
612
+	 * @param Matcher $matcher
613
+	 * @return ConstraintInterface|NULL
614
+	 */
615
+	protected function computeSearchTermConstraint(Query $query, Matcher $matcher)
616
+	{
617
+
618
+		$result = NULL;
619
+
620
+		// Search term case
621
+		if ($matcher->getSearchTerm()) {
622
+
623
+			$fields = GeneralUtility::trimExplode(',', Tca::table($this->dataType)->getSearchFields(), TRUE);
624
+
625
+			$constraints = array();
626
+			$likeClause = sprintf('%%%s%%', $matcher->getSearchTerm());
627
+			foreach ($fields as $fieldNameAndPath) {
628
+				if ($this->isSuitableForLike($fieldNameAndPath, $matcher->getSearchTerm())) {
629
+
630
+					$dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType);
631
+					$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType);
632
+
633
+					if (Tca::table($dataType)->hasField($fieldName) && Tca::table($dataType)->field($fieldName)->hasRelation()) {
634
+						$foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable();
635
+						$fieldNameAndPath = $fieldNameAndPath . '.' . Tca::table($foreignTable)->getLabelField();
636
+					}
637
+					$constraints[] = $query->like($fieldNameAndPath, $likeClause);
638
+				}
639
+			}
640
+			$logical = $matcher->getLogicalSeparatorForSearchTerm();
641
+			$result = $query->$logical($constraints);
642
+		}
643
+
644
+		return $result;
645
+	}
646
+
647
+	/**
648
+	 * It does not make sense to have a "like" in presence of numerical field, e.g "uid".
649
+	 * Tell whether the given value makes sense for a "like" clause.
650
+	 *
651
+	 * @param string $fieldNameAndPath
652
+	 * @param string $value
653
+	 * @return bool
654
+	 */
655
+	protected function isSuitableForLike($fieldNameAndPath, $value)
656
+	{
657
+		$isSuitable = TRUE;
658
+
659
+		// TRUE means it is a string
660
+		if (!MathUtility::canBeInterpretedAsInteger($value)) {
661
+
662
+			$dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType);
663
+			$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType);
664
+
665
+			if (Tca::table($dataType)->field($fieldName)->isNumerical()
666
+				&& !Tca::table($dataType)->field($fieldName)->hasRelation()
667
+			) {
668
+				$isSuitable = FALSE;
669
+			}
670
+		}
671
+
672
+		return $isSuitable;
673
+	}
674
+
675
+	/**
676
+	 * Computes the constraint for matches and returns it.
677
+	 *
678
+	 * @param Query $query
679
+	 * @param Matcher $matcher
680
+	 * @param string $operator
681
+	 * @return ConstraintInterface|NULL
682
+	 */
683
+	protected function computeConstraint(Query $query, Matcher $matcher, $operator)
684
+	{
685
+		$result = NULL;
686
+
687
+		$operatorName = ucfirst($operator);
688
+		$getCriteria = sprintf('get%sCriteria', $operatorName);
689
+		$criteria = $matcher->$getCriteria();
690
+
691
+		if (!empty($criteria)) {
692
+			$constraints = array();
693
+
694
+			foreach ($criteria as $criterion) {
695
+
696
+				$fieldNameAndPath = $criterion['fieldNameAndPath'];
697
+				$operand = $criterion['operand'];
698
+
699
+				// Compute a few variables...
700
+				// $dataType is generally equals to $this->dataType but not always... if fieldName is a path.
701
+				$dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType);
702
+				$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType);
703
+				$fieldPath = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath, $this->dataType);
704
+
705
+				if (Tca::table($dataType)->field($fieldName)->hasRelation()) {
706
+					if (MathUtility::canBeInterpretedAsInteger($operand)) {
707
+						$fieldNameAndPath = $fieldName . '.uid';
708
+					} else {
709
+						$foreignTableName = Tca::table($dataType)->field($fieldName)->getForeignTable();
710
+						$foreignTable = Tca::table($foreignTableName);
711
+						$fieldNameAndPath = $fieldName . '.' . $foreignTable->getLabelField();
712
+					}
713
+
714
+					// If different means we should restore the prepended path segment for proper SQL parser.
715
+					// This is TRUE for a composite field, e.g items.sys_file_metadata for categories.
716
+					if ($fieldName !== $fieldPath) {
717
+						$fieldNameAndPath = $fieldPath . '.' . $fieldNameAndPath;
718
+					}
719
+				}
720
+
721
+				$constraints[] = $query->$operator($fieldNameAndPath, $criterion['operand']);
722
+			}
723
+
724
+			$getLogicalSeparator = sprintf('getLogicalSeparatorFor%s', $operatorName);
725
+			$logical = $matcher->$getLogicalSeparator();
726
+			$result = $query->$logical($constraints);
727
+		}
728
+
729
+		return $result;
730
+	}
731
+
732
+	/**
733
+	 * @return \TYPO3\CMS\Core\DataHandling\DataHandler
734
+	 */
735
+	protected function getDataHandler()
736
+	{
737
+		if (!$this->dataHandler) {
738
+			$this->dataHandler = GeneralUtility::makeInstance('TYPO3\CMS\Core\DataHandling\DataHandler');
739
+		}
740
+		return $this->dataHandler;
741
+	}
742
+
743
+	/**
744
+	 * Handle the magic call by properly creating a Query object and returning its result.
745
+	 *
746
+	 * @param string $propertyName
747
+	 * @param string $value
748
+	 * @param string $flag
749
+	 * @return array
750
+	 */
751
+	protected function processMagicCall($propertyName, $value, $flag = '')
752
+	{
753
+
754
+		$fieldName = Property::name($propertyName)->of($this->dataType)->toFieldName();
755
+
756
+		/** @var $matcher Matcher */
757
+		$matcher = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Matcher', array(), $this->getDataType());
758
+
759
+		$table = Tca::table($this->dataType);
760
+		if ($table->field($fieldName)->isGroup()) {
761
+
762
+			$valueParts = explode('.', $value, 2);
763
+			$fieldName = $fieldName . '.' . $valueParts[0];
764
+			$value = $valueParts[1];
765
+		}
766
+
767
+		$matcher->equals($fieldName, $value);
768
+
769
+		if ($flag == 'count') {
770
+			$result = $this->countBy($matcher);
771
+		} else {
772
+			$result = $this->findBy($matcher);
773
+		}
774
+		return $flag == 'one' && !empty($result) ? reset($result) : $result;
775
+	}
776
+
777
+	/**
778
+	 * @return \Fab\Vidi\DataHandler\DataHandlerFactory
779
+	 */
780
+	protected function getDataHandlerFactory()
781
+	{
782
+		return GeneralUtility::makeInstance('Fab\Vidi\DataHandler\DataHandlerFactory');
783
+	}
784
+
785
+	/**
786
+	 * Returns whether the current mode is Backend
787
+	 *
788
+	 * @return bool
789
+	 */
790
+	protected function isBackendMode()
791
+	{
792
+		return TYPO3_MODE == 'BE';
793
+	}
794
+
795
+	/**
796
+	 * @return \Fab\Vidi\Resolver\FieldPathResolver
797
+	 */
798
+	protected function getFieldPathResolver()
799
+	{
800
+		return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
801
+	}
802
+
803
+	/**
804
+	 * @return \TYPO3\CMS\Extbase\Object\ObjectManager
805
+	 */
806
+	protected function getObjectManager()
807
+	{
808
+		return GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
809
+	}
810
+
811
+	/**
812
+	 * @return \Fab\Vidi\Domain\Validator\ContentValidator
813
+	 */
814
+	protected function getContentValidator()
815
+	{
816
+		return GeneralUtility::makeInstance('Fab\Vidi\Domain\Validator\ContentValidator');
817
+	}
818
+
819
+	/**
820
+	 * @return \Fab\Vidi\Domain\Validator\LanguageValidator
821
+	 */
822
+	protected function getLanguageValidator()
823
+	{
824
+		return GeneralUtility::makeInstance('Fab\Vidi\Domain\Validator\LanguageValidator');
825
+	}
826
+
827
+	/**
828
+	 * Signal that is called for post-processing the computed constraints object.
829
+	 *
830
+	 * @param Query $query
831
+	 * @param ConstraintInterface|NULL $constraints
832
+	 * @return ConstraintInterface|NULL $constraints
833
+	 * @signal
834
+	 */
835
+	protected function emitPostProcessConstraintsSignal(Query $query, $constraints)
836
+	{
837
+		$result = $this->getSignalSlotDispatcher()->dispatch(
838
+			'Fab\Vidi\Domain\Repository\ContentRepository',
839
+			'postProcessConstraintsObject',
840
+			array(
841
+				$query,
842
+				$constraints
843
+			)
844
+		);
845
+
846
+		return $result[1];
847
+	}
848
+
849
+	/**
850
+	 * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
851
+	 */
852
+	protected function getSignalSlotDispatcher()
853
+	{
854
+		return $this->getObjectManager()->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
855
+	}
856 856
 
857 857
 }
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
@@ -22,114 +22,114 @@
 block discarded – undo
22 22
 class GridAnalyserService
23 23
 {
24 24
 
25
-    /**
26
-     * Check relation for table.
27
-     *
28
-     * @param $tableName
29
-     * @return array
30
-     */
31
-    public function checkRelationForTable($tableName)
32
-    {
25
+	/**
26
+	 * Check relation for table.
27
+	 *
28
+	 * @param $tableName
29
+	 * @return array
30
+	 */
31
+	public function checkRelationForTable($tableName)
32
+	{
33 33
 
34
-        $relations = array();
35
-        $table = Tca::table($tableName);
34
+		$relations = array();
35
+		$table = Tca::table($tableName);
36 36
 
37
-        $missingOppositionRelationMessage = <<<EOF
37
+		$missingOppositionRelationMessage = <<<EOF
38 38
 
39 39
   WARNING! Could not define relation precisely. This is not necessarily a problem
40 40
   if the opposite relation is not required in a Grid. But consider adding the opposite
41 41
   TCA configuration if so.
42 42
 EOF;
43 43
 
44
-        foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) {
45
-
46
-            if ($table->hasField($fieldName)) {
47
-                if ($table->field($fieldName)->hasMany()) {
48
-                    if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
49
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values');
50
-                        $relations = array_merge($relations, $_relations);
51
-                    } elseif ($table->field($fieldName)->hasRelationManyToMany()) {
52
-                        $_relations = $this->checkRelationManyToMany($tableName, $fieldName);
53
-                        $relations = array_merge($relations, $_relations);
54
-
55
-                    } elseif ($table->field($fieldName)->hasRelationOneToMany()) {
56
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many');
57
-                        $relations = array_merge($relations, $_relations);
58
-                    } else {
59
-                        $relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage);
60
-                    }
61
-                    $relations[] = '';
62
-                } elseif ($table->field($fieldName)->hasOne()) {
63
-
64
-                    if ($table->field($fieldName)->hasRelationOneToOne()) {
65
-                        $relations[] = sprintf('* one-to-one "%s"', $fieldName);
66
-                    } elseif ($table->field($fieldName)->hasRelationManyToOne()) {
67
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one');
68
-                        $relations = array_merge($relations, $_relations);
69
-                    } else {
70
-                        $relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage);
71
-                    }
72
-                    $relations[] = '';
73
-                }
74
-            }
75
-        }
76
-        return $relations;
77
-    }
78
-
79
-    /**
80
-     * Convenience method for printing out relation many-to-many.
81
-     *
82
-     * @param string $tableName
83
-     * @param string $fieldName
84
-     * @return array
85
-     */
86
-    protected function checkRelationManyToMany($tableName, $fieldName)
87
-    {
88
-
89
-        $output = array();
90
-
91
-        $table = Tca::table($tableName);
92
-        $output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName);
93
-
94
-        $foreignTable = $table->field($fieldName)->getForeignTable();
95
-        $manyToManyTable = $table->field($fieldName)->getManyToManyTable();
96
-        $foreignField = $table->field($fieldName)->getForeignField();
97
-
98
-        if (!$foreignField) {
99
-            $output[] = sprintf('  ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName);
100
-        } elseif (!$foreignTable) {
101
-            $output[] = sprintf('  ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName);
102
-        } elseif (!$manyToManyTable) {
103
-            $output[] = sprintf('  ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName);
104
-        } else {
105
-            $output[] = sprintf('  %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField);
106
-        }
107
-
108
-        $output[] = '';
109
-        return $output;
110
-    }
111
-
112
-    /**
113
-     * Convenience method for printing out relation.
114
-     *
115
-     * @param string $tableName
116
-     * @param string $fieldName
117
-     * @param string $relationType
118
-     * @return array
119
-     */
120
-    protected function checkRelationOf($tableName, $fieldName, $relationType)
121
-    {
122
-
123
-        $output = array();
124
-
125
-        $table = Tca::table($tableName);
126
-        $output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType);
127
-
128
-        $foreignTable = $table->field($fieldName)->getForeignTable();
129
-        $foreignField = $table->field($fieldName)->getForeignField();
130
-        $output[] = sprintf('  %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField);
131
-        $output[] = '';
132
-
133
-        return $output;
134
-    }
44
+		foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) {
45
+
46
+			if ($table->hasField($fieldName)) {
47
+				if ($table->field($fieldName)->hasMany()) {
48
+					if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
49
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values');
50
+						$relations = array_merge($relations, $_relations);
51
+					} elseif ($table->field($fieldName)->hasRelationManyToMany()) {
52
+						$_relations = $this->checkRelationManyToMany($tableName, $fieldName);
53
+						$relations = array_merge($relations, $_relations);
54
+
55
+					} elseif ($table->field($fieldName)->hasRelationOneToMany()) {
56
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many');
57
+						$relations = array_merge($relations, $_relations);
58
+					} else {
59
+						$relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage);
60
+					}
61
+					$relations[] = '';
62
+				} elseif ($table->field($fieldName)->hasOne()) {
63
+
64
+					if ($table->field($fieldName)->hasRelationOneToOne()) {
65
+						$relations[] = sprintf('* one-to-one "%s"', $fieldName);
66
+					} elseif ($table->field($fieldName)->hasRelationManyToOne()) {
67
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one');
68
+						$relations = array_merge($relations, $_relations);
69
+					} else {
70
+						$relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage);
71
+					}
72
+					$relations[] = '';
73
+				}
74
+			}
75
+		}
76
+		return $relations;
77
+	}
78
+
79
+	/**
80
+	 * Convenience method for printing out relation many-to-many.
81
+	 *
82
+	 * @param string $tableName
83
+	 * @param string $fieldName
84
+	 * @return array
85
+	 */
86
+	protected function checkRelationManyToMany($tableName, $fieldName)
87
+	{
88
+
89
+		$output = array();
90
+
91
+		$table = Tca::table($tableName);
92
+		$output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName);
93
+
94
+		$foreignTable = $table->field($fieldName)->getForeignTable();
95
+		$manyToManyTable = $table->field($fieldName)->getManyToManyTable();
96
+		$foreignField = $table->field($fieldName)->getForeignField();
97
+
98
+		if (!$foreignField) {
99
+			$output[] = sprintf('  ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName);
100
+		} elseif (!$foreignTable) {
101
+			$output[] = sprintf('  ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName);
102
+		} elseif (!$manyToManyTable) {
103
+			$output[] = sprintf('  ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName);
104
+		} else {
105
+			$output[] = sprintf('  %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField);
106
+		}
107
+
108
+		$output[] = '';
109
+		return $output;
110
+	}
111
+
112
+	/**
113
+	 * Convenience method for printing out relation.
114
+	 *
115
+	 * @param string $tableName
116
+	 * @param string $fieldName
117
+	 * @param string $relationType
118
+	 * @return array
119
+	 */
120
+	protected function checkRelationOf($tableName, $fieldName, $relationType)
121
+	{
122
+
123
+		$output = array();
124
+
125
+		$table = Tca::table($tableName);
126
+		$output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType);
127
+
128
+		$foreignTable = $table->field($fieldName)->getForeignTable();
129
+		$foreignField = $table->field($fieldName)->getForeignField();
130
+		$output[] = sprintf('  %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField);
131
+		$output[] = '';
132
+
133
+		return $output;
134
+	}
135 135
 }
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
@@ -25,178 +25,178 @@
 block discarded – undo
25 25
 class LanguageService implements SingletonInterface
26 26
 {
27 27
 
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $languages;
32
-
33
-    /**
34
-     * @var array
35
-     */
36
-    protected $defaultIcon;
37
-
38
-    /**
39
-     * Store the localized records to boost up performance.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $localizedRecordStorage;
44
-
45
-    /**
46
-     * Returns available language records.
47
-     * The method stores the records in the property to speed up the process as the method can be often called.
48
-     *
49
-     * @return array
50
-     */
51
-    public function getLanguages()
52
-    {
53
-        if (is_null($this->languages)) {
54
-
55
-            $tableName = 'sys_language';
56
-
57
-            $clause = '1 = 1';
58
-            $clause .= BackendUtility::deleteClause($tableName);
59
-            $clause .= BackendUtility::BEenableFields($tableName);
60
-            $this->languages = $this->getDatabaseConnection()->exec_SELECTgetRows('*', $tableName, $clause);
61
-        }
62
-        return $this->languages;
63
-    }
64
-
65
-    /**
66
-     * Returns a localized record according to a Content object and a language identifier.
67
-     * Notice! This method does not overlay anything but simply returns the raw localized record.
68
-     *
69
-     * @param Content $object
70
-     * @param int $language
71
-     * @return Content
72
-     */
73
-    public function getLocalizedContent(Content $object, $language)
74
-    {
75
-
76
-        // We want to cache data per Content object. Retrieve the Object hash.
77
-        $objectHash = spl_object_hash($object);
78
-
79
-        // Initialize the storage
80
-        if (empty($this->localizedRecordStorage[$objectHash])) {
81
-            $this->localizedRecordStorage[$objectHash] = array();
82
-        }
83
-
84
-        if (empty($this->localizedRecordStorage[$objectHash][$language])) {
85
-
86
-            $clause = sprintf('%s = %s AND %s = %s',
87
-                Tca::table($object)->getLanguageParentField(), // e.g. l10n_parent
88
-                $object->getUid(),
89
-                Tca::table($object)->getLanguageField(), // e.g. sys_language_uid
90
-                $language
91
-            );
92
-
93
-            $clause .= BackendUtility::deleteClause($object->getDataType());
94
-            $localizedRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $object->getDataType(), $clause);
95
-
96
-            if ($localizedRecord) {
97
-                $localizedContent = GeneralUtility::makeInstance('Fab\Vidi\Domain\Model\Content', $object->getDataType(), $localizedRecord);
98
-                $this->localizedRecordStorage[$objectHash][$language] = $localizedContent;
99
-            } else {
100
-                $this->localizedRecordStorage[$objectHash][$language] = array(); // We want an array at least, even if empty.
101
-            }
102
-        }
103
-
104
-        return $this->localizedRecordStorage[$objectHash][$language];
105
-    }
106
-
107
-    /**
108
-     * Tell whether the given Content object has a localization.
109
-     *
110
-     * @param Content $object
111
-     * @param int $language
112
-     * @return string
113
-     */
114
-    public function hasLocalization(Content $object, $language)
115
-    {
116
-        $localizedRecord = $this->getLocalizedContent($object, $language);
117
-        return !empty($localizedRecord);
118
-    }
119
-
120
-    /**
121
-     * Returns a localized field according to a Content object and a language identifier.
122
-     * Notice! If there is not translation, simply returns an empty string.
123
-     *
124
-     * @param Content $object
125
-     * @param int $language
126
-     * @param string $fieldName
127
-     * @return string
128
-     */
129
-    public function getLocalizedFieldName(Content $object, $language, $fieldName)
130
-    {
131
-        $localizedRecord = $this->getLocalizedContent($object, $language);
132
-        return empty($localizedRecord) ? '' : $localizedRecord[$fieldName];
133
-    }
134
-
135
-    /**
136
-     * Returns the default language configured by TSConfig.
137
-     *
138
-     * @return array
139
-     */
140
-    public function getDefaultFlag()
141
-    {
142
-
143
-        if (is_null($this->defaultIcon)) {
144
-
145
-            $defaultFlag = ''; // default value
146
-
147
-            $tsConfig = BackendUtility::getModTSconfig(0, 'mod.SHARED');
148
-
149
-            // Fallback non sprite-configuration
150
-            if (($pos = strrpos($tsConfig['properties']['defaultLanguageFlag'], '.')) !== FALSE) {
151
-                $defaultFlag = substr($tsConfig['properties']['defaultLanguageFlag'], 0, $pos);
152
-            }
153
-
154
-            $this->defaultIcon = $defaultFlag;
155
-        }
156
-
157
-        return $this->defaultIcon;
158
-    }
159
-
160
-    /**
161
-     * Returns whether the system includes language records.
162
-     *
163
-     * @return bool
164
-     */
165
-    public function hasLanguages()
166
-    {
167
-        $languages = $this->getLanguages();
168
-        return !empty($languages);
169
-    }
170
-
171
-    /**
172
-     * Tell whether the given language exists.
173
-     *
174
-     * @param int $language
175
-     * @return bool
176
-     */
177
-    public function languageExists($language)
178
-    {
179
-        $languages = $this->getLanguages();
180
-
181
-        $LanguageExists = FALSE;
182
-        foreach ($languages as $_language) {
183
-            if ((int)$_language['uid'] === (int)$language) {
184
-                $LanguageExists = TRUE;
185
-                break;
186
-            }
187
-        }
188
-
189
-        return $LanguageExists;
190
-    }
191
-
192
-    /**
193
-     * Returns a pointer to the database.
194
-     *
195
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
196
-     */
197
-    protected function getDatabaseConnection()
198
-    {
199
-        return $GLOBALS['TYPO3_DB'];
200
-    }
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $languages;
32
+
33
+	/**
34
+	 * @var array
35
+	 */
36
+	protected $defaultIcon;
37
+
38
+	/**
39
+	 * Store the localized records to boost up performance.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $localizedRecordStorage;
44
+
45
+	/**
46
+	 * Returns available language records.
47
+	 * The method stores the records in the property to speed up the process as the method can be often called.
48
+	 *
49
+	 * @return array
50
+	 */
51
+	public function getLanguages()
52
+	{
53
+		if (is_null($this->languages)) {
54
+
55
+			$tableName = 'sys_language';
56
+
57
+			$clause = '1 = 1';
58
+			$clause .= BackendUtility::deleteClause($tableName);
59
+			$clause .= BackendUtility::BEenableFields($tableName);
60
+			$this->languages = $this->getDatabaseConnection()->exec_SELECTgetRows('*', $tableName, $clause);
61
+		}
62
+		return $this->languages;
63
+	}
64
+
65
+	/**
66
+	 * Returns a localized record according to a Content object and a language identifier.
67
+	 * Notice! This method does not overlay anything but simply returns the raw localized record.
68
+	 *
69
+	 * @param Content $object
70
+	 * @param int $language
71
+	 * @return Content
72
+	 */
73
+	public function getLocalizedContent(Content $object, $language)
74
+	{
75
+
76
+		// We want to cache data per Content object. Retrieve the Object hash.
77
+		$objectHash = spl_object_hash($object);
78
+
79
+		// Initialize the storage
80
+		if (empty($this->localizedRecordStorage[$objectHash])) {
81
+			$this->localizedRecordStorage[$objectHash] = array();
82
+		}
83
+
84
+		if (empty($this->localizedRecordStorage[$objectHash][$language])) {
85
+
86
+			$clause = sprintf('%s = %s AND %s = %s',
87
+				Tca::table($object)->getLanguageParentField(), // e.g. l10n_parent
88
+				$object->getUid(),
89
+				Tca::table($object)->getLanguageField(), // e.g. sys_language_uid
90
+				$language
91
+			);
92
+
93
+			$clause .= BackendUtility::deleteClause($object->getDataType());
94
+			$localizedRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $object->getDataType(), $clause);
95
+
96
+			if ($localizedRecord) {
97
+				$localizedContent = GeneralUtility::makeInstance('Fab\Vidi\Domain\Model\Content', $object->getDataType(), $localizedRecord);
98
+				$this->localizedRecordStorage[$objectHash][$language] = $localizedContent;
99
+			} else {
100
+				$this->localizedRecordStorage[$objectHash][$language] = array(); // We want an array at least, even if empty.
101
+			}
102
+		}
103
+
104
+		return $this->localizedRecordStorage[$objectHash][$language];
105
+	}
106
+
107
+	/**
108
+	 * Tell whether the given Content object has a localization.
109
+	 *
110
+	 * @param Content $object
111
+	 * @param int $language
112
+	 * @return string
113
+	 */
114
+	public function hasLocalization(Content $object, $language)
115
+	{
116
+		$localizedRecord = $this->getLocalizedContent($object, $language);
117
+		return !empty($localizedRecord);
118
+	}
119
+
120
+	/**
121
+	 * Returns a localized field according to a Content object and a language identifier.
122
+	 * Notice! If there is not translation, simply returns an empty string.
123
+	 *
124
+	 * @param Content $object
125
+	 * @param int $language
126
+	 * @param string $fieldName
127
+	 * @return string
128
+	 */
129
+	public function getLocalizedFieldName(Content $object, $language, $fieldName)
130
+	{
131
+		$localizedRecord = $this->getLocalizedContent($object, $language);
132
+		return empty($localizedRecord) ? '' : $localizedRecord[$fieldName];
133
+	}
134
+
135
+	/**
136
+	 * Returns the default language configured by TSConfig.
137
+	 *
138
+	 * @return array
139
+	 */
140
+	public function getDefaultFlag()
141
+	{
142
+
143
+		if (is_null($this->defaultIcon)) {
144
+
145
+			$defaultFlag = ''; // default value
146
+
147
+			$tsConfig = BackendUtility::getModTSconfig(0, 'mod.SHARED');
148
+
149
+			// Fallback non sprite-configuration
150
+			if (($pos = strrpos($tsConfig['properties']['defaultLanguageFlag'], '.')) !== FALSE) {
151
+				$defaultFlag = substr($tsConfig['properties']['defaultLanguageFlag'], 0, $pos);
152
+			}
153
+
154
+			$this->defaultIcon = $defaultFlag;
155
+		}
156
+
157
+		return $this->defaultIcon;
158
+	}
159
+
160
+	/**
161
+	 * Returns whether the system includes language records.
162
+	 *
163
+	 * @return bool
164
+	 */
165
+	public function hasLanguages()
166
+	{
167
+		$languages = $this->getLanguages();
168
+		return !empty($languages);
169
+	}
170
+
171
+	/**
172
+	 * Tell whether the given language exists.
173
+	 *
174
+	 * @param int $language
175
+	 * @return bool
176
+	 */
177
+	public function languageExists($language)
178
+	{
179
+		$languages = $this->getLanguages();
180
+
181
+		$LanguageExists = FALSE;
182
+		foreach ($languages as $_language) {
183
+			if ((int)$_language['uid'] === (int)$language) {
184
+				$LanguageExists = TRUE;
185
+				break;
186
+			}
187
+		}
188
+
189
+		return $LanguageExists;
190
+	}
191
+
192
+	/**
193
+	 * Returns a pointer to the database.
194
+	 *
195
+	 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
196
+	 */
197
+	protected function getDatabaseConnection()
198
+	{
199
+		return $GLOBALS['TYPO3_DB'];
200
+	}
201 201
 
202 202
 }
Please login to merge, or discard this patch.
Classes/Module/ModuleLoader.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -242,7 +242,7 @@
 block discarded – undo
242 242
     /**
243 243
      * Returns the current pid.
244 244
      *
245
-     * @return bool
245
+     * @return integer
246 246
      */
247 247
     public function getCurrentPid()
248 248
     {
Please login to merge, or discard this patch.
Indentation   +895 added lines, -895 removed lines patch added patch discarded remove patch
@@ -26,900 +26,900 @@
 block discarded – undo
26 26
 class ModuleLoader
27 27
 {
28 28
 
29
-    /**
30
-     * Define the default main module
31
-     */
32
-    const DEFAULT_MAIN_MODULE = 'content';
33
-
34
-    /**
35
-     * Define the default pid
36
-     */
37
-    const DEFAULT_PID = 0;
38
-
39
-    /**
40
-     * The type of data being listed (which corresponds to a table name in TCA)
41
-     *
42
-     * @var string
43
-     */
44
-    protected $dataType;
45
-
46
-    /**
47
-     * @var string
48
-     */
49
-    protected $defaultPid;
50
-
51
-    /**
52
-     * @var bool
53
-     */
54
-    protected $showPageTree;
55
-
56
-    /**
57
-     * @var bool
58
-     */
59
-    protected $isShown = TRUE;
60
-
61
-    /**
62
-     * @var string
63
-     */
64
-    protected $access = Access::USER;
65
-
66
-    /**
67
-     * @var string
68
-     */
69
-    protected $mainModule;
70
-
71
-    /**
72
-     * @var string
73
-     */
74
-    protected $position = '';
75
-
76
-    /**
77
-     * @var string
78
-     */
79
-    protected $icon = '';
80
-
81
-    /**
82
-     * @var string
83
-     */
84
-    protected $moduleLanguageFile = 'LLL:EXT:vidi/Resources/Private/Language/locallang_module.xlf';
85
-
86
-    /**
87
-     * The module key such as m1, m2.
88
-     *
89
-     * @var string
90
-     */
91
-    protected $moduleKey = 'm1';
92
-
93
-    /**
94
-     * @var string[]
95
-     */
96
-    protected $additionalJavaScriptFiles = array();
97
-
98
-    /**
99
-     * @var string[]
100
-     */
101
-    protected $additionalStyleSheetFiles = array();
102
-
103
-    /**
104
-     * @var array
105
-     */
106
-    protected $components = array(
107
-        ModulePosition::DOC_HEADER => array(
108
-            ModulePosition::TOP => array(
109
-                ModulePosition::LEFT => array(),
110
-                ModulePosition::RIGHT => array(
111
-                    'Fab\Vidi\View\Button\ToolButton',
112
-                ),
113
-            ),
114
-            ModulePosition::BOTTOM => array(
115
-                ModulePosition::LEFT => array(
116
-                    'Fab\Vidi\View\Button\NewButton',
117
-                    'Fab\Vidi\ViewHelpers\Link\BackViewHelper',
118
-                ),
119
-                ModulePosition::RIGHT => array(),
120
-            ),
121
-        ),
122
-        ModulePosition::GRID => array(
123
-            ModulePosition::TOP => array(
124
-                'Fab\Vidi\View\Check\PidCheck',
125
-                'Fab\Vidi\View\Check\RelationsCheck',
126
-                'Fab\Vidi\View\Tab\DataTypeTab',
127
-            ),
128
-            ModulePosition::BUTTONS => array(
129
-                'Fab\Vidi\View\Button\EditButton',
130
-                'Fab\Vidi\View\Button\DeleteButton',
131
-            ),
132
-            ModulePosition::BOTTOM => array(),
133
-        ),
134
-        ModulePosition::MENU_MASS_ACTION => array(
135
-            'Fab\Vidi\View\MenuItem\ExportXlsMenuItem',
136
-            'Fab\Vidi\View\MenuItem\ExportXmlMenuItem',
137
-            'Fab\Vidi\View\MenuItem\ExportCsvMenuItem',
138
-            'Fab\Vidi\View\MenuItem\DividerMenuItem',
139
-            'Fab\Vidi\View\MenuItem\MassDeleteMenuItem',
140
-            #'Fab\Vidi\View\MenuItem\MassEditMenuItem',
141
-        ),
142
-    );
143
-
144
-    /**
145
-     * @param string $dataType
146
-     */
147
-    public function __construct($dataType = NULL)
148
-    {
149
-        $this->dataType = $dataType;
150
-    }
151
-
152
-    /**
153
-     * Tell whether a module is already registered.
154
-     *
155
-     * @param string $dataType
156
-     * @return bool
157
-     */
158
-    public function isRegistered($dataType)
159
-    {
160
-        $internalModuleSignature = $this->getInternalModuleSignature($dataType);
161
-        return !empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]);
162
-    }
163
-
164
-    /**
165
-     * Register the module
166
-     *
167
-     * @return void
168
-     */
169
-    public function register()
170
-    {
171
-
172
-        $this->initializeDefaultValues();
173
-        $internalModuleSignature = $this->getInternalModuleSignature();
174
-
175
-        $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] = array();
176
-        $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['dataType'] = $this->dataType;
177
-        $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['mainModule'] = $this->mainModule;
178
-        $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['defaultPid'] = $this->defaultPid;
179
-        $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['additionalJavaScriptFiles'] = $this->additionalJavaScriptFiles;
180
-        $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['additionalStyleSheetFiles'] = $this->additionalStyleSheetFiles;
181
-        $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['components'] = $this->components;
182
-
183
-        // Register and displays module in the BE only if told, default is TRUE.
184
-        if ($this->isShown) {
185
-            $moduleConfiguration = array(
186
-                #'routeTarget' => \Fab\Vidi\Controller\Backend\ContentController::class . '::mainAction', // what to do here?
187
-                'access' => $this->access,
188
-                'labels' => $this->moduleLanguageFile,
189
-                'inheritNavigationComponentFromMainModule' => TRUE
190
-            );
191
-
192
-            if (!empty($this->icon)) {
193
-                $moduleConfiguration['icon'] = $this->icon;
194
-            }
195
-
196
-            if (!is_null($this->showPageTree)) {
197
-                if ($this->showPageTree) {
198
-                    $moduleConfiguration['navigationComponentId'] = 'typo3-pagetree';
199
-                } else {
200
-                    $moduleConfiguration['inheritNavigationComponentFromMainModule'] = FALSE;
201
-                }
202
-            }
203
-
204
-            ExtensionUtility::registerModule(
205
-                'Fab.vidi',
206
-                $this->mainModule,
207
-                $this->dataType . '_' . $this->moduleKey,
208
-                $this->position,
209
-                array(
210
-                    'Content' => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard',
211
-                    'Tool' => 'welcome, work',
212
-                    'Facet' => 'autoSuggest, autoSuggests',
213
-                    'Selection' => 'edit, update, create, delete, list, show',
214
-                    'UserPreferences' => 'save',
215
-                    'Clipboard' => 'save, flush, show',
216
-                ),
217
-                $moduleConfiguration
218
-            );
219
-        }
220
-    }
221
-
222
-    /**
223
-     * Return the module code for a BE module.
224
-     *
225
-     * @return string
226
-     */
227
-    public function getSignature()
228
-    {
229
-        return GeneralUtility::_GP(Parameter::MODULE);
230
-    }
231
-
232
-    /**
233
-     * Tell whether the current module is the list one.
234
-     *
235
-     * @return bool
236
-     */
237
-    public function copeWithPageTree()
238
-    {
239
-        return GeneralUtility::_GP(Parameter::MODULE) === 'web_VidiM1';
240
-    }
241
-
242
-    /**
243
-     * Returns the current pid.
244
-     *
245
-     * @return bool
246
-     */
247
-    public function getCurrentPid()
248
-    {
249
-        return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0;
250
-    }
251
-
252
-    /**
253
-     * Return the Vidi module code which is stored in TBE_MODULES_EXT
254
-     *
255
-     * @return string
256
-     */
257
-    public function getVidiModuleCode()
258
-    {
259
-
260
-        if ($this->copeWithPageTree()) {
261
-            $userPreferenceKey = sprintf('Vidi_pid_%s', $this->getCurrentPid());
262
-
263
-            if (GeneralUtility::_GP(Parameter::SUBMODULE)) {
264
-                $subModuleCode = GeneralUtility::_GP(Parameter::SUBMODULE);
265
-                BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $subModuleCode);
266
-            } else {
267
-
268
-                $defaultModuleCode = BackendUserPreferenceService::getInstance()->get($userPreferenceKey);
269
-                if (empty($defaultModuleCode)) {
270
-                    $defaultModuleCode = 'VidiTtContentM1'; // hard-coded submodule
271
-                    BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $defaultModuleCode);
272
-                }
273
-
274
-                $vidiModules = ModuleService::getInstance()->getModulesForCurrentPid();
275
-
276
-                if (empty($vidiModules)) {
277
-                    $subModuleCode = $defaultModuleCode;
278
-                } elseif (isset($vidiModules[$defaultModuleCode])) {
279
-                    $subModuleCode = $defaultModuleCode;
280
-                } else {
281
-                    $subModuleCode = ModuleService::getInstance()->getFirstModuleForPid($this->getCurrentPid());
282
-                }
283
-            }
284
-        } else {
285
-            $moduleCode = $this->getSignature();
286
-
287
-            // Remove first part which is separated "_"
288
-            $delimiter = strpos($moduleCode, '_') + 1;
289
-            $subModuleCode = substr($moduleCode, $delimiter);
290
-        }
291
-
292
-        return $subModuleCode;
293
-    }
294
-
295
-    /**
296
-     * Return the module URL.
297
-     *
298
-     * @param array $additionalParameters
299
-     * @param bool $absoluteUrl
300
-     * @return string
301
-     */
302
-    public function getModuleUrl(array $additionalParameters = array(), $absoluteUrl = false)
303
-    {
304
-        $moduleCode = $this->getSignature();
305
-
306
-        // Add possible submodule if current module has page tree.
307
-        if ($this->copeWithPageTree() && !isset($additionalParameters[Parameter::SUBMODULE])) {
308
-            $additionalParameters[Parameter::SUBMODULE] = $this->getVidiModuleCode();
309
-        }
310
-
311
-        // And don't forget the pid!
312
-        if (GeneralUtility::_GET(Parameter::PID)) {
313
-            $additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID);
314
-        }
315
-
316
-        $moduleUrl = BackendUtility::getModuleUrl($moduleCode, $additionalParameters, false, $absoluteUrl);
317
-        return $moduleUrl;
318
-    }
319
-
320
-    /**
321
-     * Return the module absolute URL.
322
-     *
323
-     * @param array $additionalParameters
324
-     * @return string
325
-     */
326
-    public function getModuleAbsoluteUrl(array $additionalParameters = array())
327
-    {
328
-        return $this->getModuleUrl($additionalParameters, true);
329
-    }
330
-
331
-    /**
332
-     * Return the parameter prefix for a BE module.
333
-     *
334
-     * @return string
335
-     */
336
-    public function getParameterPrefix()
337
-    {
338
-        return 'tx_vidi_' . strtolower($this->getSignature());
339
-    }
340
-
341
-    /**
342
-     * Return a configuration key or the entire module configuration array if not key is given.
343
-     *
344
-     * @param string $key
345
-     * @throws InvalidKeyInArrayException
346
-     * @return mixed
347
-     */
348
-    public function getModuleConfiguration($key = '')
349
-    {
350
-
351
-        $vidiModuleCode = $this->getVidiModuleCode();
352
-
353
-        // Module code must exist
354
-        if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) {
355
-            $message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode);
356
-            throw new InvalidKeyInArrayException($message, 1375092053);
357
-        }
358
-
359
-        $result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode];
360
-
361
-        if (!empty($key)) {
362
-            if (isset($result[$key])) {
363
-                $result = $result[$key];
364
-            } else {
365
-                // key must exist
366
-                $message = sprintf('Invalid key configuration "%s"', $key);
367
-                throw new InvalidKeyInArrayException($message, 1375092054);
368
-            }
369
-        }
370
-        return $result;
371
-    }
372
-
373
-    /**
374
-     * @param string $icon
375
-     * @return $this
376
-     */
377
-    public function setIcon($icon)
378
-    {
379
-        $this->icon = $icon;
380
-        return $this;
381
-    }
382
-
383
-    /**
384
-     * @return string
385
-     */
386
-    public function getIcon()
387
-    {
388
-        return $this->icon;
389
-    }
390
-
391
-    /**
392
-     * @param string $mainModule
393
-     * @return $this
394
-     */
395
-    public function setMainModule($mainModule)
396
-    {
397
-        $this->mainModule = $mainModule;
398
-        return $this;
399
-    }
400
-
401
-    /**
402
-     * @return string
403
-     */
404
-    public function getMainModule()
405
-    {
406
-        if (is_null($this->mainModule)) {
407
-            $this->mainModule = $this->getModuleConfiguration('mainModule');
408
-        }
409
-        return $this->mainModule;
410
-    }
411
-
412
-    /**
413
-     * @param string $moduleLanguageFile
414
-     * @return $this
415
-     */
416
-    public function setModuleLanguageFile($moduleLanguageFile)
417
-    {
418
-        $this->moduleLanguageFile = $moduleLanguageFile;
419
-        return $this;
420
-    }
421
-
422
-    /**
423
-     * @return string
424
-     */
425
-    public function getModuleLanguageFile()
426
-    {
427
-        return $this->moduleLanguageFile;
428
-    }
429
-
430
-    /**
431
-     * @param string $position
432
-     * @return $this
433
-     */
434
-    public function setPosition($position)
435
-    {
436
-        $this->position = $position;
437
-        return $this;
438
-    }
439
-
440
-    /**
441
-     * @return string
442
-     */
443
-    public function getPosition()
444
-    {
445
-        return $this->position;
446
-    }
447
-
448
-    /**
449
-     * @param array $files
450
-     * @return $this
451
-     */
452
-    public function addJavaScriptFiles(array $files)
453
-    {
454
-        foreach ($files as $file) {
455
-            $this->additionalJavaScriptFiles[] = $file;
456
-        }
457
-        return $this;
458
-    }
459
-
460
-    /**
461
-     * @param string $fileNameAndPath
462
-     * @return $this
463
-     */
464
-    public function addJavaScriptFile($fileNameAndPath)
465
-    {
466
-        $this->additionalJavaScriptFiles[] = $fileNameAndPath;
467
-        return $this;
468
-    }
469
-
470
-    /**
471
-     * @param array $files
472
-     * @return $this
473
-     */
474
-    public function addStyleSheetFiles(array $files)
475
-    {
476
-        foreach ($files as $file) {
477
-            $this->additionalStyleSheetFiles[] = $file;
478
-        }
479
-        return $this;
480
-    }
481
-
482
-    /**
483
-     * @param string $fileNameAndPath
484
-     * @return $this
485
-     */
486
-    public function addStyleSheetFile($fileNameAndPath)
487
-    {
488
-        $this->additionalStyleSheetFiles[] = $fileNameAndPath;
489
-        return $this;
490
-    }
491
-
492
-    /**
493
-     * @return string
494
-     */
495
-    public function getDataType()
496
-    {
497
-        if (is_null($this->dataType)) {
498
-            $this->dataType = $this->getModuleConfiguration('dataType');
499
-        }
500
-        return $this->dataType;
501
-    }
502
-
503
-    /**
504
-     * @return array
505
-     */
506
-    public function getDataTypes()
507
-    {
508
-        $dataTypes = array();
509
-        foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) {
510
-            $dataTypes[] = $module['dataType'];
511
-        }
512
-        return $dataTypes;
513
-    }
514
-
515
-    /**
516
-     * @param string $dataType
517
-     * @return $this
518
-     */
519
-    public function setDataType($dataType)
520
-    {
521
-        $this->dataType = $dataType;
522
-        return $this;
523
-    }
524
-
525
-    /**
526
-     * @return string
527
-     */
528
-    public function getDefaultPid()
529
-    {
530
-        if (empty($this->defaultPid)) {
531
-            $this->defaultPid = $this->getModuleConfiguration('defaultPid');
532
-        }
533
-        return $this->defaultPid;
534
-    }
535
-
536
-    /**
537
-     * @param string $defaultPid
538
-     * @return $this
539
-     */
540
-    public function setDefaultPid($defaultPid)
541
-    {
542
-        $this->defaultPid = $defaultPid;
543
-        return $this;
544
-    }
545
-
546
-    /**
547
-     * @param bool $isPageTreeShown
548
-     * @return $this
549
-     */
550
-    public function showPageTree($isPageTreeShown)
551
-    {
552
-        $this->showPageTree = $isPageTreeShown;
553
-        return $this;
554
-    }
555
-
556
-    /**
557
-     * @param string $isShown
558
-     * @return $this
559
-     */
560
-    public function isShown($isShown)
561
-    {
562
-        $this->isShown = $isShown;
563
-        return $this;
564
-    }
565
-
566
-    /**
567
-     * @return $array
568
-     */
569
-    public function getDocHeaderTopLeftComponents()
570
-    {
571
-        $configuration = $this->getModuleConfiguration();
572
-        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
573
-    }
574
-
575
-    /**
576
-     * @param array $components
577
-     * @return $this
578
-     */
579
-    public function setDocHeaderTopLeftComponents(array $components)
580
-    {
581
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components;
582
-        return $this;
583
-    }
584
-
585
-    /**
586
-     * @param string|array $components
587
-     * @return $this
588
-     */
589
-    public function addDocHeaderTopLeftComponents($components)
590
-    {
591
-        if (is_string($components)) {
592
-            $components = array($components);
593
-        }
594
-        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
595
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components);
596
-        return $this;
597
-    }
598
-
599
-    /**
600
-     * @return $array
601
-     */
602
-    public function getDocHeaderTopRightComponents()
603
-    {
604
-        $configuration = $this->getModuleConfiguration();
605
-        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
606
-    }
607
-
608
-    /**
609
-     * @param array $components
610
-     * @return $this
611
-     */
612
-    public function setDocHeaderTopRightComponents(array $components)
613
-    {
614
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components;
615
-        return $this;
616
-    }
617
-
618
-    /**
619
-     * @param string|array $components
620
-     * @return $this
621
-     */
622
-    public function addDocHeaderTopRightComponents($components)
623
-    {
624
-        if (is_string($components)) {
625
-            $components = array($components);
626
-        }
627
-        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
628
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
629
-        return $this;
630
-    }
631
-
632
-    /**
633
-     * @return $array
634
-     */
635
-    public function getDocHeaderBottomLeftComponents()
636
-    {
637
-        $configuration = $this->getModuleConfiguration();
638
-        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
639
-    }
640
-
641
-    /**
642
-     * @param array $components
643
-     * @return $this
644
-     */
645
-    public function setDocHeaderBottomLeftComponents(array $components)
646
-    {
647
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components;
648
-        return $this;
649
-    }
650
-
651
-    /**
652
-     * @param string|array $components
653
-     * @return $this
654
-     */
655
-    public function addDocHeaderBottomLeftComponents($components)
656
-    {
657
-        if (is_string($components)) {
658
-            $components = array($components);
659
-        }
660
-        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
661
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components);
662
-        return $this;
663
-    }
664
-
665
-    /**
666
-     * @return $array
667
-     */
668
-    public function getDocHeaderBottomRightComponents()
669
-    {
670
-        $configuration = $this->getModuleConfiguration();
671
-        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
672
-    }
673
-
674
-    /**
675
-     * @param array $components
676
-     * @return $this
677
-     */
678
-    public function setDocHeaderBottomRightComponents(array $components)
679
-    {
680
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components;
681
-        return $this;
682
-    }
683
-
684
-    /**
685
-     * @param string|array $components
686
-     * @return $this
687
-     */
688
-    public function addDocHeaderBottomRightComponents($components)
689
-    {
690
-        if (is_string($components)) {
691
-            $components = array($components);
692
-        }
693
-        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
694
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
695
-        return $this;
696
-    }
697
-
698
-    /**
699
-     * @return $array
700
-     */
701
-    public function getGridTopComponents()
702
-    {
703
-        $configuration = $this->getModuleConfiguration();
704
-        return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP];
705
-    }
706
-
707
-    /**
708
-     * @param array $components
709
-     * @return $this
710
-     */
711
-    public function setGridTopComponents(array $components)
712
-    {
713
-        $this->components[ModulePosition::GRID][ModulePosition::TOP] = $components;
714
-        return $this;
715
-    }
716
-
717
-    /**
718
-     * @param string|array $components
719
-     * @return $this
720
-     */
721
-    public function addGridTopComponents($components)
722
-    {
723
-        if (is_string($components)) {
724
-            $components = array($components);
725
-        }
726
-        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP];
727
-        $this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components);
728
-        return $this;
729
-    }
730
-
731
-    /**
732
-     * @return $array
733
-     */
734
-    public function getGridBottomComponents()
735
-    {
736
-        $configuration = $this->getModuleConfiguration();
737
-        return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM];
738
-    }
739
-
740
-    /**
741
-     * @param array $components
742
-     * @return $this
743
-     */
744
-    public function setGridBottomComponents(array $components)
745
-    {
746
-        $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components;
747
-        return $this;
748
-    }
749
-
750
-    /**
751
-     * @param string|array $components
752
-     * @return $this
753
-     */
754
-    public function addGridBottomComponents($components)
755
-    {
756
-        if (is_string($components)) {
757
-            $components = array($components);
758
-        }
759
-        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM];
760
-        $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components);
761
-        return $this;
762
-    }
763
-
764
-    /**
765
-     * @return $array
766
-     */
767
-    public function getGridButtonsComponents()
768
-    {
769
-        $configuration = $this->getModuleConfiguration();
770
-        return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS];
771
-    }
772
-
773
-    /**
774
-     * @param array $components
775
-     * @return $this
776
-     */
777
-    public function setGridButtonsComponents(array $components)
778
-    {
779
-        $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components;
780
-        return $this;
781
-    }
782
-
783
-    /**
784
-     * @param string|array $components
785
-     * @return $this
786
-     */
787
-    public function addGridButtonsComponents($components)
788
-    {
789
-        if (is_string($components)) {
790
-            $components = array($components);
791
-        }
792
-        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS];
793
-        $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($currentComponents, $components);
794
-        return $this;
795
-    }
796
-
797
-    /**
798
-     * @return $array
799
-     */
800
-    public function getMenuMassActionComponents()
801
-    {
802
-        $configuration = $this->getModuleConfiguration();
803
-        return $configuration['components'][ModulePosition::MENU_MASS_ACTION];
804
-    }
805
-
806
-    /**
807
-     * @param array $components
808
-     * @return $this
809
-     */
810
-    public function setMenuMassActionComponents(array $components)
811
-    {
812
-        $this->components[ModulePosition::MENU_MASS_ACTION] = $components;
813
-        return $this;
814
-    }
815
-
816
-    /**
817
-     * @param string|array $components
818
-     * @return $this
819
-     */
820
-    public function addMenuMassActionComponents($components)
821
-    {
822
-        if (is_string($components)) {
823
-            $components = array($components);
824
-        }
825
-        $currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION];
826
-        $this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($currentComponents, $components);
827
-        return $this;
828
-    }
829
-
830
-    /**
831
-     * @return string
832
-     */
833
-    public function getAccess()
834
-    {
835
-        return $this->access;
836
-    }
837
-
838
-    /**
839
-     * @param string $access
840
-     * @return $this
841
-     */
842
-    public function setAccess($access)
843
-    {
844
-        $this->access = $access;
845
-        return $this;
846
-    }
847
-
848
-    /**
849
-     * @return \string[]
850
-     */
851
-    public function getAdditionalJavaScriptFiles()
852
-    {
853
-        if (empty($this->additionalJavaScriptFiles)) {
854
-            $this->additionalJavaScriptFiles = $this->getModuleConfiguration('additionalJavaScriptFiles');
855
-        }
856
-        return $this->additionalJavaScriptFiles;
857
-    }
858
-
859
-    /**
860
-     * @return \string[]
861
-     */
862
-    public function getAdditionalStyleSheetFiles()
863
-    {
864
-        if (empty($this->additionalStyleSheetFiles)) {
865
-            $this->additionalStyleSheetFiles = $this->getModuleConfiguration('additionalStyleSheetFiles');
866
-        }
867
-        return $this->additionalStyleSheetFiles;
868
-    }
869
-
870
-    /**
871
-     * @return array
872
-     */
873
-    public function getComponents()
874
-    {
875
-        return $this->components;
876
-    }
877
-
878
-    /**
879
-     * @param string $pluginName
880
-     * @return bool
881
-     */
882
-    public function hasPlugin($pluginName = '')
883
-    {
884
-        $parameterPrefix = $this->getParameterPrefix();
885
-        $parameters = GeneralUtility::_GET($parameterPrefix);
886
-
887
-        $hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']);
888
-        if ($hasPlugin && $pluginName) {
889
-            $hasPlugin = in_array($pluginName, $parameters['plugins']);
890
-        }
891
-        return $hasPlugin;
892
-    }
893
-
894
-    /**
895
-     * Compute the internal module code
896
-     *
897
-     * @param NULL|string $dataType
898
-     * @return string
899
-     */
900
-    protected function getInternalModuleSignature($dataType = NULL)
901
-    {
902
-        if (is_null($dataType)) {
903
-            $dataType = $this->dataType;
904
-        }
905
-        $subModuleName = $dataType . '_' . $this->moduleKey;
906
-        return 'Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName);
907
-    }
908
-
909
-    /**
910
-     * Make sure default values are correctly initialized for the module.
911
-     *
912
-     * @return void
913
-     */
914
-    protected function initializeDefaultValues()
915
-    {
916
-        if (is_null($this->mainModule)) {
917
-            $this->mainModule = self::DEFAULT_MAIN_MODULE;
918
-        }
919
-
920
-        if (is_null($this->defaultPid)) {
921
-            $this->defaultPid = self::DEFAULT_PID;
922
-        }
923
-    }
29
+	/**
30
+	 * Define the default main module
31
+	 */
32
+	const DEFAULT_MAIN_MODULE = 'content';
33
+
34
+	/**
35
+	 * Define the default pid
36
+	 */
37
+	const DEFAULT_PID = 0;
38
+
39
+	/**
40
+	 * The type of data being listed (which corresponds to a table name in TCA)
41
+	 *
42
+	 * @var string
43
+	 */
44
+	protected $dataType;
45
+
46
+	/**
47
+	 * @var string
48
+	 */
49
+	protected $defaultPid;
50
+
51
+	/**
52
+	 * @var bool
53
+	 */
54
+	protected $showPageTree;
55
+
56
+	/**
57
+	 * @var bool
58
+	 */
59
+	protected $isShown = TRUE;
60
+
61
+	/**
62
+	 * @var string
63
+	 */
64
+	protected $access = Access::USER;
65
+
66
+	/**
67
+	 * @var string
68
+	 */
69
+	protected $mainModule;
70
+
71
+	/**
72
+	 * @var string
73
+	 */
74
+	protected $position = '';
75
+
76
+	/**
77
+	 * @var string
78
+	 */
79
+	protected $icon = '';
80
+
81
+	/**
82
+	 * @var string
83
+	 */
84
+	protected $moduleLanguageFile = 'LLL:EXT:vidi/Resources/Private/Language/locallang_module.xlf';
85
+
86
+	/**
87
+	 * The module key such as m1, m2.
88
+	 *
89
+	 * @var string
90
+	 */
91
+	protected $moduleKey = 'm1';
92
+
93
+	/**
94
+	 * @var string[]
95
+	 */
96
+	protected $additionalJavaScriptFiles = array();
97
+
98
+	/**
99
+	 * @var string[]
100
+	 */
101
+	protected $additionalStyleSheetFiles = array();
102
+
103
+	/**
104
+	 * @var array
105
+	 */
106
+	protected $components = array(
107
+		ModulePosition::DOC_HEADER => array(
108
+			ModulePosition::TOP => array(
109
+				ModulePosition::LEFT => array(),
110
+				ModulePosition::RIGHT => array(
111
+					'Fab\Vidi\View\Button\ToolButton',
112
+				),
113
+			),
114
+			ModulePosition::BOTTOM => array(
115
+				ModulePosition::LEFT => array(
116
+					'Fab\Vidi\View\Button\NewButton',
117
+					'Fab\Vidi\ViewHelpers\Link\BackViewHelper',
118
+				),
119
+				ModulePosition::RIGHT => array(),
120
+			),
121
+		),
122
+		ModulePosition::GRID => array(
123
+			ModulePosition::TOP => array(
124
+				'Fab\Vidi\View\Check\PidCheck',
125
+				'Fab\Vidi\View\Check\RelationsCheck',
126
+				'Fab\Vidi\View\Tab\DataTypeTab',
127
+			),
128
+			ModulePosition::BUTTONS => array(
129
+				'Fab\Vidi\View\Button\EditButton',
130
+				'Fab\Vidi\View\Button\DeleteButton',
131
+			),
132
+			ModulePosition::BOTTOM => array(),
133
+		),
134
+		ModulePosition::MENU_MASS_ACTION => array(
135
+			'Fab\Vidi\View\MenuItem\ExportXlsMenuItem',
136
+			'Fab\Vidi\View\MenuItem\ExportXmlMenuItem',
137
+			'Fab\Vidi\View\MenuItem\ExportCsvMenuItem',
138
+			'Fab\Vidi\View\MenuItem\DividerMenuItem',
139
+			'Fab\Vidi\View\MenuItem\MassDeleteMenuItem',
140
+			#'Fab\Vidi\View\MenuItem\MassEditMenuItem',
141
+		),
142
+	);
143
+
144
+	/**
145
+	 * @param string $dataType
146
+	 */
147
+	public function __construct($dataType = NULL)
148
+	{
149
+		$this->dataType = $dataType;
150
+	}
151
+
152
+	/**
153
+	 * Tell whether a module is already registered.
154
+	 *
155
+	 * @param string $dataType
156
+	 * @return bool
157
+	 */
158
+	public function isRegistered($dataType)
159
+	{
160
+		$internalModuleSignature = $this->getInternalModuleSignature($dataType);
161
+		return !empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]);
162
+	}
163
+
164
+	/**
165
+	 * Register the module
166
+	 *
167
+	 * @return void
168
+	 */
169
+	public function register()
170
+	{
171
+
172
+		$this->initializeDefaultValues();
173
+		$internalModuleSignature = $this->getInternalModuleSignature();
174
+
175
+		$GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] = array();
176
+		$GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['dataType'] = $this->dataType;
177
+		$GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['mainModule'] = $this->mainModule;
178
+		$GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['defaultPid'] = $this->defaultPid;
179
+		$GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['additionalJavaScriptFiles'] = $this->additionalJavaScriptFiles;
180
+		$GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['additionalStyleSheetFiles'] = $this->additionalStyleSheetFiles;
181
+		$GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['components'] = $this->components;
182
+
183
+		// Register and displays module in the BE only if told, default is TRUE.
184
+		if ($this->isShown) {
185
+			$moduleConfiguration = array(
186
+				#'routeTarget' => \Fab\Vidi\Controller\Backend\ContentController::class . '::mainAction', // what to do here?
187
+				'access' => $this->access,
188
+				'labels' => $this->moduleLanguageFile,
189
+				'inheritNavigationComponentFromMainModule' => TRUE
190
+			);
191
+
192
+			if (!empty($this->icon)) {
193
+				$moduleConfiguration['icon'] = $this->icon;
194
+			}
195
+
196
+			if (!is_null($this->showPageTree)) {
197
+				if ($this->showPageTree) {
198
+					$moduleConfiguration['navigationComponentId'] = 'typo3-pagetree';
199
+				} else {
200
+					$moduleConfiguration['inheritNavigationComponentFromMainModule'] = FALSE;
201
+				}
202
+			}
203
+
204
+			ExtensionUtility::registerModule(
205
+				'Fab.vidi',
206
+				$this->mainModule,
207
+				$this->dataType . '_' . $this->moduleKey,
208
+				$this->position,
209
+				array(
210
+					'Content' => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard',
211
+					'Tool' => 'welcome, work',
212
+					'Facet' => 'autoSuggest, autoSuggests',
213
+					'Selection' => 'edit, update, create, delete, list, show',
214
+					'UserPreferences' => 'save',
215
+					'Clipboard' => 'save, flush, show',
216
+				),
217
+				$moduleConfiguration
218
+			);
219
+		}
220
+	}
221
+
222
+	/**
223
+	 * Return the module code for a BE module.
224
+	 *
225
+	 * @return string
226
+	 */
227
+	public function getSignature()
228
+	{
229
+		return GeneralUtility::_GP(Parameter::MODULE);
230
+	}
231
+
232
+	/**
233
+	 * Tell whether the current module is the list one.
234
+	 *
235
+	 * @return bool
236
+	 */
237
+	public function copeWithPageTree()
238
+	{
239
+		return GeneralUtility::_GP(Parameter::MODULE) === 'web_VidiM1';
240
+	}
241
+
242
+	/**
243
+	 * Returns the current pid.
244
+	 *
245
+	 * @return bool
246
+	 */
247
+	public function getCurrentPid()
248
+	{
249
+		return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0;
250
+	}
251
+
252
+	/**
253
+	 * Return the Vidi module code which is stored in TBE_MODULES_EXT
254
+	 *
255
+	 * @return string
256
+	 */
257
+	public function getVidiModuleCode()
258
+	{
259
+
260
+		if ($this->copeWithPageTree()) {
261
+			$userPreferenceKey = sprintf('Vidi_pid_%s', $this->getCurrentPid());
262
+
263
+			if (GeneralUtility::_GP(Parameter::SUBMODULE)) {
264
+				$subModuleCode = GeneralUtility::_GP(Parameter::SUBMODULE);
265
+				BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $subModuleCode);
266
+			} else {
267
+
268
+				$defaultModuleCode = BackendUserPreferenceService::getInstance()->get($userPreferenceKey);
269
+				if (empty($defaultModuleCode)) {
270
+					$defaultModuleCode = 'VidiTtContentM1'; // hard-coded submodule
271
+					BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $defaultModuleCode);
272
+				}
273
+
274
+				$vidiModules = ModuleService::getInstance()->getModulesForCurrentPid();
275
+
276
+				if (empty($vidiModules)) {
277
+					$subModuleCode = $defaultModuleCode;
278
+				} elseif (isset($vidiModules[$defaultModuleCode])) {
279
+					$subModuleCode = $defaultModuleCode;
280
+				} else {
281
+					$subModuleCode = ModuleService::getInstance()->getFirstModuleForPid($this->getCurrentPid());
282
+				}
283
+			}
284
+		} else {
285
+			$moduleCode = $this->getSignature();
286
+
287
+			// Remove first part which is separated "_"
288
+			$delimiter = strpos($moduleCode, '_') + 1;
289
+			$subModuleCode = substr($moduleCode, $delimiter);
290
+		}
291
+
292
+		return $subModuleCode;
293
+	}
294
+
295
+	/**
296
+	 * Return the module URL.
297
+	 *
298
+	 * @param array $additionalParameters
299
+	 * @param bool $absoluteUrl
300
+	 * @return string
301
+	 */
302
+	public function getModuleUrl(array $additionalParameters = array(), $absoluteUrl = false)
303
+	{
304
+		$moduleCode = $this->getSignature();
305
+
306
+		// Add possible submodule if current module has page tree.
307
+		if ($this->copeWithPageTree() && !isset($additionalParameters[Parameter::SUBMODULE])) {
308
+			$additionalParameters[Parameter::SUBMODULE] = $this->getVidiModuleCode();
309
+		}
310
+
311
+		// And don't forget the pid!
312
+		if (GeneralUtility::_GET(Parameter::PID)) {
313
+			$additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID);
314
+		}
315
+
316
+		$moduleUrl = BackendUtility::getModuleUrl($moduleCode, $additionalParameters, false, $absoluteUrl);
317
+		return $moduleUrl;
318
+	}
319
+
320
+	/**
321
+	 * Return the module absolute URL.
322
+	 *
323
+	 * @param array $additionalParameters
324
+	 * @return string
325
+	 */
326
+	public function getModuleAbsoluteUrl(array $additionalParameters = array())
327
+	{
328
+		return $this->getModuleUrl($additionalParameters, true);
329
+	}
330
+
331
+	/**
332
+	 * Return the parameter prefix for a BE module.
333
+	 *
334
+	 * @return string
335
+	 */
336
+	public function getParameterPrefix()
337
+	{
338
+		return 'tx_vidi_' . strtolower($this->getSignature());
339
+	}
340
+
341
+	/**
342
+	 * Return a configuration key or the entire module configuration array if not key is given.
343
+	 *
344
+	 * @param string $key
345
+	 * @throws InvalidKeyInArrayException
346
+	 * @return mixed
347
+	 */
348
+	public function getModuleConfiguration($key = '')
349
+	{
350
+
351
+		$vidiModuleCode = $this->getVidiModuleCode();
352
+
353
+		// Module code must exist
354
+		if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) {
355
+			$message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode);
356
+			throw new InvalidKeyInArrayException($message, 1375092053);
357
+		}
358
+
359
+		$result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode];
360
+
361
+		if (!empty($key)) {
362
+			if (isset($result[$key])) {
363
+				$result = $result[$key];
364
+			} else {
365
+				// key must exist
366
+				$message = sprintf('Invalid key configuration "%s"', $key);
367
+				throw new InvalidKeyInArrayException($message, 1375092054);
368
+			}
369
+		}
370
+		return $result;
371
+	}
372
+
373
+	/**
374
+	 * @param string $icon
375
+	 * @return $this
376
+	 */
377
+	public function setIcon($icon)
378
+	{
379
+		$this->icon = $icon;
380
+		return $this;
381
+	}
382
+
383
+	/**
384
+	 * @return string
385
+	 */
386
+	public function getIcon()
387
+	{
388
+		return $this->icon;
389
+	}
390
+
391
+	/**
392
+	 * @param string $mainModule
393
+	 * @return $this
394
+	 */
395
+	public function setMainModule($mainModule)
396
+	{
397
+		$this->mainModule = $mainModule;
398
+		return $this;
399
+	}
400
+
401
+	/**
402
+	 * @return string
403
+	 */
404
+	public function getMainModule()
405
+	{
406
+		if (is_null($this->mainModule)) {
407
+			$this->mainModule = $this->getModuleConfiguration('mainModule');
408
+		}
409
+		return $this->mainModule;
410
+	}
411
+
412
+	/**
413
+	 * @param string $moduleLanguageFile
414
+	 * @return $this
415
+	 */
416
+	public function setModuleLanguageFile($moduleLanguageFile)
417
+	{
418
+		$this->moduleLanguageFile = $moduleLanguageFile;
419
+		return $this;
420
+	}
421
+
422
+	/**
423
+	 * @return string
424
+	 */
425
+	public function getModuleLanguageFile()
426
+	{
427
+		return $this->moduleLanguageFile;
428
+	}
429
+
430
+	/**
431
+	 * @param string $position
432
+	 * @return $this
433
+	 */
434
+	public function setPosition($position)
435
+	{
436
+		$this->position = $position;
437
+		return $this;
438
+	}
439
+
440
+	/**
441
+	 * @return string
442
+	 */
443
+	public function getPosition()
444
+	{
445
+		return $this->position;
446
+	}
447
+
448
+	/**
449
+	 * @param array $files
450
+	 * @return $this
451
+	 */
452
+	public function addJavaScriptFiles(array $files)
453
+	{
454
+		foreach ($files as $file) {
455
+			$this->additionalJavaScriptFiles[] = $file;
456
+		}
457
+		return $this;
458
+	}
459
+
460
+	/**
461
+	 * @param string $fileNameAndPath
462
+	 * @return $this
463
+	 */
464
+	public function addJavaScriptFile($fileNameAndPath)
465
+	{
466
+		$this->additionalJavaScriptFiles[] = $fileNameAndPath;
467
+		return $this;
468
+	}
469
+
470
+	/**
471
+	 * @param array $files
472
+	 * @return $this
473
+	 */
474
+	public function addStyleSheetFiles(array $files)
475
+	{
476
+		foreach ($files as $file) {
477
+			$this->additionalStyleSheetFiles[] = $file;
478
+		}
479
+		return $this;
480
+	}
481
+
482
+	/**
483
+	 * @param string $fileNameAndPath
484
+	 * @return $this
485
+	 */
486
+	public function addStyleSheetFile($fileNameAndPath)
487
+	{
488
+		$this->additionalStyleSheetFiles[] = $fileNameAndPath;
489
+		return $this;
490
+	}
491
+
492
+	/**
493
+	 * @return string
494
+	 */
495
+	public function getDataType()
496
+	{
497
+		if (is_null($this->dataType)) {
498
+			$this->dataType = $this->getModuleConfiguration('dataType');
499
+		}
500
+		return $this->dataType;
501
+	}
502
+
503
+	/**
504
+	 * @return array
505
+	 */
506
+	public function getDataTypes()
507
+	{
508
+		$dataTypes = array();
509
+		foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) {
510
+			$dataTypes[] = $module['dataType'];
511
+		}
512
+		return $dataTypes;
513
+	}
514
+
515
+	/**
516
+	 * @param string $dataType
517
+	 * @return $this
518
+	 */
519
+	public function setDataType($dataType)
520
+	{
521
+		$this->dataType = $dataType;
522
+		return $this;
523
+	}
524
+
525
+	/**
526
+	 * @return string
527
+	 */
528
+	public function getDefaultPid()
529
+	{
530
+		if (empty($this->defaultPid)) {
531
+			$this->defaultPid = $this->getModuleConfiguration('defaultPid');
532
+		}
533
+		return $this->defaultPid;
534
+	}
535
+
536
+	/**
537
+	 * @param string $defaultPid
538
+	 * @return $this
539
+	 */
540
+	public function setDefaultPid($defaultPid)
541
+	{
542
+		$this->defaultPid = $defaultPid;
543
+		return $this;
544
+	}
545
+
546
+	/**
547
+	 * @param bool $isPageTreeShown
548
+	 * @return $this
549
+	 */
550
+	public function showPageTree($isPageTreeShown)
551
+	{
552
+		$this->showPageTree = $isPageTreeShown;
553
+		return $this;
554
+	}
555
+
556
+	/**
557
+	 * @param string $isShown
558
+	 * @return $this
559
+	 */
560
+	public function isShown($isShown)
561
+	{
562
+		$this->isShown = $isShown;
563
+		return $this;
564
+	}
565
+
566
+	/**
567
+	 * @return $array
568
+	 */
569
+	public function getDocHeaderTopLeftComponents()
570
+	{
571
+		$configuration = $this->getModuleConfiguration();
572
+		return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
573
+	}
574
+
575
+	/**
576
+	 * @param array $components
577
+	 * @return $this
578
+	 */
579
+	public function setDocHeaderTopLeftComponents(array $components)
580
+	{
581
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components;
582
+		return $this;
583
+	}
584
+
585
+	/**
586
+	 * @param string|array $components
587
+	 * @return $this
588
+	 */
589
+	public function addDocHeaderTopLeftComponents($components)
590
+	{
591
+		if (is_string($components)) {
592
+			$components = array($components);
593
+		}
594
+		$currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
595
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components);
596
+		return $this;
597
+	}
598
+
599
+	/**
600
+	 * @return $array
601
+	 */
602
+	public function getDocHeaderTopRightComponents()
603
+	{
604
+		$configuration = $this->getModuleConfiguration();
605
+		return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
606
+	}
607
+
608
+	/**
609
+	 * @param array $components
610
+	 * @return $this
611
+	 */
612
+	public function setDocHeaderTopRightComponents(array $components)
613
+	{
614
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components;
615
+		return $this;
616
+	}
617
+
618
+	/**
619
+	 * @param string|array $components
620
+	 * @return $this
621
+	 */
622
+	public function addDocHeaderTopRightComponents($components)
623
+	{
624
+		if (is_string($components)) {
625
+			$components = array($components);
626
+		}
627
+		$currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
628
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
629
+		return $this;
630
+	}
631
+
632
+	/**
633
+	 * @return $array
634
+	 */
635
+	public function getDocHeaderBottomLeftComponents()
636
+	{
637
+		$configuration = $this->getModuleConfiguration();
638
+		return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
639
+	}
640
+
641
+	/**
642
+	 * @param array $components
643
+	 * @return $this
644
+	 */
645
+	public function setDocHeaderBottomLeftComponents(array $components)
646
+	{
647
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components;
648
+		return $this;
649
+	}
650
+
651
+	/**
652
+	 * @param string|array $components
653
+	 * @return $this
654
+	 */
655
+	public function addDocHeaderBottomLeftComponents($components)
656
+	{
657
+		if (is_string($components)) {
658
+			$components = array($components);
659
+		}
660
+		$currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
661
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components);
662
+		return $this;
663
+	}
664
+
665
+	/**
666
+	 * @return $array
667
+	 */
668
+	public function getDocHeaderBottomRightComponents()
669
+	{
670
+		$configuration = $this->getModuleConfiguration();
671
+		return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
672
+	}
673
+
674
+	/**
675
+	 * @param array $components
676
+	 * @return $this
677
+	 */
678
+	public function setDocHeaderBottomRightComponents(array $components)
679
+	{
680
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components;
681
+		return $this;
682
+	}
683
+
684
+	/**
685
+	 * @param string|array $components
686
+	 * @return $this
687
+	 */
688
+	public function addDocHeaderBottomRightComponents($components)
689
+	{
690
+		if (is_string($components)) {
691
+			$components = array($components);
692
+		}
693
+		$currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
694
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
695
+		return $this;
696
+	}
697
+
698
+	/**
699
+	 * @return $array
700
+	 */
701
+	public function getGridTopComponents()
702
+	{
703
+		$configuration = $this->getModuleConfiguration();
704
+		return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP];
705
+	}
706
+
707
+	/**
708
+	 * @param array $components
709
+	 * @return $this
710
+	 */
711
+	public function setGridTopComponents(array $components)
712
+	{
713
+		$this->components[ModulePosition::GRID][ModulePosition::TOP] = $components;
714
+		return $this;
715
+	}
716
+
717
+	/**
718
+	 * @param string|array $components
719
+	 * @return $this
720
+	 */
721
+	public function addGridTopComponents($components)
722
+	{
723
+		if (is_string($components)) {
724
+			$components = array($components);
725
+		}
726
+		$currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP];
727
+		$this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components);
728
+		return $this;
729
+	}
730
+
731
+	/**
732
+	 * @return $array
733
+	 */
734
+	public function getGridBottomComponents()
735
+	{
736
+		$configuration = $this->getModuleConfiguration();
737
+		return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM];
738
+	}
739
+
740
+	/**
741
+	 * @param array $components
742
+	 * @return $this
743
+	 */
744
+	public function setGridBottomComponents(array $components)
745
+	{
746
+		$this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components;
747
+		return $this;
748
+	}
749
+
750
+	/**
751
+	 * @param string|array $components
752
+	 * @return $this
753
+	 */
754
+	public function addGridBottomComponents($components)
755
+	{
756
+		if (is_string($components)) {
757
+			$components = array($components);
758
+		}
759
+		$currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM];
760
+		$this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components);
761
+		return $this;
762
+	}
763
+
764
+	/**
765
+	 * @return $array
766
+	 */
767
+	public function getGridButtonsComponents()
768
+	{
769
+		$configuration = $this->getModuleConfiguration();
770
+		return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS];
771
+	}
772
+
773
+	/**
774
+	 * @param array $components
775
+	 * @return $this
776
+	 */
777
+	public function setGridButtonsComponents(array $components)
778
+	{
779
+		$this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components;
780
+		return $this;
781
+	}
782
+
783
+	/**
784
+	 * @param string|array $components
785
+	 * @return $this
786
+	 */
787
+	public function addGridButtonsComponents($components)
788
+	{
789
+		if (is_string($components)) {
790
+			$components = array($components);
791
+		}
792
+		$currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS];
793
+		$this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($currentComponents, $components);
794
+		return $this;
795
+	}
796
+
797
+	/**
798
+	 * @return $array
799
+	 */
800
+	public function getMenuMassActionComponents()
801
+	{
802
+		$configuration = $this->getModuleConfiguration();
803
+		return $configuration['components'][ModulePosition::MENU_MASS_ACTION];
804
+	}
805
+
806
+	/**
807
+	 * @param array $components
808
+	 * @return $this
809
+	 */
810
+	public function setMenuMassActionComponents(array $components)
811
+	{
812
+		$this->components[ModulePosition::MENU_MASS_ACTION] = $components;
813
+		return $this;
814
+	}
815
+
816
+	/**
817
+	 * @param string|array $components
818
+	 * @return $this
819
+	 */
820
+	public function addMenuMassActionComponents($components)
821
+	{
822
+		if (is_string($components)) {
823
+			$components = array($components);
824
+		}
825
+		$currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION];
826
+		$this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($currentComponents, $components);
827
+		return $this;
828
+	}
829
+
830
+	/**
831
+	 * @return string
832
+	 */
833
+	public function getAccess()
834
+	{
835
+		return $this->access;
836
+	}
837
+
838
+	/**
839
+	 * @param string $access
840
+	 * @return $this
841
+	 */
842
+	public function setAccess($access)
843
+	{
844
+		$this->access = $access;
845
+		return $this;
846
+	}
847
+
848
+	/**
849
+	 * @return \string[]
850
+	 */
851
+	public function getAdditionalJavaScriptFiles()
852
+	{
853
+		if (empty($this->additionalJavaScriptFiles)) {
854
+			$this->additionalJavaScriptFiles = $this->getModuleConfiguration('additionalJavaScriptFiles');
855
+		}
856
+		return $this->additionalJavaScriptFiles;
857
+	}
858
+
859
+	/**
860
+	 * @return \string[]
861
+	 */
862
+	public function getAdditionalStyleSheetFiles()
863
+	{
864
+		if (empty($this->additionalStyleSheetFiles)) {
865
+			$this->additionalStyleSheetFiles = $this->getModuleConfiguration('additionalStyleSheetFiles');
866
+		}
867
+		return $this->additionalStyleSheetFiles;
868
+	}
869
+
870
+	/**
871
+	 * @return array
872
+	 */
873
+	public function getComponents()
874
+	{
875
+		return $this->components;
876
+	}
877
+
878
+	/**
879
+	 * @param string $pluginName
880
+	 * @return bool
881
+	 */
882
+	public function hasPlugin($pluginName = '')
883
+	{
884
+		$parameterPrefix = $this->getParameterPrefix();
885
+		$parameters = GeneralUtility::_GET($parameterPrefix);
886
+
887
+		$hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']);
888
+		if ($hasPlugin && $pluginName) {
889
+			$hasPlugin = in_array($pluginName, $parameters['plugins']);
890
+		}
891
+		return $hasPlugin;
892
+	}
893
+
894
+	/**
895
+	 * Compute the internal module code
896
+	 *
897
+	 * @param NULL|string $dataType
898
+	 * @return string
899
+	 */
900
+	protected function getInternalModuleSignature($dataType = NULL)
901
+	{
902
+		if (is_null($dataType)) {
903
+			$dataType = $this->dataType;
904
+		}
905
+		$subModuleName = $dataType . '_' . $this->moduleKey;
906
+		return 'Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName);
907
+	}
908
+
909
+	/**
910
+	 * Make sure default values are correctly initialized for the module.
911
+	 *
912
+	 * @return void
913
+	 */
914
+	protected function initializeDefaultValues()
915
+	{
916
+		if (is_null($this->mainModule)) {
917
+			$this->mainModule = self::DEFAULT_MAIN_MODULE;
918
+		}
919
+
920
+		if (is_null($this->defaultPid)) {
921
+			$this->defaultPid = self::DEFAULT_PID;
922
+		}
923
+	}
924 924
 
925 925
 }
Please login to merge, or discard this patch.
Classes/Persistence/Matcher.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -192,7 +192,7 @@
 block discarded – undo
192 192
     }
193 193
 
194 194
     /**
195
-     * @return array
195
+     * @return string
196 196
      */
197 197
     public function getDefaultLogicalSeparator()
198 198
     {
Please login to merge, or discard this patch.
Indentation   +286 added lines, -286 removed lines patch added patch discarded remove patch
@@ -20,290 +20,290 @@
 block discarded – undo
20 20
 class Matcher
21 21
 {
22 22
 
23
-    /**
24
-     * The logical OR
25
-     */
26
-    const LOGICAL_OR = 'logicalOr';
27
-
28
-    /**
29
-     * The logical AND
30
-     */
31
-    const LOGICAL_AND = 'logicalAnd';
32
-
33
-    /**
34
-     * @var string
35
-     */
36
-    protected $dataType = '';
37
-
38
-    /**
39
-     * @var string
40
-     */
41
-    protected $searchTerm = '';
42
-
43
-    /**
44
-     * @var array
45
-     */
46
-    protected $supportedOperators = array('equals', 'in', 'like');
47
-
48
-    /**
49
-     * Associative values used for "equals" operator ($fieldName => $value)
50
-     *
51
-     * @var array
52
-     */
53
-    protected $equalsCriteria = array();
54
-
55
-    /**
56
-     * Associative values used for "in" operator ($fieldName => $value)
57
-     *
58
-     * @var array
59
-     */
60
-    protected $inCriteria = array();
61
-
62
-    /**
63
-     * Associative values used for "like" operator ($fieldName => $value)
64
-     *
65
-     * @var array
66
-     */
67
-    protected $likeCriteria = array();
68
-
69
-    /**
70
-     * Default logical operator for like.
71
-     *
72
-     * @var string
73
-     */
74
-    protected $defaultLogicalSeparator = self::LOGICAL_AND;
75
-
76
-    /**
77
-     * Default logical operator for equals.
78
-     *
79
-     * @var string
80
-     */
81
-    protected $logicalSeparatorForEquals = self::LOGICAL_AND;
82
-
83
-    /**
84
-     * Default logical operator for equals.
85
-     *
86
-     * @var string
87
-     */
88
-    protected $logicalSeparatorForIn = self::LOGICAL_AND;
89
-
90
-    /**
91
-     * Default logical operator for like.
92
-     *
93
-     * @var string
94
-     */
95
-    protected $logicalSeparatorForLike = self::LOGICAL_AND;
96
-
97
-    /**
98
-     * Default logical operator for the search term.
99
-     *
100
-     * @var string
101
-     */
102
-    protected $logicalSeparatorForSearchTerm = self::LOGICAL_OR;
103
-
104
-    /**
105
-     * Constructs a new Matcher
106
-     *
107
-     * @param array $matches associative array($field => $value)
108
-     * @param string $dataType which corresponds to an entry of the TCA (table name).
109
-     * @return \Fab\Vidi\Persistence\Matcher
110
-     */
111
-    public function __construct($matches = array(), $dataType = '')
112
-    {
113
-        $this->dataType = $dataType;
114
-        $this->matches = $matches;
115
-    }
116
-
117
-    /**
118
-     * @param string $searchTerm
119
-     * @return \Fab\Vidi\Persistence\Matcher
120
-     */
121
-    public function setSearchTerm($searchTerm)
122
-    {
123
-        $this->searchTerm = $searchTerm;
124
-        return $this;
125
-    }
126
-
127
-    /**
128
-     * @return string
129
-     */
130
-    public function getSearchTerm()
131
-    {
132
-        return $this->searchTerm;
133
-    }
134
-
135
-    /**
136
-     * @return array
137
-     */
138
-    public function getEqualsCriteria()
139
-    {
140
-        return $this->equalsCriteria;
141
-    }
142
-
143
-    /**
144
-     * @param $fieldNameAndPath
145
-     * @param $operand
146
-     * @return $this
147
-     */
148
-    public function equals($fieldNameAndPath, $operand)
149
-    {
150
-        $this->equalsCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand);
151
-        return $this;
152
-    }
153
-
154
-    /**
155
-     * @return array
156
-     */
157
-    public function getLikeCriteria()
158
-    {
159
-        return $this->likeCriteria;
160
-    }
161
-
162
-    /**
163
-     * @param $fieldNameAndPath
164
-     * @param $operand
165
-     * @return $this
166
-     */
167
-    public function in($fieldNameAndPath, $operand)
168
-    {
169
-        $this->inCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand);
170
-        return $this;
171
-    }
172
-
173
-    /**
174
-     * @return array
175
-     */
176
-    public function getInCriteria()
177
-    {
178
-        return $this->inCriteria;
179
-    }
180
-
181
-    /**
182
-     * @param $fieldNameAndPath
183
-     * @param $operand
184
-     * @param bool $addWildCard
185
-     * @return $this
186
-     */
187
-    public function like($fieldNameAndPath, $operand, $addWildCard = TRUE)
188
-    {
189
-        $wildCardSymbol = $addWildCard ? '%' : '';
190
-        $this->likeCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $wildCardSymbol . $operand . $wildCardSymbol);
191
-        return $this;
192
-    }
193
-
194
-    /**
195
-     * @return array
196
-     */
197
-    public function getDefaultLogicalSeparator()
198
-    {
199
-        return $this->defaultLogicalSeparator;
200
-    }
201
-
202
-    /**
203
-     * @param string $defaultLogicalSeparator
204
-     * @return $this
205
-     */
206
-    public function setDefaultLogicalSeparator($defaultLogicalSeparator)
207
-    {
208
-        $this->defaultLogicalSeparator = $defaultLogicalSeparator;
209
-        return $this;
210
-    }
211
-
212
-    /**
213
-     * @return string
214
-     */
215
-    public function getLogicalSeparatorForEquals()
216
-    {
217
-        return $this->logicalSeparatorForEquals;
218
-    }
219
-
220
-    /**
221
-     * @param string $logicalSeparatorForEquals
222
-     * @return $this
223
-     */
224
-    public function setLogicalSeparatorForEquals($logicalSeparatorForEquals)
225
-    {
226
-        $this->logicalSeparatorForEquals = $logicalSeparatorForEquals;
227
-        return $this;
228
-    }
229
-
230
-    /**
231
-     * @return string
232
-     */
233
-    public function getLogicalSeparatorForIn()
234
-    {
235
-        return $this->logicalSeparatorForIn;
236
-    }
237
-
238
-    /**
239
-     * @param string $logicalSeparatorForIn
240
-     * @return $this
241
-     */
242
-    public function setLogicalSeparatorForIn($logicalSeparatorForIn)
243
-    {
244
-        $this->logicalSeparatorForIn = $logicalSeparatorForIn;
245
-        return $this;
246
-    }
247
-
248
-    /**
249
-     * @return string
250
-     */
251
-    public function getLogicalSeparatorForLike()
252
-    {
253
-        return $this->logicalSeparatorForLike;
254
-    }
255
-
256
-    /**
257
-     * @param string $logicalSeparatorForLike
258
-     * @return $this
259
-     */
260
-    public function setLogicalSeparatorForLike($logicalSeparatorForLike)
261
-    {
262
-        $this->logicalSeparatorForLike = $logicalSeparatorForLike;
263
-        return $this;
264
-    }
265
-
266
-    /**
267
-     * @return string
268
-     */
269
-    public function getLogicalSeparatorForSearchTerm()
270
-    {
271
-        return $this->logicalSeparatorForSearchTerm;
272
-    }
273
-
274
-    /**
275
-     * @param string $logicalSeparatorForSearchTerm
276
-     * @return $this
277
-     */
278
-    public function setLogicalSeparatorForSearchTerm($logicalSeparatorForSearchTerm)
279
-    {
280
-        $this->logicalSeparatorForSearchTerm = $logicalSeparatorForSearchTerm;
281
-        return $this;
282
-    }
283
-
284
-    /**
285
-     * @return array
286
-     */
287
-    public function getSupportedOperators()
288
-    {
289
-        return $this->supportedOperators;
290
-    }
291
-
292
-    /**
293
-     * @return string
294
-     */
295
-    public function getDataType()
296
-    {
297
-        return $this->dataType;
298
-    }
299
-
300
-    /**
301
-     * @param string $dataType
302
-     * @return $this
303
-     */
304
-    public function setDataType($dataType)
305
-    {
306
-        $this->dataType = $dataType;
307
-        return $this;
308
-    }
23
+	/**
24
+	 * The logical OR
25
+	 */
26
+	const LOGICAL_OR = 'logicalOr';
27
+
28
+	/**
29
+	 * The logical AND
30
+	 */
31
+	const LOGICAL_AND = 'logicalAnd';
32
+
33
+	/**
34
+	 * @var string
35
+	 */
36
+	protected $dataType = '';
37
+
38
+	/**
39
+	 * @var string
40
+	 */
41
+	protected $searchTerm = '';
42
+
43
+	/**
44
+	 * @var array
45
+	 */
46
+	protected $supportedOperators = array('equals', 'in', 'like');
47
+
48
+	/**
49
+	 * Associative values used for "equals" operator ($fieldName => $value)
50
+	 *
51
+	 * @var array
52
+	 */
53
+	protected $equalsCriteria = array();
54
+
55
+	/**
56
+	 * Associative values used for "in" operator ($fieldName => $value)
57
+	 *
58
+	 * @var array
59
+	 */
60
+	protected $inCriteria = array();
61
+
62
+	/**
63
+	 * Associative values used for "like" operator ($fieldName => $value)
64
+	 *
65
+	 * @var array
66
+	 */
67
+	protected $likeCriteria = array();
68
+
69
+	/**
70
+	 * Default logical operator for like.
71
+	 *
72
+	 * @var string
73
+	 */
74
+	protected $defaultLogicalSeparator = self::LOGICAL_AND;
75
+
76
+	/**
77
+	 * Default logical operator for equals.
78
+	 *
79
+	 * @var string
80
+	 */
81
+	protected $logicalSeparatorForEquals = self::LOGICAL_AND;
82
+
83
+	/**
84
+	 * Default logical operator for equals.
85
+	 *
86
+	 * @var string
87
+	 */
88
+	protected $logicalSeparatorForIn = self::LOGICAL_AND;
89
+
90
+	/**
91
+	 * Default logical operator for like.
92
+	 *
93
+	 * @var string
94
+	 */
95
+	protected $logicalSeparatorForLike = self::LOGICAL_AND;
96
+
97
+	/**
98
+	 * Default logical operator for the search term.
99
+	 *
100
+	 * @var string
101
+	 */
102
+	protected $logicalSeparatorForSearchTerm = self::LOGICAL_OR;
103
+
104
+	/**
105
+	 * Constructs a new Matcher
106
+	 *
107
+	 * @param array $matches associative array($field => $value)
108
+	 * @param string $dataType which corresponds to an entry of the TCA (table name).
109
+	 * @return \Fab\Vidi\Persistence\Matcher
110
+	 */
111
+	public function __construct($matches = array(), $dataType = '')
112
+	{
113
+		$this->dataType = $dataType;
114
+		$this->matches = $matches;
115
+	}
116
+
117
+	/**
118
+	 * @param string $searchTerm
119
+	 * @return \Fab\Vidi\Persistence\Matcher
120
+	 */
121
+	public function setSearchTerm($searchTerm)
122
+	{
123
+		$this->searchTerm = $searchTerm;
124
+		return $this;
125
+	}
126
+
127
+	/**
128
+	 * @return string
129
+	 */
130
+	public function getSearchTerm()
131
+	{
132
+		return $this->searchTerm;
133
+	}
134
+
135
+	/**
136
+	 * @return array
137
+	 */
138
+	public function getEqualsCriteria()
139
+	{
140
+		return $this->equalsCriteria;
141
+	}
142
+
143
+	/**
144
+	 * @param $fieldNameAndPath
145
+	 * @param $operand
146
+	 * @return $this
147
+	 */
148
+	public function equals($fieldNameAndPath, $operand)
149
+	{
150
+		$this->equalsCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand);
151
+		return $this;
152
+	}
153
+
154
+	/**
155
+	 * @return array
156
+	 */
157
+	public function getLikeCriteria()
158
+	{
159
+		return $this->likeCriteria;
160
+	}
161
+
162
+	/**
163
+	 * @param $fieldNameAndPath
164
+	 * @param $operand
165
+	 * @return $this
166
+	 */
167
+	public function in($fieldNameAndPath, $operand)
168
+	{
169
+		$this->inCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand);
170
+		return $this;
171
+	}
172
+
173
+	/**
174
+	 * @return array
175
+	 */
176
+	public function getInCriteria()
177
+	{
178
+		return $this->inCriteria;
179
+	}
180
+
181
+	/**
182
+	 * @param $fieldNameAndPath
183
+	 * @param $operand
184
+	 * @param bool $addWildCard
185
+	 * @return $this
186
+	 */
187
+	public function like($fieldNameAndPath, $operand, $addWildCard = TRUE)
188
+	{
189
+		$wildCardSymbol = $addWildCard ? '%' : '';
190
+		$this->likeCriteria[] = array('fieldNameAndPath' => $fieldNameAndPath, 'operand' => $wildCardSymbol . $operand . $wildCardSymbol);
191
+		return $this;
192
+	}
193
+
194
+	/**
195
+	 * @return array
196
+	 */
197
+	public function getDefaultLogicalSeparator()
198
+	{
199
+		return $this->defaultLogicalSeparator;
200
+	}
201
+
202
+	/**
203
+	 * @param string $defaultLogicalSeparator
204
+	 * @return $this
205
+	 */
206
+	public function setDefaultLogicalSeparator($defaultLogicalSeparator)
207
+	{
208
+		$this->defaultLogicalSeparator = $defaultLogicalSeparator;
209
+		return $this;
210
+	}
211
+
212
+	/**
213
+	 * @return string
214
+	 */
215
+	public function getLogicalSeparatorForEquals()
216
+	{
217
+		return $this->logicalSeparatorForEquals;
218
+	}
219
+
220
+	/**
221
+	 * @param string $logicalSeparatorForEquals
222
+	 * @return $this
223
+	 */
224
+	public function setLogicalSeparatorForEquals($logicalSeparatorForEquals)
225
+	{
226
+		$this->logicalSeparatorForEquals = $logicalSeparatorForEquals;
227
+		return $this;
228
+	}
229
+
230
+	/**
231
+	 * @return string
232
+	 */
233
+	public function getLogicalSeparatorForIn()
234
+	{
235
+		return $this->logicalSeparatorForIn;
236
+	}
237
+
238
+	/**
239
+	 * @param string $logicalSeparatorForIn
240
+	 * @return $this
241
+	 */
242
+	public function setLogicalSeparatorForIn($logicalSeparatorForIn)
243
+	{
244
+		$this->logicalSeparatorForIn = $logicalSeparatorForIn;
245
+		return $this;
246
+	}
247
+
248
+	/**
249
+	 * @return string
250
+	 */
251
+	public function getLogicalSeparatorForLike()
252
+	{
253
+		return $this->logicalSeparatorForLike;
254
+	}
255
+
256
+	/**
257
+	 * @param string $logicalSeparatorForLike
258
+	 * @return $this
259
+	 */
260
+	public function setLogicalSeparatorForLike($logicalSeparatorForLike)
261
+	{
262
+		$this->logicalSeparatorForLike = $logicalSeparatorForLike;
263
+		return $this;
264
+	}
265
+
266
+	/**
267
+	 * @return string
268
+	 */
269
+	public function getLogicalSeparatorForSearchTerm()
270
+	{
271
+		return $this->logicalSeparatorForSearchTerm;
272
+	}
273
+
274
+	/**
275
+	 * @param string $logicalSeparatorForSearchTerm
276
+	 * @return $this
277
+	 */
278
+	public function setLogicalSeparatorForSearchTerm($logicalSeparatorForSearchTerm)
279
+	{
280
+		$this->logicalSeparatorForSearchTerm = $logicalSeparatorForSearchTerm;
281
+		return $this;
282
+	}
283
+
284
+	/**
285
+	 * @return array
286
+	 */
287
+	public function getSupportedOperators()
288
+	{
289
+		return $this->supportedOperators;
290
+	}
291
+
292
+	/**
293
+	 * @return string
294
+	 */
295
+	public function getDataType()
296
+	{
297
+		return $this->dataType;
298
+	}
299
+
300
+	/**
301
+	 * @param string $dataType
302
+	 * @return $this
303
+	 */
304
+	public function setDataType($dataType)
305
+	{
306
+		$this->dataType = $dataType;
307
+		return $this;
308
+	}
309 309
 }
Please login to merge, or discard this patch.
Classes/Persistence/Query.php 2 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.
Indentation   +644 added lines, -644 removed lines patch added patch discarded remove patch
@@ -29,649 +29,649 @@
 block discarded – undo
29 29
 class Query implements QueryInterface
30 30
 {
31 31
 
32
-    /**
33
-     * An inner join.
34
-     */
35
-    const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner';
36
-
37
-    /**
38
-     * A left-outer join.
39
-     */
40
-    const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter';
41
-
42
-    /**
43
-     * A right-outer join.
44
-     */
45
-    const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter';
46
-
47
-    /**
48
-     * Charset of strings in QOM
49
-     */
50
-    const CHARSET = 'utf-8';
51
-
52
-    /**
53
-     * @var string
54
-     */
55
-    protected $sourceFieldName;
56
-
57
-    /**
58
-     * @var string
59
-     */
60
-    protected $type;
61
-
62
-    /**
63
-     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
64
-     */
65
-    protected $objectManager;
66
-
67
-    /**
68
-     * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
69
-     */
70
-    protected $persistenceManager;
71
-
72
-    /**
73
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
74
-     */
75
-    protected $qomFactory;
76
-
77
-    /**
78
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface
79
-     */
80
-    protected $source;
81
-
82
-    /**
83
-     * @var ConstraintInterface
84
-     */
85
-    protected $constraint;
86
-
87
-    /**
88
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
89
-     */
90
-    protected $statement;
91
-
92
-    /**
93
-     * @var int
94
-     */
95
-    protected $orderings = array();
96
-
97
-    /**
98
-     * @var int
99
-     */
100
-    protected $limit;
101
-
102
-    /**
103
-     * @var int
104
-     */
105
-    protected $offset;
106
-
107
-    /**
108
-     * Apply DISTINCT upon property.
109
-     *
110
-     * @var string
111
-     */
112
-    protected $distinct;
113
-
114
-    /**
115
-     * The query settings.
116
-     *
117
-     * @var \Fab\Vidi\Persistence\QuerySettings
118
-     * @inject
119
-     */
120
-    protected $querySettings;
121
-
122
-    /**
123
-     * Constructs a query object working on the given class name
124
-     *
125
-     * @param string $type
126
-     */
127
-    public function __construct($type)
128
-    {
129
-        $this->type = $type;
130
-    }
131
-
132
-    /**
133
-     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
134
-     * @return void
135
-     */
136
-    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
137
-    {
138
-        $this->objectManager = $objectManager;
139
-    }
140
-
141
-    /**
142
-     * Injects the persistence manager, used to fetch the CR session
143
-     *
144
-     * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
145
-     * @return void
146
-     */
147
-    public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
148
-    {
149
-        $this->persistenceManager = $persistenceManager;
150
-    }
151
-
152
-    /**
153
-     * Injects the Query Object Model Factory
154
-     *
155
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory
156
-     * @return void
157
-     */
158
-    public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory)
159
-    {
160
-        $this->qomFactory = $qomFactory;
161
-    }
162
-
163
-    /**
164
-     * Sets the Query Settings. These Query settings must match the settings expected by
165
-     * the specific Storage Backend.
166
-     *
167
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
168
-     * @return void
169
-     * @api This method is not part of FLOW3 API
170
-     */
171
-    public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings)
172
-    {
173
-        $this->querySettings = $querySettings;
174
-    }
175
-
176
-    /**
177
-     * Returns the Query Settings.
178
-     *
179
-     * @throws \Exception
180
-     * @return \Fab\Vidi\Persistence\QuerySettings $querySettings The Query Settings
181
-     * @api This method is not part of FLOW3 API
182
-     */
183
-    public function getQuerySettings()
184
-    {
185
-        if (!$this->querySettings instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface) {
186
-            throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('Tried to get the query settings without setting them before.', 1248689115);
187
-        }
188
-
189
-        // Apply possible settings to the query.
190
-        if ($this->isBackendMode()) {
191
-            /** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */
192
-            $backendConfigurationManager = $this->objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
193
-            $configuration = $backendConfigurationManager->getTypoScriptSetup();
194
-            $querySettings = array('respectSysLanguage');
195
-            foreach ($querySettings as $setting) {
196
-                if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) {
197
-                    $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting];
198
-                    ObjectAccess::setProperty($this->querySettings, $setting, $value);
199
-                }
200
-            }
201
-        }
202
-
203
-        return $this->querySettings;
204
-    }
205
-
206
-    /**
207
-     * Returns the type this query cares for.
208
-     *
209
-     * @return string
210
-     * @api
211
-     */
212
-    public function getType()
213
-    {
214
-        return $this->type;
215
-    }
216
-
217
-    /**
218
-     * Sets the source to fetch the result from
219
-     *
220
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
221
-     */
222
-    public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source)
223
-    {
224
-        $this->source = $source;
225
-    }
226
-
227
-    /**
228
-     * Returns the selectorn name or an empty string, if the source is not a selector
229
-     * TODO This has to be checked at another place
230
-     *
231
-     * @return string The selector name
232
-     */
233
-    protected function getSelectorName()
234
-    {
235
-        if ($this->getSource() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
236
-            return $this->source->getSelectorName();
237
-        } else {
238
-            return '';
239
-        }
240
-    }
241
-
242
-    /**
243
-     * Gets the node-tuple source for this query.
244
-     *
245
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-null
246
-     */
247
-    public function getSource()
248
-    {
249
-        if ($this->source === NULL) {
250
-            $this->source = $this->qomFactory->selector($this->getType());
251
-        }
252
-        return $this->source;
253
-    }
254
-
255
-    /**
256
-     * Executes the query against the database and returns the result
257
-     *
258
-     * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE
259
-     * @api
260
-     */
261
-    public function execute($returnRawQueryResult = FALSE)
262
-    {
263
-        /** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
264
-        $backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
265
-        return $backend->fetchResult();
266
-    }
267
-
268
-    /**
269
-     * Sets the property names to order the result by. Expected like this:
270
-     * array(
271
-     * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
272
-     * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
273
-     * )
274
-     * where 'foo' and 'bar' are property names.
275
-     *
276
-     * @param array $orderings The property names to order by
277
-     * @return QueryInterface
278
-     * @api
279
-     */
280
-    public function setOrderings(array $orderings)
281
-    {
282
-        $this->orderings = $orderings;
283
-        return $this;
284
-    }
285
-
286
-    /**
287
-     * Returns the property names to order the result by. Like this:
288
-     * array(
289
-     * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
290
-     * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
291
-     * )
292
-     *
293
-     * @return array
294
-     * @api
295
-     */
296
-    public function getOrderings()
297
-    {
298
-        return $this->orderings;
299
-    }
300
-
301
-    /**
302
-     * Sets the maximum size of the result set to limit. Returns $this to allow
303
-     * for chaining (fluid interface)
304
-     *
305
-     * @param integer $limit
306
-     * @throws \InvalidArgumentException
307
-     * @return QueryInterface
308
-     * @api
309
-     */
310
-    public function setLimit($limit)
311
-    {
312
-        if (!is_int($limit) || $limit < 1) {
313
-            throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870);
314
-        }
315
-        $this->limit = $limit;
316
-        return $this;
317
-    }
318
-
319
-    /**
320
-     * Resets a previously set maximum size of the result set. Returns $this to allow
321
-     * for chaining (fluid interface)
322
-     *
323
-     * @return QueryInterface
324
-     * @api
325
-     */
326
-    public function unsetLimit()
327
-    {
328
-        unset($this->limit);
329
-        return $this;
330
-    }
331
-
332
-    /**
333
-     * Returns the maximum size of the result set to limit.
334
-     *
335
-     * @return integer
336
-     * @api
337
-     */
338
-    public function getLimit()
339
-    {
340
-        return $this->limit;
341
-    }
342
-
343
-    /**
344
-     * Sets the start offset of the result set to offset. Returns $this to
345
-     * allow for chaining (fluid interface)
346
-     *
347
-     * @param integer $offset
348
-     * @throws \InvalidArgumentException
349
-     * @return QueryInterface
350
-     * @api
351
-     */
352
-    public function setOffset($offset)
353
-    {
354
-        if (!is_int($offset) || $offset < 0) {
355
-            throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872);
356
-        }
357
-        $this->offset = $offset;
358
-        return $this;
359
-    }
360
-
361
-    /**
362
-     * Returns the start offset of the result set.
363
-     *
364
-     * @return integer
365
-     * @api
366
-     */
367
-    public function getOffset()
368
-    {
369
-        return $this->offset;
370
-    }
371
-
372
-    /**
373
-     * The constraint used to limit the result set. Returns $this to allow
374
-     * for chaining (fluid interface)
375
-     *
376
-     * @param ConstraintInterface $constraint
377
-     * @return QueryInterface
378
-     * @api
379
-     */
380
-    public function matching($constraint)
381
-    {
382
-        $this->constraint = $constraint;
383
-        return $this;
384
-    }
385
-
386
-    /**
387
-     * Gets the constraint for this query.
388
-     *
389
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Constraint the constraint, or null if none
390
-     * @api
391
-     */
392
-    public function getConstraint()
393
-    {
394
-        return $this->constraint;
395
-    }
396
-
397
-    /**
398
-     * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND.
399
-     * It also scepts a single array of constraints to be concatenated.
400
-     *
401
-     * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
402
-     * @throws InvalidNumberOfConstraintsException
403
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface
404
-     * @api
405
-     */
406
-    public function logicalAnd($constraint1)
407
-    {
408
-        if (is_array($constraint1)) {
409
-            $resultingConstraint = array_shift($constraint1);
410
-            $constraints = $constraint1;
411
-        } else {
412
-            $constraints = func_get_args();
413
-            $resultingConstraint = array_shift($constraints);
414
-        }
415
-        if ($resultingConstraint === NULL) {
416
-            throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500);
417
-        }
418
-        foreach ($constraints as $constraint) {
419
-            $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint);
420
-        }
421
-        return $resultingConstraint;
422
-    }
423
-
424
-    /**
425
-     * Performs a logical disjunction of the two given constraints
426
-     *
427
-     * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
428
-     * @throws InvalidNumberOfConstraintsException
429
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface
430
-     * @api
431
-     */
432
-    public function logicalOr($constraint1)
433
-    {
434
-        if (is_array($constraint1)) {
435
-            $resultingConstraint = array_shift($constraint1);
436
-            $constraints = $constraint1;
437
-        } else {
438
-            $constraints = func_get_args();
439
-            $resultingConstraint = array_shift($constraints);
440
-        }
441
-        if ($resultingConstraint === NULL) {
442
-            throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501);
443
-        }
444
-        foreach ($constraints as $constraint) {
445
-            $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint);
446
-        }
447
-        return $resultingConstraint;
448
-    }
449
-
450
-    /**
451
-     * Performs a logical negation of the given constraint
452
-     *
453
-     * @param ConstraintInterface $constraint Constraint to negate
454
-     * @throws \RuntimeException
455
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
456
-     * @api
457
-     */
458
-    public function logicalNot(ConstraintInterface $constraint)
459
-    {
460
-        return $this->qomFactory->not($constraint);
461
-    }
462
-
463
-    /**
464
-     * Returns an equals criterion used for matching objects against a query
465
-     *
466
-     * @param string $propertyName The name of the property to compare against
467
-     * @param mixed $operand The value to compare with
468
-     * @param boolean $caseSensitive Whether the equality test should be done case-sensitive
469
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
470
-     * @api
471
-     */
472
-    public function equals($propertyName, $operand, $caseSensitive = TRUE)
473
-    {
474
-        if (is_object($operand) || $caseSensitive) {
475
-            $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand);
476
-        } else {
477
-            $comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter')->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower'));
478
-        }
479
-        return $comparison;
480
-    }
481
-
482
-    /**
483
-     * Returns a like criterion used for matching objects against a query
484
-     *
485
-     * @param string $propertyName The name of the property to compare against
486
-     * @param mixed $operand The value to compare with
487
-     * @param boolean $caseSensitive Whether the matching should be done case-sensitive
488
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
489
-     * @api
490
-     */
491
-    public function like($propertyName, $operand, $caseSensitive = TRUE)
492
-    {
493
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand);
494
-    }
495
-
496
-    /**
497
-     * Returns a "contains" criterion used for matching objects against a query.
498
-     * It matches if the multivalued property contains the given operand.
499
-     *
500
-     * @param string $propertyName The name of the (multivalued) property to compare against
501
-     * @param mixed $operand The value to compare with
502
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
503
-     * @api
504
-     */
505
-    public function contains($propertyName, $operand)
506
-    {
507
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand);
508
-    }
509
-
510
-    /**
511
-     * Returns an "in" criterion used for matching objects against a query. It
512
-     * matches if the property's value is contained in the multivalued operand.
513
-     *
514
-     * @param string $propertyName The name of the property to compare against
515
-     * @param mixed $operand The value to compare with, multivalued
516
-     * @throws UnexpectedTypeException
517
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
518
-     * @api
519
-     */
520
-    public function in($propertyName, $operand)
521
-    {
522
-        if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) {
523
-            throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095);
524
-        }
525
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand);
526
-    }
527
-
528
-    /**
529
-     * Returns a less than criterion used for matching objects against a query
530
-     *
531
-     * @param string $propertyName The name of the property to compare against
532
-     * @param mixed $operand The value to compare with
533
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
534
-     * @api
535
-     */
536
-    public function lessThan($propertyName, $operand)
537
-    {
538
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand);
539
-    }
540
-
541
-    /**
542
-     * Returns a less or equal than criterion used for matching objects against a query
543
-     *
544
-     * @param string $propertyName The name of the property to compare against
545
-     * @param mixed $operand The value to compare with
546
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
547
-     * @api
548
-     */
549
-    public function lessThanOrEqual($propertyName, $operand)
550
-    {
551
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand);
552
-    }
553
-
554
-    /**
555
-     * Returns a greater than criterion used for matching objects against a query
556
-     *
557
-     * @param string $propertyName The name of the property to compare against
558
-     * @param mixed $operand The value to compare with
559
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
560
-     * @api
561
-     */
562
-    public function greaterThan($propertyName, $operand)
563
-    {
564
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand);
565
-    }
566
-
567
-    /**
568
-     * Returns a greater than or equal criterion used for matching objects against a query
569
-     *
570
-     * @param string $propertyName The name of the property to compare against
571
-     * @param mixed $operand The value to compare with
572
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
573
-     * @api
574
-     */
575
-    public function greaterThanOrEqual($propertyName, $operand)
576
-    {
577
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand);
578
-    }
579
-
580
-    /**
581
-     * Returns the query result count.
582
-     *
583
-     * @return integer The query result count
584
-     * @api
585
-     */
586
-    public function count()
587
-    {
588
-        /** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
589
-        $backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
590
-        return $backend->countResult();
591
-    }
592
-
593
-    /**
594
-     * Returns an "isEmpty" criterion used for matching objects against a query.
595
-     * It matches if the multivalued property contains no values or is NULL.
596
-     *
597
-     * @param string $propertyName The name of the multivalued property to compare against
598
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
599
-     * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
600
-     * @api
601
-     */
602
-    public function isEmpty($propertyName)
603
-    {
604
-        throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
605
-    }
606
-
607
-    /**
608
-     * @return string
609
-     */
610
-    public function getDistinct()
611
-    {
612
-        return $this->distinct;
613
-    }
614
-
615
-    /**
616
-     * @param string $distinct
617
-     * @return $this
618
-     */
619
-    public function setDistinct($distinct)
620
-    {
621
-        $this->distinct = $distinct;
622
-        return $this;
623
-    }
624
-
625
-    /**
626
-     * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage
627
-     * backend (database).
628
-     *
629
-     * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement
630
-     * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement.
631
-     * @return QueryInterface
632
-     */
633
-    public function statement($statement, array $parameters = array())
634
-    {
635
-        $this->statement = $this->qomFactory->statement($statement, $parameters);
636
-        return $this;
637
-    }
638
-
639
-    /**
640
-     * Returns the statement of this query.
641
-     *
642
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
643
-     */
644
-    public function getStatement()
645
-    {
646
-        return $this->statement;
647
-    }
648
-
649
-    /**
650
-     * Returns whether the current mode is Backend.
651
-     *
652
-     * @return bool
653
-     */
654
-    protected function isBackendMode()
655
-    {
656
-        return TYPO3_MODE == 'BE';
657
-    }
658
-
659
-    /**
660
-     * @return string
661
-     */
662
-    public function getSourceFieldName()
663
-    {
664
-        return $this->sourceFieldName;
665
-    }
666
-
667
-    /**
668
-     * @param string $sourceFieldName
669
-     * @return $this
670
-     */
671
-    public function setSourceFieldName($sourceFieldName)
672
-    {
673
-        $this->sourceFieldName = $sourceFieldName;
674
-        return $this;
675
-    }
32
+	/**
33
+	 * An inner join.
34
+	 */
35
+	const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner';
36
+
37
+	/**
38
+	 * A left-outer join.
39
+	 */
40
+	const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter';
41
+
42
+	/**
43
+	 * A right-outer join.
44
+	 */
45
+	const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter';
46
+
47
+	/**
48
+	 * Charset of strings in QOM
49
+	 */
50
+	const CHARSET = 'utf-8';
51
+
52
+	/**
53
+	 * @var string
54
+	 */
55
+	protected $sourceFieldName;
56
+
57
+	/**
58
+	 * @var string
59
+	 */
60
+	protected $type;
61
+
62
+	/**
63
+	 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
64
+	 */
65
+	protected $objectManager;
66
+
67
+	/**
68
+	 * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
69
+	 */
70
+	protected $persistenceManager;
71
+
72
+	/**
73
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
74
+	 */
75
+	protected $qomFactory;
76
+
77
+	/**
78
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface
79
+	 */
80
+	protected $source;
81
+
82
+	/**
83
+	 * @var ConstraintInterface
84
+	 */
85
+	protected $constraint;
86
+
87
+	/**
88
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
89
+	 */
90
+	protected $statement;
91
+
92
+	/**
93
+	 * @var int
94
+	 */
95
+	protected $orderings = array();
96
+
97
+	/**
98
+	 * @var int
99
+	 */
100
+	protected $limit;
101
+
102
+	/**
103
+	 * @var int
104
+	 */
105
+	protected $offset;
106
+
107
+	/**
108
+	 * Apply DISTINCT upon property.
109
+	 *
110
+	 * @var string
111
+	 */
112
+	protected $distinct;
113
+
114
+	/**
115
+	 * The query settings.
116
+	 *
117
+	 * @var \Fab\Vidi\Persistence\QuerySettings
118
+	 * @inject
119
+	 */
120
+	protected $querySettings;
121
+
122
+	/**
123
+	 * Constructs a query object working on the given class name
124
+	 *
125
+	 * @param string $type
126
+	 */
127
+	public function __construct($type)
128
+	{
129
+		$this->type = $type;
130
+	}
131
+
132
+	/**
133
+	 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
134
+	 * @return void
135
+	 */
136
+	public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
137
+	{
138
+		$this->objectManager = $objectManager;
139
+	}
140
+
141
+	/**
142
+	 * Injects the persistence manager, used to fetch the CR session
143
+	 *
144
+	 * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
145
+	 * @return void
146
+	 */
147
+	public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
148
+	{
149
+		$this->persistenceManager = $persistenceManager;
150
+	}
151
+
152
+	/**
153
+	 * Injects the Query Object Model Factory
154
+	 *
155
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory
156
+	 * @return void
157
+	 */
158
+	public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory)
159
+	{
160
+		$this->qomFactory = $qomFactory;
161
+	}
162
+
163
+	/**
164
+	 * Sets the Query Settings. These Query settings must match the settings expected by
165
+	 * the specific Storage Backend.
166
+	 *
167
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
168
+	 * @return void
169
+	 * @api This method is not part of FLOW3 API
170
+	 */
171
+	public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings)
172
+	{
173
+		$this->querySettings = $querySettings;
174
+	}
175
+
176
+	/**
177
+	 * Returns the Query Settings.
178
+	 *
179
+	 * @throws \Exception
180
+	 * @return \Fab\Vidi\Persistence\QuerySettings $querySettings The Query Settings
181
+	 * @api This method is not part of FLOW3 API
182
+	 */
183
+	public function getQuerySettings()
184
+	{
185
+		if (!$this->querySettings instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface) {
186
+			throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('Tried to get the query settings without setting them before.', 1248689115);
187
+		}
188
+
189
+		// Apply possible settings to the query.
190
+		if ($this->isBackendMode()) {
191
+			/** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */
192
+			$backendConfigurationManager = $this->objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
193
+			$configuration = $backendConfigurationManager->getTypoScriptSetup();
194
+			$querySettings = array('respectSysLanguage');
195
+			foreach ($querySettings as $setting) {
196
+				if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) {
197
+					$value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting];
198
+					ObjectAccess::setProperty($this->querySettings, $setting, $value);
199
+				}
200
+			}
201
+		}
202
+
203
+		return $this->querySettings;
204
+	}
205
+
206
+	/**
207
+	 * Returns the type this query cares for.
208
+	 *
209
+	 * @return string
210
+	 * @api
211
+	 */
212
+	public function getType()
213
+	{
214
+		return $this->type;
215
+	}
216
+
217
+	/**
218
+	 * Sets the source to fetch the result from
219
+	 *
220
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
221
+	 */
222
+	public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source)
223
+	{
224
+		$this->source = $source;
225
+	}
226
+
227
+	/**
228
+	 * Returns the selectorn name or an empty string, if the source is not a selector
229
+	 * TODO This has to be checked at another place
230
+	 *
231
+	 * @return string The selector name
232
+	 */
233
+	protected function getSelectorName()
234
+	{
235
+		if ($this->getSource() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
236
+			return $this->source->getSelectorName();
237
+		} else {
238
+			return '';
239
+		}
240
+	}
241
+
242
+	/**
243
+	 * Gets the node-tuple source for this query.
244
+	 *
245
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-null
246
+	 */
247
+	public function getSource()
248
+	{
249
+		if ($this->source === NULL) {
250
+			$this->source = $this->qomFactory->selector($this->getType());
251
+		}
252
+		return $this->source;
253
+	}
254
+
255
+	/**
256
+	 * Executes the query against the database and returns the result
257
+	 *
258
+	 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE
259
+	 * @api
260
+	 */
261
+	public function execute($returnRawQueryResult = FALSE)
262
+	{
263
+		/** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
264
+		$backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
265
+		return $backend->fetchResult();
266
+	}
267
+
268
+	/**
269
+	 * Sets the property names to order the result by. Expected like this:
270
+	 * array(
271
+	 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
272
+	 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
273
+	 * )
274
+	 * where 'foo' and 'bar' are property names.
275
+	 *
276
+	 * @param array $orderings The property names to order by
277
+	 * @return QueryInterface
278
+	 * @api
279
+	 */
280
+	public function setOrderings(array $orderings)
281
+	{
282
+		$this->orderings = $orderings;
283
+		return $this;
284
+	}
285
+
286
+	/**
287
+	 * Returns the property names to order the result by. Like this:
288
+	 * array(
289
+	 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
290
+	 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
291
+	 * )
292
+	 *
293
+	 * @return array
294
+	 * @api
295
+	 */
296
+	public function getOrderings()
297
+	{
298
+		return $this->orderings;
299
+	}
300
+
301
+	/**
302
+	 * Sets the maximum size of the result set to limit. Returns $this to allow
303
+	 * for chaining (fluid interface)
304
+	 *
305
+	 * @param integer $limit
306
+	 * @throws \InvalidArgumentException
307
+	 * @return QueryInterface
308
+	 * @api
309
+	 */
310
+	public function setLimit($limit)
311
+	{
312
+		if (!is_int($limit) || $limit < 1) {
313
+			throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870);
314
+		}
315
+		$this->limit = $limit;
316
+		return $this;
317
+	}
318
+
319
+	/**
320
+	 * Resets a previously set maximum size of the result set. Returns $this to allow
321
+	 * for chaining (fluid interface)
322
+	 *
323
+	 * @return QueryInterface
324
+	 * @api
325
+	 */
326
+	public function unsetLimit()
327
+	{
328
+		unset($this->limit);
329
+		return $this;
330
+	}
331
+
332
+	/**
333
+	 * Returns the maximum size of the result set to limit.
334
+	 *
335
+	 * @return integer
336
+	 * @api
337
+	 */
338
+	public function getLimit()
339
+	{
340
+		return $this->limit;
341
+	}
342
+
343
+	/**
344
+	 * Sets the start offset of the result set to offset. Returns $this to
345
+	 * allow for chaining (fluid interface)
346
+	 *
347
+	 * @param integer $offset
348
+	 * @throws \InvalidArgumentException
349
+	 * @return QueryInterface
350
+	 * @api
351
+	 */
352
+	public function setOffset($offset)
353
+	{
354
+		if (!is_int($offset) || $offset < 0) {
355
+			throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872);
356
+		}
357
+		$this->offset = $offset;
358
+		return $this;
359
+	}
360
+
361
+	/**
362
+	 * Returns the start offset of the result set.
363
+	 *
364
+	 * @return integer
365
+	 * @api
366
+	 */
367
+	public function getOffset()
368
+	{
369
+		return $this->offset;
370
+	}
371
+
372
+	/**
373
+	 * The constraint used to limit the result set. Returns $this to allow
374
+	 * for chaining (fluid interface)
375
+	 *
376
+	 * @param ConstraintInterface $constraint
377
+	 * @return QueryInterface
378
+	 * @api
379
+	 */
380
+	public function matching($constraint)
381
+	{
382
+		$this->constraint = $constraint;
383
+		return $this;
384
+	}
385
+
386
+	/**
387
+	 * Gets the constraint for this query.
388
+	 *
389
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Constraint the constraint, or null if none
390
+	 * @api
391
+	 */
392
+	public function getConstraint()
393
+	{
394
+		return $this->constraint;
395
+	}
396
+
397
+	/**
398
+	 * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND.
399
+	 * It also scepts a single array of constraints to be concatenated.
400
+	 *
401
+	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
402
+	 * @throws InvalidNumberOfConstraintsException
403
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface
404
+	 * @api
405
+	 */
406
+	public function logicalAnd($constraint1)
407
+	{
408
+		if (is_array($constraint1)) {
409
+			$resultingConstraint = array_shift($constraint1);
410
+			$constraints = $constraint1;
411
+		} else {
412
+			$constraints = func_get_args();
413
+			$resultingConstraint = array_shift($constraints);
414
+		}
415
+		if ($resultingConstraint === NULL) {
416
+			throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500);
417
+		}
418
+		foreach ($constraints as $constraint) {
419
+			$resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint);
420
+		}
421
+		return $resultingConstraint;
422
+	}
423
+
424
+	/**
425
+	 * Performs a logical disjunction of the two given constraints
426
+	 *
427
+	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
428
+	 * @throws InvalidNumberOfConstraintsException
429
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface
430
+	 * @api
431
+	 */
432
+	public function logicalOr($constraint1)
433
+	{
434
+		if (is_array($constraint1)) {
435
+			$resultingConstraint = array_shift($constraint1);
436
+			$constraints = $constraint1;
437
+		} else {
438
+			$constraints = func_get_args();
439
+			$resultingConstraint = array_shift($constraints);
440
+		}
441
+		if ($resultingConstraint === NULL) {
442
+			throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501);
443
+		}
444
+		foreach ($constraints as $constraint) {
445
+			$resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint);
446
+		}
447
+		return $resultingConstraint;
448
+	}
449
+
450
+	/**
451
+	 * Performs a logical negation of the given constraint
452
+	 *
453
+	 * @param ConstraintInterface $constraint Constraint to negate
454
+	 * @throws \RuntimeException
455
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
456
+	 * @api
457
+	 */
458
+	public function logicalNot(ConstraintInterface $constraint)
459
+	{
460
+		return $this->qomFactory->not($constraint);
461
+	}
462
+
463
+	/**
464
+	 * Returns an equals criterion used for matching objects against a query
465
+	 *
466
+	 * @param string $propertyName The name of the property to compare against
467
+	 * @param mixed $operand The value to compare with
468
+	 * @param boolean $caseSensitive Whether the equality test should be done case-sensitive
469
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
470
+	 * @api
471
+	 */
472
+	public function equals($propertyName, $operand, $caseSensitive = TRUE)
473
+	{
474
+		if (is_object($operand) || $caseSensitive) {
475
+			$comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand);
476
+		} else {
477
+			$comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter')->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower'));
478
+		}
479
+		return $comparison;
480
+	}
481
+
482
+	/**
483
+	 * Returns a like criterion used for matching objects against a query
484
+	 *
485
+	 * @param string $propertyName The name of the property to compare against
486
+	 * @param mixed $operand The value to compare with
487
+	 * @param boolean $caseSensitive Whether the matching should be done case-sensitive
488
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
489
+	 * @api
490
+	 */
491
+	public function like($propertyName, $operand, $caseSensitive = TRUE)
492
+	{
493
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand);
494
+	}
495
+
496
+	/**
497
+	 * Returns a "contains" criterion used for matching objects against a query.
498
+	 * It matches if the multivalued property contains the given operand.
499
+	 *
500
+	 * @param string $propertyName The name of the (multivalued) property to compare against
501
+	 * @param mixed $operand The value to compare with
502
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
503
+	 * @api
504
+	 */
505
+	public function contains($propertyName, $operand)
506
+	{
507
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand);
508
+	}
509
+
510
+	/**
511
+	 * Returns an "in" criterion used for matching objects against a query. It
512
+	 * matches if the property's value is contained in the multivalued operand.
513
+	 *
514
+	 * @param string $propertyName The name of the property to compare against
515
+	 * @param mixed $operand The value to compare with, multivalued
516
+	 * @throws UnexpectedTypeException
517
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
518
+	 * @api
519
+	 */
520
+	public function in($propertyName, $operand)
521
+	{
522
+		if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) {
523
+			throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095);
524
+		}
525
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand);
526
+	}
527
+
528
+	/**
529
+	 * Returns a less than criterion used for matching objects against a query
530
+	 *
531
+	 * @param string $propertyName The name of the property to compare against
532
+	 * @param mixed $operand The value to compare with
533
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
534
+	 * @api
535
+	 */
536
+	public function lessThan($propertyName, $operand)
537
+	{
538
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand);
539
+	}
540
+
541
+	/**
542
+	 * Returns a less or equal than criterion used for matching objects against a query
543
+	 *
544
+	 * @param string $propertyName The name of the property to compare against
545
+	 * @param mixed $operand The value to compare with
546
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
547
+	 * @api
548
+	 */
549
+	public function lessThanOrEqual($propertyName, $operand)
550
+	{
551
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand);
552
+	}
553
+
554
+	/**
555
+	 * Returns a greater than criterion used for matching objects against a query
556
+	 *
557
+	 * @param string $propertyName The name of the property to compare against
558
+	 * @param mixed $operand The value to compare with
559
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
560
+	 * @api
561
+	 */
562
+	public function greaterThan($propertyName, $operand)
563
+	{
564
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand);
565
+	}
566
+
567
+	/**
568
+	 * Returns a greater than or equal criterion used for matching objects against a query
569
+	 *
570
+	 * @param string $propertyName The name of the property to compare against
571
+	 * @param mixed $operand The value to compare with
572
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
573
+	 * @api
574
+	 */
575
+	public function greaterThanOrEqual($propertyName, $operand)
576
+	{
577
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand);
578
+	}
579
+
580
+	/**
581
+	 * Returns the query result count.
582
+	 *
583
+	 * @return integer The query result count
584
+	 * @api
585
+	 */
586
+	public function count()
587
+	{
588
+		/** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */
589
+		$backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this);
590
+		return $backend->countResult();
591
+	}
592
+
593
+	/**
594
+	 * Returns an "isEmpty" criterion used for matching objects against a query.
595
+	 * It matches if the multivalued property contains no values or is NULL.
596
+	 *
597
+	 * @param string $propertyName The name of the multivalued property to compare against
598
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
599
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
600
+	 * @api
601
+	 */
602
+	public function isEmpty($propertyName)
603
+	{
604
+		throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
605
+	}
606
+
607
+	/**
608
+	 * @return string
609
+	 */
610
+	public function getDistinct()
611
+	{
612
+		return $this->distinct;
613
+	}
614
+
615
+	/**
616
+	 * @param string $distinct
617
+	 * @return $this
618
+	 */
619
+	public function setDistinct($distinct)
620
+	{
621
+		$this->distinct = $distinct;
622
+		return $this;
623
+	}
624
+
625
+	/**
626
+	 * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage
627
+	 * backend (database).
628
+	 *
629
+	 * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement
630
+	 * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement.
631
+	 * @return QueryInterface
632
+	 */
633
+	public function statement($statement, array $parameters = array())
634
+	{
635
+		$this->statement = $this->qomFactory->statement($statement, $parameters);
636
+		return $this;
637
+	}
638
+
639
+	/**
640
+	 * Returns the statement of this query.
641
+	 *
642
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
643
+	 */
644
+	public function getStatement()
645
+	{
646
+		return $this->statement;
647
+	}
648
+
649
+	/**
650
+	 * Returns whether the current mode is Backend.
651
+	 *
652
+	 * @return bool
653
+	 */
654
+	protected function isBackendMode()
655
+	{
656
+		return TYPO3_MODE == 'BE';
657
+	}
658
+
659
+	/**
660
+	 * @return string
661
+	 */
662
+	public function getSourceFieldName()
663
+	{
664
+		return $this->sourceFieldName;
665
+	}
666
+
667
+	/**
668
+	 * @param string $sourceFieldName
669
+	 * @return $this
670
+	 */
671
+	public function setSourceFieldName($sourceFieldName)
672
+	{
673
+		$this->sourceFieldName = $sourceFieldName;
674
+		return $this;
675
+	}
676 676
 
677 677
 }
Please login to merge, or discard this patch.