From 948c20730c860c43e6a6a88b9f381a495db2d14b Mon Sep 17 00:00:00 2001 From: Nicolas Boulay Date: Fri, 19 Jan 2024 14:56:07 -0500 Subject: [PATCH] pkp/pkp-lib#9453 Matching the correct decline email and get review comments data --- api/v1/reviews/PKPReviewController.php | 37 +++++++++++++++++--------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/api/v1/reviews/PKPReviewController.php b/api/v1/reviews/PKPReviewController.php index 2ceeb8facc9..2506dfdc266 100644 --- a/api/v1/reviews/PKPReviewController.php +++ b/api/v1/reviews/PKPReviewController.php @@ -120,16 +120,20 @@ public function getHistory(Request $illuminateRequest): JsonResponse $publicationTitle = $submission->getCurrentPublication()->getLocalizedTitle(); $declineEmail = null; - if (!$reviewAssignment->getDeclined()) { + if ($reviewAssignment->getDeclined()) { $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); $emailLogs = $submissionEmailLogDao->getBySenderId($submissionId, SubmissionEmailLogEntry::SUBMISSION_EMAIL_REVIEW_DECLINE, $reviewerId)->toArray(); - // TODO: look for the right email log with the right round number. - if ($emailLogs) { - $emailLog = $emailLogs[0]; - $declineEmail = [ - 'subject' => $emailLog->getData('subject'), - 'body' => $emailLog->getData('body'), - ]; + foreach ($emailLogs as $emailLog) { + $dateSent = substr($emailLog->getData('dateSent'), 0, 10); + $dateConfirmed = substr($reviewAssignment->getData('dateConfirmed'), 0, 10); + // Compare the dates to get the decline email associated to the current round. + if ($dateSent === $dateConfirmed) { + $declineEmail = [ + 'subject' => $emailLog->getData('subject'), + 'body' => $emailLog->getData('body'), + ]; + break; + } } } @@ -138,10 +142,17 @@ public function getHistory(Request $illuminateRequest): JsonResponse $reviewAssignmentId = $reviewAssignment->getId(); $submissionCommentDao = DAORegistry::getDAO('SubmissionCommentDAO'); - $comments = $submissionCommentDao->getReviewerCommentsByReviewerId($submissionId, $reviewerId, $reviewAssignmentId, true)->toArray(); - $privateComments = $submissionCommentDao->getReviewerCommentsByReviewerId($submissionId, $reviewerId, $reviewAssignmentId, false)->toArray(); - - // TODO: get the comments data... + $allSubmissionComments = $submissionCommentDao->getReviewerCommentsByReviewerId($submissionId, $reviewerId, $reviewAssignmentId)->toArray(); + $viewableComments = []; + $privateComments = []; + foreach ($allSubmissionComments as $submissionComment) { + $comments = $submissionComment->getData('comments'); + if ($submissionComment->getData('viewable')) { + $viewableComments[] = $comments; + } else { + $privateComments[] = $comments; + } + } $lastReviewAssignment = Repo::reviewAssignment()->getCollector() ->filterByContextIds([$contextId]) @@ -157,7 +168,7 @@ public function getHistory(Request $illuminateRequest): JsonResponse 'declineEmail' => $declineEmail, 'reviewAssignment' => $reviewAssignmentProps, 'recommendation' => $recommendation, - 'comments' => $comments, + 'comments' => $viewableComments, 'privateComments' => $privateComments, 'displayFiles' => $displayFiles, ];