Completed
Push — master ( ce1dfd...9c5a0c )
by Fabien
55:24
created
Tests/Unit/Tca/GridServiceTest.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 	#public function getLabelReturnNameAsValue() {
52 52
 	#	$GLOBALS['LANG'] = $this->getMock('TYPO3\CMS\Core\Localization\LanguageService', [], [], '', false);
53 53
 	#	$GLOBALS['LANG']->expects($this->once())->method('sL')->will($this->returnValue('Name'));
54
-    #
54
+	#
55 55
 	#	$this->assertEquals('Name', $this->fixture->getLabel('name'));
56 56
 	#}
57 57
 
Please login to merge, or discard this patch.
Configuration/Extbase/Persistence/Classes.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 declare(strict_types = 1);
3 3
 
4 4
 return [
5
-    \Fab\Vidi\Domain\Model\Selection::class => [
6
-        'tableName' => 'tx_vidi_selection',
7
-    ],
5
+	\Fab\Vidi\Domain\Model\Selection::class => [
6
+		'tableName' => 'tx_vidi_selection',
7
+	],
8 8
 ];
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-declare(strict_types = 1);
2
+declare(strict_types=1);
3 3
 
4 4
 return [
5 5
     \Fab\Vidi\Domain\Model\Selection::class => [
Please login to merge, or discard this patch.
ext_emconf.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 $EM_CONF[$_EXTKEY] = [
4
-    'title' => 'Versatile and Interactive Display - List Component',
5
-    'description' => 'Generic listing of records with versatile ways of interacting with the data, e.g. advanced filter, inline editing, mass editing, ... Veni, vidi, vici!',
6
-    'category' => 'module',
7
-    'author' => 'Fabien Udriot',
8
-    'author_email' => '[email protected]',
9
-    'module' => '',
10
-    'state' => 'stable',
11
-    'version' => '4.1.0-dev',
12
-    'autoload' => [
13
-        'psr-4' => ['Fab\\Vidi\\' => 'Classes']
14
-    ],
15
-    'constraints' =>
16
-        [
17
-            'depends' =>
18
-                [
19
-                    'typo3' => '9.5.0-10.4.99',
20
-                ],
21
-            'conflicts' =>
22
-                [
23
-                ],
24
-            'suggests' =>
25
-                [
26
-                ],
27
-        ]
4
+	'title' => 'Versatile and Interactive Display - List Component',
5
+	'description' => 'Generic listing of records with versatile ways of interacting with the data, e.g. advanced filter, inline editing, mass editing, ... Veni, vidi, vici!',
6
+	'category' => 'module',
7
+	'author' => 'Fabien Udriot',
8
+	'author_email' => '[email protected]',
9
+	'module' => '',
10
+	'state' => 'stable',
11
+	'version' => '4.1.0-dev',
12
+	'autoload' => [
13
+		'psr-4' => ['Fab\\Vidi\\' => 'Classes']
14
+	],
15
+	'constraints' =>
16
+		[
17
+			'depends' =>
18
+				[
19
+					'typo3' => '9.5.0-10.4.99',
20
+				],
21
+			'conflicts' =>
22
+				[
23
+				],
24
+			'suggests' =>
25
+				[
26
+				],
27
+		]
28 28
 ];
29 29
\ No newline at end of file
Please login to merge, or discard this patch.
Classes/Module/ModuleLoader.php 1 patch
Indentation   +1002 added lines, -1002 removed lines patch added patch discarded remove patch
@@ -20,1007 +20,1007 @@
 block discarded – undo
20 20
 class ModuleLoader
21 21
 {
22 22
 
23
-    /**
24
-     * Define the default main module
25
-     */
26
-    const DEFAULT_MAIN_MODULE = 'content';
27
-
28
-    /**
29
-     * Define the default pid
30
-     */
31
-    const DEFAULT_PID = 0;
32
-
33
-    /**
34
-     * The type of data being listed (which corresponds to a table name in TCA)
35
-     *
36
-     * @var string
37
-     */
38
-    protected $dataType;
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    protected $defaultPid;
44
-
45
-    /**
46
-     * @var bool
47
-     */
48
-    protected $isPidIgnored = false;
49
-
50
-    /**
51
-     * @var bool
52
-     */
53
-    protected $showPageTree = false;
54
-
55
-    /**
56
-     * @var bool
57
-     */
58
-    protected $isShown = true;
59
-
60
-    /**
61
-     * @var string
62
-     */
63
-    protected $access;
64
-
65
-    /**
66
-     * @var string
67
-     */
68
-    protected $mainModule;
69
-
70
-    /**
71
-     * @var string
72
-     */
73
-    protected $position = '';
74
-
75
-    /**
76
-     * @var string
77
-     */
78
-    protected $icon;
79
-
80
-    /**
81
-     * @var string
82
-     */
83
-    protected $moduleLanguageFile;
84
-
85
-    /**
86
-     * The module key such as m1, m2.
87
-     *
88
-     * @var string
89
-     */
90
-    protected $moduleKey = 'm1';
91
-
92
-    /**
93
-     * @var string[]
94
-     */
95
-    protected $additionalJavaScriptFiles = [];
96
-
97
-    /**
98
-     * @var string[]
99
-     */
100
-    protected $additionalStyleSheetFiles = [];
101
-
102
-    /**
103
-     * @var array
104
-     */
105
-    protected $components = [];
106
-
107
-    /**
108
-     * @param string $dataType
109
-     */
110
-    public function __construct($dataType = null)
111
-    {
112
-        $this->dataType = $dataType;
113
-
114
-        // Initialize components
115
-        $this->components = [
116
-            ModulePosition::DOC_HEADER => [
117
-                ModulePosition::TOP => [
118
-                    ModulePosition::LEFT => [],
119
-                    ModulePosition::RIGHT => [
120
-                        \Fab\Vidi\View\Button\ToolButton::class,
121
-                    ],
122
-                ],
123
-                ModulePosition::BOTTOM => [
124
-                    ModulePosition::LEFT => [
125
-                        \Fab\Vidi\View\Button\NewButton::class,
126
-                        \Fab\Vidi\ViewHelpers\Link\BackViewHelper::class,
127
-                    ],
128
-                    ModulePosition::RIGHT => [],
129
-                ],
130
-            ],
131
-            ModulePosition::GRID => [
132
-                ModulePosition::TOP => [
133
-                    \Fab\Vidi\View\Check\RelationsCheck::class,
134
-                    #\Fab\Vidi\View\Tab\DataTypeTab::class,
135
-                ],
136
-                ModulePosition::BUTTONS => [
137
-                    \Fab\Vidi\View\Button\EditButton::class,
138
-                    \Fab\Vidi\View\Button\DeleteButton::class,
139
-                ],
140
-                ModulePosition::BOTTOM => [],
141
-            ],
142
-            ModulePosition::MENU_MASS_ACTION => [
143
-                \Fab\Vidi\View\MenuItem\ExportXlsMenuItem::class,
144
-                \Fab\Vidi\View\MenuItem\ExportXmlMenuItem::class,
145
-                \Fab\Vidi\View\MenuItem\ExportCsvMenuItem::class,
146
-                \Fab\Vidi\View\MenuItem\DividerMenuItem::class,
147
-                \Fab\Vidi\View\MenuItem\MassDeleteMenuItem::class,
148
-                #\Fab\Vidi\View\MenuItem\MassEditMenuItem::class,
149
-            ],
150
-        ];
151
-    }
152
-
153
-    /**
154
-     * Tell whether a module is already registered.
155
-     *
156
-     * @param string $dataType
157
-     * @return bool
158
-     */
159
-    public function isRegistered($dataType): bool
160
-    {
161
-        $internalModuleSignature = $this->getInternalModuleSignature($dataType);
162
-        return !empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]);
163
-    }
164
-
165
-    /**
166
-     * @return array
167
-     */
168
-    protected function getExistingInternalConfiguration(): array
169
-    {
170
-        $internalModuleSignature = $this->getInternalModuleSignature();
171
-        return is_array($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature])
172
-            ? $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]
173
-            : [];
174
-    }
175
-
176
-    /**
177
-     * @return array
178
-     */
179
-    protected function getExistingMainConfiguration(): array
180
-    {
181
-        $possibleConfiguration = $GLOBALS['TBE_MODULES']['_configuration'][$this->computeMainModule() . '_' . $this->getInternalModuleSignature()];
182
-        return is_array($possibleConfiguration) ? $possibleConfiguration : [];
183
-    }
184
-
185
-    /**
186
-     * @return string
187
-     */
188
-    protected function computeMainModule(): string
189
-    {
190
-        $existingConfiguration = $this->getExistingInternalConfiguration();
191
-
192
-        if ($this->mainModule !== null) {
193
-            $mainModule = $this->mainModule;
194
-        } elseif ($existingConfiguration['mainModule']) { // existing configuration may override.
195
-            $mainModule = $existingConfiguration['mainModule'];
196
-        } else {
197
-            $mainModule = self::DEFAULT_MAIN_MODULE; //default value.
198
-        }
199
-        return $mainModule;
200
-    }
201
-
202
-    /**
203
-     * @return string
204
-     */
205
-    protected function computeDefaultPid(): string
206
-    {
207
-        $existingConfiguration = $this->getExistingInternalConfiguration();
208
-
209
-        if ($this->defaultPid !== null) {
210
-            $defaultPid = $this->defaultPid;
211
-        } elseif ($existingConfiguration['defaultPid']) { // existing configuration may override.
212
-            $defaultPid = $existingConfiguration['defaultPid'];
213
-        } else {
214
-            $defaultPid = self::DEFAULT_PID; //default value.
215
-        }
216
-        return $defaultPid;
217
-    }
218
-
219
-    /**
220
-     * @return array
221
-     */
222
-    protected function computeAdditionalJavaScriptFiles(): array
223
-    {
224
-        $additionalJavaScriptFiles = $this->additionalJavaScriptFiles;
225
-
226
-        // Possible merge of existing javascript files.
227
-        $existingConfiguration = $this->getExistingInternalConfiguration();
228
-        if ($existingConfiguration['additionalJavaScriptFiles']) {
229
-            $additionalJavaScriptFiles = array_merge($additionalJavaScriptFiles, $existingConfiguration['additionalJavaScriptFiles']);
230
-        }
231
-
232
-        return $additionalJavaScriptFiles;
233
-    }
234
-
235
-    /**
236
-     * @return array
237
-     */
238
-    protected function computeAdditionalStyleSheetFiles(): array
239
-    {
240
-        $additionalStyleSheetFiles = $this->additionalStyleSheetFiles;
241
-
242
-        // Possible merge of existing style sheets.
243
-        $existingConfiguration = $this->getExistingInternalConfiguration();
244
-        if ($existingConfiguration['additionalStyleSheetFiles']) {
245
-            $additionalStyleSheetFiles = array_merge($additionalStyleSheetFiles, $existingConfiguration['additionalStyleSheetFiles']);
246
-        }
247
-
248
-        return $additionalStyleSheetFiles;
249
-    }
250
-
251
-    /**
252
-     * @return array
253
-     */
254
-    protected function computeComponents(): array
255
-    {
256
-        // We override the config in any case. See if we need more than that.
257
-        return $this->components;
258
-    }
259
-
260
-    /**
261
-     * Register the module in two places: core + vidi internal.
262
-     *
263
-     * @return $this
264
-     */
265
-    public function register(): self
266
-    {
267
-        // Internal Vidi module registration.
268
-        $configuration = [];
269
-        $configuration['dataType'] = $this->dataType;
270
-        $configuration['mainModule'] = $this->computeMainModule();
271
-        $configuration['defaultPid'] = $this->computeDefaultPid();
272
-        $configuration['additionalJavaScriptFiles'] = $this->computeAdditionalJavaScriptFiles();
273
-        $configuration['additionalStyleSheetFiles'] = $this->computeAdditionalStyleSheetFiles();
274
-        $configuration['components'] = $this->computeComponents();
275
-        $configuration['isPidIgnored'] = $this->isPidIgnored;
276
-
277
-        $internalModuleSignature = $this->getInternalModuleSignature();
278
-        $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] = $configuration;
279
-
280
-        // Core module registration.
281
-        // Register and displays module in the BE only if told, default is "true".
282
-        if ($this->isShown) {
283
-
284
-            $moduleConfiguration = [];
285
-            #$moduleConfiguration['routeTarget'] = \Fab\Vidi\Controller\ContentController::class . '::mainAction', // what to do here?
286
-            $moduleConfiguration['access'] = $this->getAccess();
287
-            $moduleConfiguration['labels'] = $this->getModuleLanguageFile();
288
-            $icon = $this->getIcon();
289
-            if ($icon) {
290
-                $moduleConfiguration['icon'] = $icon;
291
-            }
292
-
293
-            if ($this->showPageTree) {
294
-                $moduleConfiguration['navigationComponentId'] = 'TYPO3/CMS/Backend/PageTree/PageTreeElement';
295
-                $moduleConfiguration['inheritNavigationComponentFromMainModule'] = true;
296
-            } else {
297
-                $moduleConfiguration['inheritNavigationComponentFromMainModule'] = true;
298
-            }
299
-
300
-            ExtensionUtility::registerModule(
301
-                'Fab.vidi',
302
-                $this->computeMainModule(),
303
-                $this->dataType . '_' . $this->moduleKey,
304
-                $this->position,
305
-                [
306
-                    'Content' => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard',
307
-                    'Tool' => 'welcome, work',
308
-                    'Facet' => 'autoSuggest, autoSuggests',
309
-                    'Selection' => 'edit, update, create, delete, list, show',
310
-                    'UserPreferences' => 'save',
311
-                    'Clipboard' => 'save, flush, show',
312
-                ],
313
-                $moduleConfiguration
314
-            );
315
-        }
316
-        return $this;
317
-    }
318
-
319
-    /**
320
-     * Return the module code for a BE module.
321
-     *
322
-     * @return string
323
-     */
324
-    public function getSignature(): string
325
-    {
326
-        $signature = GeneralUtility::_GP(Parameter::MODULE);
327
-        $trimmedSignature = trim($signature, '/');
328
-        return str_replace(['/', 'module_'], ['_', ''], $trimmedSignature);
329
-    }
330
-
331
-    /**
332
-     * Returns the current pid.
333
-     *
334
-     * @return int
335
-     */
336
-    public function getCurrentPid(): int
337
-    {
338
-        return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0;
339
-    }
340
-
341
-    /**
342
-     * Return the module URL.
343
-     *
344
-     * @param array $additionalParameters
345
-     * @return string
346
-     */
347
-    public function getModuleUrl(array $additionalParameters = []): string
348
-    {
349
-        $moduleCode = $this->getSignature();
350
-
351
-        // And don't forget the pid!
352
-        if (GeneralUtility::_GET(Parameter::PID)) {
353
-            $additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID);
354
-        }
355
-
356
-        return BackendUtility::getModuleUrl($moduleCode, $additionalParameters);
357
-    }
358
-
359
-    /**
360
-     * Return the parameter prefix for a BE module.
361
-     *
362
-     * @return string
363
-     */
364
-    public function getParameterPrefix(): string
365
-    {
366
-        return 'tx_vidi_' . strtolower($this->getSignature());
367
-    }
368
-
369
-    /**
370
-     * Return a configuration key or the entire module configuration array if not key is given.
371
-     *
372
-     * @param string $key
373
-     * @return mixed
374
-     */
375
-    public function getModuleConfiguration($key = '')
376
-    {
377
-
378
-        $vidiModuleCode = $this->getSignature();
379
-
380
-        // Module code must exist
381
-        if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) {
382
-            $message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode);
383
-            throw new InvalidKeyInArrayException($message, 1375092053);
384
-        }
385
-
386
-        $result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode];
387
-
388
-        if (!empty($key)) {
389
-            if (isset($result[$key])) {
390
-                $result = $result[$key];
391
-            } else {
392
-                // key must exist
393
-                $message = sprintf('Invalid key configuration "%s"', $key);
394
-                throw new InvalidKeyInArrayException($message, 1375092054);
395
-            }
396
-        }
397
-        return $result;
398
-    }
399
-
400
-    /**
401
-     * @param string $icon
402
-     * @return $this
403
-     */
404
-    public function setIcon($icon): self
405
-    {
406
-        $this->icon = $icon;
407
-        return $this;
408
-    }
409
-
410
-    /**
411
-     * @return string
412
-     */
413
-    protected function getIcon(): string
414
-    {
415
-        $moduleConfiguration = $this->getExistingMainConfiguration();
416
-
417
-
418
-        if ($this->icon) {
419
-            $icon = $this->icon;
420
-        } elseif ($moduleConfiguration['icon']) { // existing configuration may override.
421
-            $icon = $moduleConfiguration['icon'];
422
-        } else {
423
-            $icon = ''; //default value.
424
-        }
425
-
426
-        return $icon;
427
-    }
428
-
429
-    /**
430
-     * @param string $mainModule
431
-     * @return $this
432
-     */
433
-    public function setMainModule($mainModule): self
434
-    {
435
-        $this->mainModule = $mainModule;
436
-        return $this;
437
-    }
438
-
439
-    /**
440
-     * @return string
441
-     */
442
-    public function getMainModule(): string
443
-    {
444
-        if ($this->mainModule === null) {
445
-            $this->mainModule = $this->getModuleConfiguration('mainModule');
446
-        }
447
-        return $this->mainModule;
448
-    }
449
-
450
-    /**
451
-     * @param string $moduleLanguageFile
452
-     * @return $this
453
-     */
454
-    public function setModuleLanguageFile($moduleLanguageFile): self
455
-    {
456
-        $this->moduleLanguageFile = $moduleLanguageFile;
457
-        return $this;
458
-    }
459
-
460
-    /**
461
-     * @param string $component
462
-     * @return $this
463
-     */
464
-    public function removeComponentFromDocHeader(string $component): self
465
-    {
466
-        foreach ($this->components[ModulePosition::DOC_HEADER] as $verticalPosition => $docHeaders) {
467
-            foreach ($docHeaders as $horizontalPosition => $docHeader) {
468
-
469
-                $index = array_search($component, $docHeader, true);
470
-                if ($index !== false) {
471
-                    // $verticalPosition: top or bottom
472
-                    // $horizontalPosition: left or right
473
-                    unset($this->components[ModulePosition::DOC_HEADER][$verticalPosition][$horizontalPosition][$index]);
474
-                }
475
-            }
476
-        }
477
-        return $this;
478
-    }
479
-
480
-    /**
481
-     * @param bool $isPidIgnored
482
-     * @return $this
483
-     */
484
-    public function ignorePid(bool $isPidIgnored): self
485
-    {
486
-        $this->isPidIgnored = $isPidIgnored;
487
-        return $this;
488
-    }
489
-
490
-    /**
491
-     * @return bool
492
-     */
493
-    public function isPidIgnored(): bool
494
-    {
495
-        return $this->getModuleConfiguration('isPidIgnored');
496
-    }
497
-
498
-    /**
499
-     * @param string $component
500
-     * @return bool
501
-     */
502
-    public function hasComponentInDocHeader(string $component): bool
503
-    {
504
-        foreach ($this->getModuleConfiguration('components')[ModulePosition::DOC_HEADER] as $verticalPosition => $docHeaders) {
505
-            foreach ($docHeaders as $horizontalPosition => $docHeader) {
506
-
507
-                $index = array_search($component, $docHeader, true);
508
-                if ($index !== false) {
509
-                    return true;
510
-                }
511
-            }
512
-        }
513
-        return false;
514
-    }
515
-
516
-    /**
517
-     * @return string
518
-     */
519
-    protected function getModuleLanguageFile(): string
520
-    {
521
-        $moduleConfiguration = $this->getExistingMainConfiguration();
522
-
523
-        if ($this->moduleLanguageFile) {
524
-            $moduleLanguageFile = $this->moduleLanguageFile;
525
-        } elseif ($moduleConfiguration['labels']) { // existing configuration may override.
526
-            $moduleLanguageFile = $moduleConfiguration['labels'];
527
-        }
528
-        else {
529
-            $moduleLanguageFile = ''; //default value.
530
-        }
531
-
532
-        return $moduleLanguageFile;
533
-    }
534
-
535
-    /**
536
-     * @param string $position
537
-     * @return $this
538
-     */
539
-    public function setPosition($position): self
540
-    {
541
-        $this->position = $position;
542
-        return $this;
543
-    }
544
-
545
-    /**
546
-     * @return string
547
-     */
548
-    public function getPosition(): string
549
-    {
550
-        return $this->position;
551
-    }
552
-
553
-    /**
554
-     * @param array $files
555
-     * @return $this
556
-     */
557
-    public function addJavaScriptFiles(array $files): self
558
-    {
559
-        foreach ($files as $file) {
560
-            $this->additionalJavaScriptFiles[] = $file;
561
-        }
562
-        return $this;
563
-    }
564
-
565
-    /**
566
-     * @param string $fileNameAndPath
567
-     * @return $this
568
-     */
569
-    public function addJavaScriptFile($fileNameAndPath): self
570
-    {
571
-        $this->additionalJavaScriptFiles[] = $fileNameAndPath;
572
-        return $this;
573
-    }
574
-
575
-    /**
576
-     * @param array $files
577
-     * @return $this
578
-     */
579
-    public function addStyleSheetFiles(array $files): self
580
-    {
581
-        foreach ($files as $file) {
582
-            $this->additionalStyleSheetFiles[] = $file;
583
-        }
584
-        return $this;
585
-    }
586
-
587
-    /**
588
-     * @param string $fileNameAndPath
589
-     * @return $this
590
-     */
591
-    public function addStyleSheetFile($fileNameAndPath): self
592
-    {
593
-        $this->additionalStyleSheetFiles[] = $fileNameAndPath;
594
-        return $this;
595
-    }
596
-
597
-    /**
598
-     * @return string
599
-     */
600
-    public function getDataType(): string
601
-    {
602
-        if ($this->dataType === null) {
603
-            $this->dataType = $this->getModuleConfiguration('dataType');
604
-        }
605
-        return $this->dataType;
606
-    }
607
-
608
-    /**
609
-     * @return array
610
-     */
611
-    public function getDataTypes(): array
612
-    {
613
-        $dataTypes = [];
614
-        foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) {
615
-            $dataTypes[] = $module['dataType'];
616
-        }
617
-        return $dataTypes;
618
-    }
619
-
620
-    /**
621
-     * @param string $dataType
622
-     * @return $this
623
-     */
624
-    public function setDataType($dataType): self
625
-    {
626
-        $this->dataType = $dataType;
627
-        return $this;
628
-    }
629
-
630
-    /**
631
-     * @return int
632
-     */
633
-    public function getDefaultPid(): int
634
-    {
635
-        if (empty($this->defaultPid)) {
636
-            $this->defaultPid = $this->getModuleConfiguration('defaultPid');
637
-        }
638
-        return (int)$this->defaultPid;
639
-    }
640
-
641
-    /**
642
-     * @param string $defaultPid
643
-     * @return $this
644
-     */
645
-    public function setDefaultPid($defaultPid): self
646
-    {
647
-        $this->defaultPid = $defaultPid;
648
-        return $this;
649
-    }
650
-
651
-    /**
652
-     * @param bool $isPageTreeShown
653
-     * @return $this
654
-     */
655
-    public function showPageTree($isPageTreeShown): self
656
-    {
657
-        $this->showPageTree = $isPageTreeShown;
658
-        return $this;
659
-    }
660
-
661
-    /**
662
-     * @param string $isShown
663
-     * @return $this
664
-     */
665
-    public function isShown($isShown): self
666
-    {
667
-        $this->isShown = $isShown;
668
-        return $this;
669
-    }
670
-
671
-    /**
672
-     * @return $array
673
-     */
674
-    public function getDocHeaderTopLeftComponents()
675
-    {
676
-        $configuration = $this->getModuleConfiguration();
677
-        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
678
-    }
679
-
680
-    /**
681
-     * @param array $components
682
-     * @return $this
683
-     */
684
-    public function setDocHeaderTopLeftComponents(array $components): self
685
-    {
686
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components;
687
-        return $this;
688
-    }
689
-
690
-    /**
691
-     * @param string|array $components
692
-     * @return $this
693
-     */
694
-    public function addDocHeaderTopLeftComponents($components): self
695
-    {
696
-        if (is_string($components)) {
697
-            $components = [$components];
698
-        }
699
-        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
700
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components);
701
-        return $this;
702
-    }
703
-
704
-    /**
705
-     * @return $array
706
-     */
707
-    public function getDocHeaderTopRightComponents()
708
-    {
709
-        $configuration = $this->getModuleConfiguration();
710
-        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
711
-    }
712
-
713
-    /**
714
-     * @param array $components
715
-     * @return $this
716
-     */
717
-    public function setDocHeaderTopRightComponents(array $components): self
718
-    {
719
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components;
720
-        return $this;
721
-    }
722
-
723
-    /**
724
-     * @param string|array $components
725
-     * @return $this
726
-     */
727
-    public function addDocHeaderTopRightComponents($components): self
728
-    {
729
-        if (is_string($components)) {
730
-            $components = [$components];
731
-        }
732
-        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
733
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
734
-        return $this;
735
-    }
736
-
737
-    /**
738
-     * @return $array
739
-     */
740
-    public function getDocHeaderBottomLeftComponents()
741
-    {
742
-        $configuration = $this->getModuleConfiguration();
743
-        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
744
-    }
745
-
746
-    /**
747
-     * @param array $components
748
-     * @return $this
749
-     */
750
-    public function setDocHeaderBottomLeftComponents(array $components): self
751
-    {
752
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components;
753
-        return $this;
754
-    }
755
-
756
-    /**
757
-     * @param string|array $components
758
-     * @return $this
759
-     */
760
-    public function addDocHeaderBottomLeftComponents($components): self
761
-    {
762
-        if (is_string($components)) {
763
-            $components = [$components];
764
-        }
765
-        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
766
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components);
767
-        return $this;
768
-    }
769
-
770
-    /**
771
-     * @return $array
772
-     */
773
-    public function getDocHeaderBottomRightComponents()
774
-    {
775
-        $configuration = $this->getModuleConfiguration();
776
-        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
777
-    }
778
-
779
-    /**
780
-     * @param array $components
781
-     * @return $this
782
-     */
783
-    public function setDocHeaderBottomRightComponents(array $components): self
784
-    {
785
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components;
786
-        return $this;
787
-    }
788
-
789
-    /**
790
-     * @param string|array $components
791
-     * @return $this
792
-     */
793
-    public function addDocHeaderBottomRightComponents($components): self
794
-    {
795
-        if (is_string($components)) {
796
-            $components = [$components];
797
-        }
798
-        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
799
-        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
800
-        return $this;
801
-    }
802
-
803
-    /**
804
-     * @return $array
805
-     */
806
-    public function getGridTopComponents()
807
-    {
808
-        $configuration = $this->getModuleConfiguration();
809
-        return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP];
810
-    }
811
-
812
-    /**
813
-     * @param array $components
814
-     * @return $this
815
-     */
816
-    public function setGridTopComponents(array $components): self
817
-    {
818
-        $this->components[ModulePosition::GRID][ModulePosition::TOP] = $components;
819
-        return $this;
820
-    }
821
-
822
-    /**
823
-     * @param string|array $components
824
-     * @return $this
825
-     */
826
-    public function addGridTopComponents($components): self
827
-    {
828
-        if (is_string($components)) {
829
-            $components = [$components];
830
-        }
831
-        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP];
832
-        $this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components);
833
-        return $this;
834
-    }
835
-
836
-    /**
837
-     * @return mixed $array
838
-     */
839
-    public function getGridBottomComponents()
840
-    {
841
-        $configuration = $this->getModuleConfiguration();
842
-        return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM];
843
-    }
844
-
845
-    /**
846
-     * @param array $components
847
-     * @return $this
848
-     */
849
-    public function setGridBottomComponents(array $components): self
850
-    {
851
-        $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components;
852
-        return $this;
853
-    }
854
-
855
-    /**
856
-     * @param string|array $components
857
-     * @return $this
858
-     */
859
-    public function addGridBottomComponents($components): self
860
-    {
861
-        if (is_string($components)) {
862
-            $components = [$components];
863
-        }
864
-        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM];
865
-        $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components);
866
-        return $this;
867
-    }
868
-
869
-    /**
870
-     * @return $array
871
-     */
872
-    public function getGridButtonsComponents()
873
-    {
874
-        $configuration = $this->getModuleConfiguration();
875
-        return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS];
876
-    }
877
-
878
-    /**
879
-     * @param array $components
880
-     * @return $this
881
-     */
882
-    public function setGridButtonsComponents(array $components): self
883
-    {
884
-        $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components;
885
-        return $this;
886
-    }
887
-
888
-    /**
889
-     * @param string|array $components
890
-     * @return $this
891
-     */
892
-    public function addGridButtonsComponents($components): self
893
-    {
894
-        if (is_string($components)) {
895
-            $components = [$components];
896
-        }
897
-        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS];
898
-        $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($components, $currentComponents);
899
-        return $this;
900
-    }
901
-
902
-    /**
903
-     * @return $array
904
-     */
905
-    public function getMenuMassActionComponents()
906
-    {
907
-        $configuration = $this->getModuleConfiguration();
908
-        return $configuration['components'][ModulePosition::MENU_MASS_ACTION];
909
-    }
910
-
911
-    /**
912
-     * @param array $components
913
-     * @return $this
914
-     */
915
-    public function setMenuMassActionComponents(array $components): self
916
-    {
917
-        $this->components[ModulePosition::MENU_MASS_ACTION] = $components;
918
-        return $this;
919
-    }
920
-
921
-    /**
922
-     * @param string|array $components
923
-     * @return $this
924
-     */
925
-    public function addMenuMassActionComponents($components): self
926
-    {
927
-        if (is_string($components)) {
928
-            $components = [$components];
929
-        }
930
-        $currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION];
931
-        $this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($components, $currentComponents);
932
-        return $this;
933
-    }
934
-
935
-    /**
936
-     * @return string
937
-     */
938
-    protected function getAccess(): string
939
-    {
940
-        $moduleConfiguration = $this->getExistingMainConfiguration();
941
-
942
-        if ($this->access !== null) {
943
-            $access = $this->access;
944
-        } elseif ($moduleConfiguration['access']) { // existing configuration may override.
945
-            $access = $moduleConfiguration['access'];
946
-        } else {
947
-            $access = Access::USER; //default value.
948
-        }
949
-        return $access;
950
-    }
951
-
952
-    /**
953
-     * @param string $access
954
-     * @return $this
955
-     */
956
-    public function setAccess($access): self
957
-    {
958
-        $this->access = $access;
959
-        return $this;
960
-    }
961
-
962
-    /**
963
-     * @return \string[]
964
-     */
965
-    public function getAdditionalJavaScriptFiles(): array
966
-    {
967
-        if (empty($this->additionalJavaScriptFiles)) {
968
-            $this->additionalJavaScriptFiles = $this->getModuleConfiguration('additionalJavaScriptFiles');
969
-        }
970
-        return $this->additionalJavaScriptFiles;
971
-    }
972
-
973
-    /**
974
-     * @return \string[]
975
-     */
976
-    public function getAdditionalStyleSheetFiles(): array
977
-    {
978
-        if (empty($this->additionalStyleSheetFiles)) {
979
-            $this->additionalStyleSheetFiles = $this->getModuleConfiguration('additionalStyleSheetFiles');
980
-        }
981
-        return $this->additionalStyleSheetFiles;
982
-    }
983
-
984
-    /**
985
-     * @return array
986
-     */
987
-    public function getComponents(): array
988
-    {
989
-        return $this->components;
990
-    }
991
-
992
-    /**
993
-     * @param string $pluginName
994
-     * @return bool
995
-     */
996
-    public function hasPlugin($pluginName = ''): bool
997
-    {
998
-        $parameterPrefix = $this->getParameterPrefix();
999
-        $parameters = GeneralUtility::_GET($parameterPrefix);
1000
-
1001
-        $hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']);
1002
-        if ($hasPlugin && $pluginName) {
1003
-            $hasPlugin = in_array($pluginName, $parameters['plugins']);
1004
-        }
1005
-        return $hasPlugin;
1006
-    }
1007
-
1008
-    /**
1009
-     * Compute the internal module code
1010
-     *
1011
-     * @param null|string $dataType
1012
-     * @return string
1013
-     */
1014
-    protected function getInternalModuleSignature($dataType = null): string
1015
-    {
1016
-        // Else we forge the module signature
1017
-        if ($dataType === null) {
1018
-            $dataType = $this->dataType;
1019
-        }
1020
-        $subModuleName = $dataType . '_' . $this->moduleKey;
1021
-
1022
-        $mainModule = $this->mainModule ? : self::DEFAULT_MAIN_MODULE;
1023
-        return $mainModule . '_Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName);
1024
-    }
23
+	/**
24
+	 * Define the default main module
25
+	 */
26
+	const DEFAULT_MAIN_MODULE = 'content';
27
+
28
+	/**
29
+	 * Define the default pid
30
+	 */
31
+	const DEFAULT_PID = 0;
32
+
33
+	/**
34
+	 * The type of data being listed (which corresponds to a table name in TCA)
35
+	 *
36
+	 * @var string
37
+	 */
38
+	protected $dataType;
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	protected $defaultPid;
44
+
45
+	/**
46
+	 * @var bool
47
+	 */
48
+	protected $isPidIgnored = false;
49
+
50
+	/**
51
+	 * @var bool
52
+	 */
53
+	protected $showPageTree = false;
54
+
55
+	/**
56
+	 * @var bool
57
+	 */
58
+	protected $isShown = true;
59
+
60
+	/**
61
+	 * @var string
62
+	 */
63
+	protected $access;
64
+
65
+	/**
66
+	 * @var string
67
+	 */
68
+	protected $mainModule;
69
+
70
+	/**
71
+	 * @var string
72
+	 */
73
+	protected $position = '';
74
+
75
+	/**
76
+	 * @var string
77
+	 */
78
+	protected $icon;
79
+
80
+	/**
81
+	 * @var string
82
+	 */
83
+	protected $moduleLanguageFile;
84
+
85
+	/**
86
+	 * The module key such as m1, m2.
87
+	 *
88
+	 * @var string
89
+	 */
90
+	protected $moduleKey = 'm1';
91
+
92
+	/**
93
+	 * @var string[]
94
+	 */
95
+	protected $additionalJavaScriptFiles = [];
96
+
97
+	/**
98
+	 * @var string[]
99
+	 */
100
+	protected $additionalStyleSheetFiles = [];
101
+
102
+	/**
103
+	 * @var array
104
+	 */
105
+	protected $components = [];
106
+
107
+	/**
108
+	 * @param string $dataType
109
+	 */
110
+	public function __construct($dataType = null)
111
+	{
112
+		$this->dataType = $dataType;
113
+
114
+		// Initialize components
115
+		$this->components = [
116
+			ModulePosition::DOC_HEADER => [
117
+				ModulePosition::TOP => [
118
+					ModulePosition::LEFT => [],
119
+					ModulePosition::RIGHT => [
120
+						\Fab\Vidi\View\Button\ToolButton::class,
121
+					],
122
+				],
123
+				ModulePosition::BOTTOM => [
124
+					ModulePosition::LEFT => [
125
+						\Fab\Vidi\View\Button\NewButton::class,
126
+						\Fab\Vidi\ViewHelpers\Link\BackViewHelper::class,
127
+					],
128
+					ModulePosition::RIGHT => [],
129
+				],
130
+			],
131
+			ModulePosition::GRID => [
132
+				ModulePosition::TOP => [
133
+					\Fab\Vidi\View\Check\RelationsCheck::class,
134
+					#\Fab\Vidi\View\Tab\DataTypeTab::class,
135
+				],
136
+				ModulePosition::BUTTONS => [
137
+					\Fab\Vidi\View\Button\EditButton::class,
138
+					\Fab\Vidi\View\Button\DeleteButton::class,
139
+				],
140
+				ModulePosition::BOTTOM => [],
141
+			],
142
+			ModulePosition::MENU_MASS_ACTION => [
143
+				\Fab\Vidi\View\MenuItem\ExportXlsMenuItem::class,
144
+				\Fab\Vidi\View\MenuItem\ExportXmlMenuItem::class,
145
+				\Fab\Vidi\View\MenuItem\ExportCsvMenuItem::class,
146
+				\Fab\Vidi\View\MenuItem\DividerMenuItem::class,
147
+				\Fab\Vidi\View\MenuItem\MassDeleteMenuItem::class,
148
+				#\Fab\Vidi\View\MenuItem\MassEditMenuItem::class,
149
+			],
150
+		];
151
+	}
152
+
153
+	/**
154
+	 * Tell whether a module is already registered.
155
+	 *
156
+	 * @param string $dataType
157
+	 * @return bool
158
+	 */
159
+	public function isRegistered($dataType): bool
160
+	{
161
+		$internalModuleSignature = $this->getInternalModuleSignature($dataType);
162
+		return !empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]);
163
+	}
164
+
165
+	/**
166
+	 * @return array
167
+	 */
168
+	protected function getExistingInternalConfiguration(): array
169
+	{
170
+		$internalModuleSignature = $this->getInternalModuleSignature();
171
+		return is_array($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature])
172
+			? $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]
173
+			: [];
174
+	}
175
+
176
+	/**
177
+	 * @return array
178
+	 */
179
+	protected function getExistingMainConfiguration(): array
180
+	{
181
+		$possibleConfiguration = $GLOBALS['TBE_MODULES']['_configuration'][$this->computeMainModule() . '_' . $this->getInternalModuleSignature()];
182
+		return is_array($possibleConfiguration) ? $possibleConfiguration : [];
183
+	}
184
+
185
+	/**
186
+	 * @return string
187
+	 */
188
+	protected function computeMainModule(): string
189
+	{
190
+		$existingConfiguration = $this->getExistingInternalConfiguration();
191
+
192
+		if ($this->mainModule !== null) {
193
+			$mainModule = $this->mainModule;
194
+		} elseif ($existingConfiguration['mainModule']) { // existing configuration may override.
195
+			$mainModule = $existingConfiguration['mainModule'];
196
+		} else {
197
+			$mainModule = self::DEFAULT_MAIN_MODULE; //default value.
198
+		}
199
+		return $mainModule;
200
+	}
201
+
202
+	/**
203
+	 * @return string
204
+	 */
205
+	protected function computeDefaultPid(): string
206
+	{
207
+		$existingConfiguration = $this->getExistingInternalConfiguration();
208
+
209
+		if ($this->defaultPid !== null) {
210
+			$defaultPid = $this->defaultPid;
211
+		} elseif ($existingConfiguration['defaultPid']) { // existing configuration may override.
212
+			$defaultPid = $existingConfiguration['defaultPid'];
213
+		} else {
214
+			$defaultPid = self::DEFAULT_PID; //default value.
215
+		}
216
+		return $defaultPid;
217
+	}
218
+
219
+	/**
220
+	 * @return array
221
+	 */
222
+	protected function computeAdditionalJavaScriptFiles(): array
223
+	{
224
+		$additionalJavaScriptFiles = $this->additionalJavaScriptFiles;
225
+
226
+		// Possible merge of existing javascript files.
227
+		$existingConfiguration = $this->getExistingInternalConfiguration();
228
+		if ($existingConfiguration['additionalJavaScriptFiles']) {
229
+			$additionalJavaScriptFiles = array_merge($additionalJavaScriptFiles, $existingConfiguration['additionalJavaScriptFiles']);
230
+		}
231
+
232
+		return $additionalJavaScriptFiles;
233
+	}
234
+
235
+	/**
236
+	 * @return array
237
+	 */
238
+	protected function computeAdditionalStyleSheetFiles(): array
239
+	{
240
+		$additionalStyleSheetFiles = $this->additionalStyleSheetFiles;
241
+
242
+		// Possible merge of existing style sheets.
243
+		$existingConfiguration = $this->getExistingInternalConfiguration();
244
+		if ($existingConfiguration['additionalStyleSheetFiles']) {
245
+			$additionalStyleSheetFiles = array_merge($additionalStyleSheetFiles, $existingConfiguration['additionalStyleSheetFiles']);
246
+		}
247
+
248
+		return $additionalStyleSheetFiles;
249
+	}
250
+
251
+	/**
252
+	 * @return array
253
+	 */
254
+	protected function computeComponents(): array
255
+	{
256
+		// We override the config in any case. See if we need more than that.
257
+		return $this->components;
258
+	}
259
+
260
+	/**
261
+	 * Register the module in two places: core + vidi internal.
262
+	 *
263
+	 * @return $this
264
+	 */
265
+	public function register(): self
266
+	{
267
+		// Internal Vidi module registration.
268
+		$configuration = [];
269
+		$configuration['dataType'] = $this->dataType;
270
+		$configuration['mainModule'] = $this->computeMainModule();
271
+		$configuration['defaultPid'] = $this->computeDefaultPid();
272
+		$configuration['additionalJavaScriptFiles'] = $this->computeAdditionalJavaScriptFiles();
273
+		$configuration['additionalStyleSheetFiles'] = $this->computeAdditionalStyleSheetFiles();
274
+		$configuration['components'] = $this->computeComponents();
275
+		$configuration['isPidIgnored'] = $this->isPidIgnored;
276
+
277
+		$internalModuleSignature = $this->getInternalModuleSignature();
278
+		$GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] = $configuration;
279
+
280
+		// Core module registration.
281
+		// Register and displays module in the BE only if told, default is "true".
282
+		if ($this->isShown) {
283
+
284
+			$moduleConfiguration = [];
285
+			#$moduleConfiguration['routeTarget'] = \Fab\Vidi\Controller\ContentController::class . '::mainAction', // what to do here?
286
+			$moduleConfiguration['access'] = $this->getAccess();
287
+			$moduleConfiguration['labels'] = $this->getModuleLanguageFile();
288
+			$icon = $this->getIcon();
289
+			if ($icon) {
290
+				$moduleConfiguration['icon'] = $icon;
291
+			}
292
+
293
+			if ($this->showPageTree) {
294
+				$moduleConfiguration['navigationComponentId'] = 'TYPO3/CMS/Backend/PageTree/PageTreeElement';
295
+				$moduleConfiguration['inheritNavigationComponentFromMainModule'] = true;
296
+			} else {
297
+				$moduleConfiguration['inheritNavigationComponentFromMainModule'] = true;
298
+			}
299
+
300
+			ExtensionUtility::registerModule(
301
+				'Fab.vidi',
302
+				$this->computeMainModule(),
303
+				$this->dataType . '_' . $this->moduleKey,
304
+				$this->position,
305
+				[
306
+					'Content' => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard',
307
+					'Tool' => 'welcome, work',
308
+					'Facet' => 'autoSuggest, autoSuggests',
309
+					'Selection' => 'edit, update, create, delete, list, show',
310
+					'UserPreferences' => 'save',
311
+					'Clipboard' => 'save, flush, show',
312
+				],
313
+				$moduleConfiguration
314
+			);
315
+		}
316
+		return $this;
317
+	}
318
+
319
+	/**
320
+	 * Return the module code for a BE module.
321
+	 *
322
+	 * @return string
323
+	 */
324
+	public function getSignature(): string
325
+	{
326
+		$signature = GeneralUtility::_GP(Parameter::MODULE);
327
+		$trimmedSignature = trim($signature, '/');
328
+		return str_replace(['/', 'module_'], ['_', ''], $trimmedSignature);
329
+	}
330
+
331
+	/**
332
+	 * Returns the current pid.
333
+	 *
334
+	 * @return int
335
+	 */
336
+	public function getCurrentPid(): int
337
+	{
338
+		return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0;
339
+	}
340
+
341
+	/**
342
+	 * Return the module URL.
343
+	 *
344
+	 * @param array $additionalParameters
345
+	 * @return string
346
+	 */
347
+	public function getModuleUrl(array $additionalParameters = []): string
348
+	{
349
+		$moduleCode = $this->getSignature();
350
+
351
+		// And don't forget the pid!
352
+		if (GeneralUtility::_GET(Parameter::PID)) {
353
+			$additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID);
354
+		}
355
+
356
+		return BackendUtility::getModuleUrl($moduleCode, $additionalParameters);
357
+	}
358
+
359
+	/**
360
+	 * Return the parameter prefix for a BE module.
361
+	 *
362
+	 * @return string
363
+	 */
364
+	public function getParameterPrefix(): string
365
+	{
366
+		return 'tx_vidi_' . strtolower($this->getSignature());
367
+	}
368
+
369
+	/**
370
+	 * Return a configuration key or the entire module configuration array if not key is given.
371
+	 *
372
+	 * @param string $key
373
+	 * @return mixed
374
+	 */
375
+	public function getModuleConfiguration($key = '')
376
+	{
377
+
378
+		$vidiModuleCode = $this->getSignature();
379
+
380
+		// Module code must exist
381
+		if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) {
382
+			$message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode);
383
+			throw new InvalidKeyInArrayException($message, 1375092053);
384
+		}
385
+
386
+		$result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode];
387
+
388
+		if (!empty($key)) {
389
+			if (isset($result[$key])) {
390
+				$result = $result[$key];
391
+			} else {
392
+				// key must exist
393
+				$message = sprintf('Invalid key configuration "%s"', $key);
394
+				throw new InvalidKeyInArrayException($message, 1375092054);
395
+			}
396
+		}
397
+		return $result;
398
+	}
399
+
400
+	/**
401
+	 * @param string $icon
402
+	 * @return $this
403
+	 */
404
+	public function setIcon($icon): self
405
+	{
406
+		$this->icon = $icon;
407
+		return $this;
408
+	}
409
+
410
+	/**
411
+	 * @return string
412
+	 */
413
+	protected function getIcon(): string
414
+	{
415
+		$moduleConfiguration = $this->getExistingMainConfiguration();
416
+
417
+
418
+		if ($this->icon) {
419
+			$icon = $this->icon;
420
+		} elseif ($moduleConfiguration['icon']) { // existing configuration may override.
421
+			$icon = $moduleConfiguration['icon'];
422
+		} else {
423
+			$icon = ''; //default value.
424
+		}
425
+
426
+		return $icon;
427
+	}
428
+
429
+	/**
430
+	 * @param string $mainModule
431
+	 * @return $this
432
+	 */
433
+	public function setMainModule($mainModule): self
434
+	{
435
+		$this->mainModule = $mainModule;
436
+		return $this;
437
+	}
438
+
439
+	/**
440
+	 * @return string
441
+	 */
442
+	public function getMainModule(): string
443
+	{
444
+		if ($this->mainModule === null) {
445
+			$this->mainModule = $this->getModuleConfiguration('mainModule');
446
+		}
447
+		return $this->mainModule;
448
+	}
449
+
450
+	/**
451
+	 * @param string $moduleLanguageFile
452
+	 * @return $this
453
+	 */
454
+	public function setModuleLanguageFile($moduleLanguageFile): self
455
+	{
456
+		$this->moduleLanguageFile = $moduleLanguageFile;
457
+		return $this;
458
+	}
459
+
460
+	/**
461
+	 * @param string $component
462
+	 * @return $this
463
+	 */
464
+	public function removeComponentFromDocHeader(string $component): self
465
+	{
466
+		foreach ($this->components[ModulePosition::DOC_HEADER] as $verticalPosition => $docHeaders) {
467
+			foreach ($docHeaders as $horizontalPosition => $docHeader) {
468
+
469
+				$index = array_search($component, $docHeader, true);
470
+				if ($index !== false) {
471
+					// $verticalPosition: top or bottom
472
+					// $horizontalPosition: left or right
473
+					unset($this->components[ModulePosition::DOC_HEADER][$verticalPosition][$horizontalPosition][$index]);
474
+				}
475
+			}
476
+		}
477
+		return $this;
478
+	}
479
+
480
+	/**
481
+	 * @param bool $isPidIgnored
482
+	 * @return $this
483
+	 */
484
+	public function ignorePid(bool $isPidIgnored): self
485
+	{
486
+		$this->isPidIgnored = $isPidIgnored;
487
+		return $this;
488
+	}
489
+
490
+	/**
491
+	 * @return bool
492
+	 */
493
+	public function isPidIgnored(): bool
494
+	{
495
+		return $this->getModuleConfiguration('isPidIgnored');
496
+	}
497
+
498
+	/**
499
+	 * @param string $component
500
+	 * @return bool
501
+	 */
502
+	public function hasComponentInDocHeader(string $component): bool
503
+	{
504
+		foreach ($this->getModuleConfiguration('components')[ModulePosition::DOC_HEADER] as $verticalPosition => $docHeaders) {
505
+			foreach ($docHeaders as $horizontalPosition => $docHeader) {
506
+
507
+				$index = array_search($component, $docHeader, true);
508
+				if ($index !== false) {
509
+					return true;
510
+				}
511
+			}
512
+		}
513
+		return false;
514
+	}
515
+
516
+	/**
517
+	 * @return string
518
+	 */
519
+	protected function getModuleLanguageFile(): string
520
+	{
521
+		$moduleConfiguration = $this->getExistingMainConfiguration();
522
+
523
+		if ($this->moduleLanguageFile) {
524
+			$moduleLanguageFile = $this->moduleLanguageFile;
525
+		} elseif ($moduleConfiguration['labels']) { // existing configuration may override.
526
+			$moduleLanguageFile = $moduleConfiguration['labels'];
527
+		}
528
+		else {
529
+			$moduleLanguageFile = ''; //default value.
530
+		}
531
+
532
+		return $moduleLanguageFile;
533
+	}
534
+
535
+	/**
536
+	 * @param string $position
537
+	 * @return $this
538
+	 */
539
+	public function setPosition($position): self
540
+	{
541
+		$this->position = $position;
542
+		return $this;
543
+	}
544
+
545
+	/**
546
+	 * @return string
547
+	 */
548
+	public function getPosition(): string
549
+	{
550
+		return $this->position;
551
+	}
552
+
553
+	/**
554
+	 * @param array $files
555
+	 * @return $this
556
+	 */
557
+	public function addJavaScriptFiles(array $files): self
558
+	{
559
+		foreach ($files as $file) {
560
+			$this->additionalJavaScriptFiles[] = $file;
561
+		}
562
+		return $this;
563
+	}
564
+
565
+	/**
566
+	 * @param string $fileNameAndPath
567
+	 * @return $this
568
+	 */
569
+	public function addJavaScriptFile($fileNameAndPath): self
570
+	{
571
+		$this->additionalJavaScriptFiles[] = $fileNameAndPath;
572
+		return $this;
573
+	}
574
+
575
+	/**
576
+	 * @param array $files
577
+	 * @return $this
578
+	 */
579
+	public function addStyleSheetFiles(array $files): self
580
+	{
581
+		foreach ($files as $file) {
582
+			$this->additionalStyleSheetFiles[] = $file;
583
+		}
584
+		return $this;
585
+	}
586
+
587
+	/**
588
+	 * @param string $fileNameAndPath
589
+	 * @return $this
590
+	 */
591
+	public function addStyleSheetFile($fileNameAndPath): self
592
+	{
593
+		$this->additionalStyleSheetFiles[] = $fileNameAndPath;
594
+		return $this;
595
+	}
596
+
597
+	/**
598
+	 * @return string
599
+	 */
600
+	public function getDataType(): string
601
+	{
602
+		if ($this->dataType === null) {
603
+			$this->dataType = $this->getModuleConfiguration('dataType');
604
+		}
605
+		return $this->dataType;
606
+	}
607
+
608
+	/**
609
+	 * @return array
610
+	 */
611
+	public function getDataTypes(): array
612
+	{
613
+		$dataTypes = [];
614
+		foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) {
615
+			$dataTypes[] = $module['dataType'];
616
+		}
617
+		return $dataTypes;
618
+	}
619
+
620
+	/**
621
+	 * @param string $dataType
622
+	 * @return $this
623
+	 */
624
+	public function setDataType($dataType): self
625
+	{
626
+		$this->dataType = $dataType;
627
+		return $this;
628
+	}
629
+
630
+	/**
631
+	 * @return int
632
+	 */
633
+	public function getDefaultPid(): int
634
+	{
635
+		if (empty($this->defaultPid)) {
636
+			$this->defaultPid = $this->getModuleConfiguration('defaultPid');
637
+		}
638
+		return (int)$this->defaultPid;
639
+	}
640
+
641
+	/**
642
+	 * @param string $defaultPid
643
+	 * @return $this
644
+	 */
645
+	public function setDefaultPid($defaultPid): self
646
+	{
647
+		$this->defaultPid = $defaultPid;
648
+		return $this;
649
+	}
650
+
651
+	/**
652
+	 * @param bool $isPageTreeShown
653
+	 * @return $this
654
+	 */
655
+	public function showPageTree($isPageTreeShown): self
656
+	{
657
+		$this->showPageTree = $isPageTreeShown;
658
+		return $this;
659
+	}
660
+
661
+	/**
662
+	 * @param string $isShown
663
+	 * @return $this
664
+	 */
665
+	public function isShown($isShown): self
666
+	{
667
+		$this->isShown = $isShown;
668
+		return $this;
669
+	}
670
+
671
+	/**
672
+	 * @return $array
673
+	 */
674
+	public function getDocHeaderTopLeftComponents()
675
+	{
676
+		$configuration = $this->getModuleConfiguration();
677
+		return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
678
+	}
679
+
680
+	/**
681
+	 * @param array $components
682
+	 * @return $this
683
+	 */
684
+	public function setDocHeaderTopLeftComponents(array $components): self
685
+	{
686
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components;
687
+		return $this;
688
+	}
689
+
690
+	/**
691
+	 * @param string|array $components
692
+	 * @return $this
693
+	 */
694
+	public function addDocHeaderTopLeftComponents($components): self
695
+	{
696
+		if (is_string($components)) {
697
+			$components = [$components];
698
+		}
699
+		$currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
700
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components);
701
+		return $this;
702
+	}
703
+
704
+	/**
705
+	 * @return $array
706
+	 */
707
+	public function getDocHeaderTopRightComponents()
708
+	{
709
+		$configuration = $this->getModuleConfiguration();
710
+		return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
711
+	}
712
+
713
+	/**
714
+	 * @param array $components
715
+	 * @return $this
716
+	 */
717
+	public function setDocHeaderTopRightComponents(array $components): self
718
+	{
719
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components;
720
+		return $this;
721
+	}
722
+
723
+	/**
724
+	 * @param string|array $components
725
+	 * @return $this
726
+	 */
727
+	public function addDocHeaderTopRightComponents($components): self
728
+	{
729
+		if (is_string($components)) {
730
+			$components = [$components];
731
+		}
732
+		$currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
733
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
734
+		return $this;
735
+	}
736
+
737
+	/**
738
+	 * @return $array
739
+	 */
740
+	public function getDocHeaderBottomLeftComponents()
741
+	{
742
+		$configuration = $this->getModuleConfiguration();
743
+		return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
744
+	}
745
+
746
+	/**
747
+	 * @param array $components
748
+	 * @return $this
749
+	 */
750
+	public function setDocHeaderBottomLeftComponents(array $components): self
751
+	{
752
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components;
753
+		return $this;
754
+	}
755
+
756
+	/**
757
+	 * @param string|array $components
758
+	 * @return $this
759
+	 */
760
+	public function addDocHeaderBottomLeftComponents($components): self
761
+	{
762
+		if (is_string($components)) {
763
+			$components = [$components];
764
+		}
765
+		$currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
766
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components);
767
+		return $this;
768
+	}
769
+
770
+	/**
771
+	 * @return $array
772
+	 */
773
+	public function getDocHeaderBottomRightComponents()
774
+	{
775
+		$configuration = $this->getModuleConfiguration();
776
+		return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
777
+	}
778
+
779
+	/**
780
+	 * @param array $components
781
+	 * @return $this
782
+	 */
783
+	public function setDocHeaderBottomRightComponents(array $components): self
784
+	{
785
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components;
786
+		return $this;
787
+	}
788
+
789
+	/**
790
+	 * @param string|array $components
791
+	 * @return $this
792
+	 */
793
+	public function addDocHeaderBottomRightComponents($components): self
794
+	{
795
+		if (is_string($components)) {
796
+			$components = [$components];
797
+		}
798
+		$currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
799
+		$this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
800
+		return $this;
801
+	}
802
+
803
+	/**
804
+	 * @return $array
805
+	 */
806
+	public function getGridTopComponents()
807
+	{
808
+		$configuration = $this->getModuleConfiguration();
809
+		return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP];
810
+	}
811
+
812
+	/**
813
+	 * @param array $components
814
+	 * @return $this
815
+	 */
816
+	public function setGridTopComponents(array $components): self
817
+	{
818
+		$this->components[ModulePosition::GRID][ModulePosition::TOP] = $components;
819
+		return $this;
820
+	}
821
+
822
+	/**
823
+	 * @param string|array $components
824
+	 * @return $this
825
+	 */
826
+	public function addGridTopComponents($components): self
827
+	{
828
+		if (is_string($components)) {
829
+			$components = [$components];
830
+		}
831
+		$currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP];
832
+		$this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components);
833
+		return $this;
834
+	}
835
+
836
+	/**
837
+	 * @return mixed $array
838
+	 */
839
+	public function getGridBottomComponents()
840
+	{
841
+		$configuration = $this->getModuleConfiguration();
842
+		return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM];
843
+	}
844
+
845
+	/**
846
+	 * @param array $components
847
+	 * @return $this
848
+	 */
849
+	public function setGridBottomComponents(array $components): self
850
+	{
851
+		$this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components;
852
+		return $this;
853
+	}
854
+
855
+	/**
856
+	 * @param string|array $components
857
+	 * @return $this
858
+	 */
859
+	public function addGridBottomComponents($components): self
860
+	{
861
+		if (is_string($components)) {
862
+			$components = [$components];
863
+		}
864
+		$currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM];
865
+		$this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components);
866
+		return $this;
867
+	}
868
+
869
+	/**
870
+	 * @return $array
871
+	 */
872
+	public function getGridButtonsComponents()
873
+	{
874
+		$configuration = $this->getModuleConfiguration();
875
+		return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS];
876
+	}
877
+
878
+	/**
879
+	 * @param array $components
880
+	 * @return $this
881
+	 */
882
+	public function setGridButtonsComponents(array $components): self
883
+	{
884
+		$this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components;
885
+		return $this;
886
+	}
887
+
888
+	/**
889
+	 * @param string|array $components
890
+	 * @return $this
891
+	 */
892
+	public function addGridButtonsComponents($components): self
893
+	{
894
+		if (is_string($components)) {
895
+			$components = [$components];
896
+		}
897
+		$currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS];
898
+		$this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($components, $currentComponents);
899
+		return $this;
900
+	}
901
+
902
+	/**
903
+	 * @return $array
904
+	 */
905
+	public function getMenuMassActionComponents()
906
+	{
907
+		$configuration = $this->getModuleConfiguration();
908
+		return $configuration['components'][ModulePosition::MENU_MASS_ACTION];
909
+	}
910
+
911
+	/**
912
+	 * @param array $components
913
+	 * @return $this
914
+	 */
915
+	public function setMenuMassActionComponents(array $components): self
916
+	{
917
+		$this->components[ModulePosition::MENU_MASS_ACTION] = $components;
918
+		return $this;
919
+	}
920
+
921
+	/**
922
+	 * @param string|array $components
923
+	 * @return $this
924
+	 */
925
+	public function addMenuMassActionComponents($components): self
926
+	{
927
+		if (is_string($components)) {
928
+			$components = [$components];
929
+		}
930
+		$currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION];
931
+		$this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($components, $currentComponents);
932
+		return $this;
933
+	}
934
+
935
+	/**
936
+	 * @return string
937
+	 */
938
+	protected function getAccess(): string
939
+	{
940
+		$moduleConfiguration = $this->getExistingMainConfiguration();
941
+
942
+		if ($this->access !== null) {
943
+			$access = $this->access;
944
+		} elseif ($moduleConfiguration['access']) { // existing configuration may override.
945
+			$access = $moduleConfiguration['access'];
946
+		} else {
947
+			$access = Access::USER; //default value.
948
+		}
949
+		return $access;
950
+	}
951
+
952
+	/**
953
+	 * @param string $access
954
+	 * @return $this
955
+	 */
956
+	public function setAccess($access): self
957
+	{
958
+		$this->access = $access;
959
+		return $this;
960
+	}
961
+
962
+	/**
963
+	 * @return \string[]
964
+	 */
965
+	public function getAdditionalJavaScriptFiles(): array
966
+	{
967
+		if (empty($this->additionalJavaScriptFiles)) {
968
+			$this->additionalJavaScriptFiles = $this->getModuleConfiguration('additionalJavaScriptFiles');
969
+		}
970
+		return $this->additionalJavaScriptFiles;
971
+	}
972
+
973
+	/**
974
+	 * @return \string[]
975
+	 */
976
+	public function getAdditionalStyleSheetFiles(): array
977
+	{
978
+		if (empty($this->additionalStyleSheetFiles)) {
979
+			$this->additionalStyleSheetFiles = $this->getModuleConfiguration('additionalStyleSheetFiles');
980
+		}
981
+		return $this->additionalStyleSheetFiles;
982
+	}
983
+
984
+	/**
985
+	 * @return array
986
+	 */
987
+	public function getComponents(): array
988
+	{
989
+		return $this->components;
990
+	}
991
+
992
+	/**
993
+	 * @param string $pluginName
994
+	 * @return bool
995
+	 */
996
+	public function hasPlugin($pluginName = ''): bool
997
+	{
998
+		$parameterPrefix = $this->getParameterPrefix();
999
+		$parameters = GeneralUtility::_GET($parameterPrefix);
1000
+
1001
+		$hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']);
1002
+		if ($hasPlugin && $pluginName) {
1003
+			$hasPlugin = in_array($pluginName, $parameters['plugins']);
1004
+		}
1005
+		return $hasPlugin;
1006
+	}
1007
+
1008
+	/**
1009
+	 * Compute the internal module code
1010
+	 *
1011
+	 * @param null|string $dataType
1012
+	 * @return string
1013
+	 */
1014
+	protected function getInternalModuleSignature($dataType = null): string
1015
+	{
1016
+		// Else we forge the module signature
1017
+		if ($dataType === null) {
1018
+			$dataType = $this->dataType;
1019
+		}
1020
+		$subModuleName = $dataType . '_' . $this->moduleKey;
1021
+
1022
+		$mainModule = $this->mainModule ? : self::DEFAULT_MAIN_MODULE;
1023
+		return $mainModule . '_Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName);
1024
+	}
1025 1025
 
