Completed
Push — master ( 4c54c0...a40619 )
by Fabien
10:04
created
Classes/View/Grid/Row.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@
 block discarded – undo
136 136
      * Flatten the localized structure to render the final value
137 137
      *
138 138
      * @param array $localizedStructure
139
-     * @return array
139
+     * @return string
140 140
      */
141 141
     protected function flattenStructure(array $localizedStructure)
142 142
     {
Please login to merge, or discard this patch.
Indentation   +617 added lines, -617 removed lines patch added patch discarded remove patch
@@ -29,622 +29,622 @@
 block discarded – undo
29 29
 class Row extends AbstractComponentView
30 30
 {
31 31
 
32
-    /**
33
-     * @var array
34
-     */
35
-    protected $columns = array();
36
-
37
-    /**
38
-     * Registry for storing variable values and speed up the processing.
39
-     *
40
-     * @var array
41
-     */
42
-    protected $variables = array();
43
-
44
-    /**
45
-     * @param array $columns
46
-     */
47
-    public function __construct($columns = array())
48
-    {
49
-        $this->columns = $columns;
50
-    }
51
-
52
-    /**
53
-     * Render a row to be displayed in the Grid given an Content Object.
54
-     *
55
-     * @param \Fab\Vidi\Domain\Model\Content $object
56
-     * @param int $rowIndex
57
-     * @return array
58
-     */
59
-    public function render(Content $object = NULL, $rowIndex = 0)
60
-    {
61
-
62
-        // Initialize returned array
63
-        $output = array();
64
-
65
-        foreach (Tca::grid()->getFields() as $fieldNameAndPath => $configuration) {
66
-
67
-            $value = ''; // default is empty at first.
68
-
69
-            $this->computeVariables($object, $fieldNameAndPath);
70
-
71
-            // Only compute the value if it is going to be shown in the Grid. Lost time otherwise!
72
-            if (in_array($fieldNameAndPath, $this->columns)) {
73
-
74
-                // Fetch value
75
-                if (Tca::grid()->hasRenderers($fieldNameAndPath)) {
76
-
77
-                    $value = '';
78
-                    $renderers = Tca::grid()->getRenderers($fieldNameAndPath);
79
-
80
-                    // if is relation has one
81
-                    foreach ($renderers as $rendererClassName => $rendererConfiguration) {
82
-
83
-                        // @todo when removing ColumnInterface in v2.0 + 2 version, GeneralUtility::makeInstance is not always necessary as it could be an object already
84
-                        /** @var $rendererObject \Fab\Vidi\Grid\ColumnRendererInterface */
85
-                        $rendererObject = GeneralUtility::makeInstance($rendererClassName);
86
-                        $value .= $rendererObject
87
-                            ->setObject($object)
88
-                            ->setFieldName($fieldNameAndPath)
89
-                            ->setRowIndex($rowIndex)
90
-                            ->setFieldConfiguration($configuration)
91
-                            ->setGridRendererConfiguration($rendererConfiguration)
92
-                            ->render();
93
-                    }
94
-                } else {
95
-                    $value = $this->resolveValue($object, $fieldNameAndPath);
96
-                    $value = $this->processValue($value, $object, $fieldNameAndPath); // post resolve processing.
97
-                }
98
-
99
-                // Possible formatting given by configuration. @see TCA['grid']
100
-                $value = $this->formatValue($value, $configuration);
101
-
102
-                // Here, there is the chance to further "decorate" the value for inline editing, localization, ...
103
-                if ($this->willBeEnriched()) {
104
-
105
-                    $localizedStructure = $this->initializeLocalizedStructure($value);
106
-
107
-                    if ($this->isEditable()) {
108
-                        $localizedStructure = $this->addEditableMarkup($localizedStructure);
109
-                    }
110
-
111
-                    if ($this->isLocalized()) {
112
-                        $localizedStructure = $this->addLocalizationMarkup($localizedStructure);
113
-                    }
114
-
115
-                    if ($this->hasIcon()) {
116
-                        $localizedStructure = $this->addSpriteIconMarkup($localizedStructure);
117
-                    }
118
-
119
-                    $value = $this->flattenStructure($localizedStructure);
120
-                }
121
-
122
-                // Final wrap given by configuration. @see TCA['grid']
123
-                $value = $this->wrapValue($value, $configuration);
124
-            }
125
-
126
-            $output[$this->getFieldName()] = $value;
127
-        }
128
-
129
-        $output['DT_RowId'] = 'row-' . $object->getUid();
130
-        $output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid());
131
-
132
-        return $output;
133
-    }
134
-
135
-    /**
136
-     * Flatten the localized structure to render the final value
137
-     *
138
-     * @param array $localizedStructure
139
-     * @return array
140
-     */
141
-    protected function flattenStructure(array $localizedStructure)
142
-    {
143
-
144
-        // Flatten the structure.
145
-        $value = '';
146
-        foreach ($localizedStructure as $structure) {
147
-            $value .= sprintf('<div class="%s">%s</div>',
148
-                $structure['status'] !== LocalizationStatus::LOCALIZED ? 'invisible' : '',
149
-                $structure['value']
150
-            );
151
-        }
152
-        return $value;
153
-    }
154
-
155
-    /**
156
-     * Store some often used variable values and speed up the processing.
157
-     *
158
-     * @param \Fab\Vidi\Domain\Model\Content $object
159
-     * @param string $fieldNameAndPath
160
-     * @return array
161
-     */
162
-    protected function computeVariables(Content $object, $fieldNameAndPath)
163
-    {
164
-        $this->variables = array();
165
-        $this->variables['dataType'] = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
166
-        $this->variables['fieldName'] = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
167
-        $this->variables['fieldNameAndPath'] = $fieldNameAndPath;
168
-        $this->variables['object'] = $object;
169
-    }
170
-
171
-    /**
172
-     * Tell whether the object will be decorated / wrapped such as
173
-     *
174
-     * @param string $value
175
-     * @return array
176
-     */
177
-    protected function initializeLocalizedStructure($value)
178
-    {
179
-
180
-        $localizedStructure[] = array(
181
-            'value' => empty($value) && $this->isEditable() ? $this->getEmptyValuePlaceholder() : $value,
182
-            'status' => empty($value) ? LocalizationStatus::EMPTY_VALUE : LocalizationStatus::LOCALIZED,
183
-            'language' => 0,
184
-            'languageFlag' => $defaultLanguage = $this->getLanguageService()->getDefaultFlag(),
185
-        );
186
-
187
-        if ($this->isLocalized()) {
188
-
189
-            foreach ($this->getLanguageService()->getLanguages() as $language) {
190
-
191
-                // Make sure the language is allowed for the current Backend User.
192
-                if ($this->isLanguageAllowedForBackendUser($language)) {
193
-
194
-                    $resolvedObject = $this->getResolvedObject();
195
-                    $fieldName = $this->getFieldName();
196
-
197
-                    if ($this->getLanguageService()->hasLocalization($resolvedObject, $language['uid'])) {
198
-                        $localizedValue = $this->getLanguageService()->getLocalizedFieldName($resolvedObject, $language['uid'], $fieldName);
199
-                        $status = LocalizationStatus::LOCALIZED;
200
-
201
-                        // Replace blank value by something more meaningful for the End User.
202
-                        if (empty($localizedValue)) {
203
-                            $status = LocalizationStatus::EMPTY_VALUE;
204
-                            $localizedValue = $this->isEditable() ? $this->getEmptyValuePlaceholder() : '';
205
-                        }
206
-                    } else {
207
-                        $localizedValue = sprintf('<a href="%s" style="color: black">%s</a>',
208
-                            $this->getLocalizedUri($language['uid']),
209
-                            $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:create_translation')
210
-                        );
211
-                        $status = LocalizationStatus::NOT_YET_LOCALIZED;
212
-                    }
213
-
214
-                    // Feed structure.
215
-                    $localizedStructure[] = array(
216
-                        'value' => $localizedValue,
217
-                        'status' => $status,
218
-                        'language' => (int)$language['uid'],
219
-                        'languageFlag' => $language['flag'],
220
-                    );
221
-                }
222
-            }
223
-        }
224
-
225
-        return $localizedStructure;
226
-    }
227
-
228
-    /**
229
-     * @param array $language
230
-     * @return bool
231
-     */
232
-    protected function isLanguageAllowedForBackendUser(array $language)
233
-    {
234
-        return $this->getBackendUser()->checkLanguageAccess($language['uid']);
235
-    }
236
-
237
-    /**
238
-     * Returns a placeholder when the value is empty.
239
-     *
240
-     * @return string
241
-     */
242
-    protected function getEmptyValuePlaceholder()
243
-    {
244
-        return sprintf('<i>%s</i>',
245
-            $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:start_editing')
246
-        );
247
-    }
248
-
249
-    /**
250
-     * Tell whether the object will be decorated (or wrapped) for inline editing, localization purpose.
251
-     *
252
-     * @return bool
253
-     */
254
-    protected function willBeEnriched()
255
-    {
256
-
257
-        $willBeEnriched = FALSE;
258
-
259
-        if ($this->fieldExists()) {
260
-            $willBeEnriched = $this->isEditable() || $this->hasIcon() || $this->isLocalized();
261
-        }
262
-
263
-        return $willBeEnriched;
264
-    }
265
-
266
-    /**
267
-     * Tell whether the field in the context will be prepended by an icon.
268
-     *
269
-     * @return bool
270
-     */
271
-    protected function hasIcon()
272
-    {
273
-        $dataType = $this->getDataType();
274
-        return Tca::table($dataType)->getLabelField() === $this->getFieldName();
275
-    }
276
-
277
-    /**
278
-     * Tell whether the field in the context will be prepended by an icon.
279
-     *
280
-     * @return bool
281
-     */
282
-    protected function isLocalized()
283
-    {
284
-        $object = $this->getObject();
285
-        $fieldName = $this->getFieldName();
286
-        $dataType = $this->getDataType();
287
-        $fieldNameAndPath = $this->getFieldNameAndPath();
288
-
289
-        return $this->getLanguageService()->hasLanguages()
290
-        && Tca::grid($object)->isLocalized($fieldNameAndPath)
291
-        && Tca::table($dataType)->field($fieldName)->isLocalized();
292
-    }
293
-
294
-    /**
295
-     * Add some markup to have the content editable in the Grid.
296
-     *
297
-     * @param array $localizedStructure
298
-     * @return array
299
-     */
300
-    protected function addEditableMarkup(array $localizedStructure)
301
-    {
302
-
303
-        $dataType = $this->getDataType();
304
-        $fieldName = $this->getFieldName();
305
-
306
-        foreach ($localizedStructure as $index => $structure) {
307
-            if ($structure['status'] !== LocalizationStatus::NOT_YET_LOCALIZED) {
308
-                $localizedStructure[$index]['value'] = sprintf('<span class="%s" data-language="%s">%s</span>',
309
-                    Tca::table($dataType)->field($fieldName)->isTextArea() ? 'editable-textarea' : 'editable-textfield',
310
-                    $structure['language'],
311
-                    $structure['value']
312
-                );
313
-            }
314
-        }
315
-        return $localizedStructure;
316
-    }
317
-
318
-    /**
319
-     * Add some markup related to the localization.
320
-     *
321
-     * @param array $localizedStructure
322
-     * @return array
323
-     */
324
-    protected function addLocalizationMarkup(array $localizedStructure)
325
-    {
326
-
327
-        foreach ($localizedStructure as $index => $structure) {
328
-
329
-            $localizedStructure[$index]['value'] = sprintf('<span>%s %s</span>',
330
-                empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL),
331
-                $structure['value']
332
-            );
333
-        }
334
-        return $localizedStructure;
335
-    }
336
-
337
-    /**
338
-     * Add some markup related to the prepended icon.
339
-     *
340
-     * @param array $localizedStructure
341
-     * @return array
342
-     */
343
-    protected function addSpriteIconMarkup(array $localizedStructure)
344
-    {
345
-
346
-        $object = $this->getObject();
347
-
348
-        foreach ($localizedStructure as $index => $structure) {
349
-
350
-            $recordData = array();
351
-
352
-            $enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime');
353
-            foreach ($enablesMethods as $enableMethod) {
354
-
355
-                $methodName = 'get' . $enableMethod . 'Field';
356
-
357
-                // Fetch possible hidden filed.
358
-                $enableField = Tca::table($object)->$methodName();
359
-                if ($enableField) {
360
-                    $recordData[$enableField] = $object[$enableField];
361
-                }
362
-            }
363
-
364
-            // Get Enable Fields of the object to render the sprite with overlays.
365
-            $localizedStructure[$index]['value'] = sprintf('%s %s',
366
-                $this->getIconFactory()->getIconForRecord($object->getDataType(), $recordData, Icon::SIZE_SMALL),
367
-                $structure['value']
368
-            );
369
-        }
370
-
371
-        return $localizedStructure;
372
-    }
373
-
374
-    /**
375
-     * Return whether the field given by the context is editable.
376
-     *
377
-     * @return boolean
378
-     */
379
-    protected function isEditable()
380
-    {
381
-        $fieldNameAndPath = $this->getFieldNameAndPath();
382
-        $dataType = $this->getDataType();
383
-        $fieldName = $this->getFieldName();
384
-
385
-        return Tca::grid()->isEditable($fieldNameAndPath)
386
-        && Tca::table($dataType)->hasField($fieldName)
387
-        && Tca::table($dataType)->field($fieldName)->hasNoRelation(); // relation are editable through Renderers only.
388
-    }
389
-
390
-    /**
391
-     * Return the appropriate URI to create the translation.
392
-     *
393
-     * @param int $language
394
-     * @return string
395
-     */
396
-    protected function getLocalizedUri($language)
397
-    {
398
-
399
-        // Transmit recursive selection parameter.
400
-        $parameterPrefix = $this->getModuleLoader()->getParameterPrefix();
401
-        $parameters = GeneralUtility::_GP($parameterPrefix);
402
-
403
-        $additionalParameters = array(
404
-            $this->getModuleLoader()->getParameterPrefix() => array(
405
-                'controller' => 'Content',
406
-                'action' => 'localize',
407
-                'format' => 'json',
408
-                'hasRecursiveSelection' => isset($parameters['hasRecursiveSelection']) ? (int)$parameters['hasRecursiveSelection'] : 0,
409
-                'fieldNameAndPath' => $this->getFieldNameAndPath(),
410
-                'language' => $language,
411
-                'matches' => array(
412
-                    'uid' => $this->getObject()->getUid(),
413
-                ),
414
-            ),
415
-        );
416
-
417
-        return $this->getModuleLoader()->getModuleUrl($additionalParameters);
418
-    }
419
-
420
-    /**
421
-     * Compute the value for the Content object according to a field name.
422
-     *
423
-     * @param \Fab\Vidi\Domain\Model\Content $object
424
-     * @param string $fieldNameAndPath
425
-     * @return string
426
-     */
427
-    protected function resolveValue(Content $object, $fieldNameAndPath)
428
-    {
429
-
430
-        // Get the first part of the field name and
431
-        $fieldName = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath);
432
-
433
-        $value = $object[$fieldName];
434
-
435
-        // Relation but contains no data.
436
-        if (is_array($value) && empty($value)) {
437
-            $value = '';
438
-        } elseif ($value instanceof Content) {
439
-
440
-            $fieldNameOfForeignTable = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
441
-
442
-            // TRUE means the field name does not contains a path. "title" vs "metadata.title"
443
-            // Fetch the default label
444
-            if ($fieldNameOfForeignTable === $fieldName) {
445
-                $foreignTable = Tca::table($object->getDataType())->field($fieldName)->getForeignTable();
446
-                $fieldNameOfForeignTable = Tca::table($foreignTable)->getLabelField();
447
-            }
448
-
449
-            $value = $object[$fieldName][$fieldNameOfForeignTable];
450
-        }
451
-
452
-        return $value;
453
-    }
454
-
455
-    /**
456
-     * Check whether a string contains HTML tags.
457
-     *
458
-     * @param string $string the content to be analyzed
459
-     * @return boolean
460
-     */
461
-    protected function hasHtml($string)
462
-    {
463
-        $result = FALSE;
464
-
465
-        // We compare the length of the string with html tags and without html tags.
466
-        if (strlen($string) != strlen(strip_tags($string))) {
467
-            $result = TRUE;
468
-        }
469
-        return $result;
470
-    }
471
-
472
-    /**
473
-     * Check whether a string contains potential XSS.
474
-     *
475
-     * @param string $string the content to be analyzed
476
-     * @return boolean
477
-     */
478
-    protected function isClean($string)
479
-    {
480
-
481
-        // @todo implement me!
482
-        $result = TRUE;
483
-        return $result;
484
-    }
485
-
486
-    /**
487
-     * Process the value
488
-     *
489
-     * @todo implement me as a processor chain to be cleaner implementation wise. Look out at the performance however!
490
-     *       e.g DefaultValueGridProcessor, TextAreaGridProcessor, ...
491
-     *
492
-     * @param string $value
493
-     * @param \Fab\Vidi\Domain\Model\Content $object
494
-     * @param string $fieldNameAndPath
495
-     * @return string
496
-     */
497
-    protected function processValue($value, Content $object, $fieldNameAndPath)
498
-    {
499
-
500
-        // Set default value if $field name correspond to the label of the table
501
-        $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
502
-        if (Tca::table($object->getDataType())->getLabelField() === $fieldName && empty($value)) {
503
-            $value = sprintf('[%s]', $this->getLabelService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', 1));
504
-        }
505
-
506
-        // Sanitize the value in case of "select" or "radio button".
507
-        if (is_scalar($value)) {
508
-            $fieldType = Tca::table($object->getDataType())->field($fieldNameAndPath)->getType();
509
-            if ($fieldType !== FieldType::TEXTAREA) {
510
-                $value = htmlspecialchars($value);
511
-            } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($value)) {
512
-                $value = htmlspecialchars($value); // Avoid bad surprise, converts characters to HTML.
513
-            } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($value)) {
514
-                $value = nl2br($value);
515
-            }
516
-        }
517
-
518
-        return $value;
519
-    }
520
-
521
-    /**
522
-     * Possible value formatting.
523
-     *
524
-     * @param string $value
525
-     * @param array $configuration
526
-     * @return string
527
-     */
528
-    protected function formatValue($value, array $configuration)
529
-    {
530
-        if (empty($configuration['format'])) {
531
-            return $value;
532
-        }
533
-        $className = $configuration['format'];
534
-
535
-        /** @var \Fab\Vidi\Formatter\FormatterInterface $formatter */
536
-        $formatter = GeneralUtility::makeInstance($className);
537
-        $value = $formatter->format($value);
538
-
539
-        return $value;
540
-    }
541
-
542
-    /**
543
-     * Possible value wrapping.
544
-     *
545
-     * @param string $value
546
-     * @param array $configuration
547
-     * @return string
548
-     */
549
-    protected function wrapValue($value, array $configuration)
550
-    {
551
-        if (!empty($configuration['wrap'])) {
552
-            $parts = explode('|', $configuration['wrap']);
553
-            $value = implode($value, $parts);
554
-        }
555
-        return $value;
556
-    }
557
-
558
-    /**
559
-     * Tell whether the field in the context really exists.
560
-     *
561
-     * @return bool
562
-     */
563
-    protected function fieldExists()
564
-    {
565
-        if (is_null($this->variables['hasField'])) {
566
-            $dataType = $this->getDataType();
567
-            $fieldName = $this->getFieldName();
568
-            $this->variables['hasField'] = Tca::table($dataType)->hasField($fieldName);
569
-        }
570
-        return $this->variables['hasField'];
571
-    }
572
-
573
-    /**
574
-     * @return string
575
-     */
576
-    protected function getDataType()
577
-    {
578
-        return $this->variables['dataType'];
579
-    }
580
-
581
-    /**
582
-     * @return string
583
-     */
584
-    protected function getFieldName()
585
-    {
586
-        return $this->variables['fieldName'];
587
-    }
588
-
589
-    /**
590
-     * @return string
591
-     */
592
-    protected function getFieldNameAndPath()
593
-    {
594
-        return $this->variables['fieldNameAndPath'];
595
-    }
596
-
597
-    /**
598
-     * @return Content
599
-     */
600
-    protected function getObject()
601
-    {
602
-        return $this->variables['object'];
603
-    }
604
-
605
-    /**
606
-     * @return Content
607
-     */
608
-    protected function getResolvedObject()
609
-    {
610
-        if (empty($this->variables['resolvedObject'])) {
611
-            $object = $this->getObject();
612
-            $fieldNameAndPath = $this->getFieldNameAndPath();
613
-            $this->variables['resolvedObject'] = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath);
614
-        }
615
-        return $this->variables['resolvedObject'];
616
-    }
617
-
618
-    /**
619
-     * @return \Fab\Vidi\Resolver\FieldPathResolver
620
-     */
621
-    protected function getFieldPathResolver()
622
-    {
623
-        return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
624
-    }
625
-
626
-    /**
627
-     * @return \Fab\Vidi\Resolver\ContentObjectResolver
628
-     */
629
-    protected function getContentObjectResolver()
630
-    {
631
-        return GeneralUtility::makeInstance('Fab\Vidi\Resolver\ContentObjectResolver');
632
-    }
633
-
634
-    /**
635
-     * @return \TYPO3\CMS\Lang\LanguageService
636
-     */
637
-    protected function getLabelService()
638
-    {
639
-        return $GLOBALS['LANG'];
640
-    }
641
-
642
-    /**
643
-     * @return LanguageService
644
-     */
645
-    protected function getLanguageService()
646
-    {
647
-        return GeneralUtility::makeInstance('Fab\Vidi\Language\LanguageService');
648
-    }
32
+	/**
33
+	 * @var array
34
+	 */
35
+	protected $columns = array();
36
+
37
+	/**
38
+	 * Registry for storing variable values and speed up the processing.
39
+	 *
40
+	 * @var array
41
+	 */
42
+	protected $variables = array();
43
+
44
+	/**
45
+	 * @param array $columns
46
+	 */
47
+	public function __construct($columns = array())
48
+	{
49
+		$this->columns = $columns;
50
+	}
51
+
52
+	/**
53
+	 * Render a row to be displayed in the Grid given an Content Object.
54
+	 *
55
+	 * @param \Fab\Vidi\Domain\Model\Content $object
56
+	 * @param int $rowIndex
57
+	 * @return array
58
+	 */
59
+	public function render(Content $object = NULL, $rowIndex = 0)
60
+	{
61
+
62
+		// Initialize returned array
63
+		$output = array();
64
+
65
+		foreach (Tca::grid()->getFields() as $fieldNameAndPath => $configuration) {
66
+
67
+			$value = ''; // default is empty at first.
68
+
69
+			$this->computeVariables($object, $fieldNameAndPath);
70
+
71
+			// Only compute the value if it is going to be shown in the Grid. Lost time otherwise!
72
+			if (in_array($fieldNameAndPath, $this->columns)) {
73
+
74
+				// Fetch value
75
+				if (Tca::grid()->hasRenderers($fieldNameAndPath)) {
76
+
77
+					$value = '';
78
+					$renderers = Tca::grid()->getRenderers($fieldNameAndPath);
79
+
80
+					// if is relation has one
81
+					foreach ($renderers as $rendererClassName => $rendererConfiguration) {
82
+
83
+						// @todo when removing ColumnInterface in v2.0 + 2 version, GeneralUtility::makeInstance is not always necessary as it could be an object already
84
+						/** @var $rendererObject \Fab\Vidi\Grid\ColumnRendererInterface */
85
+						$rendererObject = GeneralUtility::makeInstance($rendererClassName);
86
+						$value .= $rendererObject
87
+							->setObject($object)
88
+							->setFieldName($fieldNameAndPath)
89
+							->setRowIndex($rowIndex)
90
+							->setFieldConfiguration($configuration)
91
+							->setGridRendererConfiguration($rendererConfiguration)
92
+							->render();
93
+					}
94
+				} else {
95
+					$value = $this->resolveValue($object, $fieldNameAndPath);
96
+					$value = $this->processValue($value, $object, $fieldNameAndPath); // post resolve processing.
97
+				}
98
+
99
+				// Possible formatting given by configuration. @see TCA['grid']
100
+				$value = $this->formatValue($value, $configuration);
101
+
102
+				// Here, there is the chance to further "decorate" the value for inline editing, localization, ...
103
+				if ($this->willBeEnriched()) {
104
+
105
+					$localizedStructure = $this->initializeLocalizedStructure($value);
106
+
107
+					if ($this->isEditable()) {
108
+						$localizedStructure = $this->addEditableMarkup($localizedStructure);
109
+					}
110
+
111
+					if ($this->isLocalized()) {
112
+						$localizedStructure = $this->addLocalizationMarkup($localizedStructure);
113
+					}
114
+
115
+					if ($this->hasIcon()) {
116
+						$localizedStructure = $this->addSpriteIconMarkup($localizedStructure);
117
+					}
118
+
119
+					$value = $this->flattenStructure($localizedStructure);
120
+				}
121
+
122
+				// Final wrap given by configuration. @see TCA['grid']
123
+				$value = $this->wrapValue($value, $configuration);
124
+			}
125
+
126
+			$output[$this->getFieldName()] = $value;
127
+		}
128
+
129
+		$output['DT_RowId'] = 'row-' . $object->getUid();
130
+		$output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid());
131
+
132
+		return $output;
133
+	}
134
+
135
+	/**
136
+	 * Flatten the localized structure to render the final value
137
+	 *
138
+	 * @param array $localizedStructure
139
+	 * @return array
140
+	 */
141
+	protected function flattenStructure(array $localizedStructure)
142
+	{
143
+
144
+		// Flatten the structure.
145
+		$value = '';
146
+		foreach ($localizedStructure as $structure) {
147
+			$value .= sprintf('<div class="%s">%s</div>',
148
+				$structure['status'] !== LocalizationStatus::LOCALIZED ? 'invisible' : '',
149
+				$structure['value']
150
+			);
151
+		}
152
+		return $value;
153
+	}
154
+
155
+	/**
156
+	 * Store some often used variable values and speed up the processing.
157
+	 *
158
+	 * @param \Fab\Vidi\Domain\Model\Content $object
159
+	 * @param string $fieldNameAndPath
160
+	 * @return array
161
+	 */
162
+	protected function computeVariables(Content $object, $fieldNameAndPath)
163
+	{
164
+		$this->variables = array();
165
+		$this->variables['dataType'] = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
166
+		$this->variables['fieldName'] = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
167
+		$this->variables['fieldNameAndPath'] = $fieldNameAndPath;
168
+		$this->variables['object'] = $object;
169
+	}
170
+
171
+	/**
172
+	 * Tell whether the object will be decorated / wrapped such as
173
+	 *
174
+	 * @param string $value
175
+	 * @return array
176
+	 */
177
+	protected function initializeLocalizedStructure($value)
178
+	{
179
+
180
+		$localizedStructure[] = array(
181
+			'value' => empty($value) && $this->isEditable() ? $this->getEmptyValuePlaceholder() : $value,
182
+			'status' => empty($value) ? LocalizationStatus::EMPTY_VALUE : LocalizationStatus::LOCALIZED,
183
+			'language' => 0,
184
+			'languageFlag' => $defaultLanguage = $this->getLanguageService()->getDefaultFlag(),
185
+		);
186
+
187
+		if ($this->isLocalized()) {
188
+
189
+			foreach ($this->getLanguageService()->getLanguages() as $language) {
190
+
191
+				// Make sure the language is allowed for the current Backend User.
192
+				if ($this->isLanguageAllowedForBackendUser($language)) {
193
+
194
+					$resolvedObject = $this->getResolvedObject();
195
+					$fieldName = $this->getFieldName();
196
+
197
+					if ($this->getLanguageService()->hasLocalization($resolvedObject, $language['uid'])) {
198
+						$localizedValue = $this->getLanguageService()->getLocalizedFieldName($resolvedObject, $language['uid'], $fieldName);
199
+						$status = LocalizationStatus::LOCALIZED;
200
+
201
+						// Replace blank value by something more meaningful for the End User.
202
+						if (empty($localizedValue)) {
203
+							$status = LocalizationStatus::EMPTY_VALUE;
204
+							$localizedValue = $this->isEditable() ? $this->getEmptyValuePlaceholder() : '';
205
+						}
206
+					} else {
207
+						$localizedValue = sprintf('<a href="%s" style="color: black">%s</a>',
208
+							$this->getLocalizedUri($language['uid']),
209
+							$this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:create_translation')
210
+						);
211
+						$status = LocalizationStatus::NOT_YET_LOCALIZED;
212
+					}
213
+
214
+					// Feed structure.
215
+					$localizedStructure[] = array(
216
+						'value' => $localizedValue,
217
+						'status' => $status,
218
+						'language' => (int)$language['uid'],
219
+						'languageFlag' => $language['flag'],
220
+					);
221
+				}
222
+			}
223
+		}
224
+
225
+		return $localizedStructure;
226
+	}
227
+
228
+	/**
229
+	 * @param array $language
230
+	 * @return bool
231
+	 */
232
+	protected function isLanguageAllowedForBackendUser(array $language)
233
+	{
234
+		return $this->getBackendUser()->checkLanguageAccess($language['uid']);
235
+	}
236
+
237
+	/**
238
+	 * Returns a placeholder when the value is empty.
239
+	 *
240
+	 * @return string
241
+	 */
242
+	protected function getEmptyValuePlaceholder()
243
+	{
244
+		return sprintf('<i>%s</i>',
245
+			$this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:start_editing')
246
+		);
247
+	}
248
+
249
+	/**
250
+	 * Tell whether the object will be decorated (or wrapped) for inline editing, localization purpose.
251
+	 *
252
+	 * @return bool
253
+	 */
254
+	protected function willBeEnriched()
255
+	{
256
+
257
+		$willBeEnriched = FALSE;
258
+
259
+		if ($this->fieldExists()) {
260
+			$willBeEnriched = $this->isEditable() || $this->hasIcon() || $this->isLocalized();
261
+		}
262
+
263
+		return $willBeEnriched;
264
+	}
265
+
266
+	/**
267
+	 * Tell whether the field in the context will be prepended by an icon.
268
+	 *
269
+	 * @return bool
270
+	 */
271
+	protected function hasIcon()
272
+	{
273
+		$dataType = $this->getDataType();
274
+		return Tca::table($dataType)->getLabelField() === $this->getFieldName();
275
+	}
276
+
277
+	/**
278
+	 * Tell whether the field in the context will be prepended by an icon.
279
+	 *
280
+	 * @return bool
281
+	 */
282
+	protected function isLocalized()
283
+	{
284
+		$object = $this->getObject();
285
+		$fieldName = $this->getFieldName();
286
+		$dataType = $this->getDataType();
287
+		$fieldNameAndPath = $this->getFieldNameAndPath();
288
+
289
+		return $this->getLanguageService()->hasLanguages()
290
+		&& Tca::grid($object)->isLocalized($fieldNameAndPath)
291
+		&& Tca::table($dataType)->field($fieldName)->isLocalized();
292
+	}
293
+
294
+	/**
295
+	 * Add some markup to have the content editable in the Grid.
296
+	 *
297
+	 * @param array $localizedStructure
298
+	 * @return array
299
+	 */
300
+	protected function addEditableMarkup(array $localizedStructure)
301
+	{
302
+
303
+		$dataType = $this->getDataType();
304
+		$fieldName = $this->getFieldName();
305
+
306
+		foreach ($localizedStructure as $index => $structure) {
307
+			if ($structure['status'] !== LocalizationStatus::NOT_YET_LOCALIZED) {
308
+				$localizedStructure[$index]['value'] = sprintf('<span class="%s" data-language="%s">%s</span>',
309
+					Tca::table($dataType)->field($fieldName)->isTextArea() ? 'editable-textarea' : 'editable-textfield',
310
+					$structure['language'],
311
+					$structure['value']
312
+				);
313
+			}
314
+		}
315
+		return $localizedStructure;
316
+	}
317
+
318
+	/**
319
+	 * Add some markup related to the localization.
320
+	 *
321
+	 * @param array $localizedStructure
322
+	 * @return array
323
+	 */
324
+	protected function addLocalizationMarkup(array $localizedStructure)
325
+	{
326
+
327
+		foreach ($localizedStructure as $index => $structure) {
328
+
329
+			$localizedStructure[$index]['value'] = sprintf('<span>%s %s</span>',
330
+				empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL),
331
+				$structure['value']
332
+			);
333
+		}
334
+		return $localizedStructure;
335
+	}
336
+
337
+	/**
338
+	 * Add some markup related to the prepended icon.
339
+	 *
340
+	 * @param array $localizedStructure
341
+	 * @return array
342
+	 */
343
+	protected function addSpriteIconMarkup(array $localizedStructure)
344
+	{
345
+
346
+		$object = $this->getObject();
347
+
348
+		foreach ($localizedStructure as $index => $structure) {
349
+
350
+			$recordData = array();
351
+
352
+			$enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime');
353
+			foreach ($enablesMethods as $enableMethod) {
354
+
355
+				$methodName = 'get' . $enableMethod . 'Field';
356
+
357
+				// Fetch possible hidden filed.
358
+				$enableField = Tca::table($object)->$methodName();
359
+				if ($enableField) {
360
+					$recordData[$enableField] = $object[$enableField];
361
+				}
362
+			}
363
+
364
+			// Get Enable Fields of the object to render the sprite with overlays.
365
+			$localizedStructure[$index]['value'] = sprintf('%s %s',
366
+				$this->getIconFactory()->getIconForRecord($object->getDataType(), $recordData, Icon::SIZE_SMALL),
367
+				$structure['value']
368
+			);
369
+		}
370
+
371
+		return $localizedStructure;
372
+	}
373
+
374
+	/**
375
+	 * Return whether the field given by the context is editable.
376
+	 *
377
+	 * @return boolean
378
+	 */
379
+	protected function isEditable()
380
+	{
381
+		$fieldNameAndPath = $this->getFieldNameAndPath();
382
+		$dataType = $this->getDataType();
383
+		$fieldName = $this->getFieldName();
384
+
385
+		return Tca::grid()->isEditable($fieldNameAndPath)
386
+		&& Tca::table($dataType)->hasField($fieldName)
387
+		&& Tca::table($dataType)->field($fieldName)->hasNoRelation(); // relation are editable through Renderers only.
388
+	}
389
+
390
+	/**
391
+	 * Return the appropriate URI to create the translation.
392
+	 *
393
+	 * @param int $language
394
+	 * @return string
395
+	 */
396
+	protected function getLocalizedUri($language)
397
+	{
398
+
399
+		// Transmit recursive selection parameter.
400
+		$parameterPrefix = $this->getModuleLoader()->getParameterPrefix();
401
+		$parameters = GeneralUtility::_GP($parameterPrefix);
402
+
403
+		$additionalParameters = array(
404
+			$this->getModuleLoader()->getParameterPrefix() => array(
405
+				'controller' => 'Content',
406
+				'action' => 'localize',
407
+				'format' => 'json',
408
+				'hasRecursiveSelection' => isset($parameters['hasRecursiveSelection']) ? (int)$parameters['hasRecursiveSelection'] : 0,
409
+				'fieldNameAndPath' => $this->getFieldNameAndPath(),
410
+				'language' => $language,
411
+				'matches' => array(
412
+					'uid' => $this->getObject()->getUid(),
413
+				),
414
+			),
415
+		);
416
+
417
+		return $this->getModuleLoader()->getModuleUrl($additionalParameters);
418
+	}
419
+
420
+	/**
421
+	 * Compute the value for the Content object according to a field name.
422
+	 *
423
+	 * @param \Fab\Vidi\Domain\Model\Content $object
424
+	 * @param string $fieldNameAndPath
425
+	 * @return string
426
+	 */
427
+	protected function resolveValue(Content $object, $fieldNameAndPath)
428
+	{
429
+
430
+		// Get the first part of the field name and
431
+		$fieldName = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath);
432
+
433
+		$value = $object[$fieldName];
434
+
435
+		// Relation but contains no data.
436
+		if (is_array($value) && empty($value)) {
437
+			$value = '';
438
+		} elseif ($value instanceof Content) {
439
+
440
+			$fieldNameOfForeignTable = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
441
+
442
+			// TRUE means the field name does not contains a path. "title" vs "metadata.title"
443
+			// Fetch the default label
444
+			if ($fieldNameOfForeignTable === $fieldName) {
445
+				$foreignTable = Tca::table($object->getDataType())->field($fieldName)->getForeignTable();
446
+				$fieldNameOfForeignTable = Tca::table($foreignTable)->getLabelField();
447
+			}
448
+
449
+			$value = $object[$fieldName][$fieldNameOfForeignTable];
450
+		}
451
+
452
+		return $value;
453
+	}
454
+
455
+	/**
456
+	 * Check whether a string contains HTML tags.
457
+	 *
458
+	 * @param string $string the content to be analyzed
459
+	 * @return boolean
460
+	 */
461
+	protected function hasHtml($string)
462
+	{
463
+		$result = FALSE;
464
+
465
+		// We compare the length of the string with html tags and without html tags.
466
+		if (strlen($string) != strlen(strip_tags($string))) {
467
+			$result = TRUE;
468
+		}
469
+		return $result;
470
+	}
471
+
472
+	/**
473
+	 * Check whether a string contains potential XSS.
474
+	 *
475
+	 * @param string $string the content to be analyzed
476
+	 * @return boolean
477
+	 */
478
+	protected function isClean($string)
479
+	{
480
+
481
+		// @todo implement me!
482
+		$result = TRUE;
483
+		return $result;
484
+	}
485
+
486
+	/**
487
+	 * Process the value
488
+	 *
489
+	 * @todo implement me as a processor chain to be cleaner implementation wise. Look out at the performance however!
490
+	 *       e.g DefaultValueGridProcessor, TextAreaGridProcessor, ...
491
+	 *
492
+	 * @param string $value
493
+	 * @param \Fab\Vidi\Domain\Model\Content $object
494
+	 * @param string $fieldNameAndPath
495
+	 * @return string
496
+	 */
497
+	protected function processValue($value, Content $object, $fieldNameAndPath)
498
+	{
499
+
500
+		// Set default value if $field name correspond to the label of the table
501
+		$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
502
+		if (Tca::table($object->getDataType())->getLabelField() === $fieldName && empty($value)) {
503
+			$value = sprintf('[%s]', $this->getLabelService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', 1));
504
+		}
505
+
506
+		// Sanitize the value in case of "select" or "radio button".
507
+		if (is_scalar($value)) {
508
+			$fieldType = Tca::table($object->getDataType())->field($fieldNameAndPath)->getType();
509
+			if ($fieldType !== FieldType::TEXTAREA) {
510
+				$value = htmlspecialchars($value);
511
+			} elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($value)) {
512
+				$value = htmlspecialchars($value); // Avoid bad surprise, converts characters to HTML.
513
+			} elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($value)) {
514
+				$value = nl2br($value);
515
+			}
516
+		}
517
+
518
+		return $value;
519
+	}
520
+
521
+	/**
522
+	 * Possible value formatting.
523
+	 *
524
+	 * @param string $value
525
+	 * @param array $configuration
526
+	 * @return string
527
+	 */
528
+	protected function formatValue($value, array $configuration)
529
+	{
530
+		if (empty($configuration['format'])) {
531
+			return $value;
532
+		}
533
+		$className = $configuration['format'];
534
+
535
+		/** @var \Fab\Vidi\Formatter\FormatterInterface $formatter */
536
+		$formatter = GeneralUtility::makeInstance($className);
537
+		$value = $formatter->format($value);
538
+
539
+		return $value;
540
+	}
541
+
542
+	/**
543
+	 * Possible value wrapping.
544
+	 *
545
+	 * @param string $value
546
+	 * @param array $configuration
547
+	 * @return string
548
+	 */
549
+	protected function wrapValue($value, array $configuration)
550
+	{
551
+		if (!empty($configuration['wrap'])) {
552
+			$parts = explode('|', $configuration['wrap']);
553
+			$value = implode($value, $parts);
554
+		}
555
+		return $value;
556
+	}
557
+
558
+	/**
559
+	 * Tell whether the field in the context really exists.
560
+	 *
561
+	 * @return bool
562
+	 */
563
+	protected function fieldExists()
564
+	{
565
+		if (is_null($this->variables['hasField'])) {
566
+			$dataType = $this->getDataType();
567
+			$fieldName = $this->getFieldName();
568
+			$this->variables['hasField'] = Tca::table($dataType)->hasField($fieldName);
569
+		}
570
+		return $this->variables['hasField'];
571
+	}
572
+
573
+	/**
574
+	 * @return string
575
+	 */
576
+	protected function getDataType()
577
+	{
578
+		return $this->variables['dataType'];
579
+	}
580
+
581
+	/**
582
+	 * @return string
583
+	 */
584
+	protected function getFieldName()
585
+	{
586
+		return $this->variables['fieldName'];
587
+	}
588
+
589
+	/**
590
+	 * @return string
591
+	 */
592
+	protected function getFieldNameAndPath()
593
+	{
594
+		return $this->variables['fieldNameAndPath'];
595
+	}
596
+
597
+	/**
598
+	 * @return Content
599
+	 */
600
+	protected function getObject()
601
+	{
602
+		return $this->variables['object'];
603
+	}
604
+
605
+	/**
606
+	 * @return Content
607
+	 */
608
+	protected function getResolvedObject()
609
+	{
610
+		if (empty($this->variables['resolvedObject'])) {
611
+			$object = $this->getObject();
612
+			$fieldNameAndPath = $this->getFieldNameAndPath();
613
+			$this->variables['resolvedObject'] = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath);
614
+		}
615
+		return $this->variables['resolvedObject'];
616
+	}
617
+
618
+	/**
619
+	 * @return \Fab\Vidi\Resolver\FieldPathResolver
620
+	 */
621
+	protected function getFieldPathResolver()
622
+	{
623
+		return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
624
+	}
625
+
626
+	/**
627
+	 * @return \Fab\Vidi\Resolver\ContentObjectResolver
628
+	 */
629
+	protected function getContentObjectResolver()
630
+	{
631
+		return GeneralUtility::makeInstance('Fab\Vidi\Resolver\ContentObjectResolver');
632
+	}
633
+
634
+	/**
635
+	 * @return \TYPO3\CMS\Lang\LanguageService
636
+	 */
637
+	protected function getLabelService()
638
+	{
639
+		return $GLOBALS['LANG'];
640
+	}
641
+
642
+	/**
643
+	 * @return LanguageService
644
+	 */
645
+	protected function getLanguageService()
646
+	{
647
+		return GeneralUtility::makeInstance('Fab\Vidi\Language\LanguageService');
648
+	}
649 649
 
