Skip to content

Commit

Permalink
Merge branch 'adaptTo3_4-607' into 'main'
Browse files Browse the repository at this point in the history
Adapts plugin to OJS/OPS 3.4

See merge request softwares-pkp/plugins_ojs/relatorioscielo!21
  • Loading branch information
JhonathanLepidus committed Nov 13, 2023
2 parents 85c67e2 + db182b6 commit 8427f30
Show file tree
Hide file tree
Showing 46 changed files with 1,554 additions and 1,205 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ include:
ref: main
file:
- 'templates/groups/pkp_plugin.yml'
- 'templates/groups/ops_plugins_unit_tests_model.yml'
- 'templates/groups/ojs_3_4_plugins_unit_tests_model.yml'
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file plugins/reports/scieloSubmissionsReport/ScieloSubmissionsReportForm.inc.php
*
Expand All @@ -10,9 +11,19 @@
*
* @brief SciELO Submissions report Form
*/
import('lib.pkp.classes.form.Form');
import('plugins.reports.scieloSubmissionsReport.classes.ClosedDateInterval');
import('plugins.reports.scieloSubmissionsReport.classes.ScieloSubmissionsReportFactory');

namespace APP\plugins\reports\scieloSubmissionsReport;

use APP\core\Application;
use APP\facades\Repo;
use APP\plugins\reports\scieloSubmissionsReport\classes\ClosedDateInterval;
use APP\plugins\reports\scieloSubmissionsReport\classes\ScieloSubmissionsReportFactory;
use APP\template\TemplateManager;
use PKP\core\PKPString;
use PKP\facades\Locale;
use PKP\form\Form;
use PKP\form\validation\FormValidatorCSRF;
use PKP\form\validation\FormValidatorPost;

