Skip to content

Commit

Permalink
pkp/pkp-lib#6251 split creation of relations node
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnyga committed May 22, 2022
1 parent e1d57b3 commit 4129138
Showing 1 changed file with 37 additions and 23 deletions.
60 changes: 37 additions & 23 deletions filter/PreprintCrossrefXmlFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,17 @@ public function createPostedContentNode($doc, $publication, $submission)
// DOI relations: if this version has a vorDoi or different DOI than the current publication (ie. versions and DOI versioning exits), add a relation node
$parentDoi = $submission->getCurrentPublication()->getDoi() && $submission->getCurrentPublication()->getDoi() != $publication->getDoi() ? $submission->getCurrentPublication()->getDoi() : '';
$vorDoi = $publication->getData('vorDoi') ? $publication->getData('vorDoi') : '';

if ($parentDoi || $vorDoi) {
$postedContentNode->appendChild($this->createRelationsDataNode($doc, $parentDoi, $vorDoi));
$relationsDataNode = $doc->createElementNS($deployment->getRELNamespace(), 'rel:program');
$relationsDataNode->setAttribute('name', 'relations');
if ($parentDoi) {
$relationsDataNode->appendChild($this->createParentDoiNode($doc, $parentDoi));
}
if ($vorDoi) {
$relationsDataNode->appendChild($this->createVorDoiNode($doc, $vorDoi));
}
$postedContentNode->appendChild($relationsDataNode);
}

// DOI data
Expand Down Expand Up @@ -300,38 +309,43 @@ public function createDOIDataNode($doc, $doi, $url)
}

/**
* Create and return the 'program' node for DOI relations.
* Create and return the parent DOI relation node.
*
* @param $doc DOMDocument
* @param $parentDoi string
*
* @return DOMElement
*/
public function createParentDoiNode($doc, $parentDoi)
{
$deployment = $this->getDeployment();
$parentDoiNode = $doc->createElementNS($deployment->getRELNamespace(), 'rel:related_item');
$intraWorkRelationNode = $doc->createElementNS($deployment->getRELNamespace(), 'rel:intra_work_relation', htmlspecialchars($parentDoi, ENT_COMPAT, 'UTF-8'));
$intraWorkRelationNode->setAttribute('relationship-type', 'isVersionOf');
$intraWorkRelationNode->setAttribute('identifier-type', 'doi');
$parentDoiNode->appendChild($intraWorkRelationNode);

return $parentDoiNode;
}

/**
* Create and return the VOR DOI relation node.
*
* @param $doc DOMDocument
* @param $vorDoi string
*
* @return DOMElement
*/
public function createRelationsDataNode($doc, $parentDoi, $vorDoi)
public function createVorDoiNode($doc, $vorDoi)
{
$deployment = $this->getDeployment();
$relationsDataNode = $doc->createElementNS($deployment->getRELNamespace(), 'rel:program');
$relationsDataNode->setAttribute('name', 'relations');

if ($parentDoi) {
$relatedItemNode = $doc->createElementNS($deployment->getRELNamespace(), 'rel:related_item');
$intraWorkRelationNode = $doc->createElementNS($deployment->getRELNamespace(), 'rel:intra_work_relation', htmlspecialchars($parentDoi, ENT_COMPAT, 'UTF-8'));
$intraWorkRelationNode->setAttribute('relationship-type', 'isVersionOf');
$intraWorkRelationNode->setAttribute('identifier-type', 'doi');
$relatedItemNode->appendChild($intraWorkRelationNode);
$relationsDataNode->appendChild($relatedItemNode);
}
if ($vorDoi) {
$relatedItemNode = $doc->createElementNS($deployment->getRELNamespace(), 'rel:related_item');
$intraWorkRelationNode = $doc->createElementNS($deployment->getRELNamespace(), 'rel:intra_work_relation', htmlspecialchars($vorDoi, ENT_COMPAT, 'UTF-8'));
$intraWorkRelationNode->setAttribute('relationship-type', 'isPreprintOf');
$intraWorkRelationNode->setAttribute('identifier-type', 'doi');
$relatedItemNode->appendChild($intraWorkRelationNode);
$relationsDataNode->appendChild($relatedItemNode);
}
$vorDoiNode = $doc->createElementNS($deployment->getRELNamespace(), 'rel:related_item');
$intraWorkRelationNode = $doc->createElementNS($deployment->getRELNamespace(), 'rel:intra_work_relation', htmlspecialchars($vorDoi, ENT_COMPAT, 'UTF-8'));
$intraWorkRelationNode->setAttribute('relationship-type', 'isPreprintOf');
$intraWorkRelationNode->setAttribute('identifier-type', 'doi');
$vorDoiNode->appendChild($intraWorkRelationNode);

return $relationsDataNode;
return $vorDoiNode;
}

/**
Expand Down

0 comments on commit 4129138

Please sign in to comment.