ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilCourseObjectiveQuestion.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24
35{
37 const TYPE_FINAL_TEST = 1;
38
39 public $db = null;
40
41 public $objective_id = null;
42 public $questions;
43 protected $tests = array();
44
50 public function __construct($a_objective_id)
51 {
52 global $ilDB;
53
54 $this->db = $ilDB;
55
56 $this->objective_id = $a_objective_id;
57
58 $this->__read();
59 }
60
61
69 public static function lookupObjectivesOfQuestion($a_qid)
70 {
71 global $ilDB;
72
73 $query = 'SELECT objective_id FROM crs_objective_qst '.
74 'WHERE question_id = '.$ilDB->quote($a_qid,'integer');
75 $res = $ilDB->query($query);
76 $objectiveIds = array();
77 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
78 {
79 $objectiveIds[] = $row->objective_id;
80 }
81 return $objectiveIds;
82 }
83
94 public static function _isTestAssignedToObjective($a_test_id,$a_objective_id)
95 {
96 global $ilDB;
97
98 $query = "SELECT qst_ass_id FROM crs_objective_qst ".
99 "WHERE ref_id = ".$ilDB->quote($a_test_id ,'integer')." ".
100 "AND objective_id = ".$ilDB->quote($a_objective_id ,'integer');
101 $res = $ilDB->query($query);
102 return $res->numRows() ? true : false;
103 }
104
114 public function cloneDependencies($a_new_objective,$a_copy_id)
115 {
116 global $ilObjDataCache,$ilLog,$ilDB;
117
118 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
119 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
120 $mappings = $cwo->getMappings();
121 foreach($this->getQuestions() as $question)
122 {
123 $mapping_key = $question['ref_id'].'_question_'.$question['question_id'];
124 if(!isset($mappings[$mapping_key]) or !$mappings[$mapping_key])
125 {
126 continue;
127 }
128 $question_ref_id = $question['ref_id'];
129 $question_obj_id = $question['obj_id'];
130 $question_qst_id = $question['question_id'];
131 $new_ref_id = $mappings[$question_ref_id];
132 $new_obj_id = $ilObjDataCache->lookupObjId($new_ref_id);
133
134 if($new_obj_id == $question_obj_id)
135 {
136 ilLoggerFactory::getLogger('crs')->info('Test has been linked. Keeping question id');
137 // Object has been linked
138 $new_question_id = $question_qst_id;
139 }
140 else
141 {
142 $new_question_info = $mappings[$question_ref_id.'_question_'.$question_qst_id];
143 $new_question_arr = explode('_',$new_question_info);
144 if(!isset($new_question_arr[2]) or !$new_question_arr[2])
145 {
146 ilLoggerFactory::getLogger('crs')->debug('found invalid format of question id mapping: ' . print_r($new_question_arr,TRUE));
147 continue;
148 }
149 $new_question_id = $new_question_arr[2];
150 ilLoggerFactory::getLogger('crs')->info('New question id is: '.$new_question_id);
151 }
152
153 ilLoggerFactory::getLogger('crs')->debug('Copying question assignments');
154 $new_question = new ilCourseObjectiveQuestion($a_new_objective);
155 $new_question->setTestRefId($new_ref_id);
156 $new_question->setTestObjId($new_obj_id);
157 $new_question->setQuestionId($new_question_id);
158 $new_question->add();
159 }
160
161 // Copy tests
162 foreach($this->getTests() as $test)
163 {
164 $new_test_id = $mappings["$test[ref_id]"];
165
166 $query = "UPDATE crs_objective_tst ".
167 "SET tst_status = ".$this->db->quote($test['tst_status'] ,'integer').", ".
168 "tst_limit_p = ".$this->db->quote($test['tst_limit'] ,'integer')." ".
169 "WHERE objective_id = ".$this->db->quote($a_new_objective ,'integer')." ".
170 "AND ref_id = ".$this->db->quote($new_test_id ,'integer');
171 $res = $ilDB->manipulate($query);
172 }
173 }
174
183 public static function _getAssignableTests($a_container_ref_id)
184 {
185 global $tree;
186
187 return $tree->getSubTree($tree->getNodeData($a_container_ref_id),true,'tst');
188 }
189
190 // ######################################################## Methods for test table
191 function setTestStatus($a_status)
192 {
193 $this->tst_status = $a_status;
194 }
195 function getTestStatus()
196 {
197 return (int) $this->tst_status;
198 }
199 function setTestSuggestedLimit($a_limit)
200 {
201 $this->tst_limit = $a_limit;
202 }
204 {
205 return (int) $this->tst_limit;
206 }
207 function __addTest()
208 {
209 global $ilDB;
210
211 $query = "UPDATE crs_objective_tst ".
212 "SET tst_status = ".$this->db->quote($this->getTestStatus() ,'integer')." ".
213 "WHERE objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
214 "AND ref_id = ".$this->db->quote($this->getTestRefId() ,'integer')." ";
215 $res = $ilDB->manipulate($query);
216
217
218 // CHECK if entry already exists
219 $query = "SELECT * FROM crs_objective_tst ".
220 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
221 "AND ref_id = ".$ilDB->quote($this->getTestRefId() ,'integer')."";
222
223 $res = $this->db->query($query);
224 if($res->numRows())
225 {
226 return false;
227 }
228
229 // Check for existing limit
230 $query = "SELECT tst_limit_p FROM crs_objective_tst ".
231 "WHERE objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
232 "AND tst_status = ".$this->db->quote($this->getTestStatus() ,'integer')." ";
233
234 $res = $this->db->query($query);
235
236 $limit = 100;
237 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
238 {
239 $limit = $row->tst_limit_p;
240 }
241
242 $next_id = $ilDB->nextId('crs_objective_tst');
243 $query = "INSERT INTO crs_objective_tst (test_objective_id,objective_id,ref_id,obj_id,tst_status,tst_limit_p) ".
244 "VALUES( ".
245 $ilDB->quote($next_id,'integer').", ".
246 $ilDB->quote($this->getObjectiveId() ,'integer').", ".
247 $ilDB->quote($this->getTestRefId() ,'integer').", ".
248 $ilDB->quote($this->getTestObjId() ,'integer').", ".
249 $ilDB->quote($this->getTestStatus() ,'integer').", ".
250 $this->db->quote($limit ,'integer')." ".
251 ")";
252 $res = $ilDB->manipulate($query);
253
254 return true;
255 }
256
257 function __deleteTest($a_test_ref_id)
258 {
259 global $ilDB;
260
261 // Delete questions
262 $query = "DELETE FROM crs_objective_qst ".
263 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
264 "AND ref_id = ".$ilDB->quote($a_test_ref_id ,'integer')." ";
265 $res = $ilDB->manipulate($query);
266
267 // delete tst entries
268 $query = "DELETE FROM crs_objective_tst ".
269 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
270 "AND ref_id = ".$ilDB->quote($a_test_ref_id ,'integer')." ";
271 $res = $ilDB->manipulate($query);
272
273 unset($this->tests[$a_test_ref_id]);
274
275 return true;
276 }
277
288 public static function _updateTestLimits($a_objective_id,$a_status,$a_limit)
289 {
290 global $ilDB;
291
292 $query = "UPDATE crs_objective_tst ".
293 "SET tst_limit_p = ".$ilDB->quote($a_limit ,'integer')." ".
294 "WHERE tst_status = ".$ilDB->quote($a_status ,'integer')." ".
295 "AND objective_id = ".$ilDB->quote($a_objective_id ,'integer');
296 $res = $ilDB->manipulate($query);
297 return true;
298 }
299
300 function updateTest($a_objective_id)
301 {
302 global $ilDB;
303
304 $query = "UPDATE crs_objective_tst ".
305 "SET tst_status = ".$ilDB->quote($this->getTestStatus() ,'integer').", ".
306 "tst_limit_p = ".$ilDB->quote($this->getTestSuggestedLimit() ,'integer')." ".
307 "WHERE test_objective_id = ".$ilDB->quote($a_objective_id ,'integer')."";
308 $res = $ilDB->manipulate($query);
309
310 return true;
311 }
312
313 function getTests()
314 {
315 global $ilDB;
316
317 $query = "SELECT * FROM crs_objective_tst cot ".
318 "JOIN object_data obd ON cot.obj_id = obd.obj_id ".
319 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
320 "ORDER BY title ";
321
322 $res = $this->db->query($query);
323 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
324 {
325 $test['test_objective_id'] = $row->test_objective_id;
326 $test['objective_id'] = $row->objective_id;
327 $test['ref_id'] = $row->ref_id;
328 $test['obj_id'] = $row->obj_id;
329 $test['tst_status'] = $row->tst_status;
330 $test['tst_limit'] = $row->tst_limit_p;
331 $test['title'] = $row->title;
332
333 $tests[] = $test;
334 }
335
336 return $tests ? $tests : array();
337 }
338
346 public function getSelfAssessmentTests()
347 {
348 foreach($this->tests as $test)
349 {
350 if($test['status'] == self::TYPE_SELF_ASSESSMENT)
351 {
352 $self[] = $test;
353 }
354 }
355 return $self ? $self : array();
356 }
357
364 public function getFinalTests()
365 {
366 foreach($this->tests as $test)
367 {
368 if($test['status'] == self::TYPE_FINAL_TEST)
369 {
370 $final[] = $test;
371 }
372 }
373 return $final ? $final : array();
374 }
375
376 public static function _getTest($a_test_objective_id)
377 {
378 global $ilDB;
379
380 $query = "SELECT * FROM crs_objective_tst ".
381 "WHERE test_objective_id = ".$ilDB->quote($a_test_objective_id ,'integer')." ";
382
383 $res = $ilDB->query($query);
384 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
385 {
386 $test['test_objective_id'] = $row->test_objective_id;
387 $test['objective_id'] = $row->objective_id;
388 $test['ref_id'] = $row->ref_id;
389 $test['obj_id'] = $row->obj_id;
390 $test['tst_status'] = $row->tst_status;
391 $test['tst_limit'] = $row->tst_limit_p;
392 }
393
394 return $test ? $test : array();
395 }
396
397 // ############################################################# METHODS for question table
398 function getQuestions()
399 {
400 return $this->questions ? $this->questions : array();
401 }
402
410 {
411 foreach($this->questions as $question)
412 {
413 if($question['test_type'] == self::TYPE_SELF_ASSESSMENT)
414 {
415 $self[] = $question;
416 }
417 }
418 return $self ? $self : array();
419 }
420
427 public function getSelfAssessmentPoints()
428 {
429 foreach($this->getSelfAssessmentQuestions() as $question)
430 {
431 $points += $question['points'];
432 }
433 return $points ? $points : 0;
434 }
435
442 public function getFinalTestPoints()
443 {
444 foreach($this->getFinalTestQuestions() as $question)
445 {
446 $points += $question['points'];
447 }
448 return $points ? $points : 0;
449 }
450
457 public function isSelfAssessmentQuestion($a_question_id)
458 {
459 foreach($this->questions as $question)
460 {
461 if($question['question_id'] == $a_question_id)
462 {
463 return $question['test_type'] == self::TYPE_SELF_ASSESSMENT;
464 }
465 }
466 return false;
467 }
468
476 public function isFinalTestQuestion($a_question_id)
477 {
478 foreach($this->questions as $question)
479 {
480 if($question['question_id'] == $a_question_id)
481 {
482 return $question['test_type'] == self::TYPE_FINAL_TEST;
483 }
484 }
485 return false;
486
487 }
488
495 public function getFinalTestQuestions()
496 {
497 foreach($this->questions as $question)
498 {
499 if($question['test_type'] == self::TYPE_FINAL_TEST)
500 {
501 $final[] = $question;
502 }
503 }
504 return $final ? $final : array();
505 }
506
507
508
516 public function getQuestionsOfTest($a_test_id)
517 {
518 foreach($this->getQuestions() as $qst)
519 {
520 if($a_test_id == $qst['obj_id'])
521 {
522 $questions[] = $qst;
523 }
524 }
525 return $questions ? $questions : array();
526 }
527
528 function getQuestion($question_id)
529 {
530 return $this->questions[$question_id] ? $this->questions[$question_id] : array();
531 }
532
533 function getObjectiveId()
534 {
535 return $this->objective_id;
536 }
537
538 function setTestRefId($a_ref_id)
539 {
540 $this->tst_ref_id = $a_ref_id;
541 }
542 function getTestRefId()
543 {
544 return $this->tst_ref_id ? $this->tst_ref_id : 0;
545 }
546 function setTestObjId($a_obj_id)
547 {
548 $this->tst_obj_id = $a_obj_id;
549 }
550 function getTestObjId()
551 {
552 return $this->tst_obj_id ? $this->tst_obj_id : 0;
553 }
554 function setQuestionId($a_question_id)
555 {
556 $this->question_id = $a_question_id;
557 }
558 function getQuestionId()
559 {
560 return $this->question_id;
561 }
562
563
565 {
566 include_once './Modules/Test/classes/class.ilObjTest.php';
567
568 $points = 0;
569 foreach($this->getQuestions() as $question)
570 {
571 $tmp_test =& ilObjectFactory::getInstanceByRefId($question['ref_id']);
572
573 $tmp_question =& ilObjTest::_instanciateQuestion($question['question_id']);
574
575 $points += $tmp_question->getMaximumPoints();
576
577 unset($tmp_question);
578 unset($tmp_test);
579 }
580 return $points;
581 }
582
583 function getMaxPointsByTest($a_test_ref_id)
584 {
585 $points = 0;
586
587 $tmp_test =& ilObjectFactory::getInstanceByRefId($a_test_ref_id);
588
589 foreach($this->getQuestions() as $question)
590 {
591 if($question['ref_id'] == $a_test_ref_id)
592 {
593 $tmp_question =& ilObjTest::_instanciateQuestion($question['question_id']);
594
595 $points += $tmp_question->getMaximumPoints();
596
597 unset($tmp_question);
598 }
599 }
600 unset($tmp_test);
601
602 return $points;
603 }
604
613 public static function _lookupMaximumPointsOfQuestion($a_question_id)
614 {
615 include_once('Modules/TestQuestionPool/classes/class.assQuestion.php');
616 return assQuestion::_getMaximumPoints($a_question_id);
617 }
618
619
620 function getNumberOfQuestionsByTest($a_test_ref_id)
621 {
622 $counter = 0;
623
624 foreach($this->getQuestions() as $question)
625 {
626 if($question['ref_id'] == $a_test_ref_id)
627 {
628 ++$counter;
629 }
630 }
631 return $counter;
632 }
633
634 function getQuestionsByTest($a_test_ref_id)
635 {
636 foreach($this->getQuestions() as $question)
637 {
638 if($question['ref_id'] == $a_test_ref_id)
639 {
640 $qst[] = $question['question_id'];
641 }
642 }
643 return $qst ? $qst : array();
644 }
645
653 public function updateLimits()
654 {
655 global $ilDB;
656
657 foreach($this->tests as $ref_id => $test_data)
658 {
659 switch($test_data['status'])
660 {
662 $points = $this->getSelfAssessmentPoints();
663 break;
664
666 $points = $this->getFinalTestPoints();
667 break;
668 }
669 if($test_data['limit'] == -1 or $test_data['limit'] > $points)
670 {
671 switch($test_data['status'])
672 {
674 $points = $this->getSelfAssessmentPoints();
675 break;
676
678 $points = $this->getFinalTestPoints();
679 break;
680 }
681 $query = "UPDATE crs_objective_tst ".
682 "SET tst_limit = ".$this->db->quote($points ,'integer')." ".
683 "WHERE test_objective_id = ".$this->db->quote($test_data['test_objective_id'] ,'integer')." ";
684 $res = $ilDB->manipulate($query);
685 }
686 }
687 }
688
689
690 function add()
691 {
692 global $ilDB;
693
694 $query = "DELETE FROM crs_objective_qst ".
695 "WHERE objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
696 "AND question_id = ".$this->db->quote($this->getQuestionId() ,'integer')." ";
697 $res = $ilDB->manipulate($query);
698
699 $next_id = $ilDB->nextId('crs_objective_qst');
700 $query = "INSERT INTO crs_objective_qst (qst_ass_id, objective_id,ref_id,obj_id,question_id) ".
701 "VALUES( ".
702 $ilDB->quote($next_id,'integer').", ".
703 $ilDB->quote($this->getObjectiveId() ,'integer').", ".
704 $ilDB->quote($this->getTestRefId() ,'integer').", ".
705 $ilDB->quote($this->getTestObjId() ,'integer').", ".
706 $ilDB->quote($this->getQuestionId() ,'integer').
707 ")";
708 $res = $ilDB->manipulate($query);
709
710 $this->__addTest();
711
712 $this->__read();
713
714 return true;
715 }
716 function delete($qst_id)
717 {
718 global $ilDB;
719
720 if(!$qst_id)
721 {
722 return false;
723 }
724
725 $query = "SELECT * FROM crs_objective_qst ".
726 "WHERE qst_ass_id = ".$ilDB->quote($qst_id ,'integer')." ";
727
728 $res = $this->db->query($query);
729 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
730 {
731 $test_rid = $row->ref_id;
732 $test_oid = $row->obj_id;
733 }
734
735 $query = "DELETE FROM crs_objective_qst ".
736 "WHERE qst_ass_id = ".$ilDB->quote($qst_id ,'integer')." ";
737 $res = $ilDB->manipulate($query);
738
739 // delete test if it was the last question
740 $query = "SELECT * FROM crs_objective_qst ".
741 "WHERE ref_id = ".$ilDB->quote($test_rid ,'integer')." ".
742 "AND obj_id = ".$ilDB->quote($test_oid ,'integer')." ".
743 "AND objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
744
745 $res = $this->db->query($query);
746 if(!$res->numRows())
747 {
748 $this->__deleteTest($test_rid);
749 }
750
751 return true;
752 }
753
754 // begin-patch lok
755 public static function deleteTest($a_tst_ref_id)
756 {
757 global $ilDB;
758
759 $query = 'DELETE FROM crs_objective_tst '.
760 'WHERE ref_id = '.$ilDB->quote($a_tst_ref_id,'integer');
761 $ilDB->manipulate($query);
762
763 $query = 'DELETE FROM crs_objective_qst '.
764 'WHERE ref_id = '.$ilDB->quote($a_tst_ref_id,'integer');
765 $ilDB->manipulate($query);
766 }
767
768
769 public function deleteByTestType($a_type)
770 {
771 global $ilDB;
772
773
774 // Read tests by type
775 $deletable_refs = array();
776 foreach((array) $this->tests as $tst_data)
777 {
778 if($tst_data['status'] == $a_type)
779 {
780 $deletable_refs[] = $tst_data['ref_id'];
781 }
782 }
783
784 $query = 'DELETE from crs_objective_tst '.
785 'WHERE objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer').' '.
786 'AND tst_status = '.$ilDB->quote($a_type,'integer');
787 $ilDB->manipulate($query);
788
789
790 $query = 'DELETE from crs_objective_tst '.
791 'WHERE objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer').' '.
792 'AND '.$ilDB->in('ref_id',$deletable_refs,false,'integer');
793 $ilDB->manipulate($query);
794
795 return true;
796 }
797 // end-patch lok
798
799
800 function deleteAll()
801 {
802 global $ilDB;
803
804 $query = "DELETE FROM crs_objective_qst ".
805 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
806 $res = $ilDB->manipulate($query);
807
808 $query = "DELETE FROM crs_objective_tst ".
809 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
810 $res = $ilDB->manipulate($query);
811
812 return true;
813 }
814
815
816 // PRIVATE
817 function __read()
818 {
819 global $ilDB,$tree;
820
821 include_once './Modules/Test/classes/class.ilObjTest.php';
822 include_once('Modules/Course/classes/class.ilCourseObjective.php');
823
825 $container_ref_id = current($container_ref_ids);
826
827 // Read test data
828 $query = "SELECT * FROM crs_objective_tst ".
829 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
830 $res = $this->db->query($query);
831 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
832 {
833 $this->tests[$row->ref_id]['test_objective_id'] = $row->test_objective_id;
834 $this->tests[$row->ref_id]['ref_id'] = $row->ref_id;
835 $this->tests[$row->ref_id]['obj_id'] = $row->obj_id;
836 $this->tests[$row->ref_id]['status'] = $row->tst_status;
837 $this->tests[$row->ref_id]['limit'] = $row->tst_limit_p;
838 }
839
840 $this->questions = array();
841 $query = "SELECT * FROM crs_objective_qst coq ".
842 "JOIN qpl_questions qq ON coq.question_id = qq.question_id ".
843 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
844 "ORDER BY title";
845
846 $res = $this->db->query($query);
847 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
848 {
849 if(!$tree->isInTree($row->ref_id) or !$tree->isGrandChild($container_ref_id,$row->ref_id))
850 {
851 $this->__deleteTest($row->ref_id);
852 continue;
853 }
854 if(!$question = ilObjTest::_instanciateQuestion($row->question_id))
855 {
856 $this->delete($row->question_id);
857 continue;
858 }
859
860 $qst['ref_id'] = $row->ref_id;
861 $qst['obj_id'] = $row->obj_id;
862 $qst['question_id'] = $row->question_id;
863 $qst['qst_ass_id'] = $row->qst_ass_id;
864 $qst['title'] = $question->getTitle();
865 $qst['description'] = $question->getComment();
866 $qst['test_type'] = $this->tests[$row->ref_id]['status'];
867 $qst['points'] = $question->getPoints();
868
869 $this->questions[$row->qst_ass_id] = $qst;
870 }
871
872 return true;
873 }
874
875 // STATIC
883 public static function _hasTests($a_course_id)
884 {
885 global $ilDB;
886
887 $query = "SELECT co.objective_id FROM crs_objectives co JOIN ".
888 "crs_objective_tst cot ON co.objective_id = cot.objective_id ".
889 "WHERE crs_id = ".$ilDB->quote($a_course_id ,'integer')." ";
890 $res = $ilDB->query($query);
891 return $res->numRows() ? true : false;
892 }
893
894
895 static function _isAssigned($a_objective_id,$a_tst_ref_id,$a_question_id)
896 {
897 global $ilDB;
898
899 $query = "SELECT crs_qst.objective_id objective_id FROM crs_objective_qst crs_qst, crs_objectives crs_obj ".
900 "WHERE crs_qst.objective_id = crs_obj.objective_id ".
901 "AND crs_qst.objective_id = ".$ilDB->quote($a_objective_id ,'integer') ." ".
902 "AND ref_id = ".$ilDB->quote($a_tst_ref_id ,'integer')." ".
903 "AND question_id = ".$ilDB->quote($a_question_id ,'integer')." ";
904
905 $res = $ilDB->query($query);
906 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
907 {
908 $objective_id = $row->objective_id;
909 }
910
911 return $objective_id ? $objective_id : 0;
912 }
913
914 // begin-patch lok
915 public static function lookupQuestionsByObjective($a_test_id, $a_objective)
916 {
917 global $ilDB;
918
919 $query = 'SELECT question_id FROM crs_objective_qst '.
920 'WHERE objective_id = '.$ilDB->quote($a_objective,'integer').' '.
921 'AND obj_id = '.$ilDB->quote($a_test_id,'integer');
922 $res = $ilDB->query($query);
923
924 $questions = array();
925 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
926 {
927 $questions[] = $row->question_id;
928 }
929 return (array) $questions;
930 }
931
932 public static function loookupTestLimit($a_test_id, $a_objective_id)
933 {
934 global $ilDB;
935
936 $query = 'SELECT tst_limit_p FROM crs_objective_tst '.
937 'WHERE objective_id = '.$ilDB->quote($a_objective_id,'integer').' '.
938 'AND obj_id = '.$ilDB->quote($a_test_id,'integer');
939 $res = $ilDB->query($query);
940 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
941 {
942 return (int) $row->tst_limit_p;
943 }
944 return 0;
945 }
946
951 public function toXml(ilXmlWriter $writer)
952 {
953 foreach($this->getTests() as $test)
954 {
955 include_once './Modules/Course/classes/Objectives/class.ilLOXmlWriter.php';
956 $writer->xmlStartTag(
957 'Test',
958 array(
960 'refId' => $test['ref_id'],
961 'testType' => $test['tst_status'],
962 'limit' => $test['tst_limit']
963 )
964 );
965
966 // questions
967 foreach($this->getQuestionsByTest($test['ref_id']) as $question_id)
968 {
969 $writer->xmlElement('Question', array('id' => $question_id));
970 }
971 $writer->xmlEndTag('Test');
972 }
973
974 }
975
976 // end-patch lok
977
978}
979?>
$test
Definition: Utf8Test.php:84
An exception for terminatinating execution or to throw for unit testing.
static _getMaximumPoints($question_id)
Returns the maximum points, a learner can reach answering the question.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
class ilcourseobjectiveQuestion
cloneDependencies($a_new_objective, $a_copy_id)
clone objective questions
isFinalTestQuestion($a_question_id)
is final test question
getQuestionsOfTest($a_test_id)
Get questions of test.
getFinalTestQuestions()
get final test questions
static _getTest($a_test_objective_id)
getSelfAssessmentTests()
get self assessment tests
__construct($a_objective_id)
Constructor @global type $ilDB.
static lookupObjectivesOfQuestion($a_qid)
Lookup objective for test question @global type $ilDB.
static lookupQuestionsByObjective($a_test_id, $a_objective)
static _updateTestLimits($a_objective_id, $a_status, $a_limit)
update test limits
static _isAssigned($a_objective_id, $a_tst_ref_id, $a_question_id)
getSelfAssessmentPoints()
get self assessment points
getSelfAssessmentQuestions()
get self assessment questions
static _lookupMaximumPointsOfQuestion($a_question_id)
lookup maximimum point
static _hasTests($a_course_id)
@access public
static loookupTestLimit($a_test_id, $a_objective_id)
static _getAssignableTests($a_container_ref_id)
Get assignable tests.
isSelfAssessmentQuestion($a_question_id)
check if question is self assessment question
static _isTestAssignedToObjective($a_test_id, $a_objective_id)
Check if test is assigned to objective.
static _lookupContainerIdByObjectiveId($a_objective_id)
Get container of object.
static getLogger($a_component_id)
Get component logger.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getAllReferences($a_id)
get all reference ids of object
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
$counter
const TYPE_SELF_ASSESSMENT
$ref_id
Definition: sahs_server.php:39
global $ilDB
$a_type
Definition: workflow.php:93