ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $DIC;
31
32 $ilDB = $DIC['ilDB'];
33
34 $res = $ilDB->query('SELECT online_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($a_user_id, 'integer'));
35 while ($row = $ilDB->fetchAssoc($res)) {
36 return (int) $row['online_time'];
37 }
38
39 return 0;
40 }
41
48 public static function addUser($a_user_id)
49 {
53 global $DIC;
54
55 $ilDB = $DIC['ilDB'];
56
57 $res = $ilDB->query('SELECT access_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($a_user_id, 'integer'));
58 if ($ilDB->numRows($res)) {
59 $row = $ilDB->fetchAssoc($res);
60 self::$last_access_time = (int) $row['access_time'];
61 return false;
62 }
63
64 $ilDB->manipulateF(
65 'INSERT INTO ut_online (usr_id, access_time) VALUES (%s, %s)',
66 array('integer', 'integer'),
67 array($a_user_id, time())
68 );
69 self::$last_access_time = time();
70
71 return true;
72 }
73
80 public static function updateAccess(ilObjUser $user)
81 {
86 global $DIC;
87
88 $ilDB = $DIC['ilDB'];
89 $ilSetting = $DIC['ilSetting'];
90
91 if (null === self::$last_access_time) {
92 $query = 'SELECT access_time FROM ut_online WHERE usr_id = ' . $ilDB->quote($user->getId(), 'integer');
93 $res = $ilDB->query($query);
94 if (!$ilDB->numRows($res)) {
95 return false;
96 }
97 $row = $ilDB->fetchAssoc($res);
98 self::$last_access_time = $row['access_time'];
99 }
100
101 $time_span = (int) $ilSetting->get('tracking_time_span', 300);
102 if (($diff = time() - self::$last_access_time) <= $time_span) {
103 $ilDB->manipulateF(
104 'UPDATE ut_online SET online_time = online_time + %s, access_time = %s WHERE usr_id = %s',
105 array('integer', 'integer', 'integer'),
106 array($diff, time(), $user->getId())
107 );
108 } else {
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}
An exception for terminatinating execution or to throw for unit testing.
getId()
get object id @access public
global $ilSetting
Definition: privfeed.php:17
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46