Completed
Push — master ( 080764...892a3f )
by Fabien
52:24
created
Classes/ViewHelpers/Content/AbstractContentViewHelper.php 1 patch
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -27,214 +27,214 @@
 block discarded – undo
27 27
 abstract class AbstractContentViewHelper extends AbstractViewHelper
28 28
 {
29 29
 
30
-    /**
31
-     * @return void
32
-     * @throws Exception
33
-     */
34
-    public function initializeArguments()
35
-    {
36
-        $this->registerArgument('type', 'string', 'Corresponds to the type of data to be fetched. It will basically be a table name e.g. fe_users.', false, '');
37
-        $this->registerArgument('matches', 'array', 'Key / value array to be used as filter. The key corresponds to a field name.', false, array());
38
-        $this->registerArgument('selection', 'int', 'A possible selection defined in the BE and stored in the database.', false, 0);
39
-        $this->registerArgument('ignoreEnableFields', 'bool', 'Whether to ignore enable fields or not (AKA hidden, deleted, starttime, ...).', false, false);
40
-        $this->registerArgument('aliases', 'array', 'Attribute "matches" does not support certain character such as "." in field name. Use this to create aliases.', false, array());
41
-    }
42
-
43
-    /**
44
-     * Generate a signature to be used for storing the result set.
45
-     *
46
-     * @param string $dataType
47
-     * @param array $matches
48
-     * @param array $orderings
49
-     * @param $limit
50
-     * @param $offset
51
-     * @return string
52
-     */
53
-    protected function getQuerySignature($dataType, array $matches, array $orderings, $limit, $offset)
54
-    {
55
-        $serializedMatches = serialize($matches);
56
-        $serializedOrderings = serialize($orderings);
57
-        return md5($dataType . $serializedMatches . $serializedOrderings . $limit . $offset);
58
-    }
59
-
60
-    /**
61
-     * Returns a matcher object.
62
-     *
63
-     * @param string $dataType
64
-     * @param array $matches
65
-     * @return Matcher
66
-     * @throws NotExistingClassException
67
-     * @throws \InvalidArgumentException
68
-     */
69
-    protected function getMatcher($dataType, $matches = array())
70
-    {
71
-
72
-        /** @var $matcher Matcher */
73
-        $matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType);
74
-
75
-        // @todo implement advanced selection parsing {or: {usergroup.title: {like: foo}}, {tstamp: {greaterThan: 1234}}}
76
-        foreach ($matches as $fieldNameAndPath => $value) {
77
-
78
-            // CSV values should be considered as "in" operator in Query, otherwise "equals".
79
-            $explodedValues = GeneralUtility::trimExplode(',', $value, true);
80
-
81
-            // The matching value contains a "1,2" as example
82
-            if (count($explodedValues) > 1) {
83
-
84
-                $resolvedDataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType);
85
-                $resolvedFieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType);
86
-
87
-                // "equals" if in presence of a relation.
88
-                // "in" if not a relation.
89
-                if (Tca::table($resolvedDataType)->field($resolvedFieldName)->hasRelation()) {
90
-                    foreach ($explodedValues as $explodedValue) {
91
-                        $matcher->equals($fieldNameAndPath, $explodedValue);
92
-                    }
93
-                } else {
94
-                    $matcher->in($fieldNameAndPath, $explodedValues);
95
-                }
96
-            } else {
97
-                $matcher->equals($fieldNameAndPath, $explodedValues[0]);
98
-            }
99
-        }
100
-
101
-        // Trigger signal for post processing Matcher Object.
102
-        $this->emitPostProcessMatcherObjectSignal($matcher->getDataType(), $matcher);
103
-
104
-        return $matcher;
105
-    }
106
-
107
-    /**
108
-     * Replace possible aliases.
109
-     *
110
-     * @param array $values
111
-     * @return array
112
-     */
113
-    protected function replacesAliases(array $values)
114
-    {
115
-
116
-        $aliases = $this->arguments['aliases'];
117
-
118
-        foreach ($aliases as $aliasName => $aliasValue) {
119
-            if (isset($values[$aliasName])) {
120
-                $values[$aliasValue] = $values[$aliasName];
121
-                unset($values[$aliasName]); // remove the alias.
122
-            }
123
-        }
124
-
125
-        return $values;
126
-    }
127
-
128
-    /**
129
-     * Returns an order object.
130
-     *
131
-     * @param string $dataType
132
-     * @param array $order
133
-     * @return Order
134
-     */
135
-    public function getOrder($dataType, array $order = array())
136
-    {
137
-        // Default orderings in case order is empty.
138
-        if (empty($order)) {
139
-            $order = Tca::table($dataType)->getDefaultOrderings();
140
-        }
141
-
142
-        $order = GeneralUtility::makeInstance(Order::class, $order);
143
-
144
-        // Trigger signal for post processing Order Object.
145
-        $this->emitPostProcessOrderObjectSignal($dataType, $order);
146
-
147
-        return $order;
148
-    }
149
-
150
-    /**
151
-     * @return ResultSetStorage
152
-     */
153
-    public function getResultSetStorage()
154
-    {
155
-        return GeneralUtility::makeInstance(ResultSetStorage::class);
156
-    }
157
-
158
-    /**
159
-     * Signal that is called for post-processing a "order" object.
160
-     *
161
-     * @param string $dataType
162
-     * @param Order $order
163
-     */
164
-    protected function emitPostProcessOrderObjectSignal($dataType, Order $order)
165
-    {
166
-        $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\ViewHelper\Content\AbstractContentViewHelper', 'postProcessOrderObject', array($order, $dataType));
167
-    }
168
-
169
-    /**
170
-     * Signal that is called for post-processing a "matcher" object.
171
-     *
172
-     * @param string $dataType
173
-     * @param Matcher $matcher
174
-     */
175
-    protected function emitPostProcessMatcherObjectSignal($dataType, Matcher $matcher)
176
-    {
177
-        $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\ViewHelper\Content\AbstractContentViewHelper', 'postProcessMatcherObject', array($matcher, $dataType));
178
-    }
179
-
180
-    /**
181
-     * Signal that is called for post-processing a "limit".
182
-     *
183
-     * @param string $dataType
184
-     * @param int $limit
185
-     */
186
-    protected function emitPostProcessLimitSignal($dataType, $limit)
187
-    {
188
-        $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\ViewHelper\Content\AbstractContentViewHelper', 'postProcessLimit', array($limit, $dataType));
189
-    }
190
-
191
-    /**
192
-     * Signal that is called for post-processing a "offset".
193
-     *
194
-     * @param string $dataType
195
-     * @param int $offset
196
-     */
197
-    protected function emitPostProcessOffsetSignal($dataType, $offset)
198
-    {
199
-        $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\ViewHelper\Content\AbstractContentViewHelper', 'postProcessLimit', array($offset, $dataType));
200
-    }
201
-
202
-    /**
203
-     * Get the SignalSlot dispatcher
204
-     *
205
-     * @return Dispatcher
206
-     */
207
-    protected function getSignalSlotDispatcher()
208
-    {
209
-        return $this->getObjectManager()->get(Dispatcher::class);
210
-    }
211
-
212
-    /**
213
-     * @return ObjectManager
214
-     */
215
-    protected function getObjectManager()
216
-    {
217
-        return GeneralUtility::makeInstance(ObjectManager::class);
218
-    }
219
-
220
-    /**
221
-     * @param $ignoreEnableFields
222
-     * @return QuerySettingsInterface
223
-     */
224
-    protected function getDefaultQuerySettings($ignoreEnableFields)
225
-    {
226
-        /** @var QuerySettings $defaultQuerySettings */
227
-        $defaultQuerySettings = GeneralUtility::makeInstance(QuerySettings::class);
228
-        $defaultQuerySettings->setIgnoreEnableFields($ignoreEnableFields);
229
-        return $defaultQuerySettings;
230
-    }
231
-
232
-    /**
233
-     * @return FieldPathResolver
234
-     */
235
-    protected function getFieldPathResolver()
236
-    {
237
-        return GeneralUtility::makeInstance(FieldPathResolver::class);
238
-    }
30
+	/**
31
+	 * @return void
32
+	 * @throws Exception
33
+	 */
34
+	public function initializeArguments()
35
+	{
36
+		$this->registerArgument('type', 'string', 'Corresponds to the type of data to be fetched. It will basically be a table name e.g. fe_users.', false, '');
37
+		$this->registerArgument('matches', 'array', 'Key / value array to be used as filter. The key corresponds to a field name.', false, array());
38
+		$this->registerArgument('selection', 'int', 'A possible selection defined in the BE and stored in the database.', false, 0);
39
+		$this->registerArgument('ignoreEnableFields', 'bool', 'Whether to ignore enable fields or not (AKA hidden, deleted, starttime, ...).', false, false);
40
+		$this->registerArgument('aliases', 'array', 'Attribute "matches" does not support certain character such as "." in field name. Use this to create aliases.', false, array());
41
+	}
42
+
43
+	/**
44
+	 * Generate a signature to be used for storing the result set.
45
+	 *
46
+	 * @param string $dataType
47
+	 * @param array $matches
48
+	 * @param array $orderings
49
+	 * @param $limit
50
+	 * @param $offset
51
+	 * @return string
52
+	 */
53
+	protected function getQuerySignature($dataType, array $matches, array $orderings, $limit, $offset)
54
+	{
55
+		$serializedMatches = serialize($matches);
56
+		$serializedOrderings = serialize($orderings);
57
+		return md5($dataType . $serializedMatches . $serializedOrderings . $limit . $offset);
58
+	}
59
+
60
+	/**
61
+	 * Returns a matcher object.
62
+	 *
63
+	 * @param string $dataType
64
+	 * @param array $matches
65
+	 * @return Matcher
66
+	 * @throws NotExistingClassException
67
+	 * @throws \InvalidArgumentException
68
+	 */
69
+	protected function getMatcher($dataType, $matches = array())
70
+	{
71
+
72
+		/** @var $matcher Matcher */
73
+		$matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType);
74
+
75
+		// @todo implement advanced selection parsing {or: {usergroup.title: {like: foo}}, {tstamp: {greaterThan: 1234}}}
76
+		foreach ($matches as $fieldNameAndPath => $value) {
77
+
78
+			// CSV values should be considered as "in" operator in Query, otherwise "equals".
79
+			$explodedValues = GeneralUtility::trimExplode(',', $value, true);
80
+
81
+			// The matching value contains a "1,2" as example
82
+			if (count($explodedValues) > 1) {
83
+
84
+				$resolvedDataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType);
85
+				$resolvedFieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType);
86
+
87
+				// "equals" if in presence of a relation.
88
+				// "in" if not a relation.
89
+				if (Tca::table($resolvedDataType)->field($resolvedFieldName)->hasRelation()) {
90
+					foreach ($explodedValues as $explodedValue) {
91
+						$matcher->equals($fieldNameAndPath, $explodedValue);
92
+					}
93
+				} else {
94
+					$matcher->in($fieldNameAndPath, $explodedValues);
95
+				}
96
+			} else {
97
+				$matcher->equals($fieldNameAndPath, $explodedValues[0]);
98
+			}
99
+		}
100
+
101
+		// Trigger signal for post processing Matcher Object.
102
+		$this->emitPostProcessMatcherObjectSignal($matcher->getDataType(), $matcher);
103
+
104
+		return $matcher;
105
+	}
106
+
107
+	/**
108
+	 * Replace possible aliases.
109
+	 *
110
+	 * @param array $values
111
+	 * @return array
112
+	 */
113
+	protected function replacesAliases(array $values)
114
+	{
115
+
116
+		$aliases = $this->arguments['aliases'];
117
+
118
+		foreach ($aliases as $aliasName => $aliasValue) {
119
+			if (isset($values[$aliasName])) {
120
+				$values[$aliasValue] = $values[$aliasName];
121
+				unset($values[$aliasName]); // remove the alias.
122
+			}
123
+		}
124
+
125
+		return $values;
126
+	}
127
+
128
+	/**
129
+	 * Returns an order object.
130
+	 *
131
+	 * @param string $dataType
132
+	 * @param array $order
133
+	 * @return Order
134
+	 */
135
+	public function getOrder($dataType, array $order = array())
136
+	{
137
+		// Default orderings in case order is empty.
138
+		if (empty($order)) {
139
+			$order = Tca::table($dataType)->getDefaultOrderings();
140
+		}
141
+
142
+		$order = GeneralUtility::makeInstance(Order::class, $order);
143
+
144
+		// Trigger signal for post processing Order Object.
145
+		$this->emitPostProcessOrderObjectSignal($dataType, $order);
146
+
147
+		return $order;
148
+	}
149
+
150
+	/**
151
+	 * @return ResultSetStorage
152
+	 */
153
+	public function getResultSetStorage()
154
+	{
155
+		return GeneralUtility::makeInstance(ResultSetStorage::class);
156
+	}
157
+
158
+	/**
159
+	 * Signal that is called for post-processing a "order" object.
160
+	 *
161
+	 * @param string $dataType
162
+	 * @param Order $order
163
+	 */
164
+	protected function emitPostProcessOrderObjectSignal($dataType, Order $order)
165
+	{
166
+		$this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\ViewHelper\Content\AbstractContentViewHelper', 'postProcessOrderObject', array($order, $dataType));
167
+	}
168
+
169
+	/**
170
+	 * Signal that is called for post-processing a "matcher" object.
171
+	 *
172
+	 * @param string $dataType
173
+	 * @param Matcher $matcher
174
+	 */
175
+	protected function emitPostProcessMatcherObjectSignal($dataType, Matcher $matcher)
176
+	{
177
+		$this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\ViewHelper\Content\AbstractContentViewHelper', 'postProcessMatcherObject', array($matcher, $dataType));
178
+	}
179
+
180
+	/**
181
+	 * Signal that is called for post-processing a "limit".
182
+	 *
183
+	 * @param string $dataType
184
+	 * @param int $limit
185
+	 */
186
+	protected function emitPostProcessLimitSignal($dataType, $limit)
187
+	{
188
+		$this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\ViewHelper\Content\AbstractContentViewHelper', 'postProcessLimit', array($limit, $dataType));
189
+	}
190
+
191
+	/**
192
+	 * Signal that is called for post-processing a "offset".
193
+	 *
194
+	 * @param string $dataType
195
+	 * @param int $offset
196
+	 */
197
+	protected function emitPostProcessOffsetSignal($dataType, $offset)
198
+	{
199
+		$this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\ViewHelper\Content\AbstractContentViewHelper', 'postProcessLimit', array($offset, $dataType));
200
+	}
201
+
202
+	/**
203
+	 * Get the SignalSlot dispatcher
204
+	 *
205
+	 * @return Dispatcher
206
+	 */
207
+	protected function getSignalSlotDispatcher()
208
+	{
209
+		return $this->getObjectManager()->get(Dispatcher::class);
210
+	}
211
+
212
+	/**
213
+	 * @return ObjectManager
214
+	 */
215
+	protected function getObjectManager()
216
+	{
217
+		return GeneralUtility::makeInstance(ObjectManager::class);
218
+	}
219
+
220
+	/**
221
+	 * @param $ignoreEnableFields
222
+	 * @return QuerySettingsInterface
223
+	 */
224
+	protected function getDefaultQuerySettings($ignoreEnableFields)
225
+	{
226
+		/** @var QuerySettings $defaultQuerySettings */
227
+		$defaultQuerySettings = GeneralUtility::makeInstance(QuerySettings::class);
228
+		$defaultQuerySettings->setIgnoreEnableFields($ignoreEnableFields);
229
+		return $defaultQuerySettings;
230
+	}
231
+
232
+	/**
233
+	 * @return FieldPathResolver
234
+	 */
235
+	protected function getFieldPathResolver()
236
+	{
237
+		return GeneralUtility::makeInstance(FieldPathResolver::class);
238
+	}
239 239
 
