forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp#4789 refactored cauculating due dates to traits with added valida…
…tions
- Loading branch information
1 parent
571c107
commit 6656fc7
Showing
4 changed files
with
83 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
controllers/grid/users/reviewer/form/traits/HasReviewDueDate.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
]; | ||
} | ||
} |