diff --git a/Classes/Common/MetsDocument.php b/Classes/Common/MetsDocument.php index 20ad1ef27..95ea45676 100644 --- a/Classes/Common/MetsDocument.php +++ b/Classes/Common/MetsDocument.php @@ -535,8 +535,8 @@ private function processMetadataSections(string $id, int $cPid, array $metadata) /** * @param array $allSubentries * @param string $parentIndex - * @param \DOMNode parentNode - * @return array + * @param \DOMNode $parentNode + * @return array|false */ private function getSubentries($allSubentries, string $parentIndex, \DOMNode $parentNode) { @@ -558,13 +558,13 @@ private function getSubentries($allSubentries, string $parentIndex, \DOMNode $pa $theseSubentries[$subentry['index_name']][] = trim($values); } else { foreach ($values as $value) { - if (!empty(trim((string)$value->nodeValue))) { - $theseSubentries[$subentry['index_name']][] = trim((string)$value->nodeValue); + if (!empty(trim((string) $value->nodeValue))) { + $theseSubentries[$subentry['index_name']][] = trim((string) $value->nodeValue); } } } } elseif (!($values instanceof \DOMNodeList)) { - $theseSubentries[$subentry['index_name']] = [trim((string)$values->nodeValue)]; + $theseSubentries[$subentry['index_name']] = [trim((string) $values->nodeValue)]; } } // Set default value if applicable. @@ -675,6 +675,7 @@ private function processAdditionalMetadata(array $additionalMetadata, \DOMXPath * @param \DOMXPath $domXPath * @param \DOMElement $domNode * @param array $metadata + * @param array $subentryResults * * @return void */ @@ -685,7 +686,8 @@ private function setMetadataFieldValues(array $resArray, \DOMXPath $domXPath, \D if ($values instanceof \DOMNodeList && $values->length > 0) { $metadata[$resArray['index_name']] = []; foreach ($values as $value) { - if ($subentries = $this->getSubentries($subentryResults, $resArray['index_name'], $value)) { + $subentries = $this->getSubentries($subentryResults, $resArray['index_name'], $value); + if ($subentries) { $metadata[$resArray['index_name']][] = $subentries; } else { $metadata[$resArray['index_name']][] = trim((string) $value->nodeValue); @@ -723,6 +725,7 @@ private function setDefaultMetadataValue(array $resArray, array &$metadata): voi * @param \DOMXPath $domXPath * @param \DOMElement $domNode * @param array $metadata + * @param array $subentryResults * * @return void */ @@ -942,66 +945,6 @@ private function getAdditionalMetadataFromDatabase(int $cPid, string $dmdId) $subentriesResult = $subentries->fetchAll(); return array_merge($allResults, ['subentries' => $subentriesResult]); -// // We need a \DOMDocument here, because SimpleXML doesn't support XPath functions properly. -// $domNode = dom_import_simplexml($this->mdSec[$dmdId]['xml']); -// $domXPath = new \DOMXPath($domNode->ownerDocument); -// $this->registerNamespaces($domXPath); -// // OK, now make the XPath queries. -// foreach ($allResults as $resArray) { -// // Set metadata field's value(s). -// if ( -// $resArray['format'] > 0 -// && !empty($resArray['xpath']) -// && ($values = $domXPath->evaluate($resArray['xpath'], $domNode)) -// ) { -// if ( -// $values instanceof \DOMNodeList -// && $values->length > 0 -// ) { -// $metadata[$resArray['index_name']] = []; -// foreach ($values as $value) { -// if ($subentries = $this->getSubentries($subentriesResult, $resArray['index_name'], $value)) { -// $metadata[$resArray['index_name']][] = $subentries; -// } else { -// $metadata[$resArray['index_name']][] = trim((string)$value->nodeValue); -// } -// } -// } elseif (!($values instanceof \DOMNodeList)) { -// $metadata[$resArray['index_name']] = [trim((string)$values)]; -// } -// } -// // Set default value if applicable. -// if ( -// empty($metadata[$resArray['index_name']][0]) -// && strlen($resArray['default_value']) > 0 -// ) { -// $metadata[$resArray['index_name']] = [$resArray['default_value']]; -// } -// // Set sorting value if applicable. -// if ( -// !empty($metadata[$resArray['index_name']]) -// && $resArray['is_sortable'] -// ) { -// if ( -// $resArray['format'] > 0 -// && !empty($resArray['xpath_sorting']) // TODO: will fail, for subentries -// && ($values = $domXPath->evaluate($resArray['xpath_sorting'], $domNode)) -// ) { -// if ( -// $values instanceof \DOMNodeList -// && $values->length > 0 -// ) { -// $metadata[$resArray['index_name'] . '_sorting'][0] = trim((string)$values->item(0)->nodeValue); -// } elseif (!($values instanceof \DOMNodeList)) { -// $metadata[$resArray['index_name'] . '_sorting'][0] = trim((string)$values); -// } -// } -// if (empty($metadata[$resArray['index_name'] . '_sorting'][0])) { -// $metadata[$resArray['index_name'] . '_sorting'][0] = $metadata[$resArray['index_name']][0]; -// } -// } -// } - //return array_merge($resultWithFormat->fetchAllAssociative(), $resultWithoutFormat->fetchAllAssociative()); } /** diff --git a/Classes/Controller/ListViewController.php b/Classes/Controller/ListViewController.php index 0ec0065ec..66bb47835 100644 --- a/Classes/Controller/ListViewController.php +++ b/Classes/Controller/ListViewController.php @@ -91,8 +91,6 @@ public function mainAction(): void $currentPage = $this->requestData['page'] ?? 1; // get all sortable metadata records - // TODO: Sebastian fragen - // TODO: Include also subentries if available. $sortableMetadata = $this->metadataRepository->findByIsSortable(true); // get all metadata records to be shown in results diff --git a/Classes/Controller/MetadataController.php b/Classes/Controller/MetadataController.php index 02d7db68d..f8016e040 100644 --- a/Classes/Controller/MetadataController.php +++ b/Classes/Controller/MetadataController.php @@ -174,8 +174,7 @@ protected function printMetadata(array $metadata): void $metadata[$i][$name] = is_array($value) ? implode($this->settings['separator'], $value) : $value; - - // TODO: This might not be necessary for subentries or needs to be typecasted correctly. + if ($metadata[$i][$name] === 'Array') { $metadata[$i][$name] = []; foreach ($value as $subKey => $subValue) {