From af52f928c53ed20ec14fe1f0be75ee5410023e09 Mon Sep 17 00:00:00 2001 From: Kaitlin Newson Date: Wed, 13 Nov 2024 11:32:13 -0400 Subject: [PATCH] pkp/pkp-lib#9928 add related identifiers to onix exports --- .../filter/MonographONIX30XmlFilter.inc.php | 57 +++++++++++++++---- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php b/plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php index 7f67fa29406..fc84a92607c 100644 --- a/plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php +++ b/plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php @@ -91,9 +91,19 @@ function createSubmissionNode($doc, $rootNode, $submission) { $deployment->addError(ASSOC_TYPE_MONOGRAPH, $submission->getId(), __('plugins.importExport.onix30.common.error.monographWithNoPublicationFormats', ['monographId' => $submission->getId()])); } + // Collect identifiers for all publication formats to connect related products + $identificationCodes = []; + foreach ($publicationFormats as $publicationFormat) { + $pubIdentificationCodes = $publicationFormat->getIdentificationCodes(); + $pubId = $publicationFormat->getId(); + while ($code = $pubIdentificationCodes->next()) { + $identificationCodes[$pubId][$code->getCode()] = $code->getValue(); + } + } + // Append all publication formats as Product nodes. foreach ($publicationFormats as $publicationFormat) { - $rootNode->appendChild($this->createProductNode($doc, $submission, $publicationFormat)); + $rootNode->appendChild($this->createProductNode($doc, $submission, $publicationFormat, $identificationCodes)); } } @@ -139,7 +149,7 @@ function createHeaderNode($doc) { * @param $publicationFormat PublicationFormat * @return DOMElement */ - function createProductNode($doc, $submission, $publicationFormat) { + function createProductNode($doc, $submission, $publicationFormat, $identificationCodes) { $deployment = $this->getDeployment(); $context = $deployment->getContext(); @@ -154,18 +164,18 @@ function createProductNode($doc, $submission, $publicationFormat) { $identifierGiven = false; - $identificationCodes = $publicationFormat->getIdentificationCodes(); + if (array_key_exists($publicationFormat->getId(), $identificationCodes)) { + foreach ($identificationCodes[$publicationFormat->getId()] as $code => $value) { + $productIdentifierNode = $doc->createElementNS($deployment->getNamespace(), 'ProductIdentifier'); + $productIdentifierNode->appendChild($this->_buildTextNode($doc, 'ProductIDType', $code)); + $productIdentifierNode->appendChild($this->_buildTextNode($doc, 'IDValue', $value)); + $productNode->appendChild($productIdentifierNode); - while ($code = $identificationCodes->next()) { - $productIdentifierNode = $doc->createElementNS($deployment->getNamespace(), 'ProductIdentifier'); - $productIdentifierNode->appendChild($this->_buildTextNode($doc, 'ProductIDType', $code->getCode())); // GTIN-13 (ISBN-13 as GTIN) - $productIdentifierNode->appendChild($this->_buildTextNode($doc, 'IDValue', $code->getValue())); - $productNode->appendChild($productIdentifierNode); - - unset($productIdentifierNode); - unset($code); + unset($productIdentifierNode); + unset($code); - $identifierGiven = true; + $identifierGiven = true; + } } // Deal with the possibility of a DOI pubId from the plugin. @@ -630,6 +640,29 @@ function createProductNode($doc, $submission, $publicationFormat) { $publishingDetailNode->appendChild($this->_buildTextNode($doc, 'ROWSalesRightsType', $salesRightsROW->getType())); } + /* --- Related Material --- */ + + unset($identificationCodes[$publicationFormat->getId()]); // remove identifiers for the current publication format + + if (count($identificationCodes) > 0) { + $relatedMaterialNode = $doc->createElementNS($deployment->getNamespace(), 'RelatedMaterial'); + + $relatedProductNode = $doc->createElementNS($deployment->getNamespace(), 'RelatedProduct'); + $relatedProductNode->appendChild($this->_buildTextNode($doc, 'ProductRelationCode', '06')); // alternative format + + foreach ($identificationCodes as $pubId => $idCodes) { + foreach ($idCodes as $code => $value) { + $productIdentifierNode = $doc->createElementNS($deployment->getNamespace(), 'ProductIdentifier'); + $productIdentifierNode->appendChild($this->_buildTextNode($doc, 'ProductIDType', $code)); + $productIdentifierNode->appendChild($this->_buildTextNode($doc, 'IDValue', $value)); + $relatedProductNode->appendChild($productIdentifierNode); + unset($productIdentifierNode); + } + } + $relatedMaterialNode->appendChild($relatedProductNode); + $productNode->appendChild($relatedMaterialNode); + } + /* --- Product Supply. We create one of these per defined Market. --- */ $representativeDao = DAORegistry::getDAO('RepresentativeDAO'); /* @var $representativeDao RepresentativeDAO */