From 526820a6d1e28365cdf8e5feb580a0f3d81c31e2 Mon Sep 17 00:00:00 2001 From: Dimitris Efstathiou Date: Fri, 24 Nov 2023 12:13:21 +0200 Subject: [PATCH] pkp/pkp-lib#7505 Initial Commit Upload - Delete - Download JATS File --- JatsTemplatePlugin.php | 2 +- classes/Article.php | 24 +++++++++++++++++++----- classes/ArticleFront.php | 30 ++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/JatsTemplatePlugin.php b/JatsTemplatePlugin.php index 40cad2d..aa52f6e 100755 --- a/JatsTemplatePlugin.php +++ b/JatsTemplatePlugin.php @@ -68,7 +68,7 @@ public function callbackFindJats($hookName, $args) { $doc =& $args[3]; if (!$doc && empty($candidateFiles)) { - $doc = new Article($record); + $doc = new Article($record); } return false; diff --git a/classes/Article.php b/classes/Article.php index d1247af..67952da 100644 --- a/classes/Article.php +++ b/classes/Article.php @@ -15,13 +15,17 @@ use APP\core\Application; use DOMException; +use PKP\oai\OAIRecord; class Article extends \DOMDocument { - function __construct($record) + function __construct(?OAIRecord $record = null) { parent::__construct('1.0', 'UTF-8'); - $this->convertToXml($record); + + if ($record) { + $this->convertToXml($record); + } } /** @@ -37,6 +41,16 @@ public function convertToXml($record) :bool|\DOMDocument $publication = $submission->getCurrentPublication(); $request = Application::get()->getRequest(); + $convertedXML = $this->convertSubmission($submission, $journal, $section, $issue, $publication, $request); + + return $this->loadXml($convertedXML); + } + + /** + * Convert submission metadata to JATS XML + */ + public function convertSubmission($submission, $context, $section, $issue, $publication, $request): string + { $articleElement = $this->appendChild($this->createElement('article')) ->setAttribute('xmlns:xlink','http://www.w3.org/1999/xlink')->parentNode ->setAttribute('xml:lang', substr($submission->getLocale(), 0, 2))->parentNode @@ -44,7 +58,7 @@ public function convertToXml($record) :bool|\DOMDocument ->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance')->parentNode; $articleFront = new ArticleFront(); - $articleElement->appendChild($this->importNode($articleFront->create($journal, $submission, $section, $issue, $request, $this), true)); + $articleElement->appendChild($this->importNode($articleFront->create($context, $submission, $section, $issue, $request, $this), true)); $articleBody = new ArticleBody(); $articleElement->appendChild($this->importNode($articleBody->create($submission), true)); @@ -52,10 +66,9 @@ public function convertToXml($record) :bool|\DOMDocument $articleBack = new ArticleBack(); $articleElement->appendChild($this->importNode($articleBack->create($publication), true)); - return $this->loadXml($this->saveXML($articleElement)); + return $this->saveXML($articleElement); } - /** * Map the specific HTML tags in title/ sub title for JATS schema compability * @see https://jats.nlm.nih.gov/publishing/0.4/xsd/JATS-journalpublishing0.xsd @@ -76,4 +89,5 @@ public function mapHtmlTagsForTitle(string $htmlTitle): string return str_replace(array_keys($mappings), array_values($mappings), $htmlTitle); } + } diff --git a/classes/ArticleFront.php b/classes/ArticleFront.php index bf0aded..e364ee9 100644 --- a/classes/ArticleFront.php +++ b/classes/ArticleFront.php @@ -13,12 +13,16 @@ namespace APP\plugins\generic\jatsTemplate\classes; use APP\core\Application; +use APP\core\PageRouter; use APP\facades\Repo; use APP\issue\Issue; use APP\journal\Journal; use APP\section\Section; use APP\submission\Submission; use APP\publication\Publication; +use PKP\core\Dispatcher; +use PKP\core\PKPApplication; +use PKP\core\PKPPageRouter; use PKP\core\PKPString; use PKP\db\DAORegistry; use PKP\plugins\PluginRegistry; @@ -27,11 +31,10 @@ class ArticleFront extends \DOMDocument { - /** * Create article front element */ - public function create(Journal $journal, Submission $submission, Section $section,Issue $issue, PKPRequest $request, Article $article): \DOMNode + public function create(Journal $journal, Submission $submission, Section $section, ?Issue $issue, PKPRequest $request, Article $article): \DOMNode { return $this->appendChild($this->createElement('front')) ->appendChild($this->createJournalMeta($journal, $request)) @@ -87,9 +90,15 @@ public function createJournalMeta(Journal $journal, PKPRequest $request): \DOMNo ->appendChild($this->createTextNode($journal->getSetting('printIssn')))->parentNode ->setAttribute('pub-type','ppub'); } + + $dispatcher = new Dispatcher(); + $dispatcher->setApplication(Application::get()); + $dispatcher->addRouterName('\APP\core\PageRouter', PKPApplication::ROUTE_PAGE); + + $journalUrl = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $journal->getPath()); $journalMetaElement ->appendChild($this->createElement('self-uri')) - ->setAttribute('xlink:href', $request->url($journal->getPath())); + ->setAttribute('xlink:href', $journalUrl); return $journalMetaElement; @@ -124,7 +133,7 @@ public function createJournalMetaJournalTitleGroup(Journal $journal): \DOMNode /** * Create xml article-meta DOMNode */ - function createArticleMeta(Submission $submission, Journal $journal, Section $section, Issue $issue, $request, Article $article) + function createArticleMeta(Submission $submission, Journal $journal, Section $section, ?Issue $issue, $request, Article $article) { $publication = $submission->getCurrentPublication(); @@ -186,9 +195,13 @@ function createArticleMeta(Submission $submission, Journal $journal, Section $se } $datePublished = $submission->getDatePublished(); - if (!$datePublished) $datePublished = $issue->getDatePublished(); + if (!$datePublished && $issue) { + $datePublished = $issue->getDatePublished(); + } if ($datePublished) $datePublished = strtotime($datePublished); + if (!$datePublished) $datePublished = strtotime('0001-01-01'); + // Include pub dates if ($submission->getDatePublished()){ $pubDateElement = $articleMetaElement->appendChild($this->createElement('pub-date')) @@ -264,10 +277,15 @@ function createArticleMeta(Submission $submission, Journal $journal, Section $se } } } + + $dispatcher = new Dispatcher(); + $dispatcher->setApplication(Application::get()); + $dispatcher->addRouterName('\APP\core\PageRouter', PKPApplication::ROUTE_PAGE); + $url = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $journal->getPath(), 'article', 'view', $submission->getBestId(), null, null, true); $articleMetaElement ->appendChild($this->createElement('self-uri')) - ->setAttribute('xlink:href', $request->url($journal->getPath(), 'article', 'view', $submission->getBestArticleId())); + ->setAttribute('xlink:href', $url); $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); foreach ($submissionKeywordDao->getKeywords($publication->getId(), $journal->getSupportedLocales()) as $locale => $keywords) {