00001 <?php
00002
00019 import('lib.pkp.classes.security.PKPUserGroupDAO');
00020
00021 class UserGroupDAO extends PKPUserGroupDAO {
00025 function UserGroupDAO() {
00026 parent::PKPUserGroupDAO();
00027 }
00028
00036 function &getUserGroupsByStage($pressId, $stageId, $omitAuthors = false, $omitReviewers = false, $roleId = null) {
00037 $params = array((int) $pressId, (int) $stageId);
00038 if ($omitAuthors) $params[] = ROLE_ID_AUTHOR;
00039 if ($omitReviewers) $params[] = ROLE_ID_REVIEWER;
00040 if ($roleId) $params[] = $roleId;
00041 $result =& $this->retrieve(
00042 'SELECT ug.*
00043 FROM user_groups ug
00044 JOIN user_group_stage ugs ON (ug.user_group_id = ugs.user_group_id AND ug.context_id = ugs.press_id)
00045 WHERE ugs.press_id = ? AND
00046 ugs.stage_id = ?' .
00047 ($omitAuthors?' AND ug.role_id <> ?':'') .
00048 ($omitReviewers?' AND ug.role_id <> ?':'') .
00049 ($roleId?' AND ug.role_id = ?':'') .
00050 ' ORDER BY role_id ASC',
00051 $params
00052 );
00053
00054 $returner = new DAOResultFactory($result, $this, '_returnFromRow');
00055 return $returner;
00056 }
00057
00063 function getAssignedStagesByUserGroupId($pressId, $userGroupId) {
00064 $result =& $this->retrieve(
00065 'SELECT stage_id
00066 FROM user_group_stage
00067 WHERE press_id = ? AND
00068 user_group_id = ?',
00069 array((int) $pressId, (int) $userGroupId)
00070 );
00071
00072 $returner = array();
00073
00074 while (!$result->EOF) {
00075 $stageId = $result->Fields('stage_id');
00076 $returner[$stageId] = $this->getTranslationKeyFromId($stageId);
00077 $result->MoveNext();
00078 }
00079
00080 return $returner;
00081 }
00082
00089 function userGroupAssignedToStage($userGroupId, $stageId) {
00090 $result = $this->retrieve(
00091 'SELECT COUNT(*)
00092 FROM user_group_stage
00093 WHERE user_group_id = ? AND
00094 stage_id = ?',
00095 array((int) $userGroupId, (int) $stageId)
00096 );
00097
00098 $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
00099
00100 $result->Close();
00101 unset($result);
00102
00103 return $returner;
00104 }
00105
00113 function assignGroupToStage($pressId, $userGroupId, $stageId) {
00114 return $this->update(
00115 'INSERT INTO user_group_stage (press_id, user_group_id, stage_id) VALUES (?, ?, ?)',
00116 array((int) $pressId, (int) $userGroupId, (int) $stageId)
00117 );
00118 }
00119
00127 function removeGroupFromStage($pressId, $userGroupId, $stageId) {
00128 return $this->update(
00129 'DELETE FROM user_group_stage WHERE press_id = ? AND user_group_id = ? AND stage_id = ?',
00130 array((int) $pressId, (int) $userGroupId, (int) $stageId)
00131 );
00132 }
00133
00141 function userAssignmentExists($pressId, $userId, $stageId) {
00142 $result =& $this->retrieve(
00143 'SELECT COUNT(*)
00144 FROM user_group_stage ugs,
00145 user_user_groups uug
00146 WHERE ugs.user_group_id = uug.user_group_id AND
00147 ugs.press_id = ? AND
00148 uug.user_id = ? AND
00149 ugs.stage_id = ?',
00150 array((int) $pressId, (int) $userId, (int) $stageId)
00151 );
00152
00153 $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
00154
00155 $result->Close();
00156 unset($result);
00157
00158 return $returner;
00159 }
00160
00161
00162
00163
00164
00170 function getPathFromId($stageId) {
00171 static $stageMapping = array(
00172 WORKFLOW_STAGE_ID_SUBMISSION => WORKFLOW_STAGE_PATH_SUBMISSION,
00173 WORKFLOW_STAGE_ID_INTERNAL_REVIEW => WORKFLOW_STAGE_PATH_INTERNAL_REVIEW,
00174 WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW,
00175 WORKFLOW_STAGE_ID_EDITING => WORKFLOW_STAGE_PATH_EDITING,
00176 WORKFLOW_STAGE_ID_PRODUCTION => WORKFLOW_STAGE_PATH_PRODUCTION
00177 );
00178 if (isset($stageMapping[$stageId])) {
00179 return $stageMapping[$stageId];
00180 } else {
00181 return null;
00182 }
00183 }
00184
00190 function getIdFromPath($stagePath) {
00191 static $stageMapping = array(
00192 WORKFLOW_STAGE_PATH_SUBMISSION => WORKFLOW_STAGE_ID_SUBMISSION,
00193 WORKFLOW_STAGE_PATH_INTERNAL_REVIEW => WORKFLOW_STAGE_ID_INTERNAL_REVIEW,
00194 WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW => WORKFLOW_STAGE_ID_EXTERNAL_REVIEW,
00195 WORKFLOW_STAGE_PATH_EDITING => WORKFLOW_STAGE_ID_EDITING,
00196 WORKFLOW_STAGE_PATH_PRODUCTION => WORKFLOW_STAGE_ID_PRODUCTION
00197 );
00198 if (isset($stageMapping[$stagePath])) {
00199 return $stageMapping[$stagePath];
00200 } else {
00201 return null;
00202 }
00203 }
00204
00210 function getTranslationKeyFromId($stageId) {
00211 $stageMapping = $this->getWorkflowStageTranslationKeys();
00212
00213 assert(isset($stageMapping[$stageId]));
00214 return $stageMapping[$stageId];
00215 }
00216
00222 function getWorkflowStageTranslationKeys() {
00223 static $stageMapping = array(
00224 WORKFLOW_STAGE_ID_SUBMISSION => 'submission.submission',
00225 WORKFLOW_STAGE_ID_INTERNAL_REVIEW => 'workflow.review.internalReview',
00226 WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => 'workflow.review.externalReview',
00227 WORKFLOW_STAGE_ID_EDITING => 'submission.editorial',
00228 WORKFLOW_STAGE_ID_PRODUCTION => 'submission.production'
00229 );
00230
00231 return $stageMapping;
00232 }
00233
00239 function getWorkflowStageKeysAndPaths() {
00240 $workflowStages = $this->getWorkflowStageTranslationKeys();
00241 $stageMapping = array();
00242 foreach ($workflowStages as $stageId => $translationKey) {
00243 $stageMapping[$stageId] = array(
00244 'id' => $stageId,
00245 'translationKey' => $translationKey,
00246 'path' => $this->getPathFromId($stageId)
00247 );
00248 }
00249
00250 return $stageMapping;
00251 }
00252 }
00253
00254 ?>