Skip to content

Commit

Permalink
Fixes errors in merge request
Browse files Browse the repository at this point in the history
Issue: documentacao-e-tarefas/scielo#714

Signed-off-by: Jhon <[email protected]>
  • Loading branch information
JhonathanLepidus committed Nov 5, 2024
1 parent 17050ec commit 21cd771
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
76 changes: 67 additions & 9 deletions classes/tasks/SendModerationReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace APP\plugins\generic\scieloModerationStages\classes\tasks;

use DateTime;
use PKP\scheduledTask\ScheduledTask;
use PKP\plugins\PluginRegistry;
use APP\core\Application;
Expand All @@ -22,6 +23,20 @@ public function executeActions()
$this->plugin = PluginRegistry::getPlugin('generic', 'scielomoderationstagesplugin');

$context = Application::get()->getRequest()->getContext();
$locale = $context->getPrimaryLocale();
$this->plugin->addLocaleData($locale);

$preModerationTimeLimit = $this->plugin->getSetting($context->getId(), 'preModerationTimeLimit');
$this->sendResponsiblesReminders($context, $preModerationTimeLimit, $locale);

$areaModerationTimeLimit = $this->plugin->getSetting($context->getId(), 'areaModerationTimeLimit');
$this->sendAreaModeratorsReminders($context, $areaModerationTimeLimit, $locale);

return true;
}

private function sendResponsiblesReminders($context, $preModerationTimeLimit, $locale)
{
$moderationReminderHelper = new ModerationReminderHelper();
$responsiblesUserGroup = $moderationReminderHelper->getResponsiblesUserGroup($context->getId());

Expand All @@ -32,16 +47,12 @@ public function executeActions()
);

if (empty($responsibleAssignments)) {
return true;
return;
}

$usersWithOverduePreModeration = $this->getUsersWithOverduePreModeration($context->getId(), $responsibleAssignments);
$usersWithOverduePreModeration = $this->getUsersWithOverduePreModeration($responsibleAssignments, $preModerationTimeLimit);
$mapModeratorsAndOverdueSubmissions = $moderationReminderHelper->mapUsersAndSubmissions($usersWithOverduePreModeration, $responsibleAssignments);

$locale = $context->getPrimaryLocale();
$this->plugin->addLocaleData($locale);
$preModerationTimeLimit = $this->plugin->getSetting($context->getId(), 'preModerationTimeLimit');

foreach ($mapModeratorsAndOverdueSubmissions as $userId => $submissions) {
$moderator = Repo::user()->get($userId);
$moderationReminderEmailBuilder = new ModerationReminderEmailBuilder(
Expand All @@ -56,14 +67,45 @@ public function executeActions()
$reminderEmail = $moderationReminderEmailBuilder->buildEmail();
Mail::send($reminderEmail);
}
}

return true;
private function sendAreaModeratorsReminders($context, $areaModerationTimeLimit, $locale)
{
$moderationReminderHelper = new ModerationReminderHelper();
$areaModeratorsUserGroup = $moderationReminderHelper->getAreaModeratorsUserGroup($context->getId());

$moderationStageDao = new ModerationStageDAO();
$areaModeratorAssignments = $moderationStageDao->getAssignmentsByUserGroupAndModerationStage(
$areaModeratorsUserGroup->getId(),
ModerationStage::SCIELO_MODERATION_STAGE_AREA
);

if (empty($areaModeratorAssignments)) {
return;
}

$usersWithOverdueAreaModeration = $this->getUsersWithOverdueAreaModeration($areaModeratorAssignments, $areaModerationTimeLimit);
$mapModeratorsAndOverdueSubmissions = $moderationReminderHelper->mapUsersAndSubmissions($usersWithOverdueAreaModeration, $areaModeratorAssignments);

foreach ($mapModeratorsAndOverdueSubmissions as $userId => $submissions) {
$moderator = Repo::user()->get($userId);
$moderationReminderEmailBuilder = new ModerationReminderEmailBuilder(
$context,
$moderator,
$submissions,
$locale,
ModerationReminderEmailBuilder::REMINDER_TYPE_AREA_MODERATION,
$areaModerationTimeLimit
);

$reminderEmail = $moderationReminderEmailBuilder->buildEmail();
Mail::send($reminderEmail);
}
}

private function getUsersWithOverduePreModeration($contextId, $assignments): array
private function getUsersWithOverduePreModeration($assignments, $preModerationTimeLimit): array
{
$usersIds = [];
$preModerationTimeLimit = $this->plugin->getSetting($contextId, 'preModerationTimeLimit');
$moderationStageDao = new ModerationStageDAO();

foreach ($assignments as $assignment) {
Expand All @@ -77,4 +119,20 @@ private function getUsersWithOverduePreModeration($contextId, $assignments): arr

return $usersIds;
}

private function getUsersWithOverdueAreaModeration($assignments, $areaModerationTimeLimit): array
{
$usersIds = [];
$limitDaysAgo = (new DateTime())->modify("-$areaModerationTimeLimit days");

foreach ($assignments as $assignment) {
$dateAssigned = new DateTime($assignment['dateAssigned']);

if ($dateAssigned < $limitDaysAgo and !isset($usersIds[$assignment['userId']])) {
$usersIds[$assignment['userId']] = $assignment['userId'];
}
}

return $usersIds;
}
}
2 changes: 1 addition & 1 deletion scheduledTasks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<scheduled_tasks>
<task class="APP\plugins\generic\scieloModerationStages\classes\tasks\SendModerationReminders">
<descr>Send moderation reminders to moderators whose moderation is overdue</descr>
<frequency minute="47"/>
<frequency dayofweek="1"/>
</task>
</scheduled_tasks>

0 comments on commit 21cd771

Please sign in to comment.