Completed
Push — master ( 5794c5...08c98b )
by Fabien
53:00
created
Classes/Domain/Model/Selection.php 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -16,145 +16,145 @@
 block discarded – undo
16 16
  */
17 17
 class Selection extends AbstractEntity
18 18
 {
19
-    public const VISIBILITY_EVERYONE = 0;
20
-    public const VISIBILITY_PRIVATE = 1;
21
-    public const VISIBILITY_ADMIN_ONLY = 2;
22
-
23
-    /**
24
-     * @var int
25
-     */
26
-    protected $visibility;
27
-
28
-    /**
29
-     * @var string
30
-     */
31
-    protected $name;
32
-
33
-    /**
34
-     * @var string
35
-     */
36
-    protected $dataType;
37
-
38
-    /**
39
-     * @var string
40
-     */
41
-    protected $query;
42
-
43
-    /**
44
-     * @var string
45
-     */
46
-    protected $speakingQuery;
47
-
48
-    /**
49
-     * @var int
50
-     */
51
-    protected $owner;
52
-
53
-    /**
54
-     * @param string $dataType
55
-     * @return $this
56
-     */
57
-    public function setDataType($dataType)
58
-    {
59
-        $this->dataType = $dataType;
60
-        return $this;
61
-    }
62
-
63
-    /**
64
-     * @return string
65
-     */
66
-    public function getDataType()
67
-    {
68
-        return $this->dataType;
69
-    }
70
-
71
-    /**
72
-     * @param string $query
73
-     * @return $this
74
-     */
75
-    public function setQuery($query)
76
-    {
77
-        $this->query = $query;
78
-        return $this;
79
-    }
80
-
81
-    /**
82
-     * @return string
83
-     */
84
-    public function getQuery()
85
-    {
86
-        return $this->query;
87
-    }
88
-
89
-    /**
90
-     * @return string
91
-     */
92
-    public function getSpeakingQuery()
93
-    {
94
-        return $this->speakingQuery;
95
-    }
96
-
97
-    /**
98
-     * @param string $speakingQuery
99
-     * @return $this
100
-     */
101
-    public function setSpeakingQuery($speakingQuery)
102
-    {
103
-        $this->speakingQuery = $speakingQuery;
104
-        return $this;
105
-    }
106
-
107
-    /**
108
-     * @param string $name
109
-     * @return $this
110
-     */
111
-    public function setName($name)
112
-    {
113
-        $this->name = $name;
114
-        return $this;
115
-    }
116
-
117
-    /**
118
-     * @return string
119
-     */
120
-    public function getName()
121
-    {
122
-        return $this->name;
123
-    }
124
-
125
-    /**
126
-     * @param int $visibility
127
-     * @return $this
128
-     */
129
-    public function setVisibility($visibility)
130
-    {
131
-        $this->visibility = $visibility;
132
-        return $this;
133
-    }
134
-
135
-    /**
136
-     * @return int
137
-     */
138
-    public function getVisibility()
139
-    {
140
-        return $this->visibility;
141
-    }
142
-
143
-    /**
144
-     * @return int
145
-     */
146
-    public function getOwner()
147
-    {
148
-        return $this->owner;
149
-    }
150
-
151
-    /**
152
-     * @param int $owner
153
-     * @return $this
154
-     */
155
-    public function setOwner($owner)
156
-    {
157
-        $this->owner = $owner;
158
-        return $this;
159
-    }
19
+	public const VISIBILITY_EVERYONE = 0;
20
+	public const VISIBILITY_PRIVATE = 1;
21
+	public const VISIBILITY_ADMIN_ONLY = 2;
22
+
23
+	/**
24
+	 * @var int
25
+	 */
26
+	protected $visibility;
27
+
28
+	/**
29
+	 * @var string
30
+	 */
31
+	protected $name;
32
+
33
+	/**
34
+	 * @var string
35
+	 */
36
+	protected $dataType;
37
+
38
+	/**
39
+	 * @var string
40
+	 */
41
+	protected $query;
42
+
43
+	/**
44
+	 * @var string
45
+	 */
46
+	protected $speakingQuery;
47
+
48
+	/**
49
+	 * @var int
50
+	 */
51
+	protected $owner;
52
+
53
+	/**
54
+	 * @param string $dataType
55
+	 * @return $this
56
+	 */
57
+	public function setDataType($dataType)
58
+	{
59
+		$this->dataType = $dataType;
60
+		return $this;
61
+	}
62
+
63
+	/**
64
+	 * @return string
65
+	 */
66
+	public function getDataType()
67
+	{
68
+		return $this->dataType;
69
+	}
70
+
71
+	/**
72
+	 * @param string $query
73
+	 * @return $this
74
+	 */
75
+	public function setQuery($query)
76
+	{
77
+		$this->query = $query;
78
+		return $this;
79
+	}
80
+
81
+	/**
82
+	 * @return string
83
+	 */
84
+	public function getQuery()
85
+	{
86
+		return $this->query;
87
+	}
88
+
89
+	/**
90
+	 * @return string
91
+	 */
92
+	public function getSpeakingQuery()
93
+	{
94
+		return $this->speakingQuery;
95
+	}
96
+
97
+	/**
98
+	 * @param string $speakingQuery
99
+	 * @return $this
100
+	 */
101
+	public function setSpeakingQuery($speakingQuery)
102
+	{
103
+		$this->speakingQuery = $speakingQuery;
104
+		return $this;
105
+	}
106
+
107
+	/**
108
+	 * @param string $name
109
+	 * @return $this
110
+	 */
111
+	public function setName($name)
112
+	{
113
+		$this->name = $name;
114
+		return $this;
115
+	}
116
+
117
+	/**
118
+	 * @return string
119
+	 */
120
+	public function getName()
121
+	{
122
+		return $this->name;
123
+	}
124
+
125
+	/**
126
+	 * @param int $visibility
127
+	 * @return $this
128
+	 */
129
+	public function setVisibility($visibility)
130
+	{
131
+		$this->visibility = $visibility;
132
+		return $this;
133
+	}
134
+
135
+	/**
136
+	 * @return int
137
+	 */
138
+	public function getVisibility()
139
+	{
140
+		return $this->visibility;
141
+	}
142
+
143
+	/**
144
+	 * @return int
145
+	 */
146
+	public function getOwner()
147
+	{
148
+		return $this->owner;
149
+	}
150
+
151
+	/**
152
+	 * @param int $owner
153
+	 * @return $this
154
+	 */
155
+	public function setOwner($owner)
156
+	{
157
+		$this->owner = $owner;
158
+		return $this;
159
+	}
160 160
 }