1026 1026
 }
Please login to merge, or discard this patch.
Classes/View/AbstractComponentView.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -17,48 +17,48 @@
 block discarded – undo
17 17
 abstract class AbstractComponentView implements ViewComponentInterface
18 18
 {
19 19
 
20
-    /**
21
-     * Get the Vidi Module Loader.
22
-     *
23
-     * @return \Fab\Vidi\Module\ModuleLoader|object
24
-     */
25
-    protected function getModuleLoader()
26
-    {
27
-        return GeneralUtility::makeInstance(\Fab\Vidi\Module\ModuleLoader::class);
28
-    }
20
+	/**
21
+	 * Get the Vidi Module Loader.
22
+	 *
23
+	 * @return \Fab\Vidi\Module\ModuleLoader|object
24
+	 */
25
+	protected function getModuleLoader()
26
+	{
27
+		return GeneralUtility::makeInstance(\Fab\Vidi\Module\ModuleLoader::class);
28
+	}
29 29
 
30
-    /**
31
-     * Returns an instance of the current Backend User.
32
-     *
33
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
34
-     */
35
-    protected function getBackendUser()
36
-    {
37
-        return $GLOBALS['BE_USER'];
38
-    }
30
+	/**
31
+	 * Returns an instance of the current Backend User.
32
+	 *
33
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
34
+	 */
35
+	protected function getBackendUser()
36
+	{
37
+		return $GLOBALS['BE_USER'];
38
+	}
39 39
 
40
-    /**
41
-     * @return \TYPO3\CMS\Core\Localization\LanguageService|object
42
-     */
43
-    protected function getLanguageService()
44
-    {
45
-        return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\LanguageService::class);
46
-    }
40
+	/**
41
+	 * @return \TYPO3\CMS\Core\Localization\LanguageService|object
42
+	 */
43
+	protected function getLanguageService()
44
+	{
45
+		return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\LanguageService::class);
46
+	}
47 47
 
