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
00148 $tmp_obj_question =& new ilCourseObjectiveQuestion($a_objective_id);
00149
00150 foreach($tmp_obj_question->getTests() as $test_data)
00151 {
00152 $tmp_points = $this->__getReachedPoints($tmp_obj_question->getQuestionsByTest($test_data['ref_id']));
00153 $max = $tmp_obj_question->getMaxPointsByTest($test_data['ref_id']);
00154 if(!$max)
00155 {
00156 return false;
00157 }
00158 if($test_data['tst_status'])
00159 {
00160 if(ilObjTest::_hasFinished($this->getUserId(),$test_data['obj_id']))
00161 {
00162 return true;
00163 }
00164 continue;
00165 }
00166 if(!$tmp_points)
00167 {
00168 $suggested = true;
00169 continue;
00170 }
00171 $percent = ($tmp_points / $max) * 100.0;
00172
00173 if($percent < $test_data['tst_limit'])
00174 {
00175 $suggested = true;
00176 }
00177 else
00178 {
00179 $suggested = false;
00180 }
00181 }
00182 return $suggested;
00183 }
00184
00185
00186 function hasAccomplishedObjective($a_objective_id)
00187 {
00188 $reached = 0;
00189 $accomplished = true;
00190
00191 include_once './course/classes/class.ilCourseObjectiveQuestion.php';
00192
00193 $tmp_obj_question =& new ilCourseObjectiveQuestion($a_objective_id);
00194
00195 foreach($tmp_obj_question->getTests() as $test_data)
00196 {
00197 $tmp_points = $this->__getReachedPoints($tmp_obj_question->getQuestionsByTest($test_data['ref_id']));
00198
00199 $max = $tmp_obj_question->getMaxPointsByTest($test_data['ref_id']);
00200
00201 if(!$max)
00202 {
00203 continue;
00204 }
00205 if(!$tmp_points)
00206 {
00207 if($test_data['tst_status'])
00208 {
00209 return false;
00210 }
00211 else
00212 {
00213 $accomplished = false;
00214 continue;
00215 }
00216 }
00217
00218 $percent = ($tmp_points / $max) * 100.0;
00219
00220 if($percent >= $test_data['tst_limit'] and $test_data['tst_status'])
00221 {
00222 return true;
00223 }
00224
00225 if($test_data['tst_status'])
00226 {
00227 return false;
00228 }
00229 $accomplished = false;
00230
00231 }
00232 return $accomplished ? true : false;
00233 }
00234
00235
00236
00237 function __deleteEntries($a_objective_ids)
00238 {
00239 if(!count($a_objective_ids))
00240 {
00241 return true;
00242 }
00243 $in = "IN ('";
00244 $in .= implode("','",$a_objective_ids);
00245 $in .= "')";
00246
00247 $query = "DELETE FROM crs_objective_results ".
00248 "WHERE usr_id = '".$this->getUserId()."' ".
00249 "AND question_id ".$in;
00250
00251 $this->db->query($query);
00252
00253
00254 }
00255
00256
00257 function __getReachedPoints($a_question_ids)
00258 {
00259 $points = 0;
00260
00261 foreach($a_question_ids as $qid)
00262 {
00263 $query = "SELECT points FROM crs_objective_results ".
00264 "WHERE usr_id = '".$this->getUserId()."' ".
00265 "AND question_id = '".$qid."'";
00266
00267 $res = $this->db->query($query);
00268 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00269 {
00270 $points += ((int) $row->points);
00271 }
00272 }
00273 return $points ? $points : 0;
00274 }
00275
00276 function __isAnswered($a_question_ids)
00277 {
00278 foreach($a_question_ids as $qid)
00279 {
00280
00281 $query = "SELECT points FROM crs_objective_results ".
00282 "WHERE usr_id = '".$this->getUserId()."' ".
00283 "AND question_id = '".$qid."'";
00284
00285 $res = $this->db->query($query);
00286 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00287 {
00288 return true;
00289 }
00290 }
00291 return false;
00292 }
00293
00294 function _updateUserResult($a_usr_id,$a_question_id,$a_points)
00295 {
00296 global $ilDB;
00297
00298
00299 $query = "DELETE FROM crs_objective_results ".
00300 "WHERE usr_id = '".$a_usr_id."' ".
00301 "AND question_id = '".$a_question_id."'";
00302
00303 $ilDB->query($query);
00304
00305
00306 $query = "INSERT INTO crs_objective_results ".
00307 "SET usr_id = '".$a_usr_id."', ".
00308 "question_id = '".$a_question_id."', ".
00309 "points = '".$a_points."'";
00310
00311 $ilDB->query($query);
00312
00313 return true;
00314 }
00315
00316
00317
00318 function addEntry($a_question_id,$a_points)
00319 {
00320
00321 $query = "DELETE FROM crs_objective_results ".
00322 "WHERE usr_id = '".$this->getUserId()."' ".
00323 "AND question_id = '".$a_question_id."'";
00324
00325 $this->db->query($query);
00326
00327 $query = "INSERT INTO crs_objective_results ".
00328 "SET usr_id = '".$this->getUserId()."', ".
00329 "question_id = '".$a_question_id."', ".
00330 "points = '".$a_points."'";
00331
00332 $this->db->query($query);
00333
00334 return true;
00335 }
00336
00337
00338 function _deleteAll($user_id)
00339 {
00340 global $ilDB;
00341
00342 $query = "DELETE FROM crs_objective_results ".
00343 "WHERE usr_id = '".$user_id."'";
00344
00345 $ilDB->query($query);
00346
00347 return true;
00348 }
00349 }
00350 ?>