Skip to content

Commit

Permalink
pkp#1660 dynamic recommendations ability complete
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Jan 10, 2025
1 parent fd9546c commit db1f977
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ public function editThankReviewer($args, $request)
*/
public function readReview($args, $request)
{
$context = $request->getContext();
$templateMgr = TemplateManager::getManager($request);
$reviewAssignment = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_REVIEW_ASSIGNMENT);
$starHtml = '<span class="fa fa-star"></span>';
Expand All @@ -828,12 +829,11 @@ public function readReview($args, $request)
ReviewAssignment::SUBMISSION_REVIEWER_RATING_POOR => str_repeat($starHtml, ReviewAssignment::SUBMISSION_REVIEWER_RATING_POOR),
ReviewAssignment::SUBMISSION_REVIEWER_RATING_VERY_POOR => str_repeat($starHtml, ReviewAssignment::SUBMISSION_REVIEWER_RATING_VERY_POOR),
],
'reviewerRecommendationOptions' => ReviewAssignment::getReviewerRecommendationOptions(),
'reviewerRecommendationOptions' => ReviewAssignment::getReviewerRecommendationOptions($context),
]);

if ($reviewAssignment->getReviewFormId()) {
// Retrieve review form
$context = $request->getContext();
$reviewFormElementDao = DAORegistry::getDAO('ReviewFormElementDAO'); /** @var ReviewFormElementDAO $reviewFormElementDao */
$reviewFormElements = $reviewFormElementDao->getByReviewFormId($reviewAssignment->getReviewFormId());
$reviewFormResponseDao = DAORegistry::getDAO('ReviewFormResponseDAO'); /** @var ReviewFormResponseDAO $reviewFormResponseDao */
Expand Down
2 changes: 1 addition & 1 deletion classes/mail/variables/ReviewAssignmentEmailVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function formatDate(string $date, string $locale, Context $context): ?

protected function getRecommendation(string $locale): string
{
$recommendationOptions = ReviewAssignment::getReviewerRecommendationOptions();
$recommendationOptions = ReviewAssignment::getReviewerRecommendationOptions($this->getContext());

return isset($recommendationOptions[$this->reviewAssignment->getRecommendation()])
? __($recommendationOptions[$this->reviewAssignment->getRecommendation()], [], $locale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
namespace PKP\migration\install;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use PKP\facades\Locale;
use PKP\submission\reviewer\recommendation\ReviewerRecommendation;
use stdClass;
use Throwable;

abstract class ReviewerRecommendationsMigration extends \PKP\migration\Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@

namespace PKP\migration\upgrade\v3_6_0;

use APP\migration\install\ReviewerRecommendationsMigration;
use Illuminate\Support\Facades\DB;
use PKP\facades\Locale;
use PKP\install\Installer;

use Throwable;

use stdClass;

use PKP\submission\reviewer\recommendation\ReviewerRecommendation;
use PKP\facades\Locale;
use APP\migration\install\ReviewerRecommendationsMigration;
use Throwable;

abstract class I1660_ReviewerRecommendations extends \PKP\migration\Migration
{
Expand All @@ -50,6 +46,8 @@ public function __construct(Installer $installer, array $attributes)
public function up(): void
{
$this->recommendationInstallMigration->up();

$this->seedNonRemovableRecommendations();
}

/**
Expand Down Expand Up @@ -147,7 +145,6 @@ protected function seedNonRemovableRecommendations(): void
Locale::setLocale($currentLocale);
ReviewerRecommendation::reguard();

ray($exception);
throw $exception;
}
}
Expand Down
84 changes: 52 additions & 32 deletions classes/submission/reviewAssignment/ReviewAssignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@

namespace PKP\submission\reviewAssignment;

use APP\core\Application;
use PKP\submission\reviewer\recommendation\ReviewerRecommendation;
use PKP\context\Context;
use PKP\core\Core;

class ReviewAssignment extends \PKP\core\DataObject
{
public const SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT = 1;
public const SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS = 2;
public const SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE = 3;
public const SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE = 4;
public const SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE = 5;
public const SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS = 6;
// public const SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT = 1;
// public const SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS = 2;
// public const SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE = 3;
// public const SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE = 4;
// public const SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE = 5;
// public const SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS = 6;

public const SUBMISSION_REVIEWER_RATING_VERY_GOOD = 5;
public const SUBMISSION_REVIEWER_RATING_GOOD = 4;
Expand Down Expand Up @@ -798,36 +801,53 @@ public function getWeeksDue()
}

/**
* Get an associative array matching reviewer recommendation codes with locale strings.
* Get an associative array matching reviewer recommendation code/value mapped to localized title.
* (Includes default '' => "Choose One" string.)
*
* @return array recommendation => localeString
* @return array recommendation => localizedTitle
*/
public static function getReviewerRecommendationOptions()
public static function getReviewerRecommendationOptions(?Context $context = null, ?bool $active = true): array
{
static $reviewerRecommendationOptions = [
'' => 'common.chooseOne',
self::SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT => 'reviewer.article.decision.accept',
self::SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS => 'reviewer.article.decision.pendingRevisions',
self::SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE => 'reviewer.article.decision.resubmitHere',
self::SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE => 'reviewer.article.decision.resubmitElsewhere',
self::SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE => 'reviewer.article.decision.decline',
self::SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS => 'reviewer.article.decision.seeComments'
];
return $reviewerRecommendationOptions;
$context ??= Application::get()->getRequest()->getContext();
static $reviewerRecommendationOptions = [];

if (!empty($reviewerRecommendationOptions)) {
return $reviewerRecommendationOptions;
}

// static $reviewerRecommendationOptions = [
// '' => 'common.chooseOne',
// self::SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT => 'reviewer.article.decision.accept',
// self::SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS => 'reviewer.article.decision.pendingRevisions',
// self::SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE => 'reviewer.article.decision.resubmitHere',
// self::SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE => 'reviewer.article.decision.resubmitElsewhere',
// self::SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE => 'reviewer.article.decision.decline',
// self::SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS => 'reviewer.article.decision.seeComments'
// ];

return $reviewerRecommendationOptions = ReviewerRecommendation::query()
->withContextId($context->getId())
->when(!is_null($active), fn ($query) => $query->withActive($active))
->get()
->mapWithKeys(
fn (ReviewerRecommendation $recommendation): array => [
$recommendation->value => $recommendation->getLocalizedData('title')
]
)
->prepend(__('common.chooseOne'), '')
->toArray();
}

/**
* Return a localized string representing the reviewer recommendation.
*/
public function getLocalizedRecommendation()
public function getLocalizedRecommendation(): string
{
$options = self::getReviewerRecommendationOptions();
if (array_key_exists($this->getRecommendation(), $options)) {
return __($options[$this->getRecommendation()]);
} else {
return '';
}
$options = static::getReviewerRecommendationOptions();

return array_key_exists($this->getRecommendation(), $options)
? $options[$this->getRecommendation()]
: '';
}

/**
Expand All @@ -850,12 +870,12 @@ public function canResendReviewRequest(): bool
if (!PKP_STRICT_MODE) {
class_alias('\PKP\submission\reviewAssignment\ReviewAssignment', '\ReviewAssignment');
foreach ([
'SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT',
'SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS',
'SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE',
'SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE',
'SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE',
'SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS',
// 'SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT',
// 'SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS',
// 'SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE',
// 'SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE',
// 'SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE',
// 'SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS',
'SUBMISSION_REVIEWER_RATING_VERY_GOOD',
'SUBMISSION_REVIEWER_RATING_GOOD',
'SUBMISSION_REVIEWER_RATING_AVERAGE',
Expand Down
10 changes: 5 additions & 5 deletions classes/submission/reviewer/form/PKPReviewerReviewStep3Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public function initData()
$submissionCommentDao = DAORegistry::getDAO('SubmissionCommentDAO'); /** @var SubmissionCommentDAO $submissionCommentDao */

$submissionComments = $submissionCommentDao->getReviewerCommentsByReviewerId($reviewAssignment->getSubmissionId(), $reviewAssignment->getReviewerId(), $reviewAssignment->getId(), true);
$submissionComment = $submissionComments->next();
$submissionComment = $submissionComments->next(); /** @var \PKP\submission\SubmissionComment $submissionComment */
$this->setData('comments', $submissionComment ? $submissionComment->getComments() : '');

$submissionCommentsPrivate = $submissionCommentDao->getReviewerCommentsByReviewerId($reviewAssignment->getSubmissionId(), $reviewAssignment->getReviewerId(), $reviewAssignment->getId(), false);
$submissionCommentPrivate = $submissionCommentsPrivate->next();
$submissionCommentPrivate = $submissionCommentsPrivate->next(); /** @var \PKP\submission\SubmissionComment $submissionCommentPrivate */
$this->setData('commentsPrivate', $submissionCommentPrivate ? $submissionCommentPrivate->getComments() : '');

parent::initData();
Expand Down Expand Up @@ -118,7 +118,7 @@ public function fetch($request, $template = null, $display = false)
$templateMgr->assign([
'reviewAssignment' => $reviewAssignment,
'reviewRoundId' => $reviewAssignment->getReviewRoundId(),
'reviewerRecommendationOptions' => ReviewAssignment::getReviewerRecommendationOptions(),
'reviewerRecommendationOptions' => ReviewAssignment::getReviewerRecommendationOptions($context),
]);

if ($reviewAssignment->getReviewFormId()) {
Expand Down Expand Up @@ -331,7 +331,7 @@ public function saveReviewForm($reviewAssignment)
// Create a comment with the review.
$submissionCommentDao = DAORegistry::getDAO('SubmissionCommentDAO'); /** @var SubmissionCommentDAO $submissionCommentDao */
$submissionComments = $submissionCommentDao->getReviewerCommentsByReviewerId($reviewAssignment->getSubmissionId(), $reviewAssignment->getReviewerId(), $reviewAssignment->getId(), true);
$comment = $submissionComments->next();
$comment = $submissionComments->next(); /** @var \PKP\submission\SubmissionComment $comment */

if (!isset($comment)) {
$comment = $submissionCommentDao->newDataObject();
Expand Down Expand Up @@ -360,7 +360,7 @@ public function saveReviewForm($reviewAssignment)
// Create a comment with the review.
$submissionCommentDao = DAORegistry::getDAO('SubmissionCommentDAO'); /** @var SubmissionCommentDAO $submissionCommentDao */
$submissionCommentsPrivate = $submissionCommentDao->getReviewerCommentsByReviewerId($reviewAssignment->getSubmissionId(), $reviewAssignment->getReviewerId(), $reviewAssignment->getId(), false);
$comment = $submissionCommentsPrivate->next();
$comment = $submissionCommentsPrivate->next(); /** @var \PKP\submission\SubmissionComment $comment */

if (!isset($comment)) {
$comment = $submissionCommentDao->newDataObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use PKP\submission\reviewer\recommendation\cast\ReviewerRecommendationValueCast;

class ReviewerRecommendation extends Model
{
Expand Down Expand Up @@ -179,4 +178,9 @@ public function scopeWithContextId(Builder $query, int $contextId): Builder
{
return $query->where('context_id', $contextId);
}

public function scopeWithActive(Builder $query, bool $active = true): Builder
{
return $query->where('status', $active);
}
}
4 changes: 2 additions & 2 deletions controllers/grid/users/reviewer/AuthorReviewerGridHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,18 @@ protected function loadData($request, $filter)
*/
public function readReview($args, $request)
{
$context = $request->getContext();
$templateMgr = TemplateManager::getManager($request);
$reviewAssignment = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_REVIEW_ASSIGNMENT);

$templateMgr->assign([
'submission' => $this->getSubmission(),
'reviewAssignment' => $reviewAssignment,
'reviewerRecommendationOptions' => ReviewAssignment::getReviewerRecommendationOptions(),
'reviewerRecommendationOptions' => ReviewAssignment::getReviewerRecommendationOptions($context),
]);

if ($reviewAssignment->getReviewFormId()) {
// Retrieve review form
$context = $request->getContext();
$reviewFormElementDao = DAORegistry::getDAO('ReviewFormElementDAO'); /** @var ReviewFormElementDAO $reviewFormElementDao */
// Get review form elements visible for authors
$reviewFormElements = $reviewFormElementDao->getByReviewFormId($reviewAssignment->getReviewFormId(), null, true);
Expand Down
22 changes: 14 additions & 8 deletions pages/dashboard/PKPDashboardHandlerNext.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
use PKP\submissionFile\SubmissionFile;
use PKP\components\forms\publication\ContributorForm;
use PKP\plugins\PluginRegistry;

use PKP\notification\Notification;
use PKP\log\SubmissionEmailLogEventType;
use PKP\submission\reviewer\recommendation\ReviewerRecommendation;

define('SUBMISSIONS_LIST_ACTIVE', 'active');
define('SUBMISSIONS_LIST_ARCHIVE', 'archive');
Expand Down Expand Up @@ -169,7 +169,13 @@ public function index($args, $request)
'componentForms' => [
'contributorForm' => $contributorForm->getConfig(),
'logResponseForm' => $logResponseForm->getConfig(),
]
],
'recommendations' => ReviewerRecommendation::query()
->withContextId($context->getId())
->get()
->select(['recommendationId', 'status', 'value', 'title'])
->values()
->toArray(),
]
]);

Expand Down Expand Up @@ -212,12 +218,12 @@ public function index($args, $request)
'SUBMISSION_REVIEW_METHOD_DOUBLEANONYMOUS' => ReviewAssignment::SUBMISSION_REVIEW_METHOD_DOUBLEANONYMOUS,
'SUBMISSION_REVIEW_METHOD_OPEN' => ReviewAssignment::SUBMISSION_REVIEW_METHOD_OPEN,

'SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT,
'SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS,
'SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE,
'SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE,
'SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE,
'SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS,
// 'SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT,
// 'SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS,
// 'SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE,
// 'SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE,
// 'SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE,
// 'SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS' => ReviewAssignment::SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS,

'DECISION_ACCEPT' => Decision::ACCEPT,
'DECISION_DECLINE' => Decision::DECLINE,
Expand Down
6 changes: 3 additions & 3 deletions pages/dashboard/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
switch ($op) {
case 'index':
case 'editorial':
return new PKP\pages\dashboard\DashboardHandlerNext(PKP\pages\dashboard\DashboardPage::EditorialDashboard);
return new APP\pages\dashboard\DashboardHandlerNext(PKP\pages\dashboard\DashboardPage::EditorialDashboard);
case 'mySubmissions':
return new PKP\pages\dashboard\DashboardHandlerNext(PKP\pages\dashboard\DashboardPage::MySubmissions);
return new APP\pages\dashboard\DashboardHandlerNext(PKP\pages\dashboard\DashboardPage::MySubmissions);
case 'reviewAssignments':
return new PKP\pages\dashboard\DashboardHandlerNext(PKP\pages\dashboard\DashboardPage::MyReviewAssignments);
return new APP\pages\dashboard\DashboardHandlerNext(PKP\pages\dashboard\DashboardPage::MyReviewAssignments);
}

0 comments on commit db1f977

Please sign in to comment.