240 240
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/Content/FindOneViewHelper.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -23,164 +23,164 @@
 block discarded – undo
23 23
 class FindOneViewHelper extends AbstractViewHelper
24 24
 {
25 25
 
26
-    /**
27
-     * @return void
28
-     */
29
-    public function initializeArguments()
30
-    {
31
-        parent::initializeArguments();
32
-
33
-        $this->registerArgument('type', 'string', 'The content type', true, '');
34
-        $this->registerArgument('matches', 'array', 'Key / value array to be used as filter. The key corresponds to a field name.', false, []);
35
-        $this->registerArgument('identifier', 'int', 'The identifier of the object to be fetched.', false, 0);
36
-        $this->registerArgument('argumentName', 'string', 'The parameter name where to retrieve the identifier', false, 'tx_vidifrontend_pi1|uid');
37
-        $this->registerArgument('as', 'string', 'The alias object', false, 'object');
38
-    }
39
-
40
-    /**
41
-     * @return string Rendered string
42
-     * @api
43
-     */
44
-    public function render()
45
-    {
46
-        return static::renderStatic(
47
-            $this->arguments,
48
-            $this->buildRenderChildrenClosure(),
49
-            $this->renderingContext
50
-        );
51
-    }
52
-
53
-    /**
54
-     * @param array $arguments
55
-     * @param \Closure $renderChildrenClosure
56
-     * @param RenderingContextInterface $renderingContext
57
-     *
58
-     * @return string
59
-     */
60
-    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
61
-    {
62
-
63
-        // Fetch the object
64
-        $matches = self::computeMatches($arguments);
65
-        $matcher = self::getMatcher($arguments['type'], $matches);
66
-
67
-        $contentRepository = ContentRepositoryFactory::getInstance($arguments['type']);
68
-        $object = $contentRepository->findOneBy($matcher);
69
-
70
-        $output = '';
71
-        if ($object) {
72
-            // Render children with "as" variable.
73
-            $templateVariableContainer = $renderingContext->getTemplateVariableContainer();
74
-            $templateVariableContainer->add($arguments['as'], $object);
75
-            $output = $renderChildrenClosure();
76
-            $templateVariableContainer->remove($arguments['as']);
77
-        }
78
-
79
-        return $output;
80
-    }
81
-
82
-    /**
83
-     * @param array $arguments
84
-     * @return array
85
-     */
86
-    protected static function computeMatches(array $arguments)
87
-    {
88
-
89
-        $matches = [];
90
-
91
-        $argumentValue = self::getArgumentValue($arguments['argumentName']);
92
-        if ($argumentValue > 0) {
93
-            $matches['uid'] = $argumentValue;
94
-        }
95
-
96
-        if ($arguments['matches']) {
97
-            $matches = $arguments['matches'];
98
-        }
99
-
100
-        if ($arguments['identifier'] > 0) {
101
-            $matches['uid'] = $arguments['identifier'];
102
-        }
103
-
104
-        // We want a default value in any case.
105
-        if (!$matches) {
106
-            $matches['uid'] = 0;
107
-        }
108
-        return $matches;
109
-    }
110
-
111
-    /**
112
-     * Returns a matcher object.
113
-     *
114
-     * @param string $dataType
115
-     * @param array $matches
116
-     * @return Matcher
117
-     */
118
-    protected static function getMatcher($dataType, array $matches = [])
119
-    {
120
-
121
-        /** @var $matcher Matcher */
122
-        $matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType);
123
-
124
-        foreach ($matches as $fieldNameAndPath => $value) {
125
-
126
-            // CSV values should be considered as "in" operator in Query, otherwise "equals".
127
-            $explodedValues = GeneralUtility::trimExplode(',', $value, true);
128
-
129
-            // The matching value contains a "1,2" as example
130
-            if (count($explodedValues) > 1) {
131
-
132
-                $resolvedDataType = self::getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType);
133
-                $resolvedFieldName = self::getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType);
134
-
135
-                // "equals" if in presence of a relation.
136
-                // "in" if not a relation.
137
-                if (Tca::table($resolvedDataType)->field($resolvedFieldName)->hasRelation()) {
138
-                    foreach ($explodedValues as $explodedValue) {
139
-                        $matcher->equals($fieldNameAndPath, $explodedValue);
140
-                    }
141
-                } else {
142
-                    $matcher->in($fieldNameAndPath, $explodedValues);
143
-                }
144
-            } else {
145
-                $matcher->equals($fieldNameAndPath, $explodedValues[0]);
146
-            }
147
-        }
148
-
149
-        return $matcher;
150
-    }
151
-
152
-    /**
153
-     * @return FieldPathResolver
154
-     */
155
-    protected static function getFieldPathResolver()
156
-    {
157
-        return GeneralUtility::makeInstance(FieldPathResolver::class);
158
-    }
159
-
160
-    /**
161
-     * @param string $argumentName
162
-     * @return int
163
-     */
164
-    protected static function getArgumentValue($argumentName)
165
-    {
166
-
167
-        $value = ''; // default value
168
-
169
-        // Merge parameters
170
-        $parameters = GeneralUtility::_GET();
171
-        $post = GeneralUtility::_POST();
172
-        ArrayUtility::mergeRecursiveWithOverrule($parameters, $post);
173
-
174
-        // Traverse argument parts and retrieve value.
175
-        $argumentParts = GeneralUtility::trimExplode('|', $argumentName);
176
-        foreach ($argumentParts as $argumentPart) {
177
-            if (isset($parameters[$argumentPart])) {
178
-                $value = $parameters[$argumentPart];
179
-                $parameters = $value;
180
-            }
181
-        }
182
-
183
-        return (int)$value;
184
-    }
26
+	/**
27
+	 * @return void
28
+	 */
29
+	public function initializeArguments()
30
+	{
31
+		parent::initializeArguments();
32
+
33
+		$this->registerArgument('type', 'string', 'The content type', true, '');
34
+		$this->registerArgument('matches', 'array', 'Key / value array to be used as filter. The key corresponds to a field name.', false, []);
35
+		$this->registerArgument('identifier', 'int', 'The identifier of the object to be fetched.', false, 0);
36
+		$this->registerArgument('argumentName', 'string', 'The parameter name where to retrieve the identifier', false, 'tx_vidifrontend_pi1|uid');
37
+		$this->registerArgument('as', 'string', 'The alias object', false, 'object');
38
+	}
39
+
40
+	/**
41
+	 * @return string Rendered string
42
+	 * @api
43
+	 */
44
+	public function render()
45
+	{
46
+		return static::renderStatic(
47
+			$this->arguments,
48
+			$this->buildRenderChildrenClosure(),
49
+			$this->renderingContext
50
+		);
51
+	}
52
+
53
+	/**
54
+	 * @param array $arguments
55
+	 * @param \Closure $renderChildrenClosure
56
+	 * @param RenderingContextInterface $renderingContext
57
+	 *
58
+	 * @return string
59
+	 */
60
+	public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
61
+	{
62
+
63
+		// Fetch the object
64
+		$matches = self::computeMatches($arguments);
65
+		$matcher = self::getMatcher($arguments['type'], $matches);
66
+
67
+		$contentRepository = ContentRepositoryFactory::getInstance($arguments['type']);
68
+		$object = $contentRepository->findOneBy($matcher);
69
+
70
+		$output = '';
71
+		if ($object) {
72
+			// Render children with "as" variable.
73
+			$templateVariableContainer = $renderingContext->getTemplateVariableContainer();
74
+			$templateVariableContainer->add($arguments['as'], $object);
75
+			$output = $renderChildrenClosure();
76
+			$templateVariableContainer->remove($arguments['as']);
77
+		}
78
+
79
+		return $output;
80
+	}
81
+
82
+	/**
83
+	 * @param array $arguments
84
+	 * @return array
85
+	 */
86
+	protected static function computeMatches(array $arguments)
87
+	{
88
+
89
+		$matches = [];
90
+
91
+		$argumentValue = self::getArgumentValue($arguments['argumentName']);
92
+		if ($argumentValue > 0) {
93
+			$matches['uid'] = $argumentValue;
94
+		}
95
+
96
+		if ($arguments['matches']) {
97
+			$matches = $arguments['matches'];
98
+		}
99
+
100
+		if ($arguments['identifier'] > 0) {
101
+			$matches['uid'] = $arguments['identifier'];
102
+		}
103
+
104
+		// We want a default value in any case.
105
+		if (!$matches) {
106
+			$matches['uid'] = 0;
107
+		}
108
+		return $matches;
109
+	}
110
+
111
+	/**
112
+	 * Returns a matcher object.
113
+	 *
114
+	 * @param string $dataType
115
+	 * @param array $matches
116
+	 * @return Matcher
117
+	 */
118
+	protected static function getMatcher($dataType, array $matches = [])
119
+	{
120
+
121
+		/** @var $matcher Matcher */
122
+		$matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType);
123
+
124
+		foreach ($matches as $fieldNameAndPath => $value) {
125
+
126
+			// CSV values should be considered as "in" operator in Query, otherwise "equals".
127
+			$explodedValues = GeneralUtility::trimExplode(',', $value, true);
128
+
129
+			// The matching value contains a "1,2" as example
130
+			if (count($explodedValues) > 1) {
131
+
132
+				$resolvedDataType = self::getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType);
133
+				$resolvedFieldName = self::getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType);
134
+
135
+				// "equals" if in presence of a relation.
136
+				// "in" if not a relation.
137
+				if (Tca::table($resolvedDataType)->field($resolvedFieldName)->hasRelation()) {
138
+					foreach ($explodedValues as $explodedValue) {
139
+						$matcher->equals($fieldNameAndPath, $explodedValue);
140
+					}
141
+				} else {
142
+					$matcher->in($fieldNameAndPath, $explodedValues);
143
+				}
144
+			} else {
145
+				$matcher->equals($fieldNameAndPath, $explodedValues[0]);
146
+			}
147
+		}
148
+
149
+		return $matcher;
150
+	}
151
+
152
+	/**
153
+	 * @return FieldPathResolver
154
+	 */
155
+	protected static function getFieldPathResolver()
156
+	{
157
+		return GeneralUtility::makeInstance(FieldPathResolver::class);
158
+	}
159
+
160
+	/**
161
+	 * @param string $argumentName
162
+	 * @return int
163
+	 */
164
+	protected static function getArgumentValue($argumentName)
165
+	{
166
+
167
+		$value = ''; // default value
168
+
169
+		// Merge parameters
170
+		$parameters = GeneralUtility::_GET();
171
+		$post = GeneralUtility::_POST();
172
+		ArrayUtility::mergeRecursiveWithOverrule($parameters, $post);
173
+
174
+		// Traverse argument parts and retrieve value.
175
+		$argumentParts = GeneralUtility::trimExplode('|', $argumentName);
176
+		foreach ($argumentParts as $argumentPart) {
177
+			if (isset($parameters[$argumentPart])) {
178
+				$value = $parameters[$argumentPart];
179
+				$parameters = $value;
180
+			}
181
+		}
182
+
183
+		return (int)$value;
184
+	}
185 185
 
