XOOPS  2.6.0
online.php
Go to the documentation of this file.
1 <?php
24 
32 class XoopsOnline extends XoopsObject
33 {
37  public function __construct()
38  {
39  $this->initVar('online_uid', XOBJ_DTYPE_INT, null, false);
40  $this->initVar('online_uname', XOBJ_DTYPE_TXTBOX, null, true);
41  $this->initVar('online_updated', XOBJ_DTYPE_INT, null, true);
42  $this->initVar('online_module', XOBJ_DTYPE_INT, null, true);
43  $this->initVar('online_ip', XOBJ_DTYPE_TXTBOX, null, true);
44  }
45 
50  public function id($format = 'n')
51  {
52  return $this->online_uid($format);
53  }
54 
59  public function online_uid($format = 'n')
60  {
61  return $this->getVar('online_uid', $format);
62  }
63 
68  public function online_uname($format = '')
69  {
70  return $this->getVar('online_uname', $format);
71  }
72 
77  public function online_updated($format = '')
78  {
79  return $this->getVar('online_updated', $format);
80  }
81 
86  public function online_module($format = '')
87  {
88  return $this->getVar('online_module', $format);
89  }
90 
95  public function online_ip($format = '')
96  {
97  return $this->getVar('online_ip', $format);
98  }
99 }
100 
109 {
115  public function __construct(Connection $db = null)
116  {
117  parent::__construct($db, 'online', 'XoopsOnline', 'online_uid', 'online_uname');
118  }
119 
131  public function write($uid, $uname, $time, $module, $ip)
132  {
133  $criteria = array();
134  $criteria['online_uid'] = $uid;
135  if ($uid == 0) {
136  $criteria['online_ip'] = $ip;
137  }
138  $rows = $this->db2->updatePrefix(
139  'online',
140  array(
141  'online_uname' => $uname,
142  'online_updated' => $time,
143  'online_module' => $module,
144  ),
145  $criteria
146  );
147  if ($rows === false) {
148  return false;
149  }
150  if ($rows == 0) {
151  $rows = $this->db2->insertPrefix(
152  'online',
153  array(
154  'online_uid' => $uid,
155  'online_uname' => $uname,
156  'online_updated' => $time,
157  'online_ip' => $ip,
158  'online_module' => $module,
159  )
160  );
161  }
162  if ($rows === false) {
163  return false;
164  }
165  return ($rows>0);
166  }
167 
175  public function destroy($uid)
176  {
177  $criteria = new Criteria('online_uid', intval($uid));
178  if (false === $this->deleteAll($criteria)) {
179  return false;
180  }
181  return true;
182  }
183 
193  public function gc($expire)
194  {
195  $criteria = new Criteria('online_updated', time() - intval($expire), '<');
196  if (false === $this->deleteAll($criteria)) {
197  return false;
198  }
199  return true;
200  }
201 }
online_uname($format= '')
Definition: online.php:68
write($uid, $uname, $time, $module, $ip)
Definition: online.php:131
getVar($key, $format= 's')
$module
Definition: main.php:52
if(!$xoops->isUser()) $uid
Definition: index.php:31
__construct(Connection $db=null)
Definition: online.php:115
deleteAll(CriteriaElement $criteria, $force=true, $asObject=false)
$uname
Definition: checklogin.php:37
online_uid($format= 'n')
Definition: online.php:59
$criteria
online_ip($format= '')
Definition: online.php:95
id($format= 'n')
Definition: online.php:50
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options= '')
__construct()
Definition: online.php:37
online_module($format= '')
Definition: online.php:86
online_updated($format= '')
Definition: online.php:77