Completed
Pull Request — master (#107)
by
unknown
03:28
created
Classes/Processor/MarkerProcessor.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
     /**
39 39
      * @param ProcessContentDataSignalArguments $signalArguments
40
-     * @return array
40
+     * @return ProcessContentDataSignalArguments[]
41 41
      */
42 42
     public function processMarkers(ProcessContentDataSignalArguments $signalArguments)
43 43
     {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      * @param string $updateValue
73 73
      * @param string $currentValue
74 74
      * @param int $counter
75
-     * @param $creationTime
75
+     * @param integer $creationTime
76 76
      * @return string
77 77
      */
78 78
     protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime)
Please login to merge, or discard this patch.
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -25,114 +25,114 @@
 block discarded – undo
25 25
 class MarkerProcessor implements SingletonInterface
26 26
 {
27 27
 
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $wellKnownMarkers = array(
32
-        '{*}',
33
-        '{counter}',
34
-        '{date}',
35
-        '{creation_date}'
36
-    );
37
-
38
-    /**
39
-     * @param ProcessContentDataSignalArguments $signalArguments
40
-     * @return array
41
-     */
42
-    public function processMarkers(ProcessContentDataSignalArguments $signalArguments)
43
-    {
44
-
45
-        $contentData = $signalArguments->getContentData();
46
-        $creationTime = $this->getCreationTime($signalArguments);
47
-
48
-        // Process markers
49
-        foreach ($signalArguments->getContentData() as $fieldName => $updateValue) {
50
-            if (is_scalar($updateValue)) {
51
-
52
-                $currentValue = $this->getContentObjectResolver()->getValue(
53
-                    $signalArguments->getContentObject(),
54
-                    $signalArguments->getFieldNameAndPath(),
55
-                    $fieldName,
56
-                    $signalArguments->getLanguage()
57
-                );
58
-                $counter = $signalArguments->getCounter();
59
-
60
-                $updateValue = $this->searchAndReplace($updateValue, $currentValue);
61
-                $updateValue = $this->replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime);
62
-
63
-                $contentData[$fieldName] = $updateValue;
64
-            }
65
-        }
66
-
67
-        $signalArguments->setContentData($contentData);
68
-        return array($signalArguments);
69
-    }
70
-
71
-    /**
72
-     * @param string $updateValue
73
-     * @param string $currentValue
74
-     * @param int $counter
75
-     * @param $creationTime
76
-     * @return string
77
-     */
78
-    protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime)
79
-    {
80
-
81
-        // Replaces values.
82
-        $replaces = array(
83
-            $currentValue,
84
-            $counter,
85
-            date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']),
86
-            date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $creationTime),
87
-        );
88
-
89
-        // Replace me!
90
-        return str_replace($this->wellKnownMarkers, $replaces, $updateValue);
91
-    }
92
-
93
-    /**
94
-     * @param string $updateValue
95
-     * @param string $currentValue
96
-     * @return string
97
-     */
98
-    protected function searchAndReplace($updateValue, $currentValue)
99
-    {
100
-
101
-        if (strpos($updateValue, 's/') !== FALSE) {
102
-            $structure = explode('/', $updateValue);
103
-            $search = $structure[1];
104
-            $replace = $structure[2];
105
-
106
-            // Perhaps needs to be improved here if $search contains "/" precisely.
107
-            $updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue);
108
-        }
109
-        return $updateValue;
110
-    }
111
-
112
-    /**
113
-     * @param ProcessContentDataSignalArguments $signalArguments
114
-     * @return int
115
-     */
116
-    protected function getCreationTime(ProcessContentDataSignalArguments $signalArguments)
117
-    {
118
-        $creationTime = 0;
119
-        $creationTimeField = Tca::table($signalArguments->getContentObject()->getDataType())->getTimeCreationField();
120
-        if ($creationTimeField) {
121
-            $creationTime = $this->getContentObjectResolver()->getValue(
122
-                $signalArguments->getContentObject(),
123
-                $signalArguments->getFieldNameAndPath(),
124
-                $creationTimeField
125
-            );
126
-        }
127
-        return $creationTime;
128
-    }
129
-
130
-    /**
131
-     * @return \Fab\Vidi\Resolver\ContentObjectResolver
132
-     */
133
-    protected function getContentObjectResolver()
134
-    {
135
-        return GeneralUtility::makeInstance('Fab\Vidi\Resolver\ContentObjectResolver');
136
-    }
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $wellKnownMarkers = array(
32
+		'{*}',
33
+		'{counter}',
34
+		'{date}',
35
+		'{creation_date}'
36
+	);
37
+
38
+	/**
39
+	 * @param ProcessContentDataSignalArguments $signalArguments
40
+	 * @return array
41
+	 */
42
+	public function processMarkers(ProcessContentDataSignalArguments $signalArguments)
43
+	{
44
+
45
+		$contentData = $signalArguments->getContentData();
46
+		$creationTime = $this->getCreationTime($signalArguments);
47
+
48
+		// Process markers
49
+		foreach ($signalArguments->getContentData() as $fieldName => $updateValue) {
50
+			if (is_scalar($updateValue)) {
51
+
52
+				$currentValue = $this->getContentObjectResolver()->getValue(
53
+					$signalArguments->getContentObject(),
54
+					$signalArguments->getFieldNameAndPath(),
55
+					$fieldName,
56
+					$signalArguments->getLanguage()
57
+				);
58
+				$counter = $signalArguments->getCounter();
59
+
60
+				$updateValue = $this->searchAndReplace($updateValue, $currentValue);
61
+				$updateValue = $this->replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime);
62
+
63
+				$contentData[$fieldName] = $updateValue;
64
+			}
65
+		}
66
+
67
+		$signalArguments->setContentData($contentData);
68
+		return array($signalArguments);
69
+	}
70
+
71
+	/**
72
+	 * @param string $updateValue
73
+	 * @param string $currentValue
74
+	 * @param int $counter
75
+	 * @param $creationTime
76
+	 * @return string
77
+	 */
78
+	protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime)
79
+	{
80
+
81
+		// Replaces values.
82
+		$replaces = array(
83
+			$currentValue,
84
+			$counter,
85
+			date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']),
86
+			date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $creationTime),
87
+		);
88
+
89
+		// Replace me!
90
+		return str_replace($this->wellKnownMarkers, $replaces, $updateValue);
91
+	}
92
+
93
+	/**
94
+	 * @param string $updateValue
95
+	 * @param string $currentValue
96
+	 * @return string
97
+	 */
98
+	protected function searchAndReplace($updateValue, $currentValue)
99
+	{
100
+
101
+		if (strpos($updateValue, 's/') !== FALSE) {
102
+			$structure = explode('/', $updateValue);
103
+			$search = $structure[1];
104
+			$replace = $structure[2];
105
+
106
+			// Perhaps needs to be improved here if $search contains "/" precisely.
107
+			$updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue);
108
+		}
109
+		return $updateValue;
110
+	}
111
+
112
+	/**
113
+	 * @param ProcessContentDataSignalArguments $signalArguments
114
+	 * @return int
115
+	 */
116
+	protected function getCreationTime(ProcessContentDataSignalArguments $signalArguments)
117
+	{
118
+		$creationTime = 0;
119
+		$creationTimeField = Tca::table($signalArguments->getContentObject()->getDataType())->getTimeCreationField();
120
+		if ($creationTimeField) {
121
+			$creationTime = $this->getContentObjectResolver()->getValue(
122
+				$signalArguments->getContentObject(),
123
+				$signalArguments->getFieldNameAndPath(),
124
+				$creationTimeField
125
+			);
126
+		}
127
+		return $creationTime;
128
+	}
129
+
130
+	/**
131
+	 * @return \Fab\Vidi\Resolver\ContentObjectResolver
132
+	 */
133
+	protected function getContentObjectResolver()
134
+	{
135
+		return GeneralUtility::makeInstance('Fab\Vidi\Resolver\ContentObjectResolver');
136
+	}
137 137
 
138 138
 }
Please login to merge, or discard this patch.
Classes/Service/ContentService.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@
 block discarded – undo
