ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
13{
19 protected static $last_access_time = null;
20
26 public static function getOnlineTime($a_user_id)
27 {
31 global $ilDB;
32
33 $res = $ilDB->query('SELECT online_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($a_user_id, 'integer'));
34 while($row = $ilDB->fetchAssoc($res))
35 {
36 return (int)$row['online_time'];
37 }
38
39 return 0;
40 }
41
48 public static function addUser($a_user_id)
49 {
53 global $ilDB;
54
55 $res = $ilDB->query('SELECT access_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($a_user_id, 'integer'));
56 if($ilDB->numRows($res))
57 {
58 $row = $ilDB->fetchAssoc($res);
59 self::$last_access_time = (int)$row['access_time'];
60 return false;
61 }
62
63 $ilDB->manipulateF(
64 'INSERT INTO ut_online (usr_id, access_time) VALUES (%s, %s)',
65 array('integer', 'integer'),
66 array($a_user_id, time())
67 );
68 self::$last_access_time = time();
69
70 return true;
71 }
72
79 public static function updateAccess(ilObjUser $user)
80 {
85 global $ilDB, $ilSetting;
86
87 if(null === self::$last_access_time)
88 {
89 $query = 'SELECT access_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($user->getId(), 'integer');
90 $res = $ilDB->query($query);
91 if(!$ilDB->numRows($res))
92 {
93 return false;
94 }
95 $row = $ilDB->fetchAssoc($res);
96 self::$last_access_time = $row['access_time'];
97 }
98
99 $time_span = (int)$ilSetting->get('tracking_time_span', 300);
100 if(($diff = time() - self::$last_access_time) <= $time_span)
101 {
102 $ilDB->manipulateF(
103 'UPDATE ut_online SET online_time = online_time + %s, access_time = %s WHERE usr_id = %s',
104 array('integer', 'integer', 'integer'),
105 array($diff, time(), $user->getId())
106 );
107 }
108 else
109 {
110 $ilDB->manipulateF(
111 'UPDATE ut_online SET access_time = %s WHERE usr_id = %s',
112 array('integer', 'integer'),
113 array(time(), $user->getId())
114 );
115 }
116 return true;
117 }
118}
getId()
get object id @access public
global $ilSetting
Definition: privfeed.php:40
global $ilDB