Skip to content

Commit

Permalink
feat: add default surname
Browse files Browse the repository at this point in the history
  • Loading branch information
forderation committed Feb 19, 2022
1 parent 7bcbded commit b637798
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions filter/ArticleCrossrefXmlFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ public function createJournalArticleNode($doc, $submission)
// Check if both givenName and familyName is set for the submission language.
if (!empty($familyNames[$locale]) && !empty($givenNames[$locale])) {
$personNameNode->setAttribute('language', LocaleConversion::getIso1FromLocale($locale));
$personNameNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'given_name', htmlspecialchars(ucfirst($givenNames[$locale]), ENT_COMPAT, 'UTF-8')));
$personNameNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'surname', htmlspecialchars(ucfirst($familyNames[$locale]), ENT_COMPAT, 'UTF-8')));
$givenName = $givenNames[$locale];
$familyName = $this->getDefaultSurname($givenName, $familyNames[$locale]);
$personNameNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'given_name', htmlspecialchars(ucfirst($givenName), ENT_COMPAT, 'UTF-8')));
$personNameNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'surname', htmlspecialchars(ucfirst($familyName), ENT_COMPAT, 'UTF-8')));
$hasAltName = false;

if ($author->getData('orcid')) {
Expand All @@ -162,7 +164,7 @@ public function createJournalArticleNode($doc, $submission)

$nameNode = $doc->createElementNS($deployment->getNamespace(), 'name');
$nameNode->setAttribute('language', LocaleConversion::getIso1FromLocale($otherLocal));

$familyName = $this->getDefaultSurname($givenName, $familyName);
$nameNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'surname', htmlspecialchars(ucfirst($familyName), ENT_COMPAT, 'UTF-8')));
if (isset($givenNames[$otherLocal]) && !empty($givenNames[$otherLocal])) {
$nameNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'given_name', htmlspecialchars(ucfirst($givenNames[$otherLocal]), ENT_COMPAT, 'UTF-8')));
Expand Down Expand Up @@ -293,6 +295,30 @@ public function createJournalArticleNode($doc, $submission)
return $journalArticleNode;
}

/**
* get default surname within given name, and family name
* will be use last given name if family name is empty
*
* @param string $givenName
* @param string $familyName
*
* @return string
*/
function getDefaultSurname($givenName, $familyName)
{
$splitGivenName = explode(" ", $givenName);
$lenSplitGivenName = count($splitGivenName);
if ($lenSplitGivenName != 0) {
$givenName = $splitGivenName[$lenSplitGivenName - 1];
}
$familyName = str_replace(" ", "", $familyName);
// if empty string
if ($familyName == null || strlen($familyName) == 0) {
$familyName = $givenName;
}
return $familyName;
}

/**
* Append the collection node 'collection property="crawler-based"' to the doi data node.
*
Expand Down

0 comments on commit b637798

Please sign in to comment.