48
-    /**
49
-     * @return IconFactory|object
50
-     */
51
-    protected function getIconFactory()
52
-    {
53
-        return GeneralUtility::makeInstance(IconFactory::class);
54
-    }
48
+	/**
49
+	 * @return IconFactory|object
50
+	 */
51
+	protected function getIconFactory()
52
+	{
53
+		return GeneralUtility::makeInstance(IconFactory::class);
54
+	}
55 55
 
56
-    /**
57
-     * @return LinkButton|object
58
-     */
59
-    protected function makeLinkButton()
60
-    {
61
-        return GeneralUtility::makeInstance(LinkButton::class);
62
-    }
56
+	/**
57
+	 * @return LinkButton|object
58
+	 */
59
+	protected function makeLinkButton()
60
+	{
61
+		return GeneralUtility::makeInstance(LinkButton::class);
62
+	}
63 63
 
64 64
 }
Please login to merge, or discard this patch.
Classes/View/Grid/Row.php 1 patch
Indentation   +623 added lines, -623 removed lines patch added patch discarded remove patch
@@ -25,628 +25,628 @@
 block discarded – undo
25 25
 class Row extends AbstractComponentView
26 26
 {
27 27
 
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $columns = [];
32
-
33
-    /**
34
-     * Registry for storing variable values and speed up the processing.
35
-     *
36
-     * @var array
37
-     */
38
-    protected $variables = [];
39
-
40
-    /**
41
-     * @param array $columns
42
-     */
43
-    public function __construct(array $columns = [])
44
-    {
45
-        $this->columns = $columns;
46
-    }
47
-
48
-    /**
49
-     * Render a row to be displayed in the Grid given an Content Object.
50
-     *
51
-     * @param \Fab\Vidi\Domain\Model\Content $object
52
-     * @param int $rowIndex
53
-     * @return array
54
-     * @throws \Exception
55
-     */
56
-    public function render(Content $object = null, $rowIndex = 0)
57
-    {
58
-
59
-        // Initialize returned array
60
-        $output = [];
61
-
62
-        foreach (Tca::grid()->getFields() as $fieldNameAndPath => $configuration) {
63
-
64
-            $value = ''; // default is empty at first.
65
-
66
-            $this->computeVariables($object, $fieldNameAndPath);
67
-
68
-            // Only compute the value if it is going to be shown in the Grid. Lost of time otherwise!
69
-            if (in_array($fieldNameAndPath, $this->columns)) {
70
-
71
-                // Fetch value
72
-                if (Tca::grid()->hasRenderers($fieldNameAndPath)) {
73
-
74
-                    $value = '';
75
-                    $renderers = Tca::grid()->getRenderers($fieldNameAndPath);
76
-
77
-                    // if is relation has one
78
-                    foreach ($renderers as $rendererClassName => $rendererConfiguration) {
79
-
80
-                        /** @var $rendererObject \Fab\Vidi\Grid\ColumnRendererInterface */
81
-                        $rendererObject = GeneralUtility::makeInstance($rendererClassName);
82
-                        $value .= $rendererObject
83
-                            ->setObject($object)
84
-                            ->setFieldName($fieldNameAndPath)
85
-                            ->setRowIndex($rowIndex)
86
-                            ->setFieldConfiguration($configuration)
87
-                            ->setGridRendererConfiguration($rendererConfiguration)
88
-                            ->render();
89
-                    }
90
-                } else {
91
-                    $value = $this->resolveValue($object, $fieldNameAndPath);
92
-                    $value = $this->processValue($value, $object, $fieldNameAndPath); // post resolve processing.
93
-                }
94
-
95
-                // Possible formatting given by configuration. @see TCA['grid']
96
-                $value = $this->formatValue($value, $configuration);
97
-
98
-                // Here, there is the chance to further "decorate" the value for inline editing, localization, ...
99
-                if ($this->willBeEnriched()) {
100
-
101
-                    $localizedStructure = $this->initializeLocalizedStructure($value);
102
-
103
-                    if ($this->isEditable()) {
104
-                        $localizedStructure = $this->addEditableMarkup($localizedStructure);
105
-                    }
106
-
107
-                    if ($this->isLocalized()) {
108
-                        $localizedStructure = $this->addLocalizationMarkup($localizedStructure);
109
-                    }
110
-
111
-                    if ($this->hasIcon()) {
112
-                        $localizedStructure = $this->addSpriteIconMarkup($localizedStructure);
113
-                    }
114
-
115
-                    $value = $this->flattenStructure($localizedStructure);
116
-                }
117
-
118
-                // Final wrap given by configuration. @see TCA['grid']
119
-                $value = $this->wrapValue($value, $configuration);
120
-            }
121
-
122
-            $output[$this->getFieldName()] = $value;
123
-        }
124
-
125
-        $output['DT_RowId'] = 'row-' . $object->getUid();
126
-        $output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid());
127
-
128
-        return $output;
129
-    }
130
-
131
-    /**
132
-     * Flatten the localized structure to render the final value
133
-     *
134
-     * @param array $localizedStructure
135
-     * @return string
136
-     */
137
-    protected function flattenStructure(array $localizedStructure)
138
-    {
139
-
140
-        // Flatten the structure.
141
-        $value = '';
142
-        foreach ($localizedStructure as $structure) {
143
-            $value .= sprintf('<div class="%s">%s</div>',
144
-                $structure['status'] !== LocalizationStatus::LOCALIZED ? 'invisible' : '',
145
-                $structure['value']
146
-            );
147
-        }
148
-        return $value;
149
-    }
150
-
151
-    /**
152
-     * Store some often used variable values and speed up the processing.
153
-     *
154
-     * @param \Fab\Vidi\Domain\Model\Content $object
155
-     * @param string $fieldNameAndPath
156
-     * @return void
157
-     */
158
-    protected function computeVariables(Content $object, $fieldNameAndPath)
159
-    {
160
-        $this->variables = [];
161
-        $this->variables['dataType'] = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
162
-        $this->variables['fieldName'] = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
163
-        $this->variables['fieldNameAndPath'] = $fieldNameAndPath;
164
-        $this->variables['object'] = $object;
165
-    }
166
-
167
-    /**
168
-     * Tell whether the object will be decorated / wrapped such as
169
-     *
170
-     * @param string $value
171
-     * @return array
172
-     */
173
-    protected function initializeLocalizedStructure($value)
174
-    {
175
-
176
-        $localizedStructure[] = [
177
-            'value' => empty($value) && $this->isEditable() ? $this->getEmptyValuePlaceholder() : $value,
178
-            'status' => empty($value) ? LocalizationStatus::EMPTY_VALUE : LocalizationStatus::LOCALIZED,
179
-            'language' => 0,
180
-            'languageFlag' => $defaultLanguage = $this->getLanguageService()->getDefaultFlag(),
181
-        ];
182
-
183
-        if ($this->isLocalized()) {
184
-
185
-            foreach ($this->getLanguageService()->getLanguages() as $language) {
186
-
187
-                // Make sure the language is allowed for the current Backend User.
188
-                if ($this->isLanguageAllowedForBackendUser($language)) {
189
-
190
-                    $resolvedObject = $this->getResolvedObject();
191
-                    $fieldName = $this->getFieldName();
192
-
193
-                    if ($this->getLanguageService()->hasLocalization($resolvedObject, $language['uid'])) {
194
-                        $localizedValue = $this->getLanguageService()->getLocalizedFieldName($resolvedObject, $language['uid'], $fieldName);
195
-                        $status = LocalizationStatus::LOCALIZED;
196
-
197
-                        // Replace blank value by something more meaningful for the End User.
198
-                        if (empty($localizedValue)) {
199
-                            $status = LocalizationStatus::EMPTY_VALUE;
200
-                            $localizedValue = $this->isEditable() ? $this->getEmptyValuePlaceholder() : '';
201
-                        }
202
-                    } else {
203
-                        $localizedValue = sprintf('<a href="%s" style="color: black">%s</a>',
204
-                            $this->getLocalizedUri($language['uid']),
205
-                            $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:create_translation')
206
-                        );
207
-                        $status = LocalizationStatus::NOT_YET_LOCALIZED;
208
-                    }
209
-
210
-                    // Feed structure.
211
-                    $localizedStructure[] = [
212
-                        'value' => $localizedValue,
213
-                        'status' => $status,
214
-                        'language' => (int)$language['uid'],
215
-                        'languageFlag' => $language['flag'],
216
-                    ];
217
-                }
218
-            }
219
-        }
220
-
221
-        return $localizedStructure;
222
-    }
223
-
224
-    /**
225
-     * @param array $language
226
-     * @return bool
227
-     */
228
-    protected function isLanguageAllowedForBackendUser(array $language)
229
-    {
230
-        return $this->getBackendUser()->checkLanguageAccess($language['uid']);
231
-    }
232
-
233
-    /**
234
-     * Returns a placeholder when the value is empty.
235
-     *
236
-     * @return string
237
-     */
238
-    protected function getEmptyValuePlaceholder()
239
-    {
240
-        return sprintf('<i>%s</i>',
241
-            $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:start_editing')
242
-        );
243
-    }
244
-
245
-    /**
246
-     * Tell whether the object will be decorated (or wrapped) for inline editing, localization purpose.
247
-     *
248
-     * @return bool
249
-     */
250
-    protected function willBeEnriched()
251
-    {
252
-
253
-        $willBeEnriched = false;
254
-
255
-        if ($this->fieldExists()) {
256
-            $willBeEnriched = $this->isEditable() || $this->hasIcon() || $this->isLocalized();
257
-        }
258
-
259
-        return $willBeEnriched;
260
-    }
261
-
262
-    /**
263
-     * Tell whether the field in the context will be prepended by an icon.
264
-     *
265
-     * @return bool
266
-     */
267
-    protected function hasIcon()
268
-    {
269
-        $dataType = $this->getDataType();
270
-        return Tca::table($dataType)->getLabelField() === $this->getFieldName();
271
-    }
272
-
273
-    /**
274
-     * Tell whether the field in the context will be prepended by an icon.
275
-     *
276
-     * @return bool
277
-     */
278
-    protected function isLocalized()
279
-    {
280
-        $object = $this->getObject();
281
-        $fieldName = $this->getFieldName();
282
-        $dataType = $this->getDataType();
283
-        $fieldNameAndPath = $this->getFieldNameAndPath();
284
-
285
-        return $this->getLanguageService()->hasLanguages()
286
-        && Tca::grid($object)->isLocalized($fieldNameAndPath)
287
-        && Tca::table($dataType)->field($fieldName)->isLocalized();
288
-    }
289
-
290
-    /**
291
-     * Add some markup to have the content editable in the Grid.
292
-     *
293
-     * @param array $localizedStructure
294
-     * @return array
295
-     */
296
-    protected function addEditableMarkup(array $localizedStructure)
297
-    {
298
-
299
-        $dataType = $this->getDataType();
300
-        $fieldName = $this->getFieldName();
301
-
302
-        foreach ($localizedStructure as $index => $structure) {
303
-            if ($structure['status'] !== LocalizationStatus::NOT_YET_LOCALIZED) {
304
-                $localizedStructure[$index]['value'] = sprintf('<span class="%s" data-language="%s">%s</span>',
305
-                    Tca::table($dataType)->field($fieldName)->isTextArea() ? 'editable-textarea' : 'editable-textfield',
306
-                    $structure['language'],
307
-                    $structure['value']
308
-                );
309
-            }
310
-        }
311
-        return $localizedStructure;
312
-    }
313
-
314
-    /**
315
-     * Add some markup related to the localization.
316
-     *
317
-     * @param array $localizedStructure
318
-     * @return array
319
-     */
320
-    protected function addLocalizationMarkup(array $localizedStructure)
321
-    {
322
-
323
-        foreach ($localizedStructure as $index => $structure) {
324
-
325
-            $localizedStructure[$index]['value'] = sprintf('<span>%s %s</span>',
326
-                empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL),
327
-                $structure['value']
328
-            );
329
-        }
330
-        return $localizedStructure;
331
-    }
332
-
333
-    /**
334
-     * Add some markup related to the prepended icon.
335
-     *
336
-     * @param array $localizedStructure
337
-     * @return array
338
-     */
339
-    protected function addSpriteIconMarkup(array $localizedStructure)
340
-    {
341
-
342
-        $object = $this->getObject();
343
-
344
-        foreach ($localizedStructure as $index => $structure) {
345
-
346
-            $recordData = [];
347
-
348
-            $enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime');
349
-            foreach ($enablesMethods as $enableMethod) {
350
-
351
-                $methodName = 'get' . $enableMethod . 'Field';
352
-
353
-                // Fetch possible hidden filed.
354
-                $enableField = Tca::table($object)->$methodName();
355
-                if ($enableField) {
356
-                    $recordData[$enableField] = $object[$enableField];
357
-                }
358
-            }
359
-
360
-            // Get Enable Fields of the object to render the sprite with overlays.
361
-            $localizedStructure[$index]['value'] = sprintf('%s %s',
362
-                $this->getIconFactory()->getIconForRecord($object->getDataType(), $recordData, Icon::SIZE_SMALL),
363
-                $structure['value']
364
-            );
365
-        }
366
-
367
-        return $localizedStructure;
368
-    }
369
-
370
-    /**
371
-     * Return whether the field given by the context is editable.
372
-     *
373
-     * @return boolean
374
-     */
375
-    protected function isEditable()
376
-    {
377
-        $fieldNameAndPath = $this->getFieldNameAndPath();
378
-        $dataType = $this->getDataType();
379
-        $fieldName = $this->getFieldName();
380
-
381
-        return Tca::grid()->isEditable($fieldNameAndPath)
382
-        && Tca::table($dataType)->hasField($fieldName)
383
-        && Tca::table($dataType)->field($fieldName)->hasNoRelation(); // relation are editable through Renderers only.
384
-    }
385
-
386
-    /**
387
-     * Return the appropriate URI to create the translation.
388
-     *
389
-     * @param int $language
390
-     * @return string
391
-     */
392
-    protected function getLocalizedUri($language)
393
-    {
394
-
395
-        // Transmit recursive selection parameter.
396
-        $parameterPrefix = $this->getModuleLoader()->getParameterPrefix();
397
-        $parameters = GeneralUtility::_GP($parameterPrefix);
398
-
399
-        $additionalParameters = array(
400
-            $this->getModuleLoader()->getParameterPrefix() => array(
401
-                'controller' => 'Content',
402
-                'action' => 'localize',
403
-                'format' => 'json',
404
-                'hasRecursiveSelection' => isset($parameters['hasRecursiveSelection']) ? (int)$parameters['hasRecursiveSelection'] : 0,
405
-                'fieldNameAndPath' => $this->getFieldNameAndPath(),
406
-                'language' => $language,
407
-                'matches' => array(
408
-                    'uid' => $this->getObject()->getUid(),
409
-                ),
410
-            ),
411
-        );
412
-
413
-        return $this->getModuleLoader()->getModuleUrl($additionalParameters);
414
-    }
415
-
416
-    /**
417
-     * Compute the value for the Content object according to a field name.
418
-     *
419
-     * @param \Fab\Vidi\Domain\Model\Content $object
420
-     * @param string $fieldNameAndPath
421
-     * @return string
422
-     */
423
-    protected function resolveValue(Content $object, $fieldNameAndPath)
424
-    {
425
-
426
-        // Get the first part of the field name and
427
-        $fieldName = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath);
428
-
429
-        $value = $object[$fieldName];
430
-
431
-        // Relation but contains no data.
432
-        if (is_array($value) && empty($value)) {
433
-            $value = '';
434
-        } elseif ($value instanceof Content) {
435
-
436
-            $fieldNameOfForeignTable = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
437
-
438
-            // true means the field name does not contains a path. "title" vs "metadata.title"
439
-            // Fetch the default label
440
-            if ($fieldNameOfForeignTable === $fieldName) {
441
-                $foreignTable = Tca::table($object->getDataType())->field($fieldName)->getForeignTable();
442
-                $fieldNameOfForeignTable = Tca::table($foreignTable)->getLabelField();
443
-            }
444
-
445
-            $value = $object[$fieldName][$fieldNameOfForeignTable];
446
-        }
447
-
448
-        return $value;
449
-    }
450
-
451
-    /**
452
-     * Check whether a string contains HTML tags.
453
-     *
454
-     * @param string $string the content to be analyzed
455
-     * @return boolean
456
-     */
457
-    protected function hasHtml($string)
458
-    {
459
-        $result = false;
460
-
461
-        // We compare the length of the string with html tags and without html tags.
462
-        if (strlen($string) !== strlen(strip_tags($string))) {
463
-            $result = true;
464
-        }
465
-        return $result;
466
-    }
467
-
468
-    /**
469
-     * Check whether a string contains potential XSS.
470
-     *
471
-     * @param string $string the content to be analyzed
472
-     * @return boolean
473
-     */
474
-    protected function isClean($string)
475
-    {
476
-
477
-        // @todo implement me!
478
-        $result = true;
479
-        return $result;
480
-    }
481
-
482
-    /**
483
-     * Process the value
484
-     *
485
-     * @todo implement me as a processor chain to be cleaner implementation wise. Look out at the performance however!
486
-     *       e.g DefaultValueGridProcessor, TextAreaGridProcessor, ...
487
-     *
488
-     * @param string $value
489
-     * @param \Fab\Vidi\Domain\Model\Content $object
490
-     * @param string $fieldNameAndPath
491
-     * @return string
492
-     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
493
-     */
494
-    protected function processValue($value, Content $object, $fieldNameAndPath)
495
-    {
496
-
497
-        // Set default value if $field name correspond to the label of the table
498
-        $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
499
-        if (Tca::table($object->getDataType())->getLabelField() === $fieldName && empty($value)) {
500
-            $value = sprintf('[%s]', $this->getLabelService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', 1));
501
-        }
502
-
503
-        // Sanitize the value in case of "select" or "radio button".
504
-        if (is_scalar($value)) {
505
-            $fieldType = Tca::table($object->getDataType())->field($fieldNameAndPath)->getType();
506
-            if ($fieldType !== FieldType::TEXTAREA) {
507
-                $value = htmlspecialchars($value);
508
-            } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($value)) {
509
-                $value = htmlspecialchars($value); // Avoid bad surprise, converts characters to HTML.
510
-            } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($value)) {
511
-                $value = nl2br($value);
512
-            }
513
-        }
514
-
515
-        return $value;
516
-    }
517
-
518
-    /**
519
-     * Possible value formatting.
520
-     *
521
-     * @param string $value
522
-     * @param array $configuration
523
-     * @return string
524
-     * @throws \InvalidArgumentException
525
-     */
526
-    protected function formatValue($value, array $configuration)
527
-    {
528
-        if (empty($configuration['format'])) {
529
-            return $value;
530
-        }
531
-        $className = $configuration['format'];
532
-
533
-        /** @var \Fab\Vidi\Formatter\FormatterInterface $formatter */
534
-        $formatter = GeneralUtility::makeInstance($className);
535
-        $value = $formatter->format($value);
536
-
537
-        return $value;
538
-    }
539
-
540
-    /**
541
-     * Possible value wrapping.
542
-     *
543
-     * @param string $value
544
-     * @param array $configuration
545
-     * @return string
546
-     */
547
-    protected function wrapValue($value, array $configuration)
548
-    {
549
-        if (!empty($configuration['wrap'])) {
550
-            $parts = explode('|', $configuration['wrap']);
551
-            $value = implode($value, $parts);
552
-        }
553
-        return $value;
554
-    }
555
-
556
-    /**
557
-     * Tell whether the field in the context really exists.
558
-     *
559
-     * @return bool
560
-     */
561
-    protected function fieldExists()
562
-    {
563
-        if ($this->variables['hasField'] === null) {
564
-            $dataType = $this->getDataType();
565
-            $fieldName = $this->getFieldName();
566
-            $this->variables['hasField'] = Tca::table($dataType)->hasField($fieldName);
567
-        }
568
-        return $this->variables['hasField'];
569
-    }
570
-
571
-    /**
572
-     * @return string
573
-     */
574
-    protected function getDataType()
575
-    {
576
-        return $this->variables['dataType'];
577
-    }
578
-
579
-    /**
580
-     * @return string
581
-     */
582
-    protected function getFieldName()
583
-    {
584
-        return $this->variables['fieldName'];
585
-    }
586
-
587
-    /**
588
-     * @return string
589
-     */
590
-    protected function getFieldNameAndPath()
591
-    {
592
-        return $this->variables['fieldNameAndPath'];
593
-    }
594
-
595
-    /**
596
-     * @return Content
597
-     */
598
-    protected function getObject()
599
-    {
600
-        return $this->variables['object'];
601
-    }
602
-
603
-    /**
604
-     * @return Content
605
-     * @throws \InvalidArgumentException
606
-     */
607
-    protected function getResolvedObject()
608
-    {
609
-        if (empty($this->variables['resolvedObject'])) {
610
-            $object = $this->getObject();
611
-            $fieldNameAndPath = $this->getFieldNameAndPath();
612
-            $this->variables['resolvedObject'] = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath);
613
-        }
614
-        return $this->variables['resolvedObject'];
615
-    }
616
-
617
-    /**
618
-     * @return FieldPathResolver|object
619
-     * @throws \InvalidArgumentException
620
-     */
621
-    protected function getFieldPathResolver()
622
-    {
623
-        return GeneralUtility::makeInstance(FieldPathResolver::class);
624
-    }
625
-
626
-    /**
627
-     * @return ContentObjectResolver|object
628
-     * @throws \InvalidArgumentException
629
-     */
630
-    protected function getContentObjectResolver()
631
-    {
632
-        return GeneralUtility::makeInstance(ContentObjectResolver::class);
633
-    }
634
-
635
-    /**
636
-     * @return \TYPO3\CMS\Core\Localization\LanguageService
637
-     */
638
-    protected function getLabelService()
639
-    {
640
-        return $GLOBALS['LANG'];
641
-    }
642
-
643
-    /**
644
-     * @return LanguageService|object
645
-     * @throws \InvalidArgumentException
646
-     */
647
-    protected function getLanguageService()
648
-    {
649
-        return GeneralUtility::makeInstance(LanguageService::class);
650
-    }
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $columns = [];
32
+
33
+	/**
34
+	 * Registry for storing variable values and speed up the processing.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $variables = [];
39
+
40
+	/**
41
+	 * @param array $columns
42
+	 */
43
+	public function __construct(array $columns = [])
44
+	{
45
+		$this->columns = $columns;
46
+	}
47
+
48
+	/**
49
+	 * Render a row to be displayed in the Grid given an Content Object.
50
+	 *
51
+	 * @param \Fab\Vidi\Domain\Model\Content $object
52
+	 * @param int $rowIndex
53
+	 * @return array
54
+	 * @throws \Exception
55
+	 */
56
+	public function render(Content $object = null, $rowIndex = 0)
57
+	{
58
+
59
+		// Initialize returned array
60
+		$output = [];
61
+
62
+		foreach (Tca::grid()->getFields() as $fieldNameAndPath => $configuration) {
63
+
64
+			$value = ''; // default is empty at first.
65
+
66
+			$this->computeVariables($object, $fieldNameAndPath);
67
+
68
+			// Only compute the value if it is going to be shown in the Grid. Lost of time otherwise!
69
+			if (in_array($fieldNameAndPath, $this->columns)) {
70
+
71
+				// Fetch value
72
+				if (Tca::grid()->hasRenderers($fieldNameAndPath)) {
73
+
74
+					$value = '';
75
+					$renderers = Tca::grid()->getRenderers($fieldNameAndPath);
76
+
77
+					// if is relation has one
78
+					foreach ($renderers as $rendererClassName => $rendererConfiguration) {
79
+
80
+						/** @var $rendererObject \Fab\Vidi\Grid\ColumnRendererInterface */
81
+						$rendererObject = GeneralUtility::makeInstance($rendererClassName);
82
+						$value .= $rendererObject
83
+							->setObject($object)
84
+							->setFieldName($fieldNameAndPath)
85
+							->setRowIndex($rowIndex)
86
+							->setFieldConfiguration($configuration)
87
+							->setGridRendererConfiguration($rendererConfiguration)
88
+							->render();
89
+					}
90
+				} else {
91
+					$value = $this->resolveValue($object, $fieldNameAndPath);
92
+					$value = $this->processValue($value, $object, $fieldNameAndPath); // post resolve processing.
93
+				}
94
+
95
+				// Possible formatting given by configuration. @see TCA['grid']
96
+				$value = $this->formatValue($value, $configuration);
97
+
98
+				// Here, there is the chance to further "decorate" the value for inline editing, localization, ...
99
+				if ($this->willBeEnriched()) {
100
+
101
+					$localizedStructure = $this->initializeLocalizedStructure($value);
102
+
103
+					if ($this->isEditable()) {
104
+						$localizedStructure = $this->addEditableMarkup($localizedStructure);
105
+					}
106
+
107
+					if ($this->isLocalized()) {
108
+						$localizedStructure = $this->addLocalizationMarkup($localizedStructure);
109
+					}
110
+
111
+					if ($this->hasIcon()) {
112
+						$localizedStructure = $this->addSpriteIconMarkup($localizedStructure);
113
+					}
114
+
115
+					$value = $this->flattenStructure($localizedStructure);
116
+				}
117
+
118
+				// Final wrap given by configuration. @see TCA['grid']
119
+				$value = $this->wrapValue($value, $configuration);
120
+			}
121
+
122
+			$output[$this->getFieldName()] = $value;
123
+		}
124
+
125
+		$output['DT_RowId'] = 'row-' . $object->getUid();
126
+		$output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid());
127
+
128
+		return $output;
129
+	}
130
+
131
+	/**
132
+	 * Flatten the localized structure to render the final value
133
+	 *
134
+	 * @param array $localizedStructure
135
+	 * @return string
136
+	 */
137
+	protected function flattenStructure(array $localizedStructure)
138
+	{
139
+
140
+		// Flatten the structure.
141
+		$value = '';
142
+		foreach ($localizedStructure as $structure) {
143
+			$value .= sprintf('<div class="%s">%s</div>',
144
+				$structure['status'] !== LocalizationStatus::LOCALIZED ? 'invisible' : '',
145
+				$structure['value']
146
+			);
147
+		}
148
+		return $value;
149
+	}
150
+
151
+	/**
152
+	 * Store some often used variable values and speed up the processing.
153
+	 *
154
+	 * @param \Fab\Vidi\Domain\Model\Content $object
155
+	 * @param string $fieldNameAndPath
156
+	 * @return void
157
+	 */
158
+	protected function computeVariables(Content $object, $fieldNameAndPath)
159
+	{
160
+		$this->variables = [];
161
+		$this->variables['dataType'] = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
162
+		$this->variables['fieldName'] = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
163
+		$this->variables['fieldNameAndPath'] = $fieldNameAndPath;
164
+		$this->variables['object'] = $object;
165
+	}
166
+
167
+	/**
168
+	 * Tell whether the object will be decorated / wrapped such as
169
+	 *
170
+	 * @param string $value
171
+	 * @return array
172
+	 */
173
+	protected function initializeLocalizedStructure($value)
174
+	{
175
+
176
+		$localizedStructure[] = [
177
+			'value' => empty($value) && $this->isEditable() ? $this->getEmptyValuePlaceholder() : $value,
178
+			'status' => empty($value) ? LocalizationStatus::EMPTY_VALUE : LocalizationStatus::LOCALIZED,
179
+			'language' => 0,
180
+			'languageFlag' => $defaultLanguage = $this->getLanguageService()->getDefaultFlag(),
181
+		];
182
+
183
+		if ($this->isLocalized()) {
184
+
185
+			foreach ($this->getLanguageService()->getLanguages() as $language) {
186
+
187
+				// Make sure the language is allowed for the current Backend User.
188
+				if ($this->isLanguageAllowedForBackendUser($language)) {
189
+
190
+					$resolvedObject = $this->getResolvedObject();
191
+					$fieldName = $this->getFieldName();
192
+
193
+					if ($this->getLanguageService()->hasLocalization($resolvedObject, $language['uid'])) {
194
+						$localizedValue = $this->getLanguageService()->getLocalizedFieldName($resolvedObject, $language['uid'], $fieldName);
195
+						$status = LocalizationStatus::LOCALIZED;
196
+
197
+						// Replace blank value by something more meaningful for the End User.
198
+						if (empty($localizedValue)) {
199
+							$status = LocalizationStatus::EMPTY_VALUE;
200
+							$localizedValue = $this->isEditable() ? $this->getEmptyValuePlaceholder() : '';
201
+						}
202
+					} else {
203
+						$localizedValue = sprintf('<a href="%s" style="color: black">%s</a>',
204
+							$this->getLocalizedUri($language['uid']),
205
+							$this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:create_translation')
206
+						);
207
+						$status = LocalizationStatus::NOT_YET_LOCALIZED;
208
+					}
209
+
210
+					// Feed structure.
211
+					$localizedStructure[] = [
212
+						'value' => $localizedValue,
213
+						'status' => $status,
214
+						'language' => (int)$language['uid'],
215
+						'languageFlag' => $language['flag'],
216
+					];
217
+				}
218
+			}
219
+		}
220
+
221
+		return $localizedStructure;
222
+	}
223
+
224
+	/**
225
+	 * @param array $language
226
+	 * @return bool
227
+	 */
228
+	protected function isLanguageAllowedForBackendUser(array $language)
229
+	{
230
+		return $this->getBackendUser()->checkLanguageAccess($language['uid']);
231
+	}
232
+
233
+	/**
234
+	 * Returns a placeholder when the value is empty.
235
+	 *
236
+	 * @return string
237
+	 */
238
+	protected function getEmptyValuePlaceholder()
239
+	{
240
+		return sprintf('<i>%s</i>',
241
+			$this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:start_editing')
242
+		);
243
+	}
244
+
245
+	/**
246
+	 * Tell whether the object will be decorated (or wrapped) for inline editing, localization purpose.
247
+	 *
248
+	 * @return bool
249
+	 */
250
+	protected function willBeEnriched()
251
+	{
252
+
253
+		$willBeEnriched = false;
254
+
255
+		if ($this->fieldExists()) {
256
+			$willBeEnriched = $this->isEditable() || $this->hasIcon() || $this->isLocalized();
257
+		}
258
+
259
+		return $willBeEnriched;
260
+	}
261
+
262
+	/**
263
+	 * Tell whether the field in the context will be prepended by an icon.
264
+	 *
265
+	 * @return bool
266
+	 */
267
+	protected function hasIcon()
268
+	{
269
+		$dataType = $this->getDataType();
270
+		return Tca::table($dataType)->getLabelField() === $this->getFieldName();
271
+	}
272
+
273
+	/**
274
+	 * Tell whether the field in the context will be prepended by an icon.
275
+	 *
276
+	 * @return bool
277
+	 */
278
+	protected function isLocalized()
279
+	{
280
+		$object = $this->getObject();
281
+		$fieldName = $this->getFieldName();
282
+		$dataType = $this->getDataType();
283
+		$fieldNameAndPath = $this->getFieldNameAndPath();
284
+
285
+		return $this->getLanguageService()->hasLanguages()
286
+		&& Tca::grid($object)->isLocalized($fieldNameAndPath)
287
+		&& Tca::table($dataType)->field($fieldName)->isLocalized();
288
+	}
289
+
290
+	/**
291
+	 * Add some markup to have the content editable in the Grid.
292
+	 *
293
+	 * @param array $localizedStructure
294
+	 * @return array
295
+	 */
296
+	protected function addEditableMarkup(array $localizedStructure)
297
+	{
298
+
299
+		$dataType = $this->getDataType();
300
+		$fieldName = $this->getFieldName();
301
+
302
+		foreach ($localizedStructure as $index => $structure) {
303
+			if ($structure['status'] !== LocalizationStatus::NOT_YET_LOCALIZED) {
304
+				$localizedStructure[$index]['value'] = sprintf('<span class="%s" data-language="%s">%s</span>',
305
+					Tca::table($dataType)->field($fieldName)->isTextArea() ? 'editable-textarea' : 'editable-textfield',
306
+					$structure['language'],
307
+					$structure['value']
308
+				);
309
+			}
310
+		}
311
+		return $localizedStructure;
312
+	}
313
+
314
+	/**
315
+	 * Add some markup related to the localization.
316
+	 *
317
+	 * @param array $localizedStructure
318
+	 * @return array
319
+	 */
320
+	protected function addLocalizationMarkup(array $localizedStructure)
321
+	{
322
+
323
+		foreach ($localizedStructure as $index => $structure) {
324
+
325
+			$localizedStructure[$index]['value'] = sprintf('<span>%s %s</span>',
326
+				empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL),
327
+				$structure['value']
328
+			);
329
+		}
330
+		return $localizedStructure;
331
+	}
332
+
333
+	/**
334
+	 * Add some markup related to the prepended icon.
335
+	 *
336
+	 * @param array $localizedStructure
337
+	 * @return array
338
+	 */
339
+	protected function addSpriteIconMarkup(array $localizedStructure)
340
+	{
341
+
342
+		$object = $this->getObject();
343
+
344
+		foreach ($localizedStructure as $index => $structure) {
345
+
346
+			$recordData = [];
347
+
348
+			$enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime');
349
+			foreach ($enablesMethods as $enableMethod) {
350
+
351
+				$methodName = 'get' . $enableMethod . 'Field';
352
+
353
+				// Fetch possible hidden filed.
354
+				$enableField = Tca::table($object)->$methodName();
355
+				if ($enableField) {
356
+					$recordData[$enableField] = $object[$enableField];
357
+				}
358
+			}
359
+
360
+			// Get Enable Fields of the object to render the sprite with overlays.
361
+			$localizedStructure[$index]['value'] = sprintf('%s %s',
362
+				$this->getIconFactory()->getIconForRecord($object->getDataType(), $recordData, Icon::SIZE_SMALL),
363
+				$structure['value']
364
+			);
365
+		}
366
+
367
+		return $localizedStructure;
368
+	}
369
+
370
+	/**
371
+	 * Return whether the field given by the context is editable.
372
+	 *
373
+	 * @return boolean
374
+	 */
375
+	protected function isEditable()
376
+	{
377
+		$fieldNameAndPath = $this->getFieldNameAndPath();
378
+		$dataType = $this->getDataType();
379
+		$fieldName = $this->getFieldName();
380
+
381
+		return Tca::grid()->isEditable($fieldNameAndPath)
382
+		&& Tca::table($dataType)->hasField($fieldName)
383
+		&& Tca::table($dataType)->field($fieldName)->hasNoRelation(); // relation are editable through Renderers only.
384
+	}
385
+
386
+	/**
387
+	 * Return the appropriate URI to create the translation.
388
+	 *
389
+	 * @param int $language
390
+	 * @return string
391
+	 */
392
+	protected function getLocalizedUri($language)
393
+	{
394
+
395
+		// Transmit recursive selection parameter.
396
+		$parameterPrefix = $this->getModuleLoader()->getParameterPrefix();
397
+		$parameters = GeneralUtility::_GP($parameterPrefix);
398
+
399
+		$additionalParameters = array(
400
+			$this->getModuleLoader()->getParameterPrefix() => array(
401
+				'controller' => 'Content',
402
+				'action' => 'localize',
403
+				'format' => 'json',
404
+				'hasRecursiveSelection' => isset($parameters['hasRecursiveSelection']) ? (int)$parameters['hasRecursiveSelection'] : 0,
405
+				'fieldNameAndPath' => $this->getFieldNameAndPath(),
406
+				'language' => $language,
407
+				'matches' => array(
408
+					'uid' => $this->getObject()->getUid(),
409
+				),
410
+			),
411
+		);
412
+
413
+		return $this->getModuleLoader()->getModuleUrl($additionalParameters);
414
+	}
415
+
416
+	/**
417
+	 * Compute the value for the Content object according to a field name.
418
+	 *
419
+	 * @param \Fab\Vidi\Domain\Model\Content $object
420
+	 * @param string $fieldNameAndPath
421
+	 * @return string
422
+	 */
423
+	protected function resolveValue(Content $object, $fieldNameAndPath)
424
+	{
425
+
426
+		// Get the first part of the field name and
427
+		$fieldName = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath);
428
+
429
+		$value = $object[$fieldName];
430
+
431
+		// Relation but contains no data.
432
+		if (is_array($value) && empty($value)) {
433
+			$value = '';
434
+		} elseif ($value instanceof Content) {
435
+
436
+			$fieldNameOfForeignTable = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
437
+
438
+			// true means the field name does not contains a path. "title" vs "metadata.title"
439
+			// Fetch the default label
440
+			if ($fieldNameOfForeignTable === $fieldName) {
441
+				$foreignTable = Tca::table($object->getDataType())->field($fieldName)->getForeignTable();
442
+				$fieldNameOfForeignTable = Tca::table($foreignTable)->getLabelField();
443
+			}
444
+
445
+			$value = $object[$fieldName][$fieldNameOfForeignTable];
446
+		}
447
+
448
+		return $value;
449
+	}
450
+
451
+	/**
452
+	 * Check whether a string contains HTML tags.
453
+	 *
454
+	 * @param string $string the content to be analyzed
455
+	 * @return boolean
456
+	 */
457
+	protected function hasHtml($string)
458
+	{
459
+		$result = false;
460
+
461
+		// We compare the length of the string with html tags and without html tags.
462
+		if (strlen($string) !== strlen(strip_tags($string))) {
463
+			$result = true;
464
+		}
465
+		return $result;
466
+	}
467
+
468
+	/**
469
+	 * Check whether a string contains potential XSS.
470
+	 *
471
+	 * @param string $string the content to be analyzed
472
+	 * @return boolean
473
+	 */
474
+	protected function isClean($string)
475
+	{
476
+
477
+		// @todo implement me!
478
+		$result = true;
479
+		return $result;
480
+	}
481
+
482
+	/**
483
+	 * Process the value
484
+	 *
485
+	 * @todo implement me as a processor chain to be cleaner implementation wise. Look out at the performance however!
486
+	 *       e.g DefaultValueGridProcessor, TextAreaGridProcessor, ...
487
+	 *
488
+	 * @param string $value
489
+	 * @param \Fab\Vidi\Domain\Model\Content $object
490
+	 * @param string $fieldNameAndPath
491
+	 * @return string
492
+	 * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
493
+	 */
494
+	protected function processValue($value, Content $object, $fieldNameAndPath)
495
+	{
496
+
497
+		// Set default value if $field name correspond to the label of the table
498
+		$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
499
+		if (Tca::table($object->getDataType())->getLabelField() === $fieldName && empty($value)) {
500
+			$value = sprintf('[%s]', $this->getLabelService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', 1));
501
+		}
502
+
503
+		// Sanitize the value in case of "select" or "radio button".
504
+		if (is_scalar($value)) {
505
+			$fieldType = Tca::table($object->getDataType())->field($fieldNameAndPath)->getType();
506
+			if ($fieldType !== FieldType::TEXTAREA) {
507
+				$value = htmlspecialchars($value);
508
+			} elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($value)) {
509
+				$value = htmlspecialchars($value); // Avoid bad surprise, converts characters to HTML.
510
+			} elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($value)) {
511
+				$value = nl2br($value);
512
+			}
513
+		}
514
+
515
+		return $value;
516
+	}
517
+
518
+	/**
519
+	 * Possible value formatting.
520
+	 *
521
+	 * @param string $value
522
+	 * @param array $configuration
523
+	 * @return string
524
+	 * @throws \InvalidArgumentException
525
+	 */
526
+	protected function formatValue($value, array $configuration)
527
+	{
528
+		if (empty($configuration['format'])) {
529
+			return $value;
530
+		}
531
+		$className = $configuration['format'];
532
+
533
+		/** @var \Fab\Vidi\Formatter\FormatterInterface $formatter */
534
+		$formatter = GeneralUtility::makeInstance($className);
535
+		$value = $formatter->format($value);
536
+
537
+		return $value;
538
+	}
539
+
540
+	/**
541
+	 * Possible value wrapping.
542
+	 *
543
+	 * @param string $value
544
+	 * @param array $configuration
545
+	 * @return string
546
+	 */
547
+	protected function wrapValue($value, array $configuration)
548
+	{
549
+		if (!empty($configuration['wrap'])) {
550
+			$parts = explode('|', $configuration['wrap']);
551
+			$value = implode($value, $parts);
552
+		}
553
+		return $value;
554
+	}
555
+
556
+	/**
557
+	 * Tell whether the field in the context really exists.
558
+	 *
559
+	 * @return bool
560
+	 */
561
+	protected function fieldExists()
562
+	{
563
+		if ($this->variables['hasField'] === null) {
564
+			$dataType = $this->getDataType();
565
+			$fieldName = $this->getFieldName();
566
+			$this->variables['hasField'] = Tca::table($dataType)->hasField($fieldName);
567
+		}
568
+		return $this->variables['hasField'];
569
+	}
570
+
571
+	/**
572
+	 * @return string
573
+	 */
574
+	protected function getDataType()
575
+	{
576
+		return $this->variables['dataType'];
577
+	}
578
+
579
+	/**
580
+	 * @return string
581
+	 */
582
+	protected function getFieldName()
583
+	{
584
+		return $this->variables['fieldName'];
585
+	}
586
+
587
+	/**
588
+	 * @return string
589
+	 */
590
+	protected function getFieldNameAndPath()
591
+	{
592
+		return $this->variables['fieldNameAndPath'];
593
+	}
594
+
595
+	/**
596
+	 * @return Content
597
+	 */
598
+	protected function getObject()
599
+	{
600
+		return $this->variables['object'];
601
+	}
602
+
603
+	/**
604
+	 * @return Content
605
+	 * @throws \InvalidArgumentException
606
+	 */
607
+	protected function getResolvedObject()
608
+	{
609
+		if (empty($this->variables['resolvedObject'])) {
610
+			$object = $this->getObject();
611
+			$fieldNameAndPath = $this->getFieldNameAndPath();
612
+			$this->variables['resolvedObject'] = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath);
613
+		}
614
+		return $this->variables['resolvedObject'];
615
+	}
616
+
617
+	/**
618
+	 * @return FieldPathResolver|object
619
+	 * @throws \InvalidArgumentException
620
+	 */
621
+	protected function getFieldPathResolver()
622
+	{
623
+		return GeneralUtility::makeInstance(FieldPathResolver::class);
624
+	}
625
+
626
+	/**
627
+	 * @return ContentObjectResolver|object
628
+	 * @throws \InvalidArgumentException
629
+	 */
630
+	protected function getContentObjectResolver()
631
+	{
632
+		return GeneralUtility::makeInstance(ContentObjectResolver::class);
633
+	}
634
+
635
+	/**
636
+	 * @return \TYPO3\CMS\Core\Localization\LanguageService
637
+	 */
638
+	protected function getLabelService()
639
+	{
640
+		return $GLOBALS['LANG'];
641
+	}
642
+
643
+	/**
644
+	 * @return LanguageService|object
645
+	 * @throws \InvalidArgumentException
646
+	 */
647
+	protected function getLanguageService()
648
+	{
649
+		return GeneralUtility::makeInstance(LanguageService::class);
650
+	}
651 651
 
