From bb5b711fda960831d1cac860c051516080a7420b Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Thu, 18 Apr 2024 17:50:12 +0600 Subject: [PATCH 1/3] pkp/pkp-lib#4789 Due date fields added for declined review request resending --- .../form/ResendRequestReviewerForm.php | 42 +++++++++++++++++-- .../grid/users/reviewer/form/ReviewerForm.php | 32 +++++++++----- .../form/resendRequestReviewerForm.tpl | 5 +++ 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/controllers/grid/users/reviewer/form/ResendRequestReviewerForm.php b/controllers/grid/users/reviewer/form/ResendRequestReviewerForm.php index 74772209457..29a189cb37d 100644 --- a/controllers/grid/users/reviewer/form/ResendRequestReviewerForm.php +++ b/controllers/grid/users/reviewer/form/ResendRequestReviewerForm.php @@ -2,8 +2,8 @@ /** * @file controllers/grid/users/reviewer/form/ResendRequestReviewerForm.php * - * Copyright (c) 2014-2022 Simon Fraser University - * Copyright (c) 2003-2022 John Willinsky + * Copyright (c) 2014-2024 Simon Fraser University + * Copyright (c) 2003-2024 John Willinsky * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. * * @class ResendRequestReviewerForm @@ -35,7 +35,6 @@ class ResendRequestReviewerForm extends ReviewerNotifyActionForm { /** * Constructor - * */ public function __construct(ReviewAssignment $reviewAssignment, ReviewRound $reviewRound, Submission $submission) { @@ -45,21 +44,54 @@ public function __construct(ReviewAssignment $reviewAssignment, ReviewRound $rev $submission, 'controllers/grid/users/reviewer/form/resendRequestReviewerForm.tpl' ); + + // Validation checks for this form + $this->addCheck(new \PKP\form\validation\FormValidator($this, 'responseDueDate', 'required', 'editor.review.errorAddingReviewer')); + $this->addCheck(new \PKP\form\validation\FormValidator($this, 'reviewDueDate', 'required', 'editor.review.errorAddingReviewer')); } + /** + * @copydoc \PKP\controllers\grid\users\reviewer\form\ReviewerNotifyActionForm::getMailable() + */ protected function getMailable(Context $context, Submission $submission, ReviewAssignment $reviewAssignment): Mailable { return new ReviewerResendRequest($context, $submission, $reviewAssignment); } /** - * @copydoc ReviewerNotifyActionForm::getEmailKey() + * @copydoc \PKP\controllers\grid\users\reviewer\form\ReviewerNotifyActionForm::getEmailKey() */ protected function getEmailKey() { return 'REVIEW_RESEND_REQUEST'; } + /** + * @copydoc \PKP\controllers\grid\users\reviewer\form\ReviewerNotifyActionForm::initData() + */ + public function initData() + { + parent::initData(); + + [$reviewDueDate, $responseDueDate] = ReviewerForm::getDueDates(Application::get()->getRequest()->getContext()); + + $this->setData('responseDueDate', $responseDueDate); + $this->setData('reviewDueDate', $reviewDueDate); + } + + /** + * @copydoc \PKP\controllers\grid\users\reviewer\form\ReviewerNotifyActionForm::readInputData() + */ + public function readInputData() + { + parent::readInputData(); + + $this->readUserVars([ + 'responseDueDate', + 'reviewDueDate', + ]); + } + /** * @copydoc Form::execute() * @@ -84,6 +116,8 @@ public function execute(...$functionArgs) 'declined' => false, 'requestResent' => true, 'dateConfirmed' => null, + 'dateDue' => $this->getData('reviewDueDate'), // Set the review due date + 'dateResponseDue' => $this->getData('responseDueDate'), // Set the response due date ]); // Stamp the modification date diff --git a/controllers/grid/users/reviewer/form/ReviewerForm.php b/controllers/grid/users/reviewer/form/ReviewerForm.php index 031b0ccc525..2f8203551f1 100644 --- a/controllers/grid/users/reviewer/form/ReviewerForm.php +++ b/controllers/grid/users/reviewer/form/ReviewerForm.php @@ -88,6 +88,26 @@ public function __construct($submission, $reviewRound) $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this)); } + /** + * Get the review submit and response due dates + */ + public static function getDueDates(Context $context): array + { + $numWeeks = (int) $context->getData('numWeeksPerReview'); + if ($numWeeks <= 0) { + $numWeeks = 4; + } + $reviewDueDate = strtotime('+' . $numWeeks . ' week'); + + $numWeeks = (int) $context->getData('numWeeksPerResponse'); + if ($numWeeks <= 0) { + $numWeeks = 3; + } + $responseDueDate = strtotime('+' . $numWeeks . ' week'); + + return [$reviewDueDate, $responseDueDate]; + } + // // Getters and Setters // @@ -211,17 +231,7 @@ public function initData() $reviewFormId = null; } - $numWeeks = (int) $context->getData('numWeeksPerReview'); - if ($numWeeks <= 0) { - $numWeeks = 4; - } - $reviewDueDate = strtotime('+' . $numWeeks . ' week'); - - $numWeeks = (int) $context->getData('numWeeksPerResponse'); - if ($numWeeks <= 0) { - $numWeeks = 3; - } - $responseDueDate = strtotime('+' . $numWeeks . ' week'); + [$reviewDueDate, $responseDueDate] = static::getDueDates($context); // Get the currently selected reviewer selection type to show the correct tab if we're re-displaying the form $selectionType = (int) $request->getUserVar('selectionType'); diff --git a/templates/controllers/grid/users/reviewer/form/resendRequestReviewerForm.tpl b/templates/controllers/grid/users/reviewer/form/resendRequestReviewerForm.tpl index 6aa0551f760..a1865d2a925 100644 --- a/templates/controllers/grid/users/reviewer/form/resendRequestReviewerForm.tpl +++ b/templates/controllers/grid/users/reviewer/form/resendRequestReviewerForm.tpl @@ -34,6 +34,11 @@ {fbvElement type="checkbox" id="skipEmail" name="skipEmail" label="editor.review.skipEmail"} {/fbvFormSection} + {fbvFormSection title="editor.review.importantDates"} + {fbvElement type="text" id="responseDueDate" name="responseDueDate" label="submission.task.responseDueDate" value=$responseDueDate inline=true size=$fbvStyles.size.MEDIUM class="datepicker"} + {fbvElement type="text" id="reviewDueDate" name="reviewDueDate" label="editor.review.reviewDueDate" value=$reviewDueDate inline=true size=$fbvStyles.size.MEDIUM class="datepicker"} + {/fbvFormSection} + {fbvFormButtons submitText="editor.review.resendRequestReviewer"} From 924e208ada664a4b7dc5f2dd5f9012b0db445e86 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Mon, 2 Sep 2024 13:42:41 +0600 Subject: [PATCH 2/3] pkp/pkp-lib#4789 refactored cauculating due dates to traits with added validations --- .../form/ResendRequestReviewerForm.php | 15 ++++- .../grid/users/reviewer/form/ReviewerForm.php | 27 ++------ .../form/ReviewerNotifyActionForm.php | 1 + .../reviewer/form/traits/HasReviewDueDate.php | 63 +++++++++++++++++++ 4 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php diff --git a/controllers/grid/users/reviewer/form/ResendRequestReviewerForm.php b/controllers/grid/users/reviewer/form/ResendRequestReviewerForm.php index 29a189cb37d..d8232e82a6a 100644 --- a/controllers/grid/users/reviewer/form/ResendRequestReviewerForm.php +++ b/controllers/grid/users/reviewer/form/ResendRequestReviewerForm.php @@ -21,6 +21,7 @@ use APP\notification\NotificationManager; use APP\submission\Submission; use PKP\context\Context; +use PKP\controllers\grid\users\reviewer\form\traits\HasReviewDueDate; use PKP\core\Core; use PKP\core\PKPApplication; use PKP\log\event\PKPSubmissionEventLogEntry; @@ -33,6 +34,8 @@ class ResendRequestReviewerForm extends ReviewerNotifyActionForm { + use HasReviewDueDate; + /** * Constructor */ @@ -48,6 +51,16 @@ public function __construct(ReviewAssignment $reviewAssignment, ReviewRound $rev // Validation checks for this form $this->addCheck(new \PKP\form\validation\FormValidator($this, 'responseDueDate', 'required', 'editor.review.errorAddingReviewer')); $this->addCheck(new \PKP\form\validation\FormValidator($this, 'reviewDueDate', 'required', 'editor.review.errorAddingReviewer')); + $this->addCheck( + new \PKP\form\validation\FormValidatorDateCompare( + $this, + 'reviewDueDate', + \Carbon\Carbon::parse(Application::get()->getRequest()->getUserVar('responseDueDate')), + \PKP\validation\enums\DateComparisonRule::GREATER_OR_EQUAL, + 'required', + 'editor.review.errorAddingReviewer.dateValidationFailed' + ) + ); } /** @@ -73,7 +86,7 @@ public function initData() { parent::initData(); - [$reviewDueDate, $responseDueDate] = ReviewerForm::getDueDates(Application::get()->getRequest()->getContext()); + [$reviewDueDate, $responseDueDate] = $this->getDueDates(Application::get()->getRequest()->getContext()); $this->setData('responseDueDate', $responseDueDate); $this->setData('reviewDueDate', $reviewDueDate); diff --git a/controllers/grid/users/reviewer/form/ReviewerForm.php b/controllers/grid/users/reviewer/form/ReviewerForm.php index 2f8203551f1..b677a3d2d7d 100644 --- a/controllers/grid/users/reviewer/form/ReviewerForm.php +++ b/controllers/grid/users/reviewer/form/ReviewerForm.php @@ -24,6 +24,7 @@ use APP\submission\Submission; use APP\template\TemplateManager; use PKP\context\Context; +use PKP\controllers\grid\users\reviewer\form\traits\HasReviewDueDate; use PKP\controllers\grid\users\reviewer\PKPReviewerGridHandler; use PKP\core\Core; use PKP\db\DAORegistry; @@ -45,6 +46,8 @@ class ReviewerForm extends Form { + use HasReviewDueDate; + /** @var Submission The submission associated with the review assignment */ public $_submission; @@ -88,26 +91,6 @@ public function __construct($submission, $reviewRound) $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this)); } - /** - * Get the review submit and response due dates - */ - public static function getDueDates(Context $context): array - { - $numWeeks = (int) $context->getData('numWeeksPerReview'); - if ($numWeeks <= 0) { - $numWeeks = 4; - } - $reviewDueDate = strtotime('+' . $numWeeks . ' week'); - - $numWeeks = (int) $context->getData('numWeeksPerResponse'); - if ($numWeeks <= 0) { - $numWeeks = 3; - } - $responseDueDate = strtotime('+' . $numWeeks . ' week'); - - return [$reviewDueDate, $responseDueDate]; - } - // // Getters and Setters // @@ -231,7 +214,7 @@ public function initData() $reviewFormId = null; } - [$reviewDueDate, $responseDueDate] = static::getDueDates($context); + [$reviewDueDate, $responseDueDate] = $this->getDueDates($context); // Get the currently selected reviewer selection type to show the correct tab if we're re-displaying the form $selectionType = (int) $request->getUserVar('selectionType'); @@ -267,7 +250,7 @@ public function fetch($request, $template = null, $display = false) $reviewFormDao = DAORegistry::getDAO('ReviewFormDAO'); /** @var ReviewFormDAO $reviewFormDao */ $reviewFormsIterator = $reviewFormDao->getActiveByAssocId(Application::getContextAssocType(), $context->getId()); $reviewForms = []; - while ($reviewForm = $reviewFormsIterator->next()) { + while ($reviewForm = $reviewFormsIterator->next()) { /** @var \PKP\reviewForm\ReviewForm $reviewForm */ $reviewForms[$reviewForm->getId()] = $reviewForm->getLocalizedTitle(); } diff --git a/controllers/grid/users/reviewer/form/ReviewerNotifyActionForm.php b/controllers/grid/users/reviewer/form/ReviewerNotifyActionForm.php index 5b27a63240b..c4be1fd30e5 100644 --- a/controllers/grid/users/reviewer/form/ReviewerNotifyActionForm.php +++ b/controllers/grid/users/reviewer/form/ReviewerNotifyActionForm.php @@ -50,6 +50,7 @@ public function __construct($reviewAssignment, $reviewRound, $submission, $templ $this->setReviewRound($reviewRound); $this->setSubmission($submission); + $this->addCheck(new \PKP\form\validation\FormValidatorPost($this)); $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this)); parent::__construct($template); diff --git a/controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php b/controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php new file mode 100644 index 00000000000..af7200fbbfe --- /dev/null +++ b/controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php @@ -0,0 +1,63 @@ +getData('numWeeksPerReview'); + + if ($numWeeks <= 0) { + $numWeeks = static::REVIEW_SUBMIT_DEFAULT_DUE_WEEKS; + } + + return Carbon::today()->endOfDay()->addWeeks($numWeeks); + } + + /** + * Get the review response due dates + */ + public function getReviewResponseDueDate(Context $context): Carbon + { + $numWeeks = (int) $context->getData('numWeeksPerResponse'); + + if ($numWeeks <= 0) { + $numWeeks = static::RESPONSE_RESPONSE_DEFAULT_DUE_WEEKS; + } + + return Carbon::today()->endOfDay()->addWeeks($numWeeks); + } + + /** + * Get the review submit and response due dates + */ + public function getDueDates(Context $context): array + { + return [ + $this->getReviewSubmitDueDate($context)->getTimestamp(), + $this->getReviewResponseDueDate($context)->getTimestamp(), + ]; + } +} From 1f6591ce7bbdc6ee66a0807737fcae448abd55b6 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Fri, 20 Sep 2024 12:35:31 +0600 Subject: [PATCH 3/3] pkp/pkp-lib#4789 fixed name and duration for review submit due date --- .../grid/users/reviewer/form/traits/HasReviewDueDate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php b/controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php index af7200fbbfe..f9ed81bcf08 100644 --- a/controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php +++ b/controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php @@ -20,7 +20,7 @@ trait HasReviewDueDate { public const REVIEW_SUBMIT_DEFAULT_DUE_WEEKS = 4; - public const RESPONSE_RESPONSE_DEFAULT_DUE_WEEKS = 4; + public const REVIEW_RESPONSE_DEFAULT_DUE_WEEKS = 3; /** * Get the review submit due dates @@ -44,7 +44,7 @@ public function getReviewResponseDueDate(Context $context): Carbon $numWeeks = (int) $context->getData('numWeeksPerResponse'); if ($numWeeks <= 0) { - $numWeeks = static::RESPONSE_RESPONSE_DEFAULT_DUE_WEEKS; + $numWeeks = static::REVIEW_RESPONSE_DEFAULT_DUE_WEEKS; } return Carbon::today()->endOfDay()->addWeeks($numWeeks);