|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU General Public License version 3 or later. |
|
9
|
|
|
* For the full copyright and license information, please read the |
|
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Hooks; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Hooks and hacks for Kitodo.Production |
|
17
|
|
|
* |
|
18
|
|
|
* @package TYPO3 |
|
19
|
|
|
* @subpackage dlf |
|
20
|
|
|
* |
|
21
|
|
|
* @access public |
|
22
|
|
|
*/ |
|
23
|
|
|
class KitodoProductionHacks |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Hook for \Kitodo\Dlf\Common\MetsDocument::establishRecordId() |
|
27
|
|
|
* When using Kitodo.Production the record identifier is saved only in MODS, but not |
|
28
|
|
|
* in METS. To get it anyway, we have to do some magic. |
|
29
|
|
|
* |
|
30
|
|
|
* @access public |
|
31
|
|
|
* |
|
32
|
|
|
* @param \SimpleXMLElement &$xml The XML object |
|
33
|
|
|
* @param mixed $recordId The record identifier |
|
34
|
|
|
* |
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
|
|
public function postProcessRecordId(\SimpleXMLElement &$xml, &$recordId): void |
|
38
|
|
|
{ |
|
39
|
|
|
if (!$recordId) { |
|
40
|
|
|
$xml->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3'); |
|
41
|
|
|
// Get all logical structure nodes with metadata, but without associated METS-Pointers. |
|
42
|
|
|
if (($divs = $xml->xpath('//mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID and not(./mets:mptr)]'))) { |
|
43
|
|
|
$smLinks = $xml->xpath('//mets:structLink/mets:smLink'); |
|
44
|
|
|
if (!empty($smLinks)) { |
|
45
|
|
|
foreach ($smLinks as $smLink) { |
|
46
|
|
|
$links[(string) $smLink->attributes('http://www.w3.org/1999/xlink')->from][] = (string) $smLink->attributes('http://www.w3.org/1999/xlink')->to; |
|
47
|
|
|
} |
|
48
|
|
|
foreach ($divs as $div) { |
|
49
|
|
|
if (!empty($links[(string) $div['ID']])) { |
|
50
|
|
|
$id = (string) $div['DMDID']; |
|
51
|
|
|
break; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
if (empty($id)) { |
|
56
|
|
|
$id = (string) $divs[0]['DMDID']; |
|
57
|
|
|
} |
|
58
|
|
|
$dmdIds = explode(' ', $id); |
|
59
|
|
|
foreach ($dmdIds as $dmdId) { |
|
60
|
|
|
$recordIds = $xml->xpath('//mets:dmdSec[@ID="' . $dmdId . '"]//mods:mods/mods:recordInfo/mods:recordIdentifier'); |
|
61
|
|
|
if (!empty($recordIds)) { |
|
62
|
|
|
$recordId = (string) $recordIds[0]; |
|
63
|
|
|
break; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|