We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 191 |
| Total Lines | 1122 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like MetsDocument 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 MetsDocument, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 50 | final class MetsDocument extends Doc |
||
| 51 | { |
||
| 52 | /** |
||
| 53 | * This holds the whole XML file as string for serialization purposes |
||
| 54 | * @see __sleep() / __wakeup() |
||
| 55 | * |
||
| 56 | * @var string |
||
| 57 | * @access protected |
||
| 58 | */ |
||
| 59 | protected $asXML = ''; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * This holds the XML file's dmdSec parts with their IDs as array key |
||
| 63 | * |
||
| 64 | * @var array |
||
| 65 | * @access protected |
||
| 66 | */ |
||
| 67 | protected $dmdSec = []; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Are the METS file's dmdSecs loaded? |
||
| 71 | * @see $dmdSec |
||
| 72 | * |
||
| 73 | * @var bool |
||
| 74 | * @access protected |
||
| 75 | */ |
||
| 76 | protected $dmdSecLoaded = false; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * The extension key |
||
| 80 | * |
||
| 81 | * @var string |
||
| 82 | * @access public |
||
| 83 | */ |
||
| 84 | public static $extKey = 'dlf'; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * This holds the file ID -> USE concordance |
||
| 88 | * @see _getFileGrps() |
||
| 89 | * |
||
| 90 | * @var array |
||
| 91 | * @access protected |
||
| 92 | */ |
||
| 93 | protected $fileGrps = []; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Are the image file groups loaded? |
||
| 97 | * @see $fileGrps |
||
| 98 | * |
||
| 99 | * @var bool |
||
| 100 | * @access protected |
||
| 101 | */ |
||
| 102 | protected $fileGrpsLoaded = false; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * This holds the XML file's METS part as \SimpleXMLElement object |
||
| 106 | * |
||
| 107 | * @var \SimpleXMLElement |
||
| 108 | * @access protected |
||
| 109 | */ |
||
| 110 | protected $mets; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * This holds the whole XML file as \SimpleXMLElement object |
||
| 114 | * |
||
| 115 | * @var \SimpleXMLElement |
||
| 116 | * @access protected |
||
| 117 | */ |
||
| 118 | protected $xml; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * This adds metadata from METS structural map to metadata array. |
||
| 122 | * |
||
| 123 | * @access public |
||
| 124 | * |
||
| 125 | * @param array &$metadata: The metadata array to extend |
||
| 126 | * @param string $id: The "@ID" attribute of the logical structure node |
||
| 127 | * |
||
| 128 | * @return void |
||
| 129 | */ |
||
| 130 | public function addMetadataFromMets(&$metadata, $id) |
||
| 131 | { |
||
| 132 | $details = $this->getLogicalStructure($id); |
||
| 133 | if (!empty($details)) { |
||
| 134 | $metadata['mets_order'][0] = $details['order']; |
||
| 135 | $metadata['mets_label'][0] = $details['label']; |
||
| 136 | $metadata['mets_orderlabel'][0] = $details['orderlabel']; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * |
||
| 142 | * {@inheritDoc} |
||
| 143 | * @see \Kitodo\Dlf\Common\Doc::establishRecordId() |
||
| 144 | */ |
||
| 145 | protected function establishRecordId($pid) |
||
| 146 | { |
||
| 147 | // Check for METS object @ID. |
||
| 148 | if (!empty($this->mets['OBJID'])) { |
||
| 149 | $this->recordId = (string) $this->mets['OBJID']; |
||
| 150 | } |
||
| 151 | // Get hook objects. |
||
| 152 | $hookObjects = Helper::getHookObjects('Classes/Common/MetsDocument.php'); |
||
| 153 | // Apply hooks. |
||
| 154 | foreach ($hookObjects as $hookObj) { |
||
| 155 | if (method_exists($hookObj, 'construct_postProcessRecordId')) { |
||
| 156 | $hookObj->construct_postProcessRecordId($this->xml, $this->recordId); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * |
||
| 163 | * {@inheritDoc} |
||
| 164 | * @see \Kitodo\Dlf\Common\Doc::getDownloadLocation() |
||
| 165 | */ |
||
| 166 | public function getDownloadLocation($id) |
||
| 167 | { |
||
| 168 | $fileMimeType = $this->getFileMimeType($id); |
||
| 169 | $fileLocation = $this->getFileLocation($id); |
||
| 170 | if ($fileMimeType === 'application/vnd.kitodo.iiif') { |
||
| 171 | $fileLocation = (strrpos($fileLocation, 'info.json') === strlen($fileLocation) - 9) ? $fileLocation : (strrpos($fileLocation, '/') === strlen($fileLocation) ? $fileLocation . 'info.json' : $fileLocation . '/info.json'); |
||
| 172 | $conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey); |
||
| 173 | IiifHelper::setUrlReader(IiifUrlReader::getInstance()); |
||
| 174 | IiifHelper::setMaxThumbnailHeight($conf['iiifThumbnailHeight']); |
||
| 175 | IiifHelper::setMaxThumbnailWidth($conf['iiifThumbnailWidth']); |
||
| 176 | $service = IiifHelper::loadIiifResource($fileLocation); |
||
| 177 | if ($service !== null && $service instanceof AbstractImageService) { |
||
| 178 | return $service->getImageUrl(); |
||
| 179 | } |
||
| 180 | } elseif ($fileMimeType === 'application/vnd.netfpx') { |
||
| 181 | $baseURL = $fileLocation . (strpos($fileLocation, '?') === false ? '?' : ''); |
||
| 182 | // TODO CVT is an optional IIP server capability; in theory, capabilities should be determined in the object request with '&obj=IIP-server' |
||
| 183 | return $baseURL . '&CVT=jpeg'; |
||
| 184 | } |
||
| 185 | return $fileLocation; |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * {@inheritDoc} |
||
| 190 | * @see \Kitodo\Dlf\Common\Doc::getFileLocation() |
||
| 191 | */ |
||
| 192 | public function getFileLocation($id) |
||
| 193 | { |
||
| 194 | $location = $this->mets->xpath('./mets:fileSec/mets:fileGrp/mets:file[@ID="' . $id . '"]/mets:FLocat[@LOCTYPE="URL"]'); |
||
| 195 | if ( |
||
| 196 | !empty($id) |
||
| 197 | && !empty($location) |
||
| 198 | ) { |
||
| 199 | return (string) $location[0]->attributes('http://www.w3.org/1999/xlink')->href; |
||
| 200 | } else { |
||
| 201 | $this->logger->warning('There is no file node with @ID "' . $id . '"'); |
||
| 202 | return ''; |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | /** |
||
| 207 | * {@inheritDoc} |
||
| 208 | * @see \Kitodo\Dlf\Common\Doc::getFileMimeType() |
||
| 209 | */ |
||
| 210 | public function getFileMimeType($id) |
||
| 221 | } |
||
| 222 | } |
||
| 223 | |||
| 224 | /** |
||
| 225 | * {@inheritDoc} |
||
| 226 | * @see \Kitodo\Dlf\Common\Doc::getLogicalStructure() |
||
| 227 | */ |
||
| 228 | public function getLogicalStructure($id, $recursive = false) |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * This gets details about a logical structure element |
||
| 261 | * |
||
| 262 | * @access protected |
||
| 263 | * |
||
| 264 | * @param \SimpleXMLElement $structure: The logical structure node |
||
| 265 | * @param bool $recursive: Whether to include the child elements |
||
| 266 | * |
||
| 267 | * @return array Array of the element's id, label, type and physical page indexes/mptr link |
||
| 268 | */ |
||
| 269 | protected function getLogicalStructureInfo(\SimpleXMLElement $structure, $recursive = false) |
||
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * {@inheritDoc} |
||
| 366 | * @see \Kitodo\Dlf\Common\Doc::getMetadata() |
||
| 367 | */ |
||
| 368 | public function getMetadata($id, $cPid = 0) |
||
| 587 | } |
||
| 588 | } |
||
| 589 | |||
| 590 | /** |
||
| 591 | * @param array $allResults |
||
| 592 | * @param array $allSubentries |
||
| 593 | * @param array $metadata |
||
| 594 | * @return array |
||
| 595 | */ |
||
| 596 | private function getXPathQueries($dmdId, $allResults, $allSubentries, array $metadata): array |
||
| 597 | { |
||
| 598 | // We need a \DOMDocument here, because SimpleXML doesn't support XPath functions properly. |
||
| 599 | $domNode = dom_import_simplexml($this->dmdSec[$dmdId]['xml']); |
||
| 600 | $domXPath = new \DOMXPath($domNode->ownerDocument); |
||
| 601 | $this->registerNamespaces($domXPath); |
||
| 602 | // OK, now make the XPath queries. |
||
| 603 | foreach ($allResults as $resArray) { |
||
| 604 | // Set metadata field's value(s). |
||
| 605 | if ( |
||
| 606 | $resArray['format'] > 0 |
||
| 607 | && !empty($resArray['xpath']) |
||
| 608 | && ($values = $domXPath->evaluate($resArray['xpath'], $domNode)) |
||
| 609 | ) { |
||
| 610 | if ( |
||
| 611 | $values instanceof \DOMNodeList |
||
| 612 | && $values->length > 0 |
||
| 613 | ) { |
||
| 614 | $metadata[$resArray['index_name']] = []; |
||
| 615 | foreach ($values as $value) { |
||
| 616 | if ($subentries = $this->getSubentries($allSubentries, $resArray['index_name'], $value)) { |
||
| 617 | $metadata[$resArray['index_name']][] = $subentries; |
||
| 618 | } else { |
||
| 619 | $metadata[$resArray['index_name']][] = trim((string)$value->nodeValue); |
||
| 620 | } |
||
| 621 | } |
||
| 622 | } elseif (!($values instanceof \DOMNodeList)) { |
||
| 623 | $metadata[$resArray['index_name']] = [trim((string)$values->nodeValue)]; |
||
| 624 | } |
||
| 625 | } |
||
| 626 | // Set default value if applicable. |
||
| 627 | if ( |
||
| 628 | empty($metadata[$resArray['index_name']][0]) |
||
| 629 | && strlen($resArray['default_value']) > 0 |
||
| 630 | ) { |
||
| 631 | $metadata[$resArray['index_name']] = [$resArray['default_value']]; |
||
| 632 | } |
||
| 633 | // Set sorting value if applicable. |
||
| 634 | if ( |
||
| 635 | !empty($metadata[$resArray['index_name']]) |
||
| 636 | && $resArray['is_sortable'] |
||
| 637 | ) { |
||
| 638 | if ( |
||
| 639 | $resArray['format'] > 0 |
||
| 640 | && !empty($resArray['xpath_sorting']) // TODO: will fail, for subentries |
||
| 641 | && ($values = $domXPath->evaluate($resArray['xpath_sorting'], $domNode)) |
||
| 642 | ) { |
||
| 643 | if ( |
||
| 644 | $values instanceof \DOMNodeList |
||
| 645 | && $values->length > 0 |
||
| 646 | ) { |
||
| 647 | $metadata[$resArray['index_name'] . '_sorting'][0] = trim((string)$values->item(0)->nodeValue); |
||
| 648 | } elseif (!($values instanceof \DOMNodeList)) { |
||
| 649 | $metadata[$resArray['index_name'] . '_sorting'][0] = trim((string)$values); |
||
| 650 | } |
||
| 651 | } |
||
| 652 | if (empty($metadata[$resArray['index_name'] . '_sorting'][0])) { |
||
| 653 | $metadata[$resArray['index_name'] . '_sorting'][0] = $metadata[$resArray['index_name']][0]; |
||
| 654 | } |
||
| 655 | } |
||
| 656 | } |
||
| 657 | // Set title to empty string if not present. |
||
| 658 | if (empty($metadata['title'][0])) { |
||
| 659 | $metadata['title'][0] = ''; |
||
| 660 | $metadata['title_sorting'][0] = ''; |
||
| 661 | } |
||
| 662 | return $metadata; |
||
| 663 | } |
||
| 664 | |||
| 665 | /** |
||
| 666 | * @param array $allSubentries |
||
| 667 | * @param string $parentIndex |
||
| 668 | * @param \DOMNode parentNode |
||
| 669 | * @return array |
||
| 670 | */ |
||
| 671 | private function getSubentries($allSubentries, string $parentIndex, \DOMNode $parentNode) |
||
| 672 | { |
||
| 673 | $domXPath = new \DOMXPath($parentNode->ownerDocument); |
||
| 674 | $this->registerNamespaces($domXPath); |
||
| 675 | $theseSubentries = []; |
||
| 676 | foreach ($allSubentries as $subentry) { |
||
| 677 | if ($subentry['parent_index_name'] == $parentIndex) { |
||
| 678 | if ( |
||
| 679 | !empty($subentry['xpath']) |
||
| 680 | && ($values = $domXPath->evaluate($subentry['xpath'], $parentNode)) |
||
| 681 | ) { |
||
| 682 | if ( |
||
| 683 | $values instanceof \DOMNodeList |
||
| 684 | && $values->length > 0 |
||
| 685 | ) { |
||
| 686 | $theseSubentries[$subentry['index_name']] = []; |
||
| 687 | foreach ($values as $value) { |
||
| 688 | $theseSubentries[$subentry['index_name']][] = trim((string)$value->nodeValue); |
||
| 689 | } |
||
| 690 | } elseif (!($values instanceof \DOMNodeList)) { |
||
| 691 | $theseSubentries[$subentry['index_name']] = [trim((string)$values->nodeValue)]; |
||
| 692 | } |
||
| 693 | } |
||
| 694 | // Set default value if applicable. |
||
| 695 | if ( |
||
| 696 | empty($theseSubentries[$subentry['index_name']][0]) |
||
| 697 | && strlen($subentry['default_value']) > 0 |
||
| 698 | ) { |
||
| 699 | $theseSubentries[$subentry['index_name']] = [$subentry['default_value']]; |
||
| 700 | } |
||
| 701 | } |
||
| 702 | } |
||
| 703 | if (empty($theseSubentries)) { |
||
| 704 | return false; |
||
| 705 | } |
||
| 706 | return $theseSubentries; |
||
| 707 | } |
||
| 708 | |||
| 709 | /** |
||
| 710 | * {@inheritDoc} |
||
| 711 | * @see \Kitodo\Dlf\Common\Doc::getFullText() |
||
| 712 | */ |
||
| 713 | public function getFullText($id) |
||
| 714 | { |
||
| 715 | $fullText = ''; |
||
| 716 | |||
| 717 | // Load fileGrps and check for full text files. |
||
| 718 | $this->_getFileGrps(); |
||
| 719 | if ($this->hasFulltext) { |
||
| 720 | $fullText = $this->getFullTextFromXml($id); |
||
| 721 | } |
||
| 722 | return $fullText; |
||
| 723 | } |
||
| 724 | |||
| 725 | /** |
||
| 726 | * {@inheritDoc} |
||
| 727 | * @see Doc::getStructureDepth() |
||
| 728 | */ |
||
| 729 | public function getStructureDepth($logId) |
||
| 730 | { |
||
| 731 | $ancestors = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="' . $logId . '"]/ancestor::*'); |
||
| 732 | if (!empty($ancestors)) { |
||
| 733 | return count($ancestors); |
||
| 734 | } else { |
||
| 735 | return 0; |
||
| 736 | } |
||
| 737 | } |
||
| 738 | |||
| 739 | /** |
||
| 740 | * {@inheritDoc} |
||
| 741 | * @see \Kitodo\Dlf\Common\Doc::init() |
||
| 742 | */ |
||
| 743 | protected function init($location) |
||
| 744 | { |
||
| 745 | $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(get_class($this)); |
||
| 746 | // Get METS node from XML file. |
||
| 747 | $this->registerNamespaces($this->xml); |
||
| 748 | $mets = $this->xml->xpath('//mets:mets'); |
||
| 749 | if (!empty($mets)) { |
||
| 750 | $this->mets = $mets[0]; |
||
| 751 | // Register namespaces. |
||
| 752 | $this->registerNamespaces($this->mets); |
||
| 753 | } else { |
||
| 754 | if (!empty($location)) { |
||
| 755 | $this->logger->error('No METS part found in document with location "' . $location . '".'); |
||
| 756 | } else if (!empty($this->recordId)) { |
||
| 757 | $this->logger->error('No METS part found in document with recordId "' . $this->recordId . '".'); |
||
| 758 | } else { |
||
| 759 | $this->logger->error('No METS part found in current document.'); |
||
| 760 | } |
||
| 761 | } |
||
| 762 | } |
||
| 763 | |||
| 764 | /** |
||
| 765 | * {@inheritDoc} |
||
| 766 | * @see \Kitodo\Dlf\Common\Doc::loadLocation() |
||
| 767 | */ |
||
| 768 | protected function loadLocation($location) |
||
| 769 | { |
||
| 770 | $fileResource = Helper::getUrl($location); |
||
| 771 | if ($fileResource !== false) { |
||
| 772 | $xml = Helper::getXmlFileAsString($fileResource); |
||
| 773 | // Set some basic properties. |
||
| 774 | if ($xml !== false) { |
||
| 775 | $this->xml = $xml; |
||
| 776 | return true; |
||
| 777 | } |
||
| 778 | } |
||
| 779 | $this->logger->error('Could not load XML file from "' . $location . '"'); |
||
| 780 | return false; |
||
| 781 | } |
||
| 782 | |||
| 783 | /** |
||
| 784 | * {@inheritDoc} |
||
| 785 | * @see \Kitodo\Dlf\Common\Doc::ensureHasFulltextIsSet() |
||
| 786 | */ |
||
| 787 | protected function ensureHasFulltextIsSet() |
||
| 788 | { |
||
| 789 | // Are the fileGrps already loaded? |
||
| 790 | if (!$this->fileGrpsLoaded) { |
||
| 791 | $this->_getFileGrps(); |
||
| 792 | } |
||
| 793 | } |
||
| 794 | |||
| 795 | /** |
||
| 796 | * {@inheritDoc} |
||
| 797 | * @see Doc::setPreloadedDocument() |
||
| 798 | */ |
||
| 799 | protected function setPreloadedDocument($preloadedDocument) |
||
| 800 | { |
||
| 801 | |||
| 802 | if ($preloadedDocument instanceof \SimpleXMLElement) { |
||
| 803 | $this->xml = $preloadedDocument; |
||
| 804 | return true; |
||
| 805 | } |
||
| 806 | return false; |
||
| 807 | } |
||
| 808 | |||
| 809 | /** |
||
| 810 | * {@inheritDoc} |
||
| 811 | * @see Doc::getDocument() |
||
| 812 | */ |
||
| 813 | protected function getDocument() |
||
| 816 | } |
||
| 817 | |||
| 818 | /** |
||
| 819 | * This builds an array of the document's dmdSecs |
||
| 820 | * |
||
| 821 | * @access protected |
||
| 822 | * |
||
| 823 | * @return array Array of dmdSecs with their IDs as array key |
||
| 824 | */ |
||
| 825 | protected function _getDmdSec() |
||
| 826 | { |
||
| 827 | if (!$this->dmdSecLoaded) { |
||
| 828 | // Get available data formats. |
||
| 829 | $this->loadFormats(); |
||
| 830 | // Get dmdSec nodes from METS. |
||
| 831 | $dmdIds = $this->mets->xpath('./mets:dmdSec/@ID'); |
||
| 832 | if (!empty($dmdIds)) { |
||
| 833 | foreach ($dmdIds as $dmdId) { |
||
| 834 | if ($type = $this->mets->xpath('./mets:dmdSec[@ID="' . (string) $dmdId . '"]/mets:mdWrap[not(@MDTYPE="OTHER")]/@MDTYPE')) { |
||
| 835 | if (!empty($this->formats[(string) $type[0]])) { |
||
| 836 | $type = (string) $type[0]; |
||
| 837 | $xml = $this->mets->xpath('./mets:dmdSec[@ID="' . (string) $dmdId . '"]/mets:mdWrap[@MDTYPE="' . $type . '"]/mets:xmlData/' . strtolower($type) . ':' . $this->formats[$type]['rootElement']); |
||
| 838 | } |
||
| 839 | } elseif ($type = $this->mets->xpath('./mets:dmdSec[@ID="' . (string) $dmdId . '"]/mets:mdWrap[@MDTYPE="OTHER"]/@OTHERMDTYPE')) { |
||
| 840 | if (!empty($this->formats[(string) $type[0]])) { |
||
| 841 | $type = (string) $type[0]; |
||
| 842 | $xml = $this->mets->xpath('./mets:dmdSec[@ID="' . (string) $dmdId . '"]/mets:mdWrap[@MDTYPE="OTHER"][@OTHERMDTYPE="' . $type . '"]/mets:xmlData/' . strtolower($type) . ':' . $this->formats[$type]['rootElement']); |
||
| 843 | } |
||
| 844 | } |
||
| 845 | if (!empty($xml)) { |
||
| 846 | $this->dmdSec[(string) $dmdId]['type'] = $type; |
||
| 847 | $this->dmdSec[(string) $dmdId]['xml'] = $xml[0]; |
||
| 848 | $this->registerNamespaces($this->dmdSec[(string) $dmdId]['xml']); |
||
| 849 | } |
||
| 850 | } |
||
| 851 | } |
||
| 852 | $this->dmdSecLoaded = true; |
||
| 853 | } |
||
| 854 | return $this->dmdSec; |
||
| 855 | } |
||
| 856 | |||
| 857 | /** |
||
| 858 | * This builds the file ID -> USE concordance |
||
| 859 | * |
||
| 860 | * @access protected |
||
| 861 | * |
||
| 862 | * @return array Array of file use groups with file IDs |
||
| 863 | */ |
||
| 864 | protected function _getFileGrps() |
||
| 865 | { |
||
| 866 | if (!$this->fileGrpsLoaded) { |
||
| 867 | // Get configured USE attributes. |
||
| 868 | $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey); |
||
| 869 | $useGrps = GeneralUtility::trimExplode(',', $extConf['fileGrpImages']); |
||
| 870 | if (!empty($extConf['fileGrpThumbs'])) { |
||
| 871 | $useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf['fileGrpThumbs'])); |
||
| 872 | } |
||
| 873 | if (!empty($extConf['fileGrpDownload'])) { |
||
| 874 | $useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf['fileGrpDownload'])); |
||
| 875 | } |
||
| 876 | if (!empty($extConf['fileGrpFulltext'])) { |
||
| 877 | $useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf['fileGrpFulltext'])); |
||
| 878 | } |
||
| 879 | if (!empty($extConf['fileGrpAudio'])) { |
||
| 880 | $useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf['fileGrpAudio'])); |
||
| 881 | } |
||
| 882 | // Get all file groups. |
||
| 883 | $fileGrps = $this->mets->xpath('./mets:fileSec/mets:fileGrp'); |
||
| 884 | if (!empty($fileGrps)) { |
||
| 885 | // Build concordance for configured USE attributes. |
||
| 886 | foreach ($fileGrps as $fileGrp) { |
||
| 887 | if (in_array((string) $fileGrp['USE'], $useGrps)) { |
||
| 888 | foreach ($fileGrp->children('http://www.loc.gov/METS/')->file as $file) { |
||
| 889 | $this->fileGrps[(string) $file->attributes()->ID] = (string) $fileGrp['USE']; |
||
| 890 | } |
||
| 891 | } |
||
| 892 | } |
||
| 893 | } |
||
| 894 | // Are there any fulltext files available? |
||
| 895 | if ( |
||
| 896 | !empty($extConf['fileGrpFulltext']) |
||
| 897 | && array_intersect(GeneralUtility::trimExplode(',', $extConf['fileGrpFulltext']), $this->fileGrps) !== [] |
||
| 898 | ) { |
||
| 899 | $this->hasFulltext = true; |
||
| 900 | } |
||
| 901 | $this->fileGrpsLoaded = true; |
||
| 902 | } |
||
| 903 | return $this->fileGrps; |
||
| 904 | } |
||
| 905 | |||
| 906 | /** |
||
| 907 | * {@inheritDoc} |
||
| 908 | * @see \Kitodo\Dlf\Common\Doc::prepareMetadataArray() |
||
| 909 | */ |
||
| 910 | protected function prepareMetadataArray($cPid) |
||
| 911 | { |
||
| 912 | $ids = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID]/@ID'); |
||
| 913 | // Get all logical structure nodes with metadata. |
||
| 914 | if (!empty($ids)) { |
||
| 915 | foreach ($ids as $id) { |
||
| 916 | $this->metadataArray[(string) $id] = $this->getMetadata((string) $id, $cPid); |
||
| 917 | } |
||
| 918 | } |
||
| 919 | // Set current PID for metadata definitions. |
||
| 920 | } |
||
| 921 | |||
| 922 | /** |
||
| 923 | * This returns $this->mets via __get() |
||
| 924 | * |
||
| 925 | * @access protected |
||
| 926 | * |
||
| 927 | * @return \SimpleXMLElement The XML's METS part as \SimpleXMLElement object |
||
| 928 | */ |
||
| 929 | protected function _getMets() |
||
| 930 | { |
||
| 931 | return $this->mets; |
||
| 932 | } |
||
| 933 | |||
| 934 | /** |
||
| 935 | * {@inheritDoc} |
||
| 936 | * @see \Kitodo\Dlf\Common\Doc::_getPhysicalStructure() |
||
| 937 | */ |
||
| 938 | protected function _getPhysicalStructure() |
||
| 939 | { |
||
| 940 | // Is there no physical structure array yet? |
||
| 941 | if (!$this->physicalStructureLoaded) { |
||
| 942 | // Does the document have a structMap node of type "PHYSICAL"? |
||
| 943 | $elementNodes = $this->mets->xpath('./mets:structMap[@TYPE="PHYSICAL"]/mets:div[@TYPE="physSequence"]/mets:div'); |
||
| 944 | if (!empty($elementNodes)) { |
||
| 945 | // Get file groups. |
||
| 946 | $fileUse = $this->_getFileGrps(); |
||
| 947 | // Get the physical sequence's metadata. |
||
| 948 | $physNode = $this->mets->xpath('./mets:structMap[@TYPE="PHYSICAL"]/mets:div[@TYPE="physSequence"]'); |
||
| 949 | $physSeq[0] = (string) $physNode[0]['ID']; |
||
| 950 | $this->physicalStructureInfo[$physSeq[0]]['id'] = (string) $physNode[0]['ID']; |
||
| 951 | $this->physicalStructureInfo[$physSeq[0]]['dmdId'] = (isset($physNode[0]['DMDID']) ? (string) $physNode[0]['DMDID'] : ''); |
||
| 952 | $this->physicalStructureInfo[$physSeq[0]]['order'] = (isset($physNode[0]['ORDER']) ? (string) $physNode[0]['ORDER'] : ''); |
||
| 953 | $this->physicalStructureInfo[$physSeq[0]]['label'] = (isset($physNode[0]['LABEL']) ? (string) $physNode[0]['LABEL'] : ''); |
||
| 954 | $this->physicalStructureInfo[$physSeq[0]]['orderlabel'] = (isset($physNode[0]['ORDERLABEL']) ? (string) $physNode[0]['ORDERLABEL'] : ''); |
||
| 955 | $this->physicalStructureInfo[$physSeq[0]]['type'] = (string) $physNode[0]['TYPE']; |
||
| 956 | $this->physicalStructureInfo[$physSeq[0]]['contentIds'] = (isset($physNode[0]['CONTENTIDS']) ? (string) $physNode[0]['CONTENTIDS'] : ''); |
||
| 957 | // Get the file representations from fileSec node. |
||
| 958 | foreach ($physNode[0]->children('http://www.loc.gov/METS/')->fptr as $fptr) { |
||
| 959 | // Check if file has valid @USE attribute. |
||
| 960 | if (!empty($fileUse[(string) $fptr->attributes()->FILEID])) { |
||
| 961 | $this->physicalStructureInfo[$physSeq[0]]['files'][$fileUse[(string) $fptr->attributes()->FILEID]] = (string) $fptr->attributes()->FILEID; |
||
| 962 | } |
||
| 963 | } |
||
| 964 | // Build the physical elements' array from the physical structMap node. |
||
| 965 | foreach ($elementNodes as $elementNode) { |
||
| 966 | $elements[(int) $elementNode['ORDER']] = (string) $elementNode['ID']; |
||
| 967 | $this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['id'] = (string) $elementNode['ID']; |
||
| 968 | $this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['dmdId'] = (isset($elementNode['DMDID']) ? (string) $elementNode['DMDID'] : ''); |
||
| 969 | $this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['order'] = (isset($elementNode['ORDER']) ? (string) $elementNode['ORDER'] : ''); |
||
| 970 | $this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['label'] = (isset($elementNode['LABEL']) ? (string) $elementNode['LABEL'] : ''); |
||
| 971 | $this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['orderlabel'] = (isset($elementNode['ORDERLABEL']) ? (string) $elementNode['ORDERLABEL'] : ''); |
||
| 972 | $this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['type'] = (string) $elementNode['TYPE']; |
||
| 973 | $this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['contentIds'] = (isset($elementNode['CONTENTIDS']) ? (string) $elementNode['CONTENTIDS'] : ''); |
||
| 974 | // Get the file representations from fileSec node. |
||
| 975 | foreach ($elementNode->children('http://www.loc.gov/METS/')->fptr as $fptr) { |
||
| 976 | // Check if file has valid @USE attribute. |
||
| 977 | if (!empty($fileUse[(string) $fptr->attributes()->FILEID])) { |
||
| 978 | $this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['files'][$fileUse[(string) $fptr->attributes()->FILEID]] = (string) $fptr->attributes()->FILEID; |
||
| 979 | } |
||
| 980 | } |
||
| 981 | } |
||
| 982 | // Sort array by keys (= @ORDER). |
||
| 983 | if (ksort($elements)) { |
||
| 984 | // Set total number of pages/tracks. |
||
| 985 | $this->numPages = count($elements); |
||
| 986 | // Merge and re-index the array to get nice numeric indexes. |
||
| 987 | $this->physicalStructure = array_merge($physSeq, $elements); |
||
| 988 | } |
||
| 989 | } |
||
| 990 | $this->physicalStructureLoaded = true; |
||
| 991 | } |
||
| 992 | return $this->physicalStructure; |
||
| 993 | } |
||
| 994 | |||
| 995 | /** |
||
| 996 | * {@inheritDoc} |
||
| 997 | * @see \Kitodo\Dlf\Common\Doc::_getSmLinks() |
||
| 998 | */ |
||
| 999 | protected function _getSmLinks() |
||
| 1000 | { |
||
| 1001 | if (!$this->smLinksLoaded) { |
||
| 1002 | $smLinks = $this->mets->xpath('./mets:structLink/mets:smLink'); |
||
| 1003 | if (!empty($smLinks)) { |
||
| 1004 | foreach ($smLinks as $smLink) { |
||
| 1005 | $this->smLinks['l2p'][(string) $smLink->attributes('http://www.w3.org/1999/xlink')->from][] = (string) $smLink->attributes('http://www.w3.org/1999/xlink')->to; |
||
| 1006 | $this->smLinks['p2l'][(string) $smLink->attributes('http://www.w3.org/1999/xlink')->to][] = (string) $smLink->attributes('http://www.w3.org/1999/xlink')->from; |
||
| 1007 | } |
||
| 1008 | } |
||
| 1009 | $this->smLinksLoaded = true; |
||
| 1010 | } |
||
| 1011 | return $this->smLinks; |
||
| 1012 | } |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * {@inheritDoc} |
||
| 1016 | * @see \Kitodo\Dlf\Common\Doc::_getThumbnail() |
||
| 1017 | */ |
||
| 1018 | protected function _getThumbnail($forceReload = false) |
||
| 1019 | { |
||
| 1020 | if ( |
||
| 1021 | !$this->thumbnailLoaded |
||
| 1022 | || $forceReload |
||
| 1023 | ) { |
||
| 1024 | // Retain current PID. |
||
| 1025 | $cPid = ($this->cPid ? $this->cPid : $this->pid); |
||
| 1026 | if (!$cPid) { |
||
| 1027 | $this->logger->error('Invalid PID ' . $cPid . ' for structure definitions'); |
||
| 1028 | $this->thumbnailLoaded = true; |
||
| 1029 | return $this->thumbnail; |
||
| 1030 | } |
||
| 1031 | // Load extension configuration. |
||
| 1032 | $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey); |
||
| 1033 | if (empty($extConf['fileGrpThumbs'])) { |
||
| 1034 | $this->logger->warning('No fileGrp for thumbnails specified'); |
||
| 1035 | $this->thumbnailLoaded = true; |
||
| 1036 | return $this->thumbnail; |
||
| 1037 | } |
||
| 1038 | $strctId = $this->_getToplevelId(); |
||
| 1039 | $metadata = $this->getTitledata($cPid); |
||
| 1040 | |||
| 1041 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 1042 | ->getQueryBuilderForTable('tx_dlf_structures'); |
||
| 1043 | |||
| 1044 | // Get structure element to get thumbnail from. |
||
| 1045 | $result = $queryBuilder |
||
| 1046 | ->select('tx_dlf_structures.thumbnail AS thumbnail') |
||
| 1047 | ->from('tx_dlf_structures') |
||
| 1048 | ->where( |
||
| 1049 | $queryBuilder->expr()->eq('tx_dlf_structures.pid', intval($cPid)), |
||
| 1050 | $queryBuilder->expr()->eq('tx_dlf_structures.index_name', $queryBuilder->expr()->literal($metadata['type'][0])), |
||
| 1051 | Helper::whereExpression('tx_dlf_structures') |
||
| 1052 | ) |
||
| 1053 | ->setMaxResults(1) |
||
| 1054 | ->execute(); |
||
| 1055 | |||
| 1056 | $allResults = $result->fetchAll(); |
||
| 1057 | |||
| 1058 | if (count($allResults) == 1) { |
||
| 1059 | $resArray = $allResults[0]; |
||
| 1060 | // Get desired thumbnail structure if not the toplevel structure itself. |
||
| 1061 | if (!empty($resArray['thumbnail'])) { |
||
| 1062 | $strctType = Helper::getIndexNameFromUid($resArray['thumbnail'], 'tx_dlf_structures', $cPid); |
||
| 1063 | // Check if this document has a structure element of the desired type. |
||
| 1064 | $strctIds = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@TYPE="' . $strctType . '"]/@ID'); |
||
| 1065 | if (!empty($strctIds)) { |
||
| 1066 | $strctId = (string) $strctIds[0]; |
||
| 1067 | } |
||
| 1068 | } |
||
| 1069 | // Load smLinks. |
||
| 1070 | $this->_getSmLinks(); |
||
| 1071 | // Get thumbnail location. |
||
| 1072 | $fileGrpsThumb = GeneralUtility::trimExplode(',', $extConf['fileGrpThumbs']); |
||
| 1073 | while ($fileGrpThumb = array_shift($fileGrpsThumb)) { |
||
| 1074 | if ( |
||
| 1075 | $this->_getPhysicalStructure() |
||
| 1076 | && !empty($this->smLinks['l2p'][$strctId]) |
||
| 1077 | && !empty($this->physicalStructureInfo[$this->smLinks['l2p'][$strctId][0]]['files'][$fileGrpThumb]) |
||
| 1078 | ) { |
||
| 1079 | $this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->smLinks['l2p'][$strctId][0]]['files'][$fileGrpThumb]); |
||
| 1080 | break; |
||
| 1081 | } elseif (!empty($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb])) { |
||
| 1082 | $this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb]); |
||
| 1083 | break; |
||
| 1084 | } |
||
| 1085 | } |
||
| 1086 | } else { |
||
| 1087 | $this->logger->error('No structure of type "' . $metadata['type'][0] . '" found in database'); |
||
| 1088 | } |
||
| 1089 | $this->thumbnailLoaded = true; |
||
| 1090 | } |
||
| 1091 | return $this->thumbnail; |
||
| 1092 | } |
||
| 1093 | |||
| 1094 | /** |
||
| 1095 | * {@inheritDoc} |
||
| 1096 | * @see \Kitodo\Dlf\Common\Doc::_getToplevelId() |
||
| 1097 | */ |
||
| 1098 | protected function _getToplevelId() |
||
| 1099 | { |
||
| 1100 | if (empty($this->toplevelId)) { |
||
| 1101 | // Get all logical structure nodes with metadata, but without associated METS-Pointers. |
||
| 1102 | $divs = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID and not(./mets:mptr)]'); |
||
| 1103 | if (!empty($divs)) { |
||
| 1104 | // Load smLinks. |
||
| 1105 | $this->_getSmLinks(); |
||
| 1106 | foreach ($divs as $div) { |
||
| 1107 | $id = (string) $div['ID']; |
||
| 1108 | // Are there physical structure nodes for this logical structure? |
||
| 1109 | if (array_key_exists($id, $this->smLinks['l2p'])) { |
||
| 1110 | // Yes. That's what we're looking for. |
||
| 1111 | $this->toplevelId = $id; |
||
| 1112 | break; |
||
| 1113 | } elseif (empty($this->toplevelId)) { |
||
| 1114 | // No. Remember this anyway, but keep looking for a better one. |
||
| 1115 | $this->toplevelId = $id; |
||
| 1116 | } |
||
| 1117 | } |
||
| 1118 | } |
||
| 1119 | } |
||
| 1120 | return $this->toplevelId; |
||
| 1121 | } |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * This magic method is executed prior to any serialization of the object |
||
| 1125 | * @see __wakeup() |
||
| 1126 | * |
||
| 1127 | * @access public |
||
| 1128 | * |
||
| 1129 | * @return array Properties to be serialized |
||
| 1130 | */ |
||
| 1131 | public function __sleep() |
||
| 1136 | } |
||
| 1137 | |||
| 1138 | /** |
||
| 1139 | * This magic method is used for setting a string value for the object |
||
| 1140 | * |
||
| 1141 | * @access public |
||
| 1142 | * |
||
| 1143 | * @return string String representing the METS object |
||
| 1144 | */ |
||
| 1145 | public function __toString() |
||
| 1146 | { |
||
| 1151 | } |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * This magic method is executed after the object is deserialized |
||
| 1155 | * @see __sleep() |
||
| 1156 | * |
||
| 1157 | * @access public |
||
| 1158 | * |
||
| 1159 | * @return void |
||
| 1160 | */ |
||
| 1161 | public function __wakeup() |
||
| 1172 | } |
||
| 1173 | } |
||
| 1174 | } |
||
| 1175 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.