Completed
Pull Request — master (#204)
by Adrien
54:53
created
Classes/DataHandler/CoreDataHandler.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@
 block discarded – undo
94 94
      *
95 95
      * @param Content $content
96 96
      * @param string $target
97
-     * @return bool
97
+     * @return boolean|null
98 98
      */
99 99
     public function processCopy(Content $content, $target)
100 100
     {
Please login to merge, or discard this patch.
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -18,140 +18,140 @@
 block discarded – undo
18 18
 class CoreDataHandler extends AbstractDataHandler
19 19
 {
20 20
 
21
-    /**
22
-     * @var array
23
-     */
24
-    protected $dataHandler;
25
-
26
-    /**
27
-     * Process Content with action "update".
28
-     *
29
-     * @param Content $content
30
-     * @throws \Exception
31
-     * @return bool
32
-     */
33
-    public function processUpdate(Content $content)
34
-    {
35
-
36
-        $values = [];
37
-
38
-        // Check the field to be updated exists
39
-        foreach ($content->toArray() as $fieldName => $value) {
40
-            if (!Tca::table($content->getDataType())->hasField($fieldName)) {
41
-                $message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType());
42
-                throw new \Exception($message, 1390668497);
43
-            }
44
-
45
-            // Flatten value if array given which is required for the DataHandler.
46
-            if (is_array($value)) {
47
-                $value = implode(',', $value);
48
-            }
49
-            $values[$fieldName] = $value;
50
-        }
51
-
52
-        $data[$content->getDataType()][$content->getUid()] = $values;
53
-
54
-        $dataHandler = $this->getDataHandler();
55
-        $dataHandler->start($data, array());
56
-        $dataHandler->process_datamap();
57
-        $this->errorMessages = $dataHandler->errorLog;
58
-
59
-        // Returns true is log does not contain errors.
60
-        return empty($dataHandler->errorLog);
61
-    }
62
-
63
-    /**
64
-     * Process Content with action "remove".
65
-     *
66
-     * @param Content $content
67
-     * @return bool
68
-     */
69
-    public function processRemove(Content $content)
70
-    {
71
-
72
-        // Build command
73
-        $cmd[$content->getDataType()][$content->getUid()]['delete'] = 1;
74
-
75
-        /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
76
-        $dataHandler = $this->getDataHandler();
77
-        $dataHandler->start([], $cmd);
78
-        $dataHandler->process_datamap();
79
-        $dataHandler->process_cmdmap();
80
-        $this->errorMessages = $dataHandler->errorLog;
81
-
82
-        // Returns true is log does not contain errors.
83
-        return empty($dataHandler->errorLog);
84
-    }
85
-
86
-    /**
87
-     * Process Content with action "copy".
88
-     *
89
-     * @param Content $content
90
-     * @param string $target
91
-     * @return bool
92
-     */
93
-    public function processCopy(Content $content, $target)
94
-    {
95
-        // TODO: Implement processCopy() method.
96
-    }
97
-
98
-    /**
99
-     * Process Content with action "move".
100
-     * The $target corresponds to the pid to move the records to.
101
-     * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor.
102
-     *
103
-     * @param Content $content
104
-     * @param int $target corresponds
105
-     * @return bool
106
-     */
107
-    public function processMove(Content $content, $target)
108
-    {
109
-
110
-        // Build command
111
-        $cmd[$content->getDataType()][$content->getUid()]['move'] = $target;
112
-
113
-        /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
114
-        $dataHandler = $this->getDataHandler();
115
-        $dataHandler->start([], $cmd);
116
-        $dataHandler->process_datamap();
117
-        $dataHandler->process_cmdmap();
118
-        $this->errorMessages = $dataHandler->errorLog;
119
-
120
-        // Returns true is log does not contain errors.
121
-        return empty($dataHandler->errorLog);
122
-    }
123
-
124
-    /**
125
-     * Process Content with action "localize".
126
-     *
127
-     * @param Content $content
128
-     * @param int $language
129
-     * @return bool
130
-     */
131
-    public function processLocalize(Content $content, $language)
132
-    {
133
-
134
-        $command[$content->getDataType()][$content->getUid()]['localize'] = $language;
135
-
136
-        $dataHandler = $this->getDataHandler();
137
-        $dataHandler->start([], $command);
138
-        $dataHandler->process_datamap();
139
-        $dataHandler->process_cmdmap();
140
-        $this->errorMessages = $dataHandler->errorLog;
141
-
142
-        // Returns true is log does not contain errors.
143
-        return empty($dataHandler->errorLog);
144
-    }
145
-
146
-    /**
147
-     * @return \TYPO3\CMS\Core\DataHandling\DataHandler
148
-     */
149
-    protected function getDataHandler()
150
-    {
151
-        if (!$this->dataHandler) {
152
-            $this->dataHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
153
-        }
154
-        return $this->dataHandler;
155
-    }
21
+	/**
22
+	 * @var array
23
+	 */
24
+	protected $dataHandler;
25
+
26
+	/**
27
+	 * Process Content with action "update".
28
+	 *
29
+	 * @param Content $content
30
+	 * @throws \Exception
31
+	 * @return bool
32
+	 */
33
+	public function processUpdate(Content $content)
34
+	{
35
+
36
+		$values = [];
37
+
38
+		// Check the field to be updated exists
39
+		foreach ($content->toArray() as $fieldName => $value) {
40
+			if (!Tca::table($content->getDataType())->hasField($fieldName)) {
41
+				$message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType());
42
+				throw new \Exception($message, 1390668497);
43
+			}
44
+
45
+			// Flatten value if array given which is required for the DataHandler.
46
+			if (is_array($value)) {
47
+				$value = implode(',', $value);
48
+			}
49
+			$values[$fieldName] = $value;
50
+		}
51
+
52
+		$data[$content->getDataType()][$content->getUid()] = $values;
53
+
54
+		$dataHandler = $this->getDataHandler();
55
+		$dataHandler->start($data, array());
56
+		$dataHandler->process_datamap();
57
+		$this->errorMessages = $dataHandler->errorLog;
58
+
59
+		// Returns true is log does not contain errors.
60
+		return empty($dataHandler->errorLog);
61
+	}
62
+
63
+	/**
64
+	 * Process Content with action "remove".
65
+	 *
66
+	 * @param Content $content
67
+	 * @return bool
68
+	 */
69
+	public function processRemove(Content $content)
70
+	{
71
+
72
+		// Build command
73
+		$cmd[$content->getDataType()][$content->getUid()]['delete'] = 1;
74
+
75
+		/** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
76
+		$dataHandler = $this->getDataHandler();
77
+		$dataHandler->start([], $cmd);
78
+		$dataHandler->process_datamap();
79
+		$dataHandler->process_cmdmap();
80
+		$this->errorMessages = $dataHandler->errorLog;
81
+
82
+		// Returns true is log does not contain errors.
83
+		return empty($dataHandler->errorLog);
84
+	}
85
+
86
+	/**
87
+	 * Process Content with action "copy".
88
+	 *
89
+	 * @param Content $content
90
+	 * @param string $target
91
+	 * @return bool
92
+	 */
93
+	public function processCopy(Content $content, $target)
94
+	{
95
+		// TODO: Implement processCopy() method.
96
+	}
97
+
98
+	/**
99
+	 * Process Content with action "move".
100
+	 * The $target corresponds to the pid to move the records to.
101
+	 * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor.
102
+	 *
103
+	 * @param Content $content
104
+	 * @param int $target corresponds
105
+	 * @return bool
106
+	 */
107
+	public function processMove(Content $content, $target)
108
+	{
109
+
110
+		// Build command
111
+		$cmd[$content->getDataType()][$content->getUid()]['move'] = $target;
112
+
113
+		/** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
114
+		$dataHandler = $this->getDataHandler();
115
+		$dataHandler->start([], $cmd);
116
+		$dataHandler->process_datamap();
117
+		$dataHandler->process_cmdmap();
118
+		$this->errorMessages = $dataHandler->errorLog;
119
+
120
+		// Returns true is log does not contain errors.
121
+		return empty($dataHandler->errorLog);
122
+	}
123
+
124
+	/**
125
+	 * Process Content with action "localize".
126
+	 *
127
+	 * @param Content $content
128
+	 * @param int $language
129
+	 * @return bool
130
+	 */
131
+	public function processLocalize(Content $content, $language)
132
+	{
133
+
134
+		$command[$content->getDataType()][$content->getUid()]['localize'] = $language;
135
+
136
+		$dataHandler = $this->getDataHandler();
137
+		$dataHandler->start([], $command);
138
+		$dataHandler->process_datamap();
139
+		$dataHandler->process_cmdmap();
140
+		$this->errorMessages = $dataHandler->errorLog;
141
+
142
+		// Returns true is log does not contain errors.
143
+		return empty($dataHandler->errorLog);
144
+	}
145
+
146
+	/**
147
+	 * @return \TYPO3\CMS\Core\DataHandling\DataHandler
148
+	 */
149
+	protected function getDataHandler()
150
+	{
151
+		if (!$this->dataHandler) {
152
+			$this->dataHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
153
+		}
154
+		return $this->dataHandler;
155
+	}
156 156
 
157 157
 }
Please login to merge, or discard this patch.
Classes/Domain/Model/Content.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -385,7 +385,7 @@
 block discarded – undo
385 385
     /**
386 386
      * Return the properties of this object.
387 387
      *
388
-     * @return array
388
+     * @return string[]
389 389
      */
390 390
     public function toFields()
391 391
     {
Please login to merge, or discard this patch.
Indentation   +445 added lines, -445 removed lines patch added patch discarded remove patch
@@ -23,450 +23,450 @@
 block discarded – undo
23 23
 class Content implements \ArrayAccess
24 24
 {
25 25
 
26
-    /**
27
-     * @var int
28
-     */
29
-    protected $uid;
30
-
31
-    /**
32
-     * @var string
33
-     */
34
-    protected $dataType;
35
-
36
-    /**
37
-     * Constructor for a Content object.
38
-     *
39
-     * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ...
40
-     * @param array $contentData
41
-     * @return \Fab\Vidi\Domain\Model\Content
42
-     * @throws \InvalidArgumentException
43
-     * @throws \Fab\Vidi\Exception\NotExistingClassException
44
-     */
45
-    public function __construct($dataType, array $contentData = array())
46
-    {
47
-
48
-        $this->dataType = $dataType;
49
-        $this->uid = empty($contentData['uid']) ? null : (int)$contentData['uid'];
50
-
51
-        /** @var \Fab\Vidi\Tca\TableService $table */
52
-        $table = Tca::table($dataType);
53
-
54
-        // Initialize the array containing the allowed fields to be filled-in.
55
-        $fields = array('pid');
56
-
57
-        // If a creation time stamp has been defined for this data type.
58
-        if ($table->getTimeCreationField()) {
59
-            $fields[] = $table->getTimeCreationField();
60
-        }
61
-
62
-        // If an update time stamp has been defined for this data type.
63
-        if ($table->getTimeModificationField()) {
64
-            $fields[] = $table->getTimeModificationField();
65
-        }
66
-
67
-        // Merge the other fields allowed for this data type.
68
-        $fields = array_merge($fields, $table->getFields());
69
-
70
-        // Fetch excluded fields from the grid.
71
-        if ($this->isBackendMode()) {
72
-            $fields = $this->filterForConfiguration($fields);
73
-            $fields = $this->filterForBackendUser($fields);
74
-        }
75
-
76
-        // Get column to be displayed
77
-        foreach ($fields as $fieldName) {
78
-            if (array_key_exists($fieldName, $contentData)) {
79
-                $propertyName = Field::name($fieldName)->of($dataType)->toPropertyName();
80
-                $this->$propertyName = $contentData[$fieldName];
81
-            }
82
-        }
83
-    }
84
-
85
-    /**
86
-     * Dispatches magic methods (findBy[Property]())
87
-     *
88
-     * @param string $methodName The name of the magic method
89
-     * @param string $arguments The arguments of the magic method
90
-     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException
91
-     * @return mixed
92
-     * @api
93
-     */
94
-    public function __call($methodName, $arguments)
95
-    {
96
-        $value = null;
97
-        if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
98
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
99
-
100
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
101
-            $field = Tca::table($this->dataType)->field($fieldName);
102
-
103
-            $value = $this->$propertyName;
104
-
105
-            // true means it is a relation and it is not yet resolved.
106
-            if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) {
107
-                $value = $this->resolveRelation($propertyName);
108
-            } elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) {
109
-
110
-                // Attempt to convert the value into a label for radio and select fields.
111
-                $label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value);
112
-                if ($label) {
113
-                    $value = $label;
114
-                }
115
-            }
116
-
117
-        } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
118
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
119
-            $this->$propertyName = $arguments[0];
120
-        }
121
-        return $value;
122
-    }
123
-
124
-    /**
125
-     * Tell whether the property has a relation.
126
-     *
127
-     * @param string $propertyName
128
-     * @return bool
129
-     */
130
-    protected function hasRelation($propertyName)
131
-    {
132
-        $fieldName = Property::name($propertyName)->of($this)->toFieldName();
133
-        return Tca::table($this->dataType)->field($fieldName)->hasRelation();
134
-    }
135
-
136
-    /**
137
-     * Try to "resolve" the property whether it has a relation.
138
-     * If the property has not relation it simply returns the same value.
139
-     *
140
-     * @throws \RuntimeException
141
-     * @param string $propertyName
142
-     * @return mixed
143
-     */
144
-    protected function resolveRelation($propertyName)
145
-    {
146
-
147
-        // Convert property name to field name and get the foreign data type.
148
-        $fieldName = Property::name($propertyName)->of($this)->toFieldName();
149
-        $foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType();
150
-
151
-        // Get the foreign repository instance form the factory
152
-        /** @var \Fab\Vidi\Domain\Repository\ContentRepository $foreignContentRepository */
153
-        $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName);
154
-
155
-        if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
156
-
157
-            // Fetch values from repository
158
-            $values = GeneralUtility::trimExplode(',', $this->$propertyName);
159
-            $this->$propertyName = $foreignContentRepository->findIn('uid', $values);
160
-        } elseif (Tca::table($this->dataType)->field($fieldName)->hasMany()) {
161
-            // Include relation many-to-many and one-to-many
162
-            // Tca::table($this->dataType)->field($fieldName)->hasRelationOneToMany()
163
-            // Tca::table($this->dataType)->field($fieldName)->hasRelationManyToMany()
164
-
165
-            $foreignFieldName = Tca::table($this->dataType)->field($fieldName)->getForeignField();
166
-            if (empty($foreignFieldName)) {
167
-                $message = sprintf('Missing "foreign_field" key for field "%s" in table "%s".',
168
-                    $fieldName,
169
-                    $this->dataType
170
-                );
171
-                throw new \RuntimeException($message, 1376149186);
172
-            }
173
-
174
-            // Fetch values from repository.
175
-            $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
176
-            $findByProperty = 'findBy' . ucfirst($foreignPropertyName);
177
-
178
-            // Date picker (type == group) are special fields because property path must contain the table name
179
-            // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
180
-            $propertyValue = $this->uid;
181
-            if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
182
-                $propertyValue = $this->dataType . '.' . $this->uid;
183
-            }
184
-
185
-            $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
186
-
187
-        } elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) {
188
-
189
-            $fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration();
190
-
191
-            // First case, we are on the "good side" of the relation, just query the repository
192
-            if (empty($fieldConfiguration['foreign_field'])) {
193
-                $this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName);
194
-            } else {
195
-                // Second case, we are the "bad side" of the relation, query the foreign repository
196
-                // e.g. in case of one-to-one relation.
197
-
198
-                // We must query the opposite side to get the identifier of the foreign object.
199
-                $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
200
-                $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
201
-                $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
202
-                $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
203
-
204
-                /** @var Content $foreignObject */
205
-                $this->$propertyName = $foreignContentRepository->$find($this->getUid());
206
-            }
207
-
208
-        }
209
-        return $this->$propertyName;
210
-    }
211
-
212
-    /**
213
-     * @return int
214
-     */
215
-    public function getUid()
216
-    {
217
-        return $this->uid;
218
-    }
219
-
220
-    /**
221
-     * @return string
222
-     */
223
-    public function getDataType()
224
-    {
225
-        return $this->dataType;
226
-    }
227
-
228
-    /**
229
-     * Whether a offset exists
230
-     *
231
-     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
232
-     * @param mixed $offset
233
-     * @return boolean true on success or false on failure.
234
-     * @throws \RuntimeException
235
-     * @throws \InvalidArgumentException
236
-     */
237
-    public function offsetExists($offset)
238
-    {
239
-        $offset = Field::name($offset)->of($this)->toPropertyName();
240
-        return isset($this->$offset);
241
-    }
242
-
243
-    /**
244
-     * Offset to retrieve
245
-     *
246
-     * @link http://php.net/manual/en/arrayaccess.offsetget.php
247
-     * @param mixed $offset
248
-     * @return mixed Can return all value types.
249
-     * @throws \RuntimeException
250
-     * @throws \InvalidArgumentException
251
-     */
252
-    public function offsetGet($offset)
253
-    {
254
-        $offset = Field::name($offset)->of($this)->toPropertyName();
255
-        $getter = 'get' . ucfirst($offset);
256
-        return $this->$getter();
257
-    }
258
-
259
-    /**
260
-     * Offset to set
261
-     *
262
-     * @link http://php.net/manual/en/arrayaccess.offsetset.php
263
-     * @param mixed $offset
264
-     * @param mixed $value
265
-     * @return $this
266
-     * @throws \RuntimeException
267
-     * @throws \InvalidArgumentException
268
-     */
269
-    public function offsetSet($offset, $value)
270
-    {
271
-        $offset = Field::name($offset)->of($this)->toPropertyName();
272
-        $setter = 'set' . ucfirst($offset);
273
-        $this->$setter($value);
274
-        return $this;
275
-    }
276
-
277
-    /**
278
-     * Offset to unset
279
-     *
280
-     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
281
-     * @param mixed $offset
282
-     * @throws NotImplementedException
283
-     * @return void
284
-     */
285
-    public function offsetUnset($offset)
286
-    {
287
-        $message = 'Un-setting value for Array object is not supported';
288
-        throw new NotImplementedException($message, 1376132306);
289
-    }
290
-
291
-    /**
292
-     * Convert this to array
293
-     *
294
-     * @return array
295
-     * @throws \InvalidArgumentException
296
-     */
297
-    public function toArray()
298
-    {
299
-        $result['uid'] = $this->uid;
300
-        $propertiesAndValues = json_decode(json_encode($this), true);
301
-
302
-        foreach ($propertiesAndValues as $propertyName => $value) {
303
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
304
-            $result[$fieldName] = $value;
305
-        }
306
-
307
-        return $result;
308
-    }
309
-
310
-    /**
311
-     * Convert this object to an array containing the resolved values.
312
-     *
313
-     * @param bool $resolveRelations
314
-     * @return array
315
-     * @throws \Exception
316
-     */
317
-    public function toValues($resolveRelations = true)
318
-    {
319
-        $result['uid'] = $this->uid;
320
-        $propertiesAndValues = json_decode(json_encode($this), true);
321
-
322
-        foreach ($propertiesAndValues as $propertyName => $value) {
323
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
324
-
325
-            $result[$fieldName] = $value;
326
-            if ($resolveRelations) {
327
-                $field = Tca::table($this->dataType)->field($fieldName);
328
-
329
-                $resolvedValue = '';
330
-                if ($field->getType() === FieldType::FILE) {
331
-
332
-                    if ($field->hasMany()) {
333
-                        $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
334
-
335
-                        $resolvedValue = [];
336
-                        foreach ($files as $file) {
337
-                            $resolvedValue[] = $file->getIdentifier();
338
-                        }
339
-                    } else {
340
-                        $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
341
-                        if (!empty($files)) {
342
-                            $resolvedValue = current($files)->getIdentifier();
343
-                        }
344
-                    }
345
-
346
-                    // Reset value
347
-                    $result[$fieldName] = $resolvedValue;
348
-
349
-                } elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) {
350
-                    $objects = $this[$fieldName];
351
-                    if (is_array($objects)) {
352
-                        $resolvedValue = [];
353
-                        foreach ($objects as $object) {
354
-                            /** @var $object Content */
355
-                            $labelField = Tca::table($object->getDataType())->getLabelField();
356
-                            $resolvedValue[] = $object[$labelField];
357
-                        }
358
-                    } elseif ($objects instanceof Content) {
359
-                        $labelField = Tca::table($objects->getDataType())->getLabelField();
360
-                        $resolvedValue = $objects[$labelField];
361
-                    }
362
-
363
-                    // Reset value
364
-                    $result[$fieldName] = $resolvedValue;
365
-                }
366
-            }
367
-        }
368
-
369
-        return $result;
370
-    }
371
-
372
-    /**
373
-     * Return the properties of this object.
374
-     *
375
-     * @return array
376
-     */
377
-    public function toProperties()
378
-    {
379
-        $result[] = 'uid';
380
-        $propertiesAndValues = json_decode(json_encode($this), true);
381
-
382
-        foreach ($propertiesAndValues as $propertyName => $value) {
383
-            $result[] = $propertyName;
384
-        }
385
-        return $result;
386
-    }
387
-
388
-    /**
389
-     * Return the properties of this object.
390
-     *
391
-     * @return array
392
-     */
393
-    public function toFields()
394
-    {
395
-        $result[] = 'uid';
396
-        $propertiesAndValues = json_decode(json_encode($this), true);
397
-
398
-        foreach ($propertiesAndValues as $propertyName => $value) {
399
-            $result[] = Property::name($propertyName)->of($this)->toFieldName();
400
-        }
401
-
402
-        return $result;
403
-    }
404
-
405
-    /**
406
-     * @return string
407
-     */
408
-    public function __toString()
409
-    {
410
-        $labelField = Tca::table($this->dataType)->getLabelField();
411
-        return $this[$labelField];
412
-    }
413
-
414
-    /**
415
-     * Remove fields according to BE User permission.
416
-     *
417
-     * @param $fields
418
-     * @return array
419
-     * @throws \Exception
420
-     */
421
-    protected function filterForBackendUser($fields)
422
-    {
423
-        if (!$this->getBackendUser()->isAdmin()) {
424
-            foreach ($fields as $key => $fieldName) {
425
-                if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) {
426
-                    unset($fields[$key]);
427
-                }
428
-            }
429
-        }
430
-        return $fields;
431
-    }
432
-
433
-    /**
434
-     * Remove fields according to Grid configuration.
435
-     *
436
-     * @param $fields
437
-     * @return array
438
-     */
439
-    protected function filterForConfiguration($fields)
440
-    {
441
-
442
-        $excludedFields = Tca::grid($this->dataType)->getExcludedFields();
443
-        foreach ($fields as $key => $field) {
444
-            if (in_array($field, $excludedFields)) {
445
-                unset($fields[$key]);
446
-            }
447
-        }
448
-
449
-        return $fields;
450
-    }
451
-
452
-    /**
453
-     * Returns an instance of the current Backend User.
454
-     *
455
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
456
-     */
457
-    protected function getBackendUser()
458
-    {
459
-        return $GLOBALS['BE_USER'];
460
-    }
461
-
462
-    /**
463
-     * Returns whether the current mode is Backend
464
-     *
465
-     * @return bool
466
-     */
467
-    protected function isBackendMode()
468
-    {
469
-        return TYPO3_MODE === 'BE';
470
-    }
26
+	/**
27
+	 * @var int
28
+	 */
29
+	protected $uid;
30
+
31
+	/**
32
+	 * @var string
33
+	 */
34
+	protected $dataType;
35
+
36
+	/**
37
+	 * Constructor for a Content object.
38
+	 *
39
+	 * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ...
40
+	 * @param array $contentData
41
+	 * @return \Fab\Vidi\Domain\Model\Content
42
+	 * @throws \InvalidArgumentException
43
+	 * @throws \Fab\Vidi\Exception\NotExistingClassException
44
+	 */
45
+	public function __construct($dataType, array $contentData = array())
46
+	{
47
+
48
+		$this->dataType = $dataType;
49
+		$this->uid = empty($contentData['uid']) ? null : (int)$contentData['uid'];
50
+
51
+		/** @var \Fab\Vidi\Tca\TableService $table */
52
+		$table = Tca::table($dataType);
53
+
54
+		// Initialize the array containing the allowed fields to be filled-in.
55
+		$fields = array('pid');
56
+
57
+		// If a creation time stamp has been defined for this data type.
58
+		if ($table->getTimeCreationField()) {
59
+			$fields[] = $table->getTimeCreationField();
60
+		}
61
+
62
+		// If an update time stamp has been defined for this data type.
63
+		if ($table->getTimeModificationField()) {
64
+			$fields[] = $table->getTimeModificationField();
65
+		}
66
+
67
+		// Merge the other fields allowed for this data type.
68
+		$fields = array_merge($fields, $table->getFields());
69
+
70
+		// Fetch excluded fields from the grid.
71
+		if ($this->isBackendMode()) {
72
+			$fields = $this->filterForConfiguration($fields);
73
+			$fields = $this->filterForBackendUser($fields);
74
+		}
75
+
76
+		// Get column to be displayed
77
+		foreach ($fields as $fieldName) {
78
+			if (array_key_exists($fieldName, $contentData)) {
79
+				$propertyName = Field::name($fieldName)->of($dataType)->toPropertyName();
80
+				$this->$propertyName = $contentData[$fieldName];
81
+			}
82
+		}
83
+	}
84
+
85
+	/**
86
+	 * Dispatches magic methods (findBy[Property]())
87
+	 *
88
+	 * @param string $methodName The name of the magic method
89
+	 * @param string $arguments The arguments of the magic method
90
+	 * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException
91
+	 * @return mixed
92
+	 * @api
93
+	 */
94
+	public function __call($methodName, $arguments)
95
+	{
96
+		$value = null;
97
+		if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
98
+			$propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
99
+
100
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
101
+			$field = Tca::table($this->dataType)->field($fieldName);
102
+
103
+			$value = $this->$propertyName;
104
+
105
+			// true means it is a relation and it is not yet resolved.
106
+			if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) {
107
+				$value = $this->resolveRelation($propertyName);
108
+			} elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) {
109
+
110
+				// Attempt to convert the value into a label for radio and select fields.
111
+				$label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value);
112
+				if ($label) {
113
+					$value = $label;
114
+				}
115
+			}
116
+
117
+		} elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
118
+			$propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
119
+			$this->$propertyName = $arguments[0];
120
+		}
121
+		return $value;
122
+	}
123
+
124
+	/**
125
+	 * Tell whether the property has a relation.
126
+	 *
127
+	 * @param string $propertyName
128
+	 * @return bool
129
+	 */
130
+	protected function hasRelation($propertyName)
131
+	{
132
+		$fieldName = Property::name($propertyName)->of($this)->toFieldName();
133
+		return Tca::table($this->dataType)->field($fieldName)->hasRelation();
134
+	}
135
+
136
+	/**
137
+	 * Try to "resolve" the property whether it has a relation.
138
+	 * If the property has not relation it simply returns the same value.
139
+	 *
140
+	 * @throws \RuntimeException
141
+	 * @param string $propertyName
142
+	 * @return mixed
143
+	 */
144
+	protected function resolveRelation($propertyName)
145
+	{
146
+
147
+		// Convert property name to field name and get the foreign data type.
148
+		$fieldName = Property::name($propertyName)->of($this)->toFieldName();
149
+		$foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType();
150
+
151
+		// Get the foreign repository instance form the factory
152
+		/** @var \Fab\Vidi\Domain\Repository\ContentRepository $foreignContentRepository */
153
+		$foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName);
154
+
155
+		if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
156
+
157
+			// Fetch values from repository
158
+			$values = GeneralUtility::trimExplode(',', $this->$propertyName);
159
+			$this->$propertyName = $foreignContentRepository->findIn('uid', $values);
160
+		} elseif (Tca::table($this->dataType)->field($fieldName)->hasMany()) {
161
+			// Include relation many-to-many and one-to-many
162
+			// Tca::table($this->dataType)->field($fieldName)->hasRelationOneToMany()
163
+			// Tca::table($this->dataType)->field($fieldName)->hasRelationManyToMany()
164
+
165
+			$foreignFieldName = Tca::table($this->dataType)->field($fieldName)->getForeignField();
166
+			if (empty($foreignFieldName)) {
167
+				$message = sprintf('Missing "foreign_field" key for field "%s" in table "%s".',
168
+					$fieldName,
169
+					$this->dataType
170
+				);
171
+				throw new \RuntimeException($message, 1376149186);
172
+			}
173
+
174
+			// Fetch values from repository.
175
+			$foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
176
+			$findByProperty = 'findBy' . ucfirst($foreignPropertyName);
177
+
178
+			// Date picker (type == group) are special fields because property path must contain the table name
179
+			// to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
180
+			$propertyValue = $this->uid;
181
+			if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
182
+				$propertyValue = $this->dataType . '.' . $this->uid;
183
+			}
184
+
185
+			$this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
186
+
187
+		} elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) {
188
+
189
+			$fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration();
190
+
191
+			// First case, we are on the "good side" of the relation, just query the repository
192
+			if (empty($fieldConfiguration['foreign_field'])) {
193
+				$this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName);
194
+			} else {
195
+				// Second case, we are the "bad side" of the relation, query the foreign repository
196
+				// e.g. in case of one-to-one relation.
197
+
198
+				// We must query the opposite side to get the identifier of the foreign object.
199
+				$foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
200
+				$foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
201
+				$foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
202
+				$find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
203
+
204
+				/** @var Content $foreignObject */
205
+				$this->$propertyName = $foreignContentRepository->$find($this->getUid());
206
+			}
207
+
208
+		}
209
+		return $this->$propertyName;
210
+	}
211
+
212
+	/**
213
+	 * @return int
214
+	 */
215
+	public function getUid()
216
+	{
217
+		return $this->uid;
218
+	}
219
+
220
+	/**
221
+	 * @return string
222
+	 */
223
+	public function getDataType()
224
+	{
225
+		return $this->dataType;
226
+	}
227
+
228
+	/**
229
+	 * Whether a offset exists
230
+	 *
231
+	 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
232
+	 * @param mixed $offset
233
+	 * @return boolean true on success or false on failure.
234
+	 * @throws \RuntimeException
235
+	 * @throws \InvalidArgumentException
236
+	 */
237
+	public function offsetExists($offset)
238
+	{
239
+		$offset = Field::name($offset)->of($this)->toPropertyName();
240
+		return isset($this->$offset);
241
+	}
242
+
243
+	/**
244
+	 * Offset to retrieve
245
+	 *
246
+	 * @link http://php.net/manual/en/arrayaccess.offsetget.php
247
+	 * @param mixed $offset
248
+	 * @return mixed Can return all value types.
249
+	 * @throws \RuntimeException
250
+	 * @throws \InvalidArgumentException
251
+	 */
252
+	public function offsetGet($offset)
253
+	{
254
+		$offset = Field::name($offset)->of($this)->toPropertyName();
255
+		$getter = 'get' . ucfirst($offset);
256
+		return $this->$getter();
257
+	}
258
+
259
+	/**
260
+	 * Offset to set
261
+	 *
262
+	 * @link http://php.net/manual/en/arrayaccess.offsetset.php
263
+	 * @param mixed $offset
264
+	 * @param mixed $value
265
+	 * @return $this
266
+	 * @throws \RuntimeException
267
+	 * @throws \InvalidArgumentException
268
+	 */
269
+	public function offsetSet($offset, $value)
270
+	{
271
+		$offset = Field::name($offset)->of($this)->toPropertyName();
272
+		$setter = 'set' . ucfirst($offset);
273
+		$this->$setter($value);
274
+		return $this;
275
+	}
276
+
277
+	/**
278
+	 * Offset to unset
279
+	 *
280
+	 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
281
+	 * @param mixed $offset
282
+	 * @throws NotImplementedException
283
+	 * @return void
284
+	 */
285
+	public function offsetUnset($offset)
286
+	{
287
+		$message = 'Un-setting value for Array object is not supported';
288
+		throw new NotImplementedException($message, 1376132306);
289
+	}
290
+
291
+	/**
292
+	 * Convert this to array
293
+	 *
294
+	 * @return array
295
+	 * @throws \InvalidArgumentException
296
+	 */
297
+	public function toArray()
298
+	{
299
+		$result['uid'] = $this->uid;
300
+		$propertiesAndValues = json_decode(json_encode($this), true);
301
+
302
+		foreach ($propertiesAndValues as $propertyName => $value) {
303
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
304
+			$result[$fieldName] = $value;
305
+		}
306
+
307
+		return $result;
308
+	}
309
+
310
+	/**
311
+	 * Convert this object to an array containing the resolved values.
312
+	 *
313
+	 * @param bool $resolveRelations
314
+	 * @return array
315
+	 * @throws \Exception
316
+	 */
317
+	public function toValues($resolveRelations = true)
318
+	{
319
+		$result['uid'] = $this->uid;
320
+		$propertiesAndValues = json_decode(json_encode($this), true);
321
+
322
+		foreach ($propertiesAndValues as $propertyName => $value) {
323
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
324
+
325
+			$result[$fieldName] = $value;
326
+			if ($resolveRelations) {
327
+				$field = Tca::table($this->dataType)->field($fieldName);
328
+
329
+				$resolvedValue = '';
330
+				if ($field->getType() === FieldType::FILE) {
331
+
332
+					if ($field->hasMany()) {
333
+						$files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
334
+
335
+						$resolvedValue = [];
336
+						foreach ($files as $file) {
337
+							$resolvedValue[] = $file->getIdentifier();
338
+						}
339
+					} else {
340
+						$files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
341
+						if (!empty($files)) {
342
+							$resolvedValue = current($files)->getIdentifier();
343
+						}
344
+					}
345
+
346
+					// Reset value
347
+					$result[$fieldName] = $resolvedValue;
348
+
349
+				} elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) {
350
+					$objects = $this[$fieldName];
351
+					if (is_array($objects)) {
352
+						$resolvedValue = [];
353
+						foreach ($objects as $object) {
354
+							/** @var $object Content */
355
+							$labelField = Tca::table($object->getDataType())->getLabelField();
356
+							$resolvedValue[] = $object[$labelField];
357
+						}
358
+					} elseif ($objects instanceof Content) {
359
+						$labelField = Tca::table($objects->getDataType())->getLabelField();
360
+						$resolvedValue = $objects[$labelField];
361
+					}
362
+
363
+					// Reset value
364
+					$result[$fieldName] = $resolvedValue;
365
+				}
366
+			}
367
+		}
368
+
369
+		return $result;
370
+	}
371
+
372
+	/**
373
+	 * Return the properties of this object.
374
+	 *
375
+	 * @return array
376
+	 */
377
+	public function toProperties()
378
+	{
379
+		$result[] = 'uid';
380
+		$propertiesAndValues = json_decode(json_encode($this), true);
381
+
382
+		foreach ($propertiesAndValues as $propertyName => $value) {
383
+			$result[] = $propertyName;
384
+		}
385
+		return $result;
386
+	}
387
+
388
+	/**
389
+	 * Return the properties of this object.
390
+	 *
391
+	 * @return array
392
+	 */
393
+	public function toFields()
394
+	{
395
+		$result[] = 'uid';
396
+		$propertiesAndValues = json_decode(json_encode($this), true);
397
+
398
+		foreach ($propertiesAndValues as $propertyName => $value) {
399
+			$result[] = Property::name($propertyName)->of($this)->toFieldName();
400
+		}
401
+
402
+		return $result;
403
+	}
404
+
405
+	/**
406
+	 * @return string
407
+	 */
408
+	public function __toString()
409
+	{
410
+		$labelField = Tca::table($this->dataType)->getLabelField();
411
+		return $this[$labelField];
412
+	}
413
+
414
+	/**
415
+	 * Remove fields according to BE User permission.
416
+	 *
417
+	 * @param $fields
418
+	 * @return array
419
+	 * @throws \Exception
420
+	 */
421
+	protected function filterForBackendUser($fields)
422
+	{
423
+		if (!$this->getBackendUser()->isAdmin()) {
424
+			foreach ($fields as $key => $fieldName) {
425
+				if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) {
426
+					unset($fields[$key]);
427
+				}
428
+			}
429
+		}
430
+		return $fields;
431
+	}
432
+
433
+	/**
434
+	 * Remove fields according to Grid configuration.
435
+	 *
436
+	 * @param $fields
437
+	 * @return array
438
+	 */
439
+	protected function filterForConfiguration($fields)
440
+	{
441
+
442
+		$excludedFields = Tca::grid($this->dataType)->getExcludedFields();
443
+		foreach ($fields as $key => $field) {
444
+			if (in_array($field, $excludedFields)) {
445
+				unset($fields[$key]);
446
+			}
447
+		}
448
+
449
+		return $fields;
450
+	}
451
+
452
+	/**
453
+	 * Returns an instance of the current Backend User.
454
+	 *
455
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
456
+	 */
457
+	protected function getBackendUser()
458
+	{
459
+		return $GLOBALS['BE_USER'];
460
+	}
461
+
462
+	/**
463
+	 * Returns whether the current mode is Backend
464
+	 *
465
+	 * @return bool
466
+	 */
467
+	protected function isBackendMode()
468
+	{
469
+		return TYPO3_MODE === 'BE';
470
+	}
471 471
 
