Skip to content

Commit

Permalink
pkp#4789 refactored cauculating due dates to traits with added valida…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
touhidurabir committed Sep 20, 2024
1 parent c2792b2 commit 032d6f8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +34,8 @@

class ResendRequestReviewerForm extends ReviewerNotifyActionForm
{
use HasReviewDueDate;

/**
* Constructor
*/
Expand All @@ -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'
)
);
}

/**
Expand All @@ -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);
Expand Down
27 changes: 5 additions & 22 deletions controllers/grid/users/reviewer/form/ReviewerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +46,8 @@

class ReviewerForm extends Form
{
use HasReviewDueDate;

/** @var Submission The submission associated with the review assignment */
public $_submission;

Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
63 changes: 63 additions & 0 deletions controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* @file controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class HasReviewDueDate
*
* @brief Helper trait to get the review submit and/or response due dates
*/

namespace PKP\controllers\grid\users\reviewer\form\traits;

use Carbon\Carbon;
use PKP\context\Context;

trait HasReviewDueDate
{
public const REVIEW_SUBMIT_DEFAULT_DUE_WEEKS = 4;
public const RESPONSE_RESPONSE_DEFAULT_DUE_WEEKS = 4;

/**
* Get the review submit due dates
*/
public function getReviewSubmitDueDate(Context $context): Carbon
{
$numWeeks = (int) $context->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(),
];
}
}

0 comments on commit 032d6f8

Please sign in to comment.