@@ -185,7 +185,7 @@ public function fetch($args, $request) {
185185 break ;
186186 case 'reviewerSubmit ' :
187187 // in case a reviewer submits the article review
188- $ this ->reviewerSubmit ();
188+ $ this ->reviewerSubmit ($ request );
189189 $ response = array (
190190 "version " => $ this ->getApiVersion ()
191191 );
@@ -457,7 +457,7 @@ function versionToStage($versionString) {
457457 * @return array
458458 * @throws Exception
459459 */
460- function reviewerSubmit () {
460+ function reviewerSubmit ($ request ) {
461461
462462 $ submissionId = $ this ->getPOSTPayloadVariable ("submission_id " );
463463 $ versionString = $ this ->getPOSTPayloadVariable ("version " );
@@ -487,7 +487,98 @@ function reviewerSubmit() {
487487 $ this ->saveCommentForEditor ($ editorMessageCommentText , $ reviewAssignment );
488488 $ this ->saveCommentForEditorAndAuthor ($ editorAndAuthorMessageCommentText , $ reviewAssignment );
489489
490+ // Set review step to last step
490491 $ this ->updateReviewStepAndSaveSubmission ($ reviewerSubmission );
492+
493+ // Mark the review assignment as completed.
494+ $ reviewAssignment ->setDateCompleted (Core::getCurrentDate ());
495+ $ reviewAssignment ->stampModified ();
496+
497+ // Set the recommendation
498+ $ recommendation = intval ($ this ->getPOSTPayloadVariable ("recommendation " ));
499+ $ reviewAssignment ->setRecommendation ($ recommendation );
500+ $ reviewAssignmentDao ->updateObject ($ reviewAssignment );
501+
502+ // Send notifications to everyone who should be informed.
503+ $ stageAssignmentDao = DAORegistry::getDAO ('StageAssignmentDAO ' );
504+ $ stageAssignments = $ stageAssignmentDao ->getBySubmissionAndStageId ($ submissionId , $ stageId );
505+ $ userGroupDao = DAORegistry::getDAO ('UserGroupDAO ' );
506+ $ receivedList = array (); // Avoid sending twice to the same user.
507+ $ notificationMgr = new NotificationManager ();
508+
509+ while ($ stageAssignment = $ stageAssignments ->next ()) {
510+ $ userId = $ stageAssignment ->getUserId ();
511+ $ userGroup = $ userGroupDao ->getById ($ stageAssignment ->getUserGroupId (), $ submission ->getContextId ());
512+
513+ // Only send notifications about reviewer comment notification to managers and editors
514+ // and only send to usrs who have not received a notificcation already.
515+ if (!in_array (
516+ $ userGroup ->getRoleId (),
517+ array (ROLE_ID_MANAGER , ROLE_ID_SUB_EDITOR )) || in_array ($ userId , $ receivedList )
518+ ) continue ;
519+
520+ $ notificationMgr ->createNotification (
521+ $ request , $ userId , NOTIFICATION_TYPE_REVIEWER_COMMENT ,
522+ $ submission ->getContextId (), ASSOC_TYPE_REVIEW_ASSIGNMENT , $ reviewAssignment ->getId ()
523+ );
524+
525+ $ receivedList [] = $ userId ;
526+ }
527+
528+ // Update the review round status.
529+ $ reviewRoundDao = DAORegistry::getDAO ('ReviewRoundDAO ' );
530+ $ reviewRound = $ reviewRoundDao ->getById ($ reviewAssignment ->getReviewRoundId ());
531+ $ reviewAssignments = $ reviewAssignmentDao ->getByReviewRoundId ($ reviewRound ->getId ());
532+ $ reviewRoundDao ->updateStatus ($ reviewRound , $ reviewAssignments );
533+
534+ $ contextId = $ submission ->getContextId ();
535+
536+
537+ // Update the notification on whether all reviews are in.
538+ $ stageAssignmentDao = DAORegistry::getDAO ('StageAssignmentDAO ' );
539+ $ stageAssignments = $ stageAssignmentDao ->getEditorsAssignedToStage ($ submissionId , $ stageId );
540+
541+ $ notificationDao = DAORegistry::getDAO ('NotificationDAO ' );
542+
543+ foreach ($ stageAssignments as $ stageAssignment ) {
544+ $ userId = $ stageAssignment ->getUserId ();
545+
546+ // Get any existing notification.
547+ $ notificationFactory = $ notificationDao ->getByAssoc (
548+ ASSOC_TYPE_REVIEW_ROUND ,
549+ $ reviewRound ->getId (), $ userId ,
550+ NOTIFICATION_TYPE_ALL_REVIEWS_IN ,
551+ $ contextId
552+ );
553+
554+ $ currentStatus = $ reviewRound ->getStatus ();
555+ if (in_array ($ currentStatus , $ reviewRoundDao ->getEditorDecisionRoundStatus ()) ||
556+ in_array ($ currentStatus , array (REVIEW_ROUND_STATUS_PENDING_REVIEWERS , REVIEW_ROUND_STATUS_PENDING_REVIEWS ))) {
557+ // Editor has taken a decision in round or there are pending
558+ // reviews or no reviews. Delete any existing notification.
559+ if (!$ notificationFactory ->wasEmpty ()) {
560+ $ notification = $ notificationFactory ->next ();
561+ $ notificationDao ->deleteObject ($ notification );
562+ }
563+ } else {
564+ // There is no currently decision in round. Also there is reviews,
565+ // but no pending reviews. Insert notification, if not already present.
566+ if ($ notificationFactory ->wasEmpty ()) {
567+ $ notificationMgr ->createNotification ($ request , $ userId , NOTIFICATION_TYPE_ALL_REVIEWS_IN , $ contextId ,
568+ ASSOC_TYPE_REVIEW_ROUND , $ reviewRound ->getId (), NOTIFICATION_LEVEL_TASK );
569+ }
570+ }
571+ }
572+
573+ // Remove the review task
574+ $ notificationDao = DAORegistry::getDAO ('NotificationDAO ' );
575+ $ notificationDao ->deleteByAssoc (
576+ ASSOC_TYPE_REVIEW_ASSIGNMENT ,
577+ $ reviewAssignment ->getId (),
578+ $ reviewAssignment ->getReviewerId (),
579+ NOTIFICATION_TYPE_REVIEW_ASSIGNMENT
580+ );
581+
491582 return ;
492583 }
493584
@@ -499,12 +590,11 @@ function reviewerSubmit() {
499590 */
500591 function updateReviewStepAndSaveSubmission (ReviewerSubmission &$ reviewerSubmission ) {
501592 //review step
502- $ submissionCompleteStep = 3 ;
593+ $ submissionCompleteStep = 4 ;
503594 $ nextStep = $ submissionCompleteStep ;
504595 if ($ reviewerSubmission ->getStep () < $ nextStep ) {
505596 $ reviewerSubmission ->setStep ($ nextStep );
506597 }
507- $ reviewerSubmission ->setRecommendation ("See Comments " );
508598 // Save the reviewer submission.
509599 $ reviewerSubmissionDao = DAORegistry::getDAO ('ReviewerSubmissionDAO ' );
510600 /* @var $reviewerSubmissionDao ReviewerSubmissionDAO */
0 commit comments