Skip to content

Commit

Permalink
pkp/pkp-lib#10641 fix onix export language and update title elements
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitlinnewson committed Dec 23, 2024
1 parent c78dcb3 commit d44f11f
Showing 1 changed file with 24 additions and 39 deletions.
63 changes: 24 additions & 39 deletions plugins/importexport/onix30/filter/MonographONIX30XmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
use APP\facades\Repo;
use APP\monograph\RepresentativeDAO;
use APP\plugins\importexport\onix30\Onix30ExportDeployment;
use APP\publication\Publication;
use APP\publicationFormat\PublicationFormat;
use APP\submission\Submission;
use DOMDocument;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\filter\FilterGroup;
use PKP\submission\SubmissionLanguageDAO;
use PKP\i18n\LocaleConversion;
use PKP\plugins\importexport\native\filter\NativeExportFilter;

class MonographONIX30XmlFilter extends \PKP\plugins\importexport\native\filter\NativeExportFilter
class MonographONIX30XmlFilter extends NativeExportFilter
{
/** @var \DOMDocument */
public $_doc;
Expand Down Expand Up @@ -318,18 +317,14 @@ public function createProductNode($doc, $submission, $publicationFormat, $identi
$seriesLocale = $context->getPrimaryLocale();
}

if ($series->getPrefix($seriesLocale) == '' || $series->getTitle($seriesLocale, false) == '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim(join(' ', [$series->getPrefix($seriesLocale), $series->getTitle($seriesLocale, false)]))));
if ($series->getPrefix($seriesLocale) != '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $series->getPrefix($seriesLocale)));
} else {
if ($series->getPrefix($seriesLocale) != '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $series->getPrefix($seriesLocale)));
} else {
$titleElementNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'NoPrefix'));
}

$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $series->getTitle($seriesLocale, false)));
$titleElementNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'NoPrefix'));
}

$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $series->getTitle($seriesLocale, false)));

if ($series->getSubtitle($seriesLocale) != '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $series->getSubtitle($seriesLocale)));
}
Expand All @@ -349,18 +344,14 @@ public function createProductNode($doc, $submission, $publicationFormat, $identi

$productTitleDetailNode->appendChild($titleElementNode);

if (!$publication->getData('prefix', $pubLocale) || !$publication->getData('title', $pubLocale)) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim($publication->getData('prefix', $pubLocale) ?? $publication->getData('title', $pubLocale))));
if ($publication->getData('prefix', $pubLocale)) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $publication->getData('prefix', $pubLocale)));
} else {
if ($publication->getData('prefix', $pubLocale)) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $publication->getData('prefix', $pubLocale)));
} else {
$titleElementNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'NoPrefix'));
}

$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', strip_tags($publication->getData('title', $pubLocale))));
$titleElementNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'NoPrefix'));
}

$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $publication->getData('title', $pubLocale)));

if ($subTitle = $publication->getData('subtitle', $pubLocale)) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $subTitle));
}
Expand All @@ -375,7 +366,13 @@ public function createProductNode($doc, $submission, $publicationFormat, $identi

$userGroup = Repo::userGroup()->get($author->getUserGroupId());

$userGroupOnixMap = ['default.groups.name.author' => 'A01', 'default.groups.name.volumeEditor' => 'B01', 'default.groups.name.chapterAuthor' => 'A01', 'default.groups.name.translator' => 'B06', 'default.groups.name.editor' => 'B21']; // From List17, ContributorRole types.
$userGroupOnixMap = [
'default.groups.name.author' => 'A01',
'default.groups.name.volumeEditor' => 'B01',
'default.groups.name.chapterAuthor' => 'A01',
'default.groups.name.translator' => 'B06',
'default.groups.name.editor' => 'B21'
]; // From List17, ContributorRole types.

$nameKey = $userGroup->getData('nameLocaleKey');
$role = array_key_exists($nameKey, $userGroupOnixMap) ? $userGroupOnixMap[$nameKey] : 'Z99'; // Z99 - unknown contributor type.
Expand Down Expand Up @@ -414,25 +411,13 @@ public function createProductNode($doc, $submission, $publicationFormat, $identi
$descDetailNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'NoContributor')); // empty state of fact.
}

/* --- Add Language elements --- */

$submissionLanguageDao = DAORegistry::getDAO('SubmissionLanguageDAO'); /** @var SubmissionLanguageDAO $submissionLanguageDao */
$allLanguages = $submissionLanguageDao->getLanguages($publication->getId(), array_keys(Locale::getSupportedFormLocales()));
$uniqueLanguages = [];
foreach ($allLanguages as $locale => $languages) {
$uniqueLanguages = array_merge($uniqueLanguages, $languages);
}
/* --- Add Language element --- */

foreach ($uniqueLanguages as $language) {
if ($onixCodelistItemDao->codeExistsInList(LocaleConversion::get3LetterIsoFromLocale($pubLocale), 'List74')) {
$languageNode = $doc->createElementNS($deployment->getNamespace(), 'Language');

$languageNode->appendChild($this->_buildTextNode($doc, 'LanguageRole', '01'));
$onixLanguageCode = $onixCodelistItemDao->getCodeFromValue($language, 'List74');
if ($onixLanguageCode != '') {
$languageNode->appendChild($this->_buildTextNode($doc, 'LanguageCode', $onixLanguageCode));
$descDetailNode->appendChild($languageNode);
}
unset($languageNode);
$languageNode->appendChild($this->_buildTextNode($doc, 'LanguageCode', LocaleConversion::get3LetterIsoFromLocale($pubLocale)));
$descDetailNode->appendChild($languageNode);
}

/* --- add Extents for 03 (front matter), 04 (back matter), 22 for digital works ---*/
Expand Down

0 comments on commit d44f11f

Please sign in to comment.