Skip to content

Commit

Permalink
pkp/pkp-lib#10537 Add available editorial decisions to submission's s…
Browse files Browse the repository at this point in the history
…tages data
  • Loading branch information
taslangraham committed Oct 23, 2024
1 parent 1dadfd1 commit eb25ebd
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,33 @@
namespace APP\submission\maps;

use APP\core\Application;
use APP\decision\types\AcceptFromInternal;
use APP\decision\types\CancelInternalReviewRound;
use APP\decision\types\DeclineInternal;
use APP\decision\types\RequestRevisionsInternal;
use APP\decision\types\RevertDeclineInternal;
use APP\decision\types\SendExternalReview;
use APP\decision\types\SendInternalReview;
use APP\decision\types\SkipInternalReview;
use APP\press\FeatureDAO;
use APP\press\NewReleaseDAO;
use APP\submission\Submission;
use Illuminate\Support\Collection;
use PKP\db\DAORegistry;
use PKP\decision\DecisionType;
use PKP\decision\types\Accept;
use PKP\decision\types\BackFromCopyediting;
use PKP\decision\types\BackFromProduction;
use PKP\decision\types\CancelReviewRound;
use PKP\decision\types\Decline;
use PKP\decision\types\InitialDecline;
use PKP\decision\types\RequestRevisions;
use PKP\decision\types\RevertDecline;
use PKP\decision\types\RevertInitialDecline;
use PKP\decision\types\SendToProduction;
use PKP\decision\types\SkipExternalReview;
use PKP\plugins\Hook;
use PKP\security\Role;
use PKP\submission\reviewRound\ReviewRound;
use PKP\submission\reviewRound\ReviewRoundDAO;

Expand Down Expand Up @@ -103,4 +125,85 @@ protected function getReviewRoundsFromSubmission(Submission $submission): Collec
return collect($reviewRoundDao->getBySubmissionId($submission->getId())->toIterator())
->groupBy(fn (ReviewRound $reviewRound) => $reviewRound->getData('round'));
}

protected function availableEditorialDecisions(int $stageId, Submission $submission): array
{
$decisionTypes = [];/** @var DecisionType[] $decisionTypes */

$request = Application::get()->getRequest();
$user = $request->getUser();
$isActiveStage = $submission->getData('stageId') == $stageId;
$userHasAccessibleRoles = $user->hasRole([Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_ASSISTANT], $request->getContext()->getId());

if (!$userHasAccessibleRoles || !$isActiveStage) {
return [];
}

$reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO');
/** @var ReviewRoundDAO $reviewRoundDao */
$reviewRound = $reviewRoundDao->getLastReviewRoundBySubmissionId($submission->getId(), $stageId);

switch ($stageId) {
case WORKFLOW_STAGE_ID_SUBMISSION:
$decisionTypes = [
new SkipInternalReview(),
new SkipExternalReview(),
];

if ($submission->getData('status') === Submission::STATUS_DECLINED) {
$decisionTypes[] = new RevertInitialDecline();
} elseif ($submission->getData('status') === Submission::STATUS_QUEUED) {
$decisionTypes[] = new InitialDecline();
}
$decisionTypes[] = new SendInternalReview();
break;
case WORKFLOW_STAGE_ID_INTERNAL_REVIEW:
$decisionTypes = [
new RequestRevisionsInternal(),
new SendExternalReview(),
new AcceptFromInternal(),
];
$cancelInternalReviewRound = new CancelInternalReviewRound();

if ($cancelInternalReviewRound->canRetract($submission, $reviewRound->getId())) {
$decisionTypes[] = $cancelInternalReviewRound;
}

if ($submission->getData('status') === Submission::STATUS_DECLINED) {
$decisionTypes[] = new RevertDeclineInternal();
} elseif ($submission->getData('status') === Submission::STATUS_QUEUED) {
$decisionTypes[] = new DeclineInternal();
}
break;
case WORKFLOW_STAGE_ID_EXTERNAL_REVIEW:
$decisionTypes = [
new RequestRevisions(),
new Accept(),
];

$cancelReviewRound = new CancelReviewRound();
if ($cancelReviewRound->canRetract($submission, $reviewRound->getId())) {
$decisionTypes[] = $cancelReviewRound;
}
if ($submission->getData('status') === Submission::STATUS_DECLINED) {
$decisionTypes[] = new RevertDecline();
} elseif ($submission->getData('status') === Submission::STATUS_QUEUED) {
$decisionTypes[] = new Decline();
}
break;
case WORKFLOW_STAGE_ID_EDITING:
$decisionTypes = [
new SendToProduction(),
new BackFromCopyediting(),
];
break;
case WORKFLOW_STAGE_ID_PRODUCTION:
$decisionTypes[] = new BackFromProduction();
break;
}

Hook::call('Workflow::Decisions', [&$decisionTypes, $stageId]);

return $decisionTypes;
}
}

0 comments on commit eb25ebd

Please sign in to comment.