2323use PKP \security \Role ;
2424use PKP \db \DAORegistry ;
2525use Illuminate \Support \Facades \Event ;
26- use Illuminate \Support \Facades \Mail ;
2726use PKP \linkAction \LinkAction ;
2827use PKP \linkAction \request \AjaxModal ;
2928use PKP \core \JSONMessage ;
30- use APP \plugins \generic \scieloModerationStages \classes \ModerationStage ;
31- use APP \plugins \generic \scieloModerationStages \classes \ModerationStageRegister ;
32- use APP \plugins \generic \scieloModerationStages \classes \mail \builders \StageAdvancementEmailBuilder ;
29+ use APP \plugins \generic \scieloModerationStages \classes \SchemaEditor ;
3330use APP \plugins \generic \scieloModerationStages \classes \observers \listeners \AssignFirstModerationStage ;
3431
3532class ScieloModerationStagesPlugin extends GenericPlugin
3633{
37- private const SCIELO_BRASIL_EMAIL = 'scielo.submission@scielo.org ' ;
38-
3934 public function register ($ category , $ path , $ mainContextId = null )
4035 {
4136 $ success = parent ::register ($ category , $ path , $ mainContextId );
@@ -47,29 +42,22 @@ public function register($category, $path, $mainContextId = null)
4742 if ($ success && $ this ->getEnabled ($ mainContextId )) {
4843 Event::subscribe (new AssignFirstModerationStage ());
4944
50- Hook::add ('Schema::get::submission ' , [$ this , 'addNewPropsToSubmissionSchema ' ]);
51- Hook::add ('Schema::get::eventLog ' , [$ this , 'addNewPropsToEventLogSchema ' ]);
52- Hook::add ('addparticipantform::display ' , [$ this , 'addStageAdvanceToAssignForm ' ]);
53- Hook::add ('addparticipantform::execute ' , [$ this , 'sendSubmissionToNextModerationStage ' ]);
54- Hook::add ('queryform::display ' , [$ this , 'hideParticipantsOnDiscussionOpening ' ]);
55-
56- Hook::add ('Template::Workflow::Publication ' , [$ this , 'addToWorkflowTabs ' ]);
57- Hook::add ('Template::Workflow ' , [$ this , 'addCurrentStageStatusToWorkflow ' ]);
5845 Hook::add ('LoadComponentHandler ' , [$ this , 'setupScieloModerationStagesHandler ' ]);
59-
6046 Hook::add ('AcronPlugin::parseCronTab ' , [$ this , 'addTasksToCrontab ' ]);
6147 Hook::add ('TemplateManager::display ' , [$ this , 'addMessageToSubmissionComplete ' ]);
6248
63- $ this ->addHandlerURLToJavaScript ();
49+ $ this ->editSchemas ();
6450 $ this ->loadDispatcherClasses ();
51+ $ this ->addHandlerURLToJavaScript ();
6552 }
6653 return $ success ;
6754 }
6855
6956 private function loadDispatcherClasses (): void
7057 {
7158 $ dispatcherClasses = [
72- 'DashboardDispatcher '
59+ 'DashboardDispatcher ' ,
60+ 'WorkflowDispatcher '
7361 ];
7462
7563 foreach ($ dispatcherClasses as $ dispatcherClass ) {
@@ -78,6 +66,13 @@ private function loadDispatcherClasses(): void
7866 }
7967 }
8068
69+ private function editSchemas ()
70+ {
71+ $ schemaEditor = new SchemaEditor ();
72+ Hook::add ('Schema::get::submission ' , [$ schemaEditor , 'editSubmissionSchema ' ]);
73+ Hook::add ('Schema::get::eventLog ' , [$ schemaEditor , 'editEventLogSchema ' ]);
74+ }
75+
8176 public function addHandlerURLToJavaScript ()
8277 {
8378 $ request = Application::get ()->getRequest ();
@@ -215,104 +210,6 @@ public function addNewPropsToEventLogSchema($hookName, $params)
215210 return Hook::CONTINUE ;
216211 }
217212
218- public function addStageAdvanceToAssignForm ($ hookName , $ params )
219- {
220- $ request = Application::get ()->getRequest ();
221- $ templateMgr = TemplateManager::getManager ($ request );
222-
223- $ submission = $ params [0 ]->getSubmission ();
224- $ moderationStage = new ModerationStage ($ submission );
225-
226- if ($ moderationStage ->canAdvanceStage ()) {
227- $ currentStageName = $ moderationStage ->getCurrentStageName ();
228- $ nextStageName = $ moderationStage ->getNextStageName ();
229-
230- $ templateMgr ->assign ('currentStage ' , $ currentStageName );
231- $ templateMgr ->assign ('nextStage ' , $ nextStageName );
232-
233- $ templateMgr ->registerFilter ("output " , array ($ this , 'addCheckboxesToAssignForm ' ));
234- }
235-
236- return false ;
237- }
238-
239- public function addCheckboxesToAssignForm ($ output , $ templateMgr )
240- {
241- if (preg_match ('/<div[^>]+class="section formButtons/ ' , $ output , $ matches , PREG_OFFSET_CAPTURE )) {
242- $ posMatch = $ matches [0 ][1 ];
243-
244- $ sentNextStageOutput = $ templateMgr ->fetch ($ this ->getTemplateResource ('sentNextStage.tpl ' ));
245-
246- $ output = substr_replace ($ output , $ sentNextStageOutput , $ posMatch , 0 );
247- $ templateMgr ->unregisterFilter ('output ' , array ($ this , 'addCheckboxesToAssignForm ' ));
248- }
249- return $ output ;
250- }
251-
252- public function addToWorkflowTabs ($ hookName , $ params )
253- {
254- $ templateMgr = &$ params [1 ];
255- $ output = &$ params [2 ];
256- $ submission = $ templateMgr ->getTemplateVars ('submission ' );
257-
258- $ request = Application::get ()->getRequest ();
259- $ context = $ request ->getContext ();
260- $ faqUrl = $ request ->url ($ context ->getPath ()) . '/faq ' ;
261-
262- $ moderationStage = new ModerationStage ($ submission );
263- if ($ moderationStage ->submissionStageExists ()) {
264- $ stageDates = $ moderationStage ->getStageEntryDates ();
265- $ currentStageName = $ moderationStage ->getCurrentStageName (false );
266-
267- $ templateMgr ->assign ([
268- ...$ stageDates ,
269- 'submissionId ' => $ submission ->getId (),
270- 'userIsAuthor ' => $ this ->userIsAuthor ($ submission ),
271- 'currentStage ' => $ currentStageName ,
272- 'canAdvanceStage ' => $ moderationStage ->canAdvanceStage (),
273- 'faqUrl ' => $ faqUrl
274- ]);
275-
276- if ($ moderationStage ->canAdvanceStage ()) {
277- $ templateMgr ->assign ('nextStage ' , $ moderationStage ->getNextStageName ());
278- }
279-
280- $ output .= sprintf (
281- '<tab id="scieloModerationStages" label="%s">%s</tab> ' ,
282- __ ('plugins.generic.scieloModerationStages.displayNameWorkflow ' ),
283- $ templateMgr ->fetch ($ this ->getTemplateResource ('moderationStageMenu.tpl ' ))
284- );
285- }
286- }
287-
288- public function addCurrentStageStatusToWorkflow ($ hookName , $ params )
289- {
290- $ templateMgr = &$ params [1 ];
291- $ submission = $ templateMgr ->getTemplateVars ('submission ' );
292-
293- if (!is_null ($ submission ->getData ('currentModerationStage ' ))) {
294- $ moderationStage = new ModerationStage ($ submission );
295-
296- $ templateMgr ->assign ('currentStageName ' , $ moderationStage ->getCurrentStageName ());
297- $ templateMgr ->registerFilter ("output " , [$ this , 'addCurrentStageStatusToWorkflowFilter ' ]);
298- }
299-
300- return false ;
301- }
302-
303- public function addCurrentStageStatusToWorkflowFilter ($ output , $ templateMgr )
304- {
305- if (preg_match ('/<span[^>]+v-if="publicationList.length/ ' , $ output , $ matches , PREG_OFFSET_CAPTURE )) {
306- $ posMatch = $ matches [0 ][1 ];
307-
308- $ currentStageStatus = $ templateMgr ->fetch ($ this ->getTemplateResource ('currentStageStatus.tpl ' ));
309-
310- $ output = substr_replace ($ output , $ currentStageStatus , $ posMatch , 0 );
311- $ templateMgr ->unregisterFilter ('output ' , array ($ this , 'addCurrentStageStatusToWorkflowFilter ' ));
312- }
313- return $ output ;
314- }
315-
316213 public function addMessageToSubmissionComplete ($ hookName , $ params )
317214 {
318215 $ template = &$ params [1 ];
@@ -343,7 +240,7 @@ public function getStyleSheet()
343240 return $ this ->getPluginPath () . '/styles/moderationStageStyleSheet.css ' ;
344241 }
345242
346- private function userIsAuthor ($ submission )
243+ public function userIsAuthor ($ submission )
347244 {
348245 $ currentUser = Application::get ()->getRequest ()->getUser ();
349246 $ currentUserAssignedRoles = array ();
@@ -359,61 +256,4 @@ private function userIsAuthor($submission)
359256
360257 return $ currentUserAssignedRoles [0 ] == Role::ROLE_ID_AUTHOR ;
361258 }
362-
363- public function sendSubmissionToNextModerationStage ($ hookName , $ params )
364- {
365- $ request = Application::get ()->getRequest ();
366- $ form = $ params [0 ];
367- $ requestVars = $ request ->getUserVars ();
368-
369- if ($ requestVars ['sendNextStage ' ]) {
370- $ submission = $ form ->getSubmission ();
371- $ moderationStage = new ModerationStage ($ submission );
372-
373- if ($ moderationStage ->canAdvanceStage ()) {
374- $ moderationStage ->sendNextStage ();
375- $ moderationStageRegister = new ModerationStageRegister ();
376- $ moderationStageRegister ->registerModerationStageOnDatabase ($ moderationStage );
377- $ moderationStageRegister ->registerModerationStageOnSubmissionLog ($ moderationStage );
378-
379- $ emailBuilder = new StageAdvancementEmailBuilder ();
380- $ email = $ emailBuilder ->setSubmission ($ submission )
381- ->buildEmailParams ()
382- ->build ();
383- Mail::send ($ email );
384- }
385- }
386- }
387-
388- public function hideParticipantsOnDiscussionOpening ($ hookName , $ params )
389- {
390- $ form = $ params [0 ];
391- $ request = Application::get ()->getRequest ();
392- $ templateMgr = TemplateManager::getManager ($ request );
393- $ allParticipants = $ templateMgr ->getTemplateVars ('allParticipants ' );
394-
395- $ query = $ form ->getQuery ();
396- $ submission = Repo::submission ()->get ($ query ->getData ('assocId ' ));
397-
398- if ($ this ->userIsAuthor ($ submission )) {
399- $ author = $ request ->getUser ();
400- $ newParticipantsList = [];
401- $ allowedUsersEmails = [
402- $ author ->getEmail (),
403- self ::SCIELO_BRASIL_EMAIL
404- ];
405-
406- foreach ($ allParticipants as $ participantId => $ participantData ) {
407- $ participant = Repo::user ()->get ($ participantId );
408-
409- if (in_array ($ participant ->getEmail (), $ allowedUsersEmails )) {
410- $ newParticipantsList [$ participantId ] = $ participantData ;
411- }
412- }
413-
414- $ templateMgr ->assign ('allParticipants ' , $ newParticipantsList );
415- }
416-
417- return false ;
418- }
419259}
0 commit comments