650 650
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
             $output[$this->getFieldName()] = $value;
127 127
         }
128 128
 
129
-        $output['DT_RowId'] = 'row-' . $object->getUid();
129
+        $output['DT_RowId'] = 'row-'.$object->getUid();
130 130
         $output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid());
131 131
 
132 132
         return $output;
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
         foreach ($localizedStructure as $index => $structure) {
328 328
 
329 329
             $localizedStructure[$index]['value'] = sprintf('<span>%s %s</span>',
330
-                empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL),
330
+                empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-'.$structure['languageFlag'], Icon::SIZE_SMALL),
331 331
                 $structure['value']
332 332
             );
333 333
         }
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
             $enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime');
353 353
             foreach ($enablesMethods as $enableMethod) {
354 354
 
355
-                $methodName = 'get' . $enableMethod . 'Field';
355
+                $methodName = 'get'.$enableMethod.'Field';
356 356
 
357 357
                 // Fetch possible hidden filed.
358 358
                 $enableField = Tca::table($object)->$methodName();
Please login to merge, or discard this patch.
Classes/Persistence/PagerObjectFactory.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -23,48 +23,48 @@
 block discarded – undo
23 23
 class PagerObjectFactory implements SingletonInterface
24 24
 {
25 25
 
26
-    /**
27
-     * Gets a singleton instance of this class.
28
-     *
29
-     * @return \Fab\Vidi\Persistence\PagerObjectFactory
30
-     */
31
-    static public function getInstance()
32
-    {
33
-        return GeneralUtility::makeInstance('Fab\Vidi\Persistence\PagerObjectFactory');
34
-    }
26
+	/**
27
+	 * Gets a singleton instance of this class.
28
+	 *
29
+	 * @return \Fab\Vidi\Persistence\PagerObjectFactory
30
+	 */
31
+	static public function getInstance()
32
+	{
33
+		return GeneralUtility::makeInstance('Fab\Vidi\Persistence\PagerObjectFactory');
34
+	}
35 35
 
36
-    /**
37
-     * Returns a pager object.
38
-     *
39
-     * @return \Fab\Vidi\Persistence\Pager
40
-     */
41
-    public function getPager()
42
-    {
36
+	/**
37
+	 * Returns a pager object.
38
+	 *
39
+	 * @return \Fab\Vidi\Persistence\Pager
40
+	 */
41
+	public function getPager()
42
+	{
43 43
 
44
-        /** @var $pager \Fab\Vidi\Persistence\Pager */
45
-        $pager = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Pager');
44
+		/** @var $pager \Fab\Vidi\Persistence\Pager */
45
+		$pager = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Pager');
46 46
 
47
-        // Set items per page
48
-        if (GeneralUtility::_GET('length') !== NULL) {
49
-            $limit = (int)GeneralUtility::_GET('length');
50
-            $pager->setLimit($limit);
51
-        }
47
+		// Set items per page
48
+		if (GeneralUtility::_GET('length') !== NULL) {
49
+			$limit = (int)GeneralUtility::_GET('length');
50
+			$pager->setLimit($limit);
51
+		}
52 52
 
53
-        // Set offset
54
-        $offset = 0;
55
-        if (GeneralUtility::_GET('start') !== NULL) {
56
-            $offset = (int)GeneralUtility::_GET('start');
57
-        }
58
-        $pager->setOffset($offset);
53
+		// Set offset
54
+		$offset = 0;
55
+		if (GeneralUtility::_GET('start') !== NULL) {
56
+			$offset = (int)GeneralUtility::_GET('start');
57
+		}
58
+		$pager->setOffset($offset);
59 59
 
60
-        // set page
61
-        $page = 1;
62
-        if ($pager->getLimit() > 0) {
63
-            $page = round($pager->getOffset() / $pager->getLimit());
64
-        }
65
-        $pager->setPage($page);
60
+		// set page
61
+		$page = 1;
62
+		if ($pager->getLimit() > 0) {
63
+			$page = round($pager->getOffset() / $pager->getLimit());
64
+		}
65
+		$pager->setPage($page);
66 66
 
67
-        return $pager;
68
-    }
67
+		return $pager;
68
+	}
69 69
 
70 70
 }
Please login to merge, or discard this patch.
Classes/Persistence/ResultSetStorage.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -22,32 +22,32 @@
 block discarded – undo
22 22
 class ResultSetStorage implements SingletonInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    protected $resultSets = array();
25
+	/**
26
+	 * @var array
27
+	 */
28
+	protected $resultSets = array();
29 29
 
30
-    /**
31
-     * @param string $querySignature
32
-     * @return array
33
-     */
34
-    public function get($querySignature)
35
-    {
36
-        $resultSet = NULL;
37
-        if (isset($this->resultSets[$querySignature])) {
38
-            $resultSet = $this->resultSets[$querySignature];
39
-        }
40
-        return $resultSet;
41
-    }
30
+	/**
31
+	 * @param string $querySignature
32
+	 * @return array
33
+	 */
34
+	public function get($querySignature)
35
+	{
36
+		$resultSet = NULL;
37
+		if (isset($this->resultSets[$querySignature])) {
38
+			$resultSet = $this->resultSets[$querySignature];
39
+		}
40
+		return $resultSet;
41
+	}
42 42
 
43
-    /**
44
-     * @param $querySignature
45
-     * @param array $resultSet
46
-     * @internal param array $resultSets
47
-     */
48
-    public function set($querySignature, array $resultSet)
49
-    {
50
-        $this->resultSets[$querySignature] = $resultSet;
51
-    }
43
+	/**
44
+	 * @param $querySignature
45
+	 * @param array $resultSet
46
+	 * @internal param array $resultSets
47
+	 */
48
+	public function set($querySignature, array $resultSet)
49
+	{
50
+		$this->resultSets[$querySignature] = $resultSet;
51
+	}
52 52
 
53 53
 }