88 88
     /**
89 89
      * Signal that is called after the content objects have been found.
90 90
      *
91
-     * @param array $contentObjects
91
+     * @param \Fab\Vidi\Domain\Model\Content[] $contentObjects
92 92
      * @param \Fab\Vidi\Persistence\Matcher $matcher
93 93
      * @param Order $order
94 94
      * @param int $limit
Please login to merge, or discard this patch.
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -27,129 +27,129 @@
 block discarded – undo
27 27
 class ContentService
28 28
 {
29 29
 
30
-    /**
31
-     * @var string
32
-     */
33
-    protected $dataType;
34
-
35
-    /**
36
-     * @var \Fab\Vidi\Domain\Model\Content[]
37
-     */
38
-    protected $objects = array();
39
-
40
-    /**
41
-     * @var int
42
-     */
43
-    protected $numberOfObjects = 0;
44
-
45
-    /**
46
-     * Constructor
47
-     *
48
-     * @param string $dataType
49
-     * @return \Fab\Vidi\Service\ContentService
50
-     */
51
-    public function __construct($dataType = '')
52
-    {
53
-        if (empty($dataType)) {
54
-            $dataType = $this->getModuleLoader()->getDataType();
55
-        }
56
-        $this->dataType = $dataType;
57
-    }
58
-
59
-    /**
60
-     * Fetch the files given an object assuming
61
-     *
62
-     * @param Matcher $matcher
63
-     * @param Order $order The order
64
-     * @param int $limit
65
-     * @param int $offset
66
-     * @return $this
67
-     */
68
-    public function findBy(Matcher $matcher, Order $order = NULL, $limit = NULL, $offset = NULL)
69
-    {
70
-
71
-        // Query the repository.
72
-        $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order, $limit, $offset);
73
-        $signalResult = $this->emitAfterFindContentObjectsSignal($objects, $matcher, $order, $limit, $offset);
74
-
75
-        // Reset objects variable after possible signal / slot processing.
76
-        $this->objects = $signalResult->getContentObjects();
77
-
78
-        // Count number of content objects.
79
-        if ($signalResult->getHasBeenProcessed()) {
80
-            $this->numberOfObjects = $signalResult->getNumberOfObjects();
81
-        } else {
82
-            $this->numberOfObjects = ContentRepositoryFactory::getInstance($this->dataType)->countBy($matcher);
83
-        }
84
-
85
-        return $this;
86
-    }
87
-
88
-    /**
89
-     * Signal that is called after the content objects have been found.
90
-     *
91
-     * @param array $contentObjects
92
-     * @param \Fab\Vidi\Persistence\Matcher $matcher
93
-     * @param Order $order
94
-     * @param int $limit
95
-     * @param int $offset
96
-     * @return AfterFindContentObjectsSignalArguments
97
-     * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
98
-     * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException
99
-     * @signal
100
-     */
101
-    protected function emitAfterFindContentObjectsSignal($contentObjects, Matcher $matcher, Order $order = NULL, $limit = 0, $offset = 0)
102
-    {
103
-
104
-        /** @var \Fab\Vidi\Signal\AfterFindContentObjectsSignalArguments $signalArguments */
105
-        $signalArguments = GeneralUtility::makeInstance('Fab\Vidi\Signal\AfterFindContentObjectsSignalArguments');
106
-        $signalArguments->setDataType($this->dataType)
107
-            ->setContentObjects($contentObjects)
108
-            ->setMatcher($matcher)
109
-            ->setOrder($order)
110
-            ->setLimit($limit)
111
-            ->setOffset($offset)
112
-            ->setHasBeenProcessed(FALSE);
113
-
114
-        $signalResult = $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\Service\ContentService', 'afterFindContentObjects', array($signalArguments));
115
-        return $signalResult[0];
116
-    }
117
-
118
-    /**
119
-     * Get the Vidi Module Loader.
120
-     *
121
-     * @return \Fab\Vidi\Module\ModuleLoader
122
-     */
123
-    protected function getModuleLoader()
124
-    {
125
-        return GeneralUtility::makeInstance('Fab\Vidi\Module\ModuleLoader');
126
-    }
127
-
128
-    /**
129
-     * Get the SignalSlot dispatcher.
130
-     *
131
-     * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
132
-     */
133
-    protected function getSignalSlotDispatcher()
134
-    {
135
-        /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
136
-        $objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
137
-        return $objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
138
-    }
139
-
140
-    /**
141
-     * @return \Fab\Vidi\Domain\Model\Content[]
142
-     */
143
-    public function getObjects()
144
-    {
145
-        return $this->objects;
146
-    }
147
-
148
-    /**
149
-     * @return int
150
-     */
151
-    public function getNumberOfObjects()
152
-    {
153
-        return $this->numberOfObjects;
154
-    }
30
+	/**
31
+	 * @var string
32
+	 */
33
+	protected $dataType;
34
+
35
+	/**
36
+	 * @var \Fab\Vidi\Domain\Model\Content[]
37
+	 */
38
+	protected $objects = array();
39
+
40
+	/**
41
+	 * @var int
42
+	 */
43
+	protected $numberOfObjects = 0;
44
+
45
+	/**
46
+	 * Constructor
47
+	 *
48
+	 * @param string $dataType
49
+	 * @return \Fab\Vidi\Service\ContentService
50
+	 */
51
+	public function __construct($dataType = '')
52
+	{
53
+		if (empty($dataType)) {
54
+			$dataType = $this->getModuleLoader()->getDataType();
55
+		}
56
+		$this->dataType = $dataType;
57
+	}
58
+
59
+	/**
60
+	 * Fetch the files given an object assuming
61
+	 *
62
+	 * @param Matcher $matcher
63
+	 * @param Order $order The order
64
+	 * @param int $limit
65
+	 * @param int $offset
66
+	 * @return $this
67
+	 */
68
+	public function findBy(Matcher $matcher, Order $order = NULL, $limit = NULL, $offset = NULL)
69
+	{
70
+
71
+		// Query the repository.
72
+		$objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order, $limit, $offset);
73
+		$signalResult = $this->emitAfterFindContentObjectsSignal($objects, $matcher, $order, $limit, $offset);
74
+
75
+		// Reset objects variable after possible signal / slot processing.
76
+		$this->objects = $signalResult->getContentObjects();
77
+
78
+		// Count number of content objects.
79
+		if ($signalResult->getHasBeenProcessed()) {
80
+			$this->numberOfObjects = $signalResult->getNumberOfObjects();
81
+		} else {
82
+			$this->numberOfObjects = ContentRepositoryFactory::getInstance($this->dataType)->countBy($matcher);
83
+		}
84
+
85
+		return $this;
86
+	}
87
+
88
+	/**
89
+	 * Signal that is called after the content objects have been found.
90
+	 *
91
+	 * @param array $contentObjects
92
+	 * @param \Fab\Vidi\Persistence\Matcher $matcher
93
+	 * @param Order $order
94
+	 * @param int $limit
95
+	 * @param int $offset
96
+	 * @return AfterFindContentObjectsSignalArguments
97
+	 * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
98
+	 * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException
99
+	 * @signal
100
+	 */
101
+	protected function emitAfterFindContentObjectsSignal($contentObjects, Matcher $matcher, Order $order = NULL, $limit = 0, $offset = 0)
102
+	{
103
+
104
+		/** @var \Fab\Vidi\Signal\AfterFindContentObjectsSignalArguments $signalArguments */
105
+		$signalArguments = GeneralUtility::makeInstance('Fab\Vidi\Signal\AfterFindContentObjectsSignalArguments');
106
+		$signalArguments->setDataType($this->dataType)
107
+			->setContentObjects($contentObjects)
108
+			->setMatcher($matcher)
109
+			->setOrder($order)
110
+			->setLimit($limit)
111
+			->setOffset($offset)
112
+			->setHasBeenProcessed(FALSE);
113
+
114
+		$signalResult = $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\Service\ContentService', 'afterFindContentObjects', array($signalArguments));
115
+		return $signalResult[0];
116
+	}
117
+
118
+	/**
119
+	 * Get the Vidi Module Loader.
120
+	 *
121
+	 * @return \Fab\Vidi\Module\ModuleLoader
122
+	 */
123
+	protected function getModuleLoader()
124
+	{
125
+		return GeneralUtility::makeInstance('Fab\Vidi\Module\ModuleLoader');
126
+	}
127
+
128
+	/**
129
+	 * Get the SignalSlot dispatcher.
130
+	 *
131
+	 * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
132
+	 */
133
+	protected function getSignalSlotDispatcher()
134
+	{
135
+		/** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
136
+		$objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
137
+		return $objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
138
+	}
139
+
140
+	/**
141
+	 * @return \Fab\Vidi\Domain\Model\Content[]
142
+	 */
143
+	public function getObjects()
144
+	{
145
+		return $this->objects;
146
+	}
147
+
148
+	/**
149
+	 * @return int
150
+	 */
151
+	public function getNumberOfObjects()
152
+	{
153
+		return $this->numberOfObjects;
154
+	}
155 155
 }
Please login to merge, or discard this patch.
Classes/Tca/GridService.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
      *
461 461
      * @param string $fieldName
462 462
      * @param string $key
463
-     * @param mixed $defaultValue
463
+     * @param boolean|string $defaultValue
464 464
      * @return NULL|mixed
465 465
      */
466 466
     public function get($fieldName, $key, $defaultValue = NULL)
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
     /**
653 653
      * Returns a "facet" service instance.
654 654
      *
655
-     * @param string|FacetInterface $facetName
655
+     * @param string $facetName
656 656
      * @return FacetInterface
657 657
      */
658 658
     public function facet($facetName = '')
Please login to merge, or discard this patch.
Indentation   +645 added lines, -645 removed lines patch added patch discarded remove patch
@@ -31,650 +31,650 @@
 block discarded – undo
31 31
 class GridService extends AbstractTca
