Total Complexity | 118 |
Total Lines | 1072 |
Duplicated Lines | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
Complex classes like Document often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Document, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | class Document extends AbstractEntity |
||
25 | { |
||
26 | // xml data size ist limited to 64 KB |
||
27 | const XML_DATA_SIZE_LIMIT = 64 * 1024; |
||
28 | |||
29 | /** |
||
30 | * title |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $title = ''; |
||
35 | |||
36 | /** |
||
37 | * authors |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $authors = ''; |
||
42 | |||
43 | /** |
||
44 | * xmlData |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $xmlData = ''; |
||
49 | |||
50 | /** |
||
51 | * slubInfoData |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $slubInfoData = ''; |
||
56 | |||
57 | /** |
||
58 | * documentType |
||
59 | * |
||
60 | * @var \EWW\Dpf\Domain\Model\DocumentType |
||
61 | */ |
||
62 | protected $documentType = null; |
||
63 | |||
64 | /** |
||
65 | * objectIdentifier |
||
66 | * |
||
67 | * @var string |
||
68 | */ |
||
69 | protected $objectIdentifier = ''; |
||
70 | |||
71 | /** |
||
72 | * reservedObjectIdentifier |
||
73 | * |
||
74 | * @var string |
||
75 | */ |
||
76 | protected $reservedObjectIdentifier; |
||
77 | |||
78 | /** |
||
79 | * transferStatus |
||
80 | * |
||
81 | * @var string |
||
82 | */ |
||
83 | protected $transferStatus; |
||
84 | |||
85 | /** |
||
86 | * transferDate |
||
87 | * |
||
88 | * @var integer |
||
89 | */ |
||
90 | protected $transferDate; |
||
91 | |||
92 | /** |
||
93 | * changed |
||
94 | * |
||
95 | * @var boolean |
||
96 | */ |
||
97 | protected $changed = false; |
||
98 | |||
99 | /** |
||
100 | * valid |
||
101 | * |
||
102 | * @var boolean |
||
103 | */ |
||
104 | protected $valid = false; |
||
105 | |||
106 | /** |
||
107 | * |
||
108 | * @var string $dateIssued |
||
109 | */ |
||
110 | protected $dateIssued; |
||
111 | |||
112 | /** |
||
113 | * |
||
114 | * @var string $processNumber |
||
115 | */ |
||
116 | protected $processNumber = ''; |
||
117 | |||
118 | /** |
||
119 | * @var bool $suggestion |
||
120 | */ |
||
121 | protected $suggestion = false; |
||
122 | |||
123 | /** |
||
124 | * creator |
||
125 | * |
||
126 | * @var int |
||
127 | */ |
||
128 | protected $creator = 0; |
||
129 | |||
130 | /** |
||
131 | * creation date |
||
132 | * |
||
133 | * @var string |
||
134 | */ |
||
135 | protected $creationDate = ""; |
||
136 | |||
137 | /** |
||
138 | * state |
||
139 | * |
||
140 | * @var string |
||
141 | */ |
||
142 | protected $state = DocumentWorkflow::STATE_NONE_NONE; |
||
143 | |||
144 | /** |
||
145 | * temporary |
||
146 | * |
||
147 | * @var boolean |
||
148 | */ |
||
149 | protected $temporary = FALSE; |
||
150 | |||
151 | /** |
||
152 | * remoteLastModDate |
||
153 | * |
||
154 | * @var string |
||
155 | */ |
||
156 | protected $remoteLastModDate = ''; |
||
157 | |||
158 | /** |
||
159 | * tstamp |
||
160 | * |
||
161 | * @var integer |
||
162 | */ |
||
163 | protected $tstamp; |
||
164 | |||
165 | /** |
||
166 | * crdate |
||
167 | * |
||
168 | * @var integer |
||
169 | */ |
||
170 | protected $crdate; |
||
171 | |||
172 | /** |
||
173 | * @var string |
||
174 | */ |
||
175 | protected $linkedUid = ''; |
||
176 | |||
177 | /** |
||
178 | * @var string |
||
179 | */ |
||
180 | protected $comment = ''; |
||
181 | |||
182 | /** |
||
183 | * date |
||
184 | * |
||
185 | * @var \DateTime |
||
186 | */ |
||
187 | protected $embargoDate = null; |
||
188 | |||
189 | /** |
||
190 | * newlyAssignedFobIdentifiers |
||
191 | * |
||
192 | * @var array |
||
193 | */ |
||
194 | protected $newlyAssignedFobIdentifiers = []; |
||
195 | |||
196 | /** |
||
197 | * @var bool |
||
198 | */ |
||
199 | protected $stateChange = false; |
||
200 | |||
201 | /** |
||
202 | * file |
||
203 | * |
||
204 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\File> |
||
205 | * @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove") |
||
206 | */ |
||
207 | protected $file = null; |
||
208 | |||
209 | const TRANSFER_ERROR = "ERROR"; |
||
210 | const TRANSFER_QUEUED = "QUEUED"; |
||
211 | const TRANSFER_SENT = "SENT"; |
||
212 | |||
213 | /** |
||
214 | * __construct |
||
215 | */ |
||
216 | public function __construct() |
||
217 | { |
||
218 | //Do not remove the next line: It would break the functionality |
||
219 | $this->initStorageObjects(); |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * Initializes all ObjectStorage properties |
||
224 | * |
||
225 | * @return void |
||
226 | */ |
||
227 | protected function initStorageObjects() |
||
228 | { |
||
229 | $this->file = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); |
||
230 | $this->initCreationDate(); |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * Returns the title |
||
235 | * |
||
236 | * @return string $title |
||
237 | */ |
||
238 | public function getTitle() |
||
239 | { |
||
240 | return $this->title; |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * Sets the title |
||
245 | * |
||
246 | * @param string $title |
||
247 | * @return void |
||
248 | */ |
||
249 | public function setTitle($title) |
||
250 | { |
||
251 | $this->title = $title ?? ''; |
||
252 | //htmlspecialchars_decode($title,ENT_QUOTES); |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * Returns the authors |
||
257 | * |
||
258 | * @return array $authors |
||
259 | */ |
||
260 | public function getAuthors() |
||
261 | { |
||
262 | $authors = @unserialize($this->authors); |
||
263 | if (is_array($authors)) { |
||
264 | return $authors; |
||
265 | } else { |
||
266 | return []; |
||
267 | } |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * Sets the authors |
||
272 | * |
||
273 | * @param array $authors |
||
274 | * @return void |
||
275 | */ |
||
276 | public function setAuthors($authors) |
||
277 | { |
||
278 | $this->authors = serialize($authors); |
||
279 | } |
||
280 | |||
281 | /** |
||
282 | * Returns the xmlData |
||
283 | * |
||
284 | * @return string $xmlData |
||
285 | */ |
||
286 | public function getXmlData() |
||
287 | { |
||
288 | return $this->xmlData; |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * Sets the xmlData |
||
293 | * |
||
294 | * @param string $xmlData |
||
295 | * @return void |
||
296 | */ |
||
297 | public function setXmlData($xmlData) |
||
298 | { |
||
299 | $this->xmlData = $xmlData; |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * Returns the slubInfoData |
||
304 | * |
||
305 | * @return string $slubInfoData |
||
306 | */ |
||
307 | public function getSlubInfoData() |
||
308 | { |
||
309 | return $this->slubInfoData; |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * Sets the slubInfoData |
||
314 | * |
||
315 | * @return string $slubInfoData |
||
316 | */ |
||
317 | public function setSlubInfoData($slubInfoData) |
||
318 | { |
||
319 | $this->slubInfoData = $slubInfoData; |
||
320 | } |
||
321 | |||
322 | /** |
||
323 | * Returns the documentType |
||
324 | * |
||
325 | * @return \EWW\Dpf\Domain\Model\DocumentType $documentType |
||
326 | */ |
||
327 | public function getDocumentType() |
||
328 | { |
||
329 | return $this->documentType; |
||
330 | } |
||
331 | |||
332 | /** |
||
333 | * Sets the documentType |
||
334 | * |
||
335 | * @param \EWW\Dpf\Domain\Model\DocumentType $documentType |
||
336 | * @return void |
||
337 | */ |
||
338 | public function setDocumentType(\EWW\Dpf\Domain\Model\DocumentType $documentType) |
||
339 | { |
||
340 | $this->documentType = $documentType; |
||
341 | } |
||
342 | |||
343 | /** |
||
344 | * Returns the objectIdentifier |
||
345 | * |
||
346 | * @return string |
||
347 | */ |
||
348 | public function getObjectIdentifier() |
||
349 | { |
||
350 | return $this->objectIdentifier; |
||
351 | } |
||
352 | |||
353 | /** |
||
354 | * Sets the objectIdentifier |
||
355 | * |
||
356 | * @param string $objectIdentifier |
||
357 | * @return void |
||
358 | */ |
||
359 | public function setObjectIdentifier($objectIdentifier) |
||
360 | { |
||
361 | // Due to uniqe key uc_object_identifier, which should ignore empty object identifiers. |
||
362 | $this->objectIdentifier = empty($objectIdentifier)? null : $objectIdentifier; |
||
363 | } |
||
364 | |||
365 | /** |
||
366 | * Returns the reservedObjectIdentifier |
||
367 | * |
||
368 | * @return string |
||
369 | */ |
||
370 | public function getReservedObjectIdentifier() |
||
371 | { |
||
372 | return $this->reservedObjectIdentifier; |
||
373 | } |
||
374 | |||
375 | /** |
||
376 | * Sets the reservedObjectIdentifier |
||
377 | * |
||
378 | * @param string $reservedObjectIdentifier |
||
379 | * @return void |
||
380 | */ |
||
381 | public function setReservedObjectIdentifier($reservedObjectIdentifier) |
||
382 | { |
||
383 | $this->reservedObjectIdentifier = $reservedObjectIdentifier; |
||
384 | } |
||
385 | |||
386 | /** |
||
387 | * Returns the transferStatus |
||
388 | * |
||
389 | * @return string |
||
390 | */ |
||
391 | public function getTransferStatus() |
||
392 | { |
||
393 | return $this->transferStatus; |
||
394 | } |
||
395 | |||
396 | /** |
||
397 | * Sets the transferStatus |
||
398 | * |
||
399 | * @param string |
||
400 | * @return void |
||
401 | */ |
||
402 | public function setTransferStatus($transferStatus) |
||
403 | { |
||
404 | $this->transferStatus = $transferStatus; |
||
405 | } |
||
406 | |||
407 | /** |
||
408 | * Returns the transferDate |
||
409 | * |
||
410 | * @return integer |
||
411 | */ |
||
412 | public function getTransferDate() |
||
413 | { |
||
414 | return $this->transferDate; |
||
415 | } |
||
416 | |||
417 | /** |
||
418 | * Sets the transferDate |
||
419 | * |
||
420 | * @param integer $transferDate |
||
421 | * @return void |
||
422 | */ |
||
423 | public function setTransferDate($transferDate) |
||
424 | { |
||
425 | $this->transferDate = $transferDate; |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * Returns the transferErrorCode |
||
430 | * |
||
431 | * @var integer |
||
432 | */ |
||
433 | public function getTransferErrorCode() |
||
434 | { |
||
435 | return $this->transferErrorCode; |
||
436 | } |
||
437 | |||
438 | /** |
||
439 | * Sets the transferErrorCode |
||
440 | * |
||
441 | * @param integer $transferErrorCode |
||
442 | * @return void |
||
443 | */ |
||
444 | public function setTransferErrorCode($transferErrorCode) |
||
445 | { |
||
446 | $this->transferErrorCode = $transferErrorCode; |
||
|
|||
447 | } |
||
448 | |||
449 | /** |
||
450 | * Returns the transferResponse |
||
451 | * |
||
452 | * @var string |
||
453 | */ |
||
454 | public function getTransferResponse() |
||
455 | { |
||
456 | return $this->transferResponse; |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * Sets the transferResponse |
||
461 | * |
||
462 | * @param string $transferResponse |
||
463 | * @return void |
||
464 | */ |
||
465 | public function setTransferResponse($transferResponse) |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * Returns the transferHttpStatus |
||
472 | * |
||
473 | * @var integer |
||
474 | */ |
||
475 | public function getTransferHttpStatus() |
||
476 | { |
||
477 | return $this->transferHttpStatus; |
||
478 | } |
||
479 | |||
480 | /** |
||
481 | * Sets the transferHttpStatus |
||
482 | * |
||
483 | * @param integer $transferHttpStatus |
||
484 | * @return void |
||
485 | */ |
||
486 | public function setTransferHttpStatus($transferHttpStatus) |
||
487 | { |
||
488 | $this->transferHttpStatus = $transferHttpStatus; |
||
489 | } |
||
490 | |||
491 | /** |
||
492 | * Adds a File |
||
493 | * |
||
494 | * @param \EWW\Dpf\Domain\Model\File $file |
||
495 | * @return void |
||
496 | */ |
||
497 | public function addFile(\EWW\Dpf\Domain\Model\File $file) |
||
498 | { |
||
499 | $this->file->attach($file); |
||
500 | } |
||
501 | |||
502 | /** |
||
503 | * Removes a File |
||
504 | * |
||
505 | * @param \EWW\Dpf\Domain\Model\File $fileToRemove The File to be removed |
||
506 | * @return void |
||
507 | */ |
||
508 | public function removeFile(\EWW\Dpf\Domain\Model\File $fileToRemove) |
||
509 | { |
||
510 | $this->file->detach($fileToRemove); |
||
511 | } |
||
512 | |||
513 | /** |
||
514 | * Returns the file |
||
515 | * |
||
516 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\File> $file |
||
517 | */ |
||
518 | public function getFile() |
||
519 | { |
||
520 | return $this->file; |
||
521 | } |
||
522 | |||
523 | /** |
||
524 | * Sets the file |
||
525 | * |
||
526 | * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EWW\Dpf\Domain\Model\File> $file |
||
527 | * @return void |
||
528 | */ |
||
529 | public function setFile(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $file) |
||
530 | { |
||
531 | $this->file = $file; |
||
532 | } |
||
533 | |||
534 | /** |
||
535 | * Get File Data |
||
536 | * |
||
537 | * @return array |
||
538 | */ |
||
539 | public function getFileData() |
||
540 | { |
||
541 | |||
542 | $fileId = new \EWW\Dpf\Services\Transfer\FileId($this); |
||
543 | |||
544 | $files = array(); |
||
545 | |||
546 | if (is_a($this->getFile(), '\TYPO3\CMS\Extbase\Persistence\ObjectStorage')) { |
||
547 | foreach ($this->getFile() as $file) { |
||
548 | |||
549 | if (!$file->isFileGroupDeleted()) { |
||
550 | |||
551 | $tmpFile = array( |
||
552 | 'path' => $file->getUrl(), |
||
553 | 'type' => $file->getContentType(), |
||
554 | 'title' => (($file->getLabel()) ? $file->getLabel() : $file->getTitle()), |
||
555 | 'download' => $file->getDownload(), |
||
556 | 'archive' => $file->getArchive(), |
||
557 | 'use' => '', |
||
558 | 'id' => null, |
||
559 | 'hasFLocat' => ($file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_ADDED || |
||
560 | $file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_CHANGED), |
||
561 | ); |
||
562 | |||
563 | $grpUSE = ($file->getDownload()) ? 'download' : 'original'; |
||
564 | |||
565 | if ($file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_DELETED) { |
||
566 | $dataStreamIdentifier = $file->getDatastreamIdentifier(); |
||
567 | if (!empty($dataStreamIdentifier)) { |
||
568 | $tmpFile['id'] = $file->getDatastreamIdentifier(); |
||
569 | $tmpFile['use'] = 'DELETE'; |
||
570 | $files[$grpUSE][$file->getUid()] = $tmpFile; |
||
571 | } |
||
572 | } else { |
||
573 | $tmpFile['id'] = $fileId->getId($file); |
||
574 | $tmpFile['use'] = ($file->getArchive()) ? 'ARCHIVE' : ''; |
||
575 | $files[$grpUSE][$file->getUid()] = $tmpFile; |
||
576 | } |
||
577 | } |
||
578 | |||
579 | } |
||
580 | } |
||
581 | |||
582 | return $files; |
||
583 | } |
||
584 | |||
585 | /** |
||
586 | * Get Current File Data |
||
587 | * |
||
588 | * @return array |
||
589 | */ |
||
590 | public function getCurrentFileData() |
||
591 | { |
||
592 | |||
593 | $fileId = new \EWW\Dpf\Services\Transfer\FileId($this); |
||
594 | |||
595 | $files = array(); |
||
596 | |||
597 | if (is_a($this->getFile(), '\TYPO3\CMS\Extbase\Persistence\ObjectStorage')) { |
||
598 | foreach ($this->getFile() as $file) { |
||
599 | |||
600 | $tmpFile = array( |
||
601 | 'path' => $file->getUrl(), |
||
602 | 'type' => $file->getContentType(), |
||
603 | 'title' => (($file->getLabel()) ? $file->getLabel() : $file->getTitle()), |
||
604 | 'download' => $file->getDownload(), |
||
605 | 'archive' => $file->getArchive(), |
||
606 | 'use' => '', |
||
607 | 'id' => null, |
||
608 | 'hasFLocat' => ($file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_ADDED || |
||
609 | $file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_CHANGED), |
||
610 | ); |
||
611 | |||
612 | $grpUSE = ($file->getDownload()) ? 'download' : 'original'; |
||
613 | |||
614 | if ($file->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_DELETED) { |
||
615 | $dataStreamIdentifier = $file->getDatastreamIdentifier(); |
||
616 | if (!empty($dataStreamIdentifier)) { |
||
617 | $tmpFile['id'] = $file->getDatastreamIdentifier(); |
||
618 | $tmpFile['use'] = 'DELETE'; |
||
619 | $files[$grpUSE][$file->getUid()] = $tmpFile; |
||
620 | } |
||
621 | } else { |
||
622 | $tmpFile['id'] = $fileId->getId($file); |
||
623 | $tmpFile['use'] = ($file->getArchive()) ? 'ARCHIVE' : ''; |
||
624 | $files[$grpUSE][$file->getUid()] = $tmpFile; |
||
625 | } |
||
626 | |||
627 | } |
||
628 | } |
||
629 | |||
630 | return $files; |
||
631 | |||
632 | } |
||
633 | |||
634 | /** |
||
635 | * Returns the changed |
||
636 | * |
||
637 | * @return boolean $changed |
||
638 | */ |
||
639 | public function getChanged() |
||
640 | { |
||
641 | return $this->changed; |
||
642 | } |
||
643 | |||
644 | /** |
||
645 | * Sets the changed |
||
646 | * |
||
647 | * @param boolean $changed |
||
648 | * @return void |
||
649 | */ |
||
650 | public function setChanged($changed) |
||
651 | { |
||
652 | $this->changed = boolval($changed); |
||
653 | } |
||
654 | |||
655 | /** |
||
656 | * Returns the valid |
||
657 | * |
||
658 | * @return boolean $valid |
||
659 | */ |
||
660 | public function getValid() |
||
661 | { |
||
662 | return $this->valid; |
||
663 | } |
||
664 | |||
665 | /** |
||
666 | * Sets the valid |
||
667 | * |
||
668 | * @param boolean $valid |
||
669 | * @return void |
||
670 | */ |
||
671 | public function setValid($valid) |
||
672 | { |
||
673 | $this->valid = boolval($valid); |
||
674 | } |
||
675 | |||
676 | /** |
||
677 | * Gets the Issue Date |
||
678 | * |
||
679 | * @return string |
||
680 | */ |
||
681 | public function getDateIssued() |
||
682 | { |
||
683 | return empty($this->dateIssued) ? '' : $this->dateIssued; |
||
684 | } |
||
685 | |||
686 | /** |
||
687 | * Sets the Issue Date |
||
688 | * |
||
689 | * @param string $dateIssued |
||
690 | * @return void |
||
691 | */ |
||
692 | public function setDateIssued($dateIssued) |
||
693 | { |
||
694 | $this->dateIssued = empty($dateIssued) ? '' : $dateIssued; |
||
695 | } |
||
696 | |||
697 | |||
698 | /** |
||
699 | * Returns the process number |
||
700 | * |
||
701 | * @return string |
||
702 | */ |
||
703 | public function getProcessNumber() |
||
704 | { |
||
705 | return $this->processNumber; |
||
706 | } |
||
707 | |||
708 | /** |
||
709 | * Sets the process number |
||
710 | * |
||
711 | * @param string $processNumber |
||
712 | * @return void |
||
713 | */ |
||
714 | public function setProcessNumber($processNumber) |
||
715 | { |
||
716 | $this->processNumber = trim($processNumber); |
||
717 | } |
||
718 | |||
719 | /** |
||
720 | * Gets the submitter name of the document |
||
721 | * |
||
722 | * @return string |
||
723 | */ |
||
724 | public function getSubmitterName() |
||
725 | { |
||
726 | try { |
||
727 | $internalFormat = new InternalFormat($this->getXmlData(), $this->getPid()); |
||
728 | return $internalFormat->getSubmitterName(); |
||
729 | } catch (\Exception $exception) { |
||
730 | return ""; |
||
731 | } |
||
732 | } |
||
733 | |||
734 | /** |
||
735 | * Gets the primary urn of the document |
||
736 | * |
||
737 | * @return string |
||
738 | */ |
||
739 | public function getPrimaryUrn() |
||
740 | { |
||
741 | $internalFormat = new InternalFormat($this->getXmlData(), $this->getPid()); |
||
742 | return $internalFormat->getPrimaryUrn(); |
||
743 | } |
||
744 | |||
745 | /** |
||
746 | * Returns the creator feuser uid |
||
747 | * |
||
748 | * @return int |
||
749 | */ |
||
750 | public function getCreator() |
||
751 | { |
||
752 | return $this->creator? $this->creator : 0; |
||
753 | } |
||
754 | |||
755 | /** |
||
756 | * Sets the creator feuser uid |
||
757 | * |
||
758 | * @param int $creator |
||
759 | * @return void |
||
760 | */ |
||
761 | public function setCreator($creator) |
||
762 | { |
||
763 | $this->creator = $creator; |
||
764 | } |
||
765 | |||
766 | public function getState() |
||
767 | { |
||
768 | return $this->state; |
||
769 | } |
||
770 | |||
771 | public function setState($state) |
||
772 | { |
||
773 | $this->stateChange = $this->state != $state; |
||
774 | $this->state = $state; |
||
775 | } |
||
776 | |||
777 | public function getRemoteState() |
||
778 | { |
||
779 | $state = explode(':', $this->state); |
||
780 | if (is_array($state) && array_key_exists(1, $state)) { |
||
781 | return $state[1]; |
||
782 | } |
||
783 | return DocumentWorkflow::REMOTE_STATE_NONE; |
||
784 | } |
||
785 | |||
786 | public function getLocalState() { |
||
787 | $state = explode(':', $this->state); |
||
788 | if (is_array($state) && array_key_exists(0, $state)) { |
||
789 | return $state[0]; |
||
790 | } |
||
791 | return DocumentWorkflow::LOCAL_STATE_NONE; |
||
792 | } |
||
793 | |||
794 | /** |
||
795 | * Returns if a document is a temporary document. |
||
796 | * |
||
797 | * @return boolean $temporary |
||
798 | */ |
||
799 | public function isTemporary() { |
||
800 | return $this->temporary; |
||
801 | } |
||
802 | |||
803 | /** |
||
804 | * Sets if a document is a temporary document or not. |
||
805 | * |
||
806 | * @param boolean $temporary |
||
807 | * @return void |
||
808 | */ |
||
809 | public function setTemporary($temporary) { |
||
810 | $this->temporary = boolval($temporary); |
||
811 | } |
||
812 | |||
813 | /** |
||
814 | * @return string |
||
815 | */ |
||
816 | public function getRemoteLastModDate() |
||
817 | { |
||
818 | return $this->remoteLastModDate; |
||
819 | } |
||
820 | |||
821 | /** |
||
822 | * @param string $remoteLastModDate |
||
823 | * @return void |
||
824 | */ |
||
825 | public function setRemoteLastModDate($remoteLastModDate) |
||
826 | { |
||
827 | $this->remoteLastModDate = $remoteLastModDate; |
||
828 | } |
||
829 | |||
830 | /** |
||
831 | * @return integer |
||
832 | */ |
||
833 | public function getTstamp() |
||
834 | { |
||
835 | return $this->tstamp; |
||
836 | } |
||
837 | |||
838 | /** |
||
839 | * @return integer |
||
840 | */ |
||
841 | public function getPid() |
||
842 | { |
||
843 | return $this->pid; |
||
844 | } |
||
845 | |||
846 | /** |
||
847 | * @return bool |
||
848 | */ |
||
849 | public function isSuggestion(): bool |
||
850 | { |
||
851 | return $this->suggestion; |
||
852 | } |
||
853 | |||
854 | /** |
||
855 | * @param bool $suggestion |
||
856 | */ |
||
857 | public function setSuggestion(bool $suggestion) |
||
858 | { |
||
859 | $this->suggestion = boolval($suggestion); |
||
860 | } |
||
861 | |||
862 | /** |
||
863 | * @return string |
||
864 | */ |
||
865 | public function getLinkedUid(): string |
||
866 | { |
||
867 | return $this->linkedUid; |
||
868 | } |
||
869 | |||
870 | /** |
||
871 | * @param string $linkedUid |
||
872 | */ |
||
873 | public function setLinkedUid(string $linkedUid) |
||
874 | { |
||
875 | $this->linkedUid = $linkedUid; |
||
876 | } |
||
877 | |||
878 | /** |
||
879 | * @return string |
||
880 | */ |
||
881 | public function getComment(): string |
||
882 | { |
||
883 | return $this->comment; |
||
884 | } |
||
885 | |||
886 | /** |
||
887 | * @param string $comment |
||
888 | */ |
||
889 | public function setComment(string $comment) |
||
890 | { |
||
891 | $this->comment = $comment; |
||
892 | } |
||
893 | |||
894 | /** |
||
895 | * Copies the data of the given document object into the current document object. |
||
896 | * |
||
897 | * @param Document $documentToCopy |
||
898 | * @return $this |
||
899 | * @throws \TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException |
||
900 | */ |
||
901 | public function copy(Document $documentToCopy) { |
||
902 | $availableProperties = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettablePropertyNames($documentToCopy); |
||
903 | $newDocument = $this; |
||
904 | |||
905 | foreach ($availableProperties as $propertyName) { |
||
906 | if (\TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($newDocument, $propertyName) |
||
907 | && !in_array($propertyName, array('uid','pid', 'file', 'comment', 'linkedUid', 'suggestion', 'creator'))) { |
||
908 | |||
909 | $propertyValue = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($documentToCopy, $propertyName); |
||
910 | \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($newDocument, $propertyName, $propertyValue); |
||
911 | } |
||
912 | } |
||
913 | |||
914 | return $this; |
||
915 | } |
||
916 | |||
917 | public function getNotes() { |
||
918 | $internalFormat = new InternalFormat($this->getXmlData(), $this->getPid()); |
||
919 | return $internalFormat->getNotes(); |
||
920 | } |
||
921 | |||
922 | /** |
||
923 | * Gets the document Identifier |
||
924 | * |
||
925 | * @return string|int |
||
926 | */ |
||
927 | public function getDocumentIdentifier() |
||
928 | { |
||
929 | return $this->getObjectIdentifier()? $this->getObjectIdentifier() : $this->getUid(); |
||
930 | } |
||
931 | |||
932 | /** |
||
933 | * Returns if a document is a working copy of a published document. |
||
934 | * |
||
935 | * @return bool |
||
936 | */ |
||
937 | public function isWorkingCopy() |
||
938 | { |
||
939 | return $this->getObjectIdentifier() && !$this->isTemporary() && !$this->isSuggestion(); |
||
940 | } |
||
941 | |||
942 | |||
943 | /** |
||
944 | * Returns if a document is a temporary copy of a published document. |
||
945 | * |
||
946 | * @return bool |
||
947 | */ |
||
948 | public function isTemporaryCopy() |
||
949 | { |
||
950 | return $this->getObjectIdentifier() && $this->isTemporary() && !$this->isSuggestion(); |
||
951 | } |
||
952 | |||
953 | |||
954 | /** |
||
955 | * Gets the publication year out of the mods-xml data. |
||
956 | * |
||
957 | * @return string|null |
||
958 | */ |
||
959 | public function getPublicationYear() |
||
960 | { |
||
961 | $internalFormat = new InternalFormat($this->getXmlData(), $this->getPid()); |
||
962 | $year = $internalFormat->getPublishingYear(); |
||
963 | return $year? $year : ""; |
||
964 | } |
||
965 | |||
966 | /** |
||
967 | * Gets the source information out of the mods-xml data. |
||
968 | * |
||
969 | * @return string|null |
||
970 | */ |
||
971 | public function getSourceDetails() |
||
976 | } |
||
977 | |||
978 | /** |
||
979 | * @return \DateTime|null |
||
980 | */ |
||
981 | public function getEmbargoDate(): ?\DateTime |
||
982 | { |
||
983 | return $this->embargoDate; |
||
984 | } |
||
985 | |||
986 | /** |
||
987 | * @param \DateTime|null $embargoDate |
||
988 | */ |
||
989 | public function setEmbargoDate(?\DateTime $embargoDate) |
||
992 | } |
||
993 | |||
994 | /** |
||
995 | * @return array |
||
996 | */ |
||
997 | public function getNewlyAssignedFobIdentifiers(): array |
||
998 | { |
||
999 | return $this->newlyAssignedFobIdentifiers; |
||
1000 | } |
||
1001 | |||
1002 | /** |
||
1003 | * @param array newlyAssignedFobIdentifiers |
||
1004 | */ |
||
1005 | public function setNewlyAssignedFobIdentifiers(array $newlyAssignedFobIdentifiers): void |
||
1006 | { |
||
1007 | $this->newlyAssignedFobIdentifiers = $newlyAssignedFobIdentifiers; |
||
1008 | } |
||
1009 | |||
1010 | /** |
||
1011 | * @return array |
||
1012 | */ |
||
1013 | public function getPreviouslyAssignedFobIdentifiers() |
||
1014 | { |
||
1015 | return array_diff( |
||
1016 | $this->getAssignedFobIdentifiers(), $this->getNewlyAssignedFobIdentifiers() |
||
1017 | ); |
||
1018 | } |
||
1019 | |||
1020 | /** |
||
1021 | * @return array |
||
1022 | */ |
||
1023 | public function getAssignedFobIdentifiers(): array |
||
1024 | { |
||
1025 | $internalFormat = new InternalFormat($this->getXmlData(), $this->getPid()); |
||
1026 | return $internalFormat->getPersonFisIdentifiers(); |
||
1027 | } |
||
1028 | |||
1029 | /** |
||
1030 | * @return bool |
||
1031 | */ |
||
1032 | public function isStateChange(): bool |
||
1033 | { |
||
1034 | return $this->stateChange; |
||
1035 | } |
||
1036 | |||
1037 | /** |
||
1038 | * @return mixed |
||
1039 | */ |
||
1040 | public function getDepositLicense() |
||
1045 | } |
||
1046 | |||
1047 | /** |
||
1048 | * @return string |
||
1049 | */ |
||
1050 | public function getCreationDate(): string |
||
1051 | { |
||
1052 | if ( |
||
1053 | $this->getRemoteState() == DocumentWorkflow::REMOTE_STATE_NONE |
||
1054 | && empty($this->creationDate) |
||
1055 | ) { |
||
1056 | $date = new \DateTime(); |
||
1057 | $date->setTimestamp($this->crdate); |
||
1058 | return $date->format(\DateTimeInterface::RFC3339_EXTENDED); |
||
1059 | } |
||
1060 | |||
1061 | return $this->creationDate; |
||
1062 | } |
||
1063 | |||
1064 | /** |
||
1065 | * @param string $creationDate |
||
1066 | */ |
||
1067 | public function setCreationDate(string $creationDate): void |
||
1068 | { |
||
1069 | $this->creationDate = $creationDate; |
||
1070 | } |
||
1071 | |||
1072 | /** |
||
1073 | * Initializes the creation date with the current date. |
||
1074 | */ |
||
1075 | public function initCreationDate(): void |
||
1079 | } |
||
1080 | |||
1081 | /** |
||
1082 | * @return bool |
||
1083 | */ |
||
1084 | public function isClientChangeable() |
||
1085 | { |
||
1086 | return ( |
||
1087 | in_array( |
||
1088 | $this->getState(), |
||
1089 | [ |
||
1090 | DocumentWorkflow::STATE_REGISTERED_NONE, |
||
1091 | DocumentWorkflow::STATE_IN_PROGRESS_NONE, |
||
1092 | DocumentWorkflow::STATE_POSTPONED_NONE, |
||
1093 | DocumentWorkflow::STATE_DISCARDED_NONE |
||
1094 | ] |
||
1095 | ) && !$this->stateChange |
||
1096 | ); |
||
1097 | } |
||
1098 | } |
||
1099 |