Skip to content

Commit

Permalink
#9674 Port StageAssignmentDAO and StageAssignment to Eloquent Model
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat committed Jan 31, 2024
1 parent b139c4a commit 91002da
Show file tree
Hide file tree
Showing 40 changed files with 680 additions and 932 deletions.
24 changes: 11 additions & 13 deletions api/v1/submissions/PKPSubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
use PKP\security\Role;
use PKP\security\Validation;
use PKP\services\PKPSchemaService;
use PKP\stageAssignment\StageAssignmentDAO;
use PKP\submission\GenreDAO;
use PKP\submission\PKPSubmission;
use PKP\submission\reviewAssignment\ReviewAssignment;
Expand Down Expand Up @@ -565,18 +564,17 @@ public function add(Request $illuminateRequest): JsonResponse
$submission = Repo::submission()->get($submissionId);

// Assign submitter to submission
/** @var StageAssignmentDAO $stageAssignmentDao */
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
$stageAssignmentDao->build(
$submission->getId(),
$submitAsUserGroup->getId(),
$request->getUser()->getId(),
$submitAsUserGroup->getRecommendOnly(),
// Authors can always edit metadata before submitting
$submission->getData('submissionProgress')
? true
: $submitAsUserGroup->getPermitMetadataEdit()
);
Repo::stageAssignment()
->build(
$submission->getId(),
$submitAsUserGroup->getId(),
$request->getUser()->getId(),
$submitAsUserGroup->getRecommendOnly(),
// Authors can always edit metadata before submitting
$submission->getData('submissionProgress')
? true
: $submitAsUserGroup->getPermitMetadataEdit()
);

// Create an author record from the submitter's user account
if ($submitAsUserGroup->getRoleId() === Role::ROLE_ID_AUTHOR) {
Expand Down
32 changes: 17 additions & 15 deletions classes/context/SubEditorsDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use PKP\notification\NotificationSubscriptionSettingsDAO;
use PKP\security\Role;
use PKP\stageAssignment\StageAssignment;
use PKP\stageAssignment\StageAssignmentDAO;
use PKP\userGroup\UserGroup;

class SubEditorsDAO extends \PKP\db\DAO
Expand Down Expand Up @@ -215,11 +214,15 @@ public function assignEditors(Submission $submission, Context $context): Collect
&& $userGroupIds->contains($assignment->userGroupId);
});

/** @var StageAssignmentDAO $stageAssignmentDao */
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
foreach ($assignments as $assignment) {
$userGroup = $userGroups->first(fn (UserGroup $userGroup) => $userGroup->getId() == $assignment->userGroupId);
$stageAssignmentDao->build($submission->getId(), $assignment->userGroupId, $assignment->userId, $userGroup->getRecommendOnly());
Repo::stageAssignment()
->build(
$submission->getId(),
$assignment->userGroupId,
$assignment->userId,
$userGroup->getRecommendOnly()
);
}

// Update assignment notifications
Expand All @@ -245,14 +248,14 @@ public function assignEditors(Submission $submission, Context $context): Collect
}

// Send an email to assigned editors
$editorAssignments = $stageAssignmentDao->getBySubmissionAndRoleIds(
$submission->getId(),
[Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR],
WORKFLOW_STAGE_ID_SUBMISSION
)->toArray();
// Replaces StageAssignmentDAO::getBySubmissionAndRoleIds
$editorAssignments = StageAssignment::withSubmissionId($submission->getId())
->withRoleIds([Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR])
->withStageId(WORKFLOW_STAGE_ID_SUBMISSION)
->get();