186 186
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/Result/ToJsonViewHelper.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -18,54 +18,54 @@
 block discarded – undo
18 18
 class ToJsonViewHelper extends AbstractViewHelper
19 19
 {
20 20
 
21
-    /**
22
-     * Render a Json response
23
-     *
24
-     */
25
-    public function render()
26
-    {
27
-        $objects = $this->templateVariableContainer->get('objects');
28
-        $columns = $this->templateVariableContainer->get('columns');
29
-        $output = array(
30
-            'sEcho' => $this->getNextTransactionId(),
31
-            'iTotalRecords' => $this->templateVariableContainer->get('numberOfObjects'),
32
-            'iTotalDisplayRecords' => $this->templateVariableContainer->get('numberOfObjects'),
33
-            'iNumberOfRecords' => count($objects),
34
-            'aaData' => $this->getRowsView()->render($objects, $columns),
35
-        );
21
+	/**
22
+	 * Render a Json response
23
+	 *
24
+	 */
25
+	public function render()
26
+	{
27
+		$objects = $this->templateVariableContainer->get('objects');
28
+		$columns = $this->templateVariableContainer->get('columns');
29
+		$output = array(
30
+			'sEcho' => $this->getNextTransactionId(),
31
+			'iTotalRecords' => $this->templateVariableContainer->get('numberOfObjects'),
32
+			'iTotalDisplayRecords' => $this->templateVariableContainer->get('numberOfObjects'),
33
+			'iNumberOfRecords' => count($objects),
34
+			'aaData' => $this->getRowsView()->render($objects, $columns),
35
+		);
36 36
 
37
-        $this->setHttpHeaders();
38
-        print json_encode($output);
39
-    }
37
+		$this->setHttpHeaders();
38
+		print json_encode($output);
39
+	}
40 40
 
41
-    /**
42
-     * @return int
43
-     */
44
-    protected function getNextTransactionId()
45
-    {
46
-        $transaction = 0;
47
-        if (GeneralUtility::_GET('sEcho')) {
48
-            $transaction = (int)GeneralUtility::_GET('sEcho') + 1;
49
-        }
50
-        return $transaction;
51
-    }
41
+	/**
42
+	 * @return int
43
+	 */
44
+	protected function getNextTransactionId()
45
+	{
46
+		$transaction = 0;
47
+		if (GeneralUtility::_GET('sEcho')) {
48
+			$transaction = (int)GeneralUtility::_GET('sEcho') + 1;
49
+		}
50
+		return $transaction;
51
+	}
52 52
 
53
-    /**
54
-     * @return void
55
-     * @throws \InvalidArgumentException
56
-     */
57
-    protected function setHttpHeaders()
58
-    {
59
-        /** @var Response $response */
60
-        $response = $this->templateVariableContainer->get('response');
61
-        $response->withHeader('Content-Type', 'application/json');
62
-    }
53
+	/**
54
+	 * @return void
55
+	 * @throws \InvalidArgumentException
56
+	 */
57
+	protected function setHttpHeaders()
58
+	{
59
+		/** @var Response $response */
60
+		$response = $this->templateVariableContainer->get('response');
61
+		$response->withHeader('Content-Type', 'application/json');
62
+	}
63 63
 
64
-    /**
65
-     * @return Rows|object
66
-     */
67
-    protected function getRowsView()
68
-    {
69
-        return GeneralUtility::makeInstance(Rows::class);
70
-    }
64
+	/**
65
+	 * @return Rows|object
66
+	 */
67
+	protected function getRowsView()
68
+	{
69
+		return GeneralUtility::makeInstance(Rows::class);
70
+	}
71 71
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/Result/ToXmlViewHelper.php 2 patches
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -17,115 +17,115 @@
 block discarded – undo
17 17
 class ToXmlViewHelper extends AbstractToFormatViewHelper
18 18
 {
19 19
 
20
-    /**
21
-     * Render an XML export.
22
-     *
23
-     */
24
-    public function render()
25
-    {
26
-
27
-        $objects = $this->templateVariableContainer->get('objects');
28
-
29
-        // Make sure we have something to process...
30
-        if (!empty($objects)) {
31
-
32
-            // Initialization step.
33
-            $this->initializeEnvironment($objects);
34
-            $this->exportFileNameAndPath .= '.xml'; // add extension to the file.
35
-
36
-            // Write the exported data to a XML file.
37
-            $this->writeXmlFile($objects);
38
-
39
-            // We must generate a zip archive since there are files included.
40
-            if ($this->hasCollectedFiles()) {
41
-
42
-                $this->writeZipFile();
43
-                $this->sendZipHttpHeaders();
44
-
45
-                readfile($this->zipFileNameAndPath);
46
-            } else {
47
-                $this->sendXmlHttpHeaders();
48
-                readfile($this->exportFileNameAndPath);
49
-            }
50
-
51
-            GeneralUtility::rmdir($this->temporaryDirectory, true);
52
-        }
53
-    }
54
-
55
-    /**
56
-     * Write the XML file to a temporary location.
57
-     *
58
-     * @param array $objects
59
-     * @return void
60
-     */
61
-    protected function writeXmlFile(array $objects)
62
-    {
63
-
64
-        // Get first object of $objects to check whether it contains possible files to include.
65
-        /** @var Content $object */
66
-        $object = reset($objects);
67
-        $this->checkWhetherObjectMayIncludeFiles($object);
68
-
69
-        $items = [];
70
-        foreach ($objects as $object) {
71
-            if ($this->hasFileFields()) {
72
-                $this->collectFiles($object);
73
-            }
74
-            $items[] = $object->toValues();
75
-        }
76
-
77
-        $xml = new \SimpleXMLElement('<items/>');
78
-        $xml = $this->arrayToXml($items, $xml);
79
-        file_put_contents($this->exportFileNameAndPath, $this->formatXml($xml->asXML()));
80
-    }
81
-
82
-    /*
20
+	/**
21
+	 * Render an XML export.
22
+	 *
23
+	 */
24
+	public function render()
25
+	{
26
+
27
+		$objects = $this->templateVariableContainer->get('objects');
28
+
29
+		// Make sure we have something to process...
30
+		if (!empty($objects)) {
31
+
32
+			// Initialization step.
33
+			$this->initializeEnvironment($objects);
34
+			$this->exportFileNameAndPath .= '.xml'; // add extension to the file.
35
+
36
+			// Write the exported data to a XML file.
37
+			$this->writeXmlFile($objects);
38
+
39
+			// We must generate a zip archive since there are files included.
40
+			if ($this->hasCollectedFiles()) {
41
+
42
+				$this->writeZipFile();
43
+				$this->sendZipHttpHeaders();
44
+
45
+				readfile($this->zipFileNameAndPath);
46
+			} else {
47
+				$this->sendXmlHttpHeaders();
48
+				readfile($this->exportFileNameAndPath);
49
+			}
50
+
51
+			GeneralUtility::rmdir($this->temporaryDirectory, true);
52
+		}
53
+	}
54
+
55
+	/**
56
+	 * Write the XML file to a temporary location.
57
+	 *
58
+	 * @param array $objects
59
+	 * @return void
60
+	 */
61
+	protected function writeXmlFile(array $objects)
62
+	{
63
+
64
+		// Get first object of $objects to check whether it contains possible files to include.
65
+		/** @var Content $object */
66
+		$object = reset($objects);
67
+		$this->checkWhetherObjectMayIncludeFiles($object);
68
+
69
+		$items = [];
70
+		foreach ($objects as $object) {
71
+			if ($this->hasFileFields()) {
72
+				$this->collectFiles($object);
73
+			}
74
+			$items[] = $object->toValues();
75
+		}
76
+
77
+		$xml = new \SimpleXMLElement('<items/>');
78
+		$xml = $this->arrayToXml($items, $xml);
79
+		file_put_contents($this->exportFileNameAndPath, $this->formatXml($xml->asXML()));
80
+	}
81
+
82
+	/*
83 83
      * Convert an array to xml
84 84
      *
85 85
      * @return \SimpleXMLElement
86 86
      */
87
-    protected function arrayToXml($array, \SimpleXMLElement $xml)
88
-    {
89
-        foreach ($array as $key => $value) {
90
-            if (is_array($value)) {
91
-                $key = is_numeric($key) ? 'item' : $key;
92
-                $subNode = $xml->addChild($key);
93
-                $this->arrayToXml($value, $subNode);
94
-            } else {
95
-                $key = is_numeric($key) ? 'item' : $key;
96
-                $xml->addChild($key, "$value");
97
-            }
98
-        }
99
-        return $xml;
100
-    }
101
-
102
-    /*
87
+	protected function arrayToXml($array, \SimpleXMLElement $xml)
88
+	{
89
+		foreach ($array as $key => $value) {
90
+			if (is_array($value)) {
91
+				$key = is_numeric($key) ? 'item' : $key;
92
+				$subNode = $xml->addChild($key);
93
+				$this->arrayToXml($value, $subNode);
94
+			} else {
95
+				$key = is_numeric($key) ? 'item' : $key;
96
+				$xml->addChild($key, "$value");
97
+			}
98
+		}
99
+		return $xml;
100
+	}
101
+
102
+	/*
103 103
      * Format the XML so that is looks human friendly.
104 104
      *
105 105
      * @param string $xml
106 106
      * @return string
107 107
      */
108
-    protected function formatXml($xml)
109
-    {
110
-        $dom = new \DOMDocument("1.0");
111
-        $dom->preserveWhiteSpace = false;
112
-        $dom->formatOutput = true;
113
-        $dom->loadXML($xml);
114
-        return $dom->saveXML();
115
-    }
116
-
117
-    /**
118
-     * @return void
119
-     */
120
-    protected function sendXmlHttpHeaders()
121
-    {
122
-
123
-        /** @var Response $response */
124
-        $response = $this->templateVariableContainer->get('response');
125
-        $response->withHeader('Content-Type', 'application/xml');
126
-        $response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"');
127
-        $response->withHeader('Content-Length', filesize($this->exportFileNameAndPath));
128
-        $response->withHeader('Content-Description', 'File Transfer');
129
-    }
108
+	protected function formatXml($xml)
109
+	{
110
+		$dom = new \DOMDocument("1.0");
111
+		$dom->preserveWhiteSpace = false;
112
+		$dom->formatOutput = true;
113
+		$dom->loadXML($xml);
114
+		return $dom->saveXML();
115
+	}
116
+
117
+	/**
118
+	 * @return void
119
+	 */
120
+	protected function sendXmlHttpHeaders()
121
+	{
122
+
123
+		/** @var Response $response */
124
+		$response = $this->templateVariableContainer->get('response');
125
+		$response->withHeader('Content-Type', 'application/xml');
126
+		$response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"');
127
+		$response->withHeader('Content-Length', filesize($this->exportFileNameAndPath));
128
+		$response->withHeader('Content-Description', 'File Transfer');
129
+	}
130 130
 
131 131
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@
 block discarded – undo
123 123
         /** @var Response $response */
124 124
         $response = $this->templateVariableContainer->get('response');
125 125
         $response->withHeader('Content-Type', 'application/xml');
126
-        $response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"');
126
+        $response->withHeader('Content-Disposition', 'attachment; filename="'.basename($this->exportFileNameAndPath).'"');
127 127
         $response->withHeader('Content-Length', filesize($this->exportFileNameAndPath));
128 128
         $response->withHeader('Content-Description', 'File Transfer');
129 129
     }
Please login to merge, or discard this patch.
Classes/ViewHelpers/Result/AbstractToFormatViewHelper.php 2 patches
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -24,157 +24,157 @@
 block discarded – undo
24 24
 abstract class AbstractToFormatViewHelper extends AbstractViewHelper
25 25
 {
26 26
 
27
-    /**
28
-     * Store fields of type "file".
29
-     *
30
-     * @var array
31
-     */
32
-    protected $fileTypeProperties = [];
33
-
34
-    /**
35
-     * @var File[]
36
-     */
37
-    protected $collectedFiles = [];
38
-
39
-    /**
40
-     * @var string
41
-     */
42
-    protected $exportFileNameAndPath;
43
-
44
-    /**
45
-     * @var string
46
-     */
47
-    protected $zipFileNameAndPath;
48
-
49
-    /**
50
-     * @var string
51
-     */
52
-    protected $temporaryDirectory;
53
-
54
-
55
-    /**
56
-     * Write the zip file to a temporary location.
57
-     *
58
-     * @return void
59
-     * @throws \RuntimeException
60
-     */
61
-    protected function writeZipFile()
62
-    {
63
-
64
-        $zip = new \ZipArchive();
65
-        $zip->open($this->zipFileNameAndPath, \ZipArchive::CREATE);
66
-
67
-        // Add the CSV content into the zipball.
68
-        $zip->addFile($this->exportFileNameAndPath, basename($this->exportFileNameAndPath));
69
-
70
-        // Add the files into the zipball.
71
-        foreach ($this->collectedFiles as $file) {
72
-            $zip->addFile($file->getForLocalProcessing(false), $file->getIdentifier());
73
-        }
74
-
75
-        $zip->close();
76
-    }
77
-
78
-    /**
79
-     * Initialize some properties
80
-     *
81
-     * @param array $objects
82
-     * @return void
83
-     */
84
-    protected function initializeEnvironment(array $objects)
85
-    {
86
-
87
-        /** @var Content $object */
88
-        $object = reset($objects);
89
-
90
-        $this->temporaryDirectory = Environment::getPublicPath() . '/typo3temp/' . uniqid() . '/';
91
-        GeneralUtility::mkdir($this->temporaryDirectory);
92
-
93
-        // Compute file name and path variable
94
-        $this->exportFileNameAndPath = $this->temporaryDirectory . $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
95
-
96
-        // Compute file name and path variable for zip
97
-        $zipFileName = $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']) . '.zip';
98
-        $this->zipFileNameAndPath = $this->temporaryDirectory . $zipFileName;
99
-    }
100
-
101
-    /**
102
-     * Fetch the files given an object.
103
-     *
104
-     * @param Content $object
105
-     * @return void
106
-     */
107
-    protected function collectFiles(Content $object)
108
-    {
109
-        foreach ($this->fileTypeProperties as $property) {
110
-            $files = FileReferenceService::getInstance()->findReferencedBy($property, $object);
111
-            foreach ($files as $file) {
112
-                $this->collectedFiles[$file->getUid()] = $file;
113
-            }
114
-        }
115
-    }
116
-
117
-    /**
118
-     * Tells whether the object has fields containing files.
119
-     *
120
-     * @return boolean
121
-     */
122
-    protected function hasCollectedFiles()
123
-    {
124
-        return !empty($this->collectedFiles);
125
-    }
126
-
127
-    /**
128
-     * Tells whether the object has fields containing files.
129
-     *
130
-     * @return boolean
131
-     */
132
-    protected function hasFileFields()
133
-    {
134
-        return !empty($this->fileTypeProperties);
135
-    }
136
-
137
-    /**
138
-     * Check whether the given object is meant to include files in some fields.
139
-     *
140
-     * @param Content $object
141
-     */
142
-    protected function checkWhetherObjectMayIncludeFiles(Content $object)
143
-    {
144
-        if (Tca::grid($object->getDataType())->areFilesIncludedInExport()) {
145
-            foreach ($object->toFields() as $fieldName) {
146
-                $fieldType = Tca::table($object->getDataType())->field($fieldName)->getType();
147
-
148
-                if ($fieldType === FieldType::FILE) {
149
-                    $this->fileTypeProperties[] = GeneralUtility::camelCaseToLowerCaseUnderscored($fieldName);
150
-                }
151
-            }
152
-        }
153
-    }
154
-
155
-    /**
156
-     * @return void
157
-     */
158
-    protected function sendZipHttpHeaders()
159
-    {
160
-        /** @var Response $response */
161
-        $response = $this->templateVariableContainer->get('response');
162
-        $response->withHeader('Pragma', 'public');
163
-        $response->withHeader('Expires', '0');
164
-        $response->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
165
-        $response->withHeader('Content-Type', 'application/zip');
166
-        $response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->zipFileNameAndPath) . '"');
167
-        $response->withHeader('Content-Length', filesize($this->zipFileNameAndPath));
168
-        $response->withHeader('Content-Description', 'File Transfer');
169
-        $response->withHeader('Content-Transfer-Encoding', 'binary');
170
-    }
171
-
172
-    /**
173
-     * @return Rows|object
174
-     */
175
-    protected function getRowsView()
176
-    {
177
-        return GeneralUtility::makeInstance(Rows::class);
178
-    }
27
+	/**
28
+	 * Store fields of type "file".
29
+	 *
30
+	 * @var array
31
+	 */
32
+	protected $fileTypeProperties = [];
33
+
34
+	/**
35
+	 * @var File[]
36
+	 */
37
+	protected $collectedFiles = [];
38
+
39
+	/**
40
+	 * @var string
41
+	 */
42
+	protected $exportFileNameAndPath;
43
+
44
+	/**
45
+	 * @var string
46
+	 */
47
+	protected $zipFileNameAndPath;
48
+
49
+	/**
50
+	 * @var string
51
+	 */
52
+	protected $temporaryDirectory;
53
+
54
+
55
+	/**
56
+	 * Write the zip file to a temporary location.
57
+	 *
58
+	 * @return void
59
+	 * @throws \RuntimeException
60
+	 */
61
+	protected function writeZipFile()
62
+	{
63
+
64
+		$zip = new \ZipArchive();
65
+		$zip->open($this->zipFileNameAndPath, \ZipArchive::CREATE);
66
+
67
+		// Add the CSV content into the zipball.
68
+		$zip->addFile($this->exportFileNameAndPath, basename($this->exportFileNameAndPath));
69
+
70
+		// Add the files into the zipball.
71
+		foreach ($this->collectedFiles as $file) {
72
+			$zip->addFile($file->getForLocalProcessing(false), $file->getIdentifier());
73
+		}
74
+
75
+		$zip->close();
76
+	}
77
+
78
+	/**
79
+	 * Initialize some properties
80
+	 *
81
+	 * @param array $objects
82
+	 * @return void
83
+	 */
84
+	protected function initializeEnvironment(array $objects)
85
+	{
86
+
87
+		/** @var Content $object */
88
+		$object = reset($objects);
89
+
90
+		$this->temporaryDirectory = Environment::getPublicPath() . '/typo3temp/' . uniqid() . '/';
91
+		GeneralUtility::mkdir($this->temporaryDirectory);
92
+
93
+		// Compute file name and path variable
94
+		$this->exportFileNameAndPath = $this->temporaryDirectory . $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
95
+
96
+		// Compute file name and path variable for zip
97
+		$zipFileName = $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']) . '.zip';
98
+		$this->zipFileNameAndPath = $this->temporaryDirectory . $zipFileName;
99
+	}
100
+
101
+	/**
102
+	 * Fetch the files given an object.
103
+	 *
104
+	 * @param Content $object
105
+	 * @return void
106
+	 */
107
+	protected function collectFiles(Content $object)
108
+	{
109
+		foreach ($this->fileTypeProperties as $property) {
110
+			$files = FileReferenceService::getInstance()->findReferencedBy($property, $object);
111
+			foreach ($files as $file) {
112
+				$this->collectedFiles[$file->getUid()] = $file;
113
+			}
114
+		}
115
+	}
116
+
117
+	/**
118
+	 * Tells whether the object has fields containing files.
119
+	 *
120
+	 * @return boolean
121
+	 */
122
+	protected function hasCollectedFiles()
123
+	{
124
+		return !empty($this->collectedFiles);
125
+	}
126
+
127
+	/**
128
+	 * Tells whether the object has fields containing files.
129
+	 *
130
+	 * @return boolean
131
+	 */
132
+	protected function hasFileFields()
133
+	{
134
+		return !empty($this->fileTypeProperties);
135
+	}
136
+
137
+	/**
138
+	 * Check whether the given object is meant to include files in some fields.
139
+	 *
140
+	 * @param Content $object
141
+	 */
142
+	protected function checkWhetherObjectMayIncludeFiles(Content $object)
143
+	{
144
+		if (Tca::grid($object->getDataType())->areFilesIncludedInExport()) {
145
+			foreach ($object->toFields() as $fieldName) {
146
+				$fieldType = Tca::table($object->getDataType())->field($fieldName)->getType();
147
+
148
+				if ($fieldType === FieldType::FILE) {
149
+					$this->fileTypeProperties[] = GeneralUtility::camelCaseToLowerCaseUnderscored($fieldName);
150
+				}
151
+			}
152
+		}
153
+	}
154
+
155
+	/**
156
+	 * @return void
157
+	 */
158
+	protected function sendZipHttpHeaders()
159
+	{
160
+		/** @var Response $response */
161
+		$response = $this->templateVariableContainer->get('response');
162
+		$response->withHeader('Pragma', 'public');
163
+		$response->withHeader('Expires', '0');
164
+		$response->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
165
+		$response->withHeader('Content-Type', 'application/zip');
166
+		$response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->zipFileNameAndPath) . '"');
167
+		$response->withHeader('Content-Length', filesize($this->zipFileNameAndPath));
168
+		$response->withHeader('Content-Description', 'File Transfer');
169
+		$response->withHeader('Content-Transfer-Encoding', 'binary');
170
+	}
171
+
172
+	/**
173
+	 * @return Rows|object
174
+	 */
175
+	protected function getRowsView()
176
+	{
177
+		return GeneralUtility::makeInstance(Rows::class);
178
+	}
179 179
 