652 652
 }
Please login to merge, or discard this patch.
Classes/Persistence/Storage/VidiDbBackend.php 1 patch
Indentation   +1053 added lines, -1053 removed lines patch added patch discarded remove patch
@@ -40,1058 +40,1058 @@
 block discarded – undo
40 40
 class VidiDbBackend
41 41
 {
42 42
 
43
-    const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull';
44
-    const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull';
45
-
46
-    /**
47
-     * The TYPO3 page repository. Used for language and workspace overlay
48
-     *
49
-     * @var PageRepository
50
-     */
51
-    protected $pageRepository;
52
-
53
-    /**
54
-     * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
55
-     * @Inject
56
-     */
57
-    protected $environmentService;
58
-
59
-    /**
60
-     * @var \Fab\Vidi\Persistence\Query
61
-     */
62
-    protected $query;
63
-
64
-    /**
65
-     * Store some info related to table name and its aliases.
66
-     *
67
-     * @var array
68
-     */
69
-    protected $tableNameAliases = array(
70
-        'aliases' => [],
71
-        'aliasIncrement' => [],
72
-    );
73
-
74
-    /**
75
-     * Use to store the current foreign table name alias.
76
-     *
77
-     * @var string
78
-     */
79
-    protected $currentChildTableNameAlias = '';
80
-
81
-    /**
82
-     * @param Query $query
83
-     */
84
-    public function __construct(Query $query)
85
-    {
86
-        $this->query = $query;
87
-    }
88
-
89
-    /**
90
-     * @param $parameters
91
-     * @return array
92
-     */
93
-    protected static function getTypes($parameters)
94
-    {
95
-        $types = [];
96
-        foreach ($parameters as $parameter) {
97
-            if (is_array($parameter)) {
98
-                if (MathUtility::canBeInterpretedAsInteger($parameter[0])) {
99
-                    $types[] = \Doctrine\DBAL\Connection::PARAM_INT_ARRAY;
100
-                } else {
101
-                    $types[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY;
102
-                }
103
-            } else {
104
-                if (MathUtility::canBeInterpretedAsInteger($parameter)) {
105
-                    $types[] = ParameterType::INTEGER;
106
-                } else {
107
-                    $types[] = ParameterType::STRING;
108
-                }
109
-            }
110
-        }
111
-        return $types;
112
-    }
113
-
114
-    /**
115
-     * Returns the result of the query
116
-     */
117
-    public function fetchResult()
118
-    {
119
-        $parameters = [];
120
-        $statementParts = $this->parseQuery($parameters);
121
-        $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts);
122
-        $sql = $this->buildQuery($statementParts);
123
-        //print $sql; exit();
124
-
125
-        $rows = $this->getConnection()
126
-            ->executeQuery($sql, $parameters, self::getTypes($parameters))
127
-            ->fetchAll();
128
-
129
-        return $this->getContentObjects($rows);
130
-    }
131
-
132
-    /**
133
-     * Returns the number of tuples matching the query.
134
-     *
135
-     * @return int The number of matching tuples
136
-     */
137
-    public function countResult()
138
-    {
139
-        $parameters = [];
140
-        $statementParts = $this->parseQuery($parameters);
141
-        $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts);
142
-        $types = self::getTypes($parameters);
143
-
144
-        // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints
145
-        if (!empty($statementParts['limit'])) {
146
-            $sql = $this->buildQuery($statementParts);
147
-
148
-            $count = $this
149
-                ->getConnection()
150
-                ->executeQuery($sql, $parameters, $types)
151
-                ->rowCount();
152
-        } else {
153
-            $statementParts['fields'] = array('COUNT(*)');
154
-            // having orderings without grouping is not compatible with non-MySQL DBMS
155
-            $statementParts['orderings'] = [];
156
-            if (isset($statementParts['keywords']['distinct'])) {
157
-                unset($statementParts['keywords']['distinct']);
158
-                $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid';
159
-                $statementParts['fields'] = array('COUNT(DISTINCT ' . $statementParts['mainTable'] . '.' . $distinctField . ')');
160
-            }
161
-
162
-            $sql = $this->buildQuery($statementParts);
163
-            $count = $this
164
-                ->getConnection()
165
-                ->executeQuery($sql, $parameters, $types)
166
-                ->fetchColumn(0);
167
-        }
168
-        return (int)$count;
169
-    }
170
-
171
-    /**
172
-     * Parses the query and returns the SQL statement parts.
173
-     *
174
-     * @param array &$parameters
175
-     * @return array
176
-     */
177
-    public function parseQuery(array &$parameters)
178
-    {
179
-        $statementParts = [];
180
-        $statementParts['keywords'] = [];
181
-        $statementParts['tables'] = [];
182
-        $statementParts['unions'] = [];
183
-        $statementParts['fields'] = [];
184
-        $statementParts['where'] = [];
185
-        $statementParts['additionalWhereClause'] = [];
186
-        $statementParts['orderings'] = [];
187
-        $statementParts['limit'] = [];
188
-        $query = $this->query;
189
-        $source = $query->getSource();
190
-        $this->parseSource($source, $statementParts);
191
-        $this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters);
192
-        $this->parseOrderings($query->getOrderings(), $source, $statementParts);
193
-        $this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts);
194
-        $tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions']));
195
-        foreach ($tableNames as $tableNameOrAlias) {
196
-            if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) {
197
-                $this->addAdditionalWhereClause($query->getQuerySettings(), $tableNameOrAlias, $statementParts);
198
-            }
199
-        }
200
-
201
-        return $statementParts;
202
-    }
203
-
204
-    /**
205
-     * Fiddle with the statement structure to handle recursive MM relations.
206
-     * For the recursive MM query to work, we must invert some values.
207
-     * Let see if that is the best way of doing that...
208
-     *
209
-     * @param array $statementParts
210
-     * @return array
211
-     */
212
-    public function processStatementStructureForRecursiveMMRelation(array $statementParts)
213
-    {
214
-
215
-        if ($this->hasRecursiveMMRelation()) {
216
-            $tableName = $this->query->getType();
217
-
218
-            // In order the MM query to work for a recursive MM query, we must invert some values.
219
-            // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name)
220
-            $values = [];
221
-            foreach ($statementParts['fields'] as $key => $value) {
222
-                $values[$key] = str_replace($tableName, $tableName . '0', $value);
223
-            }
224
-            $statementParts['fields'] = $values;
225
-
226
-            // Same comment as above.
227
-            $values = [];
228
-            foreach ($statementParts['where'] as $key => $value) {
229
-                $values[$key] = str_replace($tableName . '0', $tableName, $value);
230
-            }
231
-            $statementParts['where'] = $values;
232
-
233
-            // We must be more restrictive by transforming the "left" union by "inner"
234
-            $values = [];
235
-            foreach ($statementParts['unions'] as $key => $value) {
236
-                $values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value);
237
-            }
238
-            $statementParts['unions'] = $values;
239
-        }
240
-
241
-        return $statementParts;
242
-    }
243
-
244
-    /**
245
-     * Tell whether there is a recursive MM relation.
246
-     *
247
-     * @return bool
248
-     */
249
-    public function hasRecursiveMMRelation()
250
-    {
251
-        return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]);
252
-
253
-    }
254
-
255
-    /**
256
-     * Returns the statement, ready to be executed.
257
-     *
258
-     * @param array $statementParts The SQL statement parts
259
-     * @return string The SQL statement
260
-     */
261
-    public function buildQuery(array $statementParts)
262
-    {
263
-
264
-        // Add more statement to the UNION part.
265
-        if (!empty($statementParts['unions'])) {
266
-            foreach ($statementParts['unions'] as $tableName => $unionPart) {
267
-                if (!empty($statementParts['additionalWhereClause'][$tableName])) {
268
-                    $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]);
269
-                }
270
-            }
271
-        }
272
-
273
-        $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']);
274
-        if (!empty($statementParts['where'])) {
275
-            $statement .= ' WHERE ' . implode('', $statementParts['where']);
276
-            if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) {
277
-                $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
278
-            }
279
-        } elseif (!empty($statementParts['additionalWhereClause'])) {
280
-            $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
281
-        }
282
-        if (!empty($statementParts['orderings'])) {
283
-            $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']);
284
-        }
285
-        if (!empty($statementParts['limit'])) {
286
-            $statement .= ' LIMIT ' . $statementParts['limit'];
287
-        }
288
-
289
-        return $statement;
290
-    }
291
-
292
-    /**
293
-     * Transforms a Query Source into SQL and parameter arrays
294
-     *
295
-     * @param SourceInterface $source The source
296
-     * @param array &$sql
297
-     * @return void
298
-     */
299
-    protected function parseSource(SourceInterface $source, array &$sql)
300
-    {
301
-        $tableName = $this->getTableName();
302
-        $sql['fields'][$tableName] = $tableName . '.*';
303
-        if ($this->query->getDistinct()) {
304
-            $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct();
305
-            $sql['keywords']['distinct'] = 'DISTINCT';
306
-        }
307
-        $sql['tables'][$tableName] = $tableName;
308
-        $sql['mainTable'] = $tableName;
309
-    }
310
-
311
-    /**
312
-     * Transforms a constraint into SQL and parameter arrays
313
-     *
314
-     * @param ConstraintInterface $constraint The constraint
315
-     * @param SourceInterface $source The source
316
-     * @param array &$statementParts The query parts
317
-     * @param array &$parameters The parameters that will replace the markers
318
-     * @return void
319
-     */
320
-    protected function parseConstraint(ConstraintInterface $constraint = null, SourceInterface $source, array &$statementParts, array &$parameters)
321
-    {
322
-        if ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface) {
323
-            $statementParts['where'][] = '(';
324
-            $this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters);
325
-            $statementParts['where'][] = ' AND ';
326
-            $this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters);
327
-            $statementParts['where'][] = ')';
328
-        } elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface) {
329
-            $statementParts['where'][] = '(';
330
-            $this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters);
331
-            $statementParts['where'][] = ' OR ';
332
-            $this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters);
333
-            $statementParts['where'][] = ')';
334
-        } elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface) {
335
-            $statementParts['where'][] = 'NOT (';
336
-            $this->parseConstraint($constraint->getConstraint(), $source, $statementParts, $parameters);
337
-            $statementParts['where'][] = ')';
338
-        } elseif ($constraint instanceof ComparisonInterface) {
339
-            $this->parseComparison($constraint, $source, $statementParts, $parameters);
340
-        }
341
-    }
342
-
343
-    /**
344
-     * Parse a Comparison into SQL and parameter arrays.
345
-     *
346
-     * @param ComparisonInterface $comparison The comparison to parse
347
-     * @param SourceInterface $source The source
348
-     * @param array &$statementParts SQL query parts to add to
349
-     * @param array &$parameters Parameters to bind to the SQL
350
-     * @return void
351
-     * @throws Exception\RepositoryException
352
-     */
353
-    protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$statementParts, array &$parameters)
354
-    {
355
-        $operand1 = $comparison->getOperand1();
356
-        $operator = $comparison->getOperator();
357
-        $operand2 = $comparison->getOperand2();
358
-        if ($operator === QueryInterface::OPERATOR_IN) {
359
-            $items = [];
360
-            $hasValue = false;
361
-            foreach ($operand2 as $value) {
362
-                $value = $this->getPlainValue($value);
363
-                if ($value !== null) {
364
-                    $items[] = $value;
365
-                    $hasValue = true;
366
-                }
367
-            }
368
-            if ($hasValue === false) {
369
-                $statementParts['where'][] = '1<>1';
370
-            } else {
371
-                $this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters, null);
372
-                $parameters[] = $items;
373
-            }
374
-        } elseif ($operator === QueryInterface::OPERATOR_CONTAINS) {
375
-            if ($operand2 === null) {
376
-                $statementParts['where'][] = '1<>1';
377
-            } else {
378
-                throw new \Exception('Not implemented! Contact extension author.', 1412931227);
379
-                # @todo re-implement me if necessary.
380
-                #$tableName = $this->query->getType();
381
-                #$propertyName = $operand1->getPropertyName();
382
-                #while (strpos($propertyName, '.') !== false) {
383
-                #	$this->addUnionStatement($tableName, $propertyName, $statementParts);
384
-                #}
385
-                #$columnName = $propertyName;
386
-                #$columnMap = $propertyName;
387
-                #$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : null;
388
-                #if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
389
-                #	$relationTableName = $columnMap->getRelationTableName();
390
-                #	$statementParts['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)';
391
-                #	$parameters[] = intval($this->getPlainValue($operand2));
392
-                #} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) {
393
-                #	$parentKeyFieldName = $columnMap->getParentKeyFieldName();
394
-                #	if (isset($parentKeyFieldName)) {
395
-                #		$childTableName = $columnMap->getChildTableName();
396
-                #		$statementParts['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)';
397
-                #		$parameters[] = intval($this->getPlainValue($operand2));
398
-                #	} else {
399
-                #		$statementParts['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')';
400
-                #		$parameters[] = intval($this->getPlainValue($operand2));
401
-                #	}
402
-                #} else {
403
-                #	throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745);
404
-                #}
405
-            }
406
-        } else {
407
-            if ($operand2 === null) {
408
-                if ($operator === QueryInterface::OPERATOR_EQUAL_TO) {
409
-                    $operator = self::OPERATOR_EQUAL_TO_NULL;
410
-                } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) {
411
-                    $operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
412
-                }
413
-            }
414
-            $this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters);
415
-            $parameters[] = $this->getPlainValue($operand2);
416
-        }
417
-    }
418
-
419
-    /**
420
-     * Returns a plain value, i.e. objects are flattened if possible.
421
-     *
422
-     * @param mixed $input
423
-     * @return mixed
424
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException
425
-     */
426
-    protected function getPlainValue($input)
427
-    {
428
-        if (is_array($input)) {
429
-            throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932);
430
-        }
431
-        if ($input instanceof \DateTime) {
432
-            return $input->format('U');
433
-        } elseif (is_object($input)) {
434
-            if ($input instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
435
-                $realInput = $input->_loadRealInstance();
436
-            } else {
437
-                $realInput = $input;
438
-            }
439
-            if ($realInput instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
440
-                return $realInput->getUid();
441
-            } else {
442
-                throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934);
443
-            }
444
-        } elseif (is_bool($input)) {
445
-            return $input === true ? 1 : 0;
446
-        } else {
447
-            return $input;
448
-        }
449
-    }
450
-
451
-    /**
452
-     * Parse a DynamicOperand into SQL and parameter arrays.
453
-     *
454
-     * @param DynamicOperandInterface $operand
455
-     * @param string $operator One of the JCR_OPERATOR_* constants
456
-     * @param SourceInterface $source The source
457
-     * @param array &$statementParts The query parts
458
-     * @param array &$parameters The parameters that will replace the markers
459
-     * @param string $valueFunction an optional SQL function to apply to the operand value
460
-     * @return void
461
-     */
462
-    protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$statementParts, array &$parameters, $valueFunction = null)
463
-    {
464
-        if ($operand instanceof LowerCaseInterface) {
465
-            $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'LOWER');
466
-        } elseif ($operand instanceof UpperCaseInterface) {
467
-            $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'UPPER');
468
-        } elseif ($operand instanceof PropertyValueInterface) {
469
-            $propertyName = $operand->getPropertyName();
470
-
471
-            // Reset value.
472
-            $this->currentChildTableNameAlias = '';
473
-
474
-            if ($source instanceof SelectorInterface) {
475
-                $tableName = $this->query->getType();
476
-                while (strpos($propertyName, '.') !== false) {
477
-                    $this->addUnionStatement($tableName, $propertyName, $statementParts);
478
-                }
479
-            } elseif ($source instanceof JoinInterface) {
480
-                $tableName = $source->getJoinCondition()->getSelector1Name();
481
-            }
482
-
483
-            $columnName = $propertyName;
484
-            $resolvedOperator = $this->resolveOperator($operator);
485
-            $constraintSQL = '';
486
-
487
-            $marker = $operator === QueryInterface::OPERATOR_IN
488
-                ? '(?)'
489
-                : '?';
490
-
491
-            if ($valueFunction === null) {
492
-                $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $resolvedOperator . ' ' . $marker;
493
-            } else {
494
-                $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $resolvedOperator . ' ' . $marker;
495
-            }
496
-
497
-            if (isset($tableName) && !empty($this->currentChildTableNameAlias)) {
498
-                $constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL);
499
-            }
500
-            $statementParts['where'][] = $constraintSQL;
501
-        }
502
-    }
503
-
504
-    /**
505
-     * @param string &$tableName
506
-     * @param string &$propertyPath
507
-     * @param array &$statementParts
508
-     */
509
-    protected function addUnionStatement(&$tableName, &$propertyPath, array &$statementParts)
510
-    {
511
-
512
-        $table = Tca::table($tableName);
513
-
514
-        $explodedPropertyPath = explode('.', $propertyPath, 2);
515
-        $fieldName = $explodedPropertyPath[0];
516
-
517
-        // Field of type "group" are special because property path must contain the table name
518
-        // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
519
-        $parts = explode('.', $propertyPath, 3);
520
-        if ($table->field($fieldName)->isGroup() && count($parts) > 2) {
521
-            $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1];
522
-            $explodedPropertyPath[1] = $parts[2];
523
-            $fieldName = $explodedPropertyPath[0];
524
-        }
525
-
526
-        $parentKeyFieldName = $table->field($fieldName)->getForeignField();
527
-        $childTableName = $table->field($fieldName)->getForeignTable();
528
-
529
-        if ($childTableName === null) {
530
-            throw new Exception\InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925);
531
-        }
532
-
533
-        if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one"
534
-            // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons.
535
-            // $parentKeyFieldName === null does the trick somehow. Before condition was if (isset($parentKeyFieldName))
536
-            if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === null) {
537
-                $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid';
538
-            } else {
539
-                $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
540
-            }
541
-        } elseif ($table->field($fieldName)->hasRelationManyToMany()) {
542
-            $relationTableName = $table->field($fieldName)->getManyToManyTable();
543
-
544
-            $parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
545
-            $childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
546
-
547
-            // MM table e.g sys_category_record_mm
548
-            $relationTableNameAlias = $this->generateAlias($relationTableName);
549
-            $join = sprintf(
550
-                'LEFT JOIN %s AS %s ON %s.uid=%s.%s', $relationTableName,
551
-                $relationTableNameAlias,
552
-                $tableName,
553
-                $relationTableNameAlias,
554
-                $parentKeyFieldName
555
-            );
556
-            $statementParts['unions'][$relationTableNameAlias] = $join;
557
-
558
-            // Foreign table e.g sys_category
559
-            $childTableNameAlias = $this->generateAlias($childTableName);
560
-            $this->currentChildTableNameAlias = $childTableNameAlias;
561
-            $join = sprintf(
562
-                'LEFT JOIN %s AS %s ON %s.%s=%s.uid',
563
-                $childTableName,
564
-                $childTableNameAlias,
565
-                $relationTableNameAlias,
566
-                $childKeyFieldName,
567
-                $childTableNameAlias
568
-            );
569
-            $statementParts['unions'][$childTableNameAlias] = $join;
570
-
571
-            // Find a possible table name for a MM condition.
572
-            $tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition();
573
-            if ($tableNameCondition) {
574
-
575
-                // If we can find a source file name,  we can then retrieve more MM conditions from the TCA such as a field name.
576
-                $sourceFileName = $this->query->getSourceFieldName();
577
-                if (empty($sourceFileName)) {
578
-                    $additionalMMConditions = array(
579
-                        'tablenames' => $tableNameCondition,
580
-                    );
581
-                } else {
582
-                    $additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition();
583
-                }
584
-
585
-                foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) {
586
-                    $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
587
-                    $statementParts['unions'][$relationTableNameAlias] .= $additionalJoin;
588
-
589
-                    $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
590
-                    $statementParts['unions'][$childTableNameAlias] .= $additionalJoin;
591
-                }
592
-            }
593
-
594
-        } elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations
595
-            $childTableNameAlias = $this->generateAlias($childTableName);
596
-            $this->currentChildTableNameAlias = $childTableNameAlias;
597
-
598
-            if (isset($parentKeyFieldName)) {
599
-                $join = sprintf(
600
-                    'LEFT JOIN %s AS %s ON %s.uid=%s.%s',
601
-                    $childTableName,
602
-                    $childTableNameAlias,
603
-                    $tableName,
604
-                    $childTableNameAlias,
605
-                    $parentKeyFieldName
606
-                );
607
-                $statementParts['unions'][$childTableNameAlias] = $join;
608
-            } else {
609
-                $join = sprintf(
610
-                    'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))',
611
-                    $childTableName,
612
-                    $childTableNameAlias,
613
-                    $childTableNameAlias,
614
-                    $tableName,
615
-                    $fieldName
616
-                );
617
-                $statementParts['unions'][$childTableNameAlias] = $join;
618
-            }
619
-        } else {
620
-            throw new Exception('Could not determine type of relation.', 1252502725);
621
-        }
622
-
623
-        $statementParts['keywords']['distinct'] = 'DISTINCT';
624
-        $propertyPath = $explodedPropertyPath[1];
625
-        $tableName = $childTableName;
626
-    }
627
-
628
-    /**
629
-     * Returns the SQL operator for the given JCR operator type.
630
-     *
631
-     * @param string $operator One of the JCR_OPERATOR_* constants
632
-     * @return string an SQL operator
633
-     * @throws Exception
634
-     */
635
-    protected function resolveOperator($operator)
636
-    {
637
-        switch ($operator) {
638
-            case self::OPERATOR_EQUAL_TO_NULL:
639
-                $operator = 'IS';
640
-                break;
641
-            case self::OPERATOR_NOT_EQUAL_TO_NULL:
642
-                $operator = 'IS NOT';
643
-                break;
644
-            case QueryInterface::OPERATOR_IN:
645
-                $operator = 'IN';
646
-                break;
647
-            case QueryInterface::OPERATOR_EQUAL_TO:
648
-                $operator = '=';
649
-                break;
650
-            case QueryInterface::OPERATOR_NOT_EQUAL_TO:
651
-                $operator = '!=';
652
-                break;
653
-            case QueryInterface::OPERATOR_LESS_THAN:
654
-                $operator = '<';
655
-                break;
656
-            case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO:
657
-                $operator = '<=';
658
-                break;
659
-            case QueryInterface::OPERATOR_GREATER_THAN:
660
-                $operator = '>';
661
-                break;
662
-            case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO:
663
-                $operator = '>=';
664
-                break;
665
-            case QueryInterface::OPERATOR_LIKE:
666
-                $operator = 'LIKE';
667
-                break;
668
-            default:
669
-                throw new Exception('Unsupported operator encountered.', 1242816073);
670
-        }
671
-        return $operator;
672
-    }
673
-
674
-    /**
675
-     * Adds additional WHERE statements according to the query settings.
676
-     *
677
-     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
678
-     * @param string $tableNameOrAlias The table name to add the additional where clause for
679
-     * @param array &$statementParts
680
-     * @return void
681
-     */
682
-    protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts)
683
-    {
684
-        $this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts);
685
-        if ($querySettings->getRespectSysLanguage()) {
686
-            $this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings);
687
-        }
688
-    }
689
-
690
-    /**
691
-     * Adds enableFields and deletedClause to the query if necessary
692
-     *
693
-     * @param QuerySettingsInterface $querySettings
694
-     * @param string $tableNameOrAlias The database table name
695
-     * @param array &$statementParts The query parts
696
-     * @return void
697
-     */
698
-    protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts)
699
-    {
700
-        $statement = '';
701
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
702
-        if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
703
-            $ignoreEnableFields = $querySettings->getIgnoreEnableFields();
704
-            $enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored();
705
-            $includeDeleted = $querySettings->getIncludeDeleted();
706
-            if ($this->environmentService->isEnvironmentInFrontendMode()) {
707
-                $statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted);
708
-            } else {
709
-                // TYPO3_MODE === 'BE'
710
-                $statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted);
711
-            }
712
-
713
-            // Remove the prefixing "AND" if any.
714
-            if (!empty($statement)) {
715
-                $statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement;
716
-                $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement;
717
-            }
718
-        }
719
-    }
720
-
721
-    /**
722
-     * Returns constraint statement for frontend context
723
-     *
724
-     * @param string $tableNameOrAlias
725
-     * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
726
-     * @param array $enableFieldsToBeIgnored If $ignoreEnableFields is true, this array specifies enable fields to be ignored. If it is null or an empty array (default) all enable fields are ignored.
727
-     * @param boolean $includeDeleted A flag indicating whether deleted records should be included
728
-     * @return string
729
-     * @throws Exception\InconsistentQuerySettingsException
730
-     */
731
-    protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted)
732
-    {
733
-        $statement = '';
734
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
735
-        if ($ignoreEnableFields && !$includeDeleted) {
736
-            if (count($enableFieldsToBeIgnored)) {
737
-                // array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented
738
-                $statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored));
739
-            } else {
740
-                $statement .= $this->getPageRepository()->deleteClause($tableName);
741
-            }
742
-        } elseif (!$ignoreEnableFields && !$includeDeleted) {
743
-            $statement .= $this->getPageRepository()->enableFields($tableName);
744
-        } elseif (!$ignoreEnableFields && $includeDeleted) {
745
-            throw new Exception\InconsistentQuerySettingsException('Query setting "ignoreEnableFields=false" can not be used together with "includeDeleted=true" in frontend context.', 1327678173);
746
-        }
747
-        return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
748
-    }
749
-
750
-    /**
751
-     * Returns constraint statement for backend context
752
-     *
753
-     * @param string $tableNameOrAlias
754
-     * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
755
-     * @param boolean $includeDeleted A flag indicating whether deleted records should be included
756
-     * @return string
757
-     */
758
-    protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted)
759
-    {
760
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
761
-        $statement = '';
762
-        if (!$ignoreEnableFields) {
763
-            $statement .= BackendUtility::BEenableFields($tableName);
764
-        }
765
-
766
-        // If the table is found to have "workspace" support, add the corresponding fields in the statement.
767
-        if (Tca::table($tableName)->hasWorkspaceSupport()) {
768
-            if ($this->getBackendUser()->workspace === 0) {
769
-                $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE);
770
-            } else {
771
-                // Show only records of live and of the current workspace
772
-                // In case we are in a Versioning preview
773
-                $statement .= ' AND (' .
774
-                    $tableName . '.t3ver_wsid=0 OR ' .
775
-                    $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace .
776
-                    ')';
777
-            }
778
-
779
-            // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0
780
-            $statement .= ' AND ' . $tableName . '.pid<>-1';
781
-        }
782
-
783
-        if (!$includeDeleted) {
784
-            $statement .= BackendUtility::deleteClause($tableName);
785
-        }
786
-
787
-        return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
788
-    }
789
-
790
-    /**
791
-     * Builds the language field statement
792
-     *
793
-     * @param string $tableNameOrAlias The database table name
794
-     * @param array &$statementParts The query parts
795
-     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
796
-     * @return void
797
-     * @throws Exception
798
-     */
799
-    protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings)
800
-    {
801
-        $tableName = $this->resolveTableNameAlias($tableNameOrAlias);
802
-        if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
803
-            if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) {
804
-                // Select all entries for the current language
805
-                $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)';
806
-                // If any language is set -> get those entries which are not translated yet
807
-                // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode
808
-                if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
809
-                    && $querySettings->getLanguageUid() > 0
810
-                ) {
811
-                    $additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' .
812
-                        ' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] .
813
-                        ' FROM ' . $tableName .
814
-                        ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' .
815
-                        ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0';
816
-
817
-                    // Add delete clause to ensure all entries are loaded
818
-                    if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) {
819
-                        $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0';
820
-                    }
821
-                    $additionalWhereClause .= '))';
822
-                }
823
-                $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')';
824
-            }
825
-        }
826
-    }
827
-
828
-    /**
829
-     * Transforms orderings into SQL.
830
-     *
831
-     * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
832
-     * @param SourceInterface $source The source
833
-     * @param array &$statementParts The query parts
834
-     * @return void
835
-     * @throws Exception\UnsupportedOrderException
836
-     */
837
-    protected function parseOrderings(array $orderings, SourceInterface $source, array &$statementParts)
838
-    {
839
-        foreach ($orderings as $fieldNameAndPath => $order) {
840
-            switch ($order) {
841
-                case QueryInterface::ORDER_ASCENDING:
842
-                    $order = 'ASC';
843
-                    break;
844
-                case QueryInterface::ORDER_DESCENDING:
845
-                    $order = 'DESC';
846
-                    break;
847
-                default:
848
-                    throw new Exception\UnsupportedOrderException('Unsupported order encountered.', 1456845126);
849
-            }
850
-
851
-            $tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType());
852
-            $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName);
853
-            $statementParts['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order);
854
-        }
855
-    }
856
-
857
-    /**
858
-     * Transforms limit and offset into SQL
859
-     *
860
-     * @param int $limit
861
-     * @param int $offset
862
-     * @param array &$statementParts
863
-     * @return void
864
-     */
865
-    protected function parseLimitAndOffset($limit, $offset, array &$statementParts)
866
-    {
867
-        if ($limit !== null && $offset !== null) {
868
-            $statementParts['limit'] = intval($offset) . ', ' . intval($limit);
869
-        } elseif ($limit !== null) {
870
-            $statementParts['limit'] = intval($limit);
871
-        }
872
-    }
873
-
874
-    /**
875
-     * @param array $rows
876
-     * @return array
877
-     */
878
-    protected function getContentObjects(array $rows): array
879
-    {
880
-        $contentObjects = [];
881
-        foreach ($rows as $row) {
882
-
883
-            // Get language uid from querySettings.
884
-            // Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed)
885
-            $overlaidRow = $this->doLanguageAndWorkspaceOverlay(
886
-                $row,
887
-                $this->query->getQuerySettings()
888
-            );
889
-
890
-            $contentObjects[] = GeneralUtility::makeInstance(
891
-                \Fab\Vidi\Domain\Model\Content::class,
892
-                $this->query->getType(),
893
-                $overlaidRow
894
-            );
895
-        }
896
-
897
-        return $contentObjects;
898
-    }
899
-
900
-    /**
901
-     * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
902
-     * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
903
-     *
904
-     * @param array $row
905
-     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
906
-     * @return array
907
-     */
908
-    protected function doLanguageAndWorkspaceOverlay(array $row, $querySettings)
909
-    {
910
-        $tableName = $this->getTableName();
911
-
912
-        $pageRepository = $this->getPageRepository();
913
-        if (is_object($GLOBALS['TSFE'])) {
914
-            $languageMode = $GLOBALS['TSFE']->sys_language_mode;
915
-            #if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) {
916
-            #    $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace;
917
-            #}
918
-        } else {
919
-            $languageMode = '';
920
-            $workspaceUid = $this->getBackendUser()->workspace;
921
-            #$pageRepository->versioningWorkspaceId = $workspaceUid;
922
-            #if ($this->getBackendUser()->workspace !== 0) {
923
-            #    $pageRepository->versioningPreview = 1;
924
-            #}
925
-        }
926
-
927
-        // If current row is a translation select its parent
928
-        if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
929
-            && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
930
-        ) {
931
-            if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']])
932
-                && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
933
-            ) {
934
-                $queryBuilder = $this->getQueryBuilder();
935
-                $row = $queryBuilder
936
-                    ->select($tableName . '.*')
937
-                    ->from($tableName)
938
-                    ->andWhere(
939
-                        $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']],
940
-                        $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' = 0'
941
-                    )
942
-                    ->execute()
943
-                    ->fetch();
944
-            }
945
-        }
946
-
947
-        // Retrieve the original uid; Used for Workspaces!
948
-        if (TYPO3_MODE !== 'BE') {
949
-            $pageRepository->versionOL($tableName, $row, true, true);
950
-        } else {
951
-            \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($tableName, $row);
952
-        }
953
-        if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) {
954
-            $row['uid'] = $row['_ORIG_uid'];
955
-        }
956
-
957
-        // Special case for table "pages"
958
-        if ($tableName == 'pages') {
959
-            $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
960
-        } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
961
-            && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== ''
962
-        ) {
963
-            if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
964
-                $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : '';
965
-                $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
966
-            }
967
-        }
968
-
969
-        return $row;
970
-    }
971
-
972
-    /**
973
-     * Return a resolved table name given a possible table name alias.
974
-     *
975
-     * @param string $tableNameOrAlias
976
-     * @return string
977
-     */
978
-    protected function resolveTableNameAlias($tableNameOrAlias)
979
-    {
980
-        $resolvedTableName = $tableNameOrAlias;
981
-        if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) {
982
-            $resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias];
983
-        }
984
-        return $resolvedTableName;
985
-    }
986
-
987
-    /**
988
-     * Generate a unique table name alias for the given table name.
989
-     *
990
-     * @param string $tableName
991
-     * @return string
992
-     */
993
-    protected function generateAlias($tableName)
994
-    {
995
-
996
-        if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) {
997
-            $this->tableNameAliases['aliasIncrement'][$tableName] = 0;
998
-        }
999
-
1000
-        $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName];
1001
-        $tableNameAlias = $tableName . $numberOfAliases;
1002
-
1003
-        $this->tableNameAliases['aliasIncrement'][$tableName]++;
1004
-        $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName;
1005
-
1006
-        return $tableNameAlias;
1007
-    }
1008
-
1009
-    /**
1010
-     * Replace the table names by its table name alias within the given statement.
1011
-     *
1012
-     * @param string $tableName
1013
-     * @param string $tableNameAlias
1014
-     * @param string $statement
1015
-     * @return string
1016
-     */
1017
-    protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement)
1018
-    {
1019
-        if ($statement && $tableName !== $tableNameAlias) {
1020
-            $statement = str_replace($tableName, $tableNameAlias, $statement);
1021
-        }
1022
-        return $statement;
1023
-    }
1024
-
1025
-    /**
1026
-     * Returns an instance of the current Backend User.
1027
-     *
1028
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1029
-     */
1030
-    protected function getBackendUser()
1031
-    {
1032
-        return $GLOBALS['BE_USER'];
1033
-    }
1034
-
1035
-    /**
1036
-     * Tell whether a Backend User is logged in.
1037
-     *
1038
-     * @return bool
1039
-     */
1040
-    protected function isBackendUserLogged()
1041
-    {
1042
-        return is_object($GLOBALS['BE_USER']);
1043
-    }
1044
-
1045
-    /**
1046
-     * @return PageRepository|object
1047
-     */
1048
-    protected function getPageRepository()
1049
-    {
1050
-        if (!$this->pageRepository instanceof PageRepository) {
1051
-            if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($GLOBALS['TSFE'])) {
1052
-                $this->pageRepository = $GLOBALS['TSFE']->sys_page;
1053
-            } else {
1054
-                $this->pageRepository = GeneralUtility::makeInstance(PageRepository::class);
1055
-            }
1056
-        }
1057
-
1058
-        return $this->pageRepository;
1059
-    }
1060
-
1061
-    /**
1062
-     * @return \Fab\Vidi\Resolver\FieldPathResolver|object
1063
-     */
1064
-    protected function getFieldPathResolver()
1065
-    {
1066
-        return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\FieldPathResolver::class);
1067
-    }
1068
-
1069
-    /**
1070
-     * @return object|Connection
1071
-     */
1072
-    protected function getConnection(): Connection
1073
-    {
1074
-        /** @var ConnectionPool $connectionPool */
1075
-        return GeneralUtility::makeInstance(ConnectionPool::class)
1076
-            ->getConnectionForTable($this->getTableName());
1077
-    }
1078
-
1079
-    /**
1080
-     * @return object|QueryBuilder
1081
-     */
1082
-    protected function getQueryBuilder(): QueryBuilder
1083
-    {
1084
-        /** @var ConnectionPool $connectionPool */
1085
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
1086
-        return $connectionPool->getQueryBuilderForTable($this->getTableName());
1087
-    }
1088
-
1089
-    /**
1090
-     * @return string
1091
-     */
1092
-    public function getTableName(): string
1093
-    {
1094
-        return $this->query->getSource()->getNodeTypeName(); // getSelectorName()
1095
-    }
43
+	const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull';
44
+	const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull';
45
+
46
+	/**
47
+	 * The TYPO3 page repository. Used for language and workspace overlay
48
+	 *
49
+	 * @var PageRepository
50
+	 */
51
+	protected $pageRepository;
52
+
53
+	/**
54
+	 * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
55
+	 * @Inject
56
+	 */
57
+	protected $environmentService;
58
+
59
+	/**
60
+	 * @var \Fab\Vidi\Persistence\Query
61
+	 */
62
+	protected $query;
63
+
64
+	/**
65
+	 * Store some info related to table name and its aliases.
66
+	 *
67
+	 * @var array
68
+	 */
69
+	protected $tableNameAliases = array(
70
+		'aliases' => [],
71
+		'aliasIncrement' => [],
72
+	);
73
+
74
+	/**
75
+	 * Use to store the current foreign table name alias.
76
+	 *
77
+	 * @var string
78
+	 */
79
+	protected $currentChildTableNameAlias = '';
80
+
81
+	/**
82
+	 * @param Query $query
83
+	 */
84
+	public function __construct(Query $query)
85
+	{
86
+		$this->query = $query;
87
+	}
88
+
89
+	/**
90
+	 * @param $parameters
91
+	 * @return array
92
+	 */
93
+	protected static function getTypes($parameters)
94
+	{
95
+		$types = [];
96
+		foreach ($parameters as $parameter) {
97
+			if (is_array($parameter)) {
98
+				if (MathUtility::canBeInterpretedAsInteger($parameter[0])) {
99
+					$types[] = \Doctrine\DBAL\Connection::PARAM_INT_ARRAY;
100
+				} else {
101
+					$types[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY;
102
+				}
103
+			} else {
104
+				if (MathUtility::canBeInterpretedAsInteger($parameter)) {
105
+					$types[] = ParameterType::INTEGER;
106
+				} else {
107
+					$types[] = ParameterType::STRING;
108
+				}
109
+			}
110
+		}
111
+		return $types;
112
+	}
113
+
114
+	/**
115
+	 * Returns the result of the query
116
+	 */
117
+	public function fetchResult()
118
+	{
119
+		$parameters = [];
120
+		$statementParts = $this->parseQuery($parameters);
121
+		$statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts);
122
+		$sql = $this->buildQuery($statementParts);
123
+		//print $sql; exit();
124
+
125
+		$rows = $this->getConnection()
126
+			->executeQuery($sql, $parameters, self::getTypes($parameters))
127
+			->fetchAll();
128
+
129
+		return $this->getContentObjects($rows);
130
+	}
131
+
132
+	/**
133
+	 * Returns the number of tuples matching the query.
134
+	 *
135
+	 * @return int The number of matching tuples
136
+	 */
137
+	public function countResult()
138
+	{
139
+		$parameters = [];
140
+		$statementParts = $this->parseQuery($parameters);
141
+		$statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts);
142
+		$types = self::getTypes($parameters);
143
+
144
+		// if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints
145
+		if (!empty($statementParts['limit'])) {
146
+			$sql = $this->buildQuery($statementParts);
147
+
148
+			$count = $this
149
+				->getConnection()
150
+				->executeQuery($sql, $parameters, $types)
151
+				->rowCount();
152
+		} else {
153
+			$statementParts['fields'] = array('COUNT(*)');
154
+			// having orderings without grouping is not compatible with non-MySQL DBMS
155
+			$statementParts['orderings'] = [];
156
+			if (isset($statementParts['keywords']['distinct'])) {
157
+				unset($statementParts['keywords']['distinct']);
158
+				$distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid';
159
+				$statementParts['fields'] = array('COUNT(DISTINCT ' . $statementParts['mainTable'] . '.' . $distinctField . ')');
160
+			}
161
+
162
+			$sql = $this->buildQuery($statementParts);
163
+			$count = $this
164
+				->getConnection()
165
+				->executeQuery($sql, $parameters, $types)
166
+				->fetchColumn(0);
167
+		}
168
+		return (int)$count;
169
+	}
170
+
171
+	/**
172
+	 * Parses the query and returns the SQL statement parts.
173
+	 *
174
+	 * @param array &$parameters
175
+	 * @return array
176
+	 */
177
+	public function parseQuery(array &$parameters)
178
+	{
179
+		$statementParts = [];
180
+		$statementParts['keywords'] = [];
181
+		$statementParts['tables'] = [];
182
+		$statementParts['unions'] = [];
183
+		$statementParts['fields'] = [];
184
+		$statementParts['where'] = [];
185
+		$statementParts['additionalWhereClause'] = [];
186
+		$statementParts['orderings'] = [];
187
+		$statementParts['limit'] = [];
188
+		$query = $this->query;
189
+		$source = $query->getSource();
190
+		$this->parseSource($source, $statementParts);
191
+		$this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters);
192
+		$this->parseOrderings($query->getOrderings(), $source, $statementParts);
193
+		$this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts);
194
+		$tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions']));
195
+		foreach ($tableNames as $tableNameOrAlias) {
196
+			if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) {
197
+				$this->addAdditionalWhereClause($query->getQuerySettings(), $tableNameOrAlias, $statementParts);
198
+			}
199
+		}
200
+
201
+		return $statementParts;
202
+	}
203
+
204
+	/**
205
+	 * Fiddle with the statement structure to handle recursive MM relations.
206
+	 * For the recursive MM query to work, we must invert some values.
207
+	 * Let see if that is the best way of doing that...
208
+	 *
209
+	 * @param array $statementParts
210
+	 * @return array
211
+	 */
212
+	public function processStatementStructureForRecursiveMMRelation(array $statementParts)
213
+	{
214
+
215
+		if ($this->hasRecursiveMMRelation()) {
216
+			$tableName = $this->query->getType();
217
+
218
+			// In order the MM query to work for a recursive MM query, we must invert some values.
219
+			// tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name)
220
+			$values = [];
221
+			foreach ($statementParts['fields'] as $key => $value) {
222
+				$values[$key] = str_replace($tableName, $tableName . '0', $value);
223
+			}
224
+			$statementParts['fields'] = $values;
225
+
226
+			// Same comment as above.
227
+			$values = [];
228
+			foreach ($statementParts['where'] as $key => $value) {
229
+				$values[$key] = str_replace($tableName . '0', $tableName, $value);
230
+			}
231
+			$statementParts['where'] = $values;
232
+
233
+			// We must be more restrictive by transforming the "left" union by "inner"
234
+			$values = [];
235
+			foreach ($statementParts['unions'] as $key => $value) {
236
+				$values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value);
237
+			}
238
+			$statementParts['unions'] = $values;
239
+		}
240
+
241
+		return $statementParts;
242
+	}
243
+
244
+	/**
245
+	 * Tell whether there is a recursive MM relation.
246
+	 *
247
+	 * @return bool
248
+	 */
249
+	public function hasRecursiveMMRelation()
250
+	{
251
+		return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]);
252
+
253
+	}
254
+
255
+	/**
256
+	 * Returns the statement, ready to be executed.
257
+	 *
258
+	 * @param array $statementParts The SQL statement parts
259
+	 * @return string The SQL statement
260
+	 */
261
+	public function buildQuery(array $statementParts)
262
+	{
263
+
264
+		// Add more statement to the UNION part.
265
+		if (!empty($statementParts['unions'])) {
266
+			foreach ($statementParts['unions'] as $tableName => $unionPart) {
267
+				if (!empty($statementParts['additionalWhereClause'][$tableName])) {
268
+					$statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]);
269
+				}
270
+			}
271
+		}
272
+
273
+		$statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']);
274
+		if (!empty($statementParts['where'])) {
275
+			$statement .= ' WHERE ' . implode('', $statementParts['where']);
276
+			if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) {
277
+				$statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
278
+			}
279
+		} elseif (!empty($statementParts['additionalWhereClause'])) {
280
+			$statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]);
281
+		}
282
+		if (!empty($statementParts['orderings'])) {
283
+			$statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']);
284
+		}
285
+		if (!empty($statementParts['limit'])) {
286
+			$statement .= ' LIMIT ' . $statementParts['limit'];
287
+		}
288
+
289
+		return $statement;
290
+	}
291
+
292
+	/**
293
+	 * Transforms a Query Source into SQL and parameter arrays
294
+	 *
295
+	 * @param SourceInterface $source The source
296
+	 * @param array &$sql
297
+	 * @return void
298
+	 */
299
+	protected function parseSource(SourceInterface $source, array &$sql)
300
+	{
301
+		$tableName = $this->getTableName();
302
+		$sql['fields'][$tableName] = $tableName . '.*';
303
+		if ($this->query->getDistinct()) {
304
+			$sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct();
305
+			$sql['keywords']['distinct'] = 'DISTINCT';
306
+		}
307
+		$sql['tables'][$tableName] = $tableName;
308
+		$sql['mainTable'] = $tableName;
309
+	}
310
+
311
+	/**
312
+	 * Transforms a constraint into SQL and parameter arrays
313
+	 *
314
+	 * @param ConstraintInterface $constraint The constraint
315
+	 * @param SourceInterface $source The source
316
+	 * @param array &$statementParts The query parts
317
+	 * @param array &$parameters The parameters that will replace the markers
318
+	 * @return void
319
+	 */
320
+	protected function parseConstraint(ConstraintInterface $constraint = null, SourceInterface $source, array &$statementParts, array &$parameters)
321
+	{
322
+		if ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface) {
323
+			$statementParts['where'][] = '(';
324
+			$this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters);
325
+			$statementParts['where'][] = ' AND ';
326
+			$this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters);
327
+			$statementParts['where'][] = ')';
328
+		} elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface) {
329
+			$statementParts['where'][] = '(';
330
+			$this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters);
331
+			$statementParts['where'][] = ' OR ';
332
+			$this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters);
333
+			$statementParts['where'][] = ')';
334
+		} elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface) {
335
+			$statementParts['where'][] = 'NOT (';
336
+			$this->parseConstraint($constraint->getConstraint(), $source, $statementParts, $parameters);
337
+			$statementParts['where'][] = ')';
338
+		} elseif ($constraint instanceof ComparisonInterface) {
339
+			$this->parseComparison($constraint, $source, $statementParts, $parameters);
340
+		}
341
+	}
342
+
343
+	/**
344
+	 * Parse a Comparison into SQL and parameter arrays.
345
+	 *
346
+	 * @param ComparisonInterface $comparison The comparison to parse
347
+	 * @param SourceInterface $source The source
348
+	 * @param array &$statementParts SQL query parts to add to
349
+	 * @param array &$parameters Parameters to bind to the SQL
350
+	 * @return void
351
+	 * @throws Exception\RepositoryException
352
+	 */
353
+	protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$statementParts, array &$parameters)
354
+	{
355
+		$operand1 = $comparison->getOperand1();
356
+		$operator = $comparison->getOperator();
357
+		$operand2 = $comparison->getOperand2();
358
+		if ($operator === QueryInterface::OPERATOR_IN) {
359
+			$items = [];
360
+			$hasValue = false;
361
+			foreach ($operand2 as $value) {
362
+				$value = $this->getPlainValue($value);
363
+				if ($value !== null) {
364
+					$items[] = $value;
365
+					$hasValue = true;
366
+				}
367
+			}
368
+			if ($hasValue === false) {
369
+				$statementParts['where'][] = '1<>1';
370
+			} else {
371
+				$this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters, null);
372
+				$parameters[] = $items;
373
+			}
374
+		} elseif ($operator === QueryInterface::OPERATOR_CONTAINS) {
375
+			if ($operand2 === null) {
376
+				$statementParts['where'][] = '1<>1';
377
+			} else {
378
+				throw new \Exception('Not implemented! Contact extension author.', 1412931227);
379
+				# @todo re-implement me if necessary.
380
+				#$tableName = $this->query->getType();
381
+				#$propertyName = $operand1->getPropertyName();
382
+				#while (strpos($propertyName, '.') !== false) {
383
+				#	$this->addUnionStatement($tableName, $propertyName, $statementParts);
384
+				#}
385
+				#$columnName = $propertyName;
386
+				#$columnMap = $propertyName;
387
+				#$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : null;
388
+				#if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
389
+				#	$relationTableName = $columnMap->getRelationTableName();
390
+				#	$statementParts['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)';
391
+				#	$parameters[] = intval($this->getPlainValue($operand2));
392
+				#} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) {
393
+				#	$parentKeyFieldName = $columnMap->getParentKeyFieldName();
394
+				#	if (isset($parentKeyFieldName)) {
395
+				#		$childTableName = $columnMap->getChildTableName();
396
+				#		$statementParts['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)';
397
+				#		$parameters[] = intval($this->getPlainValue($operand2));
398
+				#	} else {
399
+				#		$statementParts['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')';
400
+				#		$parameters[] = intval($this->getPlainValue($operand2));
401
+				#	}
402
+				#} else {
403
+				#	throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745);
404
+				#}
405
+			}
406
+		} else {
407
+			if ($operand2 === null) {
408
+				if ($operator === QueryInterface::OPERATOR_EQUAL_TO) {
409
+					$operator = self::OPERATOR_EQUAL_TO_NULL;
410
+				} elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) {
411
+					$operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
412
+				}
413
+			}
414
+			$this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters);
415
+			$parameters[] = $this->getPlainValue($operand2);
416
+		}
417
+	}
418
+
419
+	/**
420
+	 * Returns a plain value, i.e. objects are flattened if possible.
421
+	 *
422
+	 * @param mixed $input
423
+	 * @return mixed
424
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException
425
+	 */
426
+	protected function getPlainValue($input)
427
+	{
428
+		if (is_array($input)) {
429
+			throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932);
430
+		}
431
+		if ($input instanceof \DateTime) {
432
+			return $input->format('U');
433
+		} elseif (is_object($input)) {
434
+			if ($input instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
435
+				$realInput = $input->_loadRealInstance();
436
+			} else {
437
+				$realInput = $input;
438
+			}
439
+			if ($realInput instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
440
+				return $realInput->getUid();
441
+			} else {
442
+				throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934);
443
+			}
444
+		} elseif (is_bool($input)) {
445
+			return $input === true ? 1 : 0;
446
+		} else {
447
+			return $input;
448
+		}
449
+	}
450
+
451
+	/**
452
+	 * Parse a DynamicOperand into SQL and parameter arrays.
453
+	 *
454
+	 * @param DynamicOperandInterface $operand
455
+	 * @param string $operator One of the JCR_OPERATOR_* constants
456
+	 * @param SourceInterface $source The source
457
+	 * @param array &$statementParts The query parts
458
+	 * @param array &$parameters The parameters that will replace the markers
459
+	 * @param string $valueFunction an optional SQL function to apply to the operand value
460
+	 * @return void
461
+	 */
462
+	protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$statementParts, array &$parameters, $valueFunction = null)
463
+	{
464
+		if ($operand instanceof LowerCaseInterface) {
465
+			$this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'LOWER');
466
+		} elseif ($operand instanceof UpperCaseInterface) {
467
+			$this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'UPPER');
468
+		} elseif ($operand instanceof PropertyValueInterface) {
469
+			$propertyName = $operand->getPropertyName();
470
+
471
+			// Reset value.
472
+			$this->currentChildTableNameAlias = '';
473
+
474
+			if ($source instanceof SelectorInterface) {
475
+				$tableName = $this->query->getType();
476
+				while (strpos($propertyName, '.') !== false) {
477
+					$this->addUnionStatement($tableName, $propertyName, $statementParts);
478
+				}
479
+			} elseif ($source instanceof JoinInterface) {
480
+				$tableName = $source->getJoinCondition()->getSelector1Name();
481
+			}
482
+
483
+			$columnName = $propertyName;
484
+			$resolvedOperator = $this->resolveOperator($operator);
485
+			$constraintSQL = '';
486
+
487
+			$marker = $operator === QueryInterface::OPERATOR_IN
488
+				? '(?)'
489
+				: '?';
490
+
491
+			if ($valueFunction === null) {
492
+				$constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $resolvedOperator . ' ' . $marker;
493
+			} else {
494
+				$constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $resolvedOperator . ' ' . $marker;
495
+			}
496
+
497
+			if (isset($tableName) && !empty($this->currentChildTableNameAlias)) {
498
+				$constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL);
499
+			}
500
+			$statementParts['where'][] = $constraintSQL;
501
+		}
502
+	}
503
+
504
+	/**
505
+	 * @param string &$tableName
506
+	 * @param string &$propertyPath
507
+	 * @param array &$statementParts
508
+	 */
509
+	protected function addUnionStatement(&$tableName, &$propertyPath, array &$statementParts)
510
+	{
511
+
512
+		$table = Tca::table($tableName);
513
+
514
+		$explodedPropertyPath = explode('.', $propertyPath, 2);
515
+		$fieldName = $explodedPropertyPath[0];
516
+
517
+		// Field of type "group" are special because property path must contain the table name
518
+		// to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
519
+		$parts = explode('.', $propertyPath, 3);
520
+		if ($table->field($fieldName)->isGroup() && count($parts) > 2) {
521
+			$explodedPropertyPath[0] = $parts[0] . '.' . $parts[1];
522
+			$explodedPropertyPath[1] = $parts[2];
523
+			$fieldName = $explodedPropertyPath[0];
524
+		}
525
+
526
+		$parentKeyFieldName = $table->field($fieldName)->getForeignField();
527
+		$childTableName = $table->field($fieldName)->getForeignTable();
528
+
529
+		if ($childTableName === null) {
530
+			throw new Exception\InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925);
531
+		}
532
+
533
+		if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one"
534
+			// sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons.
535
+			// $parentKeyFieldName === null does the trick somehow. Before condition was if (isset($parentKeyFieldName))
536
+			if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === null) {
537
+				$statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid';
538
+			} else {
539
+				$statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
540
+			}
541
+		} elseif ($table->field($fieldName)->hasRelationManyToMany()) {
542
+			$relationTableName = $table->field($fieldName)->getManyToManyTable();
543
+
544
+			$parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
545
+			$childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local';
546
+
547
+			// MM table e.g sys_category_record_mm
548
+			$relationTableNameAlias = $this->generateAlias($relationTableName);
549
+			$join = sprintf(
550
+				'LEFT JOIN %s AS %s ON %s.uid=%s.%s', $relationTableName,
551
+				$relationTableNameAlias,
552
+				$tableName,
553
+				$relationTableNameAlias,
554
+				$parentKeyFieldName
555
+			);
556
+			$statementParts['unions'][$relationTableNameAlias] = $join;
557
+
558
+			// Foreign table e.g sys_category
559
+			$childTableNameAlias = $this->generateAlias($childTableName);
560
+			$this->currentChildTableNameAlias = $childTableNameAlias;
561
+			$join = sprintf(
562
+				'LEFT JOIN %s AS %s ON %s.%s=%s.uid',
563
+				$childTableName,
564
+				$childTableNameAlias,
565
+				$relationTableNameAlias,
566
+				$childKeyFieldName,
567
+				$childTableNameAlias
568
+			);
569
+			$statementParts['unions'][$childTableNameAlias] = $join;
570
+
571
+			// Find a possible table name for a MM condition.
572
+			$tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition();
573
+			if ($tableNameCondition) {
574
+
575
+				// If we can find a source file name,  we can then retrieve more MM conditions from the TCA such as a field name.
576
+				$sourceFileName = $this->query->getSourceFieldName();
577
+				if (empty($sourceFileName)) {
578
+					$additionalMMConditions = array(
579
+						'tablenames' => $tableNameCondition,
580
+					);
581
+				} else {
582
+					$additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition();
583
+				}
584
+
585
+				foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) {
586
+					$additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
587
+					$statementParts['unions'][$relationTableNameAlias] .= $additionalJoin;
588
+
589
+					$additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition);
590
+					$statementParts['unions'][$childTableNameAlias] .= $additionalJoin;
591
+				}
592
+			}
593
+
594
+		} elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations
595
+			$childTableNameAlias = $this->generateAlias($childTableName);
596
+			$this->currentChildTableNameAlias = $childTableNameAlias;
597
+
598
+			if (isset($parentKeyFieldName)) {
599
+				$join = sprintf(
600
+					'LEFT JOIN %s AS %s ON %s.uid=%s.%s',
601
+					$childTableName,
602
+					$childTableNameAlias,
603
+					$tableName,
604
+					$childTableNameAlias,
605
+					$parentKeyFieldName
606
+				);
607
+				$statementParts['unions'][$childTableNameAlias] = $join;
608
+			} else {
609
+				$join = sprintf(
610
+					'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))',
611
+					$childTableName,
612
+					$childTableNameAlias,
613
+					$childTableNameAlias,
614
+					$tableName,
615
+					$fieldName
616
+				);
617
+				$statementParts['unions'][$childTableNameAlias] = $join;
618
+			}
619
+		} else {
620
+			throw new Exception('Could not determine type of relation.', 1252502725);
621
+		}
622
+
623
+		$statementParts['keywords']['distinct'] = 'DISTINCT';
624
+		$propertyPath = $explodedPropertyPath[1];
625
+		$tableName = $childTableName;
626
+	}
627
+
628
+	/**
629
+	 * Returns the SQL operator for the given JCR operator type.
630
+	 *
631
+	 * @param string $operator One of the JCR_OPERATOR_* constants
632
+	 * @return string an SQL operator
633
+	 * @throws Exception
634
+	 */
635
+	protected function resolveOperator($operator)
636
+	{
637
+		switch ($operator) {
638
+			case self::OPERATOR_EQUAL_TO_NULL:
639
+				$operator = 'IS';
640
+				break;
641
+			case self::OPERATOR_NOT_EQUAL_TO_NULL:
642
+				$operator = 'IS NOT';
643
+				break;
644
+			case QueryInterface::OPERATOR_IN:
645
+				$operator = 'IN';
646
+				break;
647
+			case QueryInterface::OPERATOR_EQUAL_TO:
648
+				$operator = '=';
649
+				break;
650
+			case QueryInterface::OPERATOR_NOT_EQUAL_TO:
651
+				$operator = '!=';
652
+				break;
653
+			case QueryInterface::OPERATOR_LESS_THAN:
654
+				$operator = '<';
655
+				break;
656
+			case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO:
657
+				$operator = '<=';
658
+				break;
659
+			case QueryInterface::OPERATOR_GREATER_THAN:
660
+				$operator = '>';
661
+				break;
662
+			case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO:
663
+				$operator = '>=';
664
+				break;
665
+			case QueryInterface::OPERATOR_LIKE:
666
+				$operator = 'LIKE';
667
+				break;
668
+			default:
669
+				throw new Exception('Unsupported operator encountered.', 1242816073);
670
+		}
671
+		return $operator;
672
+	}
673
+
674
+	/**
675
+	 * Adds additional WHERE statements according to the query settings.
676
+	 *
677
+	 * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
678
+	 * @param string $tableNameOrAlias The table name to add the additional where clause for
679
+	 * @param array &$statementParts
680
+	 * @return void
681
+	 */
682
+	protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts)
683
+	{
684
+		$this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts);
685
+		if ($querySettings->getRespectSysLanguage()) {
686
+			$this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings);
687
+		}
688
+	}
689
+
690
+	/**
691
+	 * Adds enableFields and deletedClause to the query if necessary
692
+	 *
693
+	 * @param QuerySettingsInterface $querySettings
694
+	 * @param string $tableNameOrAlias The database table name
695
+	 * @param array &$statementParts The query parts
696
+	 * @return void
697
+	 */
698
+	protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts)
699
+	{
700
+		$statement = '';
701
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
702
+		if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
703
+			$ignoreEnableFields = $querySettings->getIgnoreEnableFields();
704
+			$enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored();
705
+			$includeDeleted = $querySettings->getIncludeDeleted();
706
+			if ($this->environmentService->isEnvironmentInFrontendMode()) {
707
+				$statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted);
708
+			} else {
709
+				// TYPO3_MODE === 'BE'
710
+				$statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted);
711
+			}
712
+
713
+			// Remove the prefixing "AND" if any.
714
+			if (!empty($statement)) {
715
+				$statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement;
716
+				$statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement;
717
+			}
718
+		}
719
+	}
720
+
721
+	/**
722
+	 * Returns constraint statement for frontend context
723
+	 *
724
+	 * @param string $tableNameOrAlias
725
+	 * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
726
+	 * @param array $enableFieldsToBeIgnored If $ignoreEnableFields is true, this array specifies enable fields to be ignored. If it is null or an empty array (default) all enable fields are ignored.
727
+	 * @param boolean $includeDeleted A flag indicating whether deleted records should be included
728
+	 * @return string
729
+	 * @throws Exception\InconsistentQuerySettingsException
730
+	 */
731
+	protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted)
732
+	{
733
+		$statement = '';
734
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
735
+		if ($ignoreEnableFields && !$includeDeleted) {
736
+			if (count($enableFieldsToBeIgnored)) {
737
+				// array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented
738
+				$statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored));
739
+			} else {
740
+				$statement .= $this->getPageRepository()->deleteClause($tableName);
741
+			}
742
+		} elseif (!$ignoreEnableFields && !$includeDeleted) {
743
+			$statement .= $this->getPageRepository()->enableFields($tableName);
744
+		} elseif (!$ignoreEnableFields && $includeDeleted) {
745
+			throw new Exception\InconsistentQuerySettingsException('Query setting "ignoreEnableFields=false" can not be used together with "includeDeleted=true" in frontend context.', 1327678173);
746
+		}
747
+		return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
748
+	}
749
+
750
+	/**
751
+	 * Returns constraint statement for backend context
752
+	 *
753
+	 * @param string $tableNameOrAlias
754
+	 * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored
755
+	 * @param boolean $includeDeleted A flag indicating whether deleted records should be included
756
+	 * @return string
757
+	 */
758
+	protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted)
759
+	{
760
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
761
+		$statement = '';
762
+		if (!$ignoreEnableFields) {
763
+			$statement .= BackendUtility::BEenableFields($tableName);
764
+		}
765
+
766
+		// If the table is found to have "workspace" support, add the corresponding fields in the statement.
767
+		if (Tca::table($tableName)->hasWorkspaceSupport()) {
768
+			if ($this->getBackendUser()->workspace === 0) {
769
+				$statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE);
770
+			} else {
771
+				// Show only records of live and of the current workspace
772
+				// In case we are in a Versioning preview
773
+				$statement .= ' AND (' .
774
+					$tableName . '.t3ver_wsid=0 OR ' .
775
+					$tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace .
776
+					')';
777
+			}
778
+
779
+			// Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0
780
+			$statement .= ' AND ' . $tableName . '.pid<>-1';
781
+		}
782
+
783
+		if (!$includeDeleted) {
784
+			$statement .= BackendUtility::deleteClause($tableName);
785
+		}
786
+
787
+		return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement);
788
+	}
789
+
790
+	/**
791
+	 * Builds the language field statement
792
+	 *
793
+	 * @param string $tableNameOrAlias The database table name
794
+	 * @param array &$statementParts The query parts
795
+	 * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
796
+	 * @return void
797
+	 * @throws Exception
798
+	 */
799
+	protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings)
800
+	{
801
+		$tableName = $this->resolveTableNameAlias($tableNameOrAlias);
802
+		if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
803
+			if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) {
804
+				// Select all entries for the current language
805
+				$additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)';
806
+				// If any language is set -> get those entries which are not translated yet
807
+				// They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode
808
+				if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
809
+					&& $querySettings->getLanguageUid() > 0
810
+				) {
811
+					$additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' .
812
+						' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] .
813
+						' FROM ' . $tableName .
814
+						' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' .
815
+						' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0';
816
+
817
+					// Add delete clause to ensure all entries are loaded
818
+					if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) {
819
+						$additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0';
820
+					}
821
+					$additionalWhereClause .= '))';
822
+				}
823
+				$statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')';
824
+			}
825
+		}
826
+	}
827
+
828
+	/**
829
+	 * Transforms orderings into SQL.
830
+	 *
831
+	 * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
832
+	 * @param SourceInterface $source The source
833
+	 * @param array &$statementParts The query parts
834
+	 * @return void
835
+	 * @throws Exception\UnsupportedOrderException
836
+	 */
837
+	protected function parseOrderings(array $orderings, SourceInterface $source, array &$statementParts)
838
+	{
839
+		foreach ($orderings as $fieldNameAndPath => $order) {
840
+			switch ($order) {
841
+				case QueryInterface::ORDER_ASCENDING:
842
+					$order = 'ASC';
843
+					break;
844
+				case QueryInterface::ORDER_DESCENDING:
845
+					$order = 'DESC';
846
+					break;
847
+				default:
848
+					throw new Exception\UnsupportedOrderException('Unsupported order encountered.', 1456845126);
849
+			}
850
+
851
+			$tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType());
852
+			$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName);
853
+			$statementParts['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order);
854
+		}
855
+	}
856
+
857
+	/**
858
+	 * Transforms limit and offset into SQL
859
+	 *
860
+	 * @param int $limit
861
+	 * @param int $offset
862
+	 * @param array &$statementParts
863
+	 * @return void
864
+	 */
865
+	protected function parseLimitAndOffset($limit, $offset, array &$statementParts)
866
+	{
867
+		if ($limit !== null && $offset !== null) {
868
+			$statementParts['limit'] = intval($offset) . ', ' . intval($limit);
869
+		} elseif ($limit !== null) {
870
+			$statementParts['limit'] = intval($limit);
871
+		}
872
+	}
873
+
874
+	/**
875
+	 * @param array $rows
876
+	 * @return array
877
+	 */
878
+	protected function getContentObjects(array $rows): array
879
+	{
880
+		$contentObjects = [];
881
+		foreach ($rows as $row) {
882
+
883
+			// Get language uid from querySettings.
884
+			// Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed)
885
+			$overlaidRow = $this->doLanguageAndWorkspaceOverlay(
886
+				$row,
887
+				$this->query->getQuerySettings()
888
+			);
889
+
890
+			$contentObjects[] = GeneralUtility::makeInstance(
891
+				\Fab\Vidi\Domain\Model\Content::class,
892
+				$this->query->getType(),
893
+				$overlaidRow
894
+			);
895
+		}
896
+
897
+		return $contentObjects;
898
+	}
899
+
900
+	/**
901
+	 * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
902
+	 * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
903
+	 *
904
+	 * @param array $row
905
+	 * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
906
+	 * @return array
907
+	 */
908
+	protected function doLanguageAndWorkspaceOverlay(array $row, $querySettings)
909
+	{
910
+		$tableName = $this->getTableName();
911
+
912
+		$pageRepository = $this->getPageRepository();
913
+		if (is_object($GLOBALS['TSFE'])) {
914
+			$languageMode = $GLOBALS['TSFE']->sys_language_mode;
915
+			#if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) {
916
+			#    $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace;
917
+			#}
918
+		} else {
919
+			$languageMode = '';
920
+			$workspaceUid = $this->getBackendUser()->workspace;
921
+			#$pageRepository->versioningWorkspaceId = $workspaceUid;
922
+			#if ($this->getBackendUser()->workspace !== 0) {
923
+			#    $pageRepository->versioningPreview = 1;
924
+			#}
925
+		}
926
+
927
+		// If current row is a translation select its parent
928
+		if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
929
+			&& isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
930
+		) {
931
+			if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']])
932
+				&& $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
933
+			) {
934
+				$queryBuilder = $this->getQueryBuilder();
935
+				$row = $queryBuilder
936
+					->select($tableName . '.*')
937
+					->from($tableName)
938
+					->andWhere(
939
+						$tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']],
940
+						$tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' = 0'
941
+					)
942
+					->execute()
943
+					->fetch();
944
+			}
945
+		}
946
+
947
+		// Retrieve the original uid; Used for Workspaces!
948
+		if (TYPO3_MODE !== 'BE') {
949
+			$pageRepository->versionOL($tableName, $row, true, true);
950
+		} else {
951
+			\TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($tableName, $row);
952
+		}
953
+		if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) {
954
+			$row['uid'] = $row['_ORIG_uid'];
955
+		}
956
+
957
+		// Special case for table "pages"
958
+		if ($tableName == 'pages') {
959
+			$row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
960
+		} elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
961
+			&& $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== ''
962
+		) {
963
+			if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
964
+				$overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : '';
965
+				$row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
966
+			}
967
+		}
968
+
969
+		return $row;
970
+	}
971
+
972
+	/**
973
+	 * Return a resolved table name given a possible table name alias.
974
+	 *
975
+	 * @param string $tableNameOrAlias
976
+	 * @return string
977
+	 */
978
+	protected function resolveTableNameAlias($tableNameOrAlias)
979
+	{
980
+		$resolvedTableName = $tableNameOrAlias;
981
+		if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) {
982
+			$resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias];
983
+		}
984
+		return $resolvedTableName;
985
+	}
986
+
987
+	/**
988
+	 * Generate a unique table name alias for the given table name.
989
+	 *
990
+	 * @param string $tableName
991
+	 * @return string
992
+	 */
993
+	protected function generateAlias($tableName)
994
+	{
995
+
996
+		if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) {
997
+			$this->tableNameAliases['aliasIncrement'][$tableName] = 0;
998
+		}
999
+
1000
+		$numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName];
1001
+		$tableNameAlias = $tableName . $numberOfAliases;
1002
+
1003
+		$this->tableNameAliases['aliasIncrement'][$tableName]++;
1004
+		$this->tableNameAliases['aliases'][$tableNameAlias] = $tableName;
1005
+
1006
+		return $tableNameAlias;
1007
+	}
1008
+
1009
+	/**
1010
+	 * Replace the table names by its table name alias within the given statement.
1011
+	 *
1012
+	 * @param string $tableName
1013
+	 * @param string $tableNameAlias
1014
+	 * @param string $statement
1015
+	 * @return string
1016
+	 */
1017
+	protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement)
1018
+	{
1019
+		if ($statement && $tableName !== $tableNameAlias) {
1020
+			$statement = str_replace($tableName, $tableNameAlias, $statement);
1021
+		}
1022
+		return $statement;
1023
+	}
1024
+
1025
+	/**
1026
+	 * Returns an instance of the current Backend User.
1027
+	 *
1028
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1029
+	 */
1030
+	protected function getBackendUser()
1031
+	{
1032
+		return $GLOBALS['BE_USER'];
1033
+	}
1034
+
1035
+	/**
1036
+	 * Tell whether a Backend User is logged in.
1037
+	 *
1038
+	 * @return bool
1039
+	 */
1040
+	protected function isBackendUserLogged()
1041
+	{
1042
+		return is_object($GLOBALS['BE_USER']);
1043
+	}
1044
+
1045
+	/**
1046
+	 * @return PageRepository|object
1047
+	 */
1048
+	protected function getPageRepository()
1049
+	{
1050
+		if (!$this->pageRepository instanceof PageRepository) {
1051
+			if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($GLOBALS['TSFE'])) {
1052
+				$this->pageRepository = $GLOBALS['TSFE']->sys_page;
1053
+			} else {
1054
+				$this->pageRepository = GeneralUtility::makeInstance(PageRepository::class);
1055
+			}
1056
+		}
1057
+
1058
+		return $this->pageRepository;
1059
+	}
1060
+
1061
+	/**
1062
+	 * @return \Fab\Vidi\Resolver\FieldPathResolver|object
1063
+	 */
1064
+	protected function getFieldPathResolver()
1065
+	{
1066
+		return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\FieldPathResolver::class);
1067
+	}
1068
+
1069
+	/**
1070
+	 * @return object|Connection
1071
+	 */
1072
+	protected function getConnection(): Connection
1073
+	{
1074
+		/** @var ConnectionPool $connectionPool */
1075
+		return GeneralUtility::makeInstance(ConnectionPool::class)
1076
+			->getConnectionForTable($this->getTableName());
1077
+	}
1078
+
1079
+	/**
1080
+	 * @return object|QueryBuilder
1081
+	 */
1082
+	protected function getQueryBuilder(): QueryBuilder
1083
+	{
1084
+		/** @var ConnectionPool $connectionPool */
1085
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
1086
+		return $connectionPool->getQueryBuilderForTable($this->getTableName());
1087
+	}
1088
+
1089
+	/**
1090
+	 * @return string
1091
+	 */
1092
+	public function getTableName(): string
1093
+	{
1094
+		return $this->query->getSource()->getNodeTypeName(); // getSelectorName()
1095
+	}
1096 1096
 
