Skip to content

Commit

Permalink
Merge branch 'addTranslationCitation-729' into 'main'
Browse files Browse the repository at this point in the history
Adicionar citação da tradução à Folha de Rosto

See merge request softwares-pkp/plugins_ojs/folhaDeRostoDoPDF!29
  • Loading branch information
JhonathanLepidus committed Dec 17, 2024
2 parents 0ce1b09 + d87f761 commit 5dbce74
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ include:
ref: main
file:
- 'templates/groups/pkp_plugin.yml'
- 'templates/groups/ops_3_4_plugins_unit_tests_model.yml'
- 'templates/groups/ops_3_4_plugins_cypress_tests_model.yml'
- 'templates/groups/ops/unit_tests.yml'
- 'templates/groups/ops/cypress_tests.yml'

.unit_test_template:
before_script:
Expand Down
1 change: 1 addition & 0 deletions TitlePageForPreprintPlugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file plugins/generic/TitlePageForPreprint/TitlePageForPreprintPlugin.inc.php
*
Expand Down
78 changes: 36 additions & 42 deletions classes/SubmissionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,91 @@

namespace APP\plugins\generic\titlePageForPreprint\classes;

class SubmissionModel
{
private $status;
private $doi;
private $doiJournal;
private $galleys;
private $authors;
private $submissionDate;
private $publicationDate;
private $version;
private $versionJustification;
private $endorserName;
private $endorserOrcid;

public function __construct(array $title, string $status, $doi, $doiJournal, string $authors, string $submissionDate, string $publicationDate, $endorserName, $endorserOrcid, string $version, $versionJustification, array $galleys = null)
{
$this->title = $title;
$this->status = $status;
$this->doi = ((empty($doi)) ? ("Not informed") : ($doi));
$this->doiJournal = ((empty($doiJournal)) ? ("Not informed") : ($doiJournal));
$this->authors = $authors;
$this->galleys = $galleys;
$this->submissionDate = $submissionDate;
$this->publicationDate = $publicationDate;
$this->endorserName = $endorserName;
$this->endorserOrcid = $endorserOrcid;
$this->version = $version;
$this->versionJustification = $versionJustification;
}
use PKP\core\DataObject;

class SubmissionModel extends DataObject
{
public function getTitle(string $locale): string
{
if (isset($this->title[$locale])) {
return $this->title[$locale];
$localizedTitle = $this->getData('title', $locale);

if (!is_null($localizedTitle)) {
return $localizedTitle;
}

return '';
}

public function getStatus(): string
{
return $this->status;
return $this->getData('status');
}

public function getDOI(): string
{
return $this->doi;
$doi = $this->getData('doi');
return empty($doi) ? ("Not informed") : $doi;
}

public function getJournalDOI(): string
{
return $this->doiJournal;
$doiJournal = $this->getData('doiJournal');
return empty($doiJournal) ? ("Not informed") : $doiJournal;
}

public function getAuthors(): string
{
return $this->authors;
return $this->getData('authors');
}

public function getGalleys(): array
{
return $this->galleys;
$galleys = $this->getData('galleys');
return is_null($galleys) ? [] : $galleys;
}

public function getSubmissionDate(): string
{
return $this->submissionDate;
return $this->getData('submissionDate');
}

public function getPublicationDate(): string
{
return $this->publicationDate;
return $this->getData('publicationDate');
}

public function getVersion(): string
{
return $this->version;
return $this->getData('version');
}

public function getEndorserName(): ?string
{
return $this->endorserName;
return $this->getData('endorserName');
}

public function getEndorserOrcid(): ?string
{
return $this->endorserOrcid;
return $this->getData('endorserOrcid');
}

public function getVersionJustification(): ?string
{
return $this->versionJustification;
return $this->getData('versionJustification');
}

public function setIsTranslation(bool $isTranslation)
{
$this->setData('isTranslation', $isTranslation);
}

public function getIsTranslation(): bool
{
return $this->getData('isTranslation') ?? false;
}

public function getCitation(): ?string
{
return $this->getData('citation');
}
}
52 changes: 34 additions & 18 deletions classes/SubmissionPressFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use APP\facades\Repo;
use APP\file\PublicFileManager;
use APP\publication\Publication;
use APP\core\Application;
use PKP\plugins\PluginRegistry;
use APP\plugins\generic\titlePageForPreprint\classes\SubmissionPress;
use APP\plugins\generic\titlePageForPreprint\classes\SubmissionModel;
use APP\plugins\generic\titlePageForPreprint\classes\GalleyAdapterFactory;
Expand All @@ -24,24 +26,25 @@ public function createSubmissionPress($submission, $publication, $context): Subm
$submissionGalleys[] = $galleyAdapterFactory->createGalleyAdapter($submission, $galley);
}

return new SubmissionPress(
new SubmissionModel(
$dataPress['title'],
$dataPress['status'],
$dataPress['doi'],
$dataPress['doiJournal'],
$dataPress['authors'],
$dataPress['submissionDate'],
$dataPress['publicationDate'],
$dataPress['endorserName'],
$dataPress['endorserOrcid'],
$dataPress['version'],
$dataPress['versionJustification'],
$submissionGalleys
),
$checklist,
$logoPath
);
$submissionModel = new SubmissionModel();
$submissionModel->setAllData([
'title' => $dataPress['title'],
'status' => $dataPress['status'],
'doi' => $dataPress['doi'],
'doiJournal' => $dataPress['doiJournal'],
'authors' => $dataPress['authors'],
'submissionDate' => $dataPress['submissionDate'],
'publicationDate' => $dataPress['publicationDate'],
'endorserName' => $dataPress['endorserName'],
'endorserOrcid' => $dataPress['endorserOrcid'],
'version' => $dataPress['version'],
'versionJustification' => $dataPress['versionJustification'],
'isTranslation' => $dataPress['isTranslation'],
'citation' => $dataPress['citation'],
'galleys' => $submissionGalleys
]);

return new SubmissionPress($submissionModel, $checklist, $logoPath);
}

