Passed
Pull Request — master (#155)
by
unknown
08:39
created

Document::setOwner()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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
use EWW\Dpf\Domain\Workflow\DocumentWorkflow;
18
19
/**
20
 * Document
21
 */
22
class Document extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
23
{
24
    /**
25
     * title
26
     *
27
     * @var string
28
     */
29
    protected $title = '';
30
31
    /**
32
     * authors
33
     *
34
     * @var string
35
     */
36
    protected $authors = '';
37
38
    /**
39
     * xmlData
40
     *
41
     * @var string
42
     */
43
    protected $xmlData = '';
44
45
    /**
46
     * slubInfoData
47
     *
48
     * @var string
49
     */
50
    protected $slubInfoData = '';
51
52
    /**
53
     * documentType
54
     *
55
     * @var \EWW\Dpf\Domain\Model\DocumentType
56
     */
57
    protected $documentType = null;
58
59
    /**
60
     * objectIdentifier
61
     *
62
     * @var string
63
     */
64
    protected $objectIdentifier;
65
66
    /**
67
     * reservedObjectIdentifier
68
     *
69
     * @var string
70
     */
71
    protected $reservedObjectIdentifier;
72
73
    /**
74
     * transferStatus
75
     *
76
     * @var string
77
     */
78
    protected $transferStatus;
79
80
    /**
81
     *  transferDate
82
     *
83
     * @var integer
84
     */
85
    protected $transferDate;
86
87
    /**
88
     * changed
89
     *
90
     * @var boolean
91
     */
92
    protected $changed = false;
93
94
    /**
95
     * valid
96
     *
97
     * @var boolean
98
     */
99
    protected $valid = false;
100
101
    /**
102
     *
103
     * @var string $dateIssued
104
     */
105
    protected $dateIssued;
106
107
    /**
108
     *
109
     * @var string $processNumber
110
     */
111
    protected $processNumber;
112
113
    /**
114
     * @var bool $suggestion
115
     */
116
    protected $suggestion = false;
117
118
    /**
119
     * owner
120
     *
121
     * @var integer
122
     */
123
    protected $owner = 0;
124
125
    /**
126
     * state
127
     *
128
     * @var string
129
     */
130
    protected $state = DocumentWorkflow::STATE_NONE_NONE;
131
132
    /**
133
     * editorUid
134
     *
135
     * @var integer
136
     */
137
    protected $editorUid = 0;
138
139
    /**
140
     * temporary
141
     *
142
     * @var boolean
143
     */
144
    protected $temporary = FALSE;
145
146
    /**
147
     * remoteLastModDate
148
     *
149
     * @var string
150
     */
151
    protected $remoteLastModDate = '';
152
153
    /**
154
     * tstamp
155
     *
156
     * @var integer
157
     */
158
    protected $tstamp;
159
160
    /**
161
     * @var string
162
     */
163
    protected $linkedUid = '';
164
165
    /**
166
     * @var string
167
     */
168
    protected $comment = '';
169
170
    /**
171
     * file
172
     *
173
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\File>
174
     * @cascade remove
175
     */
176
    protected $file = null;
177
178
    const TRANSFER_ERROR = "ERROR";
179
    const TRANSFER_QUEUED = "QUEUED";
180
    const TRANSFER_SENT = "SENT";
181
182
    /**
183
     * __construct
184
     */
185
    public function __construct()
186
    {
187
        //Do not remove the next line: It would break the functionality
188
        $this->initStorageObjects();
189
    }
190
191
    /**
192
     * Initializes all ObjectStorage properties
193
     *
194
     * @return void
195
     */
196
    protected function initStorageObjects()
197
    {
198
        $this->file = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
199
    }
200
201
    /**
202
     * Returns the title
203
     *
204
     * @return string $title
205
     */
206
    public function getTitle()
207
    {
208
        return $this->title;
209
    }
210
211
    /**
212
     * Sets the title
213
     *
214
     * @param string $title
215
     * @return void
216
     */
217
    public function setTitle($title)
218
    {
219
        $this->title = $title;
220
        //htmlspecialchars_decode($title,ENT_QUOTES);
221
    }
222
223
    /**
224
     * Returns the authors
225
     *
226
     * @return array $authors
227
     */
228
    public function getAuthors()
229
    {
230
        return array_map('trim', explode(";", $this->authors));
231
    }
232
233
    /**
234
     * Sets the authors
235
     *
236
     * @param array $authors
237
     * @return void
238
     */
239
    public function setAuthors($authors)
240
    {
241
        $authors = implode("; ", $authors);
242
        $this->authors = $authors;
243
    }
244
245
    /**
246
     * Returns the xmlData
247
     *
248
     * @return string $xmlData
249
     */
250
    public function getXmlData()
251
    {
252
        return $this->xmlData;
253
    }
254
255
    /**
256
     * Sets the xmlData
257
     *
258
     * @param string $xmlData
259
     * @return void
260
     */
261
    public function setXmlData($xmlData)
262
    {
263
        $this->xmlData = $xmlData;
264
    }
265
266
    /**
267
     * Returns the slubInfoData
268
     *
269
     * @return string $slubInfoData
270
     */
271
    public function getSlubInfoData()
272
    {
273
        return $this->slubInfoData;
274
    }
275
276
    /**
277
     * Sets the slubInfoData
278
     *
279
     * @return string $slubInfoData
280
     */
281
    public function setSlubInfoData($slubInfoData)
282
    {
283
        $this->slubInfoData = $slubInfoData;
284
    }
285
286
    /**
287
     * Returns the documentType
288
     *
289
     * @return \EWW\Dpf\Domain\Model\DocumentType $documentType
290
     */
291
    public function getDocumentType()
292
    {
293
        return $this->documentType;
294
    }
295
296
    /**
297
     * Sets the documentType
298
     *
299
     * @param \EWW\Dpf\Domain\Model\DocumentType $documentType
300
     * @return void
301
     */
302
    public function setDocumentType(\EWW\Dpf\Domain\Model\DocumentType $documentType)
303
    {
304
        $this->documentType = $documentType;
305
    }
306
307
    /**
308
     * Returns the objectIdentifier
309
     *
310
     * @return string
311
     */
312
    public function getObjectIdentifier()
313
    {
314
        return $this->objectIdentifier;
315
    }
316
317
    /**
318
     * Sets the objectIdentifier
319
     *
320
     * @param string $objectIdentifier
321
     * @return void
322
     */
323
    public function setObjectIdentifier($objectIdentifier)
324
    {
325
        $this->objectIdentifier = $objectIdentifier;
326
    }
327
328
    /**
329
     * Returns the reservedObjectIdentifier
330
     *
331
     * @return string
332
     */
333
    public function getReservedObjectIdentifier()
334
    {
335
        return $this->reservedObjectIdentifier;
336
    }
337
338
    /**
339
     * Sets the reservedObjectIdentifier
340
     *
341
     * @param string $reservedObjectIdentifier
342
     * @return void
343
     */
344
    public function setReservedObjectIdentifier($reservedObjectIdentifier)
345
    {
346
        $this->reservedObjectIdentifier = $reservedObjectIdentifier;
347
    }
348
349
    /**
350
     * Returns the transferStatus
351
     *
352
     * @return string
353
     */
354
    public function getTransferStatus()
355
    {
356
        return $this->transferStatus;
357
    }
358
359
    /**
360
     * Sets the transferStatus
361
     *
362
     * @param string
363
     * @return void
364
     */
365
    public function setTransferStatus($transferStatus)
366
    {
367
        $this->transferStatus = $transferStatus;
368
    }
369
370
    /**
371
     * Returns the transferDate
372
     *
373
     * @return integer
374
     */
375
    public function getTransferDate()
376
    {
377
        return $this->transferDate;
378
    }
379
380
    /**
381
     * Sets the transferDate
382
     *
383
     * @param integer $transferDate
384
     * @return void
385
     */
386
    public function setTransferDate($transferDate)
387
    {
388
        $this->transferDate = $transferDate;
389
    }
390
391
    /**
392
     * Returns the transferErrorCode
393
     *
394
     * @var integer
395
     */
396
    public function getTransferErrorCode()
397
    {
398
        return $this->transferErrorCode;
399
    }
400
401
    /**
402
     * Sets the transferErrorCode
403
     *
404
     * @param integer $transferErrorCode
405
     * @return void
406
     */
407
    public function setTransferErrorCode($transferErrorCode)
408
    {
409
        $this->transferErrorCode = $transferErrorCode;
0 ignored issues
show
Bug Best Practice introduced by
The property transferErrorCode does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
410
    }
411
412
    /**
413
     * Returns the transferResponse
414
     *
415
     * @var string
416
     */
417
    public function getTransferResponse()
418
    {
419
        return $this->transferResponse;
420
    }
421
422
    /**
423
     * Sets the transferResponse
424
     *
425
     * @param string $transferResponse
426
     * @return void
427
     */
428
    public function setTransferResponse($transferResponse)
429
    {
430
        $this->transferResponse = $transferResponse;
0 ignored issues
show
Bug Best Practice introduced by
The property transferResponse does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
431
    }
432
433
    /**
434
     * Returns the transferHttpStatus
435
     *
436
     * @var integer
437
     */
438
    public function getTransferHttpStatus()
439
    {
440
        return $this->transferHttpStatus;
441
    }
442
443
    /**
444
     * Sets the transferHttpStatus
445
     *
446
     * @param integer $transferHttpStatus
447
     * @return void
448
     */
449
    public function setTransferHttpStatus($transferHttpStatus)
450
    {
451
        $this->transferHttpStatus = $transferHttpStatus;
0 ignored issues
show
Bug Best Practice introduced by
The property transferHttpStatus does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
452
    }
453
454
    /**
455
     * Adds a File
456
     *
457
     * @param \EWW\Dpf\Domain\Model\File $file
458
     * @return void
459
     */
460
    public function addFile(\EWW\Dpf\Domain\Model\File $file)
461
    {
462
        $this->file->attach($file);
463
    }
464
465
    /**
466
     * Removes a File
467
     *
468
     * @param \EWW\Dpf\Domain\Model\File $fileToRemove The File to be removed
469
     * @return void
470
     */
471
    public function removeFile(\EWW\Dpf\Domain\Model\File $fileToRemove)
472
    {
473
        $this->file->detach($fileToRemove);
474
    }
475
476
    /**
477
     * Returns the file
478
     *
479
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\File> $file
480
     */
481
    public function getFile()
482
    {
483
        return $this->file;
484
    }
485
486
    /**
487
     * Sets the file
488
     *
489
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\File> $file
490
     * @return void
491
     */
492
    public function setFile(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $file)
493
    {
494
        $this->file = $file;
495
    }
496
497
    /**
498
     * Get File Data
499
     *
500
     * @return array
501
     */
502
    public function getFileData()
503
    {
504
505
        $fileId = new \EWW\Dpf\Services\Transfer\FileId($this);
506
507
        $files = array();
508
509
        if (is_a($this->getFile(), '\TYPO3\CMS\Extbase\Persistence\ObjectStorage')) {
510
            foreach ($this->getFile() as $file) {
511
512
                if (!$file->isFileGroupDeleted()) {
513
514
                    $tmpFile = array(
515
                        'path' => $file->getLink(),
516
                        'type' => $file->getContentType(),
517
                        'title' => (($file->getLabel()) ? $file->getLabel() : $file->getTitle()),
518
                        'download' => $file->getDownload(),
519
                        'archive' => $file->getArchive(),
520
                        'use' => '',
521
                        'id' => null,
522
                        'hasFLocat' => ($file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_ADDED ||
523
                            $file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_CHANGED),
524
                    );
525
526
                    $grpUSE = ($file->getDownload()) ? 'download' : 'original';
527
528
                    if ($file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_DELETED) {
529
                        $dataStreamIdentifier = $file->getDatastreamIdentifier();
530
                        if (!empty($dataStreamIdentifier)) {
531
                            $tmpFile['id'] = $file->getDatastreamIdentifier();
532
                            $tmpFile['use'] = 'DELETE';
533
                            $files[$grpUSE][$file->getUid()] = $tmpFile;
534
                        }
535
                    } else {
536
                        $tmpFile['id'] = $fileId->getId($file);
537
                        $tmpFile['use'] = ($file->getArchive()) ? 'ARCHIVE' : '';
538
                        $files[$grpUSE][$file->getUid()] = $tmpFile;
539
                    }
540
                }
541
542
            }
543
        }
544
545
        return $files;
546
    }
547
548
    /**
549
     * Get Current File Data
550
     *
551
     * @return array
552
     */
553
    public function getCurrentFileData()
554
    {
555
556
        $fileId = new \EWW\Dpf\Services\Transfer\FileId($this);
557
558
        $files = array();
559
560
        if (is_a($this->getFile(), '\TYPO3\CMS\Extbase\Persistence\ObjectStorage')) {
561
            foreach ($this->getFile() as $file) {
562
563
                $tmpFile = array(
564
                    'path' => $file->getLink(),
565
                    'type' => $file->getContentType(),
566
                    'title' => (($file->getLabel()) ? $file->getLabel() : $file->getTitle()),
567
                    'download' => $file->getDownload(),
568
                    'archive' => $file->getArchive(),
569
                    'use' => '',
570
                    'id' => null,
571
                    'hasFLocat' => ($file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_ADDED ||
572
                        $file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_CHANGED),
573
                );
574
575
                $grpUSE = ($file->getDownload()) ? 'download' : 'original';
576
577
                if ($file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_DELETED) {
578
                    $dataStreamIdentifier = $file->getDatastreamIdentifier();
579
                    if (!empty($dataStreamIdentifier)) {
580
                        $tmpFile['id'] = $file->getDatastreamIdentifier();
581
                        $tmpFile['use'] = 'DELETE';
582
                        $files[$grpUSE][$file->getUid()] = $tmpFile;
583
                    }
584
                } else {
585
                    $tmpFile['id'] = $fileId->getId($file);
586
                    $tmpFile['use'] = ($file->getArchive()) ? 'ARCHIVE' : '';
587
                    $files[$grpUSE][$file->getUid()] = $tmpFile;
588
                }
589
590
            }
591
        }
592
593
        return $files;
594
595
    }
596
597
    /**
598
     * Returns the changed
599
     *
600
     * @return boolean $changed
601
     */
602
    public function getChanged()
603
    {
604
        return $this->changed;
605
    }
606
607
    /**
608
     * Sets the changed
609
     *
610
     * @param boolean $changed
611
     * @return void
612
     */
613
    public function setChanged($changed)
614
    {
615
        $this->changed = $changed;
616
    }
617
618
    /**
619
     * Returns the valid
620
     *
621
     * @return boolean $valid
622
     */
623
    public function getValid()
624
    {
625
        return $this->valid;
626
    }
627
628
    /**
629
     * Sets the valid
630
     *
631
     * @param boolean $valid
632
     * @return void
633
     */
634
    public function setValid($valid)
635
    {
636
        $this->valid = $valid;
637
    }
638
639
    /**
640
     * Gets the Issue Date
641
     *
642
     * @return string
643
     */
644
    public function getDateIssued()
645
    {
646
        return empty($this->dateIssued) ? '' : $this->dateIssued;
647
    }
648
649
    /**
650
     * Sets the Issue Date
651
     *
652
     * @param string $dateIssued
653
     * @return void
654
     */
655
    public function setDateIssued($dateIssued)
656
    {
657
        $this->dateIssued = empty($dateIssued) ? '' : $dateIssued;
658
    }
659
660
661
    /**
662
     * Returns the process number
663
     *
664
     * @return string
665
     */
666
    public function getProcessNumber()
667
    {
668
        return $this->processNumber;
669
    }
670
671
    /**
672
     * Sets the process number
673
     *
674
     * @param string $processNumber
675
     * @return void
676
     */
677
    public function setProcessNumber($processNumber)
678
    {
679
        $this->processNumber = trim($processNumber);
680
    }
681
682
683
    /**
684
     * Gets the submitter name of the document
685
     *
686
     * @return string
687
     */
688
    public function getSubmitterName()
689
    {
690
        try {
691
            $slub = new \EWW\Dpf\Helper\Slub($this->getSlubInfoData());
692
            return $slub->getSubmitterName();
693
        } catch (\Exception $exception) {
694
            return "";
695
        }
696
    }
697
698
    /**
699
     * Gets the qucosa urn of the document
700
     *
701
     * @return string
702
     */
703
    public function getQucosaUrn()
704
    {
705
        $mods = new \EWW\Dpf\Helper\Mods($this->getXmlData());
706
        return $mods->getQucosaUrn();
707
    }
708
709
    /**
710
     * Returns the owner uid
711
     *
712
     * @return integer
713
     */
714
    public function getOwner()
715
    {
716
        return $this->owner;
717
    }
718
719
    /**
720
     * Sets the owner uid
721
     *
722
     * @param integer $owner
723
     * @return void
724
     */
725
    public function setOwner($owner)
726
    {
727
        $this->owner = $owner;
728
    }
729
730
    public function getState()
731
    {
732
        return $this->state;
733
    }
734
735
    public function setState($state)
736
    {
737
        $this->state = $state;
738
    }
739
740
    public function getRemoteState()
741
    {
742
        $state = explode(':', $this->state);
743
        if (is_array($state) && array_key_exists(1, $state)) {
744
            return $state[1];
745
        }
746
        return DocumentWorkflow::REMOTE_STATE_NONE;
747
    }
748
749
    public function getLocalState() {
750
        $state = explode(':', $this->state);
751
        if (is_array($state) && array_key_exists(0, $state)) {
752
            return $state[0];
753
        }
754
        return DocumentWorkflow::LOCAL_STATE_NONE;
755
    }
756
757
    /**
758
     * Returns if a document is a temporary document.
759
     *
760
     * @return boolean $temporary
761
     */
762
    public function isTemporary() {
763
        return $this->temporary;
764
    }
765
766
    /**
767
     * Sets if a document is a temporary document or not.
768
     *
769
     * @param boolean $temporary
770
     * @return void
771
     */
772
    public function setTemporary($temporary) {
773
        $this->temporary = $temporary;
774
    }
775
776
    /**
777
     * @return integer
778
     */
779
    public function getEditorUid()
780
    {
781
        return $this->editorUid;
782
    }
783
784
    /**
785
     * @param integer $editorUid
786
     * @return void
787
     */
788
    public function setEditorUid($editorUid)
789
    {
790
        $this->editorUid = $editorUid;
791
    }
792
793
    /**
794
     * @return string
795
     */
796
    public function getRemoteLastModDate()
797
    {
798
        return $this->remoteLastModDate;
799
    }
800
801
    /**
802
     * @param string $remoteLastModDate
803
     * @return void
804
     */
805
    public function setRemoteLastModDate($remoteLastModDate)
806
    {
807
        $this->remoteLastModDate = $remoteLastModDate;
808
    }
809
810
    /**
811
     * @return integer
812
     */
813
    public function getTstamp()
814
    {
815
        return $this->tstamp;
816
    }
817
818
    /**
819
     * @return bool
820
     */
821
    public function isSuggestion(): bool
822
    {
823
        return $this->suggestion;
824
    }
825
826
    /**
827
     * @param bool $suggestion
828
     */
829
    public function setSuggestion(bool $suggestion)
830
    {
831
        $this->suggestion = $suggestion;
832
    }
833
834
    /**
835
     * @return string
836
     */
837
    public function getLinkedUid(): string
838
    {
839
        return $this->linkedUid;
840
    }
841
842
    /**
843
     * @param string $linkedUid
844
     */
845
    public function setLinkedUid(string $linkedUid)
846
    {
847
        $this->linkedUid = $linkedUid;
848
    }
849
850
    /**
851
     * @return string
852
     */
853
    public function getComment(): string
854
    {
855
        return $this->comment;
856
    }
857
858
    /**
859
     * @param string $comment
860
     */
861
    public function setComment(string $comment)
862
    {
863
        $this->comment = $comment;
864
    }
865
866
    /**
867
     * Copies the data of the given document object into the current document object.
868
     *
869
     * @param Document $documentToCopy
870
     * @return $this
871
     * @throws \TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException
872
     */
873
    public function copy(Document $documentToCopy) {
874
        $availableProperties = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettablePropertyNames($documentToCopy);
875
        $newDocument = $this;
876
877
        foreach ($availableProperties as $propertyName) {
878
            if (\TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($newDocument, $propertyName)
879
                && !in_array($propertyName, array('uid','pid', 'file', 'comment', 'linkedUid', 'suggestion', 'owner'))) {
880
881
                $propertyValue = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($documentToCopy, $propertyName);
882
                \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($newDocument, $propertyName, $propertyValue);
883
            }
884
        }
885
886
        return $this;
887
    }
888
889
    public function getNotes() {
890
        $slub = new \EWW\Dpf\Helper\Slub($this->getSlubInfoData());
891
        return $slub->getNotes();
892
    }
893
894
895
}
896