1097 1097
 }
Please login to merge, or discard this patch.
Classes/Persistence/Query.php 1 patch
Indentation   +637 added lines, -637 removed lines patch added patch discarded remove patch
@@ -25,642 +25,642 @@
 block discarded – undo
25 25
 class Query implements QueryInterface
26 26
 {
27 27
 
28
-    /**
29
-     * An inner join.
30
-     */
31
-    const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner';
32
-
33
-    /**
34
-     * A left-outer join.
35
-     */
36
-    const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter';
37
-
38
-    /**
39
-     * A right-outer join.
40
-     */
41
-    const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter';
42
-
43
-    /**
44
-     * Charset of strings in QOM
45
-     */
46
-    const CHARSET = 'utf-8';
47
-
48
-    /**
49
-     * @var string
50
-     */
51
-    protected $sourceFieldName;
52
-
53
-    /**
54
-     * @var string
55
-     */
56
-    protected $type;
57
-
58
-    /**
59
-     * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
60
-     */
61
-    protected $persistenceManager;
62
-
63
-    /**
64
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
65
-     */
66
-    protected $qomFactory;
67
-
68
-    /**
69
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface
70
-     */
71
-    protected $source;
72
-
73
-    /**
74
-     * @var ConstraintInterface
75
-     */
76
-    protected $constraint;
77
-
78
-    /**
79
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
80
-     */
81
-    protected $statement;
82
-
83
-    /**
84
-     * @var array
85
-     */
86
-    protected $orderings = [];
87
-
88
-    /**
89
-     * @var int
90
-     */
91
-    protected $limit;
92
-
93
-    /**
94
-     * @var int
95
-     */
96
-    protected $offset;
97
-
98
-    /**
99
-     * Apply DISTINCT upon property.
100
-     *
101
-     * @var string
102
-     */
103
-    protected $distinct;
104
-
105
-    /**
106
-     * The query settings.
107
-     *
108
-     * @var \Fab\Vidi\Persistence\QuerySettings
109
-     * @Inject
110
-     */
111
-    protected $querySettings;
112
-
113
-    /**
114
-     * Constructs a query object working on the given class name
115
-     *
116
-     * @param string $type
117
-     */
118
-    public function __construct($type)
119
-    {
120
-        $this->type = $type;
121
-    }
122
-
123
-    /**
124
-     * Injects the persistence manager, used to fetch the CR session
125
-     *
126
-     * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
127
-     * @return void
128
-     */
129
-    public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
130
-    {
131
-        $this->persistenceManager = $persistenceManager;
132
-    }
133
-
134
-    /**
135
-     * Injects the Query Object Model Factory
136
-     *
137
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory
138
-     * @return void
139
-     */
140
-    public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory)
141
-    {
142
-        $this->qomFactory = $qomFactory;
143
-    }
144
-
145
-    /**
146
-     * Sets the Query Settings. These Query settings must match the settings expected by
147
-     * the specific Storage Backend.
148
-     *
149
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
150
-     * @return void
151
-     * @api This method is not part of FLOW3 API
152
-     */
153
-    public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings)
154
-    {
155
-        $this->querySettings = $querySettings;
156
-    }
157
-
158
-    /**
159
-     * Returns the Query Settings.
160
-     *
161
-     * @throws \Exception
162
-     * @return \Fab\Vidi\Persistence\QuerySettings $querySettings The Query Settings
163
-     * @api This method is not part of FLOW3 API
164
-     */
165
-    public function getQuerySettings()
166
-    {
167
-        if (!$this->querySettings instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface) {
168
-            throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('Tried to get the query settings without setting them before.', 1248689115);
169
-        }
170
-
171
-        // Apply possible settings to the query.
172
-        if ($this->isBackendMode()) {
173
-            /** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */
174
-            $backendConfigurationManager = $this->getObjectManager()->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
175
-            $configuration = $backendConfigurationManager->getTypoScriptSetup();
176
-            $querySettings = array('respectSysLanguage');
177
-            foreach ($querySettings as $setting) {
178
-                if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) {
179
-                    $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting];
180
-                    ObjectAccess::setProperty($this->querySettings, $setting, $value);
181
-                }
182
-            }
183
-        }
184
-
185
-        return $this->querySettings;
186
-    }
187
-
188
-    /**
189
-     * Returns the type this query cares for.
190
-     *
191
-     * @return string
192
-     * @api
193
-     */
194
-    public function getType()
195
-    {
196
-        return $this->type;
197
-    }
198
-
199
-    /**
200
-     * Sets the source to fetch the result from
201
-     *
202
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
203
-     */
204
-    public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source)
205
-    {
206
-        $this->source = $source;
207
-    }
208
-
209
-    /**
210
-     * Returns the selectorn name or an empty string, if the source is not a selector
211
-     * TODO This has to be checked at another place
212
-     *
213
-     * @return string The selector name
214
-     */
215
-    protected function getSelectorName()
216
-    {
217
-        if ($this->getSource() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
218
-            return $this->source->getSelectorName();
219
-        } else {
220
-            return '';
221
-        }
222
-    }
223
-
224
-    /**
225
-     * Gets the node-tuple source for this query.
226
-     *
227
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-null
228
-     */
229
-    public function getSource()
230
-    {
231
-        if ($this->source === null) {
232
-            $this->source = $this->qomFactory->selector($this->getType());
233
-        }
234
-        return $this->source;
235
-    }
236
-
237
-    /**
238
-     * Executes the query against the database and returns the result
239
-     *
240
-     * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is true
241
-     * @api
242
-     */
243
-    public function execute($returnRawQueryResult = false)
244
-    {
245
-        /** @var VidiDbBackend $backend */
246
-        $backend = $this->getObjectManager()->get(VidiDbBackend::class, $this);
247
-        return $backend->fetchResult();
248
-    }
249
-
250
-    /**
251
-     * Sets the property names to order the result by. Expected like this:
252
-     * array(
253
-     * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
254
-     * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
255
-     * )
256
-     * where 'foo' and 'bar' are property names.
257
-     *
258
-     * @param array $orderings The property names to order by
259
-     * @return QueryInterface
260
-     * @api
261
-     */
262
-    public function setOrderings(array $orderings)
263
-    {
264
-        $this->orderings = $orderings;
265
-        return $this;
266
-    }
267
-
268
-    /**
269
-     * Returns the property names to order the result by. Like this:
270
-     * array(
271
-     * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
272
-     * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
273
-     * )
274
-     *
275
-     * @return array
276
-     */
277
-    public function getOrderings()
278
-    {
279
-        return $this->orderings;
280
-    }
281
-
282
-    /**
283
-     * Sets the maximum size of the result set to limit. Returns $this to allow
284
-     * for chaining (fluid interface)
285
-     *
286
-     * @param integer $limit
287
-     * @throws \InvalidArgumentException
288
-     * @return QueryInterface
289
-     * @api
290
-     */
291
-    public function setLimit($limit)
292
-    {
293
-        if (!is_int($limit) || $limit < 1) {
294
-            throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870);
295
-        }
296
-        $this->limit = $limit;
297
-        return $this;
298
-    }
299
-
300
-    /**
301
-     * Resets a previously set maximum size of the result set. Returns $this to allow
302
-     * for chaining (fluid interface)
303
-     *
304
-     * @return QueryInterface
305
-     * @api
306
-     */
307
-    public function unsetLimit()
308
-    {
309
-        unset($this->limit);
310
-        return $this;
311
-    }
312
-
313
-    /**
314
-     * Returns the maximum size of the result set to limit.
315
-     *
316
-     * @return integer
317
-     * @api
318
-     */
319
-    public function getLimit()
320
-    {
321
-        return $this->limit;
322
-    }
323
-
324
-    /**
325
-     * Sets the start offset of the result set to offset. Returns $this to
326
-     * allow for chaining (fluid interface)
327
-     *
328
-     * @param integer $offset
329
-     * @throws \InvalidArgumentException
330
-     * @return QueryInterface
331
-     * @api
332
-     */
333
-    public function setOffset($offset)
334
-    {
335
-        if (!is_int($offset) || $offset < 0) {
336
-            throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872);
337
-        }
338
-        $this->offset = $offset;
339
-        return $this;
340
-    }
341
-
342
-    /**
343
-     * Returns the start offset of the result set.
344
-     *
345
-     * @return integer
346
-     * @api
347
-     */
348
-    public function getOffset()
349
-    {
350
-        return $this->offset;
351
-    }
352
-
353
-    /**
354
-     * The constraint used to limit the result set. Returns $this to allow
355
-     * for chaining (fluid interface)
356
-     *
357
-     * @param ConstraintInterface $constraint
358
-     * @return QueryInterface
359
-     * @api
360
-     */
361
-    public function matching($constraint)
362
-    {
363
-        $this->constraint = $constraint;
364
-        return $this;
365
-    }
366
-
367
-    /**
368
-     * Gets the constraint for this query.
369
-     *
370
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface the constraint, or null if none
371
-     * @api
372
-     */
373
-    public function getConstraint()
374
-    {
375
-        return $this->constraint;
376
-    }
377
-
378
-    /**
379
-     * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND.
380
-     * It also scepts a single array of constraints to be concatenated.
381
-     *
382
-     * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
383
-     * @throws InvalidNumberOfConstraintsException
384
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface
385
-     * @api
386
-     */
387
-    public function logicalAnd($constraint1)
388
-    {
389
-        if (is_array($constraint1)) {
390
-            $resultingConstraint = array_shift($constraint1);
391
-            $constraints = $constraint1;
392
-        } else {
393
-            $constraints = func_get_args();
394
-            $resultingConstraint = array_shift($constraints);
395
-        }
396
-        if ($resultingConstraint === null) {
397
-            throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500);
398
-        }
399
-        foreach ($constraints as $constraint) {
400
-            $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint);
401
-        }
402
-        return $resultingConstraint;
403
-    }
404
-
405
-    /**
406
-     * Performs a logical disjunction of the two given constraints
407
-     *
408
-     * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
409
-     * @throws InvalidNumberOfConstraintsException
410
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface
411
-     * @api
412
-     */
413
-    public function logicalOr($constraint1)
414
-    {
415
-        if (is_array($constraint1)) {
416
-            $resultingConstraint = array_shift($constraint1);
417
-            $constraints = $constraint1;
418
-        } else {
419
-            $constraints = func_get_args();
420
-            $resultingConstraint = array_shift($constraints);
421
-        }
422
-        if ($resultingConstraint === null) {
423
-            throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501);
424
-        }
425
-        foreach ($constraints as $constraint) {
426
-            $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint);
427
-        }
428
-        return $resultingConstraint;
429
-    }
430
-
431
-    /**
432
-     * Performs a logical negation of the given constraint
433
-     *
434
-     * @param ConstraintInterface $constraint Constraint to negate
435
-     * @throws \RuntimeException
436
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
437
-     * @api
438
-     */
439
-    public function logicalNot(ConstraintInterface $constraint)
440
-    {
441
-        return $this->qomFactory->not($constraint);
442
-    }
443
-
444
-    /**
445
-     * Returns an equals criterion used for matching objects against a query
446
-     *
447
-     * @param string $propertyName The name of the property to compare against
448
-     * @param mixed $operand The value to compare with
449
-     * @param boolean $caseSensitive Whether the equality test should be done case-sensitive
450
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
451
-     * @api
452
-     */
453
-    public function equals($propertyName, $operand, $caseSensitive = true)
454
-    {
455
-        if (is_object($operand) || $caseSensitive) {
456
-            $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand);
457
-        } else {
458
-            $comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class)->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower'));
459
-        }
460
-        return $comparison;
461
-    }
462
-
463
-    /**
464
-     * Returns a like 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 matching should be done case-sensitive
469
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
470
-     * @api
471
-     */
472
-    public function like($propertyName, $operand, $caseSensitive = true)
473
-    {
474
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand);
475
-    }
476
-
477
-    /**
478
-     * Returns a "contains" criterion used for matching objects against a query.
479
-     * It matches if the multivalued property contains the given operand.
480
-     *
481
-     * @param string $propertyName The name of the (multivalued) property to compare against
482
-     * @param mixed $operand The value to compare with
483
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
484
-     * @api
485
-     */
486
-    public function contains($propertyName, $operand)
487
-    {
488
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand);
489
-    }
490
-
491
-    /**
492
-     * Returns an "in" criterion used for matching objects against a query. It
493
-     * matches if the property's value is contained in the multivalued operand.
494
-     *
495
-     * @param string $propertyName The name of the property to compare against
496
-     * @param mixed $operand The value to compare with, multivalued
497
-     * @throws UnexpectedTypeException
498
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
499
-     * @api
500
-     */
501
-    public function in($propertyName, $operand)
502
-    {
503
-        if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) {
504
-            throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095);
505
-        }
506
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand);
507
-    }
508
-
509
-    /**
510
-     * Returns a less than criterion used for matching objects against a query
511
-     *
512
-     * @param string $propertyName The name of the property to compare against
513
-     * @param mixed $operand The value to compare with
514
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
515
-     * @api
516
-     */
517
-    public function lessThan($propertyName, $operand)
518
-    {
519
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand);
520
-    }
521
-
522
-    /**
523
-     * Returns a less or equal than criterion used for matching objects against a query
524
-     *
525
-     * @param string $propertyName The name of the property to compare against
526
-     * @param mixed $operand The value to compare with
527
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
528
-     * @api
529
-     */
530
-    public function lessThanOrEqual($propertyName, $operand)
531
-    {
532
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand);
533
-    }
534
-
535
-    /**
536
-     * Returns a greater than criterion used for matching objects against a query
537
-     *
538
-     * @param string $propertyName The name of the property to compare against
539
-     * @param mixed $operand The value to compare with
540
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
541
-     * @api
542
-     */
543
-    public function greaterThan($propertyName, $operand)
544
-    {
545
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand);
546
-    }
547
-
548
-    /**
549
-     * Returns a greater than or equal criterion used for matching objects against a query
550
-     *
551
-     * @param string $propertyName The name of the property to compare against
552
-     * @param mixed $operand The value to compare with
553
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
554
-     * @api
555
-     */
556
-    public function greaterThanOrEqual($propertyName, $operand)
557
-    {
558
-        return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand);
559
-    }
560
-
561
-    /**
562
-     * Returns the query result count.
563
-     *
564
-     * @return integer The query result count
565
-     * @api
566
-     */
567
-    public function count()
568
-    {
569
-        /** @var VidiDbBackend $backend */
570
-        $backend = $this->getObjectManager()->get(VidiDbBackend::class, $this);
571
-        return $backend->countResult();
572
-    }
573
-
574
-    /**
575
-     * Returns an "isEmpty" criterion used for matching objects against a query.
576
-     * It matches if the multivalued property contains no values or is null.
577
-     *
578
-     * @param string $propertyName The name of the multivalued property to compare against
579
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
580
-     * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
581
-     * @api
582
-     */
583
-    public function isEmpty($propertyName)
584
-    {
585
-        throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
586
-    }
587
-
588
-    /**
589
-     * @return string
590
-     */
591
-    public function getDistinct()
592
-    {
593
-        return $this->distinct;
594
-    }
595
-
596
-    /**
597
-     * @param string $distinct
598
-     * @return $this
599
-     */
600
-    public function setDistinct($distinct)
601
-    {
602
-        $this->distinct = $distinct;
603
-        return $this;
604
-    }
605
-
606
-    /**
607
-     * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage
608
-     * backend (database).
609
-     *
610
-     * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement
611
-     * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement.
612
-     * @return QueryInterface
613
-     */
614
-    public function statement($statement, array $parameters = array())
615
-    {
616
-        $this->statement = $this->qomFactory->statement($statement, $parameters);
617
-        return $this;
618
-    }
619
-
620
-    /**
621
-     * Returns the statement of this query.
622
-     *
623
-     * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
624
-     */
625
-    public function getStatement()
626
-    {
627
-        return $this->statement;
628
-    }
629
-
630
-    /**
631
-     * Returns whether the current mode is Backend.
632
-     *
633
-     * @return bool
634
-     */
635
-    protected function isBackendMode()
636
-    {
637
-        return TYPO3_MODE == 'BE';
638
-    }
639
-
640
-    /**
641
-     * @return string
642
-     */
643
-    public function getSourceFieldName()
644
-    {
645
-        return $this->sourceFieldName;
646
-    }
647
-
648
-    /**
649
-     * @param string $sourceFieldName
650
-     * @return $this
651
-     */
652
-    public function setSourceFieldName($sourceFieldName)
653
-    {
654
-        $this->sourceFieldName = $sourceFieldName;
655
-        return $this;
656
-    }
657
-
658
-    /**
659
-     * @return object|\TYPO3\CMS\Extbase\Object\ObjectManager
660
-     */
661
-    protected function getObjectManager()
662
-    {
663
-        return GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
664
-    }
28
+	/**
29
+	 * An inner join.
30
+	 */
31
+	const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner';
32
+
33
+	/**
34
+	 * A left-outer join.
35
+	 */
36
+	const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter';
37
+
38
+	/**
39
+	 * A right-outer join.
40
+	 */
41
+	const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter';
42
+
43
+	/**
44
+	 * Charset of strings in QOM
45
+	 */
46
+	const CHARSET = 'utf-8';
47
+
48
+	/**
49
+	 * @var string
50
+	 */
51
+	protected $sourceFieldName;
52
+
53
+	/**
54
+	 * @var string
55
+	 */
56
+	protected $type;
57
+
58
+	/**
59
+	 * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
60
+	 */
61
+	protected $persistenceManager;
62
+
63
+	/**
64
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
65
+	 */
66
+	protected $qomFactory;
67
+
68
+	/**
69
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface
70
+	 */
71
+	protected $source;
72
+
73
+	/**
74
+	 * @var ConstraintInterface
75
+	 */
76
+	protected $constraint;
77
+
78
+	/**
79
+	 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
80
+	 */
81
+	protected $statement;
82
+
83
+	/**
84
+	 * @var array
85
+	 */
86
+	protected $orderings = [];
87
+
88
+	/**
89
+	 * @var int
90
+	 */
91
+	protected $limit;
92
+
93
+	/**
94
+	 * @var int
95
+	 */
96
+	protected $offset;
97
+
98
+	/**
99
+	 * Apply DISTINCT upon property.
100
+	 *
101
+	 * @var string
102
+	 */
103
+	protected $distinct;
104
+
105
+	/**
106
+	 * The query settings.
107
+	 *
108
+	 * @var \Fab\Vidi\Persistence\QuerySettings
109
+	 * @Inject
110
+	 */
111
+	protected $querySettings;
112
+
113
+	/**
114
+	 * Constructs a query object working on the given class name
115
+	 *
116
+	 * @param string $type
117
+	 */
118
+	public function __construct($type)
119
+	{
120
+		$this->type = $type;
121
+	}
122
+
123
+	/**
124
+	 * Injects the persistence manager, used to fetch the CR session
125
+	 *
126
+	 * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
127
+	 * @return void
128
+	 */
129
+	public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
130
+	{
131
+		$this->persistenceManager = $persistenceManager;
132
+	}
133
+
134
+	/**
135
+	 * Injects the Query Object Model Factory
136
+	 *
137
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory
138
+	 * @return void
139
+	 */
140
+	public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory)
141
+	{
142
+		$this->qomFactory = $qomFactory;
143
+	}
144
+
145
+	/**
146
+	 * Sets the Query Settings. These Query settings must match the settings expected by
147
+	 * the specific Storage Backend.
148
+	 *
149
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
150
+	 * @return void
151
+	 * @api This method is not part of FLOW3 API
152
+	 */
153
+	public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings)
154
+	{
155
+		$this->querySettings = $querySettings;
156
+	}
157
+
158
+	/**
159
+	 * Returns the Query Settings.
160
+	 *
161
+	 * @throws \Exception
162
+	 * @return \Fab\Vidi\Persistence\QuerySettings $querySettings The Query Settings
163
+	 * @api This method is not part of FLOW3 API
164
+	 */
165
+	public function getQuerySettings()
166
+	{
167
+		if (!$this->querySettings instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface) {
168
+			throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('Tried to get the query settings without setting them before.', 1248689115);
169
+		}
170
+
171
+		// Apply possible settings to the query.
172
+		if ($this->isBackendMode()) {
173
+			/** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */
174
+			$backendConfigurationManager = $this->getObjectManager()->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
175
+			$configuration = $backendConfigurationManager->getTypoScriptSetup();
176
+			$querySettings = array('respectSysLanguage');
177
+			foreach ($querySettings as $setting) {
178
+				if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) {
179
+					$value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting];
180
+					ObjectAccess::setProperty($this->querySettings, $setting, $value);
181
+				}
182
+			}
183
+		}
184
+
185
+		return $this->querySettings;
186
+	}
187
+
188
+	/**
189
+	 * Returns the type this query cares for.
190
+	 *
191
+	 * @return string
192
+	 * @api
193
+	 */
194
+	public function getType()
195
+	{
196
+		return $this->type;
197
+	}
198
+
199
+	/**
200
+	 * Sets the source to fetch the result from
201
+	 *
202
+	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
203
+	 */
204
+	public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source)
205
+	{
206
+		$this->source = $source;
207
+	}
208
+
209
+	/**
210
+	 * Returns the selectorn name or an empty string, if the source is not a selector
211
+	 * TODO This has to be checked at another place
212
+	 *
213
+	 * @return string The selector name
214
+	 */
215
+	protected function getSelectorName()
216
+	{
217
+		if ($this->getSource() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
218
+			return $this->source->getSelectorName();
219
+		} else {
220
+			return '';
221
+		}
222
+	}
223
+
224
+	/**
225
+	 * Gets the node-tuple source for this query.
226
+	 *
227
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-null
228
+	 */
229
+	public function getSource()
230
+	{
231
+		if ($this->source === null) {
232
+			$this->source = $this->qomFactory->selector($this->getType());
233
+		}
234
+		return $this->source;
235
+	}
236
+
237
+	/**
238
+	 * Executes the query against the database and returns the result
239
+	 *
240
+	 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is true
241
+	 * @api
242
+	 */
243
+	public function execute($returnRawQueryResult = false)
244
+	{
245
+		/** @var VidiDbBackend $backend */
246
+		$backend = $this->getObjectManager()->get(VidiDbBackend::class, $this);
247
+		return $backend->fetchResult();
248
+	}
249
+
250
+	/**
251
+	 * Sets the property names to order the result by. Expected like this:
252
+	 * array(
253
+	 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
254
+	 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
255
+	 * )
256
+	 * where 'foo' and 'bar' are property names.
257
+	 *
258
+	 * @param array $orderings The property names to order by
259
+	 * @return QueryInterface
260
+	 * @api
261
+	 */
262
+	public function setOrderings(array $orderings)
263
+	{
264
+		$this->orderings = $orderings;
265
+		return $this;
266
+	}
267
+
268
+	/**
269
+	 * Returns the property names to order the result by. Like this:
270
+	 * array(
271
+	 * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
272
+	 * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
273
+	 * )
274
+	 *
275
+	 * @return array
276
+	 */
277
+	public function getOrderings()
278
+	{
279
+		return $this->orderings;
280
+	}
281
+
282
+	/**
283
+	 * Sets the maximum size of the result set to limit. Returns $this to allow
284
+	 * for chaining (fluid interface)
285
+	 *
286
+	 * @param integer $limit
287
+	 * @throws \InvalidArgumentException
288
+	 * @return QueryInterface
289
+	 * @api
290
+	 */
291
+	public function setLimit($limit)
292
+	{
293
+		if (!is_int($limit) || $limit < 1) {
294
+			throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870);
295
+		}
296
+		$this->limit = $limit;
297
+		return $this;
298
+	}
299
+
300
+	/**
301
+	 * Resets a previously set maximum size of the result set. Returns $this to allow
302
+	 * for chaining (fluid interface)
303
+	 *
304
+	 * @return QueryInterface
305
+	 * @api
306
+	 */
307
+	public function unsetLimit()
308
+	{
309
+		unset($this->limit);
310
+		return $this;
311
+	}
312
+
313
+	/**
314
+	 * Returns the maximum size of the result set to limit.
315
+	 *
316
+	 * @return integer
317
+	 * @api
318
+	 */
319
+	public function getLimit()
320
+	{
321
+		return $this->limit;
322
+	}
323
+
324
+	/**
325
+	 * Sets the start offset of the result set to offset. Returns $this to
326
+	 * allow for chaining (fluid interface)
327
+	 *
328
+	 * @param integer $offset
329
+	 * @throws \InvalidArgumentException
330
+	 * @return QueryInterface
331
+	 * @api
332
+	 */
333
+	public function setOffset($offset)
334
+	{
335
+		if (!is_int($offset) || $offset < 0) {
336
+			throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872);
337
+		}
338
+		$this->offset = $offset;
339
+		return $this;
340
+	}
341
+
342
+	/**
343
+	 * Returns the start offset of the result set.
344
+	 *
345
+	 * @return integer
346
+	 * @api
347
+	 */
348
+	public function getOffset()
349
+	{
350
+		return $this->offset;
351
+	}
352
+
353
+	/**
354
+	 * The constraint used to limit the result set. Returns $this to allow
355
+	 * for chaining (fluid interface)
356
+	 *
357
+	 * @param ConstraintInterface $constraint
358
+	 * @return QueryInterface
359
+	 * @api
360
+	 */
361
+	public function matching($constraint)
362
+	{
363
+		$this->constraint = $constraint;
364
+		return $this;
365
+	}
366
+
367
+	/**
368
+	 * Gets the constraint for this query.
369
+	 *
370
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface the constraint, or null if none
371
+	 * @api
372
+	 */
373
+	public function getConstraint()
374
+	{
375
+		return $this->constraint;
376
+	}
377
+
378
+	/**
379
+	 * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND.
380
+	 * It also scepts a single array of constraints to be concatenated.
381
+	 *
382
+	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
383
+	 * @throws InvalidNumberOfConstraintsException
384
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface
385
+	 * @api
386
+	 */
387
+	public function logicalAnd($constraint1)
388
+	{
389
+		if (is_array($constraint1)) {
390
+			$resultingConstraint = array_shift($constraint1);
391
+			$constraints = $constraint1;
392
+		} else {
393
+			$constraints = func_get_args();
394
+			$resultingConstraint = array_shift($constraints);
395
+		}
396
+		if ($resultingConstraint === null) {
397
+			throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500);
398
+		}
399
+		foreach ($constraints as $constraint) {
400
+			$resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint);
401
+		}
402
+		return $resultingConstraint;
403
+	}
404
+
405
+	/**
406
+	 * Performs a logical disjunction of the two given constraints
407
+	 *
408
+	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
409
+	 * @throws InvalidNumberOfConstraintsException
410
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface
411
+	 * @api
412
+	 */
413
+	public function logicalOr($constraint1)
414
+	{
415
+		if (is_array($constraint1)) {
416
+			$resultingConstraint = array_shift($constraint1);
417
+			$constraints = $constraint1;
418
+		} else {
419
+			$constraints = func_get_args();
420
+			$resultingConstraint = array_shift($constraints);
421
+		}
422
+		if ($resultingConstraint === null) {
423
+			throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501);
424
+		}
425
+		foreach ($constraints as $constraint) {
426
+			$resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint);
427
+		}
428
+		return $resultingConstraint;
429
+	}
430
+
431
+	/**
432
+	 * Performs a logical negation of the given constraint
433
+	 *
434
+	 * @param ConstraintInterface $constraint Constraint to negate
435
+	 * @throws \RuntimeException
436
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
437
+	 * @api
438
+	 */
439
+	public function logicalNot(ConstraintInterface $constraint)
440
+	{
441
+		return $this->qomFactory->not($constraint);
442
+	}
443
+
444
+	/**
445
+	 * Returns an equals criterion used for matching objects against a query
446
+	 *
447
+	 * @param string $propertyName The name of the property to compare against
448
+	 * @param mixed $operand The value to compare with
449
+	 * @param boolean $caseSensitive Whether the equality test should be done case-sensitive
450
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
451
+	 * @api
452
+	 */
453
+	public function equals($propertyName, $operand, $caseSensitive = true)
454
+	{
455
+		if (is_object($operand) || $caseSensitive) {
456
+			$comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand);
457
+		} else {
458
+			$comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class)->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower'));
459
+		}
460
+		return $comparison;
461
+	}
462
+
463
+	/**
464
+	 * Returns a like 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 matching should be done case-sensitive
469
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
470
+	 * @api
471
+	 */
472
+	public function like($propertyName, $operand, $caseSensitive = true)
473
+	{
474
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand);
475
+	}
476
+
477
+	/**
478
+	 * Returns a "contains" criterion used for matching objects against a query.
479
+	 * It matches if the multivalued property contains the given operand.
480
+	 *
481
+	 * @param string $propertyName The name of the (multivalued) property to compare against
482
+	 * @param mixed $operand The value to compare with
483
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
484
+	 * @api
485
+	 */
486
+	public function contains($propertyName, $operand)
487
+	{
488
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand);
489
+	}
490
+
491
+	/**
492
+	 * Returns an "in" criterion used for matching objects against a query. It
493
+	 * matches if the property's value is contained in the multivalued operand.
494
+	 *
495
+	 * @param string $propertyName The name of the property to compare against
496
+	 * @param mixed $operand The value to compare with, multivalued
497
+	 * @throws UnexpectedTypeException
498
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
499
+	 * @api
500
+	 */
501
+	public function in($propertyName, $operand)
502
+	{
503
+		if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) {
504
+			throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095);
505
+		}
506
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand);
507
+	}
508
+
509
+	/**
510
+	 * Returns a less than criterion used for matching objects against a query
511
+	 *
512
+	 * @param string $propertyName The name of the property to compare against
513
+	 * @param mixed $operand The value to compare with
514
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
515
+	 * @api
516
+	 */
517
+	public function lessThan($propertyName, $operand)
518
+	{
519
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand);
520
+	}
521
+
522
+	/**
523
+	 * Returns a less or equal than criterion used for matching objects against a query
524
+	 *
525
+	 * @param string $propertyName The name of the property to compare against
526
+	 * @param mixed $operand The value to compare with
527
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
528
+	 * @api
529
+	 */
530
+	public function lessThanOrEqual($propertyName, $operand)
531
+	{
532
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand);
533
+	}
534
+
535
+	/**
536
+	 * Returns a greater than criterion used for matching objects against a query
537
+	 *
538
+	 * @param string $propertyName The name of the property to compare against
539
+	 * @param mixed $operand The value to compare with
540
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
541
+	 * @api
542
+	 */
543
+	public function greaterThan($propertyName, $operand)
544
+	{
545
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand);
546
+	}
547
+
548
+	/**
549
+	 * Returns a greater than or equal criterion used for matching objects against a query
550
+	 *
551
+	 * @param string $propertyName The name of the property to compare against
552
+	 * @param mixed $operand The value to compare with
553
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
554
+	 * @api
555
+	 */
556
+	public function greaterThanOrEqual($propertyName, $operand)
557
+	{
558
+		return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand);
559
+	}
560
+
561
+	/**
562
+	 * Returns the query result count.
563
+	 *
564
+	 * @return integer The query result count
565
+	 * @api
566
+	 */
567
+	public function count()
568
+	{
569
+		/** @var VidiDbBackend $backend */
570
+		$backend = $this->getObjectManager()->get(VidiDbBackend::class, $this);
571
+		return $backend->countResult();
572
+	}
573
+
574
+	/**
575
+	 * Returns an "isEmpty" criterion used for matching objects against a query.
576
+	 * It matches if the multivalued property contains no values or is null.
577
+	 *
578
+	 * @param string $propertyName The name of the multivalued property to compare against
579
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
580
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
581
+	 * @api
582
+	 */
583
+	public function isEmpty($propertyName)
584
+	{
585
+		throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
586
+	}
587
+
588
+	/**
589
+	 * @return string
590
+	 */
591
+	public function getDistinct()
592
+	{
593
+		return $this->distinct;
594
+	}
595
+
596
+	/**
597
+	 * @param string $distinct
598
+	 * @return $this
599
+	 */
600
+	public function setDistinct($distinct)
601
+	{
602
+		$this->distinct = $distinct;
603
+		return $this;
604
+	}
605
+
606
+	/**
607
+	 * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage
608
+	 * backend (database).
609
+	 *
610
+	 * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement
611
+	 * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement.
612
+	 * @return QueryInterface
613
+	 */
614
+	public function statement($statement, array $parameters = array())
615
+	{
616
+		$this->statement = $this->qomFactory->statement($statement, $parameters);
617
+		return $this;
618
+	}
619
+
620
+	/**
621
+	 * Returns the statement of this query.
622
+	 *
623
+	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
624
+	 */
625
+	public function getStatement()
626
+	{
627
+		return $this->statement;
628
+	}
629
+
630
+	/**
631
+	 * Returns whether the current mode is Backend.
632
+	 *
633
+	 * @return bool
634
+	 */
635
+	protected function isBackendMode()
636
+	{
637
+		return TYPO3_MODE == 'BE';
638
+	}
639
+
640
+	/**
641
+	 * @return string
642
+	 */
643
+	public function getSourceFieldName()
644
+	{
645
+		return $this->sourceFieldName;
646
+	}
647
+
648
+	/**
649
+	 * @param string $sourceFieldName
650
+	 * @return $this
651
+	 */
652
+	public function setSourceFieldName($sourceFieldName)
653
+	{
654
+		$this->sourceFieldName = $sourceFieldName;
655
+		return $this;
656
+	}
657
+
658
+	/**
659
+	 * @return object|\TYPO3\CMS\Extbase\Object\ObjectManager
660
+	 */
661
+	protected function getObjectManager()
662
+	{
663
+		return GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
664
+	}
665 665
 
