Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
UserGroupAssignmentDAO.inc.php
1 <?php
2 
20 import('lib.pkp.classes.security.UserGroupAssignment');
21 
22 class UserGroupAssignmentDAO extends DAO {
27  parent::DAO();
28  }
29 
34  function newDataObject() {
35  return new UserGroupAssignment();
36  }
37 
43  function _fromRow($row) {
44  $userGroupAssignment = $this->newDataObject();
45  $userGroupAssignment->setUserGroupId($row['user_group_id']);
46  $userGroupAssignment->setUserId($row['user_id']);
47 
48  return $userGroupAssignment;
49  }
50 
56  function deleteByUserId($userId, $userGroupId = null) {
57  $params = array((int) $userId);
58  if ($userGroupId) $params[] = (int) $userGroupId;
59 
60  $this->update(
61  'DELETE FROM user_user_groups
62  WHERE user_id = ?
63  ' . ($userGroupId?' AND user_group_id = ?':''),
64  $params
65  );
66  }
67 
72  function deleteAssignmentsByUserGroupId($userGroupId) {
73  return $this->update('DELETE FROM user_user_groups
74  WHERE user_group_id = ?',
75  (int) $userGroupId);
76  }
77 
83  function deleteAssignmentsByContextId($contextId, $userId = null) {
84  $params = array((int) $contextId);
85  if ($userId) $params[] = (int) $userId;
86  $result = $this->retrieve(
87  'SELECT uug.user_group_id, uug.user_id
88  FROM user_groups ug
89  JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id
90  WHERE ug.context_id = ?
91  ' . ($userId?' AND uug.user_id = ?':''),
92  $params
93  );
94 
95  $assignments = new DAOResultFactory($result, $this, '_fromRow');
96  while ($assignment = $assignments->next()) {
97  $this->deleteByUserId($assignment->getUserId(), $assignment->getUserGroupId());
98  }
99  }
100 
101 
109  function getByUserId($userId, $contextId = null, $roleId = null) {
110  $params = array((int) $userId);
111  if ($contextId) $params[] = (int) $contextId;
112  if ($roleId) $params[] = (int) $roleId;
113 
114  $result = $this->retrieve(
115  'SELECT uug.user_group_id, uug.user_id
116  FROM user_groups ug
117  JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id
118  WHERE uug.user_id = ?' .
119  ($contextId?' AND ug.context_id = ?':'') .
120  ($roleId?' AND ug.role_id = ?':''),
121  $params
122  );
123  return new DAOResultFactory($result, $this, '_fromRow');
124  }
125 
126 
132  function insertObject($userGroupAssignment) {
133  $this->update(
134  'INSERT INTO user_user_groups (user_id, user_group_id) VALUES(?, ?)',
135  array((int) $userGroupAssignment->getUserId(), (int) $userGroupAssignment->getUserGroupId())
136  );
137  }
138 
143  function deleteAssignment(&$userGroupAssignment) {
144  $this->update(
145  'DELETE FROM user_user_groups WHERE user_id = ? AND user_group_id = ?',
146  array((int) $userGroupAssignment->getUserId(), (int) $userGroupAssignment->getUserGroupId())
147  );
148  }
149 }
150 
151 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
deleteAssignment(&$userGroupAssignment)
Operations for retrieving and modifying user group assignments FIXME: Some of the context-specific fe...
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getByUserId($userId, $contextId=null, $roleId=null)
insertObject($userGroupAssignment)
deleteAssignmentsByContextId($contextId, $userId=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
deleteByUserId($userId, $userGroupId=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208