Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / session / Session.class.php
1 <?php
2 namespace wcf\data\session;
3 use wcf\data\acp\session\ACPSession;
4 use wcf\system\WCF;
5
6 /**
7 * Represents a session.
8 *
9 * @author Alexander Ebert
10 * @copyright 2001-2014 WoltLab GmbH
11 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 * @package com.woltlab.wcf
13 * @subpackage data.session
14 * @category Community Framework
15 */
16 class Session extends ACPSession {
17 /**
18 * @see \wcf\data\DatabaseObject::$databaseTableName
19 */
20 protected static $databaseTableName = 'session';
21
22 /**
23 * @see \wcf\data\DatabaseObject::$databaseTableIndexName
24 */
25 protected static $databaseTableIndexName = 'sessionID';
26
27 /**
28 * @see \wcf\data\acp\session\ACPSession::supportsPersistentLogins()
29 */
30 public static function supportsPersistentLogins() {
31 return true;
32 }
33
34 /**
35 * @see \wcf\data\acp\session\ACPSession::supportsVirtualSessions()
36 */
37 public static function supportsVirtualSessions() {
38 return (SESSION_ENABLE_VIRTUALIZATION) ? true : false;
39 }
40
41 /**
42 * Returns the existing session object for given user id or null if there
43 * is no such session.
44 *
45 * @param integer $userID
46 * @return \wcf\data\session\Session
47 */
48 public static function getSessionByUserID($userID) {
49 $sql = "SELECT *
50 FROM ".static::getDatabaseTableName()."
51 WHERE userID = ?";
52 $statement = WCF::getDB()->prepareStatement($sql);
53 $statement->execute(array($userID));
54 $row = $statement->fetchArray();
55
56 if ($row === false) {
57 return null;
58 }
59
60 return new static(null, $row);
61 }
62 }