472 472
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     {
96 96
         $value = null;
97 97
         if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
98
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
98
+            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)).substr(substr($methodName, 3), 1);
99 99
 
100 100
             $fieldName = Property::name($propertyName)->of($this)->toFieldName();
101 101
             $field = Tca::table($this->dataType)->field($fieldName);
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             }
116 116
 
117 117
         } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
118
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
118
+            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)).substr(substr($methodName, 3), 1);
119 119
             $this->$propertyName = $arguments[0];
120 120
         }
121 121
         return $value;
@@ -173,13 +173,13 @@  discard block
 block discarded – undo
173 173
 
174 174
             // Fetch values from repository.
175 175
             $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
176
-            $findByProperty = 'findBy' . ucfirst($foreignPropertyName);
176
+            $findByProperty = 'findBy'.ucfirst($foreignPropertyName);
177 177
 
178 178
             // Date picker (type == group) are special fields because property path must contain the table name
179 179
             // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
180 180
             $propertyValue = $this->uid;
181 181
             if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
182
-                $propertyValue = $this->dataType . '.' . $this->uid;
182
+                $propertyValue = $this->dataType.'.'.$this->uid;
183 183
             }
184 184
 
185 185
             $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
                 $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
200 200
                 $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
201 201
                 $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
202
-                $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
202
+                $find = 'findOneBy'.GeneralUtility::underscoredToUpperCamelCase($foreignField);
203 203
 
204 204
                 /** @var Content $foreignObject */
205 205
                 $this->$propertyName = $foreignContentRepository->$find($this->getUid());
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
     public function offsetGet($offset)
253 253
     {
254 254
         $offset = Field::name($offset)->of($this)->toPropertyName();
255
-        $getter = 'get' . ucfirst($offset);
255
+        $getter = 'get'.ucfirst($offset);
256 256
         return $this->$getter();
257 257
     }
258 258
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
     public function offsetSet($offset, $value)
270 270
     {
271 271
         $offset = Field::name($offset)->of($this)->toPropertyName();
272
-        $setter = 'set' . ucfirst($offset);
272
+        $setter = 'set'.ucfirst($offset);
273 273
         $this->$setter($value);
274 274
         return $this;
275 275
     }
Please login to merge, or discard this patch.
Classes/Grid/GridAnalyserService.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      *
82 82
      * @param string $tableName
83 83
      * @param string $fieldName
84
-     * @return array
84
+     * @return string[]
85 85
      */
86 86
     protected function checkRelationManyToMany($tableName, $fieldName)
87 87
     {
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      * @param string $tableName
116 116
      * @param string $fieldName
117 117
      * @param string $relationType
118
-     * @return array
118
+     * @return string[]
119 119
      */
120 120
     protected function checkRelationOf($tableName, $fieldName, $relationType)
121 121
     {
Please login to merge, or discard this patch.
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -16,114 +16,114 @@
 block discarded – undo
16 16
 class GridAnalyserService
17 17
 {
18 18
 
19
-    /**
20
-     * Check relation for table.
21
-     *
22
-     * @param $tableName
23
-     * @return array
24
-     */
25
-    public function checkRelationForTable($tableName)
26
-    {
19
+	/**
20
+	 * Check relation for table.
21
+	 *
22
+	 * @param $tableName
23
+	 * @return array
24
+	 */
25
+	public function checkRelationForTable($tableName)
26
+	{
27 27
 
28
-        $relations = [];
29
-        $table = Tca::table($tableName);
28
+		$relations = [];
29
+		$table = Tca::table($tableName);
30 30
 
31
-        $missingOppositionRelationMessage = <<<EOF
31
+		$missingOppositionRelationMessage = <<<EOF
32 32
 
33 33
   WARNING! Could not define relation precisely. This is not necessarily a problem
34 34
   if the opposite relation is not required in a Grid. But consider adding the opposite
35 35
   TCA configuration if so.
36 36
 EOF;
37 37
 
38
-        foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) {
39
-
40
-            if ($table->hasField($fieldName)) {
41
-                if ($table->field($fieldName)->hasMany()) {
42
-                    if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
43
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values');
44
-                        $relations = array_merge($relations, $_relations);
45
-                    } elseif ($table->field($fieldName)->hasRelationManyToMany()) {
46
-                        $_relations = $this->checkRelationManyToMany($tableName, $fieldName);
47
-                        $relations = array_merge($relations, $_relations);
48
-
49
-                    } elseif ($table->field($fieldName)->hasRelationOneToMany()) {
50
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many');
51
-                        $relations = array_merge($relations, $_relations);
52
-                    } else {
53
-                        $relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage);
54
-                    }
55
-                    $relations[] = '';
56
-                } elseif ($table->field($fieldName)->hasOne()) {
57
-
58
-                    if ($table->field($fieldName)->hasRelationOneToOne()) {
59
-                        $relations[] = sprintf('* one-to-one "%s"', $fieldName);
60
-                    } elseif ($table->field($fieldName)->hasRelationManyToOne()) {
61
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one');
62
-                        $relations = array_merge($relations, $_relations);
63
-                    } else {
64
-                        $relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage);
65
-                    }
66
-                    $relations[] = '';
67
-                }
68
-            }
69
-        }
70
-        return $relations;
71
-    }
72
-
73
-    /**
74
-     * Convenience method for printing out relation many-to-many.
75
-     *
76
-     * @param string $tableName
77
-     * @param string $fieldName
78
-     * @return array
79
-     */
80
-    protected function checkRelationManyToMany($tableName, $fieldName)
81
-    {
82
-
83
-        $output = [];
84
-
85
-        $table = Tca::table($tableName);
86
-        $output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName);
87
-
88
-        $foreignTable = $table->field($fieldName)->getForeignTable();
89
-        $manyToManyTable = $table->field($fieldName)->getManyToManyTable();
90
-        $foreignField = $table->field($fieldName)->getForeignField();
91
-
92
-        if (!$foreignField) {
93
-            $output[] = sprintf('  ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName);
94
-        } elseif (!$foreignTable) {
95
-            $output[] = sprintf('  ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName);
96
-        } elseif (!$manyToManyTable) {
97
-            $output[] = sprintf('  ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName);
98
-        } else {
99
-            $output[] = sprintf('  %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField);
100
-        }
101
-
102
-        $output[] = '';
103
-        return $output;
104
-    }
105
-
106
-    /**
107
-     * Convenience method for printing out relation.
108
-     *
109
-     * @param string $tableName
110
-     * @param string $fieldName
111
-     * @param string $relationType
112
-     * @return array
113
-     */
114
-    protected function checkRelationOf($tableName, $fieldName, $relationType)
115
-    {
116
-
117
-        $output = [];
118
-
119
-        $table = Tca::table($tableName);
120
-        $output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType);
121
-
122
-        $foreignTable = $table->field($fieldName)->getForeignTable();
123
-        $foreignField = $table->field($fieldName)->getForeignField();
124
-        $output[] = sprintf('  %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField);
125
-        $output[] = '';
126
-
127
-        return $output;
128
-    }
38
+		foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) {
39
+
40
+			if ($table->hasField($fieldName)) {
41
+				if ($table->field($fieldName)->hasMany()) {
42
+					if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
43
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values');
44
+						$relations = array_merge($relations, $_relations);
45
+					} elseif ($table->field($fieldName)->hasRelationManyToMany()) {
46
+						$_relations = $this->checkRelationManyToMany($tableName, $fieldName);
47
+						$relations = array_merge($relations, $_relations);
48
+
49
+					} elseif ($table->field($fieldName)->hasRelationOneToMany()) {
50
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many');
51
+						$relations = array_merge($relations, $_relations);
52
+					} else {
53
+						$relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage);
54
+					}
55
+					$relations[] = '';
56
+				} elseif ($table->field($fieldName)->hasOne()) {
57
+
58
+					if ($table->field($fieldName)->hasRelationOneToOne()) {
59
+						$relations[] = sprintf('* one-to-one "%s"', $fieldName);
60
+					} elseif ($table->field($fieldName)->hasRelationManyToOne()) {
61
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one');
62
+						$relations = array_merge($relations, $_relations);
63
+					} else {
64
+						$relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage);
65
+					}
66
+					$relations[] = '';
67
+				}
68
+			}
69
+		}
70
+		return $relations;
71
+	}
72
+
73
+	/**
74
+	 * Convenience method for printing out relation many-to-many.
75
+	 *
76
+	 * @param string $tableName
77
+	 * @param string $fieldName
78
+	 * @return array
79
+	 */
80
+	protected function checkRelationManyToMany($tableName, $fieldName)
81
+	{
82
+
83
+		$output = [];
84
+
85
+		$table = Tca::table($tableName);
86
+		$output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName);
87
+
88
+		$foreignTable = $table->field($fieldName)->getForeignTable();
89
+		$manyToManyTable = $table->field($fieldName)->getManyToManyTable();
90
+		$foreignField = $table->field($fieldName)->getForeignField();
91
+
92
+		if (!$foreignField) {
93
+			$output[] = sprintf('  ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName);
94
+		} elseif (!$foreignTable) {
95
+			$output[] = sprintf('  ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName);
96
+		} elseif (!$manyToManyTable) {
97
+			$output[] = sprintf('  ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName);
98
+		} else {
99
+			$output[] = sprintf('  %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField);
100
+		}
101
+
102
+		$output[] = '';
103
+		return $output;
104
+	}
105
+
106
+	/**
107
+	 * Convenience method for printing out relation.
108
+	 *
109
+	 * @param string $tableName
110
+	 * @param string $fieldName
111
+	 * @param string $relationType
112
+	 * @return array
113
+	 */
114
+	protected function checkRelationOf($tableName, $fieldName, $relationType)
115
+	{
116
+
117
+		$output = [];
118
+
119
+		$table = Tca::table($tableName);
120
+		$output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType);
121
+
122
+		$foreignTable = $table->field($fieldName)->getForeignTable();
123
+		$foreignField = $table->field($fieldName)->getForeignField();
124
+		$output[] = sprintf('  %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField);
125
+		$output[] = '';
126
+
127
+		return $output;
128
+	}
129 129
 }
Please login to merge, or discard this patch.
Classes/Processor/ContentObjectProcessor.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
     /**
32 32
      * @param ProcessContentDataSignalArguments $signalArguments
33
-     * @return array
33
+     * @return ProcessContentDataSignalArguments[]
34 34
      */
35 35
     public function processRelations(ProcessContentDataSignalArguments $signalArguments)
36 36
     {
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
     /**
52 52
      * @param \Fab\Vidi\Domain\Model\Content $object
53
-     * @param $fieldNameAndPath
53
+     * @param string $fieldNameAndPath
54 54
      * @param array $contentData
55 55
      * @param string $savingBehavior
56 56
      * @return array
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@
 block discarded – undo
71 71
                 $relatedValues = $this->getRelatedValues($object, $fieldNameAndPath, $fieldName);
72 72
 
73 73
                 foreach ($values as $value) {
74
-                    $appendOrRemove = $savingBehavior . 'Relations';
74
+                    $appendOrRemove = $savingBehavior.'Relations';
75 75
                     $relatedValues = $this->$appendOrRemove($value, $relatedValues);
76 76
                 }
77 77
 
Please login to merge, or discard this patch.
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -22,121 +22,121 @@
 block discarded – undo
22 22
 class ContentObjectProcessor implements SingletonInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @param ProcessContentDataSignalArguments $signalArguments
27
-     * @return array
28
-     */
29
-    public function processRelations(ProcessContentDataSignalArguments $signalArguments)
30
-    {
31
-
32
-        $contentObject = $signalArguments->getContentObject();
33
-        $fieldNameAndPath = $signalArguments->getFieldNameAndPath();
34
-        $contentData = $signalArguments->getContentData();
35
-        $savingBehavior = $signalArguments->getSavingBehavior();
36
-
37
-        if ($savingBehavior !== SavingBehavior::REPLACE) {
38
-            $contentData = $this->appendOrRemoveRelations($contentObject, $fieldNameAndPath, $contentData, $savingBehavior);
39
-            $signalArguments->setContentData($contentData);
40
-        }
41
-
42
-        return array($signalArguments);
43
-    }
44
-
45
-    /**
46
-     * @param \Fab\Vidi\Domain\Model\Content $object
47
-     * @param $fieldNameAndPath
48
-     * @param array $contentData
49
-     * @param string $savingBehavior
50
-     * @return array
51
-     */
52
-    protected function appendOrRemoveRelations(Content $object, $fieldNameAndPath, array $contentData, $savingBehavior)
53
-    {
54
-
55
-        foreach ($contentData as $fieldName => $values) {
56
-
57
-            $resolvedObject = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath);
58
-
59
-            if (Tca::table($resolvedObject)->field($fieldName)->hasMany()) {
60
-
61
-                // true means CSV values must be converted to array.
62
-                if (!is_array($values)) {
63
-                    $values = GeneralUtility::trimExplode(',', $values);
64
-                }
65
-                $relatedValues = $this->getRelatedValues($object, $fieldNameAndPath, $fieldName);
66
-
67
-                foreach ($values as $value) {
68
-                    $appendOrRemove = $savingBehavior . 'Relations';
69
-                    $relatedValues = $this->$appendOrRemove($value, $relatedValues);
70
-                }
71
-
72
-                $contentData[$fieldName] = $relatedValues;
73
-            }
74
-        }
75
-        return $contentData;
76
-    }
77
-
78
-    /**
79
-     * @param $value
80
-     * @param array $relatedValues
81
-     * @return array
82
-     */
83
-    protected function appendRelations($value, array $relatedValues)
84
-    {
85
-        if (!in_array($value, $relatedValues)) {
86
-            $relatedValues[] = $value;
87
-        }
88
-        return $relatedValues;
89
-    }
90
-
91
-    /**
92
-     * @param $value
93
-     * @param array $relatedValues
94
-     * @return array
95
-     */
96
-    protected function removeRelations($value, array $relatedValues)
97
-    {
98
-        if (in_array($value, $relatedValues)) {
99
-            $key = array_search($value, $relatedValues);
100
-            unset($relatedValues[$key]);
101
-        }
102
-        return $relatedValues;
103
-    }
104
-
105
-    /**
106
-     * @param \Fab\Vidi\Domain\Model\Content $object
107
-     * @param string $fieldNameAndPath
108
-     * @param string $fieldName
109
-     * @return array
110
-     */
111
-    protected function getRelatedValues(Content $object, $fieldNameAndPath, $fieldName)
112
-    {
113
-
114
-        $values = [];
115
-        $relatedContentObjects = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, $fieldName);
116
-
117
-        if (is_array($relatedContentObjects)) {
118
-            /** @var Content $relatedContentObject */
119
-            foreach ($relatedContentObjects as $relatedContentObject) {
120
-                $values[] = $relatedContentObject->getUid();
121
-            }
122
-        }
123
-
124
-        return $values;
125
-    }
126
-
127
-    /**
128
-     * @return \Fab\Vidi\Resolver\ContentObjectResolver|object
129
-     */
130
-    protected function getContentObjectResolver()
131
-    {
132
-        return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\ContentObjectResolver::class);
133
-    }
134
-
135
-    /**
136
-     * @return \Fab\Vidi\Resolver\FieldPathResolver|object
137
-     */
138
-    protected function getFieldPathResolver()
139
-    {
140
-        return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\FieldPathResolver::class);
141
-    }
25
+	/**
26
+	 * @param ProcessContentDataSignalArguments $signalArguments
27
+	 * @return array
28
+	 */
29
+	public function processRelations(ProcessContentDataSignalArguments $signalArguments)
30
+	{
31
+
32
+		$contentObject = $signalArguments->getContentObject();
33
+		$fieldNameAndPath = $signalArguments->getFieldNameAndPath();
34
+		$contentData = $signalArguments->getContentData();
35
+		$savingBehavior = $signalArguments->getSavingBehavior();
36
+
37
+		if ($savingBehavior !== SavingBehavior::REPLACE) {
38
+			$contentData = $this->appendOrRemoveRelations($contentObject, $fieldNameAndPath, $contentData, $savingBehavior);
39
+			$signalArguments->setContentData($contentData);
40
+		}
41
+
42
+		return array($signalArguments);
43
+	}
44
+
45
+	/**
46
+	 * @param \Fab\Vidi\Domain\Model\Content $object
47
+	 * @param $fieldNameAndPath
48
+	 * @param array $contentData
49
+	 * @param string $savingBehavior
50
+	 * @return array
51
+	 */
52
+	protected function appendOrRemoveRelations(Content $object, $fieldNameAndPath, array $contentData, $savingBehavior)
53
+	{
54
+
55
+		foreach ($contentData as $fieldName => $values) {
56
+
57
+			$resolvedObject = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath);
58
+
59
+			if (Tca::table($resolvedObject)->field($fieldName)->hasMany()) {
60
+
61
+				// true means CSV values must be converted to array.
62
+				if (!is_array($values)) {
63
+					$values = GeneralUtility::trimExplode(',', $values);
64
+				}
65
+				$relatedValues = $this->getRelatedValues($object, $fieldNameAndPath, $fieldName);
66
+
67
+				foreach ($values as $value) {
68
+					$appendOrRemove = $savingBehavior . 'Relations';
69
+					$relatedValues = $this->$appendOrRemove($value, $relatedValues);
70
+				}
71
+
72
+				$contentData[$fieldName] = $relatedValues;
73
+			}
74
+		}
75
+		return $contentData;
76
+	}
77
+
78
+	/**
79
+	 * @param $value
80
+	 * @param array $relatedValues
81
+	 * @return array
82
+	 */
83
+	protected function appendRelations($value, array $relatedValues)
84
+	{
85
+		if (!in_array($value, $relatedValues)) {
86
+			$relatedValues[] = $value;
87
+		}
88
+		return $relatedValues;
89
+	}
90
+
91
+	/**
92
+	 * @param $value
93
+	 * @param array $relatedValues
94
+	 * @return array
95
+	 */
96
+	protected function removeRelations($value, array $relatedValues)
97
+	{
98
+		if (in_array($value, $relatedValues)) {
99
+			$key = array_search($value, $relatedValues);
100
+			unset($relatedValues[$key]);
101
+		}
102
+		return $relatedValues;
103
+	}
104
+
105
+	/**
106
+	 * @param \Fab\Vidi\Domain\Model\Content $object
107
+	 * @param string $fieldNameAndPath
108
+	 * @param string $fieldName
109
+	 * @return array
110
+	 */
111
+	protected function getRelatedValues(Content $object, $fieldNameAndPath, $fieldName)
112
+	{
113
+
114
+		$values = [];
115
+		$relatedContentObjects = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, $fieldName);
116
+
117
+		if (is_array($relatedContentObjects)) {
118
+			/** @var Content $relatedContentObject */
119
+			foreach ($relatedContentObjects as $relatedContentObject) {
120
+				$values[] = $relatedContentObject->getUid();
121
+			}
122
+		}
123
+
124
+		return $values;
125
+	}
126
+
127
+	/**
128
+	 * @return \Fab\Vidi\Resolver\ContentObjectResolver|object
129
+	 */
130
+	protected function getContentObjectResolver()
131
+	{
132
+		return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\ContentObjectResolver::class);
133
+	}
134
+
135
+	/**
136
+	 * @return \Fab\Vidi\Resolver\FieldPathResolver|object
137
+	 */
138
+	protected function getFieldPathResolver()
139
+	{
140
+		return GeneralUtility::makeInstance(\Fab\Vidi\Resolver\FieldPathResolver::class);
141
+	}
142 142
 }
