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
00036 class ilLearningProgress
00037 {
00038 var $db = null;
00039
00040 function ilLearningProgress()
00041 {
00042 global $ilDB;
00043
00044 $this->db = $ilDB;
00045 }
00046
00047
00048 function _tracProgress($a_user_id,$a_obj_id, $a_obj_type = '')
00049 {
00050 global $ilDB,$ilObjDataCache;
00051
00052 if(!strlen($a_obj_type))
00053 {
00054 $a_obj_type = $ilObjDataCache->lookupType($a_obj_id);
00055 }
00056
00057 if($progress = ilLearningProgress::_getProgress($a_user_id,$a_obj_id))
00058 {
00059 ilLearningProgress::_updateProgress($progress);
00060 return true;
00061 }
00062 $query = "INSERT INTO ut_learning_progress ".
00063 "SET user_id = '".$a_user_id."', ".
00064 "obj_type = '".$a_obj_type."', ".
00065 "obj_id = '".$a_obj_id."', ".
00066 "spent_time = '0',".
00067 "access_time = '".time()."', ".
00068 "visits = '1'";
00069
00070 $ilDB->query($query);
00071 return true;
00072 }
00073
00074 function _getProgress($a_user_id,$a_obj_id)
00075 {
00076 global $ilDB;
00077
00078 $query = "SELECT * FROM ut_learning_progress ".
00079 "WHERE user_id = '".$a_user_id."' ".
00080 "AND obj_id = '".$a_obj_id."'";
00081 $res = $ilDB->query($query);
00082
00083 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00084 {
00085 $progress['lp_id'] = $row->lp_id;
00086 $progress['obj_id'] = $row->obj_id;
00087 $progress['obj_type'] = $row->obj_type;
00088 $progress['user_id'] = $row->user_id;
00089 $progress['spent_time'] = $row->spent_time;
00090 $progress['access_time'] = $row->access_time;
00091 $progress['visits'] = $row->visits;
00092 }
00093 return $progress ? $progress : array();
00094 }
00095
00096 function _updateProgress($data)
00097 {
00098 global $ilDB;
00099
00100 $spent = $data['spent_time'];
00101
00102 include_once('Services/Tracking/classes/class.ilObjUserTracking.php');
00103 if((time() - $data['access_time']) <= ilObjUserTracking::_getValidTimeSpan())
00104 {
00105 $spent = $data['spent_time'] + time() - $data['access_time'];
00106 }
00107 $visits = $data['visits'] + 1;
00108
00109 $query = "UPDATE ut_learning_progress ".
00110 "SET visits = visits + 1, ".
00111 "spent_time = '".$spent."', ".
00112 "access_time = '".time()."' ".
00113 "WHERE lp_id = '".$data['lp_id']."'";
00114
00115 $ilDB->query($query);
00116 }
00117 }
00118 ?>