ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

RoleDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 import('security.Role');
19 
20 class RoleDAO extends DAO {
24  function RoleDAO() {
25  parent::DAO();
26  $this->userDao =& DAORegistry::getDAO('UserDAO');
27  }
28 
36  function &getRole($conferenceId, $schedConfId, $userId, $roleId) {
37  $result =& $this->retrieve(
38  'SELECT * FROM roles WHERE conference_id = ? AND sched_conf_id = ? AND user_id = ? AND role_id = ?',
39  array(
40  (int) $conferenceId,
41  (int) $schedConfId,
42  (int) $userId,
43  (int) $roleId
44  )
45  );
46 
47  $returner = null;
48  if ($result->RecordCount() != 0) {
49  $returner =& $this->_returnRoleFromRow($result->GetRowAssoc(false));
50  }
51 
52  $result->Close();
53  unset($result);
54 
55  return $returner;
56  }
57 
63  function &_returnRoleFromRow(&$row) {
64  $role = new Role();
65  $role->setConferenceId($row['conference_id']);
66  $role->setSchedConfId($row['sched_conf_id']);
67  $role->setUserId($row['user_id']);
68  $role->setRoleId($row['role_id']);
69 
70  HookRegistry::call('RoleDAO::_returnRoleFromRow', array(&$role, &$row));
71 
72  return $role;
73  }
74 
79  function insertRole(&$role) {
80  return $this->update(
81  'INSERT INTO roles
82  (conference_id, sched_conf_id, user_id, role_id)
83  VALUES
84  (?, ?, ?, ?)',
85  array(
86  (int) $role->getConferenceId(),
87  (int) $role->getSchedConfId(),
88  (int) $role->getUserId(),
89  (int) $role->getRoleId()
90  )
91  );
92  }
93 
98  function deleteRole(&$role) {
99  return $this->update(
100  'DELETE FROM roles WHERE conference_id = ? AND sched_conf_id = ? AND user_id = ? AND role_id = ?',
101  array(
102  (int) $role->getConferenceId(),
103  (int) $role->getSchedConfId(),
104  (int) $role->getUserId(),
105  (int) $role->getRoleId()
106  )
107  );
108  }
109 
117  function &getRolesByUserId($userId, $conferenceId = null, $schedConfId = null) {
118  $roles = array();
119  $params = array();
120 
121  $params[] = $userId;
122  if(isset($conferenceId)) $params[] = $conferenceId;
123  if(isset($schedConfId)) $params[] = $schedConfId;
124 
125  $result =& $this->retrieve('SELECT * FROM roles WHERE user_id = ?' .
126  (isset($conferenceId) ? ' AND conference_id = ?' : '') .
127  (isset($schedConfId) ? ' AND sched_conf_id = ?' : ''),
128  (count($params) == 1 ? array_shift($params) : $params));
129 
130  while (!$result->EOF) {
131  $roles[] =& $this->_returnRoleFromRow($result->GetRowAssoc(false));
132  $result->moveNext();
133  }
134 
135  $result->Close();
136  unset($result);
137 
138  return $roles;
139  }
140 
152  function &getUsersByRoleId($roleId = null, $conferenceId = null, $schedConfId = null,
153  $searchType = null, $search = null, $searchMatch = null, $dbResultRange = null,
154  $sortBy = null, $sortDirection = SORT_DIRECTION_ASC ) {
155 
156  $users = array();
157 
158  $paramArray = array('interests');
159  if (isset($roleId)) $paramArray[] = (int) $roleId;
160  if (isset($conferenceId)) $paramArray[] = (int) $conferenceId;
161  if (isset($schedConfId)) $paramArray[] = (int) $schedConfId;
162 
163  // For security / resource usage reasons, a role, scheduled conference, or conference
164  // must be specified. Don't allow calls supplying none.
165  if ($conferenceId === null && $schedConfId === null && $roleId === null) return null;
166 
167  $searchSql = '';
168 
169  $searchTypeMap = array(
170  USER_FIELD_FIRSTNAME => 'u.first_name',
171  USER_FIELD_LASTNAME => 'u.last_name',
172  USER_FIELD_USERNAME => 'u.username',
173  USER_FIELD_EMAIL => 'u.email',
174  USER_FIELD_INTERESTS => 's.setting_value'
175  );
176 
177  if (!empty($search) && isset($searchTypeMap[$searchType])) {
178  $fieldName = $searchTypeMap[$searchType];
179  switch ($searchMatch) {
180  case 'is':
181  $searchSql = "AND LOWER($fieldName) = LOWER(?)";
182  $paramArray[] = $search;
183  break;
184  case 'contains':
185  $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
186  $paramArray[] = '%' . $search . '%';
187  break;
188  case 'startsWith':
189  $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
190  $paramArray[] = $search . '%';
191  break;
192  }
193  } elseif (!empty($search)) switch ($searchType) {
194  case USER_FIELD_USERID:
195  $searchSql = 'AND u.user_id=?';
196  $paramArray[] = $search;
197  break;
198  case USER_FIELD_INITIAL:
199  $searchSql = 'AND LOWER(u.last_name) LIKE LOWER(?)';
200  $paramArray[] = $search . '%';
201  break;
202  }
203 
204  $searchSql .= ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : '');
205 
206  $result =& $this->retrieveRange(
207  'SELECT DISTINCT u.* FROM users AS u LEFT JOIN user_settings s ON (u.user_id = s.user_id AND s.setting_name = ?), roles AS r WHERE u.user_id = r.user_id ' .
208  (isset($roleId)?'AND r.role_id = ?':'') .
209  (isset($conferenceId) ? ' AND r.conference_id = ?' : '') .
210  (isset($schedConfId) ? ' AND r.sched_conf_id = ?' : '') .
211  ' ' . $searchSql,
212  $paramArray,
213  $dbResultRange
214  );
215 
216  $returner = new DAOResultFactory($result, $this->userDao, '_returnUserFromRowWithData');
217  return $returner;
218  }
219 
229  function &getUsersByConferenceId($conferenceId, $searchType = null, $search = null, $searchMatch = null, $dbResultRange = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
230  $users = array();
231 
232  $paramArray = array('interests', (int) $conferenceId);
233  $searchSql = '';
234 
235  $searchTypeMap = array(
236  USER_FIELD_FIRSTNAME => 'u.first_name',
237  USER_FIELD_LASTNAME => 'u.last_name',
238  USER_FIELD_USERNAME => 'u.username',
239  USER_FIELD_EMAIL => 'u.email',
240  USER_FIELD_INTERESTS => 's.setting_value'
241  );
242 
243  if (!empty($search) && isset($searchTypeMap[$searchType])) {
244  $fieldName = $searchTypeMap[$searchType];
245  switch ($searchMatch) {
246  case 'is':
247  $searchSql = "AND LOWER($fieldName) = LOWER(?)";
248  $paramArray[] = $search;
249  break;
250  case 'contains':
251  $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
252  $paramArray[] = '%' . $search . '%';
253  break;
254  case 'startsWith':
255  $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
256  $paramArray[] = $search . '%';
257  break;
258  }
259  } elseif (!empty($search)) switch ($searchType) {
260  case USER_FIELD_USERID:
261  $searchSql = 'AND u.user_id=?';
262  $paramArray[] = $search;
263  break;
264  case USER_FIELD_INITIAL:
265  $searchSql = 'AND LOWER(u.last_name) LIKE LOWER(?)';
266  $paramArray[] = $search . '%';
267  break;
268  }
269 
270  $searchSql .= ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : '');
271 
272  $result =& $this->retrieveRange(
273 
274  'SELECT DISTINCT u.* FROM users AS u LEFT JOIN user_settings s ON (u.user_id = s.user_id AND s.setting_name = ?), roles AS r WHERE u.user_id = r.user_id AND r.conference_id = ? ' . $searchSql,
275  $paramArray,
276  $dbResultRange
277  );
278 
279  $returner = new DAOResultFactory($result, $this->userDao, '_returnUserFromRowWithData');
280  return $returner;
281  }
282 
292  function &getUsersBySchedConfId($schedConfId, $searchType = null, $search = null, $searchMatch = null, $dbResultRange = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
293  $users = array();
294 
295  $paramArray = array('interests', (int) $schedConfId);
296  $searchSql = '';
297 
298  if (!empty($search)) switch ($searchType) {
299  case USER_FIELD_USERID:
300  $searchSql = 'AND u.user_id=?';
301  $paramArray[] = $search;
302  break;
304  $searchSql = 'AND LOWER(u.first_name) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
305  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
306  break;
307  case USER_FIELD_LASTNAME:
308  $searchSql = 'AND LOWER(u.last_name) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
309  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
310  break;
311  case USER_FIELD_USERNAME:
312  $searchSql = 'AND LOWER(u.username) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
313  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
314  break;
315  case USER_FIELD_EMAIL:
316  $searchSql = 'AND LOWER(u.email) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
317  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
318  break;
320  $searchSql = 'AND LOWER(s.setting_value) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
321  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
322  break;
323  case USER_FIELD_INITIAL:
324  $searchSql = 'AND LOWER(u.last_name) LIKE LOWER(?)';
325  $paramArray[] = $search . '%';
326  break;
327  }
328 
329  $searchSql .= ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : '');
330 
331  $result =& $this->retrieveRange(
332 
333  'SELECT DISTINCT u.* FROM users AS u LEFT JOIN user_settings s ON (u.user_id = s.user_id AND s.setting_name = ?), roles AS r WHERE u.user_id = r.user_id AND r.sched_conf_id = ? ' . $searchSql,
334  $paramArray,
335  $dbResultRange
336  );
337 
338  $returner = new DAOResultFactory($result, $this->userDao, '_returnUserFromRowWithData');
339  return $returner;
340  }
341 
347  function getConferenceUsersCount($conferenceId) {
348  $userDao =& DAORegistry::getDAO('UserDAO');
349 
350  $result =& $this->retrieve(
351  'SELECT COUNT(DISTINCT(user_id)) FROM roles WHERE conference_id = ?',
352  (int) $conferenceId
353  );
354 
355  $returner = $result->fields[0];
356 
357  $result->Close();
358  unset($result);
359 
360  return $returner;
361  }
362 
369  function getSchedConfUsersCount($schedConfId, $roleId = null) {
370  $userDao =& DAORegistry::getDAO('UserDAO');
371 
372  $params = array((int) $schedConfId);
373  if ($roleId !== null) $params[] = (int) $roleId;
374 
375  $result =& $this->retrieve(
376  'SELECT COUNT(DISTINCT(user_id)) FROM roles WHERE sched_conf_id = ?' . ($roleId === null?'':' AND role_id = ?'),
377  $params
378  );
379 
380  $returner = $result->fields[0];
381 
382  $result->Close();
383  unset($result);
384 
385  return $returner;
386  }
387 
393  function &getRolesByConferenceId($conferenceId = null, $roleId = null) {
394  $params = array();
395  $conditions = array();
396  if (isset($conferenceId)) {
397  $params[] = (int) $conferenceId;
398  $conditions[] = 'conference_id = ?';
399  }
400  if (isset($roleId)) {
401  $params[] = (int) $roleId;
402  $conditions[] = 'role_id = ?';
403  }
404 
405  $result =& $this->retrieve(
406  'SELECT * FROM roles' . (empty($conditions) ? '' : ' WHERE ' . join(' AND ', $conditions)),
407  $params
408  );
409 
410  $returner = new DAOResultFactory($result, $this, '_returnRoleFromRow');
411  return $returner;
412  }
413 
418  function deleteRoleByConferenceId($conferenceId) {
419  return $this->update(
420  'DELETE FROM roles WHERE conference_id = ?', (int) $conferenceId
421  );
422  }
423 
428  function deleteRoleBySchedConfId($schedConfId) {
429  return $this->update(
430  'DELETE FROM roles WHERE sched_conf_id = ?', (int) $schedConfId
431  );
432  }
433 
440  function deleteRoleByUserId($userId, $conferenceId = null, $roleId = null, $schedConfId = null) {
441 
442  $args = array((int)$userId);
443  if(isset($conferenceId)) $args[] = (int)$conferenceId;
444  if(isset($roleId)) $args[] = (int)$roleId;
445  if(isset($schedConfId)) $args[] = (int)$schedConfId;
446 
447  return $this->update(
448  'DELETE FROM roles WHERE user_id = ?' .
449  (isset($conferenceId) ? ' AND conference_id = ?' : '') .
450  (isset($roleId) ? ' AND role_id = ?' : '') .
451  (isset($schedConfId) ? ' AND sched_conf_id = ?' : ''),
452  (count($args) ? $args : shift($args)));
453  }
454 
462  function roleExists($conferenceId, $schedConfId, $userId, $roleId) {
463  $result =& $this->retrieve(
464  'SELECT COUNT(*) FROM roles WHERE conference_id = ? AND sched_conf_id = ? AND user_id = ? AND role_id = ?', array((int) $conferenceId, (int)$schedConfId, (int) $userId, (int) $roleId)
465  );
466  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
467 
468  $result->Close();
469  unset($result);
470 
471  return $returner;
472  }
473 
480  function getRoleName($roleId, $plural = false) {
481  switch ($roleId) {
482  case ROLE_ID_SITE_ADMIN:
483  return 'user.role.siteAdmin' . ($plural ? 's' : '');
485  return 'user.role.manager' . ($plural ? 's' : '');
486  case ROLE_ID_DIRECTOR:
487  return 'user.role.director' . ($plural ? 's' : '');
489  return 'user.role.trackDirector' . ($plural ? 's' : '');
490  case ROLE_ID_REVIEWER:
491  return 'user.role.reviewer' . ($plural ? 's' : '');
492  case ROLE_ID_AUTHOR:
493  return 'user.role.author' . ($plural ? 's' : '');
494  case ROLE_ID_READER:
495  return 'user.role.reader' . ($plural ? 's' : '');
496  default:
497  return '';
498  }
499  }
500 
506  function getRolePath($roleId) {
507  switch ($roleId) {
508  case ROLE_ID_SITE_ADMIN:
509  return ROLE_PATH_SITE_ADMIN;
512  case ROLE_ID_DIRECTOR:
513  return ROLE_PATH_DIRECTOR;
516  case ROLE_ID_REVIEWER:
517  return ROLE_PATH_REVIEWER;
518  case ROLE_ID_AUTHOR:
519  return ROLE_PATH_AUTHOR;
520  case ROLE_ID_READER:
521  return ROLE_PATH_READER;
522  default:
523  return '';
524  }
525  }
526 
532  function getRoleIdFromPath($rolePath) {
533  switch ($rolePath) {
535  return ROLE_ID_SITE_ADMIN;
538  case ROLE_PATH_DIRECTOR:
539  return ROLE_ID_DIRECTOR;
541  return ROLE_ID_TRACK_DIRECTOR;
542  case ROLE_PATH_REVIEWER:
543  return ROLE_ID_REVIEWER;
544  case ROLE_PATH_AUTHOR:
545  return ROLE_ID_AUTHOR;
546  case ROLE_PATH_READER:
547  return ROLE_ID_READER;
548  default:
549  return null;
550  }
551  }
552 
558  function getSortMapping($heading) {
559  switch ($heading) {
560  case 'username': return 'u.username';
561  case 'name': return 'u.last_name';
562  case 'email': return 'u.email';
563  case 'id': return 'u.user_id';
564  default: return null;
565  }
566  }
567 }
568 
569 ?>
const ROLE_PATH_AUTHOR
Definition: Role.inc.php:35
const ROLE_PATH_SITE_ADMIN
Definition: Role.inc.php:20
config TEMPLATE inc php
Definition: config.inc.php:4
& getRolesByUserId($userId, $conferenceId=null, $schedConfId=null)
deleteRoleByUserId($userId, $conferenceId=null, $roleId=null, $schedConfId=null)
const USER_FIELD_INTERESTS
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
const USER_FIELD_FIRSTNAME
const USER_FIELD_LASTNAME
const USER_FIELD_USERNAME
const ROLE_PATH_CONFERENCE_MANAGER
Definition: Role.inc.php:23
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
& getUsersBySchedConfId($schedConfId, $searchType=null, $search=null, $searchMatch=null, $dbResultRange=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)
deleteRole(&$role)
Definition: RoleDAO.inc.php:98
getConferenceUsersCount($conferenceId)
getRoleIdFromPath($rolePath)
Operations for retrieving and modifying Role objects.
Definition: RoleDAO.inc.php:20
deleteRoleByConferenceId($conferenceId)
const ROLE_ID_TRACK_DIRECTOR
Definition: Role.inc.php:28
const USER_FIELD_INITIAL
const ROLE_PATH_READER
Definition: Role.inc.php:47
const ROLE_ID_DIRECTOR
Definition: Role.inc.php:25
getSchedConfUsersCount($schedConfId, $roleId=null)
Describes user roles within the system and the associated permissions.
Definition: Role.inc.php:49
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:152
& getRolesByConferenceId($conferenceId=null, $roleId=null)
& getRole($conferenceId, $schedConfId, $userId, $roleId)
Definition: RoleDAO.inc.php:36
const USER_FIELD_USERID
const ROLE_ID_SITE_ADMIN
Definition: Role.inc.php:19
& getUsersByRoleId($roleId=null, $conferenceId=null, $schedConfId=null, $searchType=null, $search=null, $searchMatch=null, $dbResultRange=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)
& getUsersByConferenceId($conferenceId, $searchType=null, $search=null, $searchMatch=null, $dbResultRange=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
deleteRoleBySchedConfId($schedConfId)
& getDAO($name, $dbconn=null)
const ROLE_PATH_TRACK_DIRECTOR
Definition: Role.inc.php:29
& _returnRoleFromRow(&$row)
Definition: RoleDAO.inc.php:63
roleExists($conferenceId, $schedConfId, $userId, $roleId)
insertRole(&$role)
Definition: RoleDAO.inc.php:79
call($hookName, $args=null)
getSortMapping($heading)
getRolePath($roleId)
const ROLE_PATH_REVIEWER
Definition: Role.inc.php:32
const ROLE_ID_READER
Definition: Role.inc.php:46
const ROLE_ID_REVIEWER
Definition: Role.inc.php:31
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
const USER_FIELD_EMAIL
getDirectionMapping($direction)
Definition: DAO.inc.php:541
const ROLE_ID_CONFERENCE_MANAGER
Definition: Role.inc.php:22
const ROLE_ID_AUTHOR
Definition: Role.inc.php:34
const SORT_DIRECTION_ASC
Definition: DAO.inc.php:27
getRoleName($roleId, $plural=false)
const ROLE_PATH_DIRECTOR
Definition: Role.inc.php:26