Please login to merge, or discard this patch.
Classes/Processor/MarkerProcessor.php 3 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.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@
 block discarded – undo
105 105
             $replace = $structure[2];
106 106
 
107 107
             // Perhaps needs to be improved here if $search contains "/" precisely.
108
-            $updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue);
108
+            $updateValue = preg_replace('/'.$search.'/isU', $replace, $currentValue);
109 109
         }
110 110
         return $updateValue;
111 111
     }
Please login to merge, or discard this patch.
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -20,114 +20,114 @@
 block discarded – undo
20 20
 class MarkerProcessor implements SingletonInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @var array
25
-     */
26
-    protected $wellKnownMarkers = array(
27
-        '{*}',
28
-        '{counter}',
29
-        '{date}',
30
-        '{creation_date}'
31
-    );
32
-
33
-    /**
34
-     * @param ProcessContentDataSignalArguments $signalArguments
35
-     * @return array
36
-     */
37
-    public function processMarkers(ProcessContentDataSignalArguments $signalArguments)
38
-    {
39
-
40
-        $contentData = $signalArguments->getContentData();
41
-        $creationTime = $this->getCreationTime($signalArguments);
42
-
43
-        // Process markers
44
-        foreach ($signalArguments->getContentData() as $fieldName => $updateValue) {
45
-            if (is_scalar($updateValue)) {
46
-
47
-                $currentValue = $this->getContentObjectResolver()->getValue(
48
-                    $signalArguments->getContentObject(),
49
-                    $signalArguments->getFieldNameAndPath(),
50
-                    $fieldName,
51
-                    $signalArguments->getLanguage()
52
-                );
53
-                $counter = $signalArguments->getCounter();
54
-
55
-                $updateValue = $this->searchAndReplace($updateValue, $currentValue);
56
-                $updateValue = $this->replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime);
57
-
58
-                $contentData[$fieldName] = $updateValue;
59
-            }
60
-        }
61
-
62
-        $signalArguments->setContentData($contentData);
63
-        return array($signalArguments);
64
-    }
65
-
66
-    /**
67
-     * @param string $updateValue
68
-     * @param string $currentValue
69
-     * @param int $counter
70
-     * @param $creationTime
71
-     * @return string
72
-     */
73
-    protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime)
74
-    {
75
-
76
-        // Replaces values.
77
-        $replaces = array(
78
-            $currentValue,
79
-            $counter,
80
-            date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']),
81
-            date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $creationTime),
82
-        );
83
-
84
-        // Replace me!
85
-        return str_replace($this->wellKnownMarkers, $replaces, $updateValue);
86
-    }
87
-
88
-    /**
89
-     * @param string $updateValue
90
-     * @param string $currentValue
91
-     * @return string
92
-     */
93
-    protected function searchAndReplace($updateValue, $currentValue)
94
-    {
95
-
96
-        if (strpos($updateValue, 's/') !== false) {
97
-            $structure = explode('/', $updateValue);
98
-            $search = $structure[1];
99
-            $replace = $structure[2];
100
-
101
-            // Perhaps needs to be improved here if $search contains "/" precisely.
102
-            $updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue);
103
-        }
104
-        return $updateValue;
105
-    }
106
-
107
-    /**
108
-     * @param ProcessContentDataSignalArguments $signalArguments
109
-     * @return int
110
-     */
111
-    protected function getCreationTime(ProcessContentDataSignalArguments $signalArguments)
112
-    {
113
-        $creationTime = 0;
114
-        $creationTimeField = Tca::table($signalArguments->getContentObject()->getDataType())->getTimeCreationField();
115
-        if ($creationTimeField) {
116
-            $creationTime = $this->getContentObjectResolver()->getValue(
117
-                $signalArguments->getContentObject(),
118
-                $signalArguments->getFieldNameAndPath(),
119
-                $creationTimeField
120
-            );
121
-        }
122
-        return $creationTime;
123
-    }
124
-
125
-    /**
126
-     * @return ContentObjectResolver
127
-     */
128
-    protected function getContentObjectResolver()
129
-    {
130
-        return GeneralUtility::makeInstance(ContentObjectResolver::class);
131
-    }
23
+	/**
24
+	 * @var array
25
+	 */
26
+	protected $wellKnownMarkers = array(
27
+		'{*}',
28
+		'{counter}',
29
+		'{date}',
30
+		'{creation_date}'
31
+	);
32
+
33
+	/**
34
+	 * @param ProcessContentDataSignalArguments $signalArguments
35
+	 * @return array
36
+	 */
37
+	public function processMarkers(ProcessContentDataSignalArguments $signalArguments)
38
+	{
39
+
40
+		$contentData = $signalArguments->getContentData();
41
+		$creationTime = $this->getCreationTime($signalArguments);
42
+
43
+		// Process markers
44
+		foreach ($signalArguments->getContentData() as $fieldName => $updateValue) {
45
+			if (is_scalar($updateValue)) {
46
+
47
+				$currentValue = $this->getContentObjectResolver()->getValue(
48
+					$signalArguments->getContentObject(),
49
+					$signalArguments->getFieldNameAndPath(),
50
+					$fieldName,
51
+					$signalArguments->getLanguage()
52
+				);
53
+				$counter = $signalArguments->getCounter();
54
+
55
+				$updateValue = $this->searchAndReplace($updateValue, $currentValue);
56
+				$updateValue = $this->replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime);
57
+
58
+				$contentData[$fieldName] = $updateValue;
59
+			}
60
+		}
61
+
62
+		$signalArguments->setContentData($contentData);
63
+		return array($signalArguments);
64
+	}
65
+
66
+	/**
67
+	 * @param string $updateValue
68
+	 * @param string $currentValue
69
+	 * @param int $counter
70
+	 * @param $creationTime
71
+	 * @return string
72
+	 */
73
+	protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime)
74
+	{
75
+
76
+		// Replaces values.
77
+		$replaces = array(
78
+			$currentValue,
79
+			$counter,
80
+			date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']),
81
+			date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $creationTime),
82
+		);
83
+
84
+		// Replace me!
85
+		return str_replace($this->wellKnownMarkers, $replaces, $updateValue);
86
+	}
87
+
88
+	/**
89
+	 * @param string $updateValue
90
+	 * @param string $currentValue
91
+	 * @return string
92
+	 */
93
+	protected function searchAndReplace($updateValue, $currentValue)
94
+	{
95
+
96
+		if (strpos($updateValue, 's/') !== false) {
97
+			$structure = explode('/', $updateValue);
98
+			$search = $structure[1];
99
+			$replace = $structure[2];
100
+
101
+			// Perhaps needs to be improved here if $search contains "/" precisely.
102
+			$updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue);
103
+		}
104
+		return $updateValue;
105
+	}
106
+
107
+	/**
108
+	 * @param ProcessContentDataSignalArguments $signalArguments
109
+	 * @return int
110
+	 */
111
+	protected function getCreationTime(ProcessContentDataSignalArguments $signalArguments)
112
+	{
113
+		$creationTime = 0;
114
+		$creationTimeField = Tca::table($signalArguments->getContentObject()->getDataType())->getTimeCreationField();
115
+		if ($creationTimeField) {
116
+			$creationTime = $this->getContentObjectResolver()->getValue(
117
+				$signalArguments->getContentObject(),
118
+				$signalArguments->getFieldNameAndPath(),
119
+				$creationTimeField
120
+			);
121
+		}
122
+		return $creationTime;
123
+	}
124
+
125
+	/**
126
+	 * @return ContentObjectResolver
127
+	 */
128
+	protected function getContentObjectResolver()
129
+	{
130
+		return GeneralUtility::makeInstance(ContentObjectResolver::class);
131
+	}
132 132
 
