From 543ff048d46c76da88434f626e7e1b097586282b Mon Sep 17 00:00:00 2001 From: Nicolas Boulay Date: Thu, 1 Feb 2024 15:36:18 -0500 Subject: [PATCH] pkp/pkp-lib#9453 Change the review API to fetch additional data for round history --- api/v1/reviews/PKPReviewController.php | 52 ++++++++++++++++++++++---- pages/reviewer/PKPReviewerHandler.php | 3 +- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/api/v1/reviews/PKPReviewController.php b/api/v1/reviews/PKPReviewController.php index 2506dfdc266..3e9649fac20 100644 --- a/api/v1/reviews/PKPReviewController.php +++ b/api/v1/reviews/PKPReviewController.php @@ -22,6 +22,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\Route; +use PKP\core\PKPApplication; use PKP\core\PKPBaseController; use PKP\core\PKPRequest; use PKP\db\DAORegistry; @@ -30,6 +31,7 @@ use PKP\security\authorization\SubmissionAccessPolicy; use PKP\security\authorization\UserRolesRequiredPolicy; use PKP\security\Role; +use PKP\submissionFile\SubmissionFile; class PKPReviewController extends PKPBaseController { @@ -96,9 +98,7 @@ public function getHistory(Request $illuminateRequest): JsonResponse $context = $request->getContext(); $contextId = $context->getId(); - // TODO: get the reviewer ID from the request or from the route? $reviewerId = $request->getUser()->getId(); - //$reviewerId = $illuminateRequest->route('reviewerId'); $submissionId = $illuminateRequest->route('submissionId'); $reviewRoundId = $illuminateRequest->route('reviewRoundId'); @@ -117,7 +117,13 @@ public function getHistory(Request $illuminateRequest): JsonResponse } $submission = Repo::submission()->get($submissionId, $contextId); - $publicationTitle = $submission->getCurrentPublication()->getLocalizedTitle(); + $publication = $submission->getCurrentPublication(); + $publicationTitle = $publication->getLocalizedTitle(); + + $section = Repo::section()->get($submission->getSectionId()); + $publicationType = $section->getLocalizedData('title'); + $publicationAbstract = $publication->getLocalizedData('abstract'); + $publicationKeywords = implode(', ', $publication->getLocalizedData('keywords')); $declineEmail = null; if ($reviewAssignment->getDeclined()) { @@ -154,6 +160,21 @@ public function getHistory(Request $illuminateRequest): JsonResponse } } + $genreDao = DAORegistry::getDAO('GenreDAO'); + $fileGenres = $genreDao->getByContextId($contextId)->toArray(); + + $attachments = Repo::submissionFile()->getCollector() + ->filterBySubmissionIds([$submissionId]) + ->filterByReviewRoundIds([$reviewRoundId]) + ->filterByUploaderUserIds([$reviewerId]) + ->filterByFileStages([SubmissionFile::SUBMISSION_FILE_REVIEW_ATTACHMENT]) + ->filterByAssoc(PKPApplication::ASSOC_TYPE_REVIEW_ASSIGNMENT, [$reviewAssignmentId]) + ->getMany(); + $attachmentsProps = Repo::submissionFile() + ->getSchemaMap() + ->mapMany($attachments, $fileGenres) + ->toArray(); + $lastReviewAssignment = Repo::reviewAssignment()->getCollector() ->filterByContextIds([$contextId]) ->filterBySubmissionIds([$submissionId]) @@ -161,18 +182,35 @@ public function getHistory(Request $illuminateRequest): JsonResponse ->filterByLastReviewRound(true) ->getMany() ->first(); - $displayFiles = $lastReviewAssignment->getDeclined() != 1; - $reviewRoundHistoryProps = [ + $filesProps = []; + if ($lastReviewAssignment->getDeclined() != 1) { + $files = Repo::submissionFile()->getCollector() + ->filterBySubmissionIds([$submissionId]) + ->filterByReviewRoundIds([$reviewRoundId]) + ->filterByAssoc(PKPApplication::ASSOC_TYPE_REVIEW_ROUND, [$reviewAssignmentId]) + ->filterByFileStages([SubmissionFile::SUBMISSION_FILE_REVIEW_FILE]) + ->getMany(); + $filesProps = Repo::submissionFile() + ->getSchemaMap() + ->mapMany($files, $fileGenres) + ->toArray(); + } + + $reviewRoundHistory = [ 'publicationTitle' => $publicationTitle, + 'publicationType' => $publicationType, + 'publicationAbstract' => $publicationAbstract, + 'publicationKeywords' => $publicationKeywords, 'declineEmail' => $declineEmail, 'reviewAssignment' => $reviewAssignmentProps, 'recommendation' => $recommendation, 'comments' => $viewableComments, 'privateComments' => $privateComments, - 'displayFiles' => $displayFiles, + 'attachments' => array_values($attachmentsProps), + 'files' => array_values($filesProps), ]; - return response()->json($reviewRoundHistoryProps, Response::HTTP_OK); + return response()->json($reviewRoundHistory, Response::HTTP_OK); } } diff --git a/pages/reviewer/PKPReviewerHandler.php b/pages/reviewer/PKPReviewerHandler.php index b5229893983..86885b5e6c8 100644 --- a/pages/reviewer/PKPReviewerHandler.php +++ b/pages/reviewer/PKPReviewerHandler.php @@ -78,7 +78,8 @@ public function submission(array $args, PKPRequest $request): void $reviewRoundHistories[] = [ 'submissionId' => $submissionId, 'reviewRoundId' => $reviewRoundId, - 'reviewRoundNumber' => $reviewAssignment->getRound() + 'reviewRoundNumber' => $reviewAssignment->getRound(), + 'submittedOn' => $reviewAssignment->getDateCompleted() ]; } }