Open Journal Systems  2.4.8
 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  $session->setDomain($row['domain']);
60  }
61 
62  $result->Close();
63  unset($result);
64 
65  return $session;
66  }
67 
72  function insertSession(&$session) {
73  return $this->update(
74  'INSERT INTO sessions
75  (session_id, ip_address, user_agent, created, last_used, remember, data, domain)
76  VALUES
77  (?, ?, ?, ?, ?, ?, ?, ?)',
78  array(
79  $session->getId(),
80  $session->getIpAddress(),
81  substr($session->getUserAgent(), 0, 255),
82  (int) $session->getSecondsCreated(),
83  (int) $session->getSecondsLastUsed(),
84  $session->getRemember() ? 1 : 0,
85  $session->getSessionData(),
86  $session->getDomain()
87  )
88  );
89  }
90 
95  function updateObject(&$session) {
96  return $this->update(
97  'UPDATE sessions
98  SET
99  user_id = ?,
100  ip_address = ?,
101  user_agent = ?,
102  created = ?,
103  last_used = ?,
104  remember = ?,
105  data = ?,
106  domain = ?
107  WHERE session_id = ?',
108  array(
109  $session->getUserId()==''?null:(int) $session->getUserId(),
110  $session->getIpAddress(),
111  substr($session->getUserAgent(), 0, 255),
112  (int) $session->getSecondsCreated(),
113  (int) $session->getSecondsLastUsed(),
114  $session->getRemember() ? 1 : 0,
115  $session->getSessionData(),
116  $session->getDomain(),
117  $session->getId()
118  )
119  );
120  }
121 
122  function updateSession(&$session) {
123  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
124  return $this->updateObject($session);
125  }
126 
131  function deleteObject(&$session) {
132  return $this->deleteSessionById($session->getId());
133  }
134 
135  function deleteSession(&$session) {
136  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
137  return $this->deleteObject($session);
138  }
139 
144  function deleteSessionById($sessionId) {
145  return $this->update(
146  'DELETE FROM sessions WHERE session_id = ?',
147  array($sessionId)
148  );
149  }
150 
155  function deleteSessionsByUserId($userId) {
156  return $this->update(
157  'DELETE FROM sessions WHERE user_id = ?',
158  array((int) $userId)
159  );
160  }
161 
167  function deleteSessionByLastUsed($lastUsed, $lastUsedRemember = 0) {
168  if ($lastUsedRemember == 0) {
169  return $this->update(
170  'DELETE FROM sessions WHERE (last_used < ? AND remember = 0)',
171  array((int) $lastUsed)
172  );
173  } else {
174  return $this->update(
175  'DELETE FROM sessions WHERE (last_used < ? AND remember = 0) OR (last_used < ? AND remember = 1)',
176  array((int) $lastUsed, (int) $lastUsedRemember)
177  );
178  }
179  }
180 
184  function deleteAllSessions() {
185  return $this->update('DELETE FROM sessions');
186  }
187 
193  function sessionExistsById($sessionId) {
194  $result =& $this->retrieve(
195  'SELECT COUNT(*) FROM sessions WHERE session_id = ?',
196  array($sessionId)
197  );
198  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
199 
200  $result->Close();
201  unset($result);
202 
203  return $returner;
204  }
205 }
206 
207 ?>
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)