133 133
 }
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   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -23,126 +23,126 @@
 block discarded – undo
23 23
 class ContentService
24 24
 {
25 25
 
26
-    /**
27
-     * @var string
28
-     */
29
-    protected $dataType;
30
-
31
-    /**
32
-     * @var \Fab\Vidi\Domain\Model\Content[]
33
-     */
34
-    protected $objects = [];
35
-
36
-    /**
37
-     * @var int
38
-     */
39
-    protected $numberOfObjects = 0;
40
-
41
-    /**
42
-     * Constructor
43
-     *
44
-     * @param string $dataType
45
-     */
46
-    public function __construct($dataType = '')
47
-    {
48
-        if (empty($dataType)) {
49
-            $dataType = $this->getModuleLoader()->getDataType();
50
-        }
51
-        $this->dataType = $dataType;
52
-    }
53
-
54
-    /**
55
-     * Fetch the files given an object assuming
56
-     *
57
-     * @param Matcher $matcher
58
-     * @param Order $order The order
59
-     * @param int $limit
60
-     * @param int $offset
61
-     * @return $this
62
-     */
63
-    public function findBy(Matcher $matcher, Order $order = null, $limit = null, $offset = null)
64
-    {
65
-
66
-        // Query the repository.
67
-        $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order, $limit, $offset);
68
-        $signalResult = $this->emitAfterFindContentObjectsSignal($objects, $matcher, $order, $limit, $offset);
69
-
70
-        // Reset objects variable after possible signal / slot processing.
71
-        $this->objects = $signalResult->getContentObjects();
72
-
73
-        // Count number of content objects.
74
-        if ($signalResult->getHasBeenProcessed()) {
75
-            $this->numberOfObjects = $signalResult->getNumberOfObjects();
76
-        } else {
77
-            $this->numberOfObjects = ContentRepositoryFactory::getInstance($this->dataType)->countBy($matcher);
78
-        }
79
-
80
-        return $this;
81
-    }
82
-
83
-    /**
84
-     * Signal that is called after the content objects have been found.
85
-     *
86
-     * @param array $contentObjects
87
-     * @param \Fab\Vidi\Persistence\Matcher $matcher
88
-     * @param Order $order
89
-     * @param int $limit
90
-     * @param int $offset
91
-     * @return AfterFindContentObjectsSignalArguments
92
-     */
93
-    protected function emitAfterFindContentObjectsSignal($contentObjects, Matcher $matcher, Order $order = null, $limit = 0, $offset = 0)
94
-    {
95
-
96
-        /** @var AfterFindContentObjectsSignalArguments $signalArguments */
97
-        $signalArguments = GeneralUtility::makeInstance(AfterFindContentObjectsSignalArguments::class);
98
-        $signalArguments->setDataType($this->dataType)
99
-            ->setContentObjects($contentObjects)
100
-            ->setMatcher($matcher)
101
-            ->setOrder($order)
102
-            ->setLimit($limit)
103
-            ->setOffset($offset)
104
-            ->setHasBeenProcessed(false);
105
-
106
-        $signalResult = $this->getSignalSlotDispatcher()->dispatch(ContentService::class, 'afterFindContentObjects', array($signalArguments));
107
-        return $signalResult[0];
108
-    }
109
-
110
-    /**
111
-     * Get the Vidi Module Loader.
112
-     *
113
-     * @return ModuleLoader|object
114
-     */
115
-    protected function getModuleLoader()
116
-    {
117
-        return GeneralUtility::makeInstance(ModuleLoader::class);
118
-    }
119
-
120
-    /**
121
-     * Get the SignalSlot dispatcher.
122
-     *
123
-     * @return Dispatcher|object
124
-     */
125
-    protected function getSignalSlotDispatcher()
126
-    {
127
-        /** @var ObjectManager $objectManager */
128
-        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
129
-        return $objectManager->get(Dispatcher::class);
130
-    }
131
-
132
-    /**
133
-     * @return \Fab\Vidi\Domain\Model\Content[]
134
-     */
135
-    public function getObjects()
136
-    {
137
-        return $this->objects;
138
-    }
139
-
140
-    /**
141
-     * @return int
142
-     */
143
-    public function getNumberOfObjects()
144
-    {
145
-        return $this->numberOfObjects;
146
-    }
26
+	/**
27
+	 * @var string
28
+	 */
29
+	protected $dataType;
30
+
31
+	/**
32
+	 * @var \Fab\Vidi\Domain\Model\Content[]
33
+	 */
34
+	protected $objects = [];
35
+
36
+	/**
37
+	 * @var int
38
+	 */
39
+	protected $numberOfObjects = 0;
40
+
41
+	/**
42
+	 * Constructor
43
+	 *
44
+	 * @param string $dataType
45
+	 */
46
+	public function __construct($dataType = '')
47
+	{
48
+		if (empty($dataType)) {
49
+			$dataType = $this->getModuleLoader()->getDataType();
50
+		}
51
+		$this->dataType = $dataType;
52
+	}
53
+
54
+	/**
55
+	 * Fetch the files given an object assuming
56
+	 *
57
+	 * @param Matcher $matcher
58
+	 * @param Order $order The order
59
+	 * @param int $limit
60
+	 * @param int $offset
61
+	 * @return $this
62
+	 */
63
+	public function findBy(Matcher $matcher, Order $order = null, $limit = null, $offset = null)
64
+	{
65
+
66
+		// Query the repository.
67
+		$objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order, $limit, $offset);
68
+		$signalResult = $this->emitAfterFindContentObjectsSignal($objects, $matcher, $order, $limit, $offset);
69
+
70
+		// Reset objects variable after possible signal / slot processing.
71
+		$this->objects = $signalResult->getContentObjects();
72
+
73
+		// Count number of content objects.
74
+		if ($signalResult->getHasBeenProcessed()) {
75
+			$this->numberOfObjects = $signalResult->getNumberOfObjects();
76
+		} else {
77
+			$this->numberOfObjects = ContentRepositoryFactory::getInstance($this->dataType)->countBy($matcher);
78
+		}
79
+
80
+		return $this;
81
+	}
82
+
83
+	/**
84
+	 * Signal that is called after the content objects have been found.
85
+	 *
86
+	 * @param array $contentObjects
87
+	 * @param \Fab\Vidi\Persistence\Matcher $matcher
88
+	 * @param Order $order
89
+	 * @param int $limit
90
+	 * @param int $offset
91
+	 * @return AfterFindContentObjectsSignalArguments
92
+	 */
93
+	protected function emitAfterFindContentObjectsSignal($contentObjects, Matcher $matcher, Order $order = null, $limit = 0, $offset = 0)
94
+	{
95
+
96
+		/** @var AfterFindContentObjectsSignalArguments $signalArguments */
97
+		$signalArguments = GeneralUtility::makeInstance(AfterFindContentObjectsSignalArguments::class);
98
+		$signalArguments->setDataType($this->dataType)
99
+			->setContentObjects($contentObjects)
100
+			->setMatcher($matcher)
101
+			->setOrder($order)
102
+			->setLimit($limit)
103
+			->setOffset($offset)
104
+			->setHasBeenProcessed(false);
105
+
106
+		$signalResult = $this->getSignalSlotDispatcher()->dispatch(ContentService::class, 'afterFindContentObjects', array($signalArguments));
107
+		return $signalResult[0];
108
+	}
109
+
110
+	/**
111
+	 * Get the Vidi Module Loader.
112
+	 *
113
+	 * @return ModuleLoader|object
114
+	 */
115
+	protected function getModuleLoader()
116
+	{
117
+		return GeneralUtility::makeInstance(ModuleLoader::class);
118
+	}
119
+
120
+	/**
121
+	 * Get the SignalSlot dispatcher.
122
+	 *
123
+	 * @return Dispatcher|object
124
+	 */
125
+	protected function getSignalSlotDispatcher()
126
+	{
127
+		/** @var ObjectManager $objectManager */
128
+		$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
129
+		return $objectManager->get(Dispatcher::class);
130
+	}
131
+
132
+	/**
133
+	 * @return \Fab\Vidi\Domain\Model\Content[]
134
+	 */
135
+	public function getObjects()
136
+	{
137
+		return $this->objects;
138
+	}
139
+
140
+	/**
141
+	 * @return int
142
+	 */
143
+	public function getNumberOfObjects()
144
+	{
145
+		return $this->numberOfObjects;
146
+	}
147 147
 