private function getContextChecklist($context): array
Expand Down Expand Up @@ -99,6 +102,9 @@ private function getDataForPress($submission, $publication)
$datePublished = strtotime($publication->getData('datePublished'));
$data['publicationDate'] = date('Y-m-d', $datePublished);

$data['isTranslation'] = !is_null($publication->getData('originalDocumentDoi'));
$data['citation'] = ($data['isTranslation'] ? $this->getSubmissionCitation($submission) : '');

$data['endorserName'] = $publication->getData('endorserName');
$data['endorserOrcid'] = $publication->getData('endorserOrcid');

Expand All @@ -108,4 +114,14 @@ private function getDataForPress($submission, $publication)

return $data;
}

private function getSubmissionCitation($submission)
{
$request = Application::get()->getRequest();
$cslPlugin = PluginRegistry::getPlugin('generic', 'citationstylelanguageplugin');

$citation = $cslPlugin->getCitation($request, $submission, 'apa');

return $citation;
}
}
9 changes: 7 additions & 2 deletions classes/TitlePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,20 @@ private function generateTitlePage(): string
$titlePage->Write(0, __('plugins.generic.titlePageForPreprint.publicationDate', ['postDate' => $this->submission->getPublicationDate(), 'version' => $this->submission->getVersion()], $this->locale), '', 0, 'JUSTIFY', true, 0, false, false, 0);
$titlePage->Write(0, __('plugins.generic.titlePageForPreprint.dateFormat', [], $this->locale), '', 0, 'JUSTIFY', true, 0, false, false, 0);

if ($this->submission->getIsTranslation()) {
$titlePage->Ln(5);
$titlePage->writeHTML(__('plugins.generic.titlePageForPreprint.citation', ['citation' => $this->submission->getCitation()], $this->locale));
}