class ScieloSubmissionsReportForm extends Form
{
Expand All @@ -30,6 +41,7 @@ class ScieloSubmissionsReportForm extends Form

/**
* Constructor
*
* @param $plugin ReviewersReport Manual payment plugin
*/
public function __construct($plugin)
Expand All @@ -38,7 +50,7 @@ public function __construct($plugin)
$this->application = substr(Application::getName(), 0, 3);
$request = Application::get()->getRequest();
$this->contextId = $request->getContext()->getId();
$this->sections = array();
$this->sections = [];
$this->submissionDateInterval = null;
$this->finalDecisionDateInterval = null;
$this->includeViews = false;
Expand Down Expand Up @@ -101,15 +113,15 @@ private function emitHttpHeaders($request)
{
$context = $request->getContext();
header('content-type: text/comma-separated-values');
$acronym = PKPString::regexp_replace("/[^A-Za-z0-9 ]/", '', $context->getLocalizedAcronym());
$acronym = PKPString::regexp_replace('/[^A-Za-z0-9 ]/', '', $context->getLocalizedAcronym());
header('content-disposition: attachment; filename=submissions' . $acronym . '-' . date('YmdHis') . '.csv');
}

public function generateReport($request)
{
$this->emitHttpHeaders($request);

$locale = AppLocale::getLocale();
$locale = Locale::getLocale();
$scieloSubmissionsReportFactory = new ScieloSubmissionsReportFactory($this->application, $this->contextId, $this->sections, $this->submissionDateInterval, $this->finalDecisionDateInterval, $locale, $this->includeViews);
$scieloSubmissionsReport = $scieloSubmissionsReportFactory->createReport();

Expand All @@ -124,14 +136,14 @@ public function display($request = null, $template = null, $args = null)

$templateManager = TemplateManager::getManager();
$url = $request->getBaseUrl() . '/' . $this->plugin->getPluginPath() . '/templates/scieloSubmissionsStyleSheet.css';
$templateManager->addStyleSheet('scieloSubmissionsStyleSheet', $url, array(
$templateManager->addStyleSheet('scieloSubmissionsStyleSheet', $url, [
'priority' => STYLE_SEQUENCE_CORE,
'contexts' => 'backend',
));
]);
$templateManager->assign('application', $this->application);
$templateManager->assign('sections', $sections);
$templateManager->assign('sections_options', $sections_options);
$templateManager->assign('years', array(0=>$args[0], 1=>$args[1]));
$templateManager->assign('years', [0 => $args[0], 1 => $args[1]]);
$templateManager->assign([
'breadcrumbs' => [
[
Expand All @@ -152,9 +164,9 @@ public function display($request = null, $template = null, $args = null)

private function getAvailableSections($contextId)
{
$sections = Services::get('section')->getSectionList($contextId);
$sections = Repo::section()->getSectionList($contextId);

$listOfSections = array();
$listOfSections = [];
foreach ($sections as $section) {
$listOfSections[$section['id']] = $section['title'];
}
Expand All @@ -163,11 +175,10 @@ private function getAvailableSections($contextId)

public function getSectionsOptions($contextId, $sections)
{
$sectionDao = DAORegistry::getDAO('SectionDAO');
$sectionsOptions = array();
$sectionsOptions = [];

foreach ($sections as $sectionId => $sectionName) {
$sectionObject = $sectionDao->getById($sectionId, $contextId);
$sectionObject = Repo::section()->get($sectionId, $contextId);
if ($sectionObject->getMetaReviewed() == 1) {
$sectionsOptions[$sectionObject->getLocalizedTitle()] = $sectionObject->getLocalizedTitle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,37 @@
* Distributed under the GNU GPL v3. For full terms see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt
*
* @class ScieloSubmissionsReportPlugin
*
* @ingroup plugins_reports_scieloSubmissions
*
* @brief SciELO Submissions report plugin
*/

import('lib.pkp.classes.plugins.ReportPlugin');
import('classes.submission.Submission');
import('plugins.reports.scieloSubmissionsReport.classes.ClosedDateInterval');
namespace APP\plugins\reports\scieloSubmissionsReport;

use APP\plugins\reports\scieloSubmissionsReport\classes\form\ScieloSubmissionsReportSettingsForm;
use PKP\config\Config;
use PKP\core\JSONMessage;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\plugins\Hook;
use PKP\plugins\ReportPlugin;

class ScieloSubmissionsReportPlugin extends ReportPlugin
{
/**
* @copydoc Plugin::register()
*
* @param null|mixed $mainContextId
*/
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);

if ($success && Config::getVar('general', 'installed')) {
$this->import('ScieloSubmissionsReportForm');
$this->addLocaleData();

HookRegistry::register('AcronPlugin::parseCronTab', array($this, 'addPluginTasksToCrontab'));
Hook::add('AcronPlugin::parseCronTab', [$this, 'addPluginTasksToCrontab']);
}
return $success;
}
Expand All @@ -50,46 +58,44 @@ public function getDescription()
return __('plugins.reports.scieloSubmissionsReport.description');
}

public function addPluginTasksToCrontab($hookName, $args) {
$taskFilesPath =& $args[0];
public function addPluginTasksToCrontab($hookName, $args)
{
$taskFilesPath = &$args[0];
$taskFilesPath[] = $this->getPluginPath() . DIRECTORY_SEPARATOR . 'scheduledTasks.xml';
return false;
}
}

public function display($args, $request)
{
AppLocale::requireComponents(LOCALE_COMPONENT_APP_EDITOR, LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_PKP_READER);
$form = new ScieloSubmissionsReportForm($this);
$form->initData();
$requestHandler = new PKPRequest();
if ($requestHandler->isPost($request)) {
$reportParams = $requestHandler->getUserVars($request);
if ($request->isPost($request)) {
$reportParams = $request->getUserVars();
$validationResult = $form->validateReportData($reportParams);
if ($validationResult) {
$form->generateReport($request);
}
} else {
$dateStart = date("Y-01-01");
$dateEnd = date("Y-m-d");
$form->display($request, 'scieloSubmissionsReportPlugin.tpl', array($dateStart, $dateEnd));
$dateStart = date('Y-01-01');
$dateEnd = date('Y-m-d');
$form->display($request, 'scieloSubmissionsReportPlugin.tpl', [$dateStart, $dateEnd]);
}
}

public function getActions($request, $actionArgs)
{
$router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal');
$actions = array_merge(
$this->getEnabled()?array(
$actions = array_merge(
$this->getEnabled() ? [
new LinkAction(
'pluginSettings',
new AjaxModal(
$router->url($request, null, null, 'manage', null, array('verb' => 'pluginSettings', 'plugin' => $this->getName(), 'category' => 'reports')),
$router->url($request, null, null, 'manage', null, ['verb' => 'pluginSettings', 'plugin' => $this->getName(), 'category' => 'reports']),
__('plugins.reports.scieloSubmissionsReport.settings.title')
),
__('manager.plugins.settings'),
)
):array(),
] : [],
parent::getActions($request, $actionArgs)
);
return $actions;
Expand All @@ -102,7 +108,6 @@ public function manage($args, $request)

switch ($request->getUserVar('verb')) {
case 'pluginSettings':
$this->import('classes.form.ScieloSubmissionsReportSettingsForm');
$form = new ScieloSubmissionsReportSettingsForm($this, $contextId);
if ($request->getUserVar('save')) {
$form->readInputData();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php

namespace APP\plugins\reports\scieloSubmissionsReport\classes;

use DateTime;

class ClosedDateInterval
{
private $beginningDate;
private $endDate;
private const DAY_BEGINNING = " 00:00:00";
private const DAY_ENDING = " 23:59:59";
private const DAY_BEGINNING = ' 00:00:00';
private const DAY_ENDING = ' 23:59:59';

public function __construct(string $beginningDate, string $endDate)
{
Expand Down
2 changes: 2 additions & 0 deletions classes/FinalDecision.inc.php → classes/FinalDecision.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace APP\plugins\reports\scieloSubmissionsReport\classes;

class FinalDecision
{
private $decision;
Expand Down
10 changes: 5 additions & 5 deletions classes/ScieloArticle.inc.php → classes/ScieloArticle.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

import('plugins.reports.scieloSubmissionsReport.classes.ScieloSubmission');
namespace APP\plugins\reports\scieloSubmissionsReport\classes;

class ScieloArticle extends ScieloSubmission
{
Expand All @@ -18,13 +18,13 @@ public function __construct(int $id, string $title, string $submitter, string $s
$this->sectionEditor = $sectionEditor;
$this->reviews = $reviews;
$this->lastDecision = $lastDecision;
$this->noEditors = __("plugins.reports.scieloSubmissionsReport.warning.noEditors");
$this->noDecision = __("plugins.reports.scieloSubmissionsReport.warning.noDecision");
$this->noEditors = __('plugins.reports.scieloSubmissionsReport.warning.noEditors');
$this->noDecision = __('plugins.reports.scieloSubmissionsReport.warning.noDecision');
}

public function asRecord(): array
{
return array($this->id, $this->title, $this->submitter, $this->submitterCountry, $this->dateSubmitted, $this->daysUntilStatusChange, $this->status, $this->getJournalEditors(), $this->getSectionEditor(), $this->authorsAsRecord(), $this->section, $this->language, $this->getReviews(), $this->lastDecision, $this->finalDecision, $this->finalDecisionDate, $this->getTimeUnderReview(), $this->getTimeBetweenSubmissionAndFinalDecision());
return [$this->id, $this->title, $this->submitter, $this->submitterCountry, $this->dateSubmitted, $this->daysUntilStatusChange, $this->status, $this->getJournalEditors(), $this->getSectionEditor(), $this->authorsAsRecord(), $this->section, $this->language, $this->getReviews(), $this->lastDecision, $this->finalDecision, $this->finalDecisionDate, $this->getTimeUnderReview(), $this->getTimeBetweenSubmissionAndFinalDecision()];
}

public function getJournalEditors(): string
Expand All @@ -39,7 +39,7 @@ public function getSectionEditor(): string

public function getReviews(): string
{
return $this->implodeEmptyFields($this->reviews, "");
return $this->implodeEmptyFields($this->reviews, '');
}

public function hasReviews(): bool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?php

import('plugins.reports.scieloSubmissionsReport.classes.ScieloSubmissionFactory');
import('plugins.reports.scieloSubmissionsReport.classes.ScieloArticle');
import('plugins.reports.scieloSubmissionsReport.classes.ScieloArticlesDAO');
namespace APP\plugins\reports\scieloSubmissionsReport\classes;

class ScieloArticleFactory extends ScieloSubmissionFactory
{
protected $application = 'ojs';

public function createSubmission(int $submissionId, string $locale)
{
$scieloArticlesDAO = new ScieloArticlesDAO();
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, $locale);
$scieloArticlesDAO = app(ScieloArticlesDAO::class);
$submission = $scieloArticlesDAO->getSubmission($submissionId);
$publicationId = $submission['current_publication_id'];

Expand All @@ -25,7 +22,7 @@ public function createSubmission(int $submissionId, string $locale)
$sectionName = $scieloArticlesDAO->getPublicationSection($publicationId, $locale);
$language = $submission['locale'];

list($finalDecision, $finalDecisionDate) = $this->retrieveFinalDecisionAndFinalDecisionDate($scieloArticlesDAO, $submissionId, $locale);
[$finalDecision, $finalDecisionDate] = $this->retrieveFinalDecisionAndFinalDecisionDate($scieloArticlesDAO, $submissionId, $locale);
$editors = $scieloArticlesDAO->getEditors($submissionId);
$sectionEditor = $scieloArticlesDAO->getSectionEditor($submissionId);
$reviews = $scieloArticlesDAO->getReviews($submissionId);
Expand Down
Loading

0 comments on commit 8427f30

Please sign in to comment.