| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Platform 4 * @subpackage Database 5 * 6 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10 defined('JPATH_PLATFORM') or die; 11 12 jimport('joomla.database.table'); 13 14 /** 15 * Session table 16 * 17 * @package Joomla.Platform 18 * @subpackage Table 19 * @since 11.1 20 */ 21 class JTableSession extends JTable 22 { 23 /** 24 * Constructor 25 * 26 * @param JDatabase &$db A database connector object. 27 * 28 * @since 11.1 29 */ 30 public function __construct(&$db) 31 { 32 parent::__construct('#__session', 'session_id', $db); 33 34 $this->guest = 1; 35 $this->username = ''; 36 } 37 38 /** 39 * Insert a session 40 * 41 * @param string $sessionId The session id 42 * @param integer $clientId The id of the client application 43 * 44 * @return boolean True on success 45 * 46 * @since 11.1 47 */ 48 public function insert($sessionId, $clientId) 49 { 50 $this->session_id = $sessionId; 51 $this->client_id = $clientId; 52 53 $this->time = time(); 54 $ret = $this->_db->insertObject($this->_tbl, $this, 'session_id'); 55 56 if (!$ret) 57 { 58 $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', strtolower(get_class($this)), $this->_db->stderr())); 59 return false; 60 } 61 else 62 { 63 return true; 64 } 65 } 66 67 /** 68 * Updates the session 69 * 70 * @param boolean $updateNulls True to update fields even if they are null. 71 * 72 * @return boolean True on success. 73 * 74 * @since 11.1 75 */ 76 public function update($updateNulls = false) 77 { 78 $this->time = time(); 79 $ret = $this->_db->updateObject($this->_tbl, $this, 'session_id', $updateNulls); 80 81 if (!$ret) 82 { 83 $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', strtolower(get_class($this)), $this->_db->stderr())); 84 return false; 85 } 86 else 87 { 88 return true; 89 } 90 } 91 92 /** 93 * Destroys the pre-existing session 94 * 95 * @param integer $userId Identifier of the user for this session. 96 * @param array $clientIds Array of client ids for which session(s) will be destroyed 97 * 98 * @return boolean True on success. 99 * 100 * @since 11.1 101 */ 102 public function destroy($userId, $clientIds = array()) 103 { 104 $clientIds = implode(',', $clientIds); 105 106 $query = $this->_db->getQuery(true); 107 $query->delete(); 108 $query->from($this->_db->quoteName($this->_tbl)); 109 $query->where($this->_db->quoteName('userid') . ' = ' . $this->_db->quote($userId)); 110 $query->where($this->_db->quoteName('client_id') . ' IN (' . $clientIds . ')'); 111 $this->_db->setQuery($query); 112 113 if (!$this->_db->query()) 114 { 115 $this->setError($this->_db->stderr()); 116 return false; 117 } 118 119 return true; 120 } 121 122 /** 123 * Purge old sessions 124 * 125 * @param integer $maxLifetime Session age in seconds 126 * 127 * @return mixed Resource on success, null on fail 128 * 129 * @since 11.1 130 */ 131 public function purge($maxLifetime = 1440) 132 { 133 $past = time() - $maxLifetime; 134 $query = $this->_db->getQuery(true); 135 $query->delete(); 136 $query->from($this->_db->quoteName($this->_tbl)); 137 $query->where($this->_db->quoteName('time') . ' < ' . (int) $past); 138 $this->_db->setQuery($query); 139 140 return $this->_db->query(); 141 } 142 143 /** 144 * Find out if a user has a one or more active sessions 145 * 146 * @param integer $userid The identifier of the user 147 * 148 * @return boolean True if a session for this user exists 149 * 150 * @since 11.1 151 */ 152 public function exists($userid) 153 { 154 $query = $this->_db->getQuery(true); 155 $query->select('COUNT(userid)'); 156 $query->from($this->_db->quoteName($this->_tbl)); 157 $query->where($this->_db->quoteName('userid') . ' = ' . $this->_db->quote($userid)); 158 $this->_db->setQuery($query); 159 160 if (!$result = $this->_db->loadResult()) 161 { 162 $this->setError($this->_db->stderr()); 163 return false; 164 } 165 166 return (boolean) $result; 167 } 168 169 /** 170 * Overloaded delete method 171 * 172 * We must override it because of the non-integer primary key 173 * 174 * @param integer $oid The object id (optional). 175 * 176 * @return mixed True if successful otherwise an error message 177 * 178 * @since 11.1 179 */ 180 public function delete($oid = null) 181 { 182 //if (!$this->canDelete($msg)) 183 //{ 184 // return $msg; 185 //} 186 187 $k = $this->_tbl_key; 188 if ($oid) 189 { 190 $this->$k = $oid; 191 } 192 193 $query = $this->_db->getQuery(true); 194 $query->delete(); 195 $query->from($this->_db->quoteName($this->_tbl)); 196 $query->where($this->_db->quoteName($this->_tbl_key) . ' = ' . $this->_db->quote($this->$k)); 197 $this->_db->setQuery($query); 198 199 if ($this->_db->query()) 200 { 201 return true; 202 } 203 else 204 { 205 $this->setError($this->_db->getErrorMsg()); 206 return false; 207 } 208 } 209 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |