Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
GroupDAO.inc.php
1 <?php
2 
18 import ('lib.pkp.classes.group.Group');
19 
20 class GroupDAO extends DAO {
24  function GroupDAO() {
25  parent::DAO();
26  }
27 
35  function &getById($groupId, $assocType = null, $assocId = null) {
36  $params = array((int) $groupId);
37  if ($assocType !== null) {
38  $params[] = (int) $assocType;
39  $params[] = (int) $assocId;
40  }
41  $result =& $this->retrieve(
42  'SELECT * FROM groups WHERE group_id = ?' . ($assocType !== null?' AND assoc_type = ? AND assoc_id = ?':''), $params
43  );
44 
45  $returner = null;
46  if ($result->RecordCount() != 0) {
47  $returner =& $this->_returnGroupFromRow($result->GetRowAssoc(false));
48  }
49  $result->Close();
50  unset($result);
51  return $returner;
52  }
53 
54  function getGroup($groupId, $assocType = null, $assocId = null) {
55  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
56  $returner =& $this->getById($groupId, $assocType, $assocId);
57  return $returner;
58  }
59 
68  function &getGroups($assocType, $assocId, $context = null, $rangeInfo = null) {
69  $params = array((int) $assocType, (int) $assocId);
70  if ($context !== null) $params[] = (int) $context;
71 
72  $result =& $this->retrieveRange(
73  'SELECT * FROM groups WHERE assoc_type = ? AND assoc_id = ?' . ($context!==null?' AND context = ?':'') . ' ORDER BY context, seq',
74  $params, $rangeInfo
75  );
76 
77  $returner = new DAOResultFactory($result, $this, '_returnGroupFromRow', array('id'));
78  return $returner;
79  }
80 
85  function getLocaleFieldNames() {
86  return array('title');
87  }
88 
93  function newDataObject() {
94  return new Group();
95  }
96 
102  function &_returnGroupFromRow(&$row) {
103  $group = $this->newDataObject();
104  $group->setId($row['group_id']);
105  $group->setAboutDisplayed($row['about_displayed']);
106  $group->setPublishEmail($row['publish_email']);
107  $group->setSequence($row['seq']);
108  $group->setContext($row['context']);
109  $group->setAssocType($row['assoc_type']);
110  $group->setAssocId($row['assoc_id']);
111  $this->getDataObjectSettings('group_settings', 'group_id', $row['group_id'], $group);
112 
113  HookRegistry::call('GroupDAO::_returnGroupFromRow', array(&$group, &$row));
114 
115  return $group;
116  }
117 
122  function updateLocaleFields(&$group) {
123  $this->updateDataObjectSettings('group_settings', $group, array(
124  'group_id' => $group->getId()
125  ));
126  }
127 
132  function insertGroup(&$group) {
133  $this->update(
134  'INSERT INTO groups
135  (seq, assoc_type, assoc_id, about_displayed, context, publish_email)
136  VALUES
137  (?, ?, ?, ?, ?, ?)',
138  array(
139  (int) $group->getSequence(),
140  (int) $group->getAssocType(),
141  (int) $group->getAssocId(),
142  (int) $group->getAboutDisplayed(),
143  (int) $group->getContext(),
144  (int) $group->getPublishEmail()
145  )
146  );
147 
148  $group->setId($this->getInsertGroupId());
149  $this->updateLocaleFields($group);
150  return $group->getId();
151  }
152 
157  function updateObject(&$group) {
158  $returner = $this->update(
159  'UPDATE groups
160  SET seq = ?,
161  assoc_type = ?,
162  assoc_id = ?,
163  about_displayed = ?,
164  context = ?,
165  publish_email = ?
166  WHERE group_id = ?',
167  array(
168  (float) $group->getSequence(),
169  (int) $group->getAssocType(),
170  (int) $group->getAssocId(),
171  (int) $group->getAboutDisplayed(),
172  (int) $group->getContext(),
173  (int) $group->getPublishEmail(),
174  (int) $group->getId()
175  )
176  );
177  $this->updateLocaleFields($group);
178  return $returner;
179  }
180 
181  function updateGroup(&$group) {
182  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
183  return $this->updateObject($group);
184  }
185 
190  function deleteObject(&$group) {
191  return $this->deleteGroupById($group->getId());
192  }
193 
194  function deleteGroup(&$group) {
195  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
196  return $this->deleteObject($group);
197  }
198 
203  function deleteGroupById($groupId) {
204  $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
205  $groupMembershipDao->deleteMembershipByGroupId($groupId);
206  $this->update('DELETE FROM group_settings WHERE group_id = ?', $groupId);
207  return $this->update('DELETE FROM groups WHERE group_id = ?', $groupId);
208  }
209 
215  function deleteGroupsByAssocId($assocType, $assocId) {
216  $groups =& $this->getGroups($assocType, $assocId);
217  while ($group =& $groups->next()) {
218  $this->deleteObject($group);
219  unset($group);
220  }
221  }
222 
228  function resequenceGroups($assocType = null, $assocId = null) {
229  if ($assocType !== null) $params = array((int) $assocType, (int) $assocId);
230  else $params = array();
231  $result =& $this->retrieve(
232  'SELECT group_id FROM groups' .
233  ($assocType !== null?' WHERE assoc_type = ? AND assoc_id = ?':'') .
234  ' ORDER BY seq',
235  $params
236  );
237 
238  for ($i=1; !$result->EOF; $i++) {
239  list($groupId) = $result->fields;
240  $this->update(
241  'UPDATE groups SET seq = ? WHERE group_id = ?',
242  array(
243  $i,
244  $groupId
245  )
246  );
247 
248  $result->MoveNext();
249  }
250 
251  $result->Close();
252  unset($result);
253  }
254 
259  function getInsertGroupId() {
260  return $this->getInsertId('groups', 'group_id');
261  }
262 }
263 
264 ?>
updateLocaleFields(&$group)
deleteObject(&$group)
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
Operations for retrieving and modifying Group objects.
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:460
getLocaleFieldNames()
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
getInsertGroupId()
& _returnGroupFromRow(&$row)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
& getById($groupId, $assocType=null, $assocId=null)
& getDAO($name, $dbconn=null)
resequenceGroups($assocType=null, $assocId=null)
& getGroups($assocType, $assocId, $context=null, $rangeInfo=null)
insertGroup(&$group)
deleteGroupsByAssocId($assocType, $assocId)
call($hookName, $args=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
updateObject(&$group)
Describes user groups.
Definition: Group.inc.php:25
deleteGroupById($groupId)