Please login to merge, or discard this patch.
Classes/Persistence/Order.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -20,45 +20,45 @@
 block discarded – undo
20 20
 class Order
21 21
 {
22 22
 
23
-    /**
24
-     * The orderings
25
-     *
26
-     * @var array
27
-     */
28
-    protected $orderings = array();
23
+	/**
24
+	 * The orderings
25
+	 *
26
+	 * @var array
27
+	 */
28
+	protected $orderings = array();
29 29
 
30
-    /**
31
-     * Constructs a new Order
32
-     *
33
-     * @para array $orders
34
-     * @param array $orders
35
-     */
36
-    public function __construct($orders = array())
37
-    {
38
-        foreach ($orders as $order => $direction) {
39
-            $this->addOrdering($order, $direction);
40
-        }
41
-    }
30
+	/**
31
+	 * Constructs a new Order
32
+	 *
33
+	 * @para array $orders
34
+	 * @param array $orders
35
+	 */
36
+	public function __construct($orders = array())
37
+	{
38
+		foreach ($orders as $order => $direction) {
39
+			$this->addOrdering($order, $direction);
40
+		}
41
+	}
42 42
 
43
-    /**
44
-     * Add ordering
45
-     *
46
-     * @param string $order The order
47
-     * @param string $direction ASC / DESC
48
-     * @return void
49
-     */
50
-    public function addOrdering($order, $direction)
51
-    {
52
-        $this->orderings[$order] = $direction;
53
-    }
43
+	/**
44
+	 * Add ordering
45
+	 *
46
+	 * @param string $order The order
47
+	 * @param string $direction ASC / DESC
48
+	 * @return void
49
+	 */
50
+	public function addOrdering($order, $direction)
51
+	{
52
+		$this->orderings[$order] = $direction;
53
+	}
54 54
 
55
-    /**
56
-     * Returns the order
57
-     *
58
-     * @return array The order
59
-     */
60
-    public function getOrderings()
61
-    {
62
-        return $this->orderings;
63
-    }
55
+	/**
56
+	 * Returns the order
57
+	 *
58
+	 * @return array The order
59
+	 */
60
+	public function getOrderings()
61
+	{
62
+		return $this->orderings;
63
+	}
64 64
 }
