ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  return (int) $row['online_time'];
35  }
36 
37  return 0;
38  }
39 
46  public static function addUser($a_user_id)
47  {
51  global $ilDB;
52 
53  $res = $ilDB->query('SELECT access_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($a_user_id, 'integer'));
54  if ($ilDB->numRows($res)) {
55  $row = $ilDB->fetchAssoc($res);
56  self::$last_access_time = (int) $row['access_time'];
57  return false;
58  }
59 
60  $ilDB->manipulateF(
61  'INSERT INTO ut_online (usr_id, access_time) VALUES (%s, %s)',
62  array('integer', 'integer'),
63  array($a_user_id, time())
64  );
65  self::$last_access_time = time();
66 
67  return true;
68  }
69 
76  public static function updateAccess(ilObjUser $user)
77  {
82  global $ilDB, $ilSetting;
83 
84  if (null === self::$last_access_time) {
85  $query = 'SELECT access_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($user->getId(), 'integer');
86  $res = $ilDB->query($query);
87  if (!$ilDB->numRows($res)) {
88  return false;
89  }
90  $row = $ilDB->fetchAssoc($res);
91  self::$last_access_time = $row['access_time'];
92  }
93 
94  $time_span = (int) $ilSetting->get('tracking_time_span', 300);
95  if (($diff = time() - self::$last_access_time) <= $time_span) {
96  $ilDB->manipulateF(
97  'UPDATE ut_online SET online_time = online_time + %s, access_time = %s WHERE usr_id = %s',
98  array('integer', 'integer', 'integer'),
99  array($diff, time(), $user->getId())
100  );
101  } else {
102  $ilDB->manipulateF(
103  'UPDATE ut_online SET access_time = %s WHERE usr_id = %s',
104  array('integer', 'integer'),
105  array(time(), $user->getId())
106  );
107  }
108  return true;
109  }
110 }
foreach($_POST as $key=> $value) $res
getId()
get object id public
$query
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.