Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
SessionDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.session.Session');
19 
20 class SessionDAO extends DAO {
24  function SessionDAO() {
25  parent::DAO();
26  }
27 
31  function newDataObject() {
32  return new Session();
33  }
34 
40  function &getSession($sessionId) {
41  $result =& $this->retrieve(
42  'SELECT * FROM sessions WHERE session_id = ?',
43  array($sessionId)
44  );
45 
46  $session = null;
47  if ($result->RecordCount() != 0) {
48  $row =& $result->GetRowAssoc(false);
49 
50  $session = $this->newDataObject();
51  $session->setId($row['session_id']);
52  $session->setUserId($row['user_id']);
53  $session->setIpAddress($row['ip_address']);
54  $session->setUserAgent($row['user_agent']);
55  $session->setSecondsCreated($row['created']);
56  $session->setSecondsLastUsed($row['last_used']);
57  $session->setRemember($row['remember']);
58  $session->setSessionData($row['data']);
59  }
60 
61  $result->Close();
62  unset($result);
63 
64  return $session;
65  }
66 
71  function insertSession(&$session) {
72  return $this->update(
73  'INSERT INTO sessions
74  (session_id, ip_address, user_agent, created, last_used, remember, data)
75  VALUES
76  (?, ?, ?, ?, ?, ?, ?)',
77  array(
78  $session->getId(),
79  $session->getIpAddress(),
80  substr($session->getUserAgent(), 0, 255),
81  (int) $session->getSecondsCreated(),
82  (int) $session->getSecondsLastUsed(),
83  $session->getRemember() ? 1 : 0,
84  $session->getSessionData()
85  )
86  );
87  }
88 
93  function updateObject(&$session) {
94  return $this->update(
95  'UPDATE sessions
96  SET
97  user_id = ?,
98  ip_address = ?,
99  user_agent = ?,
100  created = ?,
101  last_used = ?,
102  remember = ?,
103  data = ?
104  WHERE session_id = ?',
105  array(
106  $session->getUserId()==''?null:(int) $session->getUserId(),
107  $session->getIpAddress(),
108  substr($session->getUserAgent(), 0, 255),
109  (int) $session->getSecondsCreated(),
110  (int) $session->getSecondsLastUsed(),
111  $session->getRemember() ? 1 : 0,
112  $session->getSessionData(),
113  $session->getId()
114  )
115  );
116  }
117 
118  function updateSession(&$session) {
119  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
120  return $this->updateObject($session);
121  }
122 
127  function deleteObject(&$session) {
128  return $this->deleteSessionById($session->getId());
129  }
130 
131  function deleteSession(&$session) {
132  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
133  return $this->deleteObject($session);
134  }
135 
140  function deleteSessionById($sessionId) {
141  return $this->update(
142  'DELETE FROM sessions WHERE session_id = ?',
143  array($sessionId)
144  );
145  }
146 
151  function deleteSessionsByUserId($userId) {
152  return $this->update(
153  'DELETE FROM sessions WHERE user_id = ?',
154  array((int) $userId)
155  );
156  }
157 
163  function deleteSessionByLastUsed($lastUsed, $lastUsedRemember = 0) {
164  if ($lastUsedRemember == 0) {
165  return $this->update(
166  'DELETE FROM sessions WHERE (last_used < ? AND remember = 0)',
167  array((int) $lastUsed)
168  );
169  } else {
170  return $this->update(
171  'DELETE FROM sessions WHERE (last_used < ? AND remember = 0) OR (last_used < ? AND remember = 1)',
172  array((int) $lastUsed, (int) $lastUsedRemember)
173  );
174  }
175  }
176 
180  function deleteAllSessions() {
181  return $this->update('DELETE FROM sessions');
182  }
183 
189  function sessionExistsById($sessionId) {
190  $result =& $this->retrieve(
191  'SELECT COUNT(*) FROM sessions WHERE session_id = ?',
192  array($sessionId)
193  );
194  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
195 
196  $result->Close();
197  unset($result);
198 
199  return $returner;
200  }
201 }
202 
203 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
sessionExistsById($sessionId)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
deleteSessionByLastUsed($lastUsed, $lastUsedRemember=0)
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
& getSession($sessionId)
updateObject(&$session)
Operations for retrieving and modifying Session objects.
Maintains user state information from one request to the next.
Definition: Session.inc.php:21
insertSession(&$session)
deleteObject(&$session)
deleteSessionById($sessionId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
deleteSessionsByUserId($userId)