Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
UserGroupDAO.inc.php
1 <?php
2 
21 import('lib.pkp.classes.security.UserGroup');
22 
23 class UserGroupDAO extends DAO {
25  var $userDao;
26 
29 
33  function UserGroupDAO() {
34  parent::DAO();
35  $this->userDao = DAORegistry::getDAO('UserDAO');
36  $this->userGroupAssignmentDao = DAORegistry::getDAO('UserGroupAssignmentDAO');
37  }
38 
43  function newDataObject() {
44  return new UserGroup();
45  }
46 
52  function _returnFromRow($row) {
53  $userGroup = $this->newDataObject();
54  $userGroup->setId($row['user_group_id']);
55  $userGroup->setRoleId($row['role_id']);
56  $userGroup->setContextId($row['context_id']);
57  $userGroup->setPath($row['path']);
58  $userGroup->setDefault($row['is_default']);
59  $userGroup->setShowTitle($row['show_title']);
60  $userGroup->setPermitSelfRegistration($row['permit_self_registration']);
61 
62  $this->getDataObjectSettings('user_group_settings', 'user_group_id', $row['user_group_id'], $userGroup);
63 
64  HookRegistry::call('UserGroupDAO::_returnFromRow', array(&$userGroup, &$row));
65 
66  return $userGroup;
67  }
68 
73  function insertObject($userGroup) {
74  $this->update(
75  'INSERT INTO user_groups
76  (role_id, path, context_id, is_default, show_title, permit_self_registration)
77  VALUES
78  (?, ?, ?, ?, ?, ?)',
79  array(
80  (int) $userGroup->getRoleId(),
81  $userGroup->getPath(),
82  (int) $userGroup->getContextId(),
83  $userGroup->getDefault()?1:0,
84  $userGroup->getShowTitle()?1:0,
85  $userGroup->getPermitSelfRegistration()?1:0,
86  )
87  );
88 
89  $userGroup->setId($this->getInsertId());
90  $this->updateLocaleFields($userGroup);
91  return $this->getInsertId();
92  }
93 
98  function updateObject($userGroup) {
99  $this->update(
100  'UPDATE user_groups SET
101  role_id = ?,
102  path = ?,
103  context_id = ?,
104  is_default = ?,
105  show_title = ?,
106  permit_self_registration = ?
107  WHERE user_group_id = ?',
108  array(
109  (int) $userGroup->getRoleId(),
110  $userGroup->getPath(),
111  (int) $userGroup->getContextId(),
112  $userGroup->getDefault()?1:0,
113  $userGroup->getShowTitle()?1:0,
114  $userGroup->getPermitSelfRegistration()?1:0,
115  (int) $userGroup->getId(),
116  )
117  );
118 
119  $this->updateLocaleFields($userGroup);
120  }
121 
128  function deleteById($contextId, $userGroupId) {
129  $ret1 = $this->userGroupAssignmentDao->deleteAssignmentsByUserGroupId($userGroupId);
130  $ret2 = $this->update('DELETE FROM user_group_settings WHERE user_group_id = ?', (int) $userGroupId);
131  $ret3 = $this->update('DELETE FROM user_groups WHERE user_group_id = ?', (int) $userGroupId);
132  $ret4 = $this->removeAllStagesFromGroup($contextId, $userGroupId);
133  return $ret1 && $ret2 && $ret3 && $ret4;
134  }
135 
141  function deleteObject($userGroup) {
142  return $this->deleteById($userGroup->getContextId(), $userGroup->getId());
143  }
144 
145 
150  function deleteByContextId($contextId) {
151  $result = $this->retrieve('SELECT user_group_id FROM user_groups WHERE context_id = ?', (int) $contextId);
152 
153  $returner = true;
154  for ($i=1; !$result->EOF; $i++) {
155  list($userGroupId) = $result->fields;
157  $ret1 = $this->update('DELETE FROM user_group_stage WHERE user_group_id = ?', (int) $userGroupId);
158  $ret2 = $this->update('DELETE FROM user_group_settings WHERE user_group_id = ?', (int) $userGroupId);
159  $ret3 = $this->update('DELETE FROM user_groups WHERE user_group_id = ?', (int) $userGroupId);
160 
161  $returner = $returner && $ret1 && $ret2 && $ret3;
162  $result->MoveNext();
163  }
164 
165  return $returner;
166  }
167 
172  function getInsertId() {
173  return $this->_getInsertId('user_groups', 'user_group_id');
174  }
175 
180  function getLocaleFieldNames() {
181  return array('name', 'abbrev');
182  }
183 
188  function updateLocaleFields($userGroup) {
189  $this->updateDataObjectSettings('user_group_settings', $userGroup, array(
190  'user_group_id' => (int) $userGroup->getId()
191  ));
192  }
193 
199  function getById($userGroupId, $contextId = null) {
200  $params = array((int) $userGroupId);
201  if ($contextId !== null) $params[] = (int) $contextId;
202  $result = $this->retrieve(
203  'SELECT *
204  FROM user_groups
205  WHERE user_group_id = ?' . ($contextId !== null?' AND context_id = ?':''),
206  $params
207  );
208 
209  return $this->_returnFromRow($result->GetRowAssoc(false));
210  }
211 
218  function getDefaultByRoleId($contextId, $roleId) {
219  $allDefaults = $this->getByRoleId($contextId, $roleId, true);
220  if ($allDefaults->eof()) return false;
221  return $allDefaults->next();
222  }
223 
230  function isDefault($userGroupId) {
231  $result = $this->retrieve(
232  'SELECT is_default FROM user_groups
233  WHERE user_group_id = ?', array((int)$userGroupId)
234  );
235 
236  $result = $result->GetArray();
237  if (isset($result[0]['is_default'])) {
238  return $result[0]['is_default'];
239  } else {
240  return false;
241  }
242  }
243 
252  function getByRoleId($contextId, $roleId, $default = false, $dbResultRange = null) {
253  $params = array((int) $contextId, (int) $roleId);
254  if ($default) $params[] = 1; // true
255  $result = $this->retrieveRange(
256  'SELECT *
257  FROM user_groups
258  WHERE context_id = ? AND
259  role_id = ?' . ($default?' AND is_default = ?':''),
260  $params,
261  $dbResultRange
262  );
263 
264  return new DAOResultFactory($result, $this, '_returnFromRow');
265  }
266 
272  function getUserGroupIdsByRoleId($roleId, $contextId = null) {
273  $sql = 'SELECT user_group_id FROM user_groups WHERE role_id = ?';
274  $params = array((int) $roleId);
275 
276  if ($contextId) {
277  $sql .= ' AND context_id = ?';
278  $params[] = (int) $contextId;
279  }
280 
281  $result = $this->retrieve($sql, $params);
282 
283  $userGroupIds = array();
284  while (!$result->EOF) {
285  $userGroupIds[] = (int) $result->fields[0];
286  $result->MoveNext();
287  }
288 
289  $result->Close();
290  return $userGroupIds;
291  }
292 
300  function userInGroup($userId, $userGroupId) {
301  $result = $this->retrieve(
302  'SELECT count(*)
303  FROM user_groups ug
304  JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id
305  WHERE
306  uug.user_id = ? AND
307  ug.user_group_id = ?',
308  array((int) $userId, (int) $userGroupId)
309  );
310 
311  // > 0 because user could belong to more than one user group with this role
312  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
313 
314  $result->Close();
315  return $returner;
316  }
317 
324  function userInAnyGroup($userId, $contextId = null) {
325  $params = array((int) $userId);
326  if ($contextId) $params[] = (int) $contextId;
327 
328  $result = $this->retrieve(
329  'SELECT count(*)
330  FROM user_groups ug
331  JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id
332  WHERE uug.user_id = ?' . ($contextId?' AND ug.context_id = ?':''),
333  $params
334  );
335 
336  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
337 
338  $result->Close();
339  return $returner;
340  }
341 
348  function getByUserId($userId, $contextId = null){
349  $params = array((int) $userId);
350  if ($contextId) {
351  $params[] = (int) $contextId;
352  }
353  $result = $this->retrieve(
354  'SELECT ug.*
355  FROM user_groups ug
356  JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id
357  WHERE uug.user_id = ?' . ($contextId?' AND ug.context_id = ?':''),
358  $params
359  );
360 
361  return new DAOResultFactory($result, $this, '_returnFromRow');
362  }
363 
370  function contextHasGroup($contextId, $userGroupId) {
371  $result = $this->retrieve(
372  'SELECT count(*)
373  FROM user_groups ug
374  WHERE ug.user_group_id = ?
375  AND ug.context_id = ?',
376  array (
377  (int) $userGroupId,
378  (int) $contextId
379  )
380  );
381 
382  $returner = isset($result->fields[0]) && $result->fields[0] == 0 ? false : true;
383 
384  $result->Close();
385  return $returner;
386  }
387 
394  function getByContextId($contextId = null, $dbResultRange = null) {
395  $params = array();
396  if ($contextId) $params[] = (int) $contextId;
397  $result = $this->retrieveRange(
398  'SELECT ug.*
399  FROM user_groups ug' .
400  ($contextId?' WHERE ug.context_id = ?':''),
401  $params,
402  $dbResultRange);
403 
404  return new DAOResultFactory($result, $this, '_returnFromRow');
405  }
406 
412  function getContextUsersCount($contextId, $userGroupId = null, $roleId = null) {
413  $params = array((int) $contextId);
414  if ($userGroupId) $params[] = (int) $userGroupId;
415  if ($roleId) $params[] = (int) $roleId;
416  $result = $this->retrieve(
417  'SELECT COUNT(DISTINCT(uug.user_id))
418  FROM user_groups ug
419  JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id
420  WHERE context_id = ?' . ($userGroupId?' AND ug.user_group_id = ?':'') . ($roleId?' AND ug.role_id = ?':''),
421  $params
422  );
423 
424  $returner = $result->fields[0];
425 
426  $result->Close();
427  return (int) $returner;
428  }
429 
438  function getUsersByContextId($contextId, $searchType = null, $search = null, $searchMatch = null, $dbResultRange = null) {
439  return $this->getUsersById(null, $contextId, $searchType, $search, $searchMatch, $dbResultRange);
440  }
441 
448  function getUsersNotInRole($roleId, $contextId = null, $search = null) {
449  $params = array((int) $roleId);
450  if ($contextId) $params[] = (int) $contextId;
451  if(isset($search)) $params = array_merge($params, array_pad(array(), 5, '%' . $search . '%'));
452 
453  $result = $this->retrieve(
454  'SELECT DISTINCT u.*
455  FROM users u, user_groups ug, user_user_groups uug
456  WHERE ug.user_group_id = uug.user_group_id AND
457  u.user_id = uug.user_id AND
458  ug.role_id <> ?' .
459  ($contextId?' AND ug.context_id = ?':'') .
460  (isset($search) ? ' AND (u.first_name LIKE ? OR u.middle_name LIKE ? OR u.last_name LIKE ? OR u.email LIKE ? OR u.username LIKE ?)':''),
461  $params
462  );
463 
464  return new DAOResultFactory($result, $this->userDao, '_returnUserFromRowWithData');
465  }
466 
476  function getUsersById($userGroupId = null, $contextId = null, $searchType = null, $search = null, $searchMatch = null, $dbResultRange = null) {
477  $params = array();
478 
479  if ($contextId) $params[] = (int) $contextId;
480  if ($userGroupId) $params[] = (int) $userGroupId;
481 
482  $result = $this->retrieveRange(
483  'SELECT DISTINCT u.*
484  FROM users AS u
485  LEFT JOIN user_settings us ON (us.user_id = u.user_id AND us.setting_name = \'affiliation\')
486  LEFT JOIN user_interests ui ON (u.user_id = ui.user_id)
487  LEFT JOIN controlled_vocab_entry_settings cves ON (ui.controlled_vocab_entry_id = cves.controlled_vocab_entry_id)
488  LEFT JOIN user_user_groups uug ON (uug.user_id = u.user_id)
489  LEFT JOIN user_groups ug ON (ug.user_group_id = uug.user_group_id)
490  WHERE 1=1' .
491  ($contextId?' AND ug.context_id = ?':'') .
492  ($userGroupId?' AND ug.user_group_id = ?':'') .
493  $this->_getSearchSql($searchType, $search, $searchMatch, $params),
494  $params,
495  $dbResultRange
496  );
497 
498  return new DAOResultFactory($result, $this->userDao, '_returnUserFromRowWithData');
499  }
500 
501  //
502  // UserGroupAssignment related
503  //
508  function deleteAssignmentsByUserId($userId, $userGroupId = null) {
509  $this->userGroupAssignmentDao->deleteByUserId($userId, $userGroupId);
510  }
511 
516  function deleteAssignmentsByUserGroupId($userGroupId) {
517  $this->userGroupAssignmentDao->deleteAssignmentsByUserGroupId($userGroupId);
518  }
519 
525  function deleteAssignmentsByContextId($contextId, $userId = null) {
526  $this->userGroupAssignmentDao->deleteAssignmentsByContextId($contextId, $userId);
527  }
528 
534  function assignUserToGroup($userId, $groupId) {
535  $assignment = $this->userGroupAssignmentDao->newDataObject();
536  $assignment->setUserId($userId);
537  $assignment->setUserGroupId($groupId);
538  return $this->userGroupAssignmentDao->insertObject($assignment);
539  }
547  function removeUserFromGroup($userId, $groupId, $contextId) {
548  $assignments = $this->userGroupAssignmentDao->getByUserId($userId, $contextId);
549  while ($assignment = $assignments->next()) {
550  if ($assignment->getUserGroupId() == $groupId) {
551  $this->userGroupAssignmentDao->deleteAssignment($assignment);
552  }
553  }
554  }
555 
561  function removeAllStagesFromGroup($contextId, $userGroupId) {
562  $assignedStages = $this->getAssignedStagesByUserGroupId($contextId, $userGroupId);
563  foreach($assignedStages as $stageId => $stageLocaleKey) {
564  $this->removeGroupFromStage($contextId, $userGroupId, $stageId);
565  }
566  }
575  function assignGroupToStage($contextId, $userGroupId, $stageId) {
576  return $this->update(
577  'INSERT INTO user_group_stage (context_id, user_group_id, stage_id) VALUES (?, ?, ?)',
578  array((int) $contextId, (int) $userGroupId, (int) $stageId)
579  );
580  }
589  function removeGroupFromStage($contextId, $userGroupId, $stageId) {
590  return $this->update(
591  'DELETE FROM user_group_stage WHERE context_id = ? AND user_group_id = ? AND stage_id = ?',
592  array((int) $contextId, (int) $userGroupId, (int) $stageId)
593  );
594  }
596  //
597  // Extra settings (not handled by rest of Dao)
598  //
607  function updateSetting($userGroupId, $name, $value, $type = null, $isLocalized = false) {
608  $keyFields = array('setting_name', 'locale', 'user_group_id');
609 
610  if (!$isLocalized) {
611  $value = $this->convertToDB($value, $type);
612  $this->replace('user_group_settings',
613  array(
614  'user_group_id' => (int) $userGroupId,
615  'setting_name' => $name,
616  'setting_value' => $value,
617  'setting_type' => $type,
618  'locale' => ''
619  ),
620  $keyFields
621  );
622  } else {
623  if (is_array($value)) foreach ($value as $locale => $localeValue) {
624  $this->update('DELETE FROM user_group_settings WHERE user_group_id = ? AND setting_name = ? AND locale = ?', array((int) $userGroupId, $name, $locale));
625  if (empty($localeValue)) continue;
626  $type = null;
627  $this->update('INSERT INTO user_group_settings
628  (user_group_id, setting_name, setting_value, setting_type, locale)
629  VALUES (?, ?, ?, ?, ?)',
630  array(
631  $userGroupId, $name, $this->convertToDB($localeValue, $type), $type, $locale
632  )
633  );
634  }
635  }
636  }
637 
638 
646  function getSetting($userGroupId, $name, $locale = null) {
647  $params = array((int) $userGroupId, $name);
648  if ($locale) $params[] = $locale;
649  $result = $this->retrieve(
650  'SELECT setting_name, setting_value, setting_type, locale
651  FROM user_group_settings
652  WHERE user_group_id = ? AND
653  setting_name = ?' .
654  ($locale?' AND locale = ?':''),
655  $params
656  );
657 
658  $recordCount = $result->RecordCount();
659  $returner = false;
660  if ($recordCount == 1) {
661  $row = $result->getRowAssoc(false);
662  $returner = $this->convertFromDB($row['setting_value'], $row['setting_type']);
663  } elseif ($recordCount > 1) {
664  $returner = array();
665  while (!$result->EOF) {
666  $returner[$row['locale']] = $this->convertFromDB($row['setting_value'], $row['setting_type']);
667  $result->MoveNext();
668  }
669  $result->Close();
670  }
671  return $returner;
672  }
673 
674  //
675  // Install/Defaults with settings
676  //
677 
683  function installSettings($contextId, $filename) {
684  $xmlParser = new XMLParser();
685  $tree = $xmlParser->parse($filename);
686 
687  if (!$tree) {
688  $xmlParser->destroy();
689  return false;
690  }
691 
692  foreach ($tree->getChildren() as $setting) {
693  $roleId = hexdec($setting->getAttribute('roleId'));
694  $nameKey = $setting->getAttribute('name');
695  $abbrevKey = $setting->getAttribute('abbrev');
696  $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration');
697  $defaultStages = explode(',', $setting->getAttribute('stages'));
698  $userGroup = $this->newDataObject();
699 
700  // create a role associated with this user group
701  $role = new Role($roleId);
702  $userGroup = $this->newDataObject();
703  $userGroup->setRoleId($roleId);
704  $userGroup->setPath($role->getPath());
705  $userGroup->setContextId($contextId);
706  $userGroup->setPermitSelfRegistration($permitSelfRegistration);
707  $userGroup->setDefault(true);
708 
709  // insert the group into the DB
710  $userGroupId = $this->insertObject($userGroup);
711 
712  // Install default groups for each stage
713  if (is_array($defaultStages)) { // test for groups with no stage assignments
714  foreach ($defaultStages as $stageId) {
715  if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) {
716  $this->assignGroupToStage($contextId, $userGroupId, $stageId);
717  }
718  }
719  }
720 
721  // add the i18n keys to the settings table so that they
722  // can be used when a new locale is added/reloaded
723  $this->updateSetting($userGroup->getId(), 'nameLocaleKey', $nameKey);
724  $this->updateSetting($userGroup->getId(), 'abbrevLocaleKey', $abbrevKey);
725 
726  // install the settings in the current locale for this context
727  $this->installLocale(AppLocale::getLocale(), $contextId);
728  }
729  }
730 
736  function installLocale($locale, $contextId = null) {
737  $userGroups = $this->getByContextId($contextId);
738  while ($userGroup = $userGroups->next()) {
739  $nameKey = $this->getSetting($userGroup->getId(), 'nameLocaleKey');
740  $this->updateSetting($userGroup->getId(),
741  'name',
742  array($locale => __($nameKey, null, $locale)),
743  'string',
744  $locale,
745  true
746  );
747 
748  $abbrevKey = $this->getSetting($userGroup->getId(), 'abbrevLocaleKey');
749  $this->updateSetting($userGroup->getId(),
750  'abbrev',
751  array($locale => __($abbrevKey, null, $locale)),
752  'string',
753  $locale,
754  true
755  );
756  }
757  }
758 
763  function deleteSettingsByLocale($locale) {
764  return $this->update('DELETE FROM user_group_settings WHERE locale = ?', $locale);
765  }
766 
774  function _getSearchSql($searchType, $search, $searchMatch, &$params) {
775  $searchTypeMap = array(
776  USER_FIELD_FIRSTNAME => 'u.first_name',
777  USER_FIELD_LASTNAME => 'u.last_name',
778  USER_FIELD_USERNAME => 'u.username',
779  USER_FIELD_EMAIL => 'u.email',
780  USER_FIELD_AFFILIATION => 'us.setting_value',
781  );
782 
783  $searchSql = '';
784 
785  if (!empty($search)) {
786 
787  if (!isset($searchTypeMap[$searchType])) {
788  $str = $this->concat('u.first_name', 'u.last_name', 'u.email', 'us.setting_value');
789  $concatFields = ' ( LOWER(' . $str . ') LIKE ? OR LOWER(cves.setting_value) LIKE ? ) ';
790 
791  $search = strtolower($search);
792 
793  $words = preg_split('{\s+}', $search);
794  $searchFieldMap = array();
795 
796  foreach ($words as $word) {
797  $searchFieldMap[] = $concatFields;
798  $term = '%' . $word . '%';
799  array_push($params, $term, $term);
800  }
801 
802  $searchSql .= ' AND ( ' . join(' AND ', $searchFieldMap) . ' ) ';
803  } else {
804  $fieldName = $searchTypeMap[$searchType];
805  switch ($searchMatch) {
806  case 'is':
807  $searchSql = "AND LOWER($fieldName) = LOWER(?)";
808  $params[] = $search;
809  break;
810  case 'contains':
811  $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
812  $params[] = '%' . $search . '%';
813  break;
814  case 'startsWith':
815  $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
816  $params[] = $search . '%';
817  break;
818  }
819  }
820  } else {
821  switch ($searchType) {
822  case USER_FIELD_USERID:
823  $searchSql = 'AND u.user_id = ?';
824  break;
825  case USER_FIELD_INITIAL:
826  $searchSql = 'AND LOWER(u.last_name) LIKE LOWER(?)';
827  break;
828  }
829  }
830 
831  $searchSql .= ' ORDER BY u.last_name, u.first_name'; // FIXME Add "sort field" parameter?
832 
833  return $searchSql;
834  }
835 
836  //
837  // Public helper methods
838  //
839 
845  function getPathFromId($stageId) {
846  static $stageMapping = array(
847  WORKFLOW_STAGE_ID_SUBMISSION => WORKFLOW_STAGE_PATH_SUBMISSION,
848  WORKFLOW_STAGE_ID_INTERNAL_REVIEW => WORKFLOW_STAGE_PATH_INTERNAL_REVIEW,
849  WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW,
850  WORKFLOW_STAGE_ID_EDITING => WORKFLOW_STAGE_PATH_EDITING,
851  WORKFLOW_STAGE_ID_PRODUCTION => WORKFLOW_STAGE_PATH_PRODUCTION
852  );
853  if (isset($stageMapping[$stageId])) {
854  return $stageMapping[$stageId];
855  }
856  return null;
857  }
858 
864  function getIdFromPath($stagePath) {
865  static $stageMapping = array(
866  WORKFLOW_STAGE_PATH_SUBMISSION => WORKFLOW_STAGE_ID_SUBMISSION,
867  WORKFLOW_STAGE_PATH_INTERNAL_REVIEW => WORKFLOW_STAGE_ID_INTERNAL_REVIEW,
868  WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW => WORKFLOW_STAGE_ID_EXTERNAL_REVIEW,
869  WORKFLOW_STAGE_PATH_EDITING => WORKFLOW_STAGE_ID_EDITING,
870  WORKFLOW_STAGE_PATH_PRODUCTION => WORKFLOW_STAGE_ID_PRODUCTION
871  );
872  if (isset($stageMapping[$stagePath])) {
873  return $stageMapping[$stagePath];
874  }
875  return null;
876  }
877 
883  function getTranslationKeyFromId($stageId) {
884  $stageMapping = $this->getWorkflowStageTranslationKeys();
885 
886  assert(isset($stageMapping[$stageId]));
887  return $stageMapping[$stageId];
888  }
894  static function getWorkflowStageTranslationKeys() {
895  $applicationStages = Application::getApplicationStages();
896  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION);
897  static $stageMapping = array(
898  WORKFLOW_STAGE_ID_SUBMISSION => 'submission.submission',
899  WORKFLOW_STAGE_ID_INTERNAL_REVIEW => 'workflow.review.internalReview',
900  WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => 'workflow.review.externalReview',
901  WORKFLOW_STAGE_ID_EDITING => 'submission.editorial',
902  WORKFLOW_STAGE_ID_PRODUCTION => 'submission.production'
903  );
904 
905  return array_intersect_key($stageMapping, array_flip($applicationStages));
906  }
907 
913  function getWorkflowStageKeysAndPaths() {
914  $workflowStages = $this->getWorkflowStageTranslationKeys();
915  $stageMapping = array();
916  foreach ($workflowStages as $stageId => $translationKey) {
917  $stageMapping[$stageId] = array(
918  'id' => $stageId,
919  'translationKey' => $translationKey,
920  'path' => $this->getPathFromId($stageId)
921  );
922  }
923 
924  return $stageMapping;
925  }
926 
927 
939  function getUserGroupsByStage($contextId, $stageId, $omitAuthors = false, $omitReviewers = false, $roleId = null, $dbResultRange = null) {
940  $params = array((int) $contextId, (int) $stageId);
941  if ($omitAuthors) $params[] = ROLE_ID_AUTHOR;
942  if ($omitReviewers) $params[] = ROLE_ID_REVIEWER;
943  if ($roleId) $params[] = $roleId;
944  $result = $this->retrieveRange(
945  'SELECT ug.*
946  FROM user_groups ug
947  JOIN user_group_stage ugs ON (ug.user_group_id = ugs.user_group_id AND ug.context_id = ugs.context_id)
948  WHERE ugs.context_id = ? AND
949  ugs.stage_id = ?' .
950  ($omitAuthors?' AND ug.role_id <> ?':'') .
951  ($omitReviewers?' AND ug.role_id <> ?':'') .
952  ($roleId?' AND ug.role_id = ?':'') .
953  ' ORDER BY role_id ASC',
954  $params,
955  $dbResultRange
956  );
957 
958  return new DAOResultFactory($result, $this, '_returnFromRow');
959  }
960 
966  function getAssignedStagesByUserGroupId($contextId, $userGroupId) {
967  $result = $this->retrieve(
968  'SELECT stage_id
969  FROM user_group_stage
970  WHERE context_id = ? AND
971  user_group_id = ?',
972  array((int) $contextId, (int) $userGroupId)
973  );
974 
975  $returner = array();
976 
977  while (!$result->EOF) {
978  $stageId = $result->Fields('stage_id');
979  $returner[$stageId] = $this->getTranslationKeyFromId($stageId);
980  $result->MoveNext();
981  }
982 
983  return $returner;
984  }
985 
992  function userGroupAssignedToStage($userGroupId, $stageId) {
993  $result = $this->retrieve(
994  'SELECT COUNT(*)
995  FROM user_group_stage
996  WHERE user_group_id = ? AND
997  stage_id = ?',
998  array((int) $userGroupId, (int) $stageId)
999  );
1000 
1001  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
1002 
1003  $result->Close();
1004  return $returner;
1005  }
1006 
1014  function userAssignmentExists($contextId, $userId, $stageId) {
1015  $result = $this->retrieve(
1016  'SELECT COUNT(*)
1017  FROM user_group_stage ugs,
1018  user_user_groups uug
1019  WHERE ugs.user_group_id = uug.user_group_id AND
1020  ugs.context_id = ? AND
1021  uug.user_id = ? AND
1022  ugs.stage_id = ?',
1023  array((int) $contextId, (int) $userId, (int) $stageId)
1024  );
1025 
1026  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
1027 
1028  $result->Close();
1029  return $returner;
1030  }
1031 }
1032 
1033 ?>
getUsersById($userGroupId=null, $contextId=null, $searchType=null, $search=null, $searchMatch=null, $dbResultRange=null)
static & getDAO($name, $dbconn=null)
getSetting($userGroupId, $name, $locale=null)
getIdFromPath($stagePath)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
static getApplicationStages()
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
deleteSettingsByLocale($locale)
static requireComponents()
getByRoleId($contextId, $roleId, $default=false, $dbResultRange=null)
userInGroup($userId, $userGroupId)
isDefault($userGroupId)
assignUserToGroup($userId, $groupId)
deleteByContextId($contextId)
deleteAssignmentsByContextId($contextId, $userId=null)
removeAllStagesFromGroup($contextId, $userGroupId)
getUsersNotInRole($roleId, $contextId=null, $search=null)
getById($userGroupId, $contextId=null)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:457
getPathFromId($stageId)
Describes user roles within the system and the associated permissions.
Definition: Role.inc.php:28
getUserGroupsByStage($contextId, $stageId, $omitAuthors=false, $omitReviewers=false, $roleId=null, $dbResultRange=null)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
getUsersByContextId($contextId, $searchType=null, $search=null, $searchMatch=null, $dbResultRange=null)
getAssignedStagesByUserGroupId($contextId, $userGroupId)
static getLocale()
deleteById($contextId, $userGroupId)
static getWorkflowStageTranslationKeys()
installSettings($contextId, $filename)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
concat()
Definition: DAO.inc.php:53
static call($hookName, $args=null)
deleteObject($userGroup)
Describes user groups.
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
convertFromDB($value, $type)
Definition: DAO.inc.php:335
assignGroupToStage($contextId, $userGroupId, $stageId)
getByUserId($userId, $contextId=null)
installLocale($locale, $contextId=null)
removeGroupFromStage($contextId, $userGroupId, $stageId)
Generic class for parsing an XML document into a data structure.
getDefaultByRoleId($contextId, $roleId)
deleteAssignmentsByUserGroupId($userGroupId)
removeUserFromGroup($userId, $groupId, $contextId)
userGroupAssignedToStage($userGroupId, $stageId)
convertToDB($value, &$type)
Definition: DAO.inc.php:391
userAssignmentExists($contextId, $userId, $stageId)
getByContextId($contextId=null, $dbResultRange=null)
getTranslationKeyFromId($stageId)
getUserGroupIdsByRoleId($roleId, $contextId=null)
Operations for retrieving and modifying User Groups and user group assignments FIXME: Some of the con...
replace($table, $arrFields, $keyCols)
Definition: DAO.inc.php:237
getContextUsersCount($contextId, $userGroupId=null, $roleId=null)
insertObject($userGroup)
userInAnyGroup($userId, $contextId=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
contextHasGroup($contextId, $userGroupId)
updateLocaleFields($userGroup)
_getSearchSql($searchType, $search, $searchMatch, &$params)
deleteAssignmentsByUserId($userId, $userGroupId=null)
updateSetting($userGroupId, $name, $value, $type=null, $isLocalized=false)
updateObject($userGroup)