Skip to content

Commit

Permalink
pkp/pkp-lib#9928 add related identifiers to onix exports
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitlinnewson committed Nov 13, 2024
1 parent a8b4597 commit 60ab899
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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();
Expand All @@ -154,18 +164,18 @@ function createProductNode($doc, $submission, $publicationFormat) {

$identifierGiven = false;

$identificationCodes = $publicationFormat->getIdentificationCodes();

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);
if ($identificationCodes[$publicationFormat->getId()]) {
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);

unset($productIdentifierNode);
unset($code);
unset($productIdentifierNode);
unset($code);

$identifierGiven = true;
$identifierGiven = true;
}
}

// Deal with the possibility of a DOI pubId from the plugin.
Expand Down Expand Up @@ -630,6 +640,31 @@ function createProductNode($doc, $submission, $publicationFormat) {
$publishingDetailNode->appendChild($this->_buildTextNode($doc, 'ROWSalesRightsType', $salesRightsROW->getType()));
}

/* --- Related Material --- */

if (array_key_exists($publicationFormat->getId(), $identificationCodes)) {
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 */
Expand Down

0 comments on commit 60ab899

Please sign in to comment.