11<?php
22
33/**
4- * @file plugins/generic/scieloScreening/ScieloScreeningPlugin.inc. php
4+ * @file plugins/generic/scieloScreening/ScieloScreeningPlugin.php
55 *
66 * @class ScieloScreeningPlugin
77 * @ingroup plugins_generic_scieloScreening
88 *
9- * @brief Plugin class for the DefaultScreening plugin.
9+ * @brief Plugin class for the SciELO Screening plugin.
1010 */
1111
1212namespace APP \plugins \generic \scieloScreening ;
1313
1414use PKP \plugins \GenericPlugin ;
1515use APP \core \Application ;
1616use PKP \plugins \Hook ;
17- use PKP \db \DAORegistry ;
1817use APP \facades \Repo ;
18+ use PKP \stageAssignment \StageAssignment ;
19+ use PKP \userGroup \UserGroup ;
1920use PKP \security \Role ;
2021use PKP \linkAction \LinkAction ;
2122use PKP \linkAction \request \AjaxModal ;
2223use APP \template \TemplateManager ;
2324use PKP \core \JSONMessage ;
2425use APP \pages \submission \SubmissionHandler ;
2526use Illuminate \Database \Migrations \Migration ;
27+ use Illuminate \Http \Request as IlluminateRequest ;
28+ use Illuminate \Http \Response ;
29+ use Illuminate \Http \JsonResponse ;
30+ use PKP \core \PKPBaseController ;
31+ use PKP \handler \APIHandler ;
2632use APP \plugins \generic \scieloScreening \classes \components \forms \NumberContributorsForm ;
2733use APP \plugins \generic \scieloScreening \classes \ScreeningExecutor ;
2834use APP \plugins \generic \scieloScreening \classes \ScreeningChecker ;
@@ -46,17 +52,96 @@ public function register($category, $path, $mainContextId = null)
4652 Hook::add ('Submission::validateSubmit ' , [$ this , 'validateSubmissionFields ' ]);
4753 Hook::add ('Template::SubmissionWizard::Section::Review ' , [$ this , 'modifyReviewSections ' ]);
4854 Hook::add ('Schema::get::publication ' , [$ this , 'addOurFieldsToPublicationSchema ' ]);
49- Hook::add ('Template::Workflow::Publication ' , [$ this , 'addToWorkFlow ' ]);
50- Hook::add ('Template::Workflow::Publication ' , [$ this , 'addPdfsWarningToGalleysTab ' ]);
5155
5256 Hook::add ('Publication::validatePublish ' , [$ this , 'validateOnPosting ' ]);
5357 Hook::add ('Settings::Workflow::listScreeningPlugins ' , [$ this , 'listPluginScreeningRules ' ]);
5458
5559 $ this ->loadDispatcherClasses ();
60+
61+ $ request = Application::get ()->getRequest ();
62+ $ templateMgr = TemplateManager::getManager ($ request );
63+ $ this ->registerWorkflowAssets ($ request , $ templateMgr );
64+ $ this ->addScreeningApiRoute ();
5665 }
5766 return $ success ;
5867 }
5968
69+ private function registerWorkflowAssets ($ request , $ templateMgr ): void
70+ {
71+ $ baseUrl = $ request ->getBaseUrl ();
72+ $ pluginPath = $ this ->getPluginPath ();
73+
74+ $ templateMgr ->addJavaScript (
75+ 'scieloScreening ' ,
76+ "{$ baseUrl }/ {$ pluginPath }/public/build/build.iife.js " ,
77+ [
78+ 'inline ' => false ,
79+ 'contexts ' => ['backend ' ],
80+ 'priority ' => TemplateManager::STYLE_SEQUENCE_LAST
81+ ]
82+ );
83+
84+ $ templateMgr ->addStyleSheet (
85+ 'scieloScreeningStyles ' ,
86+ "{$ baseUrl }/ {$ pluginPath }/public/build/build.css " ,
87+ [
88+ 'contexts ' => ['backend ' ]
89+ ]
90+ );
91+ }
92+
93+ private function addScreeningApiRoute (): void
94+ {
95+ Hook::add (
96+ 'APIHandler::endpoints::submissions ' ,
97+ function (
98+ string $ hookName ,
99+ PKPBaseController $ apiController ,
100+ APIHandler $ apiHandler
101+ ): bool {
102+ $ apiHandler ->addRoute (
103+ 'GET ' ,
104+ '{submissionId}/screening ' ,
105+ $ this ->getScreeningDataHandler (),
106+ 'screening.get ' ,
107+ [
108+ Role::ROLE_ID_SITE_ADMIN ,
109+ Role::ROLE_ID_MANAGER ,
110+ Role::ROLE_ID_SUB_EDITOR ,
111+ ]
112+ );
113+
114+ return false ;
115+ }
116+ );
117+ }
118+
119+ private function getScreeningDataHandler (): callable
120+ {
121+ return function (IlluminateRequest $ request ): JsonResponse {
122+ $ submissionId = $ request ->route ('submissionId ' );
123+ $ submission = Repo::submission ()->get ((int ) $ submissionId );
124+
125+ if (!$ submission ) {
126+ return response ()->json (
127+ ['error ' => 'Submission not found ' ],
128+ Response::HTTP_NOT_FOUND
129+ );
130+ }
131+
132+ $ context = Application::get ()->getRequest ()->getContext ();
133+ $ documentChecker = $ this ->getDocumentChecker ($ submission );
134+ $ orcidClient = new OrcidClient ($ this , $ context ->getId ());
135+ $ screeningExecutor = new ScreeningExecutor (
136+ $ documentChecker ,
137+ $ orcidClient
138+ );
139+ $ screeningData = $ screeningExecutor ->getScreeningData ($ submission );
140+
141+ return response ()->json ($ screeningData , Response::HTTP_OK );
142+ };
143+ }
144+
60145 private function loadDispatcherClasses (): void
61146 {
62147 $ dispatcherClasses = [
@@ -295,34 +380,6 @@ public function modifyReviewSections($hookName, $params)
295380 }
296381 }
297382
298- public function addToWorkFlow ($ hookName , $ params )
299- {
300- $ smarty = &$ params [1 ];
301- $ output = &$ params [2 ];
302- $ context = Application::get ()->getRequest ()->getContext ();
303- $ submission = $ smarty ->getTemplateVars ('submission ' );
304-
305- $ documentChecker = $ this ->getDocumentChecker ($ submission );
306- $ orcidClient = new OrcidClient ($ this , $ context ->getId ());
307- $ screeningExecutor = new ScreeningExecutor ($ documentChecker , $ orcidClient );
308- $ dataScreening = $ screeningExecutor ->getScreeningData ($ submission );
309-
310- $ smarty ->assign ($ dataScreening );
311- $ output .= sprintf (
312- '<tab id="screeningInfo" label="%s">%s</tab> ' ,
313- __ ('plugins.generic.scieloScreening.info.name ' ),
314- $ smarty ->fetch ($ this ->getTemplateResource ('screeningInfo.tpl ' ))
315- );
316- }
317-
318- public function addPdfsWarningToGalleysTab ($ hookName , $ params )
319- {
320- $ smarty = & $ params [1 ];
321- $ output = & $ params [2 ];
322-
323- $ output .= sprintf ('%s ' , $ smarty ->fetch ($ this ->getTemplateResource ('addGalleysWarning.tpl ' )));
324- }
325-
326383 public function listPluginScreeningRules ($ hookName , $ args )
327384 {
328385 $ rules = & $ args [0 ];
@@ -368,11 +425,16 @@ public function validateOnPosting($hookName, $args)
368425
369426 private function getDocumentChecker ($ submission )
370427 {
371- $ galleys = $ submission ->getGalleys ();
428+ $ publication = $ submission ->getCurrentPublication ();
429+ $ galleys = Repo::galley ()->getCollector ()
430+ ->filterByPublicationIds ([$ publication ->getId ()])
431+ ->getMany ()
432+ ->toArray ();
372433
373434 if (count ($ galleys ) > 0 && $ galleys [0 ]->getFile ()) {
374435 $ galley = $ galleys [0 ];
375- $ path = \Config::getVar ('files ' , 'files_dir ' ) . DIRECTORY_SEPARATOR . $ galley ->getFile ()->getData ('path ' );
436+ $ filesDir = \Config::getVar ('files ' , 'files_dir ' );
437+ $ path = $ filesDir . DIRECTORY_SEPARATOR . $ galley ->getFile ()->getData ('path ' );
376438
377439 return new DocumentChecker ($ path );
378440 }
@@ -385,15 +447,19 @@ public function userIsAuthor($submission)
385447 $ currentUser = Application::get ()->getRequest ()->getUser ();
386448 $ currentUserAssignedRoles = [];
387449 if ($ currentUser ) {
388- $ stageAssignmentDao = DAORegistry::getDAO ('StageAssignmentDAO ' );
389- $ stageAssignmentsResult = $ stageAssignmentDao ->getBySubmissionAndUserIdAndStageId ($ submission ->getId (), $ currentUser ->getId (), $ submission ->getData ('stageId ' ));
390-
391- while ($ stageAssignment = $ stageAssignmentsResult ->next ()) {
392- $ userGroup = Repo::userGroup ()->get ($ stageAssignment ->getUserGroupId (), $ submission ->getData ('contextId ' ));
393- $ currentUserAssignedRoles [] = (int ) $ userGroup ->getRoleId ();
450+ $ stageAssignments = StageAssignment::withSubmissionIds ([$ submission ->getId ()])
451+ ->withStageIds ([$ submission ->getData ('stageId ' )])
452+ ->withUserId ($ currentUser ->getId ())
453+ ->get ();
454+
455+ foreach ($ stageAssignments as $ stageAssignment ) {
456+ $ userGroup = UserGroup::find ($ stageAssignment ->userGroupId );
457+ if ($ userGroup ) {
458+ $ currentUserAssignedRoles [] = (int ) $ userGroup ->roleId ;
459+ }
394460 }
395461 }
396462
397- return !empty ($ currentUserAssignedRoles ) and $ currentUserAssignedRoles [0 ] == Role::ROLE_ID_AUTHOR ;
463+ return !empty ($ currentUserAssignedRoles ) && $ currentUserAssignedRoles [0 ] == Role::ROLE_ID_AUTHOR ;
398464 }
399465}
0 commit comments