Please login to merge, or discard this patch.
Classes/Domain/Model/Content.php 2 patches
Indentation   +436 added lines, -436 removed lines patch added patch discarded remove patch
@@ -28,440 +28,440 @@
 block discarded – undo
28 28
  */
29 29
 class Content implements \ArrayAccess
30 30
 {
31
-    /**
32
-     * @var int
33
-     */
34
-    protected $uid;
35
-
36
-    /**
37
-     * @var string
38
-     */
39
-    protected $dataType;
40
-
41
-    /**
42
-     * Constructor for a Content object.
43
-     *
44
-     * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ...
45
-     * @param array $contentData
46
-     * @return \Fab\Vidi\Domain\Model\Content
47
-     * @throws \InvalidArgumentException
48
-     * @throws NotExistingClassException
49
-     */
50
-    public function __construct($dataType, array $contentData = array())
51
-    {
52
-        $this->dataType = $dataType;
53
-        $this->uid = empty($contentData['uid']) ? null : (int)$contentData['uid'];
54
-
55
-        /** @var TableService $table */
56
-        $table = Tca::table($dataType);
57
-
58
-        // Initialize the array containing the allowed fields to be filled-in.
59
-        $fields = array('pid');
60
-
61
-        // If a creation time stamp has been defined for this data type.
62
-        if ($table->getTimeCreationField()) {
63
-            $fields[] = $table->getTimeCreationField();
64
-        }
65
-
66
-        // If an update time stamp has been defined for this data type.
67
-        if ($table->getTimeModificationField()) {
68
-            $fields[] = $table->getTimeModificationField();
69
-        }
70
-
71
-        // Merge the other fields allowed for this data type.
72
-        $fields = array_merge($fields, $table->getFields());
73
-
74
-        // Fetch excluded fields from the grid.
75
-        if ($this->isBackendMode()) {
76
-            $fields = $this->filterForConfiguration($fields);
77
-            $fields = $this->filterForBackendUser($fields);
78
-        }
79
-
80
-        // Get column to be displayed
81
-        foreach ($fields as $fieldName) {
82
-            if (array_key_exists($fieldName, $contentData)) {
83
-                $propertyName = Field::name($fieldName)->of($dataType)->toPropertyName();
84
-                $this->$propertyName = $contentData[$fieldName];
85
-            }
86
-        }
87
-    }
88
-
89
-    /**
90
-     * Dispatches magic methods (findBy[Property]())
91
-     *
92
-     * @param string $methodName The name of the magic method
93
-     * @param string $arguments The arguments of the magic method
94
-     * @throws UnsupportedMethodException
95
-     * @return mixed
96
-     * @api
97
-     */
98
-    public function __call($methodName, $arguments)
99
-    {
100
-        $value = null;
101
-        if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
102
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
103
-
104
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
105
-            $field = Tca::table($this->dataType)->field($fieldName);
106
-
107
-            $value = $this->$propertyName;
108
-
109
-            // true means it is a relation and it is not yet resolved.
110
-            if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) {
111
-                $value = $this->resolveRelation($propertyName);
112
-            } elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) {
113
-                // Attempt to convert the value into a label for radio and select fields.
114
-                $label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value);
115
-                if ($label) {
116
-                    $value = $label;
117
-                }
118
-            }
119
-        } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
120
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
121
-            $this->$propertyName = $arguments[0];
122
-        }
123
-        return $value;
124
-    }
125
-
126
-    /**
127
-     * Tell whether the property has a relation.
128
-     *
129
-     * @param string $propertyName
130
-     * @return bool
131
-     */
132
-    protected function hasRelation($propertyName)
133
-    {
134
-        $fieldName = Property::name($propertyName)->of($this)->toFieldName();
135
-        return Tca::table($this->dataType)->field($fieldName)->hasRelation();
136
-    }
137
-
138
-    /**
139
-     * Try to "resolve" the property whether it has a relation.
140
-     * If the property has not relation it simply returns the same value.
141
-     *
142
-     * @throws \RuntimeException
143
-     * @param string $propertyName
144
-     * @return mixed
145
-     */
146
-    protected function resolveRelation($propertyName)
147
-    {
148
-        // Convert property name to field name and get the foreign data type.
149
-        $fieldName = Property::name($propertyName)->of($this)->toFieldName();
150
-        $foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType();
151
-
152
-        // Get the foreign repository instance form the factory
153
-        /** @var ContentRepository $foreignContentRepository */
154
-        $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName);
155
-
156
-        if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
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(
168
-                    'Missing "foreign_field" key for field "%s" in table "%s".',
169
-                    $fieldName,
170
-                    $this->dataType
171
-                );
172
-                throw new \RuntimeException($message, 1376149186);
173
-            }
174
-
175
-            // Fetch values from repository.
176
-            $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
177
-            $findByProperty = 'findBy' . ucfirst($foreignPropertyName);
178
-
179
-            // Date picker (type == group) are special fields because property path must contain the table name
180
-            // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
181
-            $propertyValue = $this->uid;
182
-            if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
183
-                $propertyValue = $this->dataType . '.' . $this->uid;
184
-            }
185
-
186
-            $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
187
-        } elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) {
188
-            $fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration();
189
-
190
-            // First case, we are on the "good side" of the relation, just query the repository
191
-            if (empty($fieldConfiguration['foreign_field'])) {
192
-                $this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName);
193
-            } else {
194
-                // Second case, we are the "bad side" of the relation, query the foreign repository
195
-                // e.g. in case of one-to-one relation.
196
-
197
-                // We must query the opposite side to get the identifier of the foreign object.
198
-                $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
199
-                $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
200
-                $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
201
-                $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
202
-
203
-                /** @var Content $foreignObject */
204
-                $this->$propertyName = $foreignContentRepository->$find($this->getUid());
205
-            }
206
-        }
207
-        return $this->$propertyName;
208
-    }
209
-
210
-    /**
211
-     * @return int
212
-     */
213
-    public function getUid()
214
-    {
215
-        return $this->uid;
216
-    }
217
-
218
-    /**
219
-     * @return string
220
-     */
221
-    public function getDataType()
222
-    {
223
-        return $this->dataType;
224
-    }
225
-
226
-    /**
227
-     * Whether a offset exists
228
-     *
229
-     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
230
-     * @param mixed $offset
231
-     * @return boolean true on success or false on failure.
232
-     * @throws \RuntimeException
233
-     * @throws \InvalidArgumentException
234
-     */
235
-    public function offsetExists($offset)
236
-    {
237
-        $offset = Field::name($offset)->of($this)->toPropertyName();
238
-        return isset($this->$offset);
239
-    }
240
-
241
-    /**
242
-     * Offset to retrieve
243
-     *
244
-     * @link http://php.net/manual/en/arrayaccess.offsetget.php
245
-     * @param mixed $offset
246
-     * @return mixed Can return all value types.
247
-     * @throws \RuntimeException
248
-     * @throws \InvalidArgumentException
249
-     */
250
-    public function offsetGet($offset)
251
-    {
252
-        $offset = Field::name($offset)->of($this)->toPropertyName();
253
-        $getter = 'get' . ucfirst($offset);
254
-        return $this->$getter();
255
-    }
256
-
257
-    /**
258
-     * Offset to set
259
-     *
260
-     * @link http://php.net/manual/en/arrayaccess.offsetset.php
261
-     * @param mixed $offset
262
-     * @param mixed $value
263
-     * @return $this
264
-     * @throws \RuntimeException
265
-     * @throws \InvalidArgumentException
266
-     */
267
-    public function offsetSet($offset, $value)
268
-    {
269
-        $offset = Field::name($offset)->of($this)->toPropertyName();
270
-        $setter = 'set' . ucfirst($offset);
271
-        $this->$setter($value);
272
-        return $this;
273
-    }
274
-
275
-    /**
276
-     * Offset to unset
277
-     *
278
-     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
279
-     * @param mixed $offset
280
-     * @throws NotImplementedException
281
-     * @return void
282
-     */
283
-    public function offsetUnset($offset)
284
-    {
285
-        $message = 'Un-setting value for Array object is not supported';
286
-        throw new NotImplementedException($message, 1376132306);
287
-    }
288
-
289
-    /**
290
-     * Convert this to array
291
-     *
292
-     * @return array
293
-     * @throws \InvalidArgumentException
294
-     */
295
-    public function toArray()
296
-    {
297
-        $result['uid'] = $this->uid;
298
-        $propertiesAndValues = json_decode(json_encode($this), true);
299
-
300
-        foreach ($propertiesAndValues as $propertyName => $value) {
301
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
302
-            $result[$fieldName] = $value;
303
-        }
304
-
305
-        return $result;
306
-    }
307
-
308
-    /**
309
-     * Convert this object to an array containing the resolved values.
310
-     *
311
-     * @param bool $resolveRelations
312
-     * @return array
313
-     * @throws \Exception
314
-     */
315
-    public function toValues($resolveRelations = true)
316
-    {
317
-        $result['uid'] = $this->uid;
318
-        $propertiesAndValues = json_decode(json_encode($this), true);
319
-
320
-        foreach ($propertiesAndValues as $propertyName => $value) {
321
-            $fieldName = Property::name($propertyName)->of($this)->toFieldName();
322
-
323
-            $result[$fieldName] = $value;
324
-            if ($resolveRelations) {
325
-                $field = Tca::table($this->dataType)->field($fieldName);
326
-
327
-                $resolvedValue = '';
328
-                if ($field->getType() === FieldType::FILE) {
329
-                    if ($field->hasMany()) {
330
-                        $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
331
-
332
-                        $resolvedValue = [];
333
-                        foreach ($files as $file) {
334
-                            $resolvedValue[] = $file->getIdentifier();
335
-                        }
336
-                    } else {
337
-                        $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
338
-                        if (!empty($files)) {
339
-                            $resolvedValue = current($files)->getIdentifier();
340
-                        }
341
-                    }
342
-
343
-                    // Reset value
344
-                    $result[$fieldName] = $resolvedValue;
345
-                } elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) {
346
-                    $objects = $this[$fieldName];
347
-                    if (is_array($objects)) {
348
-                        $resolvedValue = [];
349
-                        foreach ($objects as $object) {
350
-                            /** @var $object Content */
351
-                            $labelField = Tca::table($object->getDataType())->getLabelField();
352
-                            $resolvedValue[] = $object[$labelField];
353
-                        }
354
-                    } elseif ($objects instanceof Content) {
355
-                        $labelField = Tca::table($objects->getDataType())->getLabelField();
356
-                        $resolvedValue = $objects[$labelField];
357
-                    }
358
-
359
-                    // Reset value
360
-                    $result[$fieldName] = $resolvedValue;
361
-                }
362
-            }
363
-        }
364
-
365
-        return $result;
366
-    }
367
-
368
-    /**
369
-     * Return the properties of this object.
370
-     *
371
-     * @return array
372
-     */
373
-    public function toProperties()
374
-    {
375
-        $result[] = 'uid';
376
-        $propertiesAndValues = json_decode(json_encode($this), true);
377
-
378
-        foreach ($propertiesAndValues as $propertyName => $value) {
379
-            $result[] = $propertyName;
380
-        }
381
-        return $result;
382
-    }
383
-
384
-    /**
385
-     * Return the properties of this object.
386
-     *
387
-     * @return array
388
-     */
389
-    public function toFields()
390
-    {
391
-        $result[] = 'uid';
392
-        $propertiesAndValues = json_decode(json_encode($this), true);
393
-
394
-        foreach ($propertiesAndValues as $propertyName => $value) {
395
-            $result[] = Property::name($propertyName)->of($this)->toFieldName();
396
-        }
397
-
398
-        return $result;
399
-    }
400
-
401
-    /**
402
-     * @return string
403
-     */
404
-    public function __toString()
405
-    {
406
-        $labelField = Tca::table($this->dataType)->getLabelField();
407
-        return $this[$labelField];
408
-    }
409
-
410
-    /**
411
-     * Remove fields according to BE User permission.
412
-     *
413
-     * @param $fields
414
-     * @return array
415
-     * @throws \Exception
416
-     */
417
-    protected function filterForBackendUser($fields)
418
-    {
419
-        if (!$this->getBackendUser()->isAdmin()) {
420
-            foreach ($fields as $key => $fieldName) {
421
-                if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) {
422
-                    unset($fields[$key]);
423
-                }
424
-            }
425
-        }
426
-        return $fields;
427
-    }
428
-
429
-    /**
430
-     * Remove fields according to Grid configuration.
431
-     *
432
-     * @param $fields
433
-     * @return array
434
-     */
435
-    protected function filterForConfiguration($fields)
436
-    {
437
-        $excludedFields = Tca::grid($this->dataType)->getExcludedFields();
438
-        foreach ($fields as $key => $field) {
439
-            if (in_array($field, $excludedFields)) {
440
-                unset($fields[$key]);
441
-            }
442
-        }
443
-
444
-        return $fields;
445
-    }
446
-
447
-    /**
448
-     * Returns an instance of the current Backend User.
449
-     *
450
-     * @return BackendUserAuthentication
451
-     */
452
-    protected function getBackendUser()
453
-    {
454
-        return $GLOBALS['BE_USER'];
455
-    }
456
-
457
-    /**
458
-     * Returns whether the current mode is Backend
459
-     *
460
-     * @return bool
461
-     */
462
-    protected function isBackendMode()
463
-    {
464
-        return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend();
465
-        ;
466
-    }
31
+	/**
32
+	 * @var int
33
+	 */
34
+	protected $uid;
35
+
36
+	/**
37
+	 * @var string
38
+	 */
39
+	protected $dataType;
40
+
41
+	/**
42
+	 * Constructor for a Content object.
43
+	 *
44
+	 * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ...
45
+	 * @param array $contentData
46
+	 * @return \Fab\Vidi\Domain\Model\Content
47
+	 * @throws \InvalidArgumentException
48
+	 * @throws NotExistingClassException
49
+	 */
50
+	public function __construct($dataType, array $contentData = array())
51
+	{
52
+		$this->dataType = $dataType;
53
+		$this->uid = empty($contentData['uid']) ? null : (int)$contentData['uid'];
54
+
55
+		/** @var TableService $table */
56
+		$table = Tca::table($dataType);
57
+
58
+		// Initialize the array containing the allowed fields to be filled-in.
59
+		$fields = array('pid');
60
+
61
+		// If a creation time stamp has been defined for this data type.
62
+		if ($table->getTimeCreationField()) {
63
+			$fields[] = $table->getTimeCreationField();
64
+		}
65
+
66
+		// If an update time stamp has been defined for this data type.
67
+		if ($table->getTimeModificationField()) {
68
+			$fields[] = $table->getTimeModificationField();
69
+		}
70
+
71
+		// Merge the other fields allowed for this data type.
72
+		$fields = array_merge($fields, $table->getFields());
73
+
74
+		// Fetch excluded fields from the grid.
75
+		if ($this->isBackendMode()) {
76
+			$fields = $this->filterForConfiguration($fields);
77
+			$fields = $this->filterForBackendUser($fields);
78
+		}
79
+
80
+		// Get column to be displayed
81
+		foreach ($fields as $fieldName) {
82
+			if (array_key_exists($fieldName, $contentData)) {
83
+				$propertyName = Field::name($fieldName)->of($dataType)->toPropertyName();
84
+				$this->$propertyName = $contentData[$fieldName];
85
+			}
86
+		}
87
+	}
88
+
89
+	/**
90
+	 * Dispatches magic methods (findBy[Property]())
91
+	 *
92
+	 * @param string $methodName The name of the magic method
93
+	 * @param string $arguments The arguments of the magic method
94
+	 * @throws UnsupportedMethodException
95
+	 * @return mixed
96
+	 * @api
97
+	 */
98
+	public function __call($methodName, $arguments)
99
+	{
100
+		$value = null;
101
+		if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
102
+			$propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
103
+
104
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
105
+			$field = Tca::table($this->dataType)->field($fieldName);
106
+
107
+			$value = $this->$propertyName;
108
+
109
+			// true means it is a relation and it is not yet resolved.
110
+			if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) {
111
+				$value = $this->resolveRelation($propertyName);
112
+			} elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) {
113
+				// Attempt to convert the value into a label for radio and select fields.
114
+				$label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value);
115
+				if ($label) {
116
+					$value = $label;
117
+				}
118
+			}
119
+		} elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
120
+			$propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
121
+			$this->$propertyName = $arguments[0];
122
+		}
123
+		return $value;
124
+	}
125
+
126
+	/**
127
+	 * Tell whether the property has a relation.
128
+	 *
129
+	 * @param string $propertyName
130
+	 * @return bool
131
+	 */
132
+	protected function hasRelation($propertyName)
133
+	{
134
+		$fieldName = Property::name($propertyName)->of($this)->toFieldName();
135
+		return Tca::table($this->dataType)->field($fieldName)->hasRelation();
136
+	}
137
+
138
+	/**
139
+	 * Try to "resolve" the property whether it has a relation.
140
+	 * If the property has not relation it simply returns the same value.
141
+	 *
142
+	 * @throws \RuntimeException
143
+	 * @param string $propertyName
144
+	 * @return mixed
145
+	 */
146
+	protected function resolveRelation($propertyName)
147
+	{
148
+		// Convert property name to field name and get the foreign data type.
149
+		$fieldName = Property::name($propertyName)->of($this)->toFieldName();
150
+		$foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType();
151
+
152
+		// Get the foreign repository instance form the factory
153
+		/** @var ContentRepository $foreignContentRepository */
154
+		$foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName);
155
+
156
+		if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
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(
168
+					'Missing "foreign_field" key for field "%s" in table "%s".',
169
+					$fieldName,
170
+					$this->dataType
171
+				);
172
+				throw new \RuntimeException($message, 1376149186);
173
+			}
174
+
175
+			// Fetch values from repository.
176
+			$foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
177
+			$findByProperty = 'findBy' . ucfirst($foreignPropertyName);
178
+
179
+			// Date picker (type == group) are special fields because property path must contain the table name
180
+			// to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
181
+			$propertyValue = $this->uid;
182
+			if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
183
+				$propertyValue = $this->dataType . '.' . $this->uid;
184
+			}
185
+
186
+			$this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
187
+		} elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) {
188
+			$fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration();
189
+
190
+			// First case, we are on the "good side" of the relation, just query the repository
191
+			if (empty($fieldConfiguration['foreign_field'])) {
192
+				$this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName);
193
+			} else {
194
+				// Second case, we are the "bad side" of the relation, query the foreign repository
195
+				// e.g. in case of one-to-one relation.
196
+
197
+				// We must query the opposite side to get the identifier of the foreign object.
198
+				$foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
199
+				$foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
200
+				$foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
201
+				$find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
202
+
203
+				/** @var Content $foreignObject */
204
+				$this->$propertyName = $foreignContentRepository->$find($this->getUid());
205
+			}
206
+		}
207
+		return $this->$propertyName;
208
+	}
209
+
210
+	/**
211
+	 * @return int
212
+	 */
213
+	public function getUid()
214
+	{
215
+		return $this->uid;
216
+	}
217
+
218
+	/**
219
+	 * @return string
220
+	 */
221
+	public function getDataType()
222
+	{
223
+		return $this->dataType;
224
+	}
225
+
226
+	/**
227
+	 * Whether a offset exists
228
+	 *
229
+	 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
230
+	 * @param mixed $offset
231
+	 * @return boolean true on success or false on failure.
232
+	 * @throws \RuntimeException
233
+	 * @throws \InvalidArgumentException
234
+	 */
235
+	public function offsetExists($offset)
236
+	{
237
+		$offset = Field::name($offset)->of($this)->toPropertyName();
238
+		return isset($this->$offset);
239
+	}
240
+
241
+	/**
242
+	 * Offset to retrieve
243
+	 *
244
+	 * @link http://php.net/manual/en/arrayaccess.offsetget.php
245
+	 * @param mixed $offset
246
+	 * @return mixed Can return all value types.
247
+	 * @throws \RuntimeException
248
+	 * @throws \InvalidArgumentException
249
+	 */
250
+	public function offsetGet($offset)
251
+	{
252
+		$offset = Field::name($offset)->of($this)->toPropertyName();
253
+		$getter = 'get' . ucfirst($offset);
254
+		return $this->$getter();
255
+	}
256
+
257
+	/**
258
+	 * Offset to set
259
+	 *
260
+	 * @link http://php.net/manual/en/arrayaccess.offsetset.php
261
+	 * @param mixed $offset
262
+	 * @param mixed $value
263
+	 * @return $this
264
+	 * @throws \RuntimeException
265
+	 * @throws \InvalidArgumentException
266
+	 */
267
+	public function offsetSet($offset, $value)
268
+	{
269
+		$offset = Field::name($offset)->of($this)->toPropertyName();
270
+		$setter = 'set' . ucfirst($offset);
271
+		$this->$setter($value);
272
+		return $this;
273
+	}
274
+
275
+	/**
276
+	 * Offset to unset
277
+	 *
278
+	 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
279
+	 * @param mixed $offset
280
+	 * @throws NotImplementedException
281
+	 * @return void
282
+	 */
283
+	public function offsetUnset($offset)
284
+	{
285
+		$message = 'Un-setting value for Array object is not supported';
286
+		throw new NotImplementedException($message, 1376132306);
287
+	}
288
+
289
+	/**
290
+	 * Convert this to array
291
+	 *
292
+	 * @return array
293
+	 * @throws \InvalidArgumentException
294
+	 */
295
+	public function toArray()
296
+	{
297
+		$result['uid'] = $this->uid;
298
+		$propertiesAndValues = json_decode(json_encode($this), true);
299
+
300
+		foreach ($propertiesAndValues as $propertyName => $value) {
301
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
302
+			$result[$fieldName] = $value;
303
+		}
304
+
305
+		return $result;
306
+	}
307
+
308
+	/**
309
+	 * Convert this object to an array containing the resolved values.
310
+	 *
311
+	 * @param bool $resolveRelations
312
+	 * @return array
313
+	 * @throws \Exception
314
+	 */
315
+	public function toValues($resolveRelations = true)
316
+	{
317
+		$result['uid'] = $this->uid;
318
+		$propertiesAndValues = json_decode(json_encode($this), true);
319
+
320
+		foreach ($propertiesAndValues as $propertyName => $value) {
321
+			$fieldName = Property::name($propertyName)->of($this)->toFieldName();
322
+
323
+			$result[$fieldName] = $value;
324
+			if ($resolveRelations) {
325
+				$field = Tca::table($this->dataType)->field($fieldName);
326
+
327
+				$resolvedValue = '';
328
+				if ($field->getType() === FieldType::FILE) {
329
+					if ($field->hasMany()) {
330
+						$files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
331
+
332
+						$resolvedValue = [];
333
+						foreach ($files as $file) {
334
+							$resolvedValue[] = $file->getIdentifier();
335
+						}
336
+					} else {
337
+						$files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this);
338
+						if (!empty($files)) {
339
+							$resolvedValue = current($files)->getIdentifier();
340
+						}
341
+					}
342
+
343
+					// Reset value
344
+					$result[$fieldName] = $resolvedValue;
345
+				} elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) {
346
+					$objects = $this[$fieldName];
347
+					if (is_array($objects)) {
348
+						$resolvedValue = [];
349
+						foreach ($objects as $object) {
350
+							/** @var $object Content */
351
+							$labelField = Tca::table($object->getDataType())->getLabelField();
352
+							$resolvedValue[] = $object[$labelField];
353
+						}
354
+					} elseif ($objects instanceof Content) {
355
+						$labelField = Tca::table($objects->getDataType())->getLabelField();
356
+						$resolvedValue = $objects[$labelField];
357
+					}
358
+
359
+					// Reset value
360
+					$result[$fieldName] = $resolvedValue;
361
+				}
362
+			}
363
+		}
364
+
365
+		return $result;
366
+	}
367
+
368
+	/**
369
+	 * Return the properties of this object.
370
+	 *
371
+	 * @return array
372
+	 */
373
+	public function toProperties()
374
+	{
375
+		$result[] = 'uid';
376
+		$propertiesAndValues = json_decode(json_encode($this), true);
377
+
378
+		foreach ($propertiesAndValues as $propertyName => $value) {
379
+			$result[] = $propertyName;
380
+		}
381
+		return $result;
382
+	}
383
+
384
+	/**
385
+	 * Return the properties of this object.
386
+	 *
387
+	 * @return array
388
+	 */
389
+	public function toFields()
390
+	{
391
+		$result[] = 'uid';
392
+		$propertiesAndValues = json_decode(json_encode($this), true);
393
+
394
+		foreach ($propertiesAndValues as $propertyName => $value) {
395
+			$result[] = Property::name($propertyName)->of($this)->toFieldName();
396
+		}
397
+
398
+		return $result;
399
+	}
400
+
401
+	/**
402
+	 * @return string
403
+	 */
404
+	public function __toString()
405
+	{
406
+		$labelField = Tca::table($this->dataType)->getLabelField();
407
+		return $this[$labelField];
408
+	}
409
+
410
+	/**
411
+	 * Remove fields according to BE User permission.
412
+	 *
413
+	 * @param $fields
414
+	 * @return array
415
+	 * @throws \Exception
416
+	 */
417
+	protected function filterForBackendUser($fields)
418
+	{
419
+		if (!$this->getBackendUser()->isAdmin()) {
420
+			foreach ($fields as $key => $fieldName) {
421
+				if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) {
422
+					unset($fields[$key]);
423
+				}
424
+			}
425
+		}
426
+		return $fields;
427
+	}
428
+
429
+	/**
430
+	 * Remove fields according to Grid configuration.
431
+	 *
432
+	 * @param $fields
433
+	 * @return array
434
+	 */
435
+	protected function filterForConfiguration($fields)
436
+	{
437
+		$excludedFields = Tca::grid($this->dataType)->getExcludedFields();
438
+		foreach ($fields as $key => $field) {
439
+			if (in_array($field, $excludedFields)) {
440
+				unset($fields[$key]);
441
+			}
442
+		}
443
+
444
+		return $fields;
445
+	}
446
+
447
+	/**
448
+	 * Returns an instance of the current Backend User.
449
+	 *
450
+	 * @return BackendUserAuthentication
451
+	 */
452
+	protected function getBackendUser()
453
+	{
454
+		return $GLOBALS['BE_USER'];
455
+	}
456
+
457
+	/**
458
+	 * Returns whether the current mode is Backend
459
+	 *
460
+	 * @return bool
461
+	 */
462
+	protected function isBackendMode()
463
+	{
464
+		return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend();
465
+		;
466
+	}
467 467
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     {
100 100
         $value = null;
101 101
         if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) {
102
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
102
+            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)).substr(substr($methodName, 3), 1);
103 103
 