180 180
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
87 87
         /** @var Content $object */
88 88
         $object = reset($objects);
89 89
 
90
-        $this->temporaryDirectory = Environment::getPublicPath() . '/typo3temp/' . uniqid() . '/';
90
+        $this->temporaryDirectory = Environment::getPublicPath().'/typo3temp/'.uniqid().'/';
91 91
         GeneralUtility::mkdir($this->temporaryDirectory);
92 92
 
93 93
         // Compute file name and path variable
94
-        $this->exportFileNameAndPath = $this->temporaryDirectory . $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
94
+        $this->exportFileNameAndPath = $this->temporaryDirectory.$object->getDataType().'-'.date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
95 95
 
96 96
         // Compute file name and path variable for zip
97
-        $zipFileName = $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']) . '.zip';
98
-        $this->zipFileNameAndPath = $this->temporaryDirectory . $zipFileName;
97
+        $zipFileName = $object->getDataType().'-'.date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']).'.zip';
98
+        $this->zipFileNameAndPath = $this->temporaryDirectory.$zipFileName;
99 99
     }
100 100
 
101 101
     /**
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         $response->withHeader('Expires', '0');
164 164
         $response->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
165 165
         $response->withHeader('Content-Type', 'application/zip');
166
-        $response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->zipFileNameAndPath) . '"');
166
+        $response->withHeader('Content-Disposition', 'attachment; filename="'.basename($this->zipFileNameAndPath).'"');
167 167
         $response->withHeader('Content-Length', filesize($this->zipFileNameAndPath));
168 168
         $response->withHeader('Content-Description', 'File Transfer');
169 169
         $response->withHeader('Content-Transfer-Encoding', 'binary');
Please login to merge, or discard this patch.
Classes/ViewHelpers/Result/ToCsvViewHelper.php 2 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -17,89 +17,89 @@
 block discarded – undo
17 17
 class ToCsvViewHelper extends AbstractToFormatViewHelper
18 18
 {
19 19
 
20
-    /**
21
-     * Render a CSV export request.
22
-     *
23
-     */
24
-    public function render()
25
-    {
26
-        $objects = $this->templateVariableContainer->get('objects');
27
-
28
-        // Make sure we have something to process...
29
-        if (!empty($objects)) {
30
-
31
-            // Initialization step.
32
-            $this->initializeEnvironment($objects);
33
-            $this->exportFileNameAndPath .= '.csv'; // add extension to the file.
34
-
35
-            // Write the exported data to a CSV file.
36
-            $this->writeCsvFile($objects);
37
-
38
-            // We must generate a zip archive since there are files included.
39
-            if ($this->hasCollectedFiles()) {
40
-
41
-                $this->writeZipFile();
42
-                $this->sendZipHttpHeaders();
43
-
44
-                readfile($this->zipFileNameAndPath);
45
-            } else {
46
-                $this->sendCsvHttpHeaders();
47
-                readfile($this->exportFileNameAndPath);
48
-            }
49
-
50
-            GeneralUtility::rmdir($this->temporaryDirectory, true);
51
-        }
52
-    }
53
-
54
-    /**
55
-     * Write the CSV file to a temporary location.
56
-     *
57
-     * @param array $objects
58
-     */
59
-    protected function writeCsvFile(array $objects)
60
-    {
61
-        // Create a file pointer
62
-        $output = fopen($this->exportFileNameAndPath, 'w');
63
-
64
-        // Handle CSV header, get the first object and get the list of fields.
65
-        /** @var Content $object */
66
-        $object = reset($objects);
67
-        fputcsv($output, $object->toFields());
68
-        $this->checkWhetherObjectMayIncludeFiles($object);
69
-
70
-        foreach ($objects as $object) {
71
-            if ($this->hasFileFields()) {
72
-                $this->collectFiles($object);
73
-            }
74
-
75
-            // Make sure we have a flat array of values for the CSV purpose.
76
-            $flattenValues = [];
77
-            foreach ($object->toValues() as $fieldName => $value) {
78
-                if (is_array($value)) {
79
-                    $flattenValues[$fieldName] = implode(', ', $value);
80
-                } else {
81
-                    $flattenValues[$fieldName] = str_replace("\n", "\r", $value); // for Excel purpose.
82
-                }
83
-            }
84
-
85
-            fputcsv($output, $flattenValues);
86
-        }
87
-
88
-        // close file handler
89
-        fclose($output);
90
-    }
91
-
92
-    /**
93
-     * @return void
94
-     */
95
-    protected function sendCsvHttpHeaders()
96
-    {
97
-        /** @var Response $response */
98
-        $response = $this->templateVariableContainer->get('response');
99
-        $response->withHeader('Content-Type', 'application/csv');
100
-        $response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"');
101
-        $response->withHeader('Content-Length', filesize($this->exportFileNameAndPath));
102
-        $response->withHeader('Content-Description', 'File Transfer');
103
-    }
20
+	/**
21
+	 * Render a CSV export request.
22
+	 *
23
+	 */
24
+	public function render()
25
+	{
26
+		$objects = $this->templateVariableContainer->get('objects');
27
+
28
+		// Make sure we have something to process...
29
+		if (!empty($objects)) {
30
+
31
+			// Initialization step.
32
+			$this->initializeEnvironment($objects);
33
+			$this->exportFileNameAndPath .= '.csv'; // add extension to the file.
34
+
35
+			// Write the exported data to a CSV file.
36
+			$this->writeCsvFile($objects);
37
+
38
+			// We must generate a zip archive since there are files included.
39
+			if ($this->hasCollectedFiles()) {
40
+
41
+				$this->writeZipFile();
42
+				$this->sendZipHttpHeaders();
43
+
44
+				readfile($this->zipFileNameAndPath);
45
+			} else {
46
+				$this->sendCsvHttpHeaders();
47
+				readfile($this->exportFileNameAndPath);
48
+			}
49
+
50
+			GeneralUtility::rmdir($this->temporaryDirectory, true);
51
+		}
52
+	}
53
+
54
+	/**
55
+	 * Write the CSV file to a temporary location.
56
+	 *
57
+	 * @param array $objects
58
+	 */
59
+	protected function writeCsvFile(array $objects)
60
+	{
61
+		// Create a file pointer
62
+		$output = fopen($this->exportFileNameAndPath, 'w');
63
+
64
+		// Handle CSV header, get the first object and get the list of fields.
65
+		/** @var Content $object */
66
+		$object = reset($objects);
67
+		fputcsv($output, $object->toFields());
68
+		$this->checkWhetherObjectMayIncludeFiles($object);
69
+
70
+		foreach ($objects as $object) {
71
+			if ($this->hasFileFields()) {
72
+				$this->collectFiles($object);
73
+			}
74
+
75
+			// Make sure we have a flat array of values for the CSV purpose.
76
+			$flattenValues = [];
77
+			foreach ($object->toValues() as $fieldName => $value) {
78
+				if (is_array($value)) {
79
+					$flattenValues[$fieldName] = implode(', ', $value);
80
+				} else {
81
+					$flattenValues[$fieldName] = str_replace("\n", "\r", $value); // for Excel purpose.
82
+				}
83
+			}
84
+
85
+			fputcsv($output, $flattenValues);
86
+		}
87
+
88
+		// close file handler
89
+		fclose($output);
90
+	}
91
+
92
+	/**
93
+	 * @return void
94
+	 */
95
+	protected function sendCsvHttpHeaders()
96
+	{
97
+		/** @var Response $response */
98
+		$response = $this->templateVariableContainer->get('response');
99
+		$response->withHeader('Content-Type', 'application/csv');
100
+		$response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"');
101
+		$response->withHeader('Content-Length', filesize($this->exportFileNameAndPath));
102
+		$response->withHeader('Content-Description', 'File Transfer');
103
+	}
104 104
 