148 148
 }
Please login to merge, or discard this patch.
Classes/Persistence/Pager.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -22,168 +22,168 @@
 block discarded – undo
22 22
 class Pager
23 23
 {
24 24
 
25
-    /**
26
-     * Total amount of entries
27
-     *
28
-     * @var integer
29
-     */
30
-    protected $count;
31
-
32
-    /**
33
-     * Current offset
34
-     *
35
-     * @var integer
36
-     */
37
-    protected $offset;
38
-
39
-    /**
40
-     * Current page index
41
-     *
42
-     * @var integer
43
-     */
44
-    protected $page;
45
-
46
-    /**
47
-     * Number of items per page
48
-     *
49
-     * @var integer
50
-     */
51
-    protected $limit = 10;
52
-
53
-    /**
54
-     * Constructs a new Pager
55
-     */
56
-    public function __construct()
57
-    {
58
-        $this->page = 1;
59
-    }
60
-
61
-    /**
62
-     * Returns the total amount of entries
63
-     *
64
-     * @return int
65
-     */
66
-    public function getCount()
67
-    {
68
-        return $this->count;
69
-    }
70
-
71
-    /**
72
-     * Sets the total amount of entries
73
-     *
74
-     * @param int $count
75
-     */
76
-    public function setCount($count)
77
-    {
78
-        $this->count = $count;
79
-    }
80
-
81
-    /**
82
-     * Returns the current page index
83
-     *
84
-     * @return int
85
-     */
86
-    public function getPage()
87
-    {
88
-        return $this->page;
89
-    }
90
-
91
-    /**
92
-     * Sets the current page index
93
-     *
94
-     * @param int $page
95
-     */
96
-    public function setPage($page)
97
-    {
98
-        $this->page = $page;
99
-    }
100
-
101
-    /**
102
-     * Returns the current limit index
103
-     *
104
-     * @return int
105
-     */
106
-    public function getLimit()
107
-    {
108
-        return $this->limit;
109
-    }
110
-
111
-    /**
112
-     * Sets the current limit index
113
-     *
114
-     * @param int $limit
115
-     */
116
-    public function setLimit($limit)
117
-    {
118
-        $this->limit = $limit;
119
-    }
120
-
121
-    /**
122
-     * @return Array Items to display
123
-     */
124
-    public function getDisplayItems()
125
-    {
126
-        $last = $this->getLastPage();
127
-        if ($last == 1) {
128
-            return null;
129
-        }
130
-        $values = Array();
131
-        for ($i = 1; $i <= $last; $i++) {
132
-            $values[] = Array('key' => $i, 'value' => $i);
133
-        }
134
-        return $values;
135
-    }
136
-
137
-    /**
138
-     * @return int The last page index
139
-     */
140
-    public function getLastPage()
141
-    {
142
-        $last = intval($this->count / $this->limit);
143
-        if ($this->count % $this->limit > 0) {
144
-            $last++;
145
-        }
146
-        return $last;
147
-    }
148
-
149
-    /**
150
-     * @return int The previous page index. Minimum value is 1
151
-     */
152
-    public function getPreviousPage()
153
-    {
154
-        $prev = $this->page - 1;
155
-        if ($prev < 1) {
156
-            $prev = 1;
157
-        }
158
-        return $prev;
159
-    }
160
-
161
-    /**
162
-     * @return int The next page index. Maximum valus is the last page
163
-     */
164
-    public function getNextPage()
165
-    {
166
-        $next = $this->page + 1;
167
-        $last = $this->getLastPage();
168
-        if ($next > $last) {
169
-            $next = $last;
170
-        }
171
-        return $next;
172
-    }
173
-
174
-    /**
175
-     * @return int
176
-     */
177
-    public function getOffset()
178
-    {
179
-        return $this->offset;
180
-    }
181
-
182
-    /**
183
-     * @param int $offset
184
-     */
185
-    public function setOffset($offset)
186
-    {
187
-        $this->offset = $offset;
188
-    }
25
+	/**
26
+	 * Total amount of entries
27
+	 *
28
+	 * @var integer
29
+	 */
30
+	protected $count;
31
+
32
+	/**
33
+	 * Current offset
34
+	 *
35
+	 * @var integer
36
+	 */
37
+	protected $offset;
38
+
39
+	/**
40
+	 * Current page index
41
+	 *
42
+	 * @var integer
43
+	 */
44
+	protected $page;
45
+
46
+	/**
47
+	 * Number of items per page
48
+	 *
49
+	 * @var integer
50
+	 */
51
+	protected $limit = 10;
52
+
53
+	/**
54
+	 * Constructs a new Pager
55
+	 */
56
+	public function __construct()
57
+	{
58
+		$this->page = 1;
59
+	}
60
+
61
+	/**
62
+	 * Returns the total amount of entries
63
+	 *
64
+	 * @return int
65
+	 */
66
+	public function getCount()
67
+	{
68
+		return $this->count;
69
+	}
70
+
71
+	/**
72
+	 * Sets the total amount of entries
73
+	 *
74
+	 * @param int $count
75
+	 */
76
+	public function setCount($count)
77
+	{
78
+		$this->count = $count;
79
+	}
80
+
81
+	/**
82
+	 * Returns the current page index
83
+	 *
84
+	 * @return int
85
+	 */
86
+	public function getPage()
87
+	{
88
+		return $this->page;
89
+	}
90
+
91
+	/**
92
+	 * Sets the current page index
93
+	 *
94
+	 * @param int $page
95
+	 */
96
+	public function setPage($page)
97
+	{
98
+		$this->page = $page;
99
+	}
100
+
101
+	/**
102
+	 * Returns the current limit index
103
+	 *
104
+	 * @return int
105
+	 */
106
+	public function getLimit()
107
+	{
108
+		return $this->limit;
109
+	}
110
+
111
+	/**
112
+	 * Sets the current limit index
113
+	 *
114
+	 * @param int $limit
115
+	 */
116
+	public function setLimit($limit)
117
+	{
118
+		$this->limit = $limit;
119
+	}
120
+
121
+	/**
122
+	 * @return Array Items to display
123
+	 */
124
+	public function getDisplayItems()
125
+	{
126
+		$last = $this->getLastPage();
127
+		if ($last == 1) {
128
+			return null;
129
+		}
130
+		$values = Array();
131
+		for ($i = 1; $i <= $last; $i++) {
132
+			$values[] = Array('key' => $i, 'value' => $i);
133
+		}
134
+		return $values;
135
+	}
136
+
137
+	/**
138
+	 * @return int The last page index
139
+	 */
140
+	public function getLastPage()
141
+	{
142
+		$last = intval($this->count / $this->limit);
143
+		if ($this->count % $this->limit > 0) {
144
+			$last++;
145
+		}
146
+		return $last;
147
+	}
148
+
149
+	/**
150
+	 * @return int The previous page index. Minimum value is 1
151
+	 */
152
+	public function getPreviousPage()
153
+	{
154
+		$prev = $this->page - 1;
155
+		if ($prev < 1) {
156
+			$prev = 1;
157
+		}
158
+		return $prev;
159
+	}
160
+
161
+	/**
162
+	 * @return int The next page index. Maximum valus is the last page
163
+	 */
164
+	public function getNextPage()
165
+	{
166
+		$next = $this->page + 1;
167
+		$last = $this->getLastPage();
168
+		if ($next > $last) {
169
+			$next = $last;
170
+		}
171
+		return $next;
172
+	}
173
+
174
+	/**
175
+	 * @return int
176
+	 */
177
+	public function getOffset()
178
+	{
179
+		return $this->offset;
180
+	}
181
+
182
+	/**
183
+	 * @param int $offset
184
+	 */
185
+	public function setOffset($offset)
186
+	{
187
+		$this->offset = $offset;
188
+	}
189 189
 }
Please login to merge, or discard this patch.
Classes/Language/LocalizationStatus.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@
 block discarded – undo
22 22
 class LocalizationStatus extends Enumeration
23 23
 {
24 24
 
25
-    const LOCALIZED = 'localized';
26
-    const NOT_YET_LOCALIZED = 'notYetLocalized';
27
-    const EMPTY_VALUE = 'emptyValue';
25
+	const LOCALIZED = 'localized';
26
+	const NOT_YET_LOCALIZED = 'notYetLocalized';
27
+	const EMPTY_VALUE = 'emptyValue';
28 28
 
29 29
 }
Please login to merge, or discard this patch.
Classes/Behavior/SavingBehavior.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@
 block discarded – undo
22 22
 class SavingBehavior extends Enumeration
23 23
 {
24 24
 
25
-    const REMOVE = 'remove';
25
+	const REMOVE = 'remove';
26 26
 
27
-    const APPEND = 'append';
27
+	const APPEND = 'append';
28 28
 
29
-    const REPLACE = 'replace';
29
+	const REPLACE = 'replace';
30 30
 
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.