$endorserName = $this->submission->getEndorserName();
$endorserOrcid = $this->submission->getEndorserOrcid();
if(!is_null($endorserOrcid) && !is_null($endorserName)) {
if (!is_null($endorserOrcid) && !is_null($endorserName)) {
$titlePage->Ln(5);
$titlePage->writeHTML(__('plugins.generic.titlePageForPreprint.endorsement', ['endorserName' => $endorserName, 'endorserOrcid' => $endorserOrcid], $this->locale));
}

$versionJustification = $this->submission->getVersionJustification();
if($this->submission->getVersion() > 1 && !is_null($versionJustification)) {
if ($this->submission->getVersion() > 1 && !is_null($versionJustification)) {
$versionJustification = __('plugins.generic.titlePageForPreprint.versionJustification', [], $this->locale) . ": " . $versionJustification;
$titlePage->Ln(5);
$titlePage->Write(0, $versionJustification, '', 0, 'JUSTIFY', true, 0, false, false, 0);
Expand Down
2 changes: 1 addition & 1 deletion classes/TitlePageRequirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function checkRequirements()

private function checkPdfManipulator()
{
if(!file_exists(self::CPDF_PATH)) {
if (!file_exists(self::CPDF_PATH)) {
$this->showMissingRequirementNotification('plugins.generic.titlePageForPreprint.requirements.pdfManipulatorMissing');
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions locale/en/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ msgstr ""
"The moderation of this preprint received the endorsement of:<br>"
"{$endorserName} (ORCID: <a href=\"{$endorserOrcid}\">{$endorserOrcid}</a>)"

msgid "plugins.generic.titlePageForPreprint.citation"
msgstr ""
"How to cite this translation:"
"{$citation}"

msgid "plugins.generic.titlePageForPreprint.versionJustification"
msgstr "Version justification"

Expand Down
5 changes: 5 additions & 0 deletions locale/es/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ msgstr ""
"La moderación de este preprint recibió lo endoso de:<br>"
"{$endorserName} (ORCID: <a href=\"{$endorserOrcid}\">{$endorserOrcid}</a>)"

msgid "plugins.generic.titlePageForPreprint.citation"
msgstr ""
"Cómo citar esta traducción:"
"{$citation}"

msgid "plugins.generic.titlePageForPreprint.versionJustification"
msgstr "Justificación de la versión"

Expand Down
5 changes: 5 additions & 0 deletions locale/pt_BR/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ msgstr ""
"A moderação deste preprint recebeu o endosso de:<br>"
"{$endorserName} (ORCID: <a href=\"{$endorserOrcid}\">{$endorserOrcid}</a>)"

msgid "plugins.generic.titlePageForPreprint.citation"
msgstr ""
"Como citar esta tradução:"
"{$citation}"

msgid "plugins.generic.titlePageForPreprint.versionJustification"
msgstr "Justificativa da versão"

Expand Down
25 changes: 25 additions & 0 deletions tests/PdfHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PKP\tests\PKPTestCase;
use PKP\db\DAORegistry;
use PKP\submissionFile\SubmissionFile;
use APP\plugins\generic\titlePageForPreprint\classes\SubmissionModel;
use APP\plugins\generic\titlePageForPreprint\classes\Translator;

class PdfHandlingTest extends PKPTestCase
Expand Down Expand Up @@ -33,6 +34,8 @@ class PdfHandlingTest extends PKPTestCase
protected $endorserOrcid = 'https://orcid.org/0123-4567-89AB-CDEF';
protected $version = "1";
protected $versionJustification = 'Nova versão criada para corrigir erros de ortografia';
protected $isTranslation = false;
protected $citation = 'Silva, C. & Carlos, J. (2024). Thus spoke Zarathustra. Public Knowledge Preprint Server';

protected function setUp(): void
{
Expand Down Expand Up @@ -63,6 +66,28 @@ protected function tearDown(): void
}
}

protected function getSubmissionForTests(): SubmissionModel
{
$submission = new SubmissionModel();
$submission->setAllData([
'title' => $this->title,
'status' => $this->status,
'doi' => $this->doi,
'doiJournal' => $this->doiJournal,
'authors' => $this->authors,
'submissionDate' => $this->submissionDate,
'publicationDate' => $this->publicationDate,
'endorserName' => $this->endorserName,
'endorserOrcid' => $this->endorserOrcid,
'version' => $this->version,
'versionJustification' => $this->versionJustification,
'isTranslation' => $this->isTranslation,
'citation' => $this->citation,
]);

return $submission;
}

public function testDummy(): void
{
$this->assertTrue(true);
Expand Down
14 changes: 8 additions & 6 deletions tests/SubmissionPressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use APP\plugins\generic\titlePageForPreprint\tests\PdfHandlingTest;
use APP\plugins\generic\titlePageForPreprint\classes\GalleyAdapter;
use APP\plugins\generic\titlePageForPreprint\classes\SubmissionFileUpdater;
use APP\plugins\generic\titlePageForPreprint\classes\SubmissionModel;
use APP\plugins\generic\titlePageForPreprint\classes\SubmissionPress;
use APP\plugins\generic\titlePageForPreprint\classes\Pdf;

Expand All @@ -17,8 +16,8 @@ private function buildMockGalleyAdapter($args): GalleyAdapter
->getMock();

$mockGalley->expects($this->any())
->method('getFullFilePath')
->will($this->returnValue($args[0]));
->method('getFullFilePath')
->will($this->returnValue($args[0]));

return $mockGalley;
}
Expand All @@ -36,7 +35,8 @@ public function testInsertsCorrectlySingleGalley(): void
{
$galleyPath = $this->pathOfTestPdf;
$galley = $this->buildMockGalleyAdapter(array($galleyPath, $this->locale, 1, 2));
$submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, array($galley));
$submission = $this->getSubmissionForTests();
$submission->setData('galleys', [$galley]);
$press = new SubmissionPress($submission, $this->checklist, $this->logo);

$press->insertTitlePage($this->buildMockSubmissionFileUpdater());
Expand All @@ -51,7 +51,8 @@ public function testInsertsCorrectlyMultipleGalleys(): void
$secondGalleyPath = $this->pathOfTestPdf2;
$firstGalley = $this->buildMockGalleyAdapter(array($fistGalleyPath, $this->locale, 2, 2));
$secondGalley = $this->buildMockGalleyAdapter(array($secondGalleyPath, "en", 3, 2));
$submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, array($firstGalley, $secondGalley));
$submission = $this->getSubmissionForTests();
$submission->setData('galleys', [$firstGalley, $secondGalley]);

$press = new SubmissionPress($submission, $this->checklist, $this->logo);
$press->insertTitlePage($this->buildMockSubmissionFileUpdater());
Expand All @@ -69,7 +70,8 @@ public function testMustIgnoreNotPdfFiles(): void
$secondGalleyPath = PdfHandlingTest::TESTS_DIRECTORY . PdfHandlingTest::ASSETS_DIRECTORY . "fileNotPdf.odt";
$firstGalley = $this->buildMockGalleyAdapter(array($fistGalleyPath, $this->locale, 4, 2));
$secondGalley = $this->buildMockGalleyAdapter(array($secondGalleyPath, $this->locale, 5, 2));
$submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, array($firstGalley, $secondGalley));
$submission = $this->getSubmissionForTests();
$submission->setData('galleys', [$firstGalley, $secondGalley]);

$hashOfNotPdfGalley = md5_file($secondGalleyPath);
$press = new SubmissionPress($submission, $this->checklist, $this->logo);
Expand Down
Loading

0 comments on commit 5dbce74

Please sign in to comment.