Skip to content

Commit

Permalink
*5557* Cleaned up getAssociatedUserIds() function
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrider committed Sep 3, 2010
1 parent fa00b00 commit 1c87d58
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 125 deletions.
87 changes: 27 additions & 60 deletions classes/monograph/Monograph.inc.php
Expand Up @@ -275,83 +275,50 @@ function getSignoff($signoffType) {

/**
* Get an array of user IDs associated with this monograph
* @param $authors boolean
* @param $reviewers boolean
* @param $editors boolean
* @param $proofreader boolean
* @param $copyeditor boolean
* @param $layoutEditor boolean
* @param $includeReviewers boolean Include reviewers in the array
* @param $userGroupIds array Only look up the user group IDs in the array
* @return array User IDs
*/
function getAssociatedUserIds($authors = true, $reviewers = true, $editors = true, $seriesEditors = true, $proofreader = true, $copyeditor = true, $layoutEditor = true) {
// FIXME #5557: We should just use an array for the third parameter containing all editor role IDs, then iterate over them
function getAssociatedUserIds($includeReviewers = false, $userGroupIds = null) {
$monographId = $this->getId();
$signoffDao =& DAORegistry::getDAO('SignoffDAO');
$userGroupDao =& DAORegistry::getDAO('UserGroupDAO');

$userIds = array();

if($authors) {
$userId = $this->getUserId();
if ($userId) $userIds[] = array('id' => $userId, 'role' => 'author');
// If $userGroupIds is set, iterate through them, adding getUsers to array (with keys as userId)
if (is_array($userGroupIds)) {
foreach($userGroupIds as $userGroupId) {
$users =& $signoffDao->getUsersBySymbolic('SIGNOFF_STAGE', ASSOC_TYPE_MONOGRAPH, $monographId, null, $userGroupId);
while ($user =& $users->next()) {
$userId = $user->getUserId();
if ($userId) $userIds[$userId] = array('id' => $userId);
unset($user);
}
unset($users);
}
} else {
$users =& $signoffDao->getUsersBySymbolic('SIGNOFF_STAGE', ASSOC_TYPE_MONOGRAPH, $monographId);

while ($user =& $users->next()) {
$userId = $user->getUserId();
if ($userId) $userIds[$userId] = array('id' => $userId);
unset($user);
}

}

if($reviewers) {
// Get reviewers if necessary
if($includeReviewers) {
$reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
$reviewAssignments =& $reviewAssignmentDao->getBySubmissionId($monographId);
foreach ($reviewAssignments as $reviewAssignment) {
$userId = $reviewAssignment->getReviewerId();
if ($userId) $userIds[] = array('id' => $userId, 'role' => 'reviewer');
if ($userId) $userIds[$userId] = array('id' => $userId, 'role' => 'reviewer');
unset($reviewAssignment);
}
}

$userGroupDao =& DAORegistry::getDAO('UserGroupDAO');

if($editors) {
$signoffDao =& DAORegistry::getDAO('SignoffDAO');
$userGroupId = $userGroupDao->getByRoleId($this->getPressId(), ROLE_ID_EDITOR);
$users =& $signoffDao->getUsersBySymbolic('SIGNOFF_STAGE', ASSOC_TYPE_MONOGRAPH, $monographId, null, $userGroupId);
while ($user =& $users->next()) {
$userId = $user->getUserId();
if ($userId) $userIds[] = array('id' => $userId, 'role' => 'editor');
unset($user);
}
}

if($seriesEditor) {
$signoffDao =& DAORegistry::getDAO('SignoffDAO');
$userGroupId = $userGroupDao->getByRoleId($this->getPressId(), ROLE_ID_SERIES_EDITOR);
$users =& $signoffDao->getUsersBySymbolic('SIGNOFF_STAGE', ASSOC_TYPE_MONOGRAPH, $monographId, null, $userGroupId);
while ($user =& $users->next()) {
$userId = $user->getUserId();
if ($userId) $userIds[] = array('id' => $userId, 'role' => 'editor');
unset($user);
}
}

if($copyeditor) {
$signoffDao =& DAORegistry::getDAO('SignoffDAO');
$userGroupId = $userGroupDao->getByRoleId($this->getPressId(), ROLE_ID_COPYEDITOR);
$users =& $signoffDao->getUsersBySymbolic('SIGNOFF_STAGE', ASSOC_TYPE_MONOGRAPH, $monographId, null, $userGroupId);
while ($user =& $users->next()) {
$userId = $user->getUserId();
if ($userId) $userIds[] = array('id' => $userId, 'role' => 'editor');
unset($user);
}
}


if($proofreader) {
$signoffDao =& DAORegistry::getDAO('SignoffDAO');
$userGroupId = $userGroupDao->getByRoleId($this->getPressId(), ROLE_ID_PROOFREADER);
$users =& $signoffDao->getUsersBySymbolic('SIGNOFF_STAGE', ASSOC_TYPE_MONOGRAPH, $monographId, null, $userGroupId);
while ($user =& $users->next()) {
$userId = $user->getUserId();
if ($userId) $userIds[] = array('id' => $userId, 'role' => 'editor');
unset($user);
}
}

return $userIds;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/submission/common/Action.inc.php
Expand Up @@ -210,7 +210,7 @@ function saveComment($monograph, &$comment, $emailComment) {

// Send a notification to associated users
import('lib.pkp.classes.notification.NotificationManager');
$notificationUsers = $monograph->getAssociatedUserIds(true, false);
$notificationUsers = $monograph->getAssociatedUserIds();
$notificationManager = new NotificationManager();
foreach ($notificationUsers as $userRole) {
$url = Request::url(null, $userRole['role'], 'submissionReview', $monograph->getId(), null, 'editorDecision');
Expand Down
64 changes: 32 additions & 32 deletions classes/submission/copyeditor/CopyeditorAction.inc.php
Expand Up @@ -54,25 +54,25 @@ function completeCopyedit($copyeditorSubmission, $send = false) {
}

$initialSignoff->setDateCompleted(Core::getCurrentDate());

$authorSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_AUTHOR', ASSOC_TYPE_MONOGRAPH, $copyeditorSubmission->getId());
$authorSignoff->setUserId($author->getId());
$authorSignoff->setDateNotified(Core::getCurrentDate());
$signoffDao->updateObject($initialSignoff);
$signoffDao->updateObject($authorSignoff);


// Add log entry
import('classes.monograph.log.MonographLog');
import('classes.monograph.log.MonographEventLogEntry');

MonographLog::logEvent(
$copyeditorSubmission->getId(),
MONOGRAPH_LOG_COPYEDIT_INITIAL,
MONOGRAPH_LOG_TYPE_COPYEDIT, $user->getId(),
'log.copyedit.initialEditComplete',
$copyeditorSubmission->getId(),
MONOGRAPH_LOG_COPYEDIT_INITIAL,
MONOGRAPH_LOG_TYPE_COPYEDIT, $user->getId(),
'log.copyedit.initialEditComplete',
Array(
'copyeditorName' => $user->getFullName(),
'copyeditorName' => $user->getFullName(),
'monographId' => $copyeditorSubmission->getId()
)
);
Expand Down Expand Up @@ -184,9 +184,9 @@ function completeFinalCopyedit($copyeditorSubmission, $send = false) {
*/
function copyeditUnderway(&$copyeditorSubmission) {
if (!HookRegistry::call('CopyeditorAction::copyeditUnderway', array(&$copyeditorSubmission))) {
$copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
$copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
$signoffDao =& DAORegistry::getDAO('SignoffDAO');

$initialSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_INITIAL', ASSOC_TYPE_MONOGRAPH, $copyeditorSubmission->getId());
$finalSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_FINAL', ASSOC_TYPE_MONOGRAPH, $copyeditorSubmission->getId());

Expand All @@ -208,18 +208,18 @@ function copyeditUnderway(&$copyeditorSubmission) {
import('classes.monograph.log.MonographEventLogEntry');

MonographLog::logEvent(
$copyeditorSubmission->getId(),
MONOGRAPH_LOG_COPYEDIT_INITIATE,
MONOGRAPH_LOG_TYPE_COPYEDIT,
$user->getId(), 'log.copyedit.initiate',
$copyeditorSubmission->getId(),
MONOGRAPH_LOG_COPYEDIT_INITIATE,
MONOGRAPH_LOG_TYPE_COPYEDIT,
$user->getId(), 'log.copyedit.initiate',
Array(
'copyeditorName' => $user->getFullName(),
'copyeditorName' => $user->getFullName(),
'monographId' => $copyeditorSubmission->getId()
)
);
}
}
}
}

/**
* Upload the copyedited version of a monograph.
Expand All @@ -228,7 +228,7 @@ function copyeditUnderway(&$copyeditorSubmission) {
function uploadCopyeditVersion($copyeditorSubmission, $copyeditStage) {
import('classes.file.MonographFileManager');
$monographFileDao =& DAORegistry::getDAO('MonographFileDAO');
$copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
$copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
$signoffDao =& DAORegistry::getDAO('SignoffDAO');

if($copyeditStage == 'initial') {
Expand Down Expand Up @@ -276,8 +276,8 @@ function uploadCopyeditVersion($copyeditorSubmission, $copyeditStage) {

MonographLog::logEventEntry($copyeditorSubmission->getId(), $entry);
}


}

//
Expand Down Expand Up @@ -314,17 +314,17 @@ function postLayoutComment($monograph, $emailComment) {

// Send a notification to associated users
import('lib.pkp.classes.notification.NotificationManager');
$notificationUsers = $monograph->getAssociatedUserIds(true, false);
$notificationUsers = $monograph->getAssociatedUserIds();
$notificationManager = new NotificationManager();
foreach ($notificationUsers as $userRole) {
$url = Request::url(null, $userRole['role'], 'submissionEditing', $monograph->getId(), null, 'layout');
$notificationManager->createNotification(
$userRole['id'], "notification.type.layoutComment",
$monograph->getLocalizedTitle(), $url, 1,
$userRole['id'], "notification.type.layoutComment",
$monograph->getLocalizedTitle(), $url, 1,
NOTIFICATION_TYPE_LAYOUT_COMMENT
);
}

if ($emailComment) {
$commentForm->email();
}
Expand Down Expand Up @@ -352,7 +352,7 @@ function viewCopyeditComments($monograph) {
}

/**
* Post copyedit comment.
* Post copyedit comment.
* @param $monograph object
*/
function postCopyeditComment($monograph, $emailComment) {
Expand All @@ -367,18 +367,18 @@ function postCopyeditComment($monograph, $emailComment) {

// Send a notification to associated users
import('lib.pkp.classes.notification.NotificationManager');
$notificationUsers = $monograph->getAssociatedUserIds(true, false);
$notificationUsers = $monograph->getAssociatedUserIds();
$notificationManager = new NotificationManager();
foreach ($notificationUsers as $userRole) {
$url = Request::url(null, $userRole['role'], 'submissionEditing', $monograph->getId(), null, 'coypedit');
$notificationManager->createNotification(
$userRole['id'],
'notification.type.copyeditComment',
$monograph->getLocalizedTitle(),
$userRole['id'],
'notification.type.copyeditComment',
$monograph->getLocalizedTitle(),
$url, 1, NOTIFICATION_TYPE_COPYEDIT_COMMENT
);
}

if ($emailComment) {
$commentForm->email();
}
Expand All @@ -402,7 +402,7 @@ function postCopyeditComment($monograph, $emailComment) {
* @param $revision int
*/
function downloadCopyeditorFile($submission, $fileId, $revision = null) {
$copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
$copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');

$canDownload = false;

Expand All @@ -413,17 +413,17 @@ function downloadCopyeditorFile($submission, $fileId, $revision = null) {
// 4) The final copyedit revision
// 5) Layout galleys
if ($submission->getFileBySignoffType('SIGNOFF_COPYEDITING_INITIAL', true) == $fileId) {
$monographFileDao =& DAORegistry::getDAO('MonographFileDAO');
$monographFileDao =& DAORegistry::getDAO('MonographFileDAO');
$currentRevision =& $monographFileDao->getRevisionNumber($fileId);

if ($revision == null) {
$revision = $currentRevision;
}

$initialSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_INITIAL', ASSOC_TYPE_MONOGRAPH, $authorSubmission->getMonographId());
$authorSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_FINAL', ASSOC_TYPE_MONOGRAPH, $authorSubmission->getMonographId());
$finalSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_FINAL', ASSOC_TYPE_MONOGRAPH, $authorSubmission->getMonographId());

if ($revision == 1) {
$canDownload = true;
} else if ($initialSignoff->getFileRevision() == $revision) {
Expand Down
16 changes: 8 additions & 8 deletions classes/submission/designer/DesignerAction.inc.php
Expand Up @@ -3,7 +3,7 @@
/**
* @defgroup submission_designer_DesignerAction
*/

/**
* @file classes/submission/designer/DesignerAction.inc.php
*
Expand Down Expand Up @@ -44,7 +44,7 @@ function selectDesigner($userId, $assignmentId, $submission) {
$designer =& $userDao->getUser($designSignoff->getUserId());
MonographLog::logEvent($submission->getId(), MONOGRAPH_LOG_LAYOUT_UNASSIGN, MONOGRAPH_LOG_TYPE_LAYOUT, $designSignoff->getId(), 'log.layout.layoutEditorUnassigned', array('editorName' => $designer->getFullName(), 'monographId' => $submission->getId()));
}

$designSignoff->setUserId($userId);
$signoffDao->updateObject($designSignoff);

Expand Down Expand Up @@ -213,10 +213,10 @@ function postLayoutComment($monograph, $emailComment) {

if ($commentForm->validate()) {
$commentForm->execute();

// Send a notification to associated users
import('lib.pkp.classes.notification.NotificationManager');
$notificationUsers = $monograph->getAssociatedUserIds(true, false);
$notificationUsers = $monograph->getAssociatedUserIds();
$notificationManager = new NotificationManager();
foreach ($notificationUsers as $userRole) {
$url = Request::url(null, $userRole['role'], 'submissionEditing', $monograph->getId(), null, 'layout');
Expand All @@ -225,7 +225,7 @@ function postLayoutComment($monograph, $emailComment) {
$monograph->getMonographTitle(), $url, 1, NOTIFICATION_TYPE_LAYOUT_COMMENT
);
}

if ($emailComment) {
$commentForm->email();
}
Expand Down Expand Up @@ -265,10 +265,10 @@ function postProofreadComment($monograph, $emailComment) {

if ($commentForm->validate()) {
$commentForm->execute();

// Send a notification to associated users
import('lib.pkp.classes.notification.NotificationManager');
$notificationUsers = $monograph->getAssociatedUserIds(true, false);
$notificationUsers = $monograph->getAssociatedUserIds();
$notificationManager = new NotificationManager();
foreach ($notificationUsers as $userRole) {
$url = Request::url(null, $userRole['role'], 'submissionEditing', $monograph->getId(), null, 'proofread');
Expand All @@ -277,7 +277,7 @@ function postProofreadComment($monograph, $emailComment) {
$monograph->getMonographTitle(), $url, 1, NOTIFICATION_TYPE_PROOFREAD_COMMENT
);
}

if ($emailComment) {
$commentForm->email();
}
Expand Down
2 changes: 1 addition & 1 deletion classes/submission/form/comment/EditCommentForm.inc.php
Expand Up @@ -123,7 +123,7 @@ function emailHelper() {
$recipients = array();

// Get editors for monograph
// FIXME #5557: Get IDs from Monograph->getAssociatedUserIds
// FIXME #5880: Get IDs from Monograph->getAssociatedUserIds, or remove this class if not needed
$editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
$editAssignments =& $editAssignmentDao->getByIdsByMonographId($this->monograph->getId());
$editAssignments =& $editAssignments->toArray();
Expand Down
Expand Up @@ -87,7 +87,7 @@ function email() {
if ($user) $recipients = array_merge($recipients, array($user->getEmail() => $user->getFullName()));
} else {
// Then add editor
// FIXME #5557: Get IDs from Monograph->getAssociatedUserIds
// FIXME #5880: Get IDs from Monograph->getAssociatedUserIds, or remove this class if not needed
$editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
$editAssignments =& $editAssignmentDao->getByIdsByMonographId($this->monograph->getMonographId());
$editorAddresses = array();
Expand Down
2 changes: 1 addition & 1 deletion classes/submission/form/comment/LayoutCommentForm.inc.php
Expand Up @@ -85,7 +85,7 @@ function email() {
}
} else {
// Then add editor
// FIXME #5557: Get IDs from Monograph->getAssociatedUserIds
// FIXME #5880: Get IDs from Monograph->getAssociatedUserIds, or remove this class if not needed
$editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
$editAssignments =& $editAssignmentDao->getByIdsByMonographId($this->monograph->getId());
$editorAddresses = array();
Expand Down
Expand Up @@ -73,7 +73,7 @@ function email() {
// excluding whomever posted the comment.

// Get editors
// FIXME #5557: Get IDs from Monograph->getAssociatedUserIds
// FIXME #5880: Get IDs from Monograph->getAssociatedUserIds, or remove this class if not needed
$editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
$editAssignments =& $editAssignmentDao->getByIdsByMonographId($this->monograph->getId());
$editorAddresses = array();
Expand Down

0 comments on commit 1c87d58

Please sign in to comment.