ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
45  function ilCourseObjectiveQuestion($a_objective_id)
46  {
47  global $ilDB;
48 
49  $this->db =& $ilDB;
50 
51  $this->objective_id = $a_objective_id;
52 
53  $this->__read();
54  }
55 
56 
64  public static function lookupObjectivesOfQuestion($a_qid)
65  {
66  global $ilDB;
67 
68  $query = 'SELECT objective_id FROM crs_objective_qst '.
69  'WHERE question_id = '.$ilDB->quote($a_qid,'integer');
70  $res = $ilDB->query($query);
71  $objectiveIds = array();
72  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
73  {
74  $objectiveIds[] = $row->objective_id;
75  }
76  return $objectiveIds;
77  }
78 
89  public static function _isTestAssignedToObjective($a_test_id,$a_objective_id)
90  {
91  global $ilDB;
92 
93  $query = "SELECT qst_ass_id FROM crs_objective_qst ".
94  "WHERE ref_id = ".$ilDB->quote($a_test_id ,'integer')." ".
95  "AND objective_id = ".$ilDB->quote($a_objective_id ,'integer');
96  $res = $ilDB->query($query);
97  return $res->numRows() ? true : false;
98  }
99 
109  public function cloneDependencies($a_new_objective,$a_copy_id)
110  {
111  global $ilObjDataCache,$ilLog,$ilDB;
112 
113  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
114  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
115  $mappings = $cwo->getMappings();
116  foreach($this->getQuestions() as $question)
117  {
118  $mapping_key = $question['ref_id'].'_question_'.$question['question_id'];
119  if(!isset($mappings[$mapping_key]) or !$mappings[$mapping_key])
120  {
121  continue;
122  }
123  $question_ref_id = $question['ref_id'];
124  $question_obj_id = $question['obj_id'];
125  $question_qst_id = $question['question_id'];
126  $new_ref_id = $mappings[$question_ref_id];
127  $new_obj_id = $ilObjDataCache->lookupObjId($new_ref_id);
128 
129  if($new_obj_id == $question_obj_id)
130  {
131  ilLoggerFactory::getLogger('crs')->info('Test has been linked. Keeping question id');
132  // Object has been linked
133  $new_question_id = $question_qst_id;
134  }
135  else
136  {
137  $new_question_info = $mappings[$question_ref_id.'_question_'.$question_qst_id];
138  $new_question_arr = explode('_',$new_question_info);
139  if(!isset($new_question_arr[2]) or !$new_question_arr[2])
140  {
141  ilLoggerFactory::getLogger('crs')->debug('found invalid format of question id mapping: ' . print_r($new_question_arr,TRUE));
142  continue;
143  }
144  $new_question_id = $new_question_arr[2];
145  ilLoggerFactory::getLogger('crs')->info('New question id is: '.$new_question_id);
146  }
147 
148  ilLoggerFactory::getLogger('crs')->debug('Copying question assignments');
149  $new_question = new ilCourseObjectiveQuestion($a_new_objective);
150  $new_question->setTestRefId($new_ref_id);
151  $new_question->setTestObjId($new_obj_id);
152  $new_question->setQuestionId($new_question_id);
153  $new_question->add();
154  }
155 
156  // Copy tests
157  foreach($this->getTests() as $test)
158  {
159  $new_test_id = $mappings["$test[ref_id]"];
160 
161  $query = "UPDATE crs_objective_tst ".
162  "SET tst_status = ".$this->db->quote($test['tst_status'] ,'integer').", ".
163  "tst_limit_p = ".$this->db->quote($test['tst_limit'] ,'integer')." ".
164  "WHERE objective_id = ".$this->db->quote($a_new_objective ,'integer')." ".
165  "AND ref_id = ".$this->db->quote($new_test_id ,'integer');
166  $res = $ilDB->manipulate($query);
167  }
168  }
169 
178  public static function _getAssignableTests($a_container_ref_id)
179  {
180  global $tree;
181 
182  return $tree->getSubTree($tree->getNodeData($a_container_ref_id),true,'tst');
183  }
184 
185  // ######################################################## Methods for test table
186  function setTestStatus($a_status)
187  {
188  $this->tst_status = $a_status;
189  }
190  function getTestStatus()
191  {
192  return (int) $this->tst_status;
193  }
194  function setTestSuggestedLimit($a_limit)
195  {
196  $this->tst_limit = $a_limit;
197  }
199  {
200  return (int) $this->tst_limit;
201  }
202  function __addTest()
203  {
204  global $ilDB;
205 
206  $query = "UPDATE crs_objective_tst ".
207  "SET tst_status = ".$this->db->quote($this->getTestStatus() ,'integer')." ".
208  "WHERE objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
209  "AND ref_id = ".$this->db->quote($this->getTestRefId() ,'integer')." ";
210  $res = $ilDB->manipulate($query);
211 
212 
213  // CHECK if entry already exists
214  $query = "SELECT * FROM crs_objective_tst ".
215  "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
216  "AND ref_id = ".$ilDB->quote($this->getTestRefId() ,'integer')."";
217 
218  $res = $this->db->query($query);
219  if($res->numRows())
220  {
221  return false;
222  }
223 
224  // Check for existing limit
225  $query = "SELECT tst_limit_p FROM crs_objective_tst ".
226  "WHERE objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
227  "AND tst_status = ".$this->db->quote($this->getTestStatus() ,'integer')." ";
228 
229  $res = $this->db->query($query);
230 
231  $limit = 100;
232  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
233  {
234  $limit = $row->tst_limit_p;
235  }
236 
237  $next_id = $ilDB->nextId('crs_objective_tst');
238  $query = "INSERT INTO crs_objective_tst (test_objective_id,objective_id,ref_id,obj_id,tst_status,tst_limit_p) ".
239  "VALUES( ".
240  $ilDB->quote($next_id,'integer').", ".
241  $ilDB->quote($this->getObjectiveId() ,'integer').", ".
242  $ilDB->quote($this->getTestRefId() ,'integer').", ".
243  $ilDB->quote($this->getTestObjId() ,'integer').", ".
244  $ilDB->quote($this->getTestStatus() ,'integer').", ".
245  $this->db->quote($limit ,'integer')." ".
246  ")";
247  $res = $ilDB->manipulate($query);
248 
249  return true;
250  }
251 
252  function __deleteTest($a_test_ref_id)
253  {
254  global $ilDB;
255 
256  // Delete questions
257  $query = "DELETE FROM crs_objective_qst ".
258  "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
259  "AND ref_id = ".$ilDB->quote($a_test_ref_id ,'integer')." ";
260  $res = $ilDB->manipulate($query);
261 
262  // delete tst entries
263  $query = "DELETE FROM crs_objective_tst ".
264  "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
265  "AND ref_id = ".$ilDB->quote($a_test_ref_id ,'integer')." ";
266  $res = $ilDB->manipulate($query);
267 
268  unset($this->tests[$a_test_ref_id]);
269 
270  return true;
271  }
272 
283  public static function _updateTestLimits($a_objective_id,$a_status,$a_limit)
284  {
285  global $ilDB;
286 
287  $query = "UPDATE crs_objective_tst ".
288  "SET tst_limit_p = ".$ilDB->quote($a_limit ,'integer')." ".
289  "WHERE tst_status = ".$ilDB->quote($a_status ,'integer')." ".
290  "AND objective_id = ".$ilDB->quote($a_objective_id ,'integer');
291  $res = $ilDB->manipulate($query);
292  return true;
293  }
294 
295  function updateTest($a_objective_id)
296  {
297  global $ilDB;
298 
299  $query = "UPDATE crs_objective_tst ".
300  "SET tst_status = ".$ilDB->quote($this->getTestStatus() ,'integer').", ".
301  "tst_limit_p = ".$ilDB->quote($this->getTestSuggestedLimit() ,'integer')." ".
302  "WHERE test_objective_id = ".$ilDB->quote($a_objective_id ,'integer')."";
303  $res = $ilDB->manipulate($query);
304 
305  return true;
306  }
307 
308  function getTests()
309  {
310  global $ilDB;
311 
312  $query = "SELECT * FROM crs_objective_tst cot ".
313  "JOIN object_data obd ON cot.obj_id = obd.obj_id ".
314  "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
315  "ORDER BY title ";
316 
317  $res = $this->db->query($query);
318  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
319  {
320  $test['test_objective_id'] = $row->test_objective_id;
321  $test['objective_id'] = $row->objective_id;
322  $test['ref_id'] = $row->ref_id;
323  $test['obj_id'] = $row->obj_id;
324  $test['tst_status'] = $row->tst_status;
325  $test['tst_limit'] = $row->tst_limit_p;
326  $test['title'] = $row->title;
327 
328  $tests[] = $test;
329  }
330 
331  return $tests ? $tests : array();
332  }
333 
341  public function getSelfAssessmentTests()
342  {
343  foreach($this->tests as $test)
344  {
345  if($test['status'] == self::TYPE_SELF_ASSESSMENT)
346  {
347  $self[] = $test;
348  }
349  }
350  return $self ? $self : array();
351  }
352 
359  public function getFinalTests()
360  {
361  foreach($this->tests as $test)
362  {
363  if($test['status'] == self::TYPE_FINAL_TEST)
364  {
365  $final[] = $test;
366  }
367  }
368  return $final ? $final : array();
369  }
370 
371  function _getTest($a_test_objective_id)
372  {
373  global $ilDB;
374 
375  $query = "SELECT * FROM crs_objective_tst ".
376  "WHERE test_objective_id = ".$ilDB->quote($a_test_objective_id ,'integer')." ";
377 
378  $res = $ilDB->query($query);
379  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
380  {
381  $test['test_objective_id'] = $row->test_objective_id;
382  $test['objective_id'] = $row->objective_id;
383  $test['ref_id'] = $row->ref_id;
384  $test['obj_id'] = $row->obj_id;
385  $test['tst_status'] = $row->tst_status;
386  $test['tst_limit'] = $row->tst_limit_p;
387  }
388 
389  return $test ? $test : array();
390  }
391 
392  // ############################################################# METHODS for question table
393  function getQuestions()
394  {
395  return $this->questions ? $this->questions : array();
396  }
397 
404  public function getSelfAssessmentQuestions()
405  {
406  foreach($this->questions as $question)
407  {
408  if($question['test_type'] == self::TYPE_SELF_ASSESSMENT)
409  {
410  $self[] = $question;
411  }
412  }
413  return $self ? $self : array();
414  }
415 
422  public function getSelfAssessmentPoints()
423  {
424  foreach($this->getSelfAssessmentQuestions() as $question)
425  {
426  $points += $question['points'];
427  }
428  return $points ? $points : 0;
429  }
430 
437  public function getFinalTestPoints()
438  {
439  foreach($this->getFinalTestQuestions() as $question)
440  {
441  $points += $question['points'];
442  }
443  return $points ? $points : 0;
444  }
445 
452  public function isSelfAssessmentQuestion($a_question_id)
453  {
454  foreach($this->questions as $question)
455  {
456  if($question['question_id'] == $a_question_id)
457  {
458  return $question['test_type'] == self::TYPE_SELF_ASSESSMENT;
459  }
460  }
461  return false;
462  }
463 
471  public function isFinalTestQuestion($a_question_id)
472  {
473  foreach($this->questions as $question)
474  {
475  if($question['question_id'] == $a_question_id)
476  {
477  return $question['test_type'] == self::TYPE_FINAL_TEST;
478  }
479  }
480  return false;
481 
482  }
483 
490  public function getFinalTestQuestions()
491  {
492  foreach($this->questions as $question)
493  {
494  if($question['test_type'] == self::TYPE_FINAL_TEST)
495  {
496  $final[] = $question;
497  }
498  }
499  return $final ? $final : array();
500  }
501 
502 
503 
511  public function getQuestionsOfTest($a_test_id)
512  {
513  foreach($this->getQuestions() as $qst)
514  {
515  if($a_test_id == $qst['obj_id'])
516  {
517  $questions[] = $qst;
518  }
519  }
520  return $questions ? $questions : array();
521  }
522 
523  function getQuestion($question_id)
524  {
525  return $this->questions[$question_id] ? $this->questions[$question_id] : array();
526  }
527 
528  function getObjectiveId()
529  {
530  return $this->objective_id;
531  }
532 
533  function setTestRefId($a_ref_id)
534  {
535  $this->tst_ref_id = $a_ref_id;
536  }
537  function getTestRefId()
538  {
539  return $this->tst_ref_id ? $this->tst_ref_id : 0;
540  }
541  function setTestObjId($a_obj_id)
542  {
543  $this->tst_obj_id = $a_obj_id;
544  }
545  function getTestObjId()
546  {
547  return $this->tst_obj_id ? $this->tst_obj_id : 0;
548  }
549  function setQuestionId($a_question_id)
550  {
551  $this->question_id = $a_question_id;
552  }
553  function getQuestionId()
554  {
555  return $this->question_id;
556  }
557 
558 
560  {
561  include_once './Modules/Test/classes/class.ilObjTest.php';
562 
563  $points = 0;
564  foreach($this->getQuestions() as $question)
565  {
566  $tmp_test =& ilObjectFactory::getInstanceByRefId($question['ref_id']);
567 
568  $tmp_question =& ilObjTest::_instanciateQuestion($question['question_id']);
569 
570  $points += $tmp_question->getMaximumPoints();
571 
572  unset($tmp_question);
573  unset($tmp_test);
574  }
575  return $points;
576  }
577 
578  function getMaxPointsByTest($a_test_ref_id)
579  {
580  $points = 0;
581 
582  $tmp_test =& ilObjectFactory::getInstanceByRefId($a_test_ref_id);
583 
584  foreach($this->getQuestions() as $question)
585  {
586  if($question['ref_id'] == $a_test_ref_id)
587  {
588  $tmp_question =& ilObjTest::_instanciateQuestion($question['question_id']);
589 
590  $points += $tmp_question->getMaximumPoints();
591 
592  unset($tmp_question);
593  }
594  }
595  unset($tmp_test);
596 
597  return $points;
598  }
599 
608  public static function _lookupMaximumPointsOfQuestion($a_question_id)
609  {
610  include_once('Modules/TestQuestionPool/classes/class.assQuestion.php');
611  return assQuestion::_getMaximumPoints($a_question_id);
612  }
613 
614 
615  function getNumberOfQuestionsByTest($a_test_ref_id)
616  {
617  $counter = 0;
618 
619  foreach($this->getQuestions() as $question)
620  {
621  if($question['ref_id'] == $a_test_ref_id)
622  {
623  ++$counter;
624  }
625  }
626  return $counter;
627  }
628 
629  function getQuestionsByTest($a_test_ref_id)
630  {
631  foreach($this->getQuestions() as $question)
632  {
633  if($question['ref_id'] == $a_test_ref_id)
634  {
635  $qst[] = $question['question_id'];
636  }
637  }
638  return $qst ? $qst : array();
639  }
640 
648  public function updateLimits()
649  {
650  global $ilDB;
651 
652  foreach($this->tests as $ref_id => $test_data)
653  {
654  switch($test_data['status'])
655  {
657  $points = $this->getSelfAssessmentPoints();
658  break;
659 
660  case self::TYPE_FINAL_TEST:
661  $points = $this->getFinalTestPoints();
662  break;
663  }
664  if($test_data['limit'] == -1 or $test_data['limit'] > $points)
665  {
666  switch($test_data['status'])
667  {
669  $points = $this->getSelfAssessmentPoints();
670  break;
671 
672  case self::TYPE_FINAL_TEST:
673  $points = $this->getFinalTestPoints();
674  break;
675  }
676  $query = "UPDATE crs_objective_tst ".
677  "SET tst_limit = ".$this->db->quote($points ,'integer')." ".
678  "WHERE test_objective_id = ".$this->db->quote($test_data['test_objective_id'] ,'integer')." ";
679  $res = $ilDB->manipulate($query);
680  }
681  }
682  }
683 
684 
685  function add()
686  {
687  global $ilDB;
688 
689  $query = "DELETE FROM crs_objective_qst ".
690  "WHERE objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
691  "AND question_id = ".$this->db->quote($this->getQuestionId() ,'integer')." ";
692  $res = $ilDB->manipulate($query);
693 
694  $next_id = $ilDB->nextId('crs_objective_qst');
695  $query = "INSERT INTO crs_objective_qst (qst_ass_id, objective_id,ref_id,obj_id,question_id) ".
696  "VALUES( ".
697  $ilDB->quote($next_id,'integer').", ".
698  $ilDB->quote($this->getObjectiveId() ,'integer').", ".
699  $ilDB->quote($this->getTestRefId() ,'integer').", ".
700  $ilDB->quote($this->getTestObjId() ,'integer').", ".
701  $ilDB->quote($this->getQuestionId() ,'integer').
702  ")";
703  $res = $ilDB->manipulate($query);
704 
705  $this->__addTest();
706 
707  $this->__read();
708 
709  return true;
710  }
711  function delete($qst_id)
712  {
713  global $ilDB;
714 
715  if(!$qst_id)
716  {
717  return false;
718  }
719 
720  $query = "SELECT * FROM crs_objective_qst ".
721  "WHERE qst_ass_id = ".$ilDB->quote($qst_id ,'integer')." ";
722 
723  $res = $this->db->query($query);
724  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
725  {
726  $test_rid = $row->ref_id;
727  $test_oid = $row->obj_id;
728  }
729 
730  $query = "DELETE FROM crs_objective_qst ".
731  "WHERE qst_ass_id = ".$ilDB->quote($qst_id ,'integer')." ";
732  $res = $ilDB->manipulate($query);
733 
734  // delete test if it was the last question
735  $query = "SELECT * FROM crs_objective_qst ".
736  "WHERE ref_id = ".$ilDB->quote($test_rid ,'integer')." ".
737  "AND obj_id = ".$ilDB->quote($test_oid ,'integer')." ".
738  "AND objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
739 
740  $res = $this->db->query($query);
741  if(!$res->numRows())
742  {
743  $this->__deleteTest($test_rid);
744  }
745 
746  return true;
747  }
748 
749  // begin-patch lok
750  public static function deleteTest($a_tst_ref_id)
751  {
752  global $ilDB;
753 
754  $query = 'DELETE FROM crs_objective_tst '.
755  'WHERE ref_id = '.$ilDB->quote($a_tst_ref_id,'integer');
756  $ilDB->manipulate($query);
757 
758  $query = 'DELETE FROM crs_objective_qst '.
759  'WHERE ref_id = '.$ilDB->quote($a_tst_ref_id,'integer');
760  $ilDB->manipulate($query);
761  }
762 
763 
764  public function deleteByTestType($a_type)
765  {
766  global $ilDB;
767 
768 
769  // Read tests by type
770  $deletable_refs = array();
771  foreach((array) $this->tests as $tst_data)
772  {
773  if($tst_data['status'] == $a_type)
774  {
775  $deletable_refs[] = $tst_data['ref_id'];
776  }
777  }
778 
779  $query = 'DELETE from crs_objective_tst '.
780  'WHERE objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer').' '.
781  'AND tst_status = '.$ilDB->quote($a_type,'integer');
782  $ilDB->manipulate($query);
783 
784 
785  $query = 'DELETE from crs_objective_tst '.
786  'WHERE objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer').' '.
787  'AND '.$ilDB->in('ref_id',$deletable_refs,false,'integer');
788  $ilDB->manipulate($query);
789 
790  return true;
791  }
792  // end-patch lok
793 
794 
795  function deleteAll()
796  {
797  global $ilDB;
798 
799  $query = "DELETE FROM crs_objective_qst ".
800  "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
801  $res = $ilDB->manipulate($query);
802 
803  $query = "DELETE FROM crs_objective_tst ".
804  "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
805  $res = $ilDB->manipulate($query);
806 
807  return true;
808  }
809 
810 
811  // PRIVATE
812  function __read()
813  {
814  global $ilDB,$tree;
815 
816  include_once './Modules/Test/classes/class.ilObjTest.php';
817  include_once('Modules/Course/classes/class.ilCourseObjective.php');
818 
819  $container_ref_ids = ilObject::_getAllReferences(ilCourseObjective::_lookupContainerIdByObjectiveId($this->objective_id));
820  $container_ref_id = current($container_ref_ids);
821 
822  // Read test data
823  $query = "SELECT * FROM crs_objective_tst ".
824  "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
825  $res = $this->db->query($query);
826  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
827  {
828  $this->tests[$row->ref_id]['test_objective_id'] = $row->test_objective_id;
829  $this->tests[$row->ref_id]['ref_id'] = $row->ref_id;
830  $this->tests[$row->ref_id]['obj_id'] = $row->obj_id;
831  $this->tests[$row->ref_id]['status'] = $row->tst_status;
832  $this->tests[$row->ref_id]['limit'] = $row->tst_limit_p;
833  }
834 
835  $this->questions = array();
836  $query = "SELECT * FROM crs_objective_qst coq ".
837  "JOIN qpl_questions qq ON coq.question_id = qq.question_id ".
838  "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
839  "ORDER BY title";
840 
841  $res = $this->db->query($query);
842  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
843  {
844  if(!$tree->isInTree($row->ref_id) or !$tree->isGrandChild($container_ref_id,$row->ref_id))
845  {
846  $this->__deleteTest($row->ref_id);
847  continue;
848  }
849  if(!$question = ilObjTest::_instanciateQuestion($row->question_id))
850  {
851  $this->delete($row->question_id);
852  continue;
853  }
854 
855  $qst['ref_id'] = $row->ref_id;
856  $qst['obj_id'] = $row->obj_id;
857  $qst['question_id'] = $row->question_id;
858  $qst['qst_ass_id'] = $row->qst_ass_id;
859  $qst['title'] = $question->getTitle();
860  $qst['description'] = $question->getComment();
861  $qst['test_type'] = $this->tests[$row->ref_id]['status'];
862  $qst['points'] = $question->getPoints();
863 
864  $this->questions[$row->qst_ass_id] = $qst;
865  }
866 
867  return true;
868  }
869 
870  // STATIC
878  public function _hasTests($a_course_id)
879  {
880  global $ilDB;
881 
882  $query = "SELECT co.objective_id FROM crs_objectives co JOIN ".
883  "crs_objective_tst cot ON co.objective_id = cot.objective_id ".
884  "WHERE crs_id = ".$ilDB->quote($a_course_id ,'integer')." ";
885  $res = $ilDB->query($query);
886  return $res->numRows() ? true : false;
887  }
888 
889 
890  function _isAssigned($a_objective_id,$a_tst_ref_id,$a_question_id)
891  {
892  global $ilDB;
893 
894  $query = "SELECT crs_qst.objective_id objective_id FROM crs_objective_qst crs_qst, crs_objectives crs_obj ".
895  "WHERE crs_qst.objective_id = crs_obj.objective_id ".
896  "AND crs_qst.objective_id = ".$ilDB->quote($a_objective_id ,'integer') ." ".
897  "AND ref_id = ".$ilDB->quote($a_tst_ref_id ,'integer')." ".
898  "AND question_id = ".$ilDB->quote($a_question_id ,'integer')." ";
899 
900  $res = $ilDB->query($query);
901  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
902  {
903  $objective_id = $row->objective_id;
904  }
905 
906  return $objective_id ? $objective_id : 0;
907  }
908 
909  // begin-patch lok
910  public static function lookupQuestionsByObjective($a_test_id, $a_objective)
911  {
912  global $ilDB;
913 
914  $query = 'SELECT question_id FROM crs_objective_qst '.
915  'WHERE objective_id = '.$ilDB->quote($a_objective,'integer').' '.
916  'AND obj_id = '.$ilDB->quote($a_test_id,'integer');
917  $res = $ilDB->query($query);
918 
919  $questions = array();
920  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
921  {
922  $questions[] = $row->question_id;
923  }
924  return (array) $questions;
925  }
926 
927  public static function loookupTestLimit($a_test_id, $a_objective_id)
928  {
929  global $ilDB;
930 
931  $query = 'SELECT tst_limit_p FROM crs_objective_tst '.
932  'WHERE objective_id = '.$ilDB->quote($a_objective_id,'integer').' '.
933  'AND obj_id = '.$ilDB->quote($a_test_id,'integer');
934  $res = $ilDB->query($query);
935  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
936  {
937  return (int) $row->tst_limit_p;
938  }
939  return 0;
940  }
941 
946  public function toXml(ilXmlWriter $writer)
947  {
948  foreach($this->getTests() as $test)
949  {
950  include_once './Modules/Course/classes/Objectives/class.ilLOXmlWriter.php';
951  $writer->xmlStartTag(
952  'Test',
953  array(
954  'type' => ilLOXmlWriter::TYPE_TST_ALL,
955  'refId' => $test['ref_id'],
956  'testType' => $test['tst_status'],
957  'limit' => $test['tst_limit']
958  )
959  );
960 
961  // questions
962  foreach($this->getQuestionsByTest($test['ref_id']) as $question_id)
963  {
964  $writer->xmlElement('Question', array('id' => $question_id));
965  }
966  $writer->xmlEndTag('Test');
967  }
968 
969  }
970 
971  // end-patch lok
972 
973 }
974 ?>
static loookupTestLimit($a_test_id, $a_objective_id)
static _lookupMaximumPointsOfQuestion($a_question_id)
lookup maximimum point
getQuestionsOfTest($a_test_id)
Get questions of test.
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupContainerIdByObjectiveId($a_objective_id)
Get container of object.
getSelfAssessmentPoints()
get self assessment points
cloneDependencies($a_new_objective, $a_copy_id)
clone objective questions
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
& _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
static _isTestAssignedToObjective($a_test_id, $a_objective_id)
Check if test is assigned to objective.
isSelfAssessmentQuestion($a_question_id)
check if question is self assessment question
isFinalTestQuestion($a_question_id)
is final test question
static _getAllReferences($a_id)
get all reference ids of object
xmlEndTag($tag)
Writes an endtag.
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
getFinalTestQuestions()
get final test questions
static _getInstance($a_copy_id)
Get instance of copy wizard options.
_getMaximumPoints($question_id)
Returns the maximum points, a learner can reach answering the question.
getSelfAssessmentQuestions()
get self assessment questions
_isAssigned($a_objective_id, $a_tst_ref_id, $a_question_id)
$ref_id
Definition: sahs_server.php:39
global $ilDB
static _updateTestLimits($a_objective_id, $a_status, $a_limit)
update test limits
static getLogger($a_component_id)
Get component logger.
static lookupObjectivesOfQuestion($a_qid)
Lookup objective for test question type $ilDB.
getSelfAssessmentTests()
get self assessment tests
static lookupQuestionsByObjective($a_test_id, $a_objective)
class ilcourseobjectiveQuestion
const TYPE_SELF_ASSESSMENT
static _getAssignableTests($a_container_ref_id)
Get assignable tests.
$test
Definition: Utf8Test.php:85