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
00024
00035 class ilCourseObjectiveResult
00036 {
00037 var $db = null;
00038 var $user_id = null;
00039
00040
00041 function ilCourseObjectiveResult($a_usr_id)
00042 {
00043 global $ilDB;
00044
00045 $this->db =& $ilDB;
00046
00047 $this->user_id = $a_usr_id;
00048 }
00049 function getUserId()
00050 {
00051 return $this->user_id;
00052 }
00053
00054 function reset($a_course_id)
00055 {
00056 include_once './course/classes/class.ilCourseObjective.php';
00057 include_once './course/classes/class.ilCourseObjectiveQuestion.php';
00058
00059
00060 foreach(ilCourseObjective::_getObjectiveIds($a_course_id) as $objective_id)
00061 {
00062 $tmp_obj_question =& new ilCourseObjectiveQuestion($objective_id);
00063
00064 foreach($tmp_obj_question->getTests() as $test_data)
00065 {
00066 $this->__deleteEntries($tmp_obj_question->getQuestionsByTest($test_data['ref_id']));
00067
00068 if($tmp_test =& ilObjectFactory::getInstanceByRefId($test_data['ref_id']))
00069 {
00070 $tmp_test->deleteResults($this->getUserId(),true);
00071 unset($tmp_test);
00072 }
00073 }
00074 }
00075
00076
00077 unset($_SESSION['accomplished']);
00078 unset($_SESSION['objectives_suggested']);
00079 unset($_SESSION['objectives_status']);
00080 unset($_SESSION['objectives_fullfilled']);
00081
00082 return true;
00083 }
00084
00085 function getStatus($a_course_id)
00086 {
00087 include_once './course/classes/class.ilCourseObjective.php';
00088 include_once './course/classes/class.ilCourseObjectiveQuestion.php';
00089
00090 $final = false;
00091 $pretest = false;
00092
00093 foreach(ilCourseObjective::_getObjectiveIds($a_course_id) as $objective_id)
00094 {
00095 $tmp_obj_question =& new ilCourseObjectiveQuestion($objective_id);
00096
00097 foreach($tmp_obj_question->getTests() as $test_data)
00098 {
00099 if($this->__isAnswered($tmp_obj_question->getQuestionsByTest($test_data['ref_id'])))
00100 {
00101 if($test_data['tst_status'])
00102 {
00103 $final = true;
00104 }
00105 else
00106 {
00107 $pretest = true;
00108 }
00109 }
00110 }
00111 }
00112 if($final)
00113 {
00114 return 'final';
00115 }
00116 if($pretest)
00117 {
00118 return 'pretest';
00119 }
00120 return 'none';
00121 }
00122
00123 function updateResults($a_test_result)
00124 {
00125 foreach($a_test_result as $question_data)
00126 {
00127 if($question_data['qid'])
00128 {
00129 $this->addEntry($question_data['qid'],$question_data['reached']);
00130 }
00131 }
00132
00133 unset($_SESSION['accomplished']);
00134 unset($_SESSION['objectives_suggested']);
00135 unset($_SESSION['objectives_status']);
00136
00137 return true;
00138 }
00139
00140 function isSuggested($a_objective_id)
00141 {
00142 $suggested = true;
00143 $edited_final = true;
00144
00145 include_once './course/classes/class.ilCourseObjectiveQuestion.php';
00146 include_once './assessment/classes/class.ilObjTest.php';
00147 include_once './assessment/classes/class.ilObjTestAccess.php';
00148
00149
00150 $tmp_obj_question =& new ilCourseObjectiveQuestion($a_objective_id);
00151
00152 foreach($tmp_obj_question->getTests() as $test_data)
00153 {
00154 $tmp_points = $this->__getReachedPoints($tmp_obj_question->getQuestionsByTest($test_data['ref_id']));
00155 $max = $tmp_obj_question->getMaxPointsByTest($test_data['ref_id']);
00156 if(!$max)
00157 {
00158 return false;
00159 }
00160 if($test_data['tst_status'])
00161 {
00162 if(ilObjTestAccess::_hasFinished($this->getUserId(),$test_data['obj_id']))
00163 {
00164 return true;
00165 }
00166 continue;
00167 }
00168 if(!$tmp_points)
00169 {
00170 $suggested = true;
00171 continue;
00172 }
00173 $percent = ($tmp_points / $max) * 100.0;
00174
00175 if($percent < $test_data['tst_limit'])
00176 {
00177 $suggested = true;
00178 }
00179 else
00180 {
00181 $suggested = false;
00182 }
00183 }
00184 return $suggested;
00185 }
00186
00187
00188 function hasAccomplishedObjective($a_objective_id)
00189 {
00190 $reached = 0;
00191 $accomplished = true;
00192
00193 include_once './course/classes/class.ilCourseObjectiveQuestion.php';
00194
00195 $tmp_obj_question =& new ilCourseObjectiveQuestion($a_objective_id);
00196
00197 foreach($tmp_obj_question->getTests() as $test_data)
00198 {
00199 $tmp_points = $this->__getReachedPoints($tmp_obj_question->getQuestionsByTest($test_data['ref_id']));
00200
00201 $max = $tmp_obj_question->getMaxPointsByTest($test_data['ref_id']);
00202
00203 if(!$max)
00204 {
00205 continue;
00206 }
00207 if(!$tmp_points)
00208 {
00209 if($test_data['tst_status'])
00210 {
00211 return false;
00212 }
00213 else
00214 {
00215 $accomplished = false;
00216 continue;
00217 }
00218 }
00219
00220 $percent = ($tmp_points / $max) * 100.0;
00221
00222 if($percent >= $test_data['tst_limit'] and $test_data['tst_status'])
00223 {
00224 return true;
00225 }
00226
00227 if($test_data['tst_status'])
00228 {
00229 return false;
00230 }
00231 $accomplished = false;
00232
00233 }
00234 return $accomplished ? true : false;
00235 }
00236
00237
00238
00239 function __deleteEntries($a_objective_ids)
00240 {
00241 if(!count($a_objective_ids))
00242 {
00243 return true;
00244 }
00245 $in = "IN ('";
00246 $in .= implode("','",$a_objective_ids);
00247 $in .= "')";
00248
00249 $query = "DELETE FROM crs_objective_results ".
00250 "WHERE usr_id = '".$this->getUserId()."' ".
00251 "AND question_id ".$in;
00252
00253 $this->db->query($query);
00254
00255
00256 }
00257
00258
00259 function __getReachedPoints($a_question_ids)
00260 {
00261 $points = 0;
00262
00263 foreach($a_question_ids as $qid)
00264 {
00265 $query = "SELECT points FROM crs_objective_results ".
00266 "WHERE usr_id = '".$this->getUserId()."' ".
00267 "AND question_id = '".$qid."'";
00268
00269 $res = $this->db->query($query);
00270 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00271 {
00272 $points += ((int) $row->points);
00273 }
00274 }
00275 return $points ? $points : 0;
00276 }
00277
00278 function __isAnswered($a_question_ids)
00279 {
00280 foreach($a_question_ids as $qid)
00281 {
00282
00283 $query = "SELECT points FROM crs_objective_results ".
00284 "WHERE usr_id = '".$this->getUserId()."' ".
00285 "AND question_id = '".$qid."'";
00286
00287 $res = $this->db->query($query);
00288 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00289 {
00290 return true;
00291 }
00292 }
00293 return false;
00294 }
00295
00296 function _updateUserResult($a_usr_id,$a_question_id,$a_points)
00297 {
00298 global $ilDB;
00299
00300
00301 $query = "DELETE FROM crs_objective_results ".
00302 "WHERE usr_id = '".$a_usr_id."' ".
00303 "AND question_id = '".$a_question_id."'";
00304
00305 $ilDB->query($query);
00306
00307
00308 $query = "INSERT INTO crs_objective_results ".
00309 "SET usr_id = '".$a_usr_id."', ".
00310 "question_id = '".$a_question_id."', ".
00311 "points = '".$a_points."'";
00312
00313 $ilDB->query($query);
00314
00315 return true;
00316 }
00317
00318
00319
00320 function addEntry($a_question_id,$a_points)
00321 {
00322
00323 $query = "DELETE FROM crs_objective_results ".
00324 "WHERE usr_id = '".$this->getUserId()."' ".
00325 "AND question_id = '".$a_question_id."'";
00326
00327 $this->db->query($query);
00328
00329 $query = "INSERT INTO crs_objective_results ".
00330 "SET usr_id = '".$this->getUserId()."', ".
00331 "question_id = '".$a_question_id."', ".
00332 "points = '".$a_points."'";
00333
00334 $this->db->query($query);
00335
00336 return true;
00337 }
00338
00339
00340 function _deleteAll($user_id)
00341 {
00342 global $ilDB;
00343
00344 $query = "DELETE FROM crs_objective_results ".
00345 "WHERE usr_id = '".$user_id."'";
00346
00347 $ilDB->query($query);
00348
00349 return true;
00350 }
00351 }
00352 ?>