$emailTemplate = Repo::emailTemplate()->getByKey($context->getId(), EditorAssigned::getEmailTemplateKey());
if (count($editorAssignments) && $emailTemplate) {
if ($editorAssignments->isNotEmpty() && $emailTemplate) {
// Never notify the same user twice, even if they are assigned in multiple roles
$notifiedEditors = [];

Expand All @@ -264,24 +267,23 @@ public function assignEditors(Submission $submission, Context $context): Collect
->subject($emailTemplate->getLocalizedData('subject') ?? '')
->body($emailTemplate->getLocalizedData('body') ?? '');

/** @var StageAssignment $editorAssignment */
foreach ($editorAssignments as $editorAssignment) {
$unsubscribed = in_array(
Notification::NOTIFICATION_TYPE_SUBMISSION_SUBMITTED,
$notificationSubscriptionSettingsDao->getNotificationSubscriptionSettings(
NotificationSubscriptionSettingsDAO::BLOCKED_EMAIL_NOTIFICATION_KEY,
$editorAssignment->getUserId(),
$editorAssignment->userId,
$context->getId()
)
);

if ($unsubscribed || in_array($editorAssignment->getUserId(), $notifiedEditors)) {
if ($unsubscribed || in_array($editorAssignment->userId, $notifiedEditors)) {
continue;
}

$notifiedEditors[] = $editorAssignment->getUserId();
$notifiedEditors[] = $editorAssignment->userId;

$recipient = Repo::user()->get($editorAssignment->getUserId());
$recipient = Repo::user()->get($editorAssignment->userId);
$mailable->recipients([$recipient]);

Mail::send($mailable);
Expand Down
1 change: 0 additions & 1 deletion classes/core/PKPApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ public function getDAOMap()
'ScheduledTaskDAO' => 'PKP\scheduledTask\ScheduledTaskDAO',
'SessionDAO' => 'PKP\session\SessionDAO',
'SiteDAO' => 'PKP\site\SiteDAO',
'StageAssignmentDAO' => 'PKP\stageAssignment\StageAssignmentDAO',
'SubEditorsDAO' => 'PKP\context\SubEditorsDAO',
'SubmissionAgencyDAO' => 'PKP\submission\SubmissionAgencyDAO',
'SubmissionAgencyEntryDAO' => 'PKP\submission\SubmissionAgencyEntryDAO',
Expand Down
17 changes: 7 additions & 10 deletions classes/decision/DecisionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use PKP\security\Role;
use PKP\services\PKPSchemaService;
use PKP\stageAssignment\StageAssignment;
use PKP\stageAssignment\StageAssignmentDAO;
use PKP\submission\GenreDAO;
use PKP\submission\reviewRound\ReviewRound;
use PKP\submission\reviewRound\ReviewRoundDAO;
Expand Down Expand Up @@ -259,15 +258,13 @@ public function getSteps(Submission $submission, Context $context, User $editor,
*/
protected function getAssignedAuthorIds(Submission $submission): array
{
$userIds = [];
/** @var StageAssignmentDAO $stageAssignmentDao */
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
$result = $stageAssignmentDao->getBySubmissionAndRoleIds($submission->getId(), [Role::ROLE_ID_AUTHOR], $this->getStageId());
/** @var StageAssignment $stageAssignment */
while ($stageAssignment = $result->next()) {
$userIds[] = (int) $stageAssignment->getUserId();
}
return $userIds;
// Replaces StageAssignmentDAO::getBySubmissionAndRoleIds
return StageAssignment::withSubmissionId($submission->getId())
->withRoleIds([Role::ROLE_ID_AUTHOR])
->withStageId($this->getStageId())
->get()
->pluck('userId')
->all();
}

/**
Expand Down
28 changes: 16 additions & 12 deletions classes/decision/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use PKP\security\Validation;
use PKP\services\PKPSchemaService;
use PKP\stageAssignment\StageAssignment;
use PKP\stageAssignment\StageAssignmentDAO;
use PKP\submission\reviewRound\ReviewRoundDAO;
use PKP\submissionFile\SubmissionFile;
use PKP\validation\ValidatorFactory;
Expand Down Expand Up @@ -158,9 +157,15 @@ public function validate(array $props, DecisionType $decisionType, Submission $s
// A recommendation can not be made if the submission does not
// have at least one assigned editor who can make a decision
if ($this->isRecommendation($decisionType->getDecision())) {
/** @var StageAssignmentDAO $stageAssignmentDao */
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
$assignedEditorIds = $stageAssignmentDao->getDecidingEditorIds($submission->getId(), $decisionType->getStageId());
// Replaces StageAssignmentDAO::getDecidingEditorIds
$assignedEditorIds = StageAssignment::withSubmissionId($submission->getId())
->withStageId($decisionType->getStageId())
->withRoleIds([Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR])
->withRecommendOnly(false)
->get()
->pluck('userId')
->all();

if (!$assignedEditorIds) {
$validator->errors()->add('decision', __('editor.submission.workflowDecision.requiredDecidingEditor'));
}
Expand Down Expand Up @@ -421,14 +426,13 @@ protected function updateNotifications(Decision $decision, DecisionType $decisio
array_unshift($notificationTypes, $editorDecisionNotificationType);
}

$authorIds = [];
/** @var StageAssignmentDAO $stageAssignmentDao */
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
$result = $stageAssignmentDao->getBySubmissionAndRoleIds($submission->getId(), [Role::ROLE_ID_AUTHOR], $decisionType->getStageId());
/** @var StageAssignment $stageAssignment */
while ($stageAssignment = $result->next()) {
$authorIds[] = (int) $stageAssignment->getUserId();
}
// Replaces StageAssignmentDAO::getBySubmissionAndRoleIds
$authorIds = StageAssignment::withSubmissionId($submission->getId())
->withRoleIds([Role::ROLE_ID_AUTHOR])
->withStageId($decisionType->getStageId())
->get()
->pluck('userId')
->all();

$notificationMgr->updateNotification(
Application::get()->getRequest(),
Expand Down
35 changes: 18 additions & 17 deletions classes/decision/Steps.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
use APP\facades\Repo;
use APP\submission\Submission;
use PKP\context\Context;
use PKP\db\DAORegistry;
use PKP\security\Role;
use PKP\stageAssignment\StageAssignment;
use PKP\stageAssignment\StageAssignmentDAO;
use PKP\submission\reviewRound\ReviewRound;
use PKP\user\User;

Expand Down Expand Up @@ -77,18 +76,14 @@ public function getState(): array
*/
public function getStageParticipants(int $roleId): array
{
/** @var StageAssignmentDAO $stageAssignmentDao */
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
$userIds = [];
$result = $stageAssignmentDao->getBySubmissionAndRoleIds(
$this->submission->getId(),
[$roleId],
$this->decisionType->getStageId()
);
/** @var StageAssignment $stageAssignment */
while ($stageAssignment = $result->next()) {
$userIds[] = (int) $stageAssignment->getUserId();
}
// Replaces StageAssignmentDAO::getBySubmissionAndRoleIds
$userIds = StageAssignment::withSubmissionId($this->submission->getId())
->withRoleIds([$roleId])
->withStageId($this->decisionType->getStageId())
->get()
->pluck('userId')
->all();

$users = [];
foreach (array_unique($userIds) as $authorUserId) {
$users[] = Repo::user()->get($authorUserId);
Expand Down Expand Up @@ -118,9 +113,15 @@ public function getReviewersFromAssignments(array $reviewAssignments): array
*/
public function getDecidingEditors(): array
{
/** @var StageAssignmentDAO $stageAssignmentDao */
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
$userIds = $stageAssignmentDao->getDecidingEditorIds($this->submission->getId(), $this->decisionType->getStageId());
// Replaces StageAssignmentDAO::getDecidingEditorIds
$userIds = StageAssignment::withSubmissionId($this->submission->getId())
->withStageId($this->decisionType->getStageId())
->withRoleIds([Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR])
->withRecommendOnly(false)
->get()
->pluck('userId')
->all();

$users = [];
foreach (array_unique($userIds) as $authorUserId) {
$users[] = Repo::user()->get($authorUserId);
Expand Down
16 changes: 11 additions & 5 deletions classes/decision/types/traits/IsRecommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
use PKP\mail\mailables\RecommendationNotifyEditors;
use PKP\note\Note;
use PKP\query\QueryDAO;
use PKP\security\Role;
use PKP\stageAssignment\StageAssignment;
use PKP\submission\reviewRound\ReviewRound;
use PKP\submissionFile\SubmissionFile;
use PKP\user\User;
Expand Down Expand Up @@ -116,13 +118,17 @@ public function getSteps(Submission $submission, Context $context, User $editor,
*/
protected function addRecommendationQuery(EmailData $email, Submission $submission, User $editor, Context $context): void
{
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /** @var \StageAssignmentDAO $stageAssignmentDao */
$queryParticipantIds = [];
$editorsStageAssignments = $stageAssignmentDao->getEditorsAssignedToStage($submission->getId(), $this->getStageId());
// Replaces StageAssignmentDAO::getEditorsAssignedToStage
$editorsStageAssignments = StageAssignment::withSubmissionId($submission->getId())
->withStageId($this->getStageId())
->withRoleIds([Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR])
->get();

foreach ($editorsStageAssignments as $editorsStageAssignment) {
if (!$editorsStageAssignment->getRecommendOnly()) {
if (!in_array($editorsStageAssignment->getUserId(), $queryParticipantIds)) {
$queryParticipantIds[] = $editorsStageAssignment->getUserId();
if (!$editorsStageAssignment->recommendOnly) {
if (!in_array($editorsStageAssignment->userId, $queryParticipantIds)) {
$queryParticipantIds[] = $editorsStageAssignment->userId;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions classes/facades/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use PKP\submissionFile\Repository as SubmissionFileRepository;
use PKP\userGroup\Repository as UserGroupRepository;
use PKP\jats\Repository as JatsRepository;
use PKP\stageAssignment\Repository as StageAssignmentRepository;

class Repo
{
Expand Down Expand Up @@ -110,4 +111,9 @@ public static function jats(): JatsRepository
{
return app(JatsRepository::class);
}

public static function stageAssignment(): StageAssignmentRepository
{
return app(StageAssignmentRepository::class);
}
}
11 changes: 7 additions & 4 deletions classes/notification/PKPNotificationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
use PKP\notification\managerDelegate\SubmissionNotificationManager;
use PKP\payment\QueuedPaymentDAO;
use PKP\security\Role;
use PKP\stageAssignment\StageAssignmentDAO;
use PKP\stageAssignment\StageAssignment;
use PKP\submission\reviewRound\ReviewRoundDAO;
use PKP\workflow\WorkflowStageDAO;

Expand Down Expand Up @@ -165,10 +165,13 @@ public function getNotificationMessage($request, $notification)
assert($notification->getAssocType() == Application::ASSOC_TYPE_REVIEW_ROUND && is_numeric($notification->getAssocId()));
$reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /** @var ReviewRoundDAO $reviewRoundDao */
$reviewRound = $reviewRoundDao->getById($notification->getAssocId());
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /** @var StageAssignmentDAO $stageAssignmentDao */
$user = $request->getUser();
$stageAssignments = $stageAssignmentDao->getBySubmissionAndRoleIds($reviewRound->getSubmissionId(), [Role::ROLE_ID_AUTHOR], null, $user->getId());
$isAuthor = (bool) $stageAssignments->next();
// Replaces StageAssignmentDAO::getBySubmissionAndRoleIds
$isAuthor = StageAssignment::withSubmissionId($reviewRound->getSubmissionId())
->withRoleIds([Role::ROLE_ID_AUTHOR])
->withUserId($user->getId())
->exists();

return __($reviewRound->getStatusKey($isAuthor));
case PKPNotification::NOTIFICATION_TYPE_PAYMENT_REQUIRED:
return __('payment.type.publication.required');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use PKP\db\DAORegistry;
use PKP\notification\NotificationManagerDelegate;
use PKP\notification\PKPNotification;
use PKP\security\Role;
use PKP\stageAssignment\StageAssignment;

class EditorAssignmentNotificationManager extends NotificationManagerDelegate
{
Expand Down Expand Up @@ -83,8 +85,11 @@ public function updateNotification($request, $userIds, $assocType, $assocId)
);

// Check for editor stage assignment.
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /** @var StageAssignmentDAO $stageAssignmentDao */
$editorAssigned = $stageAssignmentDao->editorAssignedToStage($submissionId, $this->_getStageIdByNotificationType());
// Replaces StageAssignmentDAO::editorAssignedToStage
$editorAssigned = StageAssignment::withSubmissionId($submissionId)
->withStageId($this->_getStageIdByNotificationType())
->withRoleIds([Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR])
->exists();

// Decide if we have to create or delete a notification.
$notification = $notificationFactory->next();
Expand Down
Loading

0 comments on commit 91002da

Please sign in to comment.