ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilOnlineTracking.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
18  protected static $last_access_time = null;
19 
25  public static function getOnlineTime($a_user_id)
26  {
30  global $ilDB;
31 
32  $res = $ilDB->query('SELECT online_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($a_user_id, 'integer'));
33  while($row = $ilDB->fetchAssoc($res))
34  {
35  return (int)$row['online_time'];
36  }
37 
38  return 0;
39  }
40 
47  public static function addUser($a_user_id)
48  {
52  global $ilDB;
53 
54  $res = $ilDB->query('SELECT access_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($a_user_id, 'integer'));
55  if($ilDB->numRows($res))
56  {
57  $row = $ilDB->fetchAssoc($res);
58  self::$last_access_time = (int)$row['access_time'];
59  return false;
60  }
61 
62  $ilDB->manipulateF(
63  'INSERT INTO ut_online (usr_id, access_time) VALUES (%s, %s)',
64  array('integer', 'integer'),
65  array($a_user_id, time())
66  );
67  self::$last_access_time = time();
68 
69  return true;
70  }
71 
78  public static function updateAccess(ilObjUser $user)
79  {
84  global $ilDB, $ilSetting;
85 
86  if(null === self::$last_access_time)
87  {
88  $query = 'SELECT access_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($user->getId(), 'integer');
89  $res = $ilDB->query($query);
90  if(!$ilDB->numRows($res))
91  {
92  return false;
93  }
94  $row = $ilDB->fetchAssoc($res);
95  self::$last_access_time = $row['access_time'];
96  }
97 
98  $time_span = (int)$ilSetting->get('tracking_time_span', 300);
99  if(($diff = time() - self::$last_access_time) <= $time_span)
100  {
101  $ilDB->manipulateF(
102  'UPDATE ut_online SET online_time = online_time + %s, access_time = %s WHERE usr_id = %s',
103  array('integer', 'integer', 'integer'),
104  array($diff, time(), $user->getId())
105  );
106  }
107  else
108  {
109  $ilDB->manipulateF(
110  'UPDATE ut_online SET access_time = %s WHERE usr_id = %s',
111  array('integer', 'integer'),
112  array(time(), $user->getId())
113  );
114  }
115  return true;
116  }
117 }
getId()
get object id public
Create styles array
The data for the language used.
global $ilSetting
Definition: privfeed.php:17
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.