666 666
 }
Please login to merge, or discard this patch.
Classes/Backend/LanguageFileGenerator.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 class LanguageFileGenerator implements SingletonInterface
19 19
 {
20 20
 
21
-    protected $template = '<?xml version="1.0" encoding="UTF-8"?>
21
+	protected $template = '<?xml version="1.0" encoding="UTF-8"?>
22 22
 <xliff version="1.0">
23 23
 	<file source-language="en" datatype="plaintext" original="messages" date="" product-name="local lang module">
24 24
 		<header/>
@@ -36,53 +36,53 @@  discard block
 block discarded – undo
36 36
 	</file>
37 37
 </xliff>';
38 38
 
39
-    /**
40
-     * @param string $dataType
41
-     * @return string
42
-     */
43
-    public function generate($dataType)
44
-    {
45
-        $label = $dataType;
46
-        if (!empty($GLOBALS['TCA'][$dataType]['ctrl']['title'])) {
47
-            $label = $this->getLanguageService()->sL($GLOBALS['TCA'][$dataType]['ctrl']['title']);
48
-        }
39
+	/**
40
+	 * @param string $dataType
41
+	 * @return string
42
+	 */
43
+	public function generate($dataType)
44
+	{
45
+		$label = $dataType;
46
+		if (!empty($GLOBALS['TCA'][$dataType]['ctrl']['title'])) {
47
+			$label = $this->getLanguageService()->sL($GLOBALS['TCA'][$dataType]['ctrl']['title']);
48
+		}
49 49
 
50
-        // Generate language file.
51
-        $languageFile = $this->getLanguageFile($dataType);
52
-        $content = str_replace('{module_name}', $label, $this->template);
53
-        GeneralUtility::writeFileToTypo3tempDir($languageFile, $content);
50
+		// Generate language file.
51
+		$languageFile = $this->getLanguageFile($dataType);
52
+		$content = str_replace('{module_name}', $label, $this->template);
53
+		GeneralUtility::writeFileToTypo3tempDir($languageFile, $content);
54 54
 
55
-        return 'LLL:' . $languageFile;
56
-    }
55
+		return 'LLL:' . $languageFile;
56
+	}
57 57
 
58
-    /**
59
-     * @param $dataType
60
-     * @return string
61
-     */
62
-    protected function getLanguageFile($dataType)
63
-    {
64
-        return $this->getLanguageDirectory() . '/' . $dataType . '.xlf';
65
-    }
58
+	/**
59
+	 * @param $dataType
60
+	 * @return string
61
+	 */
62
+	protected function getLanguageFile($dataType)
63
+	{
64
+		return $this->getLanguageDirectory() . '/' . $dataType . '.xlf';
65
+	}
66 66
 
67
-    /**
68
-     * @return string
69
-     */
70
-    protected function getLanguageDirectory()
71
-    {
72
-        // Create language file dynamically
73
-        $languageDirectory = PATH_site . 'typo3temp/vidi';
74
-        if (!is_dir($languageDirectory)) {
75
-            GeneralUtility::mkdir($languageDirectory);
76
-        }
77
-        return $languageDirectory;
78
-    }
67
+	/**
68
+	 * @return string
69
+	 */
70
+	protected function getLanguageDirectory()
71
+	{
72
+		// Create language file dynamically
73
+		$languageDirectory = PATH_site . 'typo3temp/vidi';
74
+		if (!is_dir($languageDirectory)) {
75
+			GeneralUtility::mkdir($languageDirectory);
76
+		}
77
+		return $languageDirectory;
78
+	}
79 79
 
80
-    /**
81
-     * @return \TYPO3\CMS\Core\Localization\LanguageService
82
-     */
83
-    protected function getLanguageService()
84
-    {
85
-        return GeneralUtility::makeInstance(LanguageService::class, $GLOBALS['BE_USER']->uc['lang']);
86
-    }
80
+	/**
81
+	 * @return \TYPO3\CMS\Core\Localization\LanguageService
82
+	 */
83
+	protected function getLanguageService()
84
+	{
85
+		return GeneralUtility::makeInstance(LanguageService::class, $GLOBALS['BE_USER']->uc['lang']);
86
+	}
87 87
 
88 88
 }
Please login to merge, or discard this patch.