Skip to content

Commit

Permalink
Fix codacy and remove todos comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chrizzor committed Jun 14, 2024
1 parent f93bee6 commit 4c6b57a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 70 deletions.
75 changes: 9 additions & 66 deletions Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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.
Expand Down Expand Up @@ -675,6 +675,7 @@ private function processAdditionalMetadata(array $additionalMetadata, \DOMXPath
* @param \DOMXPath $domXPath
* @param \DOMElement $domNode
* @param array $metadata
* @param array $subentryResults
*
* @return void
*/
Expand All @@ -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);
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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());
}

/**
Expand Down
2 changes: 0 additions & 2 deletions Classes/Controller/ListViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Classes/Controller/MetadataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4c6b57a

Please sign in to comment.