104 104
             $fieldName = Property::name($propertyName)->of($this)->toFieldName();
105 105
             $field = Tca::table($this->dataType)->field($fieldName);
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                 }
118 118
             }
119 119
         } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) {
120
-            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1);
120
+            $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)).substr(substr($methodName, 3), 1);
121 121
             $this->$propertyName = $arguments[0];
122 122
         }
123 123
         return $value;
@@ -174,13 +174,13 @@  discard block
 block discarded – undo
174 174
 
175 175
             // Fetch values from repository.
176 176
             $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName();
177
-            $findByProperty = 'findBy' . ucfirst($foreignPropertyName);
177
+            $findByProperty = 'findBy'.ucfirst($foreignPropertyName);
178 178
 
179 179
             // Date picker (type == group) are special fields because property path must contain the table name
180 180
             // to determine the relation type. Example for sys_category, property path will look like "items.sys_file"
181 181
             $propertyValue = $this->uid;
182 182
             if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) {
183
-                $propertyValue = $this->dataType . '.' . $this->uid;
183
+                $propertyValue = $this->dataType.'.'.$this->uid;
184 184
             }
185 185
 
186 186
             $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue);
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
                 $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable();
199 199
                 $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField();
200 200
                 $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType);
201
-                $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField);
201
+                $find = 'findOneBy'.GeneralUtility::underscoredToUpperCamelCase($foreignField);
202 202
 
