Skip to content

Commit 315c6b8

Browse files
committed
pkp/pkp-lib#10923 add funding metadata to ONIX exports
1 parent 148c417 commit 315c6b8

File tree

1 file changed

+60
-3
lines changed

1 file changed

+60
-3
lines changed

plugins/importexport/onix30/filter/MonographONIX30XmlFilter.php

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
use DOMElement;
2929
use DOMException;
3030
use Exception;
31+
use Illuminate\Database\Query\JoinClause;
32+
use Illuminate\Support\Collection;
33+
use Illuminate\Support\Facades\DB;
3134
use PKP\db\DAORegistry;
3235
use PKP\filter\FilterGroup;
3336
use PKP\i18n\LocaleConversion;
3437
use PKP\plugins\importexport\native\filter\NativeExportFilter;
38+
use PKP\plugins\PluginRegistry;
3539
use PKP\userGroup\UserGroup;
3640

3741
class MonographONIX30XmlFilter extends NativeExportFilter
@@ -563,9 +567,6 @@ public function createProductNode(DOMDocument $doc, Submission $submission, Publ
563567

564568
$publisherNode->appendChild($this->buildTextNode($doc, 'PublishingRole', '01')); // Publisher
565569
$publisherNode->appendChild($this->buildTextNode($doc, 'PublisherName', $context->getData('publisher')));
566-
if ($context->getData('location') != '') {
567-
$publishingDetailNode->appendChild($this->buildTextNode($doc, 'CityOfPublication', $context->getData('location')));
568-
}
569570

570571
$websiteNode = $doc->createElementNS($deployment->getNamespace(), 'Website');
571572
$publisherNode->appendChild($websiteNode);
@@ -586,6 +587,37 @@ public function createProductNode(DOMDocument $doc, Submission $submission, Publ
586587

587588
$websiteNode->appendChild($this->buildTextNode($doc, 'WebsiteLink', $request->url($context->getPath(), 'catalog', 'book', [$submissionBestId])));
588589

590+
/* --- Funders and awards --- */
591+
592+
$fundingData = $this->getFundingData($context->getId(), $submissionBestId);
593+
if (!$fundingData->isEmpty()) {
594+
foreach ($fundingData as $funder) {
595+
$publisherNode = $doc->createElementNS($deployment->getNamespace(), 'Publisher');
596+
$publisherNode->appendChild($this->buildTextNode($doc, 'PublishingRole', '16')); // 16 -> Funding body
597+
$publisherIdentifierNode = $doc->createElementNS($deployment->getNamespace(), 'PublisherIdentifier');
598+
$publisherIdentifierNode->appendChild($this->buildTextNode($doc, 'PublisherIDType', '32')); // 32 -> FundRef DOI
599+
$publisherIdentifierNode->appendChild($this->buildTextNode($doc, 'IDValue', $funder[0]->funder_identification));
600+
$publisherNode->appendChild($publisherIdentifierNode);
601+
$publisherNode->appendChild($this->buildTextNode($doc, 'PublisherName', $funder[0]->funder_name));
602+
foreach ($funder as $awards) {
603+
$fundingNode = $doc->createElementNS($deployment->getNamespace(), 'Funding');
604+
$fundingIdentifierNode = $doc->createElementNS($deployment->getNamespace(), 'FundingIdentifier');
605+
$fundingIdentifierNode->appendChild($this->buildTextNode($doc, 'FundingIDType', '01')); // 01 -> proprietary
606+
$fundingIdentifierNode->appendChild($this->buildTextNode($doc, 'IDTypeName', 'Award/Grant Number'));
607+
$fundingIdentifierNode->appendChild($this->buildTextNode($doc, 'IDValue', $awards->funder_award_number));
608+
$fundingNode->appendChild($fundingIdentifierNode);
609+
$publisherNode->appendChild($fundingNode);
610+
}
611+
$publishingDetailNode->appendChild($publisherNode);
612+
}
613+
}
614+
615+
/* --- Publishing Location --- */
616+
617+
if ($context->getData('location') != '') {
618+
$publishingDetailNode->appendChild($this->buildTextNode($doc, 'CityOfPublication', $context->getData('location')));
619+
}
620+
589621
/* --- Publishing Dates --- */
590622

591623
$publicationDates = $publicationFormat->getPublicationDates();
@@ -956,4 +988,29 @@ public function buildTextNode(DOMDocument $doc, string $nodeName, string $textCo
956988
$node->appendChild($doc->createTextNode($textContent));
957989
return $node;
958990
}
991+
992+
/**
993+
* Helper function to retrieve funding data when available.
994+
*/
995+
public function getFundingData(int $contextId, int $submissionId): Collection|false
996+
{
997+
if (!PluginRegistry::getPlugin('generic', 'FundingPlugin')) {
998+
return false;
999+
}
1000+
1001+
$fundingData = DB::table('funders AS f')
1002+
->select('f.funder_id', 'f.funder_identification', 'fs.setting_value as funder_name', 'fa.funder_award_id', 'fa.funder_award_number')
1003+
->where('submission_id', $submissionId)
1004+
->where('context_id', $contextId)
1005+
->leftJoin(
1006+
'funder_settings AS fs',
1007+
fn (JoinClause $j) => $j->on('f.funder_id', '=', 'fs.funder_id')
1008+
->where('fs.setting_name', '=', 'funderName')
1009+
)
1010+
->leftjoin('funder_awards AS fa', 'f.funder_id', '=', 'fa.funder_id')
1011+
->get()
1012+
->groupBy('funder_id');
1013+
1014+
return $fundingData ?? false;
1015+
}
9591016
}

0 commit comments

Comments
 (0)