|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU General Public License version 3 or later. |
|
8
|
|
|
* For the full copyright and license information, please read the |
|
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Kitodo\Dlf\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Kitodo\Dlf\Common\Doc; |
|
15
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
16
|
|
|
use Kitodo\Dlf\Domain\Model\Document; |
|
17
|
|
|
use Kitodo\Dlf\Domain\Repository\DocumentRepository; |
|
18
|
|
|
use Psr\Log\LoggerAwareInterface; |
|
19
|
|
|
use Psr\Log\LoggerAwareTrait; |
|
20
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
21
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
|
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
23
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* |
|
28
|
|
|
*/ |
|
29
|
|
|
abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController implements LoggerAwareInterface |
|
30
|
|
|
{ |
|
31
|
|
|
use LoggerAwareTrait; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var DocumentRepository |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $documentRepository; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param DocumentRepository $documentRepository |
|
40
|
|
|
*/ |
|
41
|
|
|
public function injectDocumentRepository(DocumentRepository $documentRepository) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->documentRepository = $documentRepository; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $extConf; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* This holds the current document |
|
53
|
|
|
* |
|
54
|
|
|
* @var \Kitodo\Dlf\Domain\Model\Document |
|
55
|
|
|
* @access protected |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $document; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Loads the current document into $this->doc |
|
61
|
|
|
* |
|
62
|
|
|
* @access protected |
|
63
|
|
|
* |
|
64
|
|
|
* @param array $requestData: The request data |
|
65
|
|
|
* |
|
66
|
|
|
* @return void |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function loadDocument($requestData) |
|
69
|
|
|
{ |
|
70
|
|
|
// Try to get document format from database |
|
71
|
|
|
if (!empty($requestData['id'])) { |
|
72
|
|
|
|
|
73
|
|
|
if (MathUtility::canBeInterpretedAsInteger($requestData['id'])) { |
|
74
|
|
|
// find document from repository by uid |
|
75
|
|
|
$this->document = $this->documentRepository->findByUid((int) $requestData['id']); |
|
76
|
|
|
if ($this->document) { |
|
77
|
|
|
$doc = Doc::getInstance($this->document->getLocation(), $this->settings, true); |
|
78
|
|
|
} |
|
79
|
|
|
} else if (GeneralUtility::isValidUrl($requestData['id'])) { |
|
80
|
|
|
|
|
81
|
|
|
$doc = Doc::getInstance($requestData['id'], $this->settings, true); |
|
82
|
|
|
|
|
83
|
|
|
if ($doc->recordId) { |
|
84
|
|
|
$this->document = $this->documentRepository->findOneByRecordId($doc->recordId); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if ($this->document === null) { |
|
88
|
|
|
// create new dummy Document object |
|
89
|
|
|
$this->document = $this->objectManager->get(Document::class); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if ($this->document) { |
|
93
|
|
|
$this->document->setLocation($requestData['id']); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
if ($this->document !== null && $doc !== null) { |
|
|
|
|
|
|
98
|
|
|
$this->document->setDoc($doc); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} elseif (!empty($requestData['recordId'])) { |
|
102
|
|
|
|
|
103
|
|
|
$this->document = $this->documentRepository->findOneByRecordId($requestData['recordId']); |
|
104
|
|
|
|
|
105
|
|
|
if ($this->document !== null) { |
|
106
|
|
|
$doc = Doc::getInstance($this->document->getLocation(), $this->settings, true); |
|
|
|
|
|
|
107
|
|
|
if ($this->document !== null && $doc !== null) { |
|
108
|
|
|
$this->document->setDoc($doc); |
|
|
|
|
|
|
109
|
|
|
} else { |
|
110
|
|
|
$this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"'); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
} else { |
|
114
|
|
|
$this->logger->error('Invalid UID ' . $requestData['id'] . ' or PID ' . $this->settings['pages'] . ' for document loading'); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Returns the LanguageService |
|
120
|
|
|
* |
|
121
|
|
|
* @return LanguageService |
|
122
|
|
|
*/ |
|
123
|
|
|
protected function getLanguageService(): LanguageService |
|
124
|
|
|
{ |
|
125
|
|
|
return $GLOBALS['LANG']; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|