@@ -18,50 +18,76 @@ public function __construct($plugin, $contextId)
1818 parent ::__construct ($ plugin ->getTemplateResource ('sendModerationReminderForm.tpl ' ));
1919 }
2020
21- private function getResponsiblesUserGroupId (int $ contextId ): int
21+ private function getResponsiblesUserGroupId ($ contextId )
2222 {
2323 $ moderationReminderHelper = new ModerationReminderHelper ();
2424 $ responsiblesUserGroup = $ moderationReminderHelper ->getResponsiblesUserGroup ($ contextId );
2525
26- return $ responsiblesUserGroup ->getId ();
26+ return ( $ responsiblesUserGroup ? $ responsiblesUserGroup ->getId () : null );
2727 }
2828
29- private function getResponsibles (int $ responsiblesUserGroupId ): array
29+ private function getAreaModeratorsUserGroupId ($ contextId )
30+ {
31+ $ moderationReminderHelper = new ModerationReminderHelper ();
32+ $ areaModeratorsUserGroup = $ moderationReminderHelper ->getAreaModeratorsUserGroup ($ contextId );
33+
34+ return ($ areaModeratorsUserGroup ? $ areaModeratorsUserGroup ->getId () : null );
35+ }
36+
37+ private function getUsersAssignedByGroupAndModerationStage (int $ userGroupId , int $ moderationStage ): array
3038 {
3139 $ moderationStageDao = new ModerationStageDAO ();
32- $ responsibleAssignments = $ moderationStageDao ->getAssignmentsByUserGroupAndModerationStage (
33- $ responsiblesUserGroupId ,
34- SCIELO_MODERATION_STAGE_CONTENT
40+ $ userAssignments = $ moderationStageDao ->getAssignmentsByUserGroupAndModerationStage (
41+ $ userGroupId ,
42+ $ moderationStage
3543 );
3644
37- if (empty ($ responsibleAssignments )) {
45+ if (empty ($ userAssignments )) {
3846 return [];
3947 }
4048
41- $ responsibles = [null => null ];
49+ $ usersAssigned = [null => null ];
4250 $ userDao = DAORegistry::getDAO ('UserDAO ' );
43- foreach ($ responsibleAssignments as $ assignment ) {
51+ foreach ($ userAssignments as $ assignment ) {
4452 $ user = $ userDao ->getById ($ assignment ['userId ' ]);
45- $ fullName = $ user ->getFullName ();
46- $ responsibles [$ user ->getId ()] = $ fullName ;
53+ $ usersAssigned [$ user ->getId ()] = $ user ->getFullName ();
4754 }
4855
49- asort ($ responsibles , SORT_STRING );
56+ asort ($ usersAssigned , SORT_STRING );
5057
51- return $ responsibles ;
58+ return $ usersAssigned ;
5259 }
5360
5461 public function fetch ($ request , $ template = null , $ display = false )
5562 {
5663 $ templateMgr = TemplateManager::getManager ($ request );
5764 $ contextId = $ request ->getContext ()->getId ();
5865
66+ $ roles = [
67+ REMINDER_TYPE_PRE_MODERATION => __ ('plugins.generic.scieloModerationStages.sendModerationReminder.responsible.title ' ),
68+ REMINDER_TYPE_AREA_MODERATION => __ ('plugins.generic.scieloModerationStages.sendModerationReminder.areaModerator.title ' )
69+ ];
70+
5971 $ responsiblesUserGroupId = $ this ->getResponsiblesUserGroupId ($ contextId );
60- $ responsibles = $ this ->getResponsibles ($ responsiblesUserGroupId );
72+ if (!is_null ($ responsiblesUserGroupId )) {
73+ $ responsibles = $ this ->getUsersAssignedByGroupAndModerationStage ($ responsiblesUserGroupId , SCIELO_MODERATION_STAGE_CONTENT );
74+ $ templateMgr ->assign ([
75+ 'responsiblesUserGroupId ' => $ responsiblesUserGroupId ,
76+ 'responsibles ' => $ responsibles
77+ ]);
78+ }
79+
80+ $ areaModeratorsUserGroupId = $ this ->getAreaModeratorsUserGroupId ($ contextId );
81+ if (!is_null ($ areaModeratorsUserGroupId )) {
82+ $ areaModerators = $ this ->getUsersAssignedByGroupAndModerationStage ($ areaModeratorsUserGroupId , SCIELO_MODERATION_STAGE_AREA );
83+ $ templateMgr ->assign ([
84+ 'areaModeratorsUserGroupId ' => $ areaModeratorsUserGroupId ,
85+ 'areaModerators ' => $ areaModerators
86+ ]);
87+ }
6188
6289 $ templateMgr ->assign ([
63- 'responsiblesUserGroupId ' => $ responsiblesUserGroupId ,
64- 'responsibles ' => $ responsibles ,
90+ 'roles ' => $ roles ,
6591 'pluginName ' => $ this ->plugin ->getName (),
6692 'applicationName ' => Application::get ()->getName ()
6793 ]);
@@ -71,21 +97,33 @@ public function fetch($request, $template = null, $display = false)
7197
7298 public function readInputData ()
7399 {
74- $ this ->readUserVars (['responsible ' , 'reminderBody ' ]);
100+ $ this ->readUserVars (['reminderRole ' , ' responsible ' , ' areaModerator ' , 'reminderBody ' ]);
75101 }
76102
77103 public function execute (...$ functionArgs )
78104 {
79- $ responsibleUserId = $ this ->getData ('responsible ' );
80- $ reminderBody = $ this ->getData ('reminderBody ' );
81-
82- $ responsible = DAORegistry::getDAO ('UserDAO ' )->getById ($ responsibleUserId );
105+ $ reminderRole = $ this ->getData ('reminderRole ' );
106+ $ locale = AppLocale::getLocale ();
83107 $ context = Application::get ()->getRequest ()->getContext ();
108+ $ reminderBody = $ this ->getData ('reminderBody ' );
84109
85- $ locale = AppLocale::getLocale ();
86- $ preModerationTimeLimit = $ this ->plugin ->getSetting ($ this ->contextId , 'preModerationTimeLimit ' );
110+ if ($ reminderRole == REMINDER_TYPE_PRE_MODERATION ) {
111+ $ userId = $ this ->getData ('responsible ' );
112+ $ moderationTimeLimit = $ this ->plugin ->getSetting ($ this ->contextId , 'preModerationTimeLimit ' );
113+ } elseif ($ reminderRole == REMINDER_TYPE_AREA_MODERATION ) {
114+ $ userId = $ this ->getData ('areaModerator ' );
115+ $ moderationTimeLimit = $ this ->plugin ->getSetting ($ this ->contextId , 'areaModerationTimeLimit ' );
116+ }
87117
88- $ moderationReminderEmailBuilder = new ModerationReminderEmailBuilder ($ context , $ responsible , [], $ locale , $ preModerationTimeLimit );
118+ $ user = DAORegistry::getDAO ('UserDAO ' )->getById ($ userId );
119+ $ moderationReminderEmailBuilder = new ModerationReminderEmailBuilder (
120+ $ context ,
121+ $ user ,
122+ [],
123+ $ locale ,
124+ $ reminderRole ,
125+ $ moderationTimeLimit
126+ );
89127 $ reminderEmail = $ moderationReminderEmailBuilder ->buildEmail ();
90128 $ reminderEmail ->setBody ($ reminderBody );
91129
0 commit comments