Skip to content

Commit

Permalink
Merge pull request pkp#1716 from kaitlinnewson/10046-main
Browse files Browse the repository at this point in the history
pkp/pkp-lib#10046 fix onix export calls to get localized data
  • Loading branch information
bozana authored Oct 7, 2024
2 parents c95d8d8 + 7e563d6 commit c60f285
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 41 deletions.
29 changes: 27 additions & 2 deletions classes/publication/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file classes/publication/Publication.php
*
* Copyright (c) 2016-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Copyright (c) 2016-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class Publication
Expand Down Expand Up @@ -45,6 +45,31 @@ public function getEditorString()
return join(__('common.commaListSeparator') . ' ', $editorNames);
}

/**
* Get the URL to a cover image
*
* @param int $contextId
* @param string $preferredLocale Return the cover image in a specified locale.
*
* @return string
*/
public function getCoverImageUrl($contextId, $preferredLocale = null)
{
$coverImage = $this->getData('coverImage', $preferredLocale);

if (!$coverImage) {
return Application::get()->getRequest()->getBaseUrl() . '/templates/images/book-default.png';
}

$publicFileManager = new PublicFileManager();

return join('/', [
Application::get()->getRequest()->getBaseUrl(),
$publicFileManager->getContextFilesPath($contextId),
$coverImage['uploadName'],
]);
}

/**
* Get the URL to a localized cover image
*
Expand Down
80 changes: 41 additions & 39 deletions plugins/importexport/onix30/filter/MonographONIX30XmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file plugins/importexport/onix30/filter/MonographONIX30XmlFilter.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2000-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class MonographONIX30XmlFilter
Expand Down Expand Up @@ -125,7 +125,7 @@ public function createHeaderNode($doc)
$senderNode->appendChild($senderIdentifierNode);

// Assemble SenderName element.
$senderNode->appendChild($this->_buildTextNode($doc, 'SenderName', $context->getLocalizedName()));
$senderNode->appendChild($this->_buildTextNode($doc, 'SenderName', $context->getName($context->getPrimaryLocale())));
$senderNode->appendChild($this->_buildTextNode($doc, 'ContactName', $context->getContactName()));
$senderNode->appendChild($this->_buildTextNode($doc, 'EmailAddress', $context->getContactEmail()));

Expand Down Expand Up @@ -251,12 +251,13 @@ public function createProductNode($doc, $submission, $publicationFormat)
/* --- License information --- */

$publication = $submission->getCurrentPublication();
$pubLocale = $publication->getData('locale');

if ($publication->isCCLicense()) {
$licenseOpts = Application::getCCLicenseOptions();
$licenseUrl = $publication->getData('licenseUrl');
if (array_key_exists($licenseUrl, $licenseOpts)) {
$licenseName = (__($licenseOpts[$licenseUrl], [], $publication->getData('locale')));
$licenseName = (__($licenseOpts[$licenseUrl], [], $pubLocale));

$epubLicenseNode = $doc->createElementNS($deployment->getNamespace(), 'EpubLicense');
$descDetailNode->appendChild($epubLicenseNode);
Expand Down Expand Up @@ -291,20 +292,26 @@ public function createProductNode($doc, $submission, $publicationFormat)
$titleElementNode->appendChild($this->_buildTextNode($doc, 'PartNumber', $submission->getCurrentPublication()->getData('seriesPosition')));
}

if ($series->getLocalizedPrefix() == '' || $series->getLocalizedTitle(false) == '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim(join(' ', [$series->getLocalizedPrefix(), $series->getLocalizedTitle(false)]))));
$seriesLocale = $pubLocale;
// If the series title doesn't exist in the submission locale, use the press locale
if ($series->getTitle($seriesLocale, false) == '') {
$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)]))));
} else {
if ($series->getLocalizedPrefix() != '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $series->getLocalizedPrefix()));
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->getLocalizedTitle(false)));
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $series->getTitle($seriesLocale, false)));
}

