-
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 'sendRemindersManually-702' into 'stable-3_3_0'
Adiciona envio manual do lembrete de moderadores See merge request softwares-pkp/plugins_ojs/scieloModerationStages!19
- Loading branch information
Showing
12 changed files
with
457 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
import('plugins.generic.scieloModerationStages.classes.ModerationStageDAO'); | ||
|
||
class ModerationReminderHelper | ||
{ | ||
private $moderationStageDao; | ||
|
||
public function __construct() | ||
{ | ||
$this->moderationStageDao = new ModerationStageDAO(); | ||
} | ||
|
||
public function setModerationStageDao($moderationStageDao) | ||
{ | ||
$this->moderationStageDao = $moderationStageDao; | ||
} | ||
|
||
public function getResponsiblesUserGroup(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; | ||
} | ||
} | ||
|
||
return $responsiblesUserGroup; | ||
} | ||
|
||
public function getResponsibleAssignments($responsiblesUserGroup, $contextId): array | ||
{ | ||
if (!$responsiblesUserGroup) { | ||
return []; | ||
} | ||
|
||
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); | ||
$responsiblesAssignments = $stageAssignmentDao->getByUserGroupId($responsiblesUserGroup->getId(), $contextId); | ||
|
||
return $responsiblesAssignments->toArray(); | ||
} | ||
|
||
public function filterAssignmentsOfSubmissionsOnPreModeration(array $assignments): array | ||
{ | ||
$preModerationAssignments = []; | ||
|
||
foreach ($assignments as $assignment) { | ||
$submissionId = $assignment->getData('submissionId'); | ||
$submissionModerationStage = $this->moderationStageDao->getSubmissionModerationStage($submissionId); | ||
|
||
if ($submissionModerationStage === SCIELO_MODERATION_STAGE_CONTENT) { | ||
$preModerationAssignments[] = $assignment; | ||
} | ||
} | ||
|
||
return $preModerationAssignments; | ||
} | ||
|
||
public function getUsersFromAssignments(array $assignments): array | ||
{ | ||
$users = []; | ||
$userDao = DAORegistry::getDAO('UserDAO'); | ||
|
||
foreach ($assignments as $assignment) { | ||
$user = $userDao->getById($assignment->getUserId()); | ||
|
||
if ($user and !isset($users[$user->getId()])) { | ||
$users[$user->getId()] = $user; | ||
} | ||
} | ||
|
||
return $users; | ||
} | ||
|
||
public function mapUsersAndSubmissions($users, $assignments) | ||
{ | ||
$usersMap = []; | ||
$submissionDao = DAORegistry::getDAO('SubmissionDAO'); | ||
|
||
foreach ($users as $userId) { | ||
foreach ($assignments as $assignment) { | ||
if ($userId != $assignment->getData('userId')) { | ||
continue; | ||
} | ||
|
||
$submission = $submissionDao->getById($assignment->getData('submissionId')); | ||
|
||
if (isset($usersMap[$userId])) { | ||
$usersMap[$userId] = array_merge($usersMap[$userId], [$submission]); | ||
} else { | ||
$usersMap[$userId] = [$submission]; | ||
} | ||
} | ||
} | ||
|
||
return $usersMap; | ||
} | ||
} |
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
File renamed without changes.
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,76 @@ | ||
<?php | ||
|
||
import('lib.pkp.classes.form.Form'); | ||
import('plugins.generic.scieloModerationStages.classes.ModerationReminderHelper'); | ||
import('plugins.generic.scieloModerationStages.classes.ModerationReminderEmailBuilder'); | ||
|
||
class SendModerationReminderForm extends Form | ||
{ | ||
public $contextId; | ||
public $plugin; | ||
|
||
public function __construct($plugin, $contextId) | ||
{ | ||
$this->contextId = $contextId; | ||
$this->plugin = $plugin; | ||
parent::__construct($plugin->getTemplateResource('sendModerationReminderForm.tpl')); | ||
} | ||
|
||
private function getResponsibles(int $contextId): array | ||
{ | ||
$moderationReminderHelper = new ModerationReminderHelper(); | ||
$responsiblesUserGroup = $moderationReminderHelper->getResponsiblesUserGroup($contextId); | ||
$responsibleAssignments = $moderationReminderHelper->getResponsibleAssignments($responsiblesUserGroup, $contextId); | ||
|
||
if (empty($responsibleAssignments)) { | ||
return []; | ||
} | ||
|
||
$filteredAssignments = $moderationReminderHelper->filterAssignmentsOfSubmissionsOnPreModeration($responsibleAssignments); | ||
$usersFromAssignments = $moderationReminderHelper->getUsersFromAssignments($filteredAssignments); | ||
|
||
$mappedUsers = [null => null]; | ||
foreach ($usersFromAssignments as $userId => $user) { | ||
$fullName = $user->getFullName(); | ||
$mappedUsers[$userId] = $fullName; | ||
} | ||
|
||
asort($mappedUsers, SORT_STRING); | ||
|
||
return $mappedUsers; | ||
} | ||
|
||
public function fetch($request, $template = null, $display = false) | ||
{ | ||
$templateMgr = TemplateManager::getManager($request); | ||
$contextId = $request->getContext()->getId(); | ||
|
||
$templateMgr->assign([ | ||
'responsibles' => $this->getResponsibles($contextId), | ||
'pluginName' => $this->plugin->getName(), | ||
'applicationName' => Application::get()->getName() | ||
]); | ||
|
||
return parent::fetch($request, $template, $display); | ||
} | ||
|
||
public function readInputData() | ||
{ | ||
$this->readUserVars(['responsible', 'reminderBody']); | ||
} | ||
|
||
public function execute(...$functionArgs) | ||
{ | ||
$responsibleUserId = $this->getData('responsible'); | ||
$reminderBody = $this->getData('reminderBody'); | ||
|
||
$responsible = DAORegistry::getDAO('UserDAO')->getById($responsibleUserId); | ||
$context = Application::get()->getRequest()->getContext(); | ||
|
||
$moderationReminderEmailBuilder = new ModerationReminderEmailBuilder($context, $responsible, []); | ||
$reminderEmail = $moderationReminderEmailBuilder->buildEmail(); | ||
$reminderEmail->setBody($reminderBody); | ||
|
||
$reminderEmail->send(); | ||
} | ||
} |
Oops, something went wrong.