Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
UserDAO.inc.php
1 <?php
2 
17 import('classes.user.User');
18 import('lib.pkp.classes.user.PKPUserDAO');
19 
20 class UserDAO extends PKPUserDAO {
26  function renewMembership(&$user){
27  $dateEnd = $user->getSetting('dateEndMembership', 0);
28  if (!$dateEnd) $dateEnd = 0;
29 
30  // if the membership is expired, extend it to today + 1 year
31  $time = time();
32  if ($dateEnd < $time ) $dateEnd = $time;
33 
34  $dateEnd = mktime(23, 59, 59, date("m", $dateEnd), date("d", $dateEnd), date("Y", $dateEnd)+1);
35  $user->updateSetting('dateEndMembership', $dateEnd, 'date', 0);
36  }
37 
49  function &getJournalUsersByField($field = USER_FIELD_NONE, $match = null, $value = null, $allowDisabled = true, $journalId = null, $dbResultRange = null) {
50  $sql = 'SELECT * FROM users u WHERE 1=1';
51  if ($journalId) $sql = 'SELECT u.* FROM users u LEFT JOIN roles r ON u.user_id=r.user_id WHERE (r.journal_id='.$journalId.' or r.role_id IS NULL)';
52 
53  switch ($field) {
54  case USER_FIELD_USERID:
55  $sql .= ' AND u.user_id = ?';
56  $var = $value;
57  break;
58  case USER_FIELD_USERNAME:
59  $sql .= ' AND LOWER(u.username) ' . ($match == 'is' ? '=' : 'LIKE') . ' LOWER(?)';
60  $var = $match == 'is' ? $value : "%$value%";
61  break;
62  case USER_FIELD_INITIAL:
63  $sql .= ' AND LOWER(u.last_name) LIKE LOWER(?)';
64  $var = "$value%";
65  break;
66  case USER_FIELD_EMAIL:
67  $sql .= ' AND LOWER(u.email) ' . ($match == 'is' ? '=' : 'LIKE') . ' LOWER(?)';
68  $var = $match == 'is' ? $value : "%$value%";
69  break;
70  case USER_FIELD_URL:
71  $sql .= ' AND LOWER(u.url) ' . ($match == 'is' ? '=' : 'LIKE') . ' LOWER(?)';
72  $var = $match == 'is' ? $value : "%$value%";
73  break;
74  case USER_FIELD_FIRSTNAME:
75  $sql .= ' AND LOWER(u.first_name) ' . ($match == 'is' ? '=' : 'LIKE') . ' LOWER(?)';
76  $var = $match == 'is' ? $value : "%$value%";
77  break;
78  case USER_FIELD_LASTNAME:
79  $sql .= ' AND LOWER(u.last_name) ' . ($match == 'is' ? '=' : 'LIKE') . ' LOWER(?)';
80  $var = $match == 'is' ? $value : "%$value%";
81  break;
82  }
83 
84  $groupSql = ' GROUP BY u.user_id';
85  $orderSql = ' ORDER BY u.last_name, u.first_name'; // FIXME Add "sort field" parameter?
86 
87  if ($field != USER_FIELD_NONE)
88  $result =& $this->retrieveRange($sql . ($allowDisabled?'':' AND u.disabled = 0') . $groupSql . $orderSql, $var, $dbResultRange);
89  else
90  $result =& $this->retrieveRange($sql . ($allowDisabled?'':' AND u.disabled = 0') . $groupSql . $orderSql, false, $dbResultRange);
91 
92  $returner = new DAOResultFactory($result, $this, '_returnUserFromRowWithData');
93  return $returner;
94  }
95 }
96 
97 ?>
Basic class describing users existing in the system.
Definition: UserDAO.inc.php:20
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
renewMembership(&$user)
Definition: UserDAO.inc.php:26
& getJournalUsersByField($field=USER_FIELD_NONE, $match=null, $value=null, $allowDisabled=true, $journalId=null, $dbResultRange=null)
Definition: UserDAO.inc.php:49
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
Operations for retrieving and modifying User objects.