32 32
 {
33 33
 
34
-    /**
35
-     * @var array
36
-     */
37
-    protected $tca;
38
-
39
-    /**
40
-     * @var string
41
-     */
42
-    protected $tableName;
43
-
44
-    /**
45
-     * All fields available in the Grid.
46
-     *
47
-     * @var array
48
-     */
49
-    protected $fields;
50
-
51
-    /**
52
-     * All fields regardless whether they have been excluded or not.
53
-     *
54
-     * @var array
55
-     */
56
-    protected $allFields;
57
-
58
-    /**
59
-     * @var array
60
-     */
61
-    protected $instances;
62
-
63
-    /**
64
-     * @var array
65
-     */
66
-    protected $facets;
67
-
68
-    /**
69
-     * __construct
70
-     *
71
-     * @throws InvalidKeyInArrayException
72
-     * @param string $tableName
73
-     * @return \Fab\Vidi\Tca\GridService
74
-     */
75
-    public function __construct($tableName)
76
-    {
77
-
78
-        $this->tableName = $tableName;
79
-
80
-        if (empty($GLOBALS['TCA'][$this->tableName])) {
81
-            throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108);
82
-        }
83
-
84
-        $this->tca = $GLOBALS['TCA'][$this->tableName]['grid'];
85
-    }
86
-
87
-    /**
88
-     * Returns an array containing column names.
89
-     *
90
-     * @return array
91
-     */
92
-    public function getFieldNames()
93
-    {
94
-        $fields = $this->getFields();
95
-        return array_keys($fields);
96
-    }
97
-
98
-    /**
99
-     * Returns an array containing column names.
100
-     *
101
-     * @return array
102
-     */
103
-    public function getAllFieldNames()
104
-    {
105
-        $allFields = $this->getAllFields();
106
-        return array_keys($allFields);
107
-    }
108
-
109
-    /**
110
-     * Get the label key.
111
-     *
112
-     * @param string $fieldNameAndPath
113
-     * @return string
114
-     */
115
-    public function getLabelKey($fieldNameAndPath)
116
-    {
117
-
118
-        $field = $this->getField($fieldNameAndPath);
119
-
120
-        // First option is to get the label from the Grid TCA.
121
-        $rawLabel = '';
122
-        if (isset($field['label'])) {
123
-            $rawLabel = $field['label'];
124
-        }
125
-
126
-        // Second option is to fetch the label from the Column Renderer object.
127
-        if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) {
128
-            $renderers = $this->getRenderers($fieldNameAndPath);
129
-            /** @var $renderer ColumnRendererInterface */
130
-            foreach ($renderers as $renderer) {
131
-                if (isset($renderer['label'])) {
132
-                    $rawLabel = $renderer['label'];
133
-                    break;
134
-                }
135
-            }
136
-        }
137
-        return $rawLabel;
138
-    }
139
-
140
-    /**
141
-     * Get the translation of a label given a column name.
142
-     *
143
-     * @param string $fieldNameAndPath
144
-     * @return string
145
-     */
146
-    public function getLabel($fieldNameAndPath)
147
-    {
148
-        $label = '';
149
-        if ($this->hasLabel($fieldNameAndPath)) {
150
-            $labelKey = $this->getLabelKey($fieldNameAndPath);
151
-            $label = LocalizationUtility::translate($labelKey, '');
152
-            if (is_null($label)) {
153
-                $label = $labelKey;
154
-            }
155
-        } else {
156
-
157
-            // Important to notice the label can contains a path, e.g. metadata.categories and must be resolved.
158
-            $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName);
159
-            $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName);
160
-            $table = Tca::table($dataType);
161
-
162
-            if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) {
163
-                $label = $table->field($fieldName)->getLabel();
164
-            }
165
-        }
166
-
167
-        return $label;
168
-    }
169
-
170
-    /**
171
-     * Returns the field name given its position.
172
-     *
173
-     * @param string $position the position of the field in the grid
174
-     * @throws InvalidKeyInArrayException
175
-     * @return int
176
-     */
177
-    public function getFieldNameByPosition($position)
178
-    {
179
-        $fields = array_keys($this->getFields());
180
-        if (empty($fields[$position])) {
181
-            throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119);
182
-        }
183
-
184
-        return $fields[$position];
185
-    }
186
-
187
-    /**
188
-     * Returns a field name.
189
-     *
190
-     * @param string $fieldName
191
-     * @return array
192
-     * @throws InvalidKeyInArrayException
193
-     */
194
-    public function getField($fieldName)
195
-    {
196
-        $fields = $this->getFields();
197
-        return $fields[$fieldName];
198
-    }
199
-
200
-    /**
201
-     * Returns an array containing column names for the Grid.
202
-     *
203
-     * @return array
204
-     */
205
-    public function getFields()
206
-    {
207
-        // Cache this operation since it can take some time.
208
-        if (is_null($this->fields)) {
209
-
210
-            // Fetch all available fields first.
211
-            $fields = $this->getAllFields();
212
-
213
-            if ($this->isBackendMode()) {
214
-                // Then remove the not allowed.
215
-                $fields = $this->filterForBackendUser($fields);
216
-                $fields = $this->filterForConfiguration($fields);
217
-            }
218
-
219
-            $this->fields = $fields;
220
-        }
221
-
222
-        return $this->fields;
223
-    }
224
-
225
-    /**
226
-     * Remove fields according to BE User permission.
227
-     *
228
-     * @param $fields
229
-     * @return array
230
-     * @throws \Exception
231
-     */
232
-    protected function filterForBackendUser($fields)
233
-    {
234
-        if (!$this->getBackendUser()->isAdmin()) {
235
-            foreach ($fields as $fieldName => $field) {
236
-                if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) {
237
-                    unset($fields[$fieldName]);
238
-                }
239
-            }
240
-        }
241
-        return $fields;
242
-    }
243
-
244
-    /**
245
-     * Remove fields according to Grid configuration.
246
-     *
247
-     * @param $fields
248
-     * @return array
249
-     */
250
-    protected function filterForConfiguration($fields)
251
-    {
252
-
253
-        // Unset excluded fields.
254
-        foreach ($this->getExcludedFields() as $excludedField) {
255
-            if (isset($fields[$excludedField])) {
256
-                unset($fields[$excludedField]);
257
-            }
258
-        }
259
-
260
-        return $fields;
261
-    }
262
-
263
-    /**
264
-     * Returns an array containing column names for the Grid.
265
-     *
266
-     * @return array
267
-     */
268
-    public function getAllFields()
269
-    {
270
-
271
-        // Cache this operation since it can take some time.
272
-        if (is_null($this->allFields)) {
273
-
274
-            $fields = is_array($this->tca['columns']) ? $this->tca['columns'] : array();
275
-            $gridFieldNames = array_keys($fields);
276
-
277
-            // Fetch all fields of the TCA and merge it back to the fields configured for Grid.
278
-            $tableFieldNames = Tca::table($this->tableName)->getFields();
279
-
280
-            // Just remove system fields from the Grid.
281
-            foreach ($tableFieldNames as $key => $fieldName) {
282
-                if (in_array($fieldName, Tca::getSystemFields())) {
283
-                    unset($tableFieldNames[$key]);
284
-                }
285
-            }
286
-
287
-            $additionalFields = array_diff($tableFieldNames, $gridFieldNames);
288
-
289
-            if (!empty($additionalFields)) {
290
-
291
-                // Pop out last element of the key
292
-                // Idea is to place new un-configured columns in between. By default, they will be hidden.
293
-                end($fields);
294
-                $lastColumnKey = key($fields);
295
-                $lastColumn = array_pop($fields);
296
-
297
-                // Feed up the grid fields with un configured elements
298
-                foreach ($additionalFields as $additionalField) {
299
-                    $fields[$additionalField] = array(
300
-                        'visible' => FALSE
301
-                    );
302
-
303
-                    // Try to guess the format of the field.
304
-                    $fieldType = Tca::table($this->tableName)->field($additionalField)->getType();
305
-                    if ($fieldType === FieldType::DATE) {
306
-                        $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date';
307
-                    } elseif ($fieldType === FieldType::DATETIME) {
308
-                        $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime';
309
-                    }
310
-                }
311
-                $fields[$lastColumnKey] = $lastColumn;
312
-            }
313
-
314
-            $this->allFields = $fields;
315
-        }
316
-
317
-        return $this->allFields;
318
-    }
319
-
320
-    /**
321
-     * Tell whether the field exists in the grid or not.
322
-     *
323
-     * @param string $fieldName
324
-     * @return bool
325
-     */
326
-    public function hasField($fieldName)
327
-    {
328
-        $fields = $this->getFields();
329
-        return isset($fields[$fieldName]);
330
-    }
331
-
332
-    /**
333
-     * Tell whether the facet exists in the grid or not.
334
-     *
335
-     * @param string $facetName
336
-     * @return bool
337
-     */
338
-    public function hasFacet($facetName)
339
-    {
340
-        $facets = $this->getFacets();
341
-        return isset($facets[$facetName]);
342
-    }
343
-
344
-    /**
345
-     * Returns an array containing facets fields.
346
-     *
347
-     * @return FacetInterface[]
348
-     */
349
-    public function getFacets()
350
-    {
351
-        if (is_null($this->facets)) {
352
-            $this->facets = array();
353
-
354
-            if (is_array($this->tca['facets'])) {
355
-                foreach ($this->tca['facets'] as $facetNameOrObject) {
356
-                    if ($facetNameOrObject instanceof FacetInterface) {
357
-                        $this->facets[$facetNameOrObject->getName()] = $facetNameOrObject;
358
-                    } else {
359
-                        $this->facets[$facetNameOrObject] = $this->instantiateStandardFacet($facetNameOrObject);
360
-                    }
361
-                }
362
-            }
363
-        }
364
-        return $this->facets;
365
-    }
366
-
367
-    /**
368
-     * Returns the "sortable" value of the column.
369
-     *
370
-     * @param string $fieldName
371
-     * @return int|string
372
-     */
373
-    public function isSortable($fieldName)
374
-    {
375
-        $defaultValue = TRUE;
376
-        $hasSortableField = Tca::table($this->tableName)->hasSortableField();
377
-        if ($hasSortableField) {
378
-            $isSortable = FALSE;
379
-        } else {
380
-            $isSortable = $this->get($fieldName, 'sortable', $defaultValue);
381
-        }
382
-        return $isSortable;
383
-    }
384
-
385
-    /**
386
-     * Returns the "canBeHidden" value of the column.
387
-     *
388
-     * @param string $fieldName
389
-     * @return bool
390
-     */
391
-    public function canBeHidden($fieldName)
392
-    {
393
-        $defaultValue = TRUE;
394
-        return $this->get($fieldName, 'canBeHidden', $defaultValue);
395
-    }
396
-
397
-    /**
398
-     * Returns the "width" value of the column.
399
-     *
400
-     * @param string $fieldName
401
-     * @return int|string
402
-     */
403
-    public function getWidth($fieldName)
404
-    {
405
-        $defaultValue = 'auto';
406
-        return $this->get($fieldName, 'width', $defaultValue);
407
-    }
408
-
409
-    /**
410
-     * Returns the "visible" value of the column.
411
-     *
412
-     * @param string $fieldName
413
-     * @return bool
414
-     */
415
-    public function isVisible($fieldName)
416
-    {
417
-        $defaultValue = TRUE;
418
-        return $this->get($fieldName, 'visible', $defaultValue);
419
-    }
420
-
421
-    /**
422
-     * Returns the "editable" value of the column.
423
-     *
424
-     * @param string $columnName
425
-     * @return bool
426
-     */
427
-    public function isEditable($columnName)
428
-    {
429
-        $defaultValue = FALSE;
430
-        return $this->get($columnName, 'editable', $defaultValue);
431
-    }
432
-
433
-    /**
434
-     * Returns the "localized" value of the column.
435
-     *
436
-     * @param string $columnName
437
-     * @return bool
438
-     */
439
-    public function isLocalized($columnName)
440
-    {
441
-        $defaultValue = TRUE;
442
-        return $this->get($columnName, 'localized', $defaultValue);
443
-    }
444
-
445
-    /**
446
-     *
447
-     * Returns the "html" value of the column.
448
-     *
449
-     * @param string $fieldName
450
-     * @return string
451
-     */
452
-    public function getHeader($fieldName)
453
-    {
454
-        $defaultValue = '';
455
-        return $this->get($fieldName, 'html', $defaultValue);
456
-    }
457
-
458
-    /**
459
-     * Fetch a possible from a Grid Renderer. If no value is found, returns NULL
460
-     *
461
-     * @param string $fieldName
462
-     * @param string $key
463
-     * @param mixed $defaultValue
464
-     * @return NULL|mixed
465
-     */
466
-    public function get($fieldName, $key, $defaultValue = NULL)
467
-    {
468
-        $value = $defaultValue;
469
-
470
-        $field = $this->getField($fieldName);
471
-        if (isset($field[$key])) {
472
-            $value = $field[$key];
473
-        } elseif ($this->hasRenderers($fieldName)) {
474
-            $renderers = $this->getRenderers($fieldName);
475
-            foreach ($renderers as $rendererConfiguration) {
476
-                if (isset($rendererConfiguration[$key])) {
477
-                    $value = $rendererConfiguration[$key];
478
-                }
479
-            }
480
-        }
481
-        return $value;
482
-    }
483
-
484
-    /**
485
-     * Returns whether the column has a renderer.
486
-     *
487
-     * @param string $fieldName
488
-     * @return bool
489
-     */
490
-    public function hasRenderers($fieldName)
491
-    {
492
-        $field = $this->getField($fieldName);
493
-        return empty($field['renderer']) && empty($field['renderers']) ? FALSE : TRUE;
494
-    }
495
-
496
-    /**
497
-     * Returns a renderer.
498
-     *
499
-     * @param string $fieldName
500
-     * @return array
501
-     */
502
-    public function getRenderers($fieldName)
503
-    {
504
-        $field = $this->getField($fieldName);
505
-        $renderers = array();
506
-        if (!empty($field['renderer'])) {
507
-            $renderers = $this->convertRendererToArray($field['renderer']);
508
-        } elseif (!empty($field['renderers']) && is_array($field['renderers'])) {
509
-            foreach ($field['renderers'] as $renderer) {
510
-                $rendererNameAndConfiguration = $this->convertRendererToArray($renderer);
511
-                $renderers = array_merge($renderers, $rendererNameAndConfiguration);
512
-            }
513
-        }
514
-
515
-        return $renderers;
516
-    }
517
-
518
-    /**
519
-     * @param string|GenericColumn $renderer
520
-     * @return array
521
-     */
522
-    public function convertRendererToArray($renderer)
523
-    {
524
-        $result = array();
525
-        if (is_string($renderer)) {
526
-            $result[$renderer] = array();
527
-        } elseif ($renderer instanceof ColumnInterface || $renderer instanceof ColumnRendererInterface) {
528
-            /** @var GenericColumn $renderer */
529
-            $result[get_class($renderer)] = $renderer->getConfiguration();
530
-        }
531
-        return $result;
532
-    }
533
-
534
-    /**
535
-     * Returns the class names applied to a cell
536
-     *
537
-     * @param string $fieldName
538
-     * @return bool
539
-     */
540
-    public function getClass($fieldName)
541
-    {
542
-        $field = $this->getField($fieldName);
543
-        return isset($field['class']) ? $field['class'] : '';
544
-    }
545
-
546
-    /**
547
-     * Returns whether the column has a label.
548
-     *
549
-     * @param string $fieldNameAndPath
550
-     * @return bool
551
-     */
552
-    public function hasLabel($fieldNameAndPath)
553
-    {
554
-        $field = $this->getField($fieldNameAndPath);
555
-
556
-        $hasLabel = empty($field['label']) ? FALSE : TRUE;
557
-
558
-        if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) {
559
-            $renderers = $this->getRenderers($fieldNameAndPath);
560
-            /** @var $renderer ColumnRendererInterface */
561
-            foreach ($renderers as $renderer) {
562
-                if (isset($renderer['label'])) {
563
-                    $hasLabel = TRUE;
564
-                    break;
565
-                }
566
-            }
567
-        }
568
-        return $hasLabel;
569
-    }
570
-
571
-    /**
572
-     * @return array
573
-     */
574
-    public function getTca()
575
-    {
576
-        return $this->tca;
577
-    }
578
-
579
-    /**
580
-     * Return excluded fields from configuration + preferences.
581
-     *
582
-     * @return array
583
-     */
584
-    public function getExcludedFields()
585
-    {
586
-        $configurationFields = $this->getExcludedFieldsFromConfiguration();
587
-        $preferencesFields = $this->getExcludedFieldsFromPreferences();
588
-
589
-        return array_merge($configurationFields, $preferencesFields);
590
-    }
591
-
592
-    /**
593
-     * Fetch excluded fields from configuration.
594
-     *
595
-     * @return array
596
-     */
597
-    protected function getExcludedFieldsFromConfiguration()
598
-    {
599
-        $excludedFields = array();
600
-        if (!empty($this->tca['excluded_fields'])) {
601
-            $excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], TRUE);
602
-        } elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason.
603
-            $excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], TRUE);
604
-        }
605
-        return $excludedFields;
606
-
607
-    }
608
-
609
-    /**
610
-     * Fetch excluded fields from preferences.
611
-     *
612
-     * @return array
613
-     */
614
-    protected function getExcludedFieldsFromPreferences()
615
-    {
616
-        $excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName);
617
-        return is_array($excludedFields) ? $excludedFields : array();
618
-    }
619
-
620
-    /**
621
-     * @return array
622
-     */
623
-    public function areFilesIncludedInExport()
624
-    {
625
-        $isIncluded = TRUE;
626
-
627
-        if (isset($this->tca['export']['include_files'])) {
628
-            $isIncluded = $this->tca['export']['include_files'];
629
-        }
630
-        return $isIncluded;
631
-    }
632
-
633
-    /**
634
-     * Returns a "facet" service instance.
635
-     *
636
-     * @param string|FacetInterface $facetName
637
-     * @return StandardFacet
638
-     */
639
-    protected function instantiateStandardFacet($facetName)
640
-    {
641
-        $label = $this->getLabel($facetName);
642
-
643
-        /** @var StandardFacet $facetName */
644
-        $facet = GeneralUtility::makeInstance('Fab\Vidi\Facet\StandardFacet', $facetName, $label);
645
-
646
-        if (!$facet instanceof StandardFacet) {
647
-            throw new \RuntimeException('I could not instantiate a facet for facet name "' . (string)$facet . '""', 1445856345);
648
-        }
649
-        return $facet;
650
-    }
651
-
652
-    /**
653
-     * Returns a "facet" service instance.
654
-     *
655
-     * @param string|FacetInterface $facetName
656
-     * @return FacetInterface
657
-     */
658
-    public function facet($facetName = '')
659
-    {
660
-        $facets = $this->getFacets();
661
-        return $facets[$facetName];
662
-    }
663
-
664
-    /**
665
-     * @return \Fab\Vidi\Resolver\FieldPathResolver
666
-     */
667
-    protected function getFieldPathResolver()
668
-    {
669
-        return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
670
-    }
671
-
672
-    /**
673
-     * @return ModulePreferences
674
-     */
675
-    protected function getModulePreferences()
676
-    {
677
-        return GeneralUtility::makeInstance('Fab\Vidi\Module\ModulePreferences');
678
-    }
34
+	/**
35
+	 * @var array
36
+	 */
37
+	protected $tca;
38
+
39
+	/**
40
+	 * @var string
41
+	 */
42
+	protected $tableName;
43
+
44
+	/**
45
+	 * All fields available in the Grid.
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $fields;
50
+
51
+	/**
52
+	 * All fields regardless whether they have been excluded or not.
53
+	 *
54
+	 * @var array
55
+	 */
56
+	protected $allFields;
57
+
58
+	/**
59
+	 * @var array
60
+	 */
61
+	protected $instances;
62
+
63
+	/**
64
+	 * @var array
65
+	 */
66
+	protected $facets;
67
+
68
+	/**
69
+	 * __construct
70
+	 *
71
+	 * @throws InvalidKeyInArrayException
72
+	 * @param string $tableName
73
+	 * @return \Fab\Vidi\Tca\GridService
74
+	 */
75
+	public function __construct($tableName)
76
+	{
77
+
78
+		$this->tableName = $tableName;
79
+
80
+		if (empty($GLOBALS['TCA'][$this->tableName])) {
81
+			throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108);
82
+		}
83
+
84
+		$this->tca = $GLOBALS['TCA'][$this->tableName]['grid'];
85
+	}
86
+
87
+	/**
88
+	 * Returns an array containing column names.
89
+	 *
90
+	 * @return array
91
+	 */
92
+	public function getFieldNames()
93
+	{
94
+		$fields = $this->getFields();
95
+		return array_keys($fields);
96
+	}
97
+
98
+	/**
99
+	 * Returns an array containing column names.
100
+	 *
101
+	 * @return array
102
+	 */
103
+	public function getAllFieldNames()
104
+	{
105
+		$allFields = $this->getAllFields();
106
+		return array_keys($allFields);
107
+	}
108
+
109
+	/**
110
+	 * Get the label key.
111
+	 *
112
+	 * @param string $fieldNameAndPath
113
+	 * @return string
114
+	 */
115
+	public function getLabelKey($fieldNameAndPath)
116
+	{
117
+
118
+		$field = $this->getField($fieldNameAndPath);
119
+
120
+		// First option is to get the label from the Grid TCA.
121
+		$rawLabel = '';
122
+		if (isset($field['label'])) {
123
+			$rawLabel = $field['label'];
124
+		}
125
+
126
+		// Second option is to fetch the label from the Column Renderer object.
127
+		if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) {
128
+			$renderers = $this->getRenderers($fieldNameAndPath);
129
+			/** @var $renderer ColumnRendererInterface */
130
+			foreach ($renderers as $renderer) {
131
+				if (isset($renderer['label'])) {
132
+					$rawLabel = $renderer['label'];
133
+					break;
134
+				}
135
+			}
136
+		}
137
+		return $rawLabel;
138
+	}
139
+
140
+	/**
141
+	 * Get the translation of a label given a column name.
142
+	 *
143
+	 * @param string $fieldNameAndPath
144
+	 * @return string
145
+	 */
146
+	public function getLabel($fieldNameAndPath)
147
+	{
148
+		$label = '';
149
+		if ($this->hasLabel($fieldNameAndPath)) {
150
+			$labelKey = $this->getLabelKey($fieldNameAndPath);
151
+			$label = LocalizationUtility::translate($labelKey, '');
152
+			if (is_null($label)) {
153
+				$label = $labelKey;
154
+			}
155
+		} else {
156
+
157
+			// Important to notice the label can contains a path, e.g. metadata.categories and must be resolved.
158
+			$dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName);
159
+			$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName);
160
+			$table = Tca::table($dataType);
161
+
162
+			if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) {
163
+				$label = $table->field($fieldName)->getLabel();
164
+			}
165
+		}
166
+
167
+		return $label;
168
+	}
169
+
170
+	/**
171
+	 * Returns the field name given its position.
172
+	 *
173
+	 * @param string $position the position of the field in the grid
174
+	 * @throws InvalidKeyInArrayException
175
+	 * @return int
176
+	 */
177
+	public function getFieldNameByPosition($position)
178
+	{
179
+		$fields = array_keys($this->getFields());
180
+		if (empty($fields[$position])) {
181
+			throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119);
182
+		}
183
+
184
+		return $fields[$position];
185
+	}
186
+
187
+	/**
188
+	 * Returns a field name.
189
+	 *
190
+	 * @param string $fieldName
191
+	 * @return array
192
+	 * @throws InvalidKeyInArrayException
193
+	 */
194
+	public function getField($fieldName)
195
+	{
196
+		$fields = $this->getFields();
197
+		return $fields[$fieldName];
198
+	}
199
+
200
+	/**
201
+	 * Returns an array containing column names for the Grid.
202
+	 *
203
+	 * @return array
204
+	 */
205
+	public function getFields()
206
+	{
207
+		// Cache this operation since it can take some time.
208
+		if (is_null($this->fields)) {
209
+
210
+			// Fetch all available fields first.
211
+			$fields = $this->getAllFields();
212
+
213
+			if ($this->isBackendMode()) {
214
+				// Then remove the not allowed.
215
+				$fields = $this->filterForBackendUser($fields);
216
+				$fields = $this->filterForConfiguration($fields);
217
+			}
218
+
219
+			$this->fields = $fields;
220
+		}
221
+
222
+		return $this->fields;
223
+	}
224
+
225
+	/**
226
+	 * Remove fields according to BE User permission.
227
+	 *
228
+	 * @param $fields
229
+	 * @return array
230
+	 * @throws \Exception
231
+	 */
232
+	protected function filterForBackendUser($fields)
233
+	{
234
+		if (!$this->getBackendUser()->isAdmin()) {
235
+			foreach ($fields as $fieldName => $field) {
236
+				if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) {
237
+					unset($fields[$fieldName]);
238
+				}
239
+			}
240
+		}
241
+		return $fields;
242
+	}
243
+
244
+	/**
245
+	 * Remove fields according to Grid configuration.
246
+	 *
247
+	 * @param $fields
248
+	 * @return array
249
+	 */
250
+	protected function filterForConfiguration($fields)
251
+	{
252
+
253
+		// Unset excluded fields.
254
+		foreach ($this->getExcludedFields() as $excludedField) {
255
+			if (isset($fields[$excludedField])) {
256
+				unset($fields[$excludedField]);
257
+			}
258
+		}
259
+
260
+		return $fields;
261
+	}
262
+
263
+	/**
264
+	 * Returns an array containing column names for the Grid.
265
+	 *
266
+	 * @return array
267
+	 */
268
+	public function getAllFields()
269
+	{
270
+
271
+		// Cache this operation since it can take some time.
272
+		if (is_null($this->allFields)) {
273
+
274
+			$fields = is_array($this->tca['columns']) ? $this->tca['columns'] : array();
275
+			$gridFieldNames = array_keys($fields);
276
+
277
+			// Fetch all fields of the TCA and merge it back to the fields configured for Grid.
278
+			$tableFieldNames = Tca::table($this->tableName)->getFields();
279
+
280
+			// Just remove system fields from the Grid.
281
+			foreach ($tableFieldNames as $key => $fieldName) {
282
+				if (in_array($fieldName, Tca::getSystemFields())) {
283
+					unset($tableFieldNames[$key]);
284
+				}
285
+			}
286
+
287
+			$additionalFields = array_diff($tableFieldNames, $gridFieldNames);
288
+
289
+			if (!empty($additionalFields)) {
290
+
291
+				// Pop out last element of the key
292
+				// Idea is to place new un-configured columns in between. By default, they will be hidden.
293
+				end($fields);
294
+				$lastColumnKey = key($fields);
295
+				$lastColumn = array_pop($fields);
296
+
297
+				// Feed up the grid fields with un configured elements
298
+				foreach ($additionalFields as $additionalField) {
299
+					$fields[$additionalField] = array(
300
+						'visible' => FALSE
301
+					);
302
+
303
+					// Try to guess the format of the field.
304
+					$fieldType = Tca::table($this->tableName)->field($additionalField)->getType();
305
+					if ($fieldType === FieldType::DATE) {
306
+						$fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date';
307
+					} elseif ($fieldType === FieldType::DATETIME) {
308
+						$fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime';
309
+					}
310
+				}
311
+				$fields[$lastColumnKey] = $lastColumn;
312
+			}
313
+
314
+			$this->allFields = $fields;
315
+		}
316
+
317
+		return $this->allFields;
318
+	}
319
+
320
+	/**
321
+	 * Tell whether the field exists in the grid or not.
322
+	 *
323
+	 * @param string $fieldName
324
+	 * @return bool
325
+	 */
326
+	public function hasField($fieldName)
327
+	{
328
+		$fields = $this->getFields();
329
+		return isset($fields[$fieldName]);
330
+	}
331
+
332
+	/**
333
+	 * Tell whether the facet exists in the grid or not.
334
+	 *
335
+	 * @param string $facetName
336
+	 * @return bool
337
+	 */
338
+	public function hasFacet($facetName)
339
+	{
340
+		$facets = $this->getFacets();
341
+		return isset($facets[$facetName]);
342
+	}
343
+
344
+	/**
345
+	 * Returns an array containing facets fields.
346
+	 *
347
+	 * @return FacetInterface[]
348
+	 */
349
+	public function getFacets()
350
+	{
351
+		if (is_null($this->facets)) {
352
+			$this->facets = array();
353
+
354
+			if (is_array($this->tca['facets'])) {
355
+				foreach ($this->tca['facets'] as $facetNameOrObject) {
356
+					if ($facetNameOrObject instanceof FacetInterface) {
357
+						$this->facets[$facetNameOrObject->getName()] = $facetNameOrObject;
358
+					} else {
359
+						$this->facets[$facetNameOrObject] = $this->instantiateStandardFacet($facetNameOrObject);
360
+					}
361
+				}
362
+			}
363
+		}
364
+		return $this->facets;
365
+	}
366
+
367
+	/**
368
+	 * Returns the "sortable" value of the column.
369
+	 *
370
+	 * @param string $fieldName
371
+	 * @return int|string
372
+	 */
373
+	public function isSortable($fieldName)
374
+	{
375
+		$defaultValue = TRUE;
376
+		$hasSortableField = Tca::table($this->tableName)->hasSortableField();
377
+		if ($hasSortableField) {
378
+			$isSortable = FALSE;
379
+		} else {
380
+			$isSortable = $this->get($fieldName, 'sortable', $defaultValue);
381
+		}
382
+		return $isSortable;
383
+	}
384
+
385
+	/**
386
+	 * Returns the "canBeHidden" value of the column.
387
+	 *
388
+	 * @param string $fieldName
389
+	 * @return bool
390
+	 */
391
+	public function canBeHidden($fieldName)
392
+	{
393
+		$defaultValue = TRUE;
394
+		return $this->get($fieldName, 'canBeHidden', $defaultValue);
395
+	}
396
+
397
+	/**
398
+	 * Returns the "width" value of the column.
399
+	 *
400
+	 * @param string $fieldName
401
+	 * @return int|string
402
+	 */
403
+	public function getWidth($fieldName)
404
+	{
405
+		$defaultValue = 'auto';
406
+		return $this->get($fieldName, 'width', $defaultValue);
407
+	}
408
+
409
+	/**
410
+	 * Returns the "visible" value of the column.
411
+	 *
412
+	 * @param string $fieldName
413
+	 * @return bool
414
+	 */
415
+	public function isVisible($fieldName)
416
+	{
417
+		$defaultValue = TRUE;
418
+		return $this->get($fieldName, 'visible', $defaultValue);
419
+	}
420
+
421
+	/**
422
+	 * Returns the "editable" value of the column.
423
+	 *
424
+	 * @param string $columnName
425
+	 * @return bool
426
+	 */
427
+	public function isEditable($columnName)
428
+	{
429
+		$defaultValue = FALSE;
430
+		return $this->get($columnName, 'editable', $defaultValue);
431
+	}
432
+
433
+	/**
434
+	 * Returns the "localized" value of the column.
435
+	 *
436
+	 * @param string $columnName
437
+	 * @return bool
438
+	 */
439
+	public function isLocalized($columnName)
440
+	{
441
+		$defaultValue = TRUE;
442
+		return $this->get($columnName, 'localized', $defaultValue);
443
+	}
444
+
445
+	/**
446
+	 *
447
+	 * Returns the "html" value of the column.
448
+	 *
449
+	 * @param string $fieldName
450
+	 * @return string
451
+	 */
452
+	public function getHeader($fieldName)
453
+	{
454
+		$defaultValue = '';
455
+		return $this->get($fieldName, 'html', $defaultValue);
456
+	}
457
+
458
+	/**
459
+	 * Fetch a possible from a Grid Renderer. If no value is found, returns NULL
460
+	 *
461
+	 * @param string $fieldName
462
+	 * @param string $key
463
+	 * @param mixed $defaultValue
464
+	 * @return NULL|mixed
465
+	 */
466
+	public function get($fieldName, $key, $defaultValue = NULL)
467
+	{
468
+		$value = $defaultValue;
469
+
470
+		$field = $this->getField($fieldName);
471
+		if (isset($field[$key])) {
472
+			$value = $field[$key];
473
+		} elseif ($this->hasRenderers($fieldName)) {
474
+			$renderers = $this->getRenderers($fieldName);
475
+			foreach ($renderers as $rendererConfiguration) {
476
+				if (isset($rendererConfiguration[$key])) {
477
+					$value = $rendererConfiguration[$key];
478
+				}
479
+			}
480
+		}
481
+		return $value;
482
+	}
483
+
484
+	/**
485
+	 * Returns whether the column has a renderer.
486
+	 *
487
+	 * @param string $fieldName
488
+	 * @return bool
489
+	 */
490
+	public function hasRenderers($fieldName)
491
+	{
492
+		$field = $this->getField($fieldName);
493
+		return empty($field['renderer']) && empty($field['renderers']) ? FALSE : TRUE;
494
+	}
495
+
496
+	/**
497
+	 * Returns a renderer.
498
+	 *
499
+	 * @param string $fieldName
500
+	 * @return array
501
+	 */
502
+	public function getRenderers($fieldName)
503
+	{
504
+		$field = $this->getField($fieldName);
505
+		$renderers = array();
506
+		if (!empty($field['renderer'])) {
507
+			$renderers = $this->convertRendererToArray($field['renderer']);
508
+		} elseif (!empty($field['renderers']) && is_array($field['renderers'])) {
509
+			foreach ($field['renderers'] as $renderer) {
510
+				$rendererNameAndConfiguration = $this->convertRendererToArray($renderer);
511
+				$renderers = array_merge($renderers, $rendererNameAndConfiguration);
512
+			}
513
+		}
514
+
515
+		return $renderers;
516
+	}
517
+
518
+	/**
519
+	 * @param string|GenericColumn $renderer
520
+	 * @return array
521
+	 */
522
+	public function convertRendererToArray($renderer)
523
+	{
524
+		$result = array();
525
+		if (is_string($renderer)) {
526
+			$result[$renderer] = array();
527
+		} elseif ($renderer instanceof ColumnInterface || $renderer instanceof ColumnRendererInterface) {
528
+			/** @var GenericColumn $renderer */
529
+			$result[get_class($renderer)] = $renderer->getConfiguration();
530
+		}
531
+		return $result;
532
+	}
533
+
534
+	/**
535
+	 * Returns the class names applied to a cell
536
+	 *
537
+	 * @param string $fieldName
538
+	 * @return bool
539
+	 */
540
+	public function getClass($fieldName)
541
+	{
542
+		$field = $this->getField($fieldName);
543
+		return isset($field['class']) ? $field['class'] : '';
544
+	}
545
+
546
+	/**
547
+	 * Returns whether the column has a label.
548
+	 *
549
+	 * @param string $fieldNameAndPath
550
+	 * @return bool
551
+	 */
552
+	public function hasLabel($fieldNameAndPath)
553
+	{
554
+		$field = $this->getField($fieldNameAndPath);
555
+
556
+		$hasLabel = empty($field['label']) ? FALSE : TRUE;
557
+
558
+		if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) {
559
+			$renderers = $this->getRenderers($fieldNameAndPath);
560
+			/** @var $renderer ColumnRendererInterface */
561
+			foreach ($renderers as $renderer) {
562
+				if (isset($renderer['label'])) {
563
+					$hasLabel = TRUE;
564
+					break;
565
+				}
566
+			}
567
+		}
568
+		return $hasLabel;
569
+	}
570
+
571
+	/**
572
+	 * @return array
573
+	 */
574
+	public function getTca()
575
+	{
576
+		return $this->tca;
577
+	}
578
+
579
+	/**
580
+	 * Return excluded fields from configuration + preferences.
581
+	 *
582
+	 * @return array
583
+	 */
584
+	public function getExcludedFields()
585
+	{
586
+		$configurationFields = $this->getExcludedFieldsFromConfiguration();
587
+		$preferencesFields = $this->getExcludedFieldsFromPreferences();
588
+
589
+		return array_merge($configurationFields, $preferencesFields);
590
+	}
591
+
592
+	/**
593
+	 * Fetch excluded fields from configuration.
594
+	 *
595
+	 * @return array
596
+	 */
597
+	protected function getExcludedFieldsFromConfiguration()
598
+	{
599
+		$excludedFields = array();
600
+		if (!empty($this->tca['excluded_fields'])) {
601
+			$excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], TRUE);
602
+		} elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason.
603
+			$excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], TRUE);
604
+		}
605
+		return $excludedFields;
606
+
607
+	}
608
+
609
+	/**
610
+	 * Fetch excluded fields from preferences.
611
+	 *
612
+	 * @return array
613
+	 */
614
+	protected function getExcludedFieldsFromPreferences()
615
+	{
616
+		$excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName);
617
+		return is_array($excludedFields) ? $excludedFields : array();
618
+	}
619
+
620
+	/**
621
+	 * @return array
622
+	 */
623
+	public function areFilesIncludedInExport()
624
+	{
625
+		$isIncluded = TRUE;
626
+
627
+		if (isset($this->tca['export']['include_files'])) {
628
+			$isIncluded = $this->tca['export']['include_files'];
629
+		}
630
+		return $isIncluded;
631
+	}
632
+
633
+	/**
634
+	 * Returns a "facet" service instance.
635
+	 *
636
+	 * @param string|FacetInterface $facetName
637
+	 * @return StandardFacet
638
+	 */
639
+	protected function instantiateStandardFacet($facetName)
640
+	{
641
+		$label = $this->getLabel($facetName);
642
+
643
+		/** @var StandardFacet $facetName */
644
+		$facet = GeneralUtility::makeInstance('Fab\Vidi\Facet\StandardFacet', $facetName, $label);
645
+
646
+		if (!$facet instanceof StandardFacet) {
647
+			throw new \RuntimeException('I could not instantiate a facet for facet name "' . (string)$facet . '""', 1445856345);
648
+		}
649
+		return $facet;
650
+	}
651
+
652
+	/**
653
+	 * Returns a "facet" service instance.
654
+	 *
655
+	 * @param string|FacetInterface $facetName
656
+	 * @return FacetInterface
657
+	 */
658
+	public function facet($facetName = '')
659
+	{
660
+		$facets = $this->getFacets();
661
+		return $facets[$facetName];
662
+	}
663
+
664
+	/**
665
+	 * @return \Fab\Vidi\Resolver\FieldPathResolver
666
+	 */
667
+	protected function getFieldPathResolver()
668
+	{
669
+		return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
670
+	}
671
+
672
+	/**
673
+	 * @return ModulePreferences
674
+	 */
675
+	protected function getModulePreferences()
676
+	{
677
+		return GeneralUtility::makeInstance('Fab\Vidi\Module\ModulePreferences');
678
+	}
679 679
 
