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\Common\IiifManifest; |
17
|
|
|
use Kitodo\Dlf\Domain\Model\Collection; |
18
|
|
|
use Kitodo\Dlf\Domain\Model\Metadata; |
19
|
|
|
use Kitodo\Dlf\Domain\Repository\CollectionRepository; |
20
|
|
|
use Kitodo\Dlf\Domain\Repository\LibraryRepository; |
21
|
|
|
use Kitodo\Dlf\Domain\Repository\MetadataRepository; |
22
|
|
|
use Kitodo\Dlf\Domain\Repository\StructureRepository; |
23
|
|
|
use Ubl\Iiif\Context\IRI; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Controller class for the plugin 'Metadata'. |
27
|
|
|
* |
28
|
|
|
* @author Sebastian Meyer <[email protected]> |
29
|
|
|
* @package TYPO3 |
30
|
|
|
* @subpackage dlf |
31
|
|
|
* @access public |
32
|
|
|
*/ |
33
|
|
|
class MetadataController extends AbstractController |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var CollectionRepository |
37
|
|
|
*/ |
38
|
|
|
protected $collectionRepository; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param CollectionRepository $collectionRepository |
42
|
|
|
*/ |
43
|
|
|
public function injectCollectionRepository(CollectionRepository $collectionRepository) |
44
|
|
|
{ |
45
|
|
|
$this->collectionRepository = $collectionRepository; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var LibraryRepository |
50
|
|
|
*/ |
51
|
|
|
protected $libraryRepository; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param LibraryRepository $libraryRepository |
55
|
|
|
*/ |
56
|
|
|
public function injectLibraryRepository(LibraryRepository $libraryRepository) |
57
|
|
|
{ |
58
|
|
|
$this->libraryRepository = $libraryRepository; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var MetadataRepository |
63
|
|
|
*/ |
64
|
|
|
protected $metadataRepository; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param MetadataRepository $metadataRepository |
68
|
|
|
*/ |
69
|
|
|
public function injectMetadataRepository(MetadataRepository $metadataRepository) |
70
|
|
|
{ |
71
|
|
|
$this->metadataRepository = $metadataRepository; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var StructureRepository |
76
|
|
|
*/ |
77
|
|
|
protected $structureRepository; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param StructureRepository $structureRepository |
81
|
|
|
*/ |
82
|
|
|
public function injectStructureRepository(StructureRepository $structureRepository) |
83
|
|
|
{ |
84
|
|
|
$this->structureRepository = $structureRepository; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string|void |
89
|
|
|
*/ |
90
|
|
|
public function mainAction() |
91
|
|
|
{ |
92
|
|
|
$this->cObj = $this->configurationManager->getContentObject(); |
|
|
|
|
93
|
|
|
|
94
|
|
|
// Load current document. |
95
|
|
|
$this->loadDocument($this->requestData); |
96
|
|
|
if ( |
97
|
|
|
$this->document === null |
98
|
|
|
|| $this->document->getDoc() === null |
99
|
|
|
) { |
100
|
|
|
// Quit without doing anything if required variables are not set. |
101
|
|
|
return ''; |
102
|
|
|
} else { |
103
|
|
|
// Set default values if not set. |
104
|
|
|
if (!isset($this->settings['rootline'])) { |
105
|
|
|
$this->settings['rootline'] = 0; |
106
|
|
|
} |
107
|
|
|
if (!isset($this->settings['originalIiifMetadata'])) { |
108
|
|
|
$this->settings['originalIiifMetadata'] = 0; |
109
|
|
|
} |
110
|
|
|
if (!isset($this->settings['displayIiifDescription'])) { |
111
|
|
|
$this->settings['displayIiifDescription'] = 1; |
112
|
|
|
} |
113
|
|
|
if (!isset($this->settings['displayIiifRights'])) { |
114
|
|
|
$this->settings['displayIiifRights'] = 1; |
115
|
|
|
} |
116
|
|
|
if (!isset($this->settings['displayIiifLinks'])) { |
117
|
|
|
$this->settings['displayIiifLinks'] = 1; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
$useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->document->getDoc() instanceof IiifManifest; |
121
|
|
|
$metadata = []; |
122
|
|
|
if ($this->settings['rootline'] < 2) { |
123
|
|
|
// Get current structure's @ID. |
124
|
|
|
$ids = []; |
125
|
|
|
if (!empty($this->document->getDoc()->physicalStructure[$this->requestData['page']]) && !empty($this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]])) { |
126
|
|
|
foreach ($this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]] as $logId) { |
127
|
|
|
$count = $this->document->getDoc()->getStructureDepth($logId); |
128
|
|
|
$ids[$count][] = $logId; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
ksort($ids); |
132
|
|
|
reset($ids); |
133
|
|
|
// Check if we should display all metadata up to the root. |
134
|
|
|
if ($this->settings['rootline'] == 1) { |
135
|
|
|
foreach ($ids as $id) { |
136
|
|
|
foreach ($id as $sid) { |
137
|
|
|
if ($useOriginalIiifManifestMetadata) { |
138
|
|
|
$data = $this->document->getDoc()->getManifestMetadata($sid, $this->settings['storagePid']); |
139
|
|
|
} else { |
140
|
|
|
$data = $this->document->getDoc()->getMetadata($sid, $this->settings['storagePid']); |
141
|
|
|
} |
142
|
|
|
if (!empty($data)) { |
143
|
|
|
$data['_id'] = $sid; |
144
|
|
|
$metadata[] = $data; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
} else { |
149
|
|
|
$id = array_pop($ids); |
150
|
|
|
if (is_array($id)) { |
151
|
|
|
foreach ($id as $sid) { |
152
|
|
|
if ($useOriginalIiifManifestMetadata) { |
153
|
|
|
$data = $this->document->getDoc()->getManifestMetadata($sid, $this->settings['storagePid']); |
154
|
|
|
} else { |
155
|
|
|
$data = $this->document->getDoc()->getMetadata($sid, $this->settings['storagePid']); |
156
|
|
|
} |
157
|
|
|
if (!empty($data)) { |
158
|
|
|
$data['_id'] = $sid; |
159
|
|
|
$metadata[] = $data; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
// Get titledata? |
166
|
|
|
if (empty($metadata) || ($this->settings['rootline'] == 1 && $metadata[0]['_id'] != $this->document->getDoc()->toplevelId)) { |
167
|
|
|
$data = $useOriginalIiifManifestMetadata ? $this->document->getDoc()->getManifestMetadata($this->document->getDoc()->toplevelId, $this->settings['storagePid']) : $this->document->getDoc()->getTitleData($this->settings['storagePid']); |
|
|
|
|
168
|
|
|
$data['_id'] = $this->document->getDoc()->toplevelId; |
169
|
|
|
array_unshift($metadata, $data); |
170
|
|
|
} |
171
|
|
|
if (empty($metadata)) { |
172
|
|
|
$this->logger->warning('No metadata found for document with UID ' . $this->document->getUid()); |
173
|
|
|
return ''; |
174
|
|
|
} |
175
|
|
|
ksort($metadata); |
176
|
|
|
// Get hook objects. |
177
|
|
|
$this->hookObjects = Helper::getHookObjects($this->scriptRelPath); |
|
|
|
|
178
|
|
|
// Hook for getting a customized title bar (requested by SBB). |
179
|
|
|
foreach ($this->hookObjects as $hookObj) { |
180
|
|
|
if (method_exists($hookObj, 'main_customizeTitleBarGetCustomTemplate')) { |
181
|
|
|
$hookObj->main_customizeTitleBarGetCustomTemplate($this, $metadata); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
$this->printMetadata($metadata, $useOriginalIiifManifestMetadata); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Prepares the metadata array for output |
189
|
|
|
* |
190
|
|
|
* @access protected |
191
|
|
|
* |
192
|
|
|
* @param array $metadataArray: The metadata array |
193
|
|
|
* @param bool $useOriginalIiifManifestMetadata: Output IIIF metadata as simple key/value pairs? |
194
|
|
|
* |
195
|
|
|
* @return string The metadata array ready for output |
196
|
|
|
*/ |
197
|
|
|
protected function printMetadata(array $metadataArray, $useOriginalIiifManifestMetadata = false) |
198
|
|
|
{ |
199
|
|
|
if ($useOriginalIiifManifestMetadata) { |
200
|
|
|
$iiifData = []; |
201
|
|
|
foreach ($metadataArray as $metadata) { |
202
|
|
|
foreach ($metadata as $key => $group) { |
203
|
|
|
if ($key == '_id') { |
204
|
|
|
continue; |
205
|
|
|
} |
206
|
|
|
if (!is_array($group)) { |
207
|
|
|
if ( |
208
|
|
|
IRI::isAbsoluteIri($group) |
209
|
|
|
&& (($scheme = (new IRI($group))->getScheme()) == 'http' || $scheme == 'https') |
210
|
|
|
) { |
211
|
|
|
// Build link |
212
|
|
|
$iiifData[$key] = [ |
213
|
|
|
'label' => $key, |
214
|
|
|
'value' => $group, |
215
|
|
|
'buildUrl' => true, |
216
|
|
|
]; |
217
|
|
|
} else { |
218
|
|
|
// Data output |
219
|
|
|
$iiifData[$key] = [ |
220
|
|
|
'label' => $key, |
221
|
|
|
'value' => $group, |
222
|
|
|
'buildUrl' => false, |
223
|
|
|
]; |
224
|
|
|
} |
225
|
|
|
} else { |
226
|
|
|
foreach ($group as $label => $value) { |
227
|
|
|
if ($label == '_id') { |
228
|
|
|
continue; |
229
|
|
|
} |
230
|
|
|
if (is_array($value)) { |
231
|
|
|
$value = implode($this->settings['separator'], $value); |
232
|
|
|
} |
233
|
|
|
// NOTE: Labels are to be escaped in Fluid template |
234
|
|
|
if (IRI::isAbsoluteIri($value) && (($scheme = (new IRI($value))->getScheme()) == 'http' || $scheme == 'https')) { |
235
|
|
|
$nolabel = $value == $label; |
236
|
|
|
$iiifData[$key]['data'][] = [ |
237
|
|
|
'label' => $nolabel ? '' : $label, |
238
|
|
|
'value' => $value, |
239
|
|
|
'buildUrl' => true, |
240
|
|
|
]; |
241
|
|
|
} else { |
242
|
|
|
$iiifData[$key]['data'][] = [ |
243
|
|
|
'label' => $label, |
244
|
|
|
'value' => $value, |
245
|
|
|
'buildUrl' => false, |
246
|
|
|
]; |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
$this->view->assign('useIiif', true); |
251
|
|
|
$this->view->assign('iiifData', $iiifData); |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
} else { |
255
|
|
|
|
256
|
|
|
// findBySettings also sorts entries by the `sorting` field |
257
|
|
|
$metadataResult = $this->metadataRepository->findBySettings([ |
258
|
|
|
'is_listed' => !$this->settings['showFull'], |
259
|
|
|
]); |
260
|
|
|
|
261
|
|
|
$buildUrl = []; |
262
|
|
|
$i = 0; |
263
|
|
|
foreach ($metadataArray as $metadataSection) { |
264
|
|
|
foreach ($metadataSection as $metadataName => $metadataValue) { |
265
|
|
|
// NOTE: Labels are to be escaped in Fluid template |
266
|
|
|
|
267
|
|
|
if ($metadataName == 'title') { |
268
|
|
|
// Get title of parent document if needed. |
269
|
|
|
if (empty($metadataValue) && $this->settings['getTitle'] && $this->document->getDoc()->parentId) { |
270
|
|
|
$superiorTitle = Doc::getTitle($this->document->getPartof(), true); |
271
|
|
|
if (!empty($superiorTitle)) { |
272
|
|
|
$metadataArray[$i][$metadataName] = ['[' . $superiorTitle . ']']; |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
if (!empty($metadataValue)) { |
276
|
|
|
$metadataArray[$i][$metadataName][0] = $metadataArray[$i][$metadataName][0]; |
277
|
|
|
// Link title to pageview. |
278
|
|
|
if ($this->settings['linkTitle'] && $metadataSection['_id']) { |
279
|
|
|
$details = $this->document->getDoc()->getLogicalStructure($metadataSection['_id']); |
280
|
|
|
$buildUrl[$i][$metadataName]['buildUrl'] = [ |
281
|
|
|
'id' => $this->document->getUid(), |
282
|
|
|
'page' => (!empty($details['points']) ? intval($details['points']) : 1), |
283
|
|
|
'targetPid' => (!empty($this->settings['targetPid']) ? $this->settings['targetPid'] : 0), |
284
|
|
|
]; |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
} elseif ($metadataName == 'owner' && !empty($metadataValue)) { |
288
|
|
|
// Translate name of holding library. |
289
|
|
|
$library = $this->libraryRepository->findOneByIndexName($metadataArray[$i][$metadataName][0]); |
|
|
|
|
290
|
|
|
$metadataArray[$i][$metadataName][0] = $library->getLabel(); |
|
|
|
|
291
|
|
|
} elseif ($metadataName == 'type' && !empty($metadataValue)) { |
292
|
|
|
// Translate document type. |
293
|
|
|
$structure = $this->structureRepository->findOneByIndexName($metadataArray[$i][$metadataName][0]); |
|
|
|
|
294
|
|
|
$metadataArray[$i][$metadataName][0] = $structure->getLabel(); |
295
|
|
|
} elseif ($metadataName == 'collection' && !empty($metadataValue)) { |
296
|
|
|
// Check if collections isn't hidden. |
297
|
|
|
$j = 0; |
298
|
|
|
foreach ($metadataValue as $metadataEntry) { |
299
|
|
|
$collection = $this->collectionRepository->findOneByIndexName($metadataEntry); |
|
|
|
|
300
|
|
|
$metadataArray[$i][$metadataName][$j] = $collection->getLabel() ? : ''; |
301
|
|
|
$j++; |
302
|
|
|
} |
303
|
|
|
} elseif ($metadataName == 'language' && !empty($metadataValue)) { |
304
|
|
|
// Translate ISO 639 language code. |
305
|
|
|
$metadataArray[$i][$metadataName][0] = Helper::getLanguageName($metadataArray[$i][$metadataName][0]); |
306
|
|
|
} elseif (!empty($metadataValue)) { |
307
|
|
|
$metadataArray[$i][$metadataName][0] = $metadataArray[$i][$metadataName][0]; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
if (is_array($metadataArray[$i][$metadataName])) { |
311
|
|
|
$metadataArray[$i][$metadataName] = array_values(array_filter($metadataArray[$i][$metadataName], function($value) |
312
|
|
|
{ |
313
|
|
|
return !empty($value); |
314
|
|
|
})); |
315
|
|
|
} |
316
|
|
|
} |
317
|
|
|
$i++; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
$this->view->assign('buildUrl', $buildUrl); |
321
|
|
|
$this->view->assign('documentMetadataSections', $metadataArray); |
322
|
|
|
$this->view->assign('configMetadata', $metadataResult); |
323
|
|
|
$this->view->assign('separator', $this->settings['separator']); |
324
|
|
|
|
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
|