if ($series->getLocalizedSubtitle() != '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $series->getLocalizedSubtitle()));
if ($series->getSubtitle($seriesLocale) != '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $series->getSubtitle($seriesLocale)));
}
} else {
$seriesCollectionNode = $doc->createElementNS($deployment->getNamespace(), 'NoCollection');
Expand All @@ -322,19 +329,19 @@ public function createProductNode($doc, $submission, $publicationFormat)

$productTitleDetailNode->appendChild($titleElementNode);

if (!$publication->getLocalizedData('prefix') || !$publication->getLocalizedData('title')) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim($publication->getLocalizedData('prefix') ?? $publication->getLocalizedTitle())));
if (!$publication->getData('prefix', $pubLocale) || !$publication->getData('title', $pubLocale)) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim($publication->getData('prefix', $pubLocale) ?? $publication->getData('title', $pubLocale))));
} else {
if ($publication->getLocalizedData('prefix')) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $publication->getLocalizedData('prefix')));
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->getLocalizedData('title'))));
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', strip_tags($publication->getData('title', $pubLocale))));
}

if ($subTitle = $publication->getLocalizedSubTitle($publication->getData('locale'))) {
if ($subTitle = $publication->getData('subtitle', $pubLocale)) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $subTitle));
}

Expand All @@ -354,17 +361,17 @@ public function createProductNode($doc, $submission, $publicationFormat)
$role = array_key_exists($nameKey, $userGroupOnixMap) ? $userGroupOnixMap[$nameKey] : 'Z99'; // Z99 - unknown contributor type.

