Skip to content

Commit

Permalink
*8212* missing stage assignment and mail template functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jnugent committed May 6, 2013
1 parent de03615 commit fb03e87
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 1 deletion.
57 changes: 57 additions & 0 deletions classes/mail/ArticleMailTemplate.inc.php
Expand Up @@ -213,6 +213,63 @@ function ccAssignedEditingSectionEditors($articleId) {
}
return $returner;
}

/**
* Send this email to all assigned section editors in the given stage
* @param $articleId int
* @param $stageId int
*/
function toAssignedSectionEditors($articleId, $stageId) {
return $this->_addUsers($articleId, ROLE_ID_SUB_EDITOR, $stageId, 'addRecipient');
}

/**
* CC this email to all assigned section editors in the given stage
* @param $articleId int
* @param $stageId int
* @return array of Users (note, this differs from OxS which returns EditAssignment objects)
*/
function ccAssignedSectionEditors($articleId, $stageId) {
return $this->_addUsers($articleId, ROLE_ID_SUB_EDITOR, $stageId, 'addCc');
}

/**
* BCC this email to all assigned section editors in the given stage
* @param $articleId int
* @param $stageId int
*/
function bccAssignedSectionEditors($articleId, $stageId) {
return $this->_addUsers($articleId, ROLE_ID_SUB_EDITOR, $stageId, 'addBcc');
}

/**
* Private method to fetch the requested users and add to the email
* @param $articleId int
* @param $roleId int
* @param $stageId int
* @param $method string one of addRecipient, addCC, or addBCC
* @return array of Users (note, this differs from OxS which returns EditAssignment objects)
*/
function _addUsers($articleId, $roleId, $stageId, $method) {
assert(in_array($method, array('addRecipient', 'addCc', 'addBcc')));

$userGroupDao = DAORegistry::getDAO('UserGroupDAO');
$userGroups =& $userGroupDao->getByRoleId($this->journal->getId(), $roleId);

$returner = array();
// Cycle through all the userGroups for this role
while ( $userGroup =& $userGroups->next() ) {
$userStageAssignmentDao = DAORegistry::getDAO('UserStageAssignmentDAO');
// FIXME: #6692# Should this be getting users just for a specific user group?
$users = $userStageAssignmentDao->getUsersBySubmissionAndStageId($articleId, $stageId, $userGroup->getId());
while ($user = $users->next()) {
$this->$method($user->getEmail(), $user->getFullName());
$returner[] = $user;
}
unset($userGroup);
}
return $returner;
}
}

?>
3 changes: 2 additions & 1 deletion classes/submission/form/SubmissionSubmitStep3Form.inc.php
Expand Up @@ -37,7 +37,7 @@ function assignDefaultParticipants($submission, $request) {
import('classes.submission.sectionEditor.SectionEditorAction');
$sectionEditorAction = new SectionEditorAction();
$sectionEditorAction->assignDefaultStageParticipants($submission, WORKFLOW_STAGE_ID_SUBMISSION, $request);
parent::assignDefaultParticipants();
parent::assignDefaultParticipants($submission, $request);
}

/**
Expand All @@ -49,6 +49,7 @@ function assignDefaultParticipants($submission, $request) {
function execute($args, $request) {
parent::execute($args, $request);

$submission = $this->submission;
// Send author notification email
import('classes.mail.ArticleMailTemplate');
$mail = new ArticleMailTemplate($submission, 'SUBMISSION_ACK');
Expand Down
75 changes: 75 additions & 0 deletions classes/submission/sectionEditor/SectionEditorAction.inc.php
Expand Up @@ -40,6 +40,81 @@ function changeSection($sectionEditorSubmission, $sectionId) {
}
}

/**
* Assign the default participants to a workflow stage.
* @param $submission Submission
* @param $stageId int
* @param $request Request
*/
function assignDefaultStageParticipants($submission, $stageId, $request) {
$userGroupDao = DAORegistry::getDAO('UserGroupDAO');

// Managerial roles are skipped -- They have access by default and
// are assigned for informational purposes only

// Section editor roles are skipped -- They are assigned by JM roles
// or by other section editors

// Journal roles -- For each journal role user group assigned to this
// stage in setup, iff there is only one user for the group,
// automatically assign the user to the stage
// But skip authors and reviewers, since these are very journal specific
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
$submissionStageGroups = $userGroupDao->getUserGroupsByStage($submission->getContextId(), $stageId, true, true);
while ($userGroup = $submissionStageGroups->next()) {
$users = $userGroupDao->getUsersById($userGroup->getId());
if($users->getCount() == 1) {
$user = $users->next();
$stageAssignmentDao->build($submission->getId(), $userGroup->getId(), $user->getId());
}
}

$notificationMgr = new NotificationManager();
$notificationMgr->updateNotification(
$request,
array(NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_SUBMISSION,
NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_EXTERNAL_REVIEW,
NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_EDITING,
NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_PRODUCTION),
null,
ASSOC_TYPE_SUBMISSION,
$submission->getId()
);

// Reviewer roles -- Do nothing. Reviewers are not included in the stage participant list, they
// are administered via review assignments.

// Author roles
// Assign only the submitter in whatever ROLE_ID_AUTHOR capacity they were assigned previously
$submitterAssignments = $stageAssignmentDao->getBySubmissionAndStageId($submission->getId(), null, null, $submission->getUserId());
while ($assignment = $submitterAssignments->next()) {
$userGroup = $userGroupDao->getById($assignment->getUserGroupId());
if ($userGroup->getRoleId() == ROLE_ID_AUTHOR) {
$stageAssignmentDao->build($submission->getId(), $userGroup->getId(), $assignment->getUserId());
// Only assign them once, since otherwise we'll one assignment for each previous stage.
// And as long as they are assigned once, they will get access to their article.
break;
}
}
}

/**
* Increment a submissions workflow stage.
* @param $submission Submission
* @param $newStage integer One of the WORKFLOW_STAGE_* constants.
* @param $request Request
*/
function incrementWorkflowStage($submission, $newStage, $request) {
// Change the article's workflow stage.
$submission->setStageId($newStage);
$submissionDao = Application::getSubmissionDAO();
$submissionDao->updateObject($submission);

// Assign the default users to the next workflow stage.
$this->assignDefaultStageParticipants($submission, $newStage, $request);
}


/**
* Records an editor's submission decision.
* @param $sectionEditorSubmission object
Expand Down

0 comments on commit fb03e87

Please sign in to comment.