Open Journal Systems  3.0.0
 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  return $session;
64  }
65 
70  function insertObject($session) {
71  $this->update(
72  'INSERT INTO sessions
73  (session_id, ip_address, user_agent, created, last_used, remember, data, domain)
74  VALUES
75  (?, ?, ?, ?, ?, ?, ?, ?)',
76  array(
77  $session->getId(),
78  $session->getIpAddress(),
79  substr($session->getUserAgent(), 0, 255),
80  (int) $session->getSecondsCreated(),
81  (int) $session->getSecondsLastUsed(),
82  $session->getRemember() ? 1 : 0,
83  $session->getSessionData(),
84  $session->getDomain()
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  domain = ?
105  WHERE session_id = ?',
106  array(
107  $session->getUserId()==''?null:(int) $session->getUserId(),
108  $session->getIpAddress(),
109  substr($session->getUserAgent(), 0, 255),
110  (int) $session->getSecondsCreated(),
111  (int) $session->getSecondsLastUsed(),
112  $session->getRemember() ? 1 : 0,
113  $session->getSessionData(),
114  $session->getDomain(),
115  $session->getId()
116  )
117  );
118  }
119 
124  function deleteObject(&$session) {
125  return $this->deleteById($session->getId());
126  }
127 
132  function deleteById($sessionId) {
133  return $this->update(
134  'DELETE FROM sessions WHERE session_id = ?',
135  array($sessionId)
136  );
137  }
138 
143  function deleteByUserId($userId) {
144  return $this->update(
145  'DELETE FROM sessions WHERE user_id = ?',
146  array((int) $userId)
147  );
148  }
149 
155  function deleteByLastUsed($lastUsed, $lastUsedRemember = 0) {
156  if ($lastUsedRemember == 0) {
157  return $this->update(
158  'DELETE FROM sessions WHERE (last_used < ? AND remember = 0)',
159  array((int) $lastUsed)
160  );
161  } else {
162  return $this->update(
163  'DELETE FROM sessions WHERE (last_used < ? AND remember = 0) OR (last_used < ? AND remember = 1)',
164  array((int) $lastUsed, (int) $lastUsedRemember)
165  );
166  }
167  }
168 
172  function deleteAllSessions() {
173  return $this->update('DELETE FROM sessions');
174  }
175 
181  function sessionExistsById($sessionId) {
182  $result = $this->retrieve(
183  'SELECT COUNT(*) FROM sessions WHERE session_id = ?',
184  array($sessionId)
185  );
186  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
187 
188  $result->Close();
189  return $returner;
190  }
191 }
192 
193 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
sessionExistsById($sessionId)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
deleteById($sessionId)
deleteByLastUsed($lastUsed, $lastUsedRemember=0)
insertObject($session)
& 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:22
deleteObject(&$session)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
deleteByUserId($userId)