-
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 'moderatorsFeedbackReminder330-695' into 'stable-3_3_0'
Envia lembretes de moderação a moderadores See merge request softwares-pkp/plugins_ojs/scieloModerationStages!18
- Loading branch information
Showing
13 changed files
with
595 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
import('lib.pkp.classes.form.Form'); | ||
|
||
class ScieloModerationStagesSettingsForm extends Form | ||
{ | ||
public const CONFIG_VARS = array( | ||
'preModerationTimeLimit' => 'int', | ||
); | ||
|
||
public $contextId; | ||
public $plugin; | ||
|
||
public function __construct($plugin, $contextId) | ||
{ | ||
$this->contextId = $contextId; | ||
$this->plugin = $plugin; | ||
parent::__construct($plugin->getTemplateResource('settingsForm.tpl')); | ||
|
||
$this->addCheck(new FormValidatorCustom($this, 'preModerationTimeLimit', 'required', 'plugins.generic.scieloModerationStages.settings.timeLimitError', function ($timeLimit) { | ||
return is_numeric($timeLimit) && intval($timeLimit) > 0; | ||
})); | ||
} | ||
|
||
public function initData() | ||
{ | ||
$contextId = $this->contextId; | ||
$plugin = &$this->plugin; | ||
|
||
foreach (self::CONFIG_VARS as $configVar => $type) { | ||
$this->setData($configVar, $plugin->getSetting($contextId, $configVar)); | ||
} | ||
} | ||
|
||
public function readInputData() | ||
{ | ||
$this->readUserVars(array_keys(self::CONFIG_VARS)); | ||
} | ||
|
||
public function fetch($request, $template = null, $display = false) | ||
{ | ||
$templateMgr = TemplateManager::getManager($request); | ||
$templateMgr->assign('pluginName', $this->plugin->getName()); | ||
$templateMgr->assign('applicationName', Application::get()->getName()); | ||
return parent::fetch($request, $template, $display); | ||
} | ||
|
||
public function execute(...$functionArgs) | ||
{ | ||
$plugin = &$this->plugin; | ||
$contextId = $this->contextId; | ||
|
||
foreach (self::CONFIG_VARS as $configVar => $type) { | ||
$plugin->updateSetting($contextId, $configVar, $this->getData($configVar), $type); | ||
} | ||
} | ||
} |
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,70 @@ | ||
<?php | ||
|
||
import('lib.pkp.classes.mail.Mail'); | ||
|
||
class ModerationReminderEmailBuilder | ||
{ | ||
private $context; | ||
private $moderator; | ||
private $submissions; | ||
|
||
public function __construct($context, $moderator, $submissions) | ||
{ | ||
$this->context = $context; | ||
$this->moderator = $moderator; | ||
$this->submissions = $submissions; | ||
} | ||
|
||
public function buildEmail(): Mail | ||
{ | ||
$email = new Mail(); | ||
|
||
$email->setFrom($this->context->getContactEmail(), $this->context->getContactName()); | ||
$email->addRecipient($this->moderator->getEmail(), $this->moderator->getFullName()); | ||
$email->addCc($this->context->getContactEmail(), $this->context->getContactName()); | ||
|
||
$email->setSubject(__('plugins.generic.scieloModerationStages.emails.moderationReminder.subject')); | ||
|
||
$bodyParams = [ | ||
'moderatorName' => $this->moderator->getFullName(), | ||
'submissions' => $this->getSubmissionsString() | ||
]; | ||
$email->setBody(__('plugins.generic.scieloModerationStages.emails.moderationReminder.body', $bodyParams)); | ||
|
||
return $email; | ||
} | ||
|
||
private function getSubmissionsString(): string | ||
{ | ||
$submissionsString = ''; | ||
$request = Application::get()->getRequest(); | ||
$dispatcher = Application::get()->getDispatcher(); | ||
$request->setDispatcher($dispatcher); | ||
|
||
foreach ($this->submissions as $submission) { | ||
$submissionLink = $request->getDispatcher()->url($request, ROUTE_PAGE, null, 'workflow', 'access', [$submission->getId()]); | ||
$submissionDaysString = $this->getSubmissionDaysString($submission); | ||
|
||
$submissionsString .= "<p><a href=\"$submissionLink\">$submissionLink</a> - $submissionDaysString</p>"; | ||
} | ||
|
||
return $submissionsString; | ||
} | ||
|
||
private function getSubmissionDaysString($submission): string | ||
{ | ||
$dateSubmitted = new DateTime($submission->getData('dateSubmitted')); | ||
$today = new DateTime(); | ||
$daysBetween = (int) $today->diff($dateSubmitted)->format('%a'); | ||
|
||
if ($daysBetween < 1) { | ||
return __('plugins.generic.scieloModerationStages.submissionMade.lessThanADayAgo'); | ||
} | ||
|
||
if ($daysBetween == 1) { | ||
return __('plugins.generic.scieloModerationStages.submissionMade.aDayAgo'); | ||
} | ||
|
||
return __('plugins.generic.scieloModerationStages.submissionMade.nDaysAgo', ['numberOfDays' => $daysBetween]); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
import('lib.pkp.classes.scheduledTask.ScheduledTask'); | ||
import('plugins.generic.scieloModerationStages.classes.ModerationStage'); | ||
import('plugins.generic.scieloModerationStages.classes.ModerationStageDAO'); | ||
import('plugins.generic.scieloModerationStages.classes.ModerationReminderEmailBuilder'); | ||
|
||
class SendModerationReminders extends ScheduledTask | ||
{ | ||
private $plugin; | ||
|
||
public function executeActions() | ||
{ | ||
PluginRegistry::loadCategory('generic'); | ||
$this->plugin = PluginRegistry::getPlugin('generic', 'scielomoderationstagesplugin'); | ||
|
||
$context = Application::get()->getRequest()->getContext(); | ||
$responsiblesAssignments = $this->getResponsiblesAssignments($context->getId()); | ||
$preModerationAssignments = $this->filterPreModerationAssignments($responsiblesAssignments); | ||
|
||
if (empty($preModerationAssignments)) { | ||
return true; | ||
} | ||
|
||
$usersWithOverduePreModeration = $this->getUsersWithOverduePreModeration($context->getId(), $preModerationAssignments); | ||
$mapModeratorsAndOverdueSubmissions = $this->mapModeratorsAndOverdueSubmissions($usersWithOverduePreModeration, $preModerationAssignments); | ||
|
||
foreach ($mapModeratorsAndOverdueSubmissions as $userId => $submissions) { | ||
$moderator = DAORegistry::getDAO('UserDAO')->getById($userId); | ||
$moderationReminderEmailBuilder = new ModerationReminderEmailBuilder($context, $moderator, $submissions); | ||
|
||
$reminderEmail = $moderationReminderEmailBuilder->buildEmail(); | ||
$reminderEmail->send(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private function getResponsiblesAssignments(int $contextId) | ||
{ | ||
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); | ||
$contextUserGroups = $userGroupDao->getByContextId($contextId)->toArray(); | ||
|
||
foreach ($contextUserGroups as $userGroup) { | ||
$userGroupAbbrev = strtolower($userGroupDao->getSetting($userGroup->getId(), 'abbrev', 'en_US')); | ||
|
||
if ($userGroupAbbrev === 'resp') { | ||
$responsiblesUserGroup = $userGroup; | ||
break; | ||
} | ||
} | ||
|
||
if (!$responsiblesUserGroup) { | ||
return []; | ||
} | ||
|
||
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); | ||
$responsiblesAssignments = $stageAssignmentDao->getByUserGroupId($responsiblesUserGroup->getId(), $contextId); | ||
|
||
return $responsiblesAssignments->toArray(); | ||
} | ||
|
||
private function filterPreModerationAssignments($responsiblesAssignments): array | ||
{ | ||
$moderationStageDao = new ModerationStageDAO(); | ||
$preModerationAssignments = []; | ||
|
||
foreach ($responsiblesAssignments as $assignment) { | ||
$submissionId = $assignment->getData('submissionId'); | ||
$submissionModerationStage = $moderationStageDao->getSubmissionModerationStage($submissionId); | ||
|
||
if ($submissionModerationStage === SCIELO_MODERATION_STAGE_CONTENT) { | ||
$preModerationAssignments[] = $assignment; | ||
} | ||
} | ||
|
||
return $preModerationAssignments; | ||
} | ||
|
||
private function getUsersWithOverduePreModeration($contextId, $preModerationAssignments): array | ||
{ | ||
$usersIds = []; | ||
$preModerationTimeLimit = $this->plugin->getSetting($contextId, 'preModerationTimeLimit'); | ||
$moderationStageDao = new ModerationStageDAO(); | ||
|
||
foreach ($preModerationAssignments as $assignment) { | ||
$submissionId = $assignment->getData('submissionId'); | ||
$preModerationIsOverdue = $moderationStageDao->getPreModerationIsOverdue($submissionId, $preModerationTimeLimit); | ||
|
||
if ($preModerationIsOverdue) { | ||
$usersIds[] = $assignment->getData('userId'); | ||
} | ||
} | ||
|
||
return $usersIds; | ||
} | ||
|
||
private function mapModeratorsAndOverdueSubmissions($moderators, $preModerationAssignments) | ||
{ | ||
$moderatorsMap = []; | ||
$submissionDao = DAORegistry::getDAO('SubmissionDAO'); | ||
|
||
foreach ($moderators as $moderatorId) { | ||
foreach ($preModerationAssignments as $assignment) { | ||
if ($moderatorId != $assignment->getData('userId')) { | ||
continue; | ||
} | ||
|
||
$submission = $submissionDao->getById($assignment->getData('submissionId')); | ||
|
||
if (isset($moderatorsMap[$moderatorId])) { | ||
$moderatorsMap[$moderatorId] = array_merge($moderatorsMap[$moderatorId], [$submission]); | ||
} else { | ||
$moderatorsMap[$moderatorId] = [$submission]; | ||
} | ||
} | ||
} | ||
|
||
return $moderatorsMap; | ||
} | ||
} |
Oops, something went wrong.