105 105
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@
 block discarded – undo
97 97
         /** @var Response $response */
98 98
         $response = $this->templateVariableContainer->get('response');
99 99
         $response->withHeader('Content-Type', 'application/csv');
100
-        $response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"');
100
+        $response->withHeader('Content-Disposition', 'attachment; filename="'.basename($this->exportFileNameAndPath).'"');
101 101
         $response->withHeader('Content-Length', filesize($this->exportFileNameAndPath));
102 102
         $response->withHeader('Content-Description', 'File Transfer');
103 103
     }
Please login to merge, or discard this patch.
Classes/ViewHelpers/Result/ToXlsViewHelper.php 1 patch
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -18,96 +18,96 @@
 block discarded – undo
18 18
 class ToXlsViewHelper extends AbstractToFormatViewHelper
19 19
 {
20 20
 
21
-    /**
22
-     * Render a XLS export request.
23
-     *
24
-     */
25
-    public function render()
26
-    {
27
-
28
-        $objects = $this->templateVariableContainer->get('objects');
29
-
30
-        // Make sure we have something to process...
31
-        if (!empty($objects)) {
32
-
33
-            // Initialization step.
34
-            $this->initializeEnvironment($objects);
35
-            $this->exportFileNameAndPath .= '.xls'; // add extension to the file.
36
-
37
-            // Write the exported data to a CSV file.
38
-            $this->writeXlsFile($objects);
39
-
40
-            // We must generate a zip archive since there are files included.
41
-            if ($this->hasCollectedFiles()) {
42
-
43
-                $this->writeZipFile();
44
-                $this->sendZipHttpHeaders();
45
-
46
-                readfile($this->zipFileNameAndPath);
47
-            } else {
48
-                $this->sendXlsHttpHeaders();
49
-                readfile($this->exportFileNameAndPath);
50
-            }
51
-
52
-            GeneralUtility::rmdir($this->temporaryDirectory, true);
53
-        }
54
-    }
55
-
56
-    /**
57
-     * Write the CSV file to a temporary location.
58
-     *
59
-     * @param array $objects
60
-     * @return void
61
-     */
62
-    protected function writeXlsFile(array $objects)
63
-    {
64
-
65
-        /** @var SpreadSheetService $spreadSheet */
66
-        $spreadSheet = GeneralUtility::makeInstance(SpreadSheetService::class);
67
-
68
-        // Handle object header, get the first object and get the list of fields.
69
-        /** @var Content $object */
70
-        $object = reset($objects);
71
-        $spreadSheet->addRow($object->toFields());
72
-
73
-        $this->checkWhetherObjectMayIncludeFiles($object);
74
-
75
-        foreach ($objects as $object) {
76
-            if ($this->hasFileFields()) {
77
-                $this->collectFiles($object);
78
-            }
79
-
80
-            // Make sure we have a flat array of values for the CSV purpose.
81
-            $flattenValues = [];
82
-            foreach ($object->toValues() as $fieldName => $value) {
83
-                if (is_array($value)) {
84
-                    $flattenValues[$fieldName] = implode(', ', $value);
85
-                } else {
86
-                    $flattenValues[$fieldName] = $value;
87
-                }
88
-            }
89
-
90
-            $spreadSheet->addRow($flattenValues);
91
-        }
92
-
93
-        file_put_contents($this->exportFileNameAndPath, $spreadSheet->toString());
94
-    }
95
-
96
-    /**
97
-     * @return void
98
-     */
99
-    protected function sendXlsHttpHeaders()
100
-    {
101
-        /** @var Response $response */
102
-        $response = $this->templateVariableContainer->get('response');
103
-        $response->withHeader('Pragma', 'public');
104
-        $response->withHeader('Expires', '0');
105
-        $response->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
106
-        $response->withHeader('Content-Type', 'application/vnd.ms-excel');
107
-        $response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"');
108
-        $response->withHeader('Content-Length', filesize($this->exportFileNameAndPath));
109
-        $response->withHeader('Content-Description', 'File Transfer');
110
-        $response->withHeader('Content-Transfer-Encoding', 'binary');
111
-    }
21
+	/**
22
+	 * Render a XLS export request.
23
+	 *
24
+	 */
25
+	public function render()
26
+	{
27
+
28
+		$objects = $this->templateVariableContainer->get('objects');
29
+
30
+		// Make sure we have something to process...
31
+		if (!empty($objects)) {
32
+
33
+			// Initialization step.
34
+			$this->initializeEnvironment($objects);
35
+			$this->exportFileNameAndPath .= '.xls'; // add extension to the file.
36
+
37
+			// Write the exported data to a CSV file.
38
+			$this->writeXlsFile($objects);
39
+
40
+			// We must generate a zip archive since there are files included.
41
+			if ($this->hasCollectedFiles()) {
42
+
43
+				$this->writeZipFile();
44
+				$this->sendZipHttpHeaders();
45
+
46
+				readfile($this->zipFileNameAndPath);
47
+			} else {
48
+				$this->sendXlsHttpHeaders();
49
+				readfile($this->exportFileNameAndPath);
50
+			}
51
+
52
+			GeneralUtility::rmdir($this->temporaryDirectory, true);
53
+		}
54
+	}
55
+
56
+	/**
57
+	 * Write the CSV file to a temporary location.
58
+	 *
59
+	 * @param array $objects
60
+	 * @return void
61
+	 */
62
+	protected function writeXlsFile(array $objects)
63
+	{
64
+
65
+		/** @var SpreadSheetService $spreadSheet */
66
+		$spreadSheet = GeneralUtility::makeInstance(SpreadSheetService::class);
67
+
68
+		// Handle object header, get the first object and get the list of fields.
69
+		/** @var Content $object */
70
+		$object = reset($objects);
71
+		$spreadSheet->addRow($object->toFields());
72
+
73
+		$this->checkWhetherObjectMayIncludeFiles($object);
74
+
75
+		foreach ($objects as $object) {
76
+			if ($this->hasFileFields()) {
77
+				$this->collectFiles($object);
78
+			}
79
+
80
+			// Make sure we have a flat array of values for the CSV purpose.
81
+			$flattenValues = [];
82
+			foreach ($object->toValues() as $fieldName => $value) {
83
+				if (is_array($value)) {
84
+					$flattenValues[$fieldName] = implode(', ', $value);
85
+				} else {
86
+					$flattenValues[$fieldName] = $value;
87
+				}
88
+			}
89
+
90
+			$spreadSheet->addRow($flattenValues);
91
+		}
92
+
93
+		file_put_contents($this->exportFileNameAndPath, $spreadSheet->toString());
94
+	}
95
+
96
+	/**
97
+	 * @return void
98
+	 */
99
+	protected function sendXlsHttpHeaders()
100
+	{
101
+		/** @var Response $response */
102
+		$response = $this->templateVariableContainer->get('response');
103
+		$response->withHeader('Pragma', 'public');
104
+		$response->withHeader('Expires', '0');
105
+		$response->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
106
+		$response->withHeader('Content-Type', 'application/vnd.ms-excel');
107
+		$response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"');
108
+		$response->withHeader('Content-Length', filesize($this->exportFileNameAndPath));
109
+		$response->withHeader('Content-Description', 'File Transfer');
110
+		$response->withHeader('Content-Transfer-Encoding', 'binary');
111
+	}
112 112
 
113 113
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/PublicPathViewHelper.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@
 block discarded – undo
16 16
 class PublicPathViewHelper extends AbstractViewHelper
17 17
 {
18 18
 
19
-    /**
20
-     * Returns the public path to Vidi extension.
21
-     *
22
-     * @return string
23
-     */
24
-    public function render()
25
-    {
26
-        return ExtensionManagementUtility::siteRelPath('vidi');
27
-    }
19
+	/**
20
+	 * Returns the public path to Vidi extension.
21
+	 *
22
+	 * @return string
23
+	 */
24
+	public function render()
25
+	{
26
+		return ExtensionManagementUtility::siteRelPath('vidi');
27
+	}
28 28
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/Grid/Column/HasRelationViewHelper.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -18,25 +18,25 @@
 block discarded – undo
18 18
 class HasRelationViewHelper extends AbstractViewHelper
19 19
 {
20 20
 
21
-    /**
22
-     * Return whether the current field name has a relation to the main content.
23
-     *
24
-     * @return boolean
25
-     */
26
-    public function render()
27
-    {
28
-        $fieldNameAndPath = $this->templateVariableContainer->get('columnName');
29
-        $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
30
-        $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
31
-        $hasRelation = Tca::table($dataType)->field($fieldName)->hasRelation();
32
-        return $hasRelation;
33
-    }
21
+	/**
22
+	 * Return whether the current field name has a relation to the main content.
23
+	 *
24
+	 * @return boolean
25
+	 */
26
+	public function render()
27
+	{
28
+		$fieldNameAndPath = $this->templateVariableContainer->get('columnName');
29
+		$dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
30
+		$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
31
+		$hasRelation = Tca::table($dataType)->field($fieldName)->hasRelation();
32
+		return $hasRelation;
33
+	}
34 34
 
35
-    /**
36
-     * @return FieldPathResolver|object
37
-     */
38
-    protected function getFieldPathResolver()
39
-    {
40
-        return GeneralUtility::makeInstance(FieldPathResolver::class);
41
-    }
35
+	/**
36
+	 * @return FieldPathResolver|object
37
+	 */
38
+	protected function getFieldPathResolver()
39
+	{
40
+		return GeneralUtility::makeInstance(FieldPathResolver::class);
41
+	}
42 42
 }
Please login to merge, or discard this patch.