Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
GroupMembershipDAO.inc.php
1 <?php
2 
18 import ('lib.pkp.classes.group.GroupMembership');
19 
20 class GroupMembershipDAO extends DAO {
21  var $userDao;
22 
26  function GroupMembershipDAO() {
27  parent::DAO();
28  $this->userDao =& DAORegistry::getDAO('UserDAO');
29  }
30 
37  function &getMembership($groupId, $userId) {
38  $result =& $this->retrieve(
39  'SELECT * FROM group_memberships WHERE group_id = ? AND user_id = ?',
40  array($groupId, $userId)
41  );
42 
43  $returner = null;
44  if ($result->RecordCount() != 0) {
45  $returner =& $this->_returnMembershipFromRow($result->GetRowAssoc(false));
46  }
47  $result->Close();
48  unset($result);
49  return $returner;
50  }
51 
57  function &getMemberships($groupId, $rangeInfo = null) {
58  $result =& $this->retrieveRange(
59  'SELECT * FROM group_memberships m, users u WHERE group_id = ? AND u.user_id = m.user_id ORDER BY m.seq',
60  $groupId,
61  $rangeInfo
62  );
63 
64  $returner = new DAOResultFactory($result, $this, '_returnMembershipFromRow');
65  return $returner;
66  }
67 
72  function newDataObject() {
73  return new GroupMembership();
74  }
75 
81  function &_returnMembershipFromRow(&$row) {
82  // Keep a cache of users.
83  static $users;
84  if (!isset($users)) {
85  $users = array();
86  }
87  $userId = $row['user_id'];
88  if (!isset($users[$userId])) {
89  $users[$userId] =& $this->userDao->getById($userId);
90  }
91 
92  $membership = $this->newDataObject();
93  $membership->setGroupId($row['group_id']);
94  $membership->setUserId($row['user_id']);
95  $membership->setUser($users[$userId]);
96  $membership->setSequence($row['seq']);
97  $membership->setAboutDisplayed($row['about_displayed']);
98 
99  HookRegistry::call('GroupMembershipDAO::_returnMemberFromRow', array(&$membership, &$row));
100 
101  return $membership;
102  }
103 
108  function insertMembership(&$membership) {
109  $this->update(
110  'INSERT INTO group_memberships
111  (group_id, user_id, seq, about_displayed)
112  VALUES
113  (?, ?, ?, ?)',
114  array(
115  $membership->getGroupId(),
116  $membership->getUserId(),
117  $membership->getSequence() == null ? 0 : $membership->getSequence(),
118  $membership->getAboutDisplayed()
119  )
120  );
121  }
122 
127  function updateObject(&$membership) {
128  return $this->update(
129  'UPDATE group_memberships
130  SET
131  seq = ?,
132  about_displayed = ?
133  WHERE
134  group_id = ? AND
135  user_id = ?',
136  array(
137  $membership->getSequence(),
138  $membership->getAboutDisplayed(),
139  $membership->getGroupId(),
140  $membership->getUserId()
141  )
142  );
143  }
144 
145  function updateMembership(&$membership) {
146  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
147  return $this->updateObject($membership);
148  }
149 
154  function deleteObject(&$membership) {
155  return $this->deleteMembershipById($membership->getGroupId(), $membership->getUserId());
156  }
157 
158  function deleteMembership(&$membership) {
159  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
160  return $this->deleteObject($membership);
161  }
162 
168  function deleteMembershipById($groupId, $userId) {
169  return $this->update(
170  'DELETE FROM group_memberships WHERE group_id = ? AND user_id = ?',
171  array($groupId, $userId)
172  );
173  }
174 
179  function deleteMembershipByGroupId($groupId) {
180  return $this->update(
181  'DELETE FROM group_memberships WHERE group_id = ?',
182  $groupId
183  );
184  }
185 
190  function deleteMembershipByUserId($userId) {
191  return $this->update(
192  'DELETE FROM group_memberships WHERE user_id = ?',
193  $userId
194  );
195  }
196 
201  function resequenceMemberships($groupId) {
202  $result =& $this->retrieve(
203  'SELECT user_id, group_id FROM group_memberships WHERE group_id = ? ORDER BY seq',
204  $groupId
205  );
206 
207  for ($i=1; !$result->EOF; $i++) {
208  list($userId, $groupId) = $result->fields;
209  $this->update(
210  'UPDATE group_memberships SET seq = ? WHERE user_id = ? AND group_id = ?',
211  array(
212  $i,
213  $userId,
214  $groupId
215  )
216  );
217 
218  $result->MoveNext();
219  }
220 
221  $result->Close();
222  unset($result);
223  }
224 }
225 
226 ?>
& getMembership($groupId, $userId)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
& getDAO($name, $dbconn=null)
call($hookName, $args=null)
deleteMembershipById($groupId, $userId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
Describes memberships for editorial board positions.
Operations for retrieving and modifying group membership info.
& getMemberships($groupId, $rangeInfo=null)