203 203
                 /** @var Content $foreignObject */
204 204
                 $this->$propertyName = $foreignContentRepository->$find($this->getUid());
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
     public function offsetGet($offset)
251 251
     {
252 252
         $offset = Field::name($offset)->of($this)->toPropertyName();
253
-        $getter = 'get' . ucfirst($offset);
253
+        $getter = 'get'.ucfirst($offset);
254 254
         return $this->$getter();
255 255
     }
256 256
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
     public function offsetSet($offset, $value)
268 268
     {
269 269
         $offset = Field::name($offset)->of($this)->toPropertyName();
270
-        $setter = 'set' . ucfirst($offset);
270
+        $setter = 'set'.ucfirst($offset);
271 271
         $this->$setter($value);
272 272
         return $this;
273 273
     }
Please login to merge, or discard this patch.
Classes/Domain/Validator/LanguageValidator.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -16,25 +16,25 @@
 block discarded – undo
16 16
  */
17 17
 class LanguageValidator
18 18
 {
19
-    /**
20
-     * Check whether the $language is valid.
21
-     *
22
-     * @param int $language
23
-     * @throws \Exception
24
-     * @return void
25
-     */
26
-    public function validate($language)
27
-    {
28
-        if (!$this->getLanguageService()->languageExists((int)$language)) {
29
-            throw new \Exception('The language "' . $language . '" does not exist', 1351605542);
30
-        }
31
-    }
19
+	/**
20
+	 * Check whether the $language is valid.
21
+	 *
22
+	 * @param int $language
23
+	 * @throws \Exception
24
+	 * @return void
25
+	 */
26
+	public function validate($language)
27
+	{
28
+		if (!$this->getLanguageService()->languageExists((int)$language)) {
29
+			throw new \Exception('The language "' . $language . '" does not exist', 1351605542);
30
+		}
31
+	}
32 32
 
33
-    /**
34
-     * @return LanguageService|object
35
-     */
36
-    protected function getLanguageService()
37
-    {
38
-        return GeneralUtility::makeInstance(LanguageService::class);
39
-    }
33
+	/**
34
+	 * @return LanguageService|object
35
+	 */
36
+	protected function getLanguageService()
37
+	{
38
+		return GeneralUtility::makeInstance(LanguageService::class);
39
+	}
40 40
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
     public function validate($language)
27 27
     {
28 28
         if (!$this->getLanguageService()->languageExists((int)$language)) {
29
-            throw new \Exception('The language "' . $language . '" does not exist', 1351605542);
29
+            throw new \Exception('The language "'.$language.'" does not exist', 1351605542);
30 30
         }
31 31
     }
32 32
 
Please login to merge, or discard this patch.
Classes/Domain/Validator/MatchesValidator.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -17,19 +17,19 @@
 block discarded – undo
17 17
  */
18 18
 class MatchesValidator extends AbstractValidator
19 19
 {
20
-    /**
21
-     * Check if $matches is valid. If it is not valid, throw an exception.
22
-     *
23
-     * @param mixed $matches
24
-     * @return void
25
-     */
26
-    public function isValid($matches)
27
-    {
28
-        foreach ($matches as $fieldName => $value) {
29
-            if (!Tca::table()->hasField($fieldName)) {
30
-                $message = sprintf('Field "%s" is not allowed. Actually, it is not configured in the TCA.', $fieldName);
31
-                $this->addError($message, 1380019718);
32
-            }
33
-        }
34
-    }
20
+	/**
21
+	 * Check if $matches is valid. If it is not valid, throw an exception.
22
+	 *
23
+	 * @param mixed $matches
24
+	 * @return void
25
+	 */
26
+	public function isValid($matches)
27
+	{
28
+		foreach ($matches as $fieldName => $value) {
29
+			if (!Tca::table()->hasField($fieldName)) {
30
+				$message = sprintf('Field "%s" is not allowed. Actually, it is not configured in the TCA.', $fieldName);
31
+				$this->addError($message, 1380019718);
32
+			}
33
+		}
34
+	}
35 35
 }
Please login to merge, or discard this patch.
Classes/Domain/Validator/FacetValidator.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -17,17 +17,17 @@
 block discarded – undo
17 17
  */
18 18
 class FacetValidator extends AbstractValidator
19 19
 {
20
-    /**
21
-     * Check if $facet is valid. If it is not valid, throw an exception.
22
-     *
23
-     * @param mixed $facet
24
-     * @return void
25
-     */
26
-    public function isValid($facet)
27
-    {
28
-        if (!Tca::grid()->hasFacet($facet)) {
29
-            $message = sprintf('Facet "%s" is not allowed. Actually, it was not configured to be displayed in the grid.', $facet);
30
-            $this->addError($message, 1380019719);
31
-        }
32
-    }
20
+	/**
21
+	 * Check if $facet is valid. If it is not valid, throw an exception.
22
+	 *
23
+	 * @param mixed $facet
24
+	 * @return void
25
+	 */
26
+	public function isValid($facet)
27
+	{
28
+		if (!Tca::grid()->hasFacet($facet)) {
29
+			$message = sprintf('Facet "%s" is not allowed. Actually, it was not configured to be displayed in the grid.', $facet);
30
+			$this->addError($message, 1380019719);
31
+		}
32
+	}
33 33
 }
Please login to merge, or discard this patch.
Classes/Domain/Validator/ColumnsValidator.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -17,19 +17,19 @@
 block discarded – undo
17 17
  */
18 18
 class ColumnsValidator extends AbstractValidator
19 19
 {
20
-    /**
21
-     * Check if $columns is valid. If it is not valid, throw an exception.
22
-     *
23
-     * @param mixed $columns
24
-     * @return void
25
-     */
26
-    public function isValid($columns)
27
-    {
28
-        foreach ($columns as $columnName) {
29
-            if (!Tca::grid()->hasField($columnName)) {
30
-                $message = sprintf('Column "%s" is not allowed. Actually, it was not configured to be displayed in the grid.', $columnName);
31
-                $this->addError($message, 1380019720);
32
-            }
33
-        }
34
-    }
20
+	/**
21
+	 * Check if $columns is valid. If it is not valid, throw an exception.
22
+	 *
23
+	 * @param mixed $columns
24
+	 * @return void
25
+	 */
26
+	public function isValid($columns)
27
+	{
28
+		foreach ($columns as $columnName) {
29
+			if (!Tca::grid()->hasField($columnName)) {
30
+				$message = sprintf('Column "%s" is not allowed. Actually, it was not configured to be displayed in the grid.', $columnName);
31
+				$this->addError($message, 1380019720);
32
+			}
33
+		}
34
+	}
35 35
 }
Please login to merge, or discard this patch.
Classes/Domain/Validator/ContentValidator.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -17,18 +17,18 @@
 block discarded – undo
17 17
  */
18 18
 class ContentValidator
19 19
 {
20
-    /**
21
-     * Check whether $Content object is valid.
22
-     *
23
-     * @param Content $content
24
-     * @throws \Exception
25
-     * @return void
26
-     */
27
-    public function validate(Content $content)
28
-    {
29
-        // Security check.
30
-        if ($content->getUid() <= 0) {
31
-            throw new MissingIdentifierException('Missing identifier for Content Object', 1351605542);
32
-        }
33
-    }
20
+	/**
21
+	 * Check whether $Content object is valid.
22
+	 *
23
+	 * @param Content $content
24
+	 * @throws \Exception
25
+	 * @return void
26
+	 */
27
+	public function validate(Content $content)
28
+	{
29
+		// Security check.
30
+		if ($content->getUid() <= 0) {
31
+			throw new MissingIdentifierException('Missing identifier for Content Object', 1351605542);
32
+		}
33
+	}
34 34
 }
Please login to merge, or discard this patch.
Classes/Domain/Validator/ToolValidator.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -18,35 +18,35 @@
 block discarded – undo
18 18
  */
19 19
 class ToolValidator extends AbstractValidator
20 20
 {
21
-    /**
22
-     * Check whether $tool is valid.
23
-     *
24
-     * @param string $tool
25
-     * @return void
26
-     */
27
-    public function isValid($tool)
28
-    {
29
-        $dataType = $this->getModuleLoader()->getDataType();
30
-        $isValid = ToolRegistry::getInstance()->isAllowed($dataType, $tool);
21
+	/**
22
+	 * Check whether $tool is valid.
23
+	 *
24
+	 * @param string $tool
25
+	 * @return void
26
+	 */
27
+	public function isValid($tool)
28
+	{
29
+		$dataType = $this->getModuleLoader()->getDataType();
30
+		$isValid = ToolRegistry::getInstance()->isAllowed($dataType, $tool);
31 31
 
32
-        if (!$isValid) {
33
-            $message = sprintf('This Tool "%s" is not allowed for the current data type.', $tool);
34
-            $this->addError($message, 1409041510);
35
-        }
32
+		if (!$isValid) {
33
+			$message = sprintf('This Tool "%s" is not allowed for the current data type.', $tool);
34
+			$this->addError($message, 1409041510);
35
+		}
36 36
 
37
-        if (!class_exists($tool)) {
38
-            $message = sprintf('I could not find class "%s"', $tool);
39
-            $this->addError($message, 1409041511);
40
-        }
41
-    }
37
+		if (!class_exists($tool)) {
38
+			$message = sprintf('I could not find class "%s"', $tool);
39
+			$this->addError($message, 1409041511);
40
+		}
41
+	}
42 42
 
43
-    /**
44
-     * Get the Vidi Module Loader.
45
-     *
46
-     * @return ModuleLoader|object
47
-     */
48
-    protected function getModuleLoader()
49
-    {
50
-        return GeneralUtility::makeInstance(ModuleLoader::class);
51
-    }
43
+	/**
44
+	 * Get the Vidi Module Loader.
45
+	 *
46
+	 * @return ModuleLoader|object
47
+	 */
48
+	protected function getModuleLoader()
49
+	{
50
+		return GeneralUtility::makeInstance(ModuleLoader::class);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
Classes/Resolver/FieldPathResolver.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -19,104 +19,104 @@
 block discarded – undo
19 19
  */
20 20
 class FieldPathResolver implements SingletonInterface
21 21
 {
22
-    /**
23
-     * Remove the prefixing path from the file name.
24
-     *
25
-     * @param string $fieldNameAndPath
26
-     * @param string $dataType
27
-     * @return string
28
-     */
29
-    public function stripFieldPath($fieldNameAndPath, $dataType = '')
30
-    {
31
-        $dataType = $this->getContextualDataType($dataType);
22
+	/**
23
+	 * Remove the prefixing path from the file name.
24
+	 *
25
+	 * @param string $fieldNameAndPath
26
+	 * @param string $dataType
27
+	 * @return string
28
+	 */
29
+	public function stripFieldPath($fieldNameAndPath, $dataType = '')
30
+	{
31
+		$dataType = $this->getContextualDataType($dataType);
32 32
 
33
-        if ($this->containsPath($fieldNameAndPath, $dataType)) {
34
-            // Corresponds to the field name of the foreign table.
35
-            $fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
36
-            $fieldName = $fieldParts[1];
37
-        } else {
38
-            $fieldName = $fieldNameAndPath;
39
-        }
40
-        return $fieldName;
41
-    }
33
+		if ($this->containsPath($fieldNameAndPath, $dataType)) {
34
+			// Corresponds to the field name of the foreign table.
35
+			$fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
36
+			$fieldName = $fieldParts[1];
37
+		} else {
38
+			$fieldName = $fieldNameAndPath;
39
+		}
40
+		return $fieldName;
41
+	}
42 42
 
43
-    /**
44
-     * Remove the suffixing field name
45
-     *
46
-     * @param string $fieldNameAndPath
47
-     * @param string $dataType
48
-     * @return string
49
-     */
50
-    public function stripFieldName($fieldNameAndPath, $dataType = '')
51
-    {
52
-        $dataType = $this->getContextualDataType($dataType);
43
+	/**
44
+	 * Remove the suffixing field name
45
+	 *
46
+	 * @param string $fieldNameAndPath
47
+	 * @param string $dataType
48
+	 * @return string
49
+	 */
50
+	public function stripFieldName($fieldNameAndPath, $dataType = '')
51
+	{
52
+		$dataType = $this->getContextualDataType($dataType);
53 53
 
54
-        if ($this->containsPath($fieldNameAndPath, $dataType)) {
55
-            // Corresponds to the field name of the foreign table.
56
-            $fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
57
-            $fieldName = $fieldParts[0];
58
-        } else {
59
-            $fieldName = $fieldNameAndPath;
60
-        }
61
-        return $fieldName;
62
-    }
54
+		if ($this->containsPath($fieldNameAndPath, $dataType)) {
55
+			// Corresponds to the field name of the foreign table.
56
+			$fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
57
+			$fieldName = $fieldParts[0];
58
+		} else {
59
+			$fieldName = $fieldNameAndPath;
60
+		}
61
+		return $fieldName;
62
+	}
63 63
 
64
-    /**
65
-     * Returns the class names to be applied to a cell ("td").
66
-     *
67
-     * @param string $fieldNameAndPath
68
-     * @param string $dataType
69
-     * @return string
70
-     */
71
-    public function getDataType($fieldNameAndPath, $dataType = '')
72
-    {
73
-        $dataType = $this->getContextualDataType($dataType);
64
+	/**
65
+	 * Returns the class names to be applied to a cell ("td").
66
+	 *
67
+	 * @param string $fieldNameAndPath
68
+	 * @param string $dataType
69
+	 * @return string
70
+	 */
71
+	public function getDataType($fieldNameAndPath, $dataType = '')
72
+	{
73
+		$dataType = $this->getContextualDataType($dataType);
74 74
 
75
-        if ($this->containsPath($fieldNameAndPath, $dataType)) {
76
-            // Compute the foreign data type.
77
-            $fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
78
-            $fieldNameAndPath = $fieldParts[0];
79
-            $dataType = Tca::table($dataType)->field($fieldNameAndPath)->getForeignTable();
80
-        }
81
-        return $dataType;
82
-    }
75
+		if ($this->containsPath($fieldNameAndPath, $dataType)) {
76
+			// Compute the foreign data type.
77
+			$fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
78
+			$fieldNameAndPath = $fieldParts[0];
79
+			$dataType = Tca::table($dataType)->field($fieldNameAndPath)->getForeignTable();
80
+		}
81
+		return $dataType;
82
+	}
83 83
 
84
-    /**
85
-     * Return the data type according to the context.
86
-     *
87
-     * @param $dataType
88
-     * @return string
89
-     */
90
-    public function getContextualDataType($dataType)
91
-    {
92
-        if (!$dataType) {
93
-            $dataType = $this->getModuleLoader()->getDataType();
94
-        }
95
-        return $dataType;
96
-    }
84
+	/**
85
+	 * Return the data type according to the context.
86
+	 *
87
+	 * @param $dataType
88
+	 * @return string
89
+	 */
90
+	public function getContextualDataType($dataType)
91
+	{
92
+		if (!$dataType) {
93
+			$dataType = $this->getModuleLoader()->getDataType();
94
+		}
95
+		return $dataType;
96
+	}
97 97
 
98
-    /**
99
-     * Tell whether the field name contains a path, e.g. metadata.title
100
-     * But resolves the case when the field is composite e.g "items.sys_file_metadata" and looks as field path but is not!
101
-     * A composite field = a field for a MM relation  of type "group" where the table name is appended.
102
-     *
103
-     * @param string $fieldNameAndPath
104
-     * @param string $dataType
105
-     * @return boolean
106
-     */
107
-    public function containsPath($fieldNameAndPath, $dataType)
108
-    {
109
-        $doesContainPath = strpos($fieldNameAndPath, '.') > 0 && !Tca::table($dataType)->hasField($fieldNameAndPath); // -> will make sure it is not a composite field name.
110
-        return $doesContainPath;
111
-    }
98
+	/**
99
+	 * Tell whether the field name contains a path, e.g. metadata.title
100
+	 * But resolves the case when the field is composite e.g "items.sys_file_metadata" and looks as field path but is not!
101
+	 * A composite field = a field for a MM relation  of type "group" where the table name is appended.
102
+	 *
103
+	 * @param string $fieldNameAndPath
104
+	 * @param string $dataType
105
+	 * @return boolean
106
+	 */
107
+	public function containsPath($fieldNameAndPath, $dataType)
108
+	{
109
+		$doesContainPath = strpos($fieldNameAndPath, '.') > 0 && !Tca::table($dataType)->hasField($fieldNameAndPath); // -> will make sure it is not a composite field name.
110
+		return $doesContainPath;
111
+	}
112 112
 
113
-    /**
114
-     * Get the Vidi Module Loader.
115
-     *
116
-     * @return ModuleLoader
117
-     */
118
-    protected function getModuleLoader()
119
-    {
120
-        return GeneralUtility::makeInstance(ModuleLoader::class);
121
-    }
113
+	/**
114
+	 * Get the Vidi Module Loader.
115
+	 *
116
+	 * @return ModuleLoader
117
+	 */
118
+	protected function getModuleLoader()
119
+	{
120
+		return GeneralUtility::makeInstance(ModuleLoader::class);
121
+	}
122 122
 }
Please login to merge, or discard this patch.