Passed
Pull Request — master (#207)
by
unknown
12:49
created

MetadataGroup::isSecondaryFileGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace EWW\Dpf\Domain\Model;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
/**
18
 * MetadataGroup
19
 */
20
class MetadataGroup extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity implements MetadataMandatoryInterface
21
{
22
23
    /**
24
     * name
25
     *
26
     * @var string
27
     */
28
    protected $name = '';
29
30
    /**
31
     * displayName
32
     *
33
     * @var string
34
     */
35
    protected $displayName = '';
36
37
    /**
38
     * mandatory
39
     *
40
     * @var string
41
     */
42
    protected $mandatory = '';
43
44
    /**
45
     * mapping
46
     *
47
     * @var string
48
     */
49
    protected $mapping = '';
50
51
    /**
52
     * mappingForReading
53
     *
54
     * @var string
55
     */
56
    protected $mappingForReading = '';
57
58
    /**
59
     * modsExtensionMapping
60
     *
61
     * @var string
62
     */
63
    protected $modsExtensionMapping = '';
64
65
    /**
66
     * modsExtensionReference
67
     *
68
     * @var string
69
     */
70
    protected $modsExtensionReference = '';
71
72
    /**
73
     * maxIteration
74
     *
75
     * @var integer
76
     */
77
    protected $maxIteration = 0;
78
79
    /**
80
     * metadataObject
81
     *
82
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\MetadataObject>
83
     * @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
84
     */
85
    protected $metadataObject = null;
86
87
    /**
88
     * accessRestrictionRoles
89
     *
90
     * @var string
91
     */
92
    protected $accessRestrictionRoles = '';
93
94
    /**
95
     * infoText
96
     *
97
     * @var string
98
     */
99
    protected $infoText;
100
101
    /**
102
     * group type
103
     * @var string
104
     */
105
    protected $groupType = '';
106
107
    /**
108
     * JSON mapping
109
     *
110
     * @var string
111
     */
112
    protected $jsonMapping = '';
113
114
    /**
115
     * @var string
116
     */
117
    protected $optionalGroups = '';
118
119
    /**
120
     * @var string
121
     */
122
    protected $requiredGroups = '';
123
124
    /**
125
     * __construct
126
     */
127
    public function __construct()
128
    {
129
        //Do not remove the next line: It would break the functionality
130
        $this->initStorageObjects();
131
    }
132
133
    /**
134
     * Initializes all ObjectStorage properties
135
     *
136
     * @return void
137
     */
138
    protected function initStorageObjects()
139
    {
140
        $this->metadataObject = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
141
    }
142
143
    /**
144
     * Returns the name
145
     *
146
     * @return string $name
147
     */
148
    public function getName()
149
    {
150
        return $this->name;
151
    }
152
153
    /**
154
     * Sets the name
155
     *
156
     * @param string $name
157
     * @return void
158
     */
159
    public function setName($name)
160
    {
161
        $this->name = $name;
162
    }
163
164
    /**
165
     * Returns the displayName
166
     *
167
     * @return string $displayName
168
     */
169
    public function getDisplayName()
170
    {
171
        return $this->displayName;
172
    }
173
174
    /**
175
     * Sets the displayName
176
     *
177
     * @param string $displayName
178
     * @return void
179
     */
180
    public function setDisplayName($displayName)
181
    {
182
        $this->displayName = $displayName;
183
    }
184
185
    /**
186
     * Returns the mandatory
187
     *
188
     * @return string $mandatory
189
     */
190
    public function getMandatory()
191
    {
192
        return $this->mandatory;
193
    }
194
195
    /**
196
     * Sets the mandatory
197
     *
198
     * @param string $mandatory
199
     * @return void
200
     */
201
    public function setMandatory($mandatory)
202
    {
203
        $this->mandatory = $mandatory;
204
    }
205
206
    /**
207
     * Returns the mapping
208
     *
209
     * @return string $mapping
210
     */
211
    public function getMapping()
212
    {
213
        return $this->mapping;
214
    }
215
216
    /**
217
     * Sets the mapping
218
     *
219
     * @param string $mapping
220
     * @return void
221
     */
222
    public function setMapping($mapping)
223
    {
224
        $this->mapping = $mapping;
225
    }
226
227
    /**
228
     * Returns the mappingForReading
229
     *
230
     * @return string $mappingForReading
231
     */
232
    public function getMappingForReading()
233
    {
234
        return $this->mappingForReading;
235
    }
236
237
    /**
238
     * Sets the mappingForReading
239
     *
240
     * @param string $mappingForReading
241
     * @return void
242
     */
243
    public function setMappingForReading($mappingForReading)
244
    {
245
        $this->mappingForReading = $mappingForReading;
246
    }
247
248
    /**
249
     * Checks if a mapping for reading is defined
250
     *
251
     * @return bool
252
     */
253
    public function hasMappingForReading()
254
    {
255
        $mapping = trim($this->mappingForReading);
256
        return !empty($mapping);
257
    }
258
259
    /**
260
     * Returns the relative mapping
261
     *
262
     * @param $mapping
263
     * @return string $relativeMapping
264
     */
265
    protected function relativeMapping($mapping)
266
    {
267
        return trim($mapping, " /");
268
    }
269
270
    /**
271
     * Returns the relative mapping for writing
272
     *
273
     * @return string $relativeMappingForWriting
274
     */
275
    public function getRelativeMapping()
276
    {
277
        return $this->relativeMapping($this->mapping);
278
    }
279
280
    /**
281
     * Returns the relative mapping for reading
282
     *
283
     * @return string $relativeMappingForReading
284
     */
285
    public function getRelativeMappingForReading()
286
    {
287
        return $this->relativeMapping($this->mappingForReading);
288
    }
289
290
    /**
291
     * Returns the absolute mapping for writing
292
     *
293
     * @return string $absoluteMappingForWriting
294
     */
295
    public function getAbsoluteMapping()
296
    {
297
        return "/data/" . $this->getRelativeMapping();
298
    }
299
300
    /**
301
     * Returns the absolute mapping for reading
302
     *
303
     * @return string $absoluteMappingForReading
304
     */
305
    public function getAbsoluteMappingForReading()
306
    {
307
        return "/data/" . $this->getRelativeMappingForReading();
308
    }
309
310
    /**
311
     * Returns the modsExtensionMapping
312
     *
313
     * @return string $modsExtensionMapping
314
     */
315
    public function getModsExtensionMapping()
316
    {
317
        return $this->modsExtensionMapping;
318
    }
319
320
    /**
321
     * Sets the modsExtensionMapping
322
     *
323
     * @param string $modsExtensionMapping
324
     * @return void
325
     */
326
    public function setModsExtensionMapping($modsExtensionMapping)
327
    {
328
        $this->modsExtensionMapping = $modsExtensionMapping;
329
    }
330
331
    /**
332
     * Returns the relative mods extension mapping
333
     *
334
     * @return string $relativeModsExtensionMapping
335
     */
336
    public function getRelativeModsExtensionMapping()
337
    {
338
//        $modsRegExp = "/^.*?mods:mods/i";
339
//        $mapping    = preg_replace($modsRegExp, "", $this->modsExtensionMapping);
340
        return trim($this->modsExtensionMapping, " /");
341
    }
342
343
    /**
344
     * Returns the absolute mods extension mapping
345
     *
346
     * @return string $absoluteModsExtensionMapping
347
     */
348
    public function getAbsoluteModsExtensionMapping()
349
    {
350
        return "/data/" . $this->getRelativeModsExtensionMapping();
351
    }
352
353
    /**
354
     * Sets the modsExtensionReference
355
     *
356
     * @param string $modsExtensionReference
357
     * @return void
358
     */
359
    public function setModsExtensionReference($modsExtensionReference)
360
    {
361
        $this->modsExtensionReference = $modsExtensionReference;
362
    }
363
364
    /**
365
     * Returns the modsExtensionReference
366
     *
367
     * @return string $modsExtensionReference
368
     */
369
    public function getModsExtensionReference()
370
    {
371
        return $this->modsExtensionReference;
372
    }
373
374
    /**
375
     * Returns the maxIteration
376
     *
377
     * @return integer $maxIteration
378
     */
379
    public function getMaxIteration()
380
    {
381
        if ($this->isPrimaryFileGroup()) {
382
            return 1;
383
        }
384
        return $this->maxIteration;
385
    }
386
387
    /**
388
     * Sets the maxIteration
389
     *
390
     * @param integer $maxIteration
391
     * @return void
392
     */
393
    public function setMaxIteration($maxIteration)
394
    {
395
        if ($this->isPrimaryFileGroup()) {
396
            $maxIteration = 1;
397
        }
398
        $this->maxIteration = $maxIteration;
399
    }
400
401
    /**
402
     * Adds a MetadataObject
403
     *
404
     * @param \EWW\Dpf\Domain\Model\MetadataObject $metadataObject
405
     * @return void
406
     */
407
    public function addMetadataObject(\EWW\Dpf\Domain\Model\MetadataObject $metadataObject)
408
    {
409
        $this->metadataObject->attach($metadataObject);
410
    }
411
412
    /**
413
     * Removes a MetadataObject
414
     *
415
     * @param \EWW\Dpf\Domain\Model\MetadataObject $metadataObjectToRemove The MetadataObject to be removed
416
     * @return void
417
     */
418
    public function removeMetadataObject(\EWW\Dpf\Domain\Model\MetadataObject $metadataObjectToRemove)
419
    {
420
        $this->metadataObject->detach($metadataObjectToRemove);
421
    }
422
423
    /**
424
     * Returns the metadataObject
425
     *
426
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\MetadataObject> $metadataObject
427
     */
428
    public function getMetadataObject()
429
    {
430
        return $this->metadataObject;
431
    }
432
433
    /**
434
     * Sets the metadataObject
435
     *
436
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\MetadataObject> $metadataObject
437
     * @return void
438
     */
439
    public function setMetadataObject(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $metadataObject)
440
    {
441
        $this->metadataObject = $metadataObject;
442
    }
443
444
    /**
445
     * Alias for function getMetadataObject()
446
     *
447
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\MetadataObject> $metadataObject
448
     */
449
    public function getChildren()
450
    {
451
        return $this->getMetadataObject();
452
    }
453
454
    /**
455
     * Returns the accessRestrictionRoles
456
     *
457
     * @return array $accessRestrictionRoles
458
     */
459
    public function getAccessRestrictionRoles()
460
    {
461
        if ($this->accessRestrictionRoles) {
462
            return array_map('trim', explode(',', $this->accessRestrictionRoles));
463
        } else {
464
            return array();
465
        }
466
    }
467
468
    /**
469
     * Sets the accessRestrictionRoles
470
     *
471
     * @param array $accessRestrictionRoles
472
     * @return void
473
     */
474
    public function setAccessRestrictionRoles($accessRestrictionRoles)
475
    {
476
        $this->accessRestrictionRoles = implode(',', $accessRestrictionRoles);
477
    }
478
479
    /**
480
     * Returns the infoText
481
     *
482
     * @return string $infoText
483
     */
484
    public function getInfoText()
485
    {
486
        return $this->infoText;
487
    }
488
489
    /**
490
     * Sets the infoText
491
     *
492
     * @param string $infoText
493
     * @return void
494
     */
495
    public function setInfoText($infoText)
496
    {
497
        $this->infoText = $infoText;
498
    }
499
500
    /**
501
     * @return string
502
     */
503
    public function getGroupType(): string
504
    {
505
        return $this->groupType;
506
    }
507
508
    /**
509
     * @param string $groupType
510
     */
511
    public function setGroupType(string $groupType)
512
    {
513
        $this->groupType = $groupType;
514
    }
515
516
    public function isFileGroup()
517
    {
518
        return $this->isPrimaryFileGroup() || $this->isSecondaryFileGroup();
519
    }
520
521
    public function isPrimaryFileGroup()
522
    {
523
        return $this->getGroupType() == 'primary_file';
524
    }
525
526
    public function isSecondaryFileGroup()
527
    {
528
        return $this->getGroupType() == 'secondary_file';
529
    }
530
531
    /**
532
     * Gets the jsonMapping
533
     *
534
     * @return string
535
     */
536
    public function getJsonMapping(): string
537
    {
538
        return $this->jsonMapping;
539
    }
540
541
    /**
542
     * Sets the jsonMapping
543
     *
544
     * @param string $jsonMapping
545
     */
546
    public function setJsonMapping(string $jsonMapping): void
547
    {
548
        $this->jsonMapping = $jsonMapping;
549
    }
550
551
    /**
552
     * @return string
553
     */
554
    public function getOptionalGroups(): string
555
    {
556
        return $this->optionalGroups;
557
    }
558
559
    /**
560
     * @param string $optionalGroups
561
     */
562
    public function setOptionalGroups(string $optionalGroups): void
563
    {
564
        $this->optionalGroups = $optionalGroups;
565
    }
566
567
    /**
568
     * @return string
569
     */
570
    public function getRequiredGroups(): string
571
    {
572
        return $this->requiredGroups;
573
    }
574
575
    /**
576
     * @param string $requiredGroups
577
     */
578
    public function setRequiredGroups(string $requiredGroups): void
579
    {
580
        $this->requiredGroups = $requiredGroups;
581
    }
582
583
584
}
585