Skip to content

Commit

Permalink
Merge pull request pkp#1764 from kaitlinnewson/9928-3_4_0
Browse files Browse the repository at this point in the history
pkp/pkp-lib#9928 add related identifiers to onix exports
  • Loading branch information
bozana authored Nov 15, 2024
2 parents 9d5de20 + 6cdbc6b commit 488408e
Showing 1 changed file with 45 additions and 12 deletions.
57 changes: 45 additions & 12 deletions plugins/importexport/onix30/filter/MonographONIX30XmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,19 @@ public function createSubmissionNode($doc, $rootNode, $submission)
{
$publicationFormats = $submission->getCurrentPublication()->getData('publicationFormats');

// 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 @@ -149,7 +159,7 @@ public function createHeaderNode($doc)
*
* @return \DOMElement
*/
public function createProductNode($doc, $submission, $publicationFormat)
public function createProductNode($doc, $submission, $publicationFormat, $identificationCodes)
{
/** @var Onix30ExportDeployment */
$deployment = $this->getDeployment();
Expand All @@ -165,18 +175,18 @@ public 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.
Expand Down Expand Up @@ -638,6 +648,29 @@ public 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 */
Expand Down

0 comments on commit 488408e

Please sign in to comment.