-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'adaptToOPS-3_4_0' into 'main'
Port plugin to OPS 3.4 See merge request softwares-pkp/plugins_ojs/scieloModerationStages!17
- Loading branch information
Showing
30 changed files
with
572 additions
and
867 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
/** | ||
* @file plugins/reports/scieloModerationStages/ScieloModerationStagesPlugin.inc.php | ||
* | ||
* Copyright (c) 2022 Lepidus Tecnologia | ||
* Copyright (c) 2022 SciELO | ||
* Copyright (c) 2022 - 2024 Lepidus Tecnologia | ||
* Copyright (c) 2022 - 2024 SciELO | ||
* Distributed under the GNU GPL v3. For full terms see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt. | ||
* | ||
* @class ScieloModerationStagesPlugin | ||
|
@@ -13,45 +13,56 @@ | |
* @brief SciELO Moderation Stages Plugin | ||
*/ | ||
|
||
import('lib.pkp.classes.plugins.GenericPlugin'); | ||
import('plugins.generic.scieloModerationStages.classes.ModerationStage'); | ||
import('plugins.generic.scieloModerationStages.classes.ModerationStageRegister'); | ||
namespace APP\plugins\generic\scieloModerationStages; | ||
|
||
define('SCIELO_BRASIL_EMAIL', '[email protected]'); | ||
use PKP\plugins\GenericPlugin; | ||
use PKP\plugins\Hook; | ||
use APP\core\Application; | ||
use APP\template\TemplateManager; | ||
use APP\facades\Repo; | ||
use PKP\security\Role; | ||
use PKP\db\DAORegistry; | ||
use Illuminate\Support\Facades\Event; | ||
use APP\plugins\generic\scieloModerationStages\classes\ModerationStage; | ||
use APP\plugins\generic\scieloModerationStages\classes\ModerationStageRegister; | ||
use APP\plugins\generic\scieloModerationStages\classes\observers\listeners\AssignFirstModerationStage; | ||
|
||
class ScieloModerationStagesPlugin extends GenericPlugin | ||
{ | ||
private const SCIELO_BRASIL_EMAIL = '[email protected]'; | ||
|
||
public function register($category, $path, $mainContextId = null) | ||
{ | ||
$success = parent::register($category, $path, $mainContextId); | ||
|
||
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) { | ||
return true; | ||
if (Application::isUnderMaintenance()) { | ||
return $success; | ||
} | ||
|
||
if ($success && $this->getEnabled($mainContextId)) { | ||
HookRegistry::register('Schema::get::submission', array($this, 'addOurFieldsToSubmissionSchema')); | ||
HookRegistry::register('submissionsubmitstep4form::execute', array($this, 'setSubmissionFirstModerationStage')); | ||
HookRegistry::register('addparticipantform::display', array($this, 'addFieldsAssignForm')); | ||
HookRegistry::register('addparticipantform::execute', array($this, 'sendSubmissionToNextModerationStage')); | ||
HookRegistry::register('queryform::display', array($this, 'hideParticipantsOnDiscussionOpening')); | ||
Event::subscribe(new AssignFirstModerationStage()); | ||
|
||
Hook::add('Schema::get::submission', [$this, 'addOurFieldsToSubmissionSchema']); | ||
Hook::add('addparticipantform::display', [$this, 'addStageAdvanceToAssignForm']); | ||
Hook::add('addparticipantform::execute', [$this, 'sendSubmissionToNextModerationStage']); | ||
Hook::add('queryform::display', [$this, 'hideParticipantsOnDiscussionOpening']); | ||
|
||
HookRegistry::register('Template::Workflow::Publication', array($this, 'addToWorkflowTabs')); | ||
HookRegistry::register('Template::Workflow', array($this, 'addCurrentStageStatus')); | ||
HookRegistry::register('LoadComponentHandler', array($this, 'setupScieloModerationStagesHandler')); | ||
Hook::add('Template::Workflow::Publication', [$this, 'addToWorkflowTabs']); | ||
Hook::add('Template::Workflow', [$this, 'addCurrentStageStatusToWorkflow']); | ||
Hook::add('LoadComponentHandler', [$this, 'setupScieloModerationStagesHandler']); | ||
|
||
Hook::add('TemplateManager::display', [$this, 'addJavaScriptAndStylesheet']); | ||
|
||
HookRegistry::register('TemplateManager::display', array($this, 'addJavaScriptAndStylesheet')); | ||
$this->addHandlerURLToJavaScript(); | ||
} | ||
|
||
return $success; | ||
} | ||
|
||
public function addHandlerURLToJavaScript() | ||
{ | ||
$request = Application::get()->getRequest(); | ||
$templateMgr = TemplateManager::getManager($request); | ||
$handlerUrl = $request->getDispatcher()->url($request, ROUTE_COMPONENT) . 'plugins/generic/scielo-moderation-stages/controllers/scielo-moderation-stages/'; | ||
$handlerUrl = $request->getDispatcher()->url($request, Application::ROUTE_COMPONENT, null, 'plugins.generic.scieloModerationStages.controllers.ScieloModerationStagesHandler'); | ||
$data = ['moderationStagesHandlerUrl' => $handlerUrl]; | ||
|
||
$templateMgr->addJavaScript('ModerationStagesHandler', 'app = ' . json_encode($data) . ';', ['contexts' => 'backend', 'inline' => true]); | ||
|
@@ -124,18 +135,9 @@ public function addOurFieldsToSubmissionSchema($hookName, $params) | |
return false; | ||
} | ||
|
||
public function setSubmissionFirstModerationStage($hookName, $params) | ||
{ | ||
$submission = $params[0]->submission; | ||
$moderationStage = new ModerationStage($submission); | ||
$moderationStage->setToFirstStage(); | ||
$moderationStageRegister = new ModerationStageRegister(); | ||
$moderationStageRegister->registerModerationStageOnSubmissionLog($moderationStage); | ||
} | ||
|
||
public function addFieldsAssignForm($hookName, $params) | ||
public function addStageAdvanceToAssignForm($hookName, $params) | ||
{ | ||
$request = PKPApplication::get()->getRequest(); | ||
$request = Application::get()->getRequest(); | ||
$templateMgr = TemplateManager::getManager($request); | ||
|
||
$submission = $params[0]->getSubmission(); | ||
|
@@ -171,7 +173,7 @@ public function addToWorkflowTabs($hookName, $params) | |
{ | ||
$templateMgr = &$params[1]; | ||
$output = &$params[2]; | ||
$submission = $templateMgr->get_template_vars('submission'); | ||
$submission = $templateMgr->getTemplateVars('submission'); | ||
|
||
$moderationStage = new ModerationStage($submission); | ||
if ($moderationStage->submissionStageExists()) { | ||
|
@@ -198,30 +200,30 @@ public function addToWorkflowTabs($hookName, $params) | |
} | ||
} | ||
|
||
public function addCurrentStageStatus($hookName, $params) | ||
public function addCurrentStageStatusToWorkflow($hookName, $params) | ||
{ | ||
$templateMgr = &$params[1]; | ||
$submission = $templateMgr->get_template_vars('submission'); | ||
$submission = $templateMgr->getTemplateVars('submission'); | ||
|
||
if (!is_null($submission->getData('currentModerationStage'))) { | ||
$moderationStage = new ModerationStage($submission); | ||
|
||
$templateMgr->assign('currentStageName', $moderationStage->getCurrentStageName()); | ||
$templateMgr->registerFilter("output", array($this, 'addCurrentStageStatusFilter')); | ||
$templateMgr->registerFilter("output", [$this, 'addCurrentStageStatusToWorkflowFilter']); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function addCurrentStageStatusFilter($output, $templateMgr) | ||
public function addCurrentStageStatusToWorkflowFilter($output, $templateMgr) | ||
{ | ||
if (preg_match('/<span[^>]+v-if="publicationList.length/', $output, $matches, PREG_OFFSET_CAPTURE)) { | ||
$posMatch = $matches[0][1]; | ||
|
||
$currentStageStatus = $templateMgr->fetch($this->getTemplateResource('currentStageStatus.tpl')); | ||
|
||
$output = substr_replace($output, $currentStageStatus, $posMatch, 0); | ||
$templateMgr->unregisterFilter('output', array($this, 'addCurrentStageStatusFilter')); | ||
$templateMgr->unregisterFilter('output', array($this, 'addCurrentStageStatusToWorkflowFilter')); | ||
} | ||
return $output; | ||
} | ||
|
@@ -233,24 +235,24 @@ public function getStyleSheet() | |
|
||
private function userIsAuthor($submission) | ||
{ | ||
$currentUser = \Application::get()->getRequest()->getUser(); | ||
$currentUser = Application::get()->getRequest()->getUser(); | ||
$currentUserAssignedRoles = array(); | ||
if ($currentUser) { | ||
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); | ||
$stageAssignmentsResult = $stageAssignmentDao->getBySubmissionAndUserIdAndStageId($submission->getId(), $currentUser->getId(), $submission->getData('stageId')); | ||
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); | ||
|
||
while ($stageAssignment = $stageAssignmentsResult->next()) { | ||
$userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId(), $submission->getData('contextId')); | ||
$userGroup = Repo::userGroup()->get($stageAssignment->getUserGroupId(), $submission->getData('contextId')); | ||
$currentUserAssignedRoles[] = (int) $userGroup->getRoleId(); | ||
} | ||
} | ||
|
||
return $currentUserAssignedRoles[0] == ROLE_ID_AUTHOR; | ||
return $currentUserAssignedRoles[0] == Role::ROLE_ID_AUTHOR; | ||
} | ||
|
||
public function sendSubmissionToNextModerationStage($hookName, $params) | ||
{ | ||
$request = PKPApplication::get()->getRequest(); | ||
$request = Application::get()->getRequest(); | ||
$form = $params[0]; | ||
$requestVars = $request->getUserVars(); | ||
|
||
|
@@ -275,19 +277,18 @@ public function hideParticipantsOnDiscussionOpening($hookName, $params) | |
$allParticipants = $templateMgr->getTemplateVars('allParticipants'); | ||
|
||
$query = $form->getQuery(); | ||
$submission = Services::get('submission')->get($query->getData('assocId')); | ||
$submission = Repo::submission()->get($query->getData('assocId')); | ||
|
||
if ($this->userIsAuthor($submission)) { | ||
$author = $request->getUser(); | ||
$newParticipantsList = []; | ||
$allowedUsersEmails = [ | ||
$author->getEmail(), | ||
SCIELO_BRASIL_EMAIL | ||
self::SCIELO_BRASIL_EMAIL | ||
]; | ||
|
||
foreach ($allParticipants as $participantId => $participantData) { | ||
$userDao = DAORegistry::getDAO('UserDAO'); | ||
$participant = $userDao->getById($participantId); | ||
$participant = Repo::user()->get($participantId); | ||
|
||
if (in_array($participant->getEmail(), $allowedUsersEmails)) { | ||
$newParticipantsList[$participantId] = $participantData; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace APP\plugins\generic\scieloModerationStages\classes; | ||
|
||
use APP\core\Application; | ||
use APP\facades\Repo; | ||
use PKP\core\Core; | ||
use PKP\security\Validation; | ||
use PKP\log\event\PKPSubmissionEventLogEntry; | ||
use APP\plugins\generic\scieloModerationStages\classes\ModerationStage; | ||
|
||
class ModerationStageRegister | ||
{ | ||
public function registerModerationStageOnDatabase(ModerationStage $stage) | ||
{ | ||
Repo::submission()->edit($stage->submission, []); | ||
} | ||
|
||
public function registerModerationStageOnSubmissionlog(ModerationStage $stage) | ||
{ | ||
$stageName = $stage->getCurrentStageName(); | ||
$submission = $stage->submission; | ||
|
||
$user = Application::get()->getRequest()->getUser(); | ||
|
||
$eventLog = Repo::eventLog()->newDataObject([ | ||
'assocType' => Application::ASSOC_TYPE_SUBMISSION, | ||
'assocId' => $submission->getId(), | ||
'eventType' => PKPSubmissionEventLogEntry::SUBMISSION_LOG_METADATA_UPDATE, | ||
'userId' => Validation::loggedInAs() ?? $user->getId(), | ||
'message' => __('plugins.generic.scieloModerationStages.log.submissionSentToModerationStage', ['moderationStageName' => $stageName]), | ||
'isTranslated' => true, | ||
'dateLogged' => Core::getCurrentDate(), | ||
]); | ||
Repo::eventLog()->add($eventLog); | ||
} | ||
} |
Oops, something went wrong.