Please login to merge, or discard this patch.
Classes/Persistence/QuerySettings.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -24,19 +24,19 @@
 block discarded – undo
24 24
 class QuerySettings extends Typo3QuerySettings
25 25
 {
26 26
 
27
-    /**
28
-     * Flag if the storage page should be respected for the query.
29
-     *
30
-     * @var boolean
31
-     */
32
-    protected $respectStoragePage = FALSE;
27
+	/**
28
+	 * Flag if the storage page should be respected for the query.
29
+	 *
30
+	 * @var boolean
31
+	 */
32
+	protected $respectStoragePage = FALSE;
33 33
 
34
-    /**
35
-     * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
36
-     * initializeObject is responsible for handling that.
37
-     */
38
-    public function initializeObject()
39
-    {
40
-        parent::initializeObject();
41
-    }
34
+	/**
35
+	 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
36
+	 * initializeObject is responsible for handling that.
37
+	 */
38
+	public function initializeObject()
39
+	{
40
+		parent::initializeObject();
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Classes/Persistence/Pager.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -22,168 +22,168 @@
 block discarded – undo
22 22
 class Pager
23 23
 {
24 24
 
25
-    /**
26
-     * Total amount of entries
27
-     *
28
-     * @var integer
29
-     */
30
-    protected $count;
31
-
32
-    /**
33
-     * Current offset
34
-     *
35
-     * @var integer
36
-     */
37
-    protected $offset;
38
-
39
-    /**
40
-     * Current page index
41
-     *
42
-     * @var integer
43
-     */
44
-    protected $page;
45
-
46
-    /**
47
-     * Number of items per page
48
-     *
49
-     * @var integer
50
-     */
51
-    protected $limit = 10;
52
-
53
-    /**
54
-     * Constructs a new Pager
55
-     */
56
-    public function __construct()
57
-    {
58
-        $this->page = 1;
59
-    }
60
-
61
-    /**
62
-     * Returns the total amount of entries
63
-     *
64
-     * @return int
65
-     */
66
-    public function getCount()
67
-    {
68
-        return $this->count;
69
-    }
70
-
71
-    /**
72
-     * Sets the total amount of entries
73
-     *
74
-     * @param int $count
75
-     */
76
-    public function setCount($count)
77
-    {
78
-        $this->count = $count;
79
-    }
80
-
81
-    /**
82
-     * Returns the current page index
83
-     *
84
-     * @return int
85
-     */
86
-    public function getPage()
87
-    {
88
-        return $this->page;
89
-    }
90
-
91
-    /**
92
-     * Sets the current page index
93
-     *
94
-     * @param int $page
95
-     */
96
-    public function setPage($page)
97
-    {
98
-        $this->page = $page;
99
-    }
100
-
101
-    /**
102
-     * Returns the current limit index
103
-     *
104
-     * @return int
105
-     */
106
-    public function getLimit()
107
-    {
108
-        return $this->limit;
109
-    }
110
-
111
-    /**
112
-     * Sets the current limit index
113
-     *
114
-     * @param int $limit
115
-     */
116
-    public function setLimit($limit)
117
-    {
118
-        $this->limit = $limit;
119
-    }
120
-
121
-    /**
122
-     * @return Array Items to display
123
-     */
124
-    public function getDisplayItems()
125
-    {
126
-        $last = $this->getLastPage();
127
-        if ($last == 1) {
128
-            return null;
129
-        }
130
-        $values = Array();
131
-        for ($i = 1; $i <= $last; $i++) {
132
-            $values[] = Array('key' => $i, 'value' => $i);
133
-        }
134
-        return $values;
135
-    }
136
-
137
-    /**
138
-     * @return int The last page index
139
-     */
140
-    public function getLastPage()
141
-    {
142
-        $last = intval($this->count / $this->limit);
143
-        if ($this->count % $this->limit > 0) {
144
-            $last++;
145
-        }
146
-        return $last;
147
-    }
148
-
149
-    /**
150
-     * @return int The previous page index. Minimum value is 1
151
-     */
152
-    public function getPreviousPage()
153
-    {
154
-        $prev = $this->page - 1;
155
-        if ($prev < 1) {
156
-            $prev = 1;
157
-        }
158
-        return $prev;
159
-    }
160
-
161
-    /**
162
-     * @return int The next page index. Maximum valus is the last page
163
-     */
164
-    public function getNextPage()
165
-    {
166
-        $next = $this->page + 1;
167
-        $last = $this->getLastPage();
168
-        if ($next > $last) {
169
-            $next = $last;
170
-        }
171
-        return $next;
172
-    }
173
-
174
-    /**
175
-     * @return int
176
-     */
177
-    public function getOffset()
178
-    {
179
-        return $this->offset;
180
-    }
181
-
182
-    /**
183
-     * @param int $offset
184
-     */
185
-    public function setOffset($offset)
186
-    {
187
-        $this->offset = $offset;
188
-    }
25
+	/**
26
+	 * Total amount of entries
27
+	 *
28
+	 * @var integer
29
+	 */
30
+	protected $count;
31
+
32
+	/**
33
+	 * Current offset
34
+	 *
35
+	 * @var integer
36
+	 */
37
+	protected $offset;
38
+
39
+	/**
40
+	 * Current page index
41
+	 *
42
+	 * @var integer
43
+	 */
44
+	protected $page;
45
+
46
+	/**
47
+	 * Number of items per page
48
+	 *
49
+	 * @var integer
50
+	 */
51
+	protected $limit = 10;
52
+
53
+	/**
54
+	 * Constructs a new Pager
55
+	 */
56
+	public function __construct()
57
+	{
58
+		$this->page = 1;
59
+	}
60
+
61
+	/**
62
+	 * Returns the total amount of entries
63
+	 *
64
+	 * @return int
65
+	 */
66
+	public function getCount()
67
+	{
68
+		return $this->count;
69
+	}
70
+
71
+	/**
72
+	 * Sets the total amount of entries
73
+	 *
74
+	 * @param int $count
75
+	 */
76
+	public function setCount($count)
77
+	{
78
+		$this->count = $count;
79
+	}
80
+
81
+	/**
82
+	 * Returns the current page index
83
+	 *
84
+	 * @return int
85
+	 */
86
+	public function getPage()
87
+	{
88
+		return $this->page;
89
+	}
90
+
91
+	/**
92
+	 * Sets the current page index
93
+	 *
94
+	 * @param int $page
95
+	 */
96
+	public function setPage($page)
97
+	{
98
+		$this->page = $page;
99
+	}
100
+
101
+	/**
102
+	 * Returns the current limit index
103
+	 *
104
+	 * @return int
105
+	 */
106
+	public function getLimit()
107
+	{
108
+		return $this->limit;
109
+	}
110
+
111
+	/**
112
+	 * Sets the current limit index
113
+	 *
114
+	 * @param int $limit
115
+	 */
116
+	public function setLimit($limit)
117
+	{
118
+		$this->limit = $limit;
119
+	}
120
+
121
+	/**
122
+	 * @return Array Items to display
123
+	 */
124
+	public function getDisplayItems()
125
+	{
126
+		$last = $this->getLastPage();
127
+		if ($last == 1) {
128
+			return null;
129
+		}
130
+		$values = Array();
131
+		for ($i = 1; $i <= $last; $i++) {
132
+			$values[] = Array('key' => $i, 'value' => $i);
133
+		}
134
+		return $values;
135
+	}
136
+
137
+	/**
138
+	 * @return int The last page index
139
+	 */
140
+	public function getLastPage()
141
+	{
142
+		$last = intval($this->count / $this->limit);
143
+		if ($this->count % $this->limit > 0) {
144
+			$last++;
145
+		}
146
+		return $last;
147
+	}
148
+
149
+	/**
150
+	 * @return int The previous page index. Minimum value is 1
151
+	 */
152
+	public function getPreviousPage()
153
+	{
154
+		$prev = $this->page - 1;
155
+		if ($prev < 1) {
156
+			$prev = 1;
157
+		}
158
+		return $prev;
159
+	}
160
+
161
+	/**
162
+	 * @return int The next page index. Maximum valus is the last page
163
+	 */
164
+	public function getNextPage()
165
+	{
166
+		$next = $this->page + 1;
167
+		$last = $this->getLastPage();
168
+		if ($next > $last) {
169
+			$next = $last;
170
+		}
171
+		return $next;
172
+	}
173
+
174
+	/**
175
+	 * @return int
176
+	 */
177
+	public function getOffset()
178
+	{
179
+		return $this->offset;
180
+	}
181
+
182
+	/**
183
+	 * @param int $offset
184
+	 */
185
+	public function setOffset($offset)
186
+	{
187
+		$this->offset = $offset;
188
+	}
189 189
 }
Please login to merge, or discard this patch.
Classes/Mvc/JsonResult.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -20,121 +20,121 @@
 block discarded – undo
20 20
 class JsonResult
21 21
 {
22 22
 
23
-    /**
24
-     * @var int
25
-     */
26
-    protected $numberOfObjects = 0;
27
-
28
-    /**
29
-     * @var int
30
-     */
31
-    protected $numberOfProcessedObjects = 0;
32
-
33
-    /**
34
-     * @var array
35
-     */
36
-    protected $errorMessages = array();
37
-
38
-    /**
39
-     * @var array
40
-     */
41
-    protected $processedObject = array();
42
-
43
-    /**
44
-     * @var array
45
-     */
46
-    protected $row = NULL;
47
-
48
-    /**
49
-     * @return $this
50
-     */
51
-    public function incrementNumberOfProcessedObjects()
52
-    {
53
-        $this->numberOfProcessedObjects++;
54
-    }
55
-
56
-    /**
57
-     * @param string $errorMessages
58
-     * @return $this
59
-     */
60
-    public function addErrorMessages($errorMessages)
61
-    {
62
-        if (!empty($errorMessages)) {
63
-            $this->errorMessages[] = $errorMessages;
64
-        } else {
65
-            $this->incrementNumberOfProcessedObjects();
66
-        }
67
-        return $this;
68
-    }
69
-
70
-    /**
71
-     * @param array $errorMessages
72
-     * @return $this
73
-     */
74
-    public function setErrorMessages($errorMessages)
75
-    {
76
-        $this->errorMessages = $errorMessages;
77
-        return $this;
78
-    }
79
-
80
-    /**
81
-     * @param array $processedObject
82
-     * @return $this
83
-     */
84
-    public function setProcessedObject($processedObject)
85
-    {
86
-        $this->processedObject = $processedObject;
87
-        return $this;
88
-    }
89
-
90
-    /**
91
-     * @return $this
92
-     */
93
-    public function hasErrors()
94
-    {
95
-        return !empty($this->errorMessages);
96
-    }
97
-
98
-    /**
99
-     * @param mixed $numberOfObjects
100
-     * @return $this
101
-     */
102
-    public function setNumberOfObjects($numberOfObjects)
103
-    {
104
-        $this->numberOfObjects = $numberOfObjects;
105
-        return $this;
106
-    }
107
-
108
-    /**
109
-     * @param mixed $row
110
-     * @return $this
111
-     */
112
-    public function setRow(array $row)
113
-    {
114
-        $this->row = $row;
115
-        return $this;
116
-    }
117
-
118
-    /**
119
-     * Convert $this to array
120
-     *
121
-     * @return array
122
-     */
123
-    public function toArray()
124
-    {
125
-        $arrayValues = array(
126
-            'numberOfObjects' => $this->numberOfObjects,
127
-            'numberOfProcessedObjects' => $this->numberOfProcessedObjects,
128
-            'hasErrors' => $this->hasErrors(),
129
-            'errorMessages' => $this->errorMessages,
130
-            'row' => $this->row,
131
-        );
132
-
133
-        // Only feed key processedObject if it has values.
134
-        if (!empty($this->processedObject)) {
135
-            $arrayValues['processedObject'] = $this->processedObject;
136
-        }
137
-
138
-        return $arrayValues;
139
-    }
23
+	/**
24
+	 * @var int
25
+	 */
26
+	protected $numberOfObjects = 0;
27
+
28
+	/**
29
+	 * @var int
30
+	 */
31
+	protected $numberOfProcessedObjects = 0;
32
+
33
+	/**
34
+	 * @var array
35
+	 */
36
+	protected $errorMessages = array();
37
+
38
+	/**
39
+	 * @var array
40
+	 */
41
+	protected $processedObject = array();
42
+
43
+	/**
44
+	 * @var array
45
+	 */
46
+	protected $row = NULL;
47
+
48
+	/**
49
+	 * @return $this
50
+	 */
51
+	public function incrementNumberOfProcessedObjects()
52
+	{
53
+		$this->numberOfProcessedObjects++;
54
+	}
55
+
56
+	/**
57
+	 * @param string $errorMessages
58
+	 * @return $this
59
+	 */
60
+	public function addErrorMessages($errorMessages)
61
+	{
62
+		if (!empty($errorMessages)) {
63
+			$this->errorMessages[] = $errorMessages;
64
+		} else {
65
+			$this->incrementNumberOfProcessedObjects();
66
+		}
67
+		return $this;
68
+	}
69
+
70
+	/**
71
+	 * @param array $errorMessages
72
+	 * @return $this
73
+	 */
74
+	public function setErrorMessages($errorMessages)
75
+	{
76
+		$this->errorMessages = $errorMessages;
77
+		return $this;
78
+	}
79
+
80
+	/**
81
+	 * @param array $processedObject
82
+	 * @return $this
83
+	 */
84
+	public function setProcessedObject($processedObject)
85
+	{
86
+		$this->processedObject = $processedObject;
87
+		return $this;
88
+	}
89
+
90
+	/**
91
+	 * @return $this
92
+	 */
93
+	public function hasErrors()
94
+	{
95
+		return !empty($this->errorMessages);
96
+	}
97
+
98
+	/**
99
+	 * @param mixed $numberOfObjects
100
+	 * @return $this
101
+	 */
102
+	public function setNumberOfObjects($numberOfObjects)
103
+	{
104
+		$this->numberOfObjects = $numberOfObjects;
105
+		return $this;
106
+	}
107
+
108
+	/**
109
+	 * @param mixed $row
110
+	 * @return $this
111
+	 */
112
+	public function setRow(array $row)
113
+	{
114
+		$this->row = $row;
115
+		return $this;
116
+	}
117
+
118
+	/**
119
+	 * Convert $this to array
120
+	 *
121
+	 * @return array
122
+	 */
123
+	public function toArray()
124
+	{
125
+		$arrayValues = array(
126
+			'numberOfObjects' => $this->numberOfObjects,
127
+			'numberOfProcessedObjects' => $this->numberOfProcessedObjects,
128
+			'hasErrors' => $this->hasErrors(),
129
+			'errorMessages' => $this->errorMessages,
130
+			'row' => $this->row,
131
+		);
132
+
133
+		// Only feed key processedObject if it has values.
134
+		if (!empty($this->processedObject)) {
135
+			$arrayValues['processedObject'] = $this->processedObject;
136
+		}
137
+
138
+		return $arrayValues;
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
Classes/Language/LocalizationStatus.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@
 block discarded – undo
22 22
 class LocalizationStatus extends Enumeration
23 23
 {
24 24
 
25
-    const LOCALIZED = 'localized';
26
-    const NOT_YET_LOCALIZED = 'notYetLocalized';
27
-    const EMPTY_VALUE = 'emptyValue';
25
+	const LOCALIZED = 'localized';
26
+	const NOT_YET_LOCALIZED = 'notYetLocalized';
27
+	const EMPTY_VALUE = 'emptyValue';
28 28
 
29 29
 }
Please login to merge, or discard this patch.
Classes/Behavior/SavingBehavior.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@
 block discarded – undo
22 22
 class SavingBehavior extends Enumeration
23 23
 {
24 24
 
25
-    const REMOVE = 'remove';
25
+	const REMOVE = 'remove';
26 26
 
27
-    const APPEND = 'append';
27
+	const APPEND = 'append';
28 28
 
29
-    const REPLACE = 'replace';
29
+	const REPLACE = 'replace';
30 30
 
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.