@@ -16,6 +16,20 @@ public function executeActions()
1616 $ this ->plugin = PluginRegistry::getPlugin ('generic ' , 'scielomoderationstagesplugin ' );
1717
1818 $ context = Application::get ()->getRequest ()->getContext ();
19+ $ locale = $ context ->getPrimaryLocale ();
20+ $ this ->plugin ->addLocaleData ($ locale );
21+
22+ $ preModerationTimeLimit = $ this ->plugin ->getSetting ($ context ->getId (), 'preModerationTimeLimit ' );
23+ $ this ->sendResponsiblesReminders ($ context , $ preModerationTimeLimit , $ locale );
24+
25+ $ areaModerationTimeLimit = $ this ->plugin ->getSetting ($ context ->getId (), 'areaModerationTimeLimit ' );
26+ $ this ->sendAreaModeratorsReminders ($ context , $ areaModerationTimeLimit , $ locale );
27+
28+ return true ;
29+ }
30+
31+ private function sendResponsiblesReminders ($ context , $ preModerationTimeLimit , $ locale )
32+ {
1933 $ moderationReminderHelper = new ModerationReminderHelper ();
2034 $ responsiblesUserGroup = $ moderationReminderHelper ->getResponsiblesUserGroup ($ context ->getId ());
2135
@@ -26,16 +40,12 @@ public function executeActions()
2640 );
2741
2842 if (empty ($ responsibleAssignments )) {
29- return true ;
43+ return ;
3044 }
3145
32- $ usersWithOverduePreModeration = $ this ->getUsersWithOverduePreModeration ($ context -> getId () , $ responsibleAssignments );
46+ $ usersWithOverduePreModeration = $ this ->getUsersWithOverduePreModeration ($ responsibleAssignments , $ preModerationTimeLimit );
3347 $ mapModeratorsAndOverdueSubmissions = $ moderationReminderHelper ->mapUsersAndSubmissions ($ usersWithOverduePreModeration , $ responsibleAssignments );
3448
35- $ locale = $ context ->getPrimaryLocale ();
36- $ this ->plugin ->addLocaleData ($ locale );
37- $ preModerationTimeLimit = $ this ->plugin ->getSetting ($ context ->getId (), 'preModerationTimeLimit ' );
38-
3949 foreach ($ mapModeratorsAndOverdueSubmissions as $ userId => $ submissions ) {
4050 $ moderator = DAORegistry::getDAO ('UserDAO ' )->getById ($ userId );
4151 $ moderationReminderEmailBuilder = new ModerationReminderEmailBuilder (
@@ -50,14 +60,45 @@ public function executeActions()
5060 $ reminderEmail = $ moderationReminderEmailBuilder ->buildEmail ();
5161 $ reminderEmail ->send ();
5262 }
63+ }
5364
54- return true ;
65+ private function sendAreaModeratorsReminders ($ context , $ areaModerationTimeLimit , $ locale )
66+ {
67+ $ moderationReminderHelper = new ModerationReminderHelper ();
68+ $ areaModeratorsUserGroup = $ moderationReminderHelper ->getAreaModeratorsUserGroup ($ context ->getId ());
69+
70+ $ moderationStageDao = new ModerationStageDAO ();
71+ $ areaModeratorAssignments = $ moderationStageDao ->getAssignmentsByUserGroupAndModerationStage (
72+ $ areaModeratorsUserGroup ->getId (),
73+ SCIELO_MODERATION_STAGE_AREA
74+ );
75+
76+ if (empty ($ areaModeratorAssignments )) {
77+ return ;
78+ }
79+
80+ $ usersWithOverdueAreaModeration = $ this ->getUsersWithOverdueAreaModeration ($ areaModeratorAssignments , $ areaModerationTimeLimit );
81+ $ mapModeratorsAndOverdueSubmissions = $ moderationReminderHelper ->mapUsersAndSubmissions ($ usersWithOverdueAreaModeration , $ areaModeratorAssignments );
82+
83+ foreach ($ mapModeratorsAndOverdueSubmissions as $ userId => $ submissions ) {
84+ $ moderator = DAORegistry::getDAO ('UserDAO ' )->getById ($ userId );
85+ $ moderationReminderEmailBuilder = new ModerationReminderEmailBuilder (
86+ $ context ,
87+ $ moderator ,
88+ $ submissions ,
89+ $ locale ,
90+ REMINDER_TYPE_AREA_MODERATION ,
91+ $ areaModerationTimeLimit
92+ );
93+
94+ $ reminderEmail = $ moderationReminderEmailBuilder ->buildEmail ();
95+ $ reminderEmail ->send ();
96+ }
5597 }
5698
57- private function getUsersWithOverduePreModeration ($ contextId , $ assignments ): array
99+ private function getUsersWithOverduePreModeration ($ assignments , $ preModerationTimeLimit ): array
58100 {
59101 $ usersIds = [];
60- $ preModerationTimeLimit = $ this ->plugin ->getSetting ($ contextId , 'preModerationTimeLimit ' );
61102 $ moderationStageDao = new ModerationStageDAO ();
62103
63104 foreach ($ assignments as $ assignment ) {
@@ -71,4 +112,20 @@ private function getUsersWithOverduePreModeration($contextId, $assignments): arr
71112
72113 return $ usersIds ;
73114 }
115+
116+ private function getUsersWithOverdueAreaModeration ($ assignments , $ areaModerationTimeLimit ): array
117+ {
118+ $ usersIds = [];
119+ $ limitDaysAgo = (new DateTime ())->modify ("- $ areaModerationTimeLimit days " );
120+
121+ foreach ($ assignments as $ assignment ) {
122+ $ dateAssigned = new DateTime ($ assignment ['dateAssigned ' ]);
123+
124+ if ($ dateAssigned < $ limitDaysAgo and !isset ($ usersIds [$ assignment ['userId ' ]])) {
125+ $ usersIds [$ assignment ['userId ' ]] = $ assignment ['userId ' ];
126+ }
127+ }
128+
129+ return $ usersIds ;
130+ }
74131}
0 commit comments