$contributorNode->appendChild($this->_buildTextNode($doc, 'ContributorRole', $role));
$contributorNode->appendChild($this->_buildTextNode($doc, 'PersonName', $author->getFullName(false)));
$contributorNode->appendChild($this->_buildTextNode($doc, 'PersonNameInverted', $author->getFullName(false, true)));
$contributorNode->appendChild($this->_buildTextNode($doc, 'NamesBeforeKey', $author->getLocalizedGivenName()));
if ($author->getLocalizedFamilyName() != '') {
$contributorNode->appendChild($this->_buildTextNode($doc, 'KeyNames', $author->getLocalizedFamilyName()));
$contributorNode->appendChild($this->_buildTextNode($doc, 'PersonName', $author->getFullName(false, false, $pubLocale)));
$contributorNode->appendChild($this->_buildTextNode($doc, 'PersonNameInverted', $author->getFullName(false, true, $pubLocale)));
$contributorNode->appendChild($this->_buildTextNode($doc, 'NamesBeforeKey', $author->getGivenName($pubLocale)));
if ($author->getFamilyName($pubLocale) != '') {
$contributorNode->appendChild($this->_buildTextNode($doc, 'KeyNames', $author->getFamilyName($pubLocale)));
} else {
$contributorNode->appendChild($this->_buildTextNode($doc, 'KeyNames', $author->getFullName(false)));
$contributorNode->appendChild($this->_buildTextNode($doc, 'KeyNames', $author->getFullName(false, false, $pubLocale)));
}

if ($author->getLocalizedBiography() != '') {
$contributorNode->appendChild($this->_buildTextNode($doc, 'BiographicalNote', $author->getLocalizedBiography()));
if ($author->getBiography($pubLocale) != '') {
$contributorNode->appendChild($this->_buildTextNode($doc, 'BiographicalNote', $author->getBiography($pubLocale)));
}

if ($author->getCountry() != '') {
Expand Down Expand Up @@ -429,13 +436,13 @@ public function createProductNode($doc, $submission, $publicationFormat)
$subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeIdentifier', '12')); // 12 is BIC subject category code list.
$subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeVersion', '2')); // Version 2 of ^^

$allSubjects = ($publication->getData('subjects')[$publication->getData('locale')]);
$allSubjects = ($publication->getData('subjects')[$pubLocale]);
$subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectCode', trim(join(', ', $allSubjects))));
$descDetailNode->appendChild($subjectNode);
}

if ($publication->getData('keywords')) {
$allKeywords = ($publication->getData('keywords')[$publication->getData('locale')]);
$allKeywords = ($publication->getData('keywords')[$pubLocale]);
$keywordNode = $doc->createElementNS($deployment->getNamespace(), 'Subject');
$keywordNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeIdentifier', '20')); // Keywords
$keywordNode->appendChild($this->_buildTextNode($doc, 'SubjectHeadingText', trim(join(', ', $allKeywords))));
Expand Down Expand Up @@ -480,7 +487,7 @@ public function createProductNode($doc, $submission, $publicationFormat)
$collateralDetailNode = $doc->createElementNS($deployment->getNamespace(), 'CollateralDetail');
$productNode->appendChild($collateralDetailNode);

$abstract = strip_tags($publication->getLocalizedData('abstract'));
$abstract = strip_tags($publication->getData('abstract', $pubLocale));

$textContentNode = $doc->createElementNS($deployment->getNamespace(), 'TextContent');
$collateralDetailNode->appendChild($textContentNode);
Expand All @@ -504,7 +511,7 @@ public function createProductNode($doc, $submission, $publicationFormat)
$resourceVersionNode = $doc->createElementNS($deployment->getNamespace(), 'ResourceVersion');
$supportingResourceNode->appendChild($resourceVersionNode);
$resourceVersionNode->appendChild($this->_buildTextNode($doc, 'ResourceForm', '01')); // Linkable resource
$resourceVersionNode->appendChild($this->_buildTextNode($doc, 'ResourceLink', $publication->getLocalizedCoverImageUrl($context->getId(), $publication->getData('locale'))));
$resourceVersionNode->appendChild($this->_buildTextNode($doc, 'ResourceLink', $publication->getCoverImageUrl($context->getId(), $pubLocale)));

/* --- Publishing Detail --- */

Expand Down Expand Up @@ -713,15 +720,15 @@ public function createProductNode($doc, $submission, $publicationFormat)
$supplyDetailNode = $doc->createElementNS($deployment->getNamespace(), 'SupplyDetail');
$productSupplyNode->appendChild($supplyDetailNode);

$supplierNode = $doc->createElementNS($deployment->getNamespace(), 'Supplier');
$supplyDetailNode->appendChild($supplierNode);
if (isset($supplier)) {
$supplierNode = $doc->createElementNS($deployment->getNamespace(), 'Supplier');
$supplyDetailNode->appendChild($supplierNode);

$supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierRole', $supplier->getRole()));
$supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierName', $supplier->getName()));
if ($supplier->getPhone()) {
$supplierNode->appendChild($this->_buildTextNode($doc, 'TelephoneNumber', $supplier->getPhone()));
}

if ($supplier->getEmail()) {
$supplierNode->appendChild($this->_buildTextNode($doc, 'EmailAddress', $supplier->getEmail()));
}
Expand All @@ -741,11 +748,7 @@ public function createProductNode($doc, $submission, $publicationFormat)

$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteRole', '29')); // 29 -> Web page for full content
$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', $request->url($context->getPath(), 'catalog', 'book', $submissionBestId)));

unset($supplierNode);
} else { // No suppliers specified, use the Press settings instead.
$supplierNode = $doc->createElementNS($deployment->getNamespace(), 'Supplier');
$supplyDetailNode->appendChild($supplierNode);

$supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierRole', '09')); // Publisher supplying to end customers
$supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierName', $context->getData('publisher')));
Expand All @@ -759,10 +762,9 @@ public function createProductNode($doc, $submission, $publicationFormat)

$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteRole', '18')); // 18 -> Public website
$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', $request->getDispatcher()->url($request, Application::ROUTE_PAGE, $context->getPath(), urlLocaleForPage: '')));

unset($supplierNode);
unset($supplierWebsiteNode);
}
unset($supplierNode);
unset($supplierWebsiteNode);

if ($publicationFormat->getReturnableIndicatorCode() != '') {
$returnsNode = $doc->createElementNS($deployment->getNamespace(), 'ReturnsConditions');
Expand Down

0 comments on commit c60f285

Please sign in to comment.