Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00038 class ilOnlineTracking
00039 {
00040
00041 function _getOnlineTime($a_user_id)
00042 {
00043 global $ilDB;
00044
00045 $query = "SELECT * FROM ut_online WHERE usr_id = '".$a_user_id."'";
00046 $res = $ilDB->query($query);
00047 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00048 {
00049 $access_time = $row->access_time;
00050 $online_time = $row->online_time;
00051 }
00052 return (int) $online_time;
00053 }
00054
00055
00056
00057 function _addUser($a_user_id)
00058 {
00059 global $ilDB;
00060
00061 $query = "SELECT * FROM ut_online WHERE usr_id = '".$a_user_id."'";
00062 $res = $ilDB->query($query);
00063
00064 if($res->numRows())
00065 {
00066 return false;
00067 }
00068 $query = "INSERT INTO ut_online SET usr_id = '".$a_user_id."', access_time = '".time()."'";
00069 $ilDB->query($query);
00070
00071 return true;
00072 }
00073
00074 function _updateAccess($a_usr_id)
00075 {
00076 global $ilDB,$ilias;
00077
00078 $query = "SELECT * FROM ut_online WHERE usr_id = '".$a_usr_id."'";
00079 $res = $ilDB->query($query);
00080
00081 if(!$res->numRows())
00082 {
00083 return false;
00084 }
00085 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00086 {
00087 $access_time = $row->access_time;
00088 $online_time = $row->online_time;
00089 }
00090
00091 $time_span = (int) $ilias->getSetting("tracking_time_span",300);
00092
00093 if(($diff = time() - $access_time) <= $time_span)
00094 {
00095 $query = "UPDATE ut_online SET online_time = online_time + '".$diff."', access_time = '".time().
00096 "' WHERE usr_id = '".$a_usr_id."'";
00097 $ilDB->query($query);
00098 }
00099 else
00100 {
00101 $query = "UPDATE ut_online SET access_time = '".time().
00102 "' WHERE usr_id = '".$a_usr_id."'";
00103 $ilDB->query($query);
00104 }
00105 return true;
00106 }
00107 }
00108 ?>