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