680 680
 }
Please login to merge, or discard this patch.
Classes/Tca/TableService.php 2 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      * Tell whether the table has a label field.
65 65
      *
66 66
      * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
67
-     * @return string
67
+     * @return boolean
68 68
      */
69 69
     public function hasLabelField()
70 70
     {
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
     /**
303 303
      * Tell whether we have a field "sorting".
304 304
      *
305
-     * @return array
305
+     * @return boolean
306 306
      */
307 307
     public function hasSortableField()
308 308
     {
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
      * Tell whether the field exists or not.
314 314
      *
315 315
      * @param string $fieldName
316
-     * @return array
316
+     * @return boolean
317 317
      */
318 318
     public function hasField($fieldName)
319 319
     {
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
      * Tells whether the $key exists.
350 350
      *
351 351
      * @param string $key
352
-     * @return string
352
+     * @return boolean
353 353
      */
354 354
     public function has($key)
355 355
     {
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
     /**
360 360
      * Tells whether the table name has "workspace" support.
361 361
      *
362
-     * @return string
362
+     * @return boolean
363 363
      */
364 364
     public function hasWorkspaceSupport()
365 365
     {
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
     /**
370 370
      * Tells whether the table name has "language" support.
371 371
      *
372
-     * @return string
372
+     * @return boolean
373 373
      */
374 374
     public function hasLanguageSupport()
375 375
     {
Please login to merge, or discard this patch.
Indentation   +434 added lines, -434 removed lines patch added patch discarded remove patch
@@ -25,439 +25,439 @@
 block discarded – undo
25 25
 class TableService extends AbstractTca
26 26
 {
27 27
 
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $tca;
32
-
33
-    /**
34
-     * @var array
35
-     */
36
-    protected $columnTca;
37
-
38
-    /**
39
-     * @var string
40
-     */
41
-    protected $tableName;
42
-
43
-    /**
44
-     * @var array
45
-     */
46
-    protected $instances;
47
-
48
-    /**
49
-     * @throws InvalidKeyInArrayException
50
-     * @param string $tableName
51
-     * @return \Fab\Vidi\Tca\TableService
52
-     */
53
-    public function __construct($tableName)
54
-    {
55
-        $this->tableName = $tableName;
56
-        if (empty($GLOBALS['TCA'][$this->tableName])) {
57
-            throw new InvalidKeyInArrayException(sprintf('No TCA existence for table "%s"', $this->tableName), 1356945106);
58
-        }
59
-        $this->tca = $GLOBALS['TCA'][$this->tableName]['ctrl'];
60
-        $this->columnTca = $GLOBALS['TCA'][$this->tableName]['columns'];
61
-    }
62
-
63
-    /**
64
-     * Tell whether the table has a label field.
65
-     *
66
-     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
67
-     * @return string
68
-     */
69
-    public function hasLabelField()
70
-    {
71
-        return $this->has('label');
72
-    }
73
-
74
-    /**
75
-     * Get the label name of table name.
76
-     *
77
-     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
78
-     * @return string
79
-     */
80
-    public function getLabelField()
81
-    {
82
-        $labelField = $this->get('label');
83
-        if (empty($labelField)) {
84
-            throw new InvalidKeyInArrayException(sprintf('No label configured for table "%s"', $this->tableName), 1385586726);
85
-        }
86
-        return $labelField;
87
-    }
88
-
89
-    /**
90
-     * Returns the translated label of the table name.
91
-     *
92
-     * @return string
93
-     */
94
-    public function getLabel()
95
-    {
96
-        $result = LocalizationUtility::translate($this->getLabelField(), '');
97
-        if (!$result) {
98
-            $result = $this->getLabelField();
99
-        }
100
-        return $result;
101
-    }
102
-
103
-    /**
104
-     * Returns the title of the table.
105
-     *
106
-     * @return string
107
-     */
108
-    public function getTitle()
109
-    {
110
-        $result = LocalizationUtility::translate($this->get('title'), '');
111
-        if (!$result) {
112
-            $result = $this->get('title');
113
-        }
114
-        return $result;
115
-    }
116
-
117
-    /**
118
-     * Return the "disabled" field.
119
-     *
120
-     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
121
-     * @return string|NULL
122
-     */
123
-    public function getHiddenField()
124
-    {
125
-        $hiddenField = NULL;
126
-        $enableColumns = $this->get('enablecolumns');
127
-        if (is_array($enableColumns) && !empty($enableColumns['disabled'])) {
128
-            $hiddenField = $enableColumns['disabled'];
129
-        }
130
-        return $hiddenField;
131
-    }
132
-
133
-    /**
134
-     * Return the "starttime" field.
135
-     *
136
-     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
137
-     * @return string|NULL
138
-     */
139
-    public function getStartTimeField()
140
-    {
141
-        $startTimeField = NULL;
142
-        $enableColumns = $this->get('enablecolumns');
143
-        if (is_array($enableColumns) && !empty($enableColumns['starttime'])) {
144
-            $startTimeField = $enableColumns['starttime'];
145
-        }
146
-        return $startTimeField;
147
-    }
148
-
149
-    /**
150
-     * Return the "endtime" field.
151
-     *
152
-     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
153
-     * @return string|NULL
154
-     */
155
-    public function getEndTimeField()
156
-    {
157
-        $endTimeField = NULL;
158
-        $enableColumns = $this->get('enablecolumns');
159
-        if (is_array($enableColumns) && !empty($enableColumns['endtime'])) {
160
-            $endTimeField = $enableColumns['endtime'];
161
-        }
162
-        return $endTimeField;
163
-    }
164
-
165
-    /**
166
-     * Tells whether the table is hidden.
167
-     *
168
-     * @return bool
169
-     */
170
-    public function isHidden()
171
-    {
172
-        return isset($this->tca['hideTable']) ? $this->tca['hideTable'] : FALSE;
173
-    }
174
-
175
-    /**
176
-     * Tells whether the table is not hidden.
177
-     *
178
-     * @return bool
179
-     */
180
-    public function isNotHidden()
181
-    {
182
-        return !$this->isHidden();
183
-    }
184
-
185
-    /**
186
-     * Get the "deleted" field for the table.
187
-     *
188
-     * @return string|NULL
189
-     */
190
-    public function getDeletedField()
191
-    {
192
-        return $this->get('delete');
193
-    }
194
-
195
-    /**
196
-     * Get the modification time stamp field.
197
-     *
198
-     * @return string|NULL
199
-     */
200
-    public function getTimeModificationField()
201
-    {
202
-        return $this->get('tstamp');
203
-    }
204
-
205
-    /**
206
-     * Get the creation time stamp field.
207
-     *
208
-     * @return string|NULL
209
-     */
210
-    public function getTimeCreationField()
211
-    {
212
-        return $this->get('crdate');
213
-    }
214
-
215
-    /**
216
-     * Get the language field for the table.
217
-     *
218
-     * @return string|NULL
219
-     */
220
-    public function getLanguageField()
221
-    {
222
-        return $this->get('languageField');
223
-    }
224
-
225
-    /**
226
-     * Get the field which points to the parent.
227
-     *
228
-     * @return string|NULL
229
-     */
230
-    public function getLanguageParentField()
231
-    {
232
-        return $this->get('transOrigPointerField');
233
-    }
234
-
235
-    /**
236
-     * Returns the default order in the form of a SQL segment.
237
-     *
238
-     * @return string|NULL
239
-     */
240
-    public function getDefaultOrderSql()
241
-    {
242
-        // "sortby" typically has "sorting" as value.
243
-        $order = $this->get('sortby') ? $this->get('sortby') . ' ASC' : $this->get('default_sortby');
244
-        return $order;
245
-    }
246
-
247
-    /**
248
-     * Returns the parsed default orderings.
249
-     * Returns array looks like array('title' => 'ASC');
250
-     *
251
-     * @return array
252
-     */
253
-    public function getDefaultOrderings()
254
-    {
255
-
256
-        // first clean up the sql segment
257
-        $defaultOrder = str_replace('ORDER BY', '', $this->getDefaultOrderSql());
258
-        $defaultOrderParts = GeneralUtility::trimExplode(',', $defaultOrder, TRUE);
259
-
260
-        $orderings = array();
261
-        foreach ($defaultOrderParts as $defaultOrderPart) {
262
-            $parts = GeneralUtility::trimExplode(' ', $defaultOrderPart);
263
-            if (empty($parts[1])) {
264
-                $parts[1] = QueryInterface::ORDER_DESCENDING;
265
-            }
266
-            $orderings[$parts[0]] = $parts[1];
267
-        }
268
-
269
-        return $orderings;
270
-    }
271
-
272
-    /**
273
-     * Returns the searchable fields.
274
-     *
275
-     * @return string|NULL
276
-     */
277
-    public function getSearchFields()
278
-    {
279
-        return $this->get('searchFields');
280
-    }
281
-
282
-    /**
283
-     * Returns an array containing the field names.
284
-     *
285
-     * @return array
286
-     */
287
-    public function getFields()
288
-    {
289
-        return array_keys($this->columnTca);
290
-    }
291
-
292
-    /**
293
-     * Returns an array containing the fields and their configuration.
294
-     *
295
-     * @return array
296
-     */
297
-    public function getFieldsAndConfiguration()
298
-    {
299
-        return $this->columnTca;
300
-    }
301
-
302
-    /**
303
-     * Tell whether we have a field "sorting".
304
-     *
305
-     * @return array
306
-     */
307
-    public function hasSortableField()
308
-    {
309
-        return $this->has('sortby');
310
-    }
311
-
312
-    /**
313
-     * Tell whether the field exists or not.
314
-     *
315
-     * @param string $fieldName
316
-     * @return array
317
-     */
318
-    public function hasField($fieldName)
319
-    {
320
-        if ($this->isComposite($fieldName)) {
321
-            $parts = explode('.', $fieldName);
322
-            $strippedFieldName = $parts[0];
323
-            $tableName = $parts[1];
324
-
325
-            $hasField = $this->columnTca[$strippedFieldName] && isset($GLOBALS['TCA'][$tableName]);
326
-
327
-            // Continue checking that the $strippedFieldName is of type "group"
328
-            if (isset($GLOBALS['TCA'][$this->tableName]['columns'][$strippedFieldName])) {
329
-                $hasField = Tca::table($this->tableName)->field($strippedFieldName)->isGroup(); // Group
330
-            }
331
-        } else {
332
-            $hasField = isset($this->columnTca[$fieldName]) || in_array($fieldName, Tca::getSystemFields());
333
-        }
334
-        return $hasField;
335
-    }
336
-
337
-    /**
338
-     * Tell whether the field name contains a path, e.g. metadata.title
339
-     *
340
-     * @param string $fieldName
341
-     * @return boolean
342
-     */
343
-    public function isComposite($fieldName)
344
-    {
345
-        return strpos($fieldName, '.') > 0;
346
-    }
347
-
348
-    /**
349
-     * Tells whether the $key exists.
350
-     *
351
-     * @param string $key
352
-     * @return string
353
-     */
354
-    public function has($key)
355
-    {
356
-        return isset($this->tca[$key]);
357
-    }
358
-
359
-    /**
360
-     * Tells whether the table name has "workspace" support.
361
-     *
362
-     * @return string
363
-     */
364
-    public function hasWorkspaceSupport()
365
-    {
366
-        return isset($this->tca['versioningWS']);
367
-    }
368
-
369
-    /**
370
-     * Tells whether the table name has "language" support.
371
-     *
372
-     * @return string
373
-     */
374
-    public function hasLanguageSupport()
375
-    {
376
-        return isset($this->tca['languageField']);
377
-    }
378
-
379
-    /**
380
-     * Return configuration value given a key.
381
-     *
382
-     * @param string $key
383
-     * @return string|NULL
384
-     */
385
-    public function get($key)
386
-    {
387
-        return $this->has($key) ? $this->tca[$key] : NULL;
388
-    }
389
-
390
-    /**
391
-     * @return array
392
-     */
393
-    public function getTca()
394
-    {
395
-        return $this->tca;
396
-    }
397
-
398
-    /**
399
-     * Tell whether the current BE User has access to this field.
400
-     *
401
-     * @return bool
402
-     */
403
-    public function hasAccess()
404
-    {
405
-        $hasAccess = TRUE;
406
-        if ($this->isBackendMode()) {
407
-            $hasAccess = $this->getBackendUser()->check('tables_modify', $this->tableName);
408
-        }
409
-        return $hasAccess;
410
-    }
411
-
412
-    /**
413
-     * @param string $fieldName
414
-     * @throws \Exception
415
-     * @return \Fab\Vidi\Tca\FieldService
416
-     */
417
-    public function field($fieldName)
418
-    {
419
-
420
-        // In case field contains items.tx_table for field type "group"
421
-        $compositeField = '';
422
-        if (strpos($fieldName, '.') !== FALSE) {
423
-            $compositeField = $fieldName;
424
-            $fieldParts = explode('.', $compositeField, 2);
425
-            $fieldName = $fieldParts[0];
426
-
427
-            // Special when field has been instantiated without the field name and path.
428
-            if (!empty($this->instances[$fieldName])) {
429
-                /** @var FieldService $field */
430
-                $field = $this->instances[$fieldName];
431
-                $field->setCompositeField($compositeField);
432
-            }
433
-        }
434
-
435
-        // True for system fields such as uid, pid that don't necessarily have a TCA.
436
-        if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) {
437
-            $this->columnTca[$fieldName] = array();
438
-        } elseif (empty($this->columnTca[$fieldName])) {
439
-            $message = sprintf(
440
-                'Does the field really exist? No TCA entry found for field "%s" for table "%s"',
441
-                $fieldName,
442
-                $this->tableName
443
-            );
444
-            throw new \Exception($message, 1385554481);
445
-        }
446
-
447
-
448
-        if (empty($this->instances[$fieldName])) {
449
-
450
-            $instance = GeneralUtility::makeInstance(
451
-                'Fab\Vidi\Tca\FieldService',
452
-                $fieldName,
453
-                $this->columnTca[$fieldName],
454
-                $this->tableName,
455
-                $compositeField
456
-            );
457
-
458
-            $this->instances[$fieldName] = $instance;
459
-        }
460
-        return $this->instances[$fieldName];
461
-    }
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $tca;
32
+
33
+	/**
34
+	 * @var array
35
+	 */
36
+	protected $columnTca;
37
+
38
+	/**
39
+	 * @var string
40
+	 */
41
+	protected $tableName;
42
+
43
+	/**
44
+	 * @var array
45
+	 */
46
+	protected $instances;
47
+
48
+	/**
49
+	 * @throws InvalidKeyInArrayException
50
+	 * @param string $tableName
51
+	 * @return \Fab\Vidi\Tca\TableService
52
+	 */
53
+	public function __construct($tableName)
54
+	{
55
+		$this->tableName = $tableName;
56
+		if (empty($GLOBALS['TCA'][$this->tableName])) {
57
+			throw new InvalidKeyInArrayException(sprintf('No TCA existence for table "%s"', $this->tableName), 1356945106);
58
+		}
59
+		$this->tca = $GLOBALS['TCA'][$this->tableName]['ctrl'];
60
+		$this->columnTca = $GLOBALS['TCA'][$this->tableName]['columns'];
61
+	}
62
+
63
+	/**
64
+	 * Tell whether the table has a label field.
65
+	 *
66
+	 * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
67
+	 * @return string
68
+	 */
69
+	public function hasLabelField()
70
+	{
71
+		return $this->has('label');
72
+	}
73
+
74
+	/**
75
+	 * Get the label name of table name.
76
+	 *
77
+	 * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
78
+	 * @return string
79
+	 */
80
+	public function getLabelField()
81
+	{
82
+		$labelField = $this->get('label');
83
+		if (empty($labelField)) {
84
+			throw new InvalidKeyInArrayException(sprintf('No label configured for table "%s"', $this->tableName), 1385586726);
85
+		}
86
+		return $labelField;
87
+	}
88
+
89
+	/**
90
+	 * Returns the translated label of the table name.
91
+	 *
92
+	 * @return string
93
+	 */
94
+	public function getLabel()
95
+	{
96
+		$result = LocalizationUtility::translate($this->getLabelField(), '');
97
+		if (!$result) {
98
+			$result = $this->getLabelField();
99
+		}
100
+		return $result;
101
+	}
102
+
103
+	/**
104
+	 * Returns the title of the table.
105
+	 *
106
+	 * @return string
107
+	 */
108
+	public function getTitle()
109
+	{
110
+		$result = LocalizationUtility::translate($this->get('title'), '');
111
+		if (!$result) {
112
+			$result = $this->get('title');
113
+		}
114
+		return $result;
115
+	}
116
+
117
+	/**
118
+	 * Return the "disabled" field.
119
+	 *
120
+	 * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
121
+	 * @return string|NULL
122
+	 */
123
+	public function getHiddenField()
124
+	{
125
+		$hiddenField = NULL;
126
+		$enableColumns = $this->get('enablecolumns');
127
+		if (is_array($enableColumns) && !empty($enableColumns['disabled'])) {
128
+			$hiddenField = $enableColumns['disabled'];
129
+		}
130
+		return $hiddenField;
131
+	}
132
+
133
+	/**
134
+	 * Return the "starttime" field.
135
+	 *
136
+	 * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
137
+	 * @return string|NULL
138
+	 */
139
+	public function getStartTimeField()
140
+	{
141
+		$startTimeField = NULL;
142
+		$enableColumns = $this->get('enablecolumns');
143
+		if (is_array($enableColumns) && !empty($enableColumns['starttime'])) {
144
+			$startTimeField = $enableColumns['starttime'];
145
+		}
146
+		return $startTimeField;
147
+	}
148
+
149
+	/**
150
+	 * Return the "endtime" field.
151
+	 *
152
+	 * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
153
+	 * @return string|NULL
154
+	 */
155
+	public function getEndTimeField()
156
+	{
157
+		$endTimeField = NULL;
158
+		$enableColumns = $this->get('enablecolumns');
159
+		if (is_array($enableColumns) && !empty($enableColumns['endtime'])) {
160
+			$endTimeField = $enableColumns['endtime'];
161
+		}
162
+		return $endTimeField;
163
+	}
164
+
165
+	/**
166
+	 * Tells whether the table is hidden.
167
+	 *
168
+	 * @return bool
169
+	 */
170
+	public function isHidden()
171
+	{
172
+		return isset($this->tca['hideTable']) ? $this->tca['hideTable'] : FALSE;
173
+	}
174
+
175
+	/**
176
+	 * Tells whether the table is not hidden.
177
+	 *
178
+	 * @return bool
179
+	 */
180
+	public function isNotHidden()
181
+	{
182
+		return !$this->isHidden();
183
+	}
184
+
185
+	/**
186
+	 * Get the "deleted" field for the table.
187
+	 *
188
+	 * @return string|NULL
189
+	 */
190
+	public function getDeletedField()
191
+	{
192
+		return $this->get('delete');
193
+	}
194
+
195
+	/**
196
+	 * Get the modification time stamp field.
197
+	 *
198
+	 * @return string|NULL
199
+	 */
200
+	public function getTimeModificationField()
201
+	{
202
+		return $this->get('tstamp');
203
+	}
204
+
205
+	/**
206
+	 * Get the creation time stamp field.
207
+	 *
208
+	 * @return string|NULL
209
+	 */
210
+	public function getTimeCreationField()
211
+	{
212
+		return $this->get('crdate');
213
+	}
214
+
215
+	/**
216
+	 * Get the language field for the table.
217
+	 *
218
+	 * @return string|NULL
219
+	 */
220
+	public function getLanguageField()
221
+	{
222
+		return $this->get('languageField');
223
+	}
224
+
225
+	/**
226
+	 * Get the field which points to the parent.
227
+	 *
228
+	 * @return string|NULL
229
+	 */
230
+	public function getLanguageParentField()
231
+	{
232
+		return $this->get('transOrigPointerField');
233
+	}
234
+
235
+	/**
236
+	 * Returns the default order in the form of a SQL segment.
237
+	 *
238
+	 * @return string|NULL
239
+	 */
240
+	public function getDefaultOrderSql()
241
+	{
242
+		// "sortby" typically has "sorting" as value.
243
+		$order = $this->get('sortby') ? $this->get('sortby') . ' ASC' : $this->get('default_sortby');
244
+		return $order;
245
+	}
246
+
247
+	/**
248
+	 * Returns the parsed default orderings.
249
+	 * Returns array looks like array('title' => 'ASC');
250
+	 *
251
+	 * @return array
252
+	 */
253
+	public function getDefaultOrderings()
254
+	{
255
+
256
+		// first clean up the sql segment
257
+		$defaultOrder = str_replace('ORDER BY', '', $this->getDefaultOrderSql());
258
+		$defaultOrderParts = GeneralUtility::trimExplode(',', $defaultOrder, TRUE);
259
+
260
+		$orderings = array();
261
+		foreach ($defaultOrderParts as $defaultOrderPart) {
262
+			$parts = GeneralUtility::trimExplode(' ', $defaultOrderPart);
263
+			if (empty($parts[1])) {
264
+				$parts[1] = QueryInterface::ORDER_DESCENDING;
265
+			}
266
+			$orderings[$parts[0]] = $parts[1];
267
+		}
268
+
269
+		return $orderings;
270
+	}
271
+
272
+	/**
273
+	 * Returns the searchable fields.
274
+	 *
275
+	 * @return string|NULL
276
+	 */
277
+	public function getSearchFields()
278
+	{
279
+		return $this->get('searchFields');
280
+	}
281
+
282
+	/**
283
+	 * Returns an array containing the field names.
284
+	 *
285
+	 * @return array
286
+	 */
287
+	public function getFields()
288
+	{
289
+		return array_keys($this->columnTca);
290
+	}
291
+
292
+	/**
293
+	 * Returns an array containing the fields and their configuration.
294
+	 *
295
+	 * @return array
296
+	 */
297
+	public function getFieldsAndConfiguration()
298
+	{
299
+		return $this->columnTca;
300
+	}
301
+
302
+	/**
303
+	 * Tell whether we have a field "sorting".
304
+	 *
305
+	 * @return array
306
+	 */
307
+	public function hasSortableField()
308
+	{
309
+		return $this->has('sortby');
310
+	}
311
+
312
+	/**
313
+	 * Tell whether the field exists or not.
314
+	 *
315
+	 * @param string $fieldName
316
+	 * @return array
317
+	 */
318
+	public function hasField($fieldName)
319
+	{
320
+		if ($this->isComposite($fieldName)) {
321
+			$parts = explode('.', $fieldName);
322
+			$strippedFieldName = $parts[0];
323
+			$tableName = $parts[1];
324
+
325
+			$hasField = $this->columnTca[$strippedFieldName] && isset($GLOBALS['TCA'][$tableName]);
326
+
327
+			// Continue checking that the $strippedFieldName is of type "group"
328
+			if (isset($GLOBALS['TCA'][$this->tableName]['columns'][$strippedFieldName])) {
329
+				$hasField = Tca::table($this->tableName)->field($strippedFieldName)->isGroup(); // Group
330
+			}
331
+		} else {
332
+			$hasField = isset($this->columnTca[$fieldName]) || in_array($fieldName, Tca::getSystemFields());
333
+		}
334
+		return $hasField;
335
+	}
336
+
337
+	/**
338
+	 * Tell whether the field name contains a path, e.g. metadata.title
339
+	 *
340
+	 * @param string $fieldName
341
+	 * @return boolean
342
+	 */
343
+	public function isComposite($fieldName)
344
+	{
345
+		return strpos($fieldName, '.') > 0;
346
+	}
347
+
348
+	/**
349
+	 * Tells whether the $key exists.
350
+	 *
351
+	 * @param string $key
352
+	 * @return string
353
+	 */
354
+	public function has($key)
355
+	{
356
+		return isset($this->tca[$key]);
357
+	}
358
+
359
+	/**
360
+	 * Tells whether the table name has "workspace" support.
361
+	 *
362
+	 * @return string
363
+	 */
364
+	public function hasWorkspaceSupport()
365
+	{
366
+		return isset($this->tca['versioningWS']);
367
+	}
368
+
369
+	/**
370
+	 * Tells whether the table name has "language" support.
371
+	 *
372
+	 * @return string
373
+	 */
374
+	public function hasLanguageSupport()
375
+	{
376
+		return isset($this->tca['languageField']);
377
+	}
378
+
379
+	/**
380
+	 * Return configuration value given a key.
381
+	 *
382
+	 * @param string $key
383
+	 * @return string|NULL
384
+	 */
385
+	public function get($key)
386
+	{
387
+		return $this->has($key) ? $this->tca[$key] : NULL;
388
+	}
389
+
390
+	/**
391
+	 * @return array
392
+	 */
393
+	public function getTca()
394
+	{
395
+		return $this->tca;
396
+	}
397
+
398
+	/**
399
+	 * Tell whether the current BE User has access to this field.
400
+	 *
401
+	 * @return bool
402
+	 */
403
+	public function hasAccess()
404
+	{
405
+		$hasAccess = TRUE;
406
+		if ($this->isBackendMode()) {
407
+			$hasAccess = $this->getBackendUser()->check('tables_modify', $this->tableName);
408
+		}
409
+		return $hasAccess;
410
+	}
411
+
412
+	/**
413
+	 * @param string $fieldName
414
+	 * @throws \Exception
415
+	 * @return \Fab\Vidi\Tca\FieldService
416
+	 */
417
+	public function field($fieldName)
418
+	{
419
+
420
+		// In case field contains items.tx_table for field type "group"
421
+		$compositeField = '';
422
+		if (strpos($fieldName, '.') !== FALSE) {
423
+			$compositeField = $fieldName;
424
+			$fieldParts = explode('.', $compositeField, 2);
425
+			$fieldName = $fieldParts[0];
426
+
427
+			// Special when field has been instantiated without the field name and path.
428
+			if (!empty($this->instances[$fieldName])) {
429
+				/** @var FieldService $field */
430
+				$field = $this->instances[$fieldName];
431
+				$field->setCompositeField($compositeField);
432
+			}
433
+		}
434
+
435
+		// True for system fields such as uid, pid that don't necessarily have a TCA.
436
+		if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) {
437
+			$this->columnTca[$fieldName] = array();
438
+		} elseif (empty($this->columnTca[$fieldName])) {
439
+			$message = sprintf(
440
+				'Does the field really exist? No TCA entry found for field "%s" for table "%s"',
441
+				$fieldName,
442
+				$this->tableName
443
+			);
444
+			throw new \Exception($message, 1385554481);
445
+		}
446
+
447
+
448
+		if (empty($this->instances[$fieldName])) {
449
+
450
+			$instance = GeneralUtility::makeInstance(
451
+				'Fab\Vidi\Tca\FieldService',
452
+				$fieldName,
453
+				$this->columnTca[$fieldName],
454
+				$this->tableName,
455
+				$compositeField
456
+			);
457
+
458
+			$this->instances[$fieldName] = $instance;
459
+		}
460
+		return $this->instances[$fieldName];
461
+	}
462 462
 
463 463
 }
Please login to merge, or discard this patch.
Classes/View/Grid/Row.php 2 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.
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.