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
00034 class ilCourseObjectiveQuestion
00035 {
00036 var $db = null;
00037
00038 var $objective_id = null;
00039 var $questions;
00040
00041 function ilCourseObjectiveQuestion($a_objective_id)
00042 {
00043 global $ilDB;
00044
00045 $this->db =& $ilDB;
00046
00047 $this->objective_id = $a_objective_id;
00048
00049 $this->__read();
00050 }
00051
00052
00063 public static function _isTestAssignedToObjective($a_test_id,$a_objective_id)
00064 {
00065 global $ilDB;
00066
00067 $query = "SELECT qst_ass_id FROM crs_objective_qst ".
00068 "WHERE ref_id = ".$ilDB->quote($a_test_id)." ".
00069 "AND objective_id = ".$ilDB->quote($a_objective_id);
00070 $res = $ilDB->query($query);
00071 return $res->numRows() ? true : false;
00072 }
00073
00083 public function cloneDependencies($a_new_objective,$a_copy_id)
00084 {
00085 global $ilObjDataCache,$ilLog;
00086
00087 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
00088 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
00089 $mappings = $cwo->getMappings();
00090 foreach($this->getQuestions() as $question)
00091 {
00092 if(!isset($mappings["$question[ref_id]"]) or !$mappings["$question[ref_id]"])
00093 {
00094 continue;
00095 }
00096 $question_ref_id = $question['ref_id'];
00097 $question_obj_id = $question['obj_id'];
00098 $question_qst_id = $question['question_id'];
00099 $new_ref_id = $mappings[$question_ref_id];
00100 $new_obj_id = $ilObjDataCache->lookupObjId($new_ref_id);
00101
00102 if($new_obj_id == $question_obj_id)
00103 {
00104 $ilLog->write(__METHOD__.': Test has been linked. Keeping question id.');
00105
00106 $new_question_id = $question_qst_id;
00107 }
00108 else
00109 {
00110 $new_question_info = $mappings[$question_ref_id.'_'.$question_qst_id];
00111 $new_question_arr = explode('_',$new_question_info);
00112 if(!isset($new_question_arr[1]) or !$new_question_arr[1])
00113 {
00114 continue;
00115 }
00116 $new_question_id = $new_question_arr[1];
00117 $ilLog->write(__METHOD__.': New question id is: '.$new_question_id);
00118 }
00119
00120 $new_question = new ilCourseObjectiveQuestion($a_new_objective);
00121 $new_question->setTestRefId($new_ref_id);
00122 $new_question->setTestObjId($new_obj_id);
00123 $new_question->setQuestionId($new_question_id);
00124 $new_question->add();
00125 }
00126
00127
00128 foreach($this->getTests() as $test)
00129 {
00130 $new_test_id = $mappings["$test[ref_id]"];
00131
00132 $query = "UPDATE crs_objective_tst ".
00133 "SET tst_status = ".$this->db->quote($test['tst_status']).", ".
00134 "tst_limit = ".$this->db->quote($test['tst_limit'])." ".
00135 "WHERE objective_id = ".$this->db->quote($a_new_objective)." ".
00136 "AND ref_id = ".$this->db->quote($new_test_id);
00137 $this->db->query($query);
00138 }
00139 }
00140
00149 public static function _getAssignableTests($a_container_ref_id)
00150 {
00151 global $tree;
00152
00153 return $tree->getSubTree($tree->getNodeData($a_container_ref_id),true,'tst');
00154 }
00155
00156
00157 function setTestStatus($a_status)
00158 {
00159 $this->tst_status = $a_status;
00160 }
00161 function getTestStatus()
00162 {
00163 return (int) $this->tst_status;
00164 }
00165 function setTestSuggestedLimit($a_limit)
00166 {
00167 $this->tst_limit = $a_limit;
00168 }
00169 function getTestSuggestedLimit()
00170 {
00171 return (int) $this->tst_limit;
00172 }
00173 function __addTest()
00174 {
00175 global $ilDB;
00176
00177
00178 $query = "SELECT * FROM crs_objective_tst ".
00179 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00180 "AND ref_id = ".$ilDB->quote($this->getTestRefId())."";
00181
00182 $res = $this->db->query($query);
00183 if($res->numRows())
00184 {
00185 return false;
00186 }
00187 $query = "INSERT INTO crs_objective_tst ".
00188 "SET objective_id = ".$ilDB->quote($this->getObjectiveId()).", ".
00189 "ref_id = ".$ilDB->quote($this->getTestRefId()).", ".
00190 "obj_id = ".$ilDB->quote($this->getTestObjId()).", ".
00191 "tst_status = ".$ilDB->quote($this->getTestStatus()).", ".
00192 "tst_limit = '100'";
00193
00194 $this->db->query($query);
00195
00196 return true;
00197 }
00198
00199 function __deleteTest($a_test_ref_id)
00200 {
00201 global $ilDB;
00202
00203
00204 $query = "DELETE FROM crs_objective_qst ".
00205 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00206 "AND ref_id = ".$ilDB->quote($a_test_ref_id)." ";
00207
00208 $this->db->query($query);
00209
00210
00211 $query = "DELETE FROM crs_objective_tst ".
00212 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00213 "AND ref_id = ".$ilDB->quote($a_test_ref_id)." ";
00214
00215 $this->db->query($query);
00216
00217 return true;
00218 }
00219
00220 function updateTest($a_test_objective_id)
00221 {
00222 global $ilDB;
00223
00224 $query = "UPDATE crs_objective_tst ".
00225 "SET tst_status = ".$ilDB->quote($this->getTestStatus()).", ".
00226 "tst_limit = ".$ilDB->quote($this->getTestSuggestedLimit())." ".
00227 "WHERE test_objective_id = ".$ilDB->quote($a_test_objective_id)."";
00228
00229 $this->db->query($query);
00230
00231 return true;
00232 }
00233
00234 function getTests()
00235 {
00236 global $ilDB;
00237
00238 $query = "SELECT * FROM crs_objective_tst as cot ".
00239 "JOIN object_data as obd ON cot.obj_id = obd.obj_id ".
00240 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00241 "ORDER BY title ";
00242
00243 $res = $this->db->query($query);
00244 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00245 {
00246 $test['test_objective_id'] = $row->test_objective_id;
00247 $test['objective_id'] = $row->objective_id;
00248 $test['ref_id'] = $row->ref_id;
00249 $test['obj_id'] = $row->obj_id;
00250 $test['tst_status'] = $row->tst_status;
00251 $test['tst_limit'] = $row->tst_limit;
00252 $test['title'] = $row->title;
00253
00254 $tests[] = $test;
00255 }
00256
00257 return $tests ? $tests : array();
00258 }
00259
00260 function _getTest($a_test_objective_id)
00261 {
00262 global $ilDB;
00263
00264 $query = "SELECT * FROM crs_objective_tst ".
00265 "WHERE test_objective_id = ".$ilDB->quote($a_test_objective_id)." ";
00266
00267 $res = $ilDB->query($query);
00268 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00269 {
00270 $test['test_objective_id'] = $row->test_objective_id;
00271 $test['objective_id'] = $row->objective_id;
00272 $test['ref_id'] = $row->ref_id;
00273 $test['obj_id'] = $row->obj_id;
00274 $test['tst_status'] = $row->tst_status;
00275 $test['tst_limit'] = $row->tst_limit;
00276 }
00277
00278 return $test ? $test : array();
00279 }
00280
00281
00282 function getQuestions()
00283 {
00284 return $this->questions ? $this->questions : array();
00285 }
00286
00294 public function getQuestionsOfTest($a_test_id)
00295 {
00296 foreach($this->getQuestions() as $qst)
00297 {
00298 if($a_test_id == $qst['obj_id'])
00299 {
00300 $questions[] = $qst;
00301 }
00302 }
00303 return $questions ? $questions : array();
00304 }
00305
00306 function getQuestion($question_id)
00307 {
00308 return $this->questions[$question_id] ? $this->questions[$question_id] : array();
00309 }
00310
00311 function getObjectiveId()
00312 {
00313 return $this->objective_id;
00314 }
00315
00316 function setTestRefId($a_ref_id)
00317 {
00318 $this->tst_ref_id = $a_ref_id;
00319 }
00320 function getTestRefId()
00321 {
00322 return $this->tst_ref_id ? $this->tst_ref_id : 0;
00323 }
00324 function setTestObjId($a_obj_id)
00325 {
00326 $this->tst_obj_id = $a_obj_id;
00327 }
00328 function getTestObjId()
00329 {
00330 return $this->tst_obj_id ? $this->tst_obj_id : 0;
00331 }
00332 function setQuestionId($a_question_id)
00333 {
00334 $this->question_id = $a_question_id;
00335 }
00336 function getQuestionId()
00337 {
00338 return $this->question_id;
00339 }
00340
00341
00342 function getMaxPointsByObjective()
00343 {
00344 include_once './Modules/Test/classes/class.ilObjTest.php';
00345
00346 $points = 0;
00347 foreach($this->getQuestions() as $question)
00348 {
00349 $tmp_test =& ilObjectFactory::getInstanceByRefId($question['ref_id']);
00350
00351 $tmp_question =& ilObjTest::_instanciateQuestion($question['question_id']);
00352
00353 $points += $tmp_question->getMaximumPoints();
00354
00355 unset($tmp_question);
00356 unset($tmp_test);
00357 }
00358 return $points;
00359 }
00360
00361 function getMaxPointsByTest($a_test_ref_id)
00362 {
00363 $points = 0;
00364
00365 $tmp_test =& ilObjectFactory::getInstanceByRefId($a_test_ref_id);
00366
00367 foreach($this->getQuestions() as $question)
00368 {
00369 if($question['ref_id'] == $a_test_ref_id)
00370 {
00371 $tmp_question =& ilObjTest::_instanciateQuestion($question['question_id']);
00372
00373 $points += $tmp_question->getMaximumPoints();
00374
00375 unset($tmp_question);
00376 }
00377 }
00378 unset($tmp_test);
00379
00380 return $points;
00381 }
00382
00383 function getNumberOfQuestionsByTest($a_test_ref_id)
00384 {
00385 $counter = 0;
00386
00387 foreach($this->getQuestions() as $question)
00388 {
00389 if($question['ref_id'] == $a_test_ref_id)
00390 {
00391 ++$counter;
00392 }
00393 }
00394 return $counter;
00395 }
00396
00397 function getQuestionsByTest($a_test_ref_id)
00398 {
00399 foreach($this->getQuestions() as $question)
00400 {
00401 if($question['ref_id'] == $a_test_ref_id)
00402 {
00403 $qst[] = $question['question_id'];
00404 }
00405 }
00406 return $qst ? $qst : array();
00407 }
00408
00409
00410 function add()
00411 {
00412 global $ilDB;
00413
00414 $query = "INSERT INTO crs_objective_qst ".
00415 "SET objective_id = ".$ilDB->quote($this->getObjectiveId()).", ".
00416 "ref_id = ".$ilDB->quote($this->getTestRefId()).", ".
00417 "obj_id = ".$ilDB->quote($this->getTestObjId()).", ".
00418 "question_id = ".$ilDB->quote($this->getQuestionId())."";
00419
00420 $this->db->query($query);
00421
00422 $this->__addTest();
00423
00424 return true;
00425 }
00426 function delete($qst_id)
00427 {
00428 global $ilDB;
00429
00430 if(!$qst_id)
00431 {
00432 return false;
00433 }
00434
00435 $query = "SELECT * FROM crs_objective_qst ".
00436 "WHERE qst_ass_id = ".$ilDB->quote($qst_id)." ";
00437
00438 $res = $this->db->query($query);
00439 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00440 {
00441 $test_rid = $row->ref_id;
00442 $test_oid = $row->obj_id;
00443 }
00444
00445 $query = "DELETE FROM crs_objective_qst ".
00446 "WHERE qst_ass_id = ".$ilDB->quote($qst_id)." ";
00447
00448 $this->db->query($query);
00449
00450
00451 $query = "SELECT * FROM crs_objective_qst ".
00452 "WHERE ref_id = ".$ilDB->quote($test_rid)." ".
00453 "AND obj_id = ".$ilDB->quote($test_oid)." ".
00454 "AND objective_id = ".$ilDB->quote($this->getObjectiveId())." ";
00455
00456
00457 $res = $this->db->query($query);
00458 if(!$res->numRows())
00459 {
00460 $this->__deleteTest($test_rid);
00461 }
00462
00463 return true;
00464 }
00465
00466 function deleteAll()
00467 {
00468 global $ilDB;
00469
00470 $query = "DELETE FROM crs_objective_qst ".
00471 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ";
00472
00473 $this->db->query($query);
00474
00475 $query = "DELETE FROM crs_objective_tst ".
00476 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ";
00477
00478 $this->db->query($query);
00479
00480 return true;
00481 }
00482
00483
00484
00485 function __read()
00486 {
00487 global $ilDB,$tree;
00488
00489 include_once './Modules/Test/classes/class.ilObjTest.php';
00490 include_once('Modules/Course/classes/class.ilCourseObjective.php');
00491
00492 $container_ref_ids = ilObject::_getAllReferences(ilCourseObjective::_lookupContainerIdByObjectiveId($this->objective_id));
00493 $container_ref_id = current($container_ref_ids);
00494
00495
00496 $this->questions = array();
00497 $query = "SELECT * FROM crs_objective_qst as coq ".
00498 "JOIN qpl_questions as qq ON coq.question_id = qq.question_id ".
00499 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00500 "ORDER BY title";
00501
00502 $res = $this->db->query($query);
00503 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00504 {
00505 if(!$tree->isInTree($row->ref_id) or !$tree->isGrandChild($container_ref_id,$row->ref_id))
00506 {
00507 $this->__deleteTest($row->ref_id);
00508 continue;
00509 }
00510 if(!$question = ilObjTest::_instanciateQuestion($row->question_id))
00511 {
00512 $this->delete($row->question_id);
00513 continue;
00514 }
00515 $qst['ref_id'] = $row->ref_id;
00516 $qst['obj_id'] = $row->obj_id;
00517 $qst['question_id'] = $row->question_id;
00518 $qst['qst_ass_id'] = $row->qst_ass_id;
00519 $qst['title'] = $question->getTitle();
00520
00521 $this->questions[$row->qst_ass_id] = $qst;
00522 }
00523 return true;
00524 }
00525
00526
00527 function _isAssigned($a_objective_id,$a_tst_ref_id,$a_question_id)
00528 {
00529 global $ilDB;
00530
00531 $query = "SELECT crs_qst.objective_id as objective_id FROM crs_objective_qst as crs_qst, crs_objectives as crs_obj ".
00532 "WHERE crs_qst.objective_id = crs_obj.objective_id ".
00533 "AND crs_qst.objective_id = ".$ilDB->quote($a_objective_id) ." ".
00534 "AND ref_id = ".$ilDB->quote($a_tst_ref_id)." ".
00535 "AND question_id = ".$ilDB->quote($a_question_id)." ";
00536
00537 $res = $ilDB->query($query);
00538 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00539 {
00540 $objective_id = $row->objective_id;
00541 }
00542
00543 return $objective_id ? $objective_id : 0;
00544 }
00545
00546 }
00547 ?>