Open Monograph Press  1.1
 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 
231  function getByRoleId($contextId, $roleId, $default = false) {
232  $params = array((int) $contextId, (int) $roleId);
233  if ($default) $params[] = 1; // true
234  $result = $this->retrieve(
235  'SELECT *
236  FROM user_groups
237  WHERE context_id = ? AND
238  role_id = ?' . ($default?' AND is_default = ?':''),
239  $params
240  );
241 
242  return new DAOResultFactory($result, $this, '_returnFromRow');
243  }
244 
250  function getUserGroupIdsByRoleId($roleId, $contextId = null) {
251  $sql = 'SELECT user_group_id FROM user_groups WHERE role_id = ?';
252  $params = array((int) $roleId);
253 
254  if ($contextId) {
255  $sql .= ' AND context_id = ?';
256  $params[] = (int) $contextId;
257  }
258 
259  $result = $this->retrieve($sql, $params);
260 
261  $userGroupIds = array();
262  while (!$result->EOF) {
263  $userGroupIds[] = (int) $result->fields[0];
264  $result->MoveNext();
265  }
266 
267  $result->Close();
268  return $userGroupIds;
269  }
270 
278  function userInGroup($userId, $userGroupId) {
279  $result = $this->retrieve(
280  'SELECT count(*)
281  FROM user_groups ug
282  JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id
283  WHERE
284  uug.user_id = ? AND
285  ug.user_group_id = ?',
286  array((int) $userId, (int) $userGroupId)
287  );
288 
289  // > 0 because user could belong to more than one user group with this role
290  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
291 
292  $result->Close();
293  return $returner;
294  }
295 
302  function userInAnyGroup($userId, $contextId = null) {
303  $params = array((int) $userId);
304  if ($contextId) $params[] = (int) $contextId;
305 
306  $result = $this->retrieve(
307  'SELECT count(*)
308  FROM user_groups ug
309  JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id
310  WHERE uug.user_id = ?' . ($contextId?' AND ug.context_id = ?':''),
311  $params
312  );
313 
314  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
315 
316  $result->Close();
317  return $returner;
318  }
319 
326  function getByUserId($userId, $contextId = null){
327  $params = array((int) $userId);
328  if ($contextId) {
329  $params[] = (int) $contextId;
330  }
331  $result = $this->retrieve(
332  'SELECT ug.*
333  FROM user_groups ug
334  JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id
335  WHERE uug.user_id = ?' . ($contextId?' AND ug.context_id = ?':''),
336  $params
337  );
338 
339  return new DAOResultFactory($result, $this, '_returnFromRow');
340  }
341 
348  function contextHasGroup($contextId, $userGroupId) {
349  $result = $this->retrieve(
350  'SELECT count(*)
351  FROM user_groups ug
352  WHERE ug.user_group_id = ?
353  AND ug.context_id = ?',
354  array (
355  (int) $userGroupId,
356  (int) $contextId
357  )
358  );
359 
360  $returner = isset($result->fields[0]) && $result->fields[0] == 0 ? false : true;
361 
362  $result->Close();
363  return $returner;
364  }
365 
370  function getByContextId($contextId = null) {
371  $params = array();
372  if ($contextId) $params[] = (int) $contextId;
373  $result = $this->retrieve(
374  'SELECT ug.*
375  FROM user_groups ug' .
376  ($contextId?' WHERE ug.context_id = ?':''),
377  $params);
378 
379  return new DAOResultFactory($result, $this, '_returnFromRow');
380  }
381 
387  function getContextUsersCount($contextId, $userGroupId = null, $roleId = null) {
388  $params = array((int) $contextId);
389  if ($userGroupId) $params[] = (int) $userGroupId;
390  if ($roleId) $params[] = (int) $roleId;
391  $result = $this->retrieve(
392  'SELECT COUNT(DISTINCT(uug.user_id))
393  FROM user_groups ug
394  JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id
395  WHERE context_id = ?' . ($userGroupId?' AND ug.user_group_id = ?':'') . ($roleId?' AND ug.role_id = ?':''),
396  $params
397  );
398 
399  $returner = $result->fields[0];
400 
401  $result->Close();
402  return $returner;
403  }
404 
413  function getUsersByContextId($contextId, $searchType = null, $search = null, $searchMatch = null, $dbResultRange = null) {
414  return $this->getUsersById(null, $contextId, $searchType, $search, $searchMatch, $dbResultRange);
415  }
416 
423  function getUsersNotInRole($roleId, $contextId = null, $search = null) {
424  $params = array((int) $roleId);
425  if ($contextId) $params[] = (int) $contextId;
426  if(isset($search)) $params = array_merge($params, array_pad(array(), 5, '%' . $search . '%'));
427 
428  $result = $this->retrieve(
429  'SELECT DISTINCT u.*
430  FROM users u, user_groups ug, user_user_groups uug
431  WHERE ug.user_group_id = uug.user_group_id AND
432  u.user_id = uug.user_id AND
433  ug.role_id <> ?' .
434  ($contextId?' AND ug.context_id = ?':'') .
435  (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 ?)':''),
436  $params
437  );
438 
439  return new DAOResultFactory($result, $this->userDao, '_returnUserFromRowWithData');
440  }
441 
451  function getUsersById($userGroupId = null, $contextId = null, $searchType = null, $search = null, $searchMatch = null, $dbResultRange = null) {
452  $params = array();
453 
454  if ($contextId) $params[] = (int) $contextId;
455  if ($userGroupId) $params[] = (int) $userGroupId;
456 
457  $result = $this->retrieveRange(
458  'SELECT DISTINCT u.*
459  FROM users AS u
460  LEFT JOIN user_settings us ON (us.user_id = u.user_id AND us.setting_name = \'affiliation\')
461  LEFT JOIN user_interests ui ON (u.user_id = ui.user_id)
462  LEFT JOIN controlled_vocab_entry_settings cves ON (ui.controlled_vocab_entry_id = cves.controlled_vocab_entry_id)
463  LEFT JOIN user_user_groups uug ON (uug.user_id = u.user_id)
464  LEFT JOIN user_groups ug ON (ug.user_group_id = uug.user_group_id)
465  WHERE 1=1' .
466  ($contextId?' AND ug.context_id = ?':'') .
467  ($userGroupId?' AND ug.user_group_id = ?':'') .
468  $this->_getSearchSql($searchType, $search, $searchMatch, $params),
469  $params,
470  $dbResultRange
471  );
472 
473  return new DAOResultFactory($result, $this->userDao, '_returnUserFromRowWithData');
474  }
475 
476  //
477  // UserGroupAssignment related
478  //
483  function deleteAssignmentsByUserId($userId, $userGroupId = null) {
484  $this->userGroupAssignmentDao->deleteByUserId($userId, $userGroupId);
485  }
486 
491  function deleteAssignmentsByUserGroupId($userGroupId) {
492  $this->userGroupAssignmentDao->deleteAssignmentsByUserGroupId($userGroupId);
493  }
494 
500  function deleteAssignmentsByContextId($contextId, $userId = null) {
501  $this->userGroupAssignmentDao->deleteAssignmentsByContextId($contextId, $userId);
502  }
503 
509  function assignUserToGroup($userId, $groupId) {
510  $assignment = $this->userGroupAssignmentDao->newDataObject();
511  $assignment->setUserId($userId);
512  $assignment->setUserGroupId($groupId);
513  return $this->userGroupAssignmentDao->insertObject($assignment);
514  }
522  function removeUserFromGroup($userId, $groupId, $contextId) {
523  $assignments = $this->userGroupAssignmentDao->getByUserId($userId, $contextId);
524  while ($assignment = $assignments->next()) {
525  if ($assignment->getUserGroupId() == $groupId) {
526  $this->userGroupAssignmentDao->deleteAssignment($assignment);
527  }
528  }
529  }
530 
536  function removeAllStagesFromGroup($contextId, $userGroupId) {
537  $assignedStages = $this->getAssignedStagesByUserGroupId($contextId, $userGroupId);
538  foreach($assignedStages as $stageId => $stageLocaleKey) {
539  $this->removeGroupFromStage($contextId, $userGroupId, $stageId);
540  }
541  }
550  function assignGroupToStage($contextId, $userGroupId, $stageId) {
551  return $this->update(
552  'INSERT INTO user_group_stage (context_id, user_group_id, stage_id) VALUES (?, ?, ?)',
553  array((int) $contextId, (int) $userGroupId, (int) $stageId)
554  );
555  }
564  function removeGroupFromStage($contextId, $userGroupId, $stageId) {
565  return $this->update(
566  'DELETE FROM user_group_stage WHERE context_id = ? AND user_group_id = ? AND stage_id = ?',
567  array((int) $contextId, (int) $userGroupId, (int) $stageId)
568  );
569  }
571  //
572  // Extra settings (not handled by rest of Dao)
573  //
582  function updateSetting($userGroupId, $name, $value, $type = null, $isLocalized = false) {
583  $keyFields = array('setting_name', 'locale', 'user_group_id');
584 
585  if (!$isLocalized) {
586  $value = $this->convertToDB($value, $type);
587  $this->replace('user_group_settings',
588  array(
589  'user_group_id' => (int) $userGroupId,
590  'setting_name' => $name,
591  'setting_value' => $value,
592  'setting_type' => $type,
593  'locale' => ''
594  ),
595  $keyFields
596  );
597  } else {
598  if (is_array($value)) foreach ($value as $locale => $localeValue) {
599  $this->update('DELETE FROM user_group_settings WHERE user_group_id = ? AND setting_name = ? AND locale = ?', array((int) $userGroupId, $name, $locale));
600  if (empty($localeValue)) continue;
601  $type = null;
602  $this->update('INSERT INTO user_group_settings
603  (user_group_id, setting_name, setting_value, setting_type, locale)
604  VALUES (?, ?, ?, ?, ?)',
605  array(
606  $userGroupId, $name, $this->convertToDB($localeValue, $type), $type, $locale
607  )
608  );
609  }
610  }
611  }
612 
613 
621  function getSetting($userGroupId, $name, $locale = null) {
622  $params = array((int) $userGroupId, $name);
623  if ($locale) $params[] = $locale;
624  $result = $this->retrieve(
625  'SELECT setting_name, setting_value, setting_type, locale
626  FROM user_group_settings
627  WHERE user_group_id = ? AND
628  setting_name = ?' .
629  ($locale?' AND locale = ?':''),
630  $params
631  );
632 
633  $recordCount = $result->RecordCount();
634  $returner = false;
635  if ($recordCount == 1) {
636  $row = $result->getRowAssoc(false);
637  $returner = $this->convertFromDB($row['setting_value'], $row['setting_type']);
638  } elseif ($recordCount > 1) {
639  $returner = array();
640  while (!$result->EOF) {
641  $returner[$row['locale']] = $this->convertFromDB($row['setting_value'], $row['setting_type']);
642  $result->MoveNext();
643  }
644  $result->Close();
645  }
646  return $returner;
647  }
648 
649  //
650  // Install/Defaults with settings
651  //
652 
658  function installSettings($contextId, $filename) {
659  $xmlParser = new XMLParser();
660  $tree = $xmlParser->parse($filename);
661 
662  if (!$tree) {
663  $xmlParser->destroy();
664  return false;
665  }
666 
667  foreach ($tree->getChildren() as $setting) {
668  $roleId = hexdec($setting->getAttribute('roleId'));
669  $nameKey = $setting->getAttribute('name');
670  $abbrevKey = $setting->getAttribute('abbrev');
671  $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration');
672  $defaultStages = explode(',', $setting->getAttribute('stages'));
673  $userGroup = $this->newDataObject();
674 
675  // create a role associated with this user group
676  $role = new Role($roleId);
677  $userGroup = $this->newDataObject();
678  $userGroup->setRoleId($roleId);
679  $userGroup->setPath($role->getPath());
680  $userGroup->setContextId($contextId);
681  $userGroup->setPermitSelfRegistration($permitSelfRegistration);
682  $userGroup->setDefault(true);
683 
684  // insert the group into the DB
685  $userGroupId = $this->insertObject($userGroup);
686 
687  // Install default groups for each stage
688  if (is_array($defaultStages)) { // test for groups with no stage assignments
689  foreach ($defaultStages as $stageId) {
690  if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) {
691  $this->assignGroupToStage($contextId, $userGroupId, $stageId);
692  }
693  }
694  }
695 
696  // add the i18n keys to the settings table so that they
697  // can be used when a new locale is added/reloaded
698  $this->updateSetting($userGroup->getId(), 'nameLocaleKey', $nameKey);
699  $this->updateSetting($userGroup->getId(), 'abbrevLocaleKey', $abbrevKey);
700 
701  // install the settings in the current locale for this context
702  $this->installLocale(AppLocale::getLocale(), $contextId);
703  }
704  }
705 
711  function installLocale($locale, $contextId = null) {
712  $userGroups = $this->getByContextId($contextId);
713  while ($userGroup = $userGroups->next()) {
714  $nameKey = $this->getSetting($userGroup->getId(), 'nameLocaleKey');
715  $this->updateSetting($userGroup->getId(),
716  'name',
717  array($locale => __($nameKey, null, $locale)),
718  'string',
719  $locale,
720  true
721  );
722 
723  $abbrevKey = $this->getSetting($userGroup->getId(), 'abbrevLocaleKey');
724  $this->updateSetting($userGroup->getId(),
725  'abbrev',
726  array($locale => __($abbrevKey, null, $locale)),
727  'string',
728  $locale,
729  true
730  );
731  }
732  }
733 
738  function deleteSettingsByLocale($locale) {
739  return $this->update('DELETE FROM user_group_settings WHERE locale = ?', $locale);
740  }
741 
749  function _getSearchSql($searchType, $search, $searchMatch, &$params) {
750  $searchTypeMap = array(
751  USER_FIELD_FIRSTNAME => 'u.first_name',
752  USER_FIELD_LASTNAME => 'u.last_name',
753  USER_FIELD_USERNAME => 'u.username',
754  USER_FIELD_EMAIL => 'u.email',
755  USER_FIELD_AFFILIATION => 'us.setting_value',
756  );
757 
758  $searchSql = '';
759 
760  if (!empty($search)) {
761 
762  if (!isset($searchTypeMap[$searchType])) {
763  $str = $this->concat('u.first_name', 'u.last_name', 'u.email', 'us.setting_value');
764  $concatFields = ' ( LOWER(' . $str . ') LIKE ? OR LOWER(cves.setting_value) LIKE ? ) ';
765 
766  $search = strtolower($search);
767 
768  $words = preg_split('{\s+}', $search);
769  $searchFieldMap = array();
770 
771  foreach ($words as $word) {
772  $searchFieldMap[] = $concatFields;
773  $term = '%' . $word . '%';
774  array_push($params, $term, $term);
775  }
776 
777  $searchSql .= ' AND ( ' . join(' AND ', $searchFieldMap) . ' ) ';
778  } else {
779  $fieldName = $searchTypeMap[$searchType];
780  switch ($searchMatch) {
781  case 'is':
782  $searchSql = "AND LOWER($fieldName) = LOWER(?)";
783  $params[] = $search;
784  break;
785  case 'contains':
786  $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
787  $params[] = '%' . $search . '%';
788  break;
789  case 'startsWith':
790  $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
791  $params[] = $search . '%';
792  break;
793  }
794  }
795  } else {
796  switch ($searchType) {
797  case USER_FIELD_USERID:
798  $searchSql = 'AND u.user_id = ?';
799  break;
800  case USER_FIELD_INITIAL:
801  $searchSql = 'AND LOWER(u.last_name) LIKE LOWER(?)';
802  break;
803  }
804  }
805 
806  $searchSql .= ' ORDER BY u.last_name, u.first_name'; // FIXME Add "sort field" parameter?
807 
808  return $searchSql;
809  }
810 
811  //
812  // Public helper methods
813  //
814 
820  function getPathFromId($stageId) {
821  static $stageMapping = array(
822  WORKFLOW_STAGE_ID_SUBMISSION => WORKFLOW_STAGE_PATH_SUBMISSION,
823  WORKFLOW_STAGE_ID_INTERNAL_REVIEW => WORKFLOW_STAGE_PATH_INTERNAL_REVIEW,
824  WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW,
825  WORKFLOW_STAGE_ID_EDITING => WORKFLOW_STAGE_PATH_EDITING,
826  WORKFLOW_STAGE_ID_PRODUCTION => WORKFLOW_STAGE_PATH_PRODUCTION
827  );
828  if (isset($stageMapping[$stageId])) {
829  return $stageMapping[$stageId];
830  }
831  return null;
832  }
833 
839  function getIdFromPath($stagePath) {
840  static $stageMapping = array(
841  WORKFLOW_STAGE_PATH_SUBMISSION => WORKFLOW_STAGE_ID_SUBMISSION,
842  WORKFLOW_STAGE_PATH_INTERNAL_REVIEW => WORKFLOW_STAGE_ID_INTERNAL_REVIEW,
843  WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW => WORKFLOW_STAGE_ID_EXTERNAL_REVIEW,
844  WORKFLOW_STAGE_PATH_EDITING => WORKFLOW_STAGE_ID_EDITING,
845  WORKFLOW_STAGE_PATH_PRODUCTION => WORKFLOW_STAGE_ID_PRODUCTION
846  );
847  if (isset($stageMapping[$stagePath])) {
848  return $stageMapping[$stagePath];
849  }
850  return null;
851  }
852 
858  function getTranslationKeyFromId($stageId) {
859  $stageMapping = $this->getWorkflowStageTranslationKeys();
860 
861  assert(isset($stageMapping[$stageId]));
862  return $stageMapping[$stageId];
863  }
869  static function getWorkflowStageTranslationKeys() {
870  $applicationStages = Application::getApplicationStages();
871  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION);
872  static $stageMapping = array(
873  WORKFLOW_STAGE_ID_SUBMISSION => 'submission.submission',
874  WORKFLOW_STAGE_ID_INTERNAL_REVIEW => 'workflow.review.internalReview',
875  WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => 'workflow.review.externalReview',
876  WORKFLOW_STAGE_ID_EDITING => 'submission.editorial',
877  WORKFLOW_STAGE_ID_PRODUCTION => 'submission.production'
878  );
879 
880  return array_intersect_key($stageMapping, array_flip($applicationStages));
881  }
882 
888  function getWorkflowStageKeysAndPaths() {
889  $workflowStages = $this->getWorkflowStageTranslationKeys();
890  $stageMapping = array();
891  foreach ($workflowStages as $stageId => $translationKey) {
892  $stageMapping[$stageId] = array(
893  'id' => $stageId,
894  'translationKey' => $translationKey,
895  'path' => $this->getPathFromId($stageId)
896  );
897  }
898 
899  return $stageMapping;
900  }
901 
902 
910  function getUserGroupsByStage($contextId, $stageId, $omitAuthors = false, $omitReviewers = false, $roleId = null) {
911  $params = array((int) $contextId, (int) $stageId);
912  if ($omitAuthors) $params[] = ROLE_ID_AUTHOR;
913  if ($omitReviewers) $params[] = ROLE_ID_REVIEWER;
914  if ($roleId) $params[] = $roleId;
915  $result = $this->retrieve(
916  'SELECT ug.*
917  FROM user_groups ug
918  JOIN user_group_stage ugs ON (ug.user_group_id = ugs.user_group_id AND ug.context_id = ugs.context_id)
919  WHERE ugs.context_id = ? AND
920  ugs.stage_id = ?' .
921  ($omitAuthors?' AND ug.role_id <> ?':'') .
922  ($omitReviewers?' AND ug.role_id <> ?':'') .
923  ($roleId?' AND ug.role_id = ?':'') .
924  ' ORDER BY role_id ASC',
925  $params
926  );
927 
928  return new DAOResultFactory($result, $this, '_returnFromRow');
929  }
930 
936  function getAssignedStagesByUserGroupId($contextId, $userGroupId) {
937  $result = $this->retrieve(
938  'SELECT stage_id
939  FROM user_group_stage
940  WHERE context_id = ? AND
941  user_group_id = ?',
942  array((int) $contextId, (int) $userGroupId)
943  );
944 
945  $returner = array();
946 
947  while (!$result->EOF) {
948  $stageId = $result->Fields('stage_id');
949  $returner[$stageId] = $this->getTranslationKeyFromId($stageId);
950  $result->MoveNext();
951  }
952 
953  return $returner;
954  }
955 
962  function userGroupAssignedToStage($userGroupId, $stageId) {
963  $result = $this->retrieve(
964  'SELECT COUNT(*)
965  FROM user_group_stage
966  WHERE user_group_id = ? AND
967  stage_id = ?',
968  array((int) $userGroupId, (int) $stageId)
969  );
970 
971  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
972 
973  $result->Close();
974  return $returner;
975  }
976 
984  function userAssignmentExists($contextId, $userId, $stageId) {
985  $result = $this->retrieve(
986  'SELECT COUNT(*)
987  FROM user_group_stage ugs,
988  user_user_groups uug
989  WHERE ugs.user_group_id = uug.user_group_id AND
990  ugs.context_id = ? AND
991  uug.user_id = ? AND
992  ugs.stage_id = ?',
993  array((int) $contextId, (int) $userId, (int) $stageId)
994  );
995 
996  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
997 
998  $result->Close();
999  return $returner;
1000  }
1001 }
1002 
1003 ?>
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()
userInGroup($userId, $userGroupId)
getByRoleId($contextId, $roleId, $default=false)
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:26
& 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)
getUserGroupsByStage($contextId, $stageId, $omitAuthors=false, $omitReviewers=false, $roleId=null)
deleteAssignmentsByUserGroupId($userGroupId)
removeUserFromGroup($userId, $groupId, $contextId)
userGroupAssignedToStage($userGroupId, $stageId)
convertToDB($value, &$type)
Definition: DAO.inc.php:391
userAssignmentExists($contextId, $userId, $stageId)
getByContextId($contextId=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)