ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
53 
54  $ilDB = $DIC['ilDB'];
55 
56  $this->db = $ilDB;
57 
58  $this->objective_id = $a_objective_id;
59 
60  $this->__read();
61  }
62 
63 
71  public static function lookupObjectivesOfQuestion($a_qid)
72  {
73  global $DIC;
74 
75  $ilDB = $DIC['ilDB'];
76 
77  $query = 'SELECT objective_id FROM crs_objective_qst ' .
78  'WHERE question_id = ' . $ilDB->quote($a_qid, 'integer');
79  $res = $ilDB->query($query);
80  $objectiveIds = array();
81  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
82  $objectiveIds[] = $row->objective_id;
83  }
84  return $objectiveIds;
85  }
86 
97  public static function _isTestAssignedToObjective($a_test_id, $a_objective_id)
98  {
99  global $DIC;
100 
101  $ilDB = $DIC['ilDB'];
102 
103  $query = "SELECT qst_ass_id FROM crs_objective_qst " .
104  "WHERE ref_id = " . $ilDB->quote($a_test_id, 'integer') . " " .
105  "AND objective_id = " . $ilDB->quote($a_objective_id, 'integer');
106  $res = $ilDB->query($query);
107  return $res->numRows() ? true : false;
108  }
109 
119  public function cloneDependencies($a_new_objective, $a_copy_id)
120  {
121  global $DIC;
122 
123  $ilObjDataCache = $DIC['ilObjDataCache'];
124  $ilLog = $DIC['ilLog'];
125  $ilDB = $DIC['ilDB'];
126 
127  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
128  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
129  $mappings = $cwo->getMappings();
130  foreach ($this->getQuestions() as $question) {
131  $mapping_key = $question['ref_id'] . '_question_' . $question['question_id'];
132  if (!isset($mappings[$mapping_key]) or !$mappings[$mapping_key]) {
133  continue;
134  }
135  $question_ref_id = $question['ref_id'];
136  $question_obj_id = $question['obj_id'];
137  $question_qst_id = $question['question_id'];
138  $new_ref_id = $mappings[$question_ref_id];
139  $new_obj_id = $ilObjDataCache->lookupObjId($new_ref_id);
140 
141  if ($new_obj_id == $question_obj_id) {
142  ilLoggerFactory::getLogger('crs')->info('Test has been linked. Keeping question id');
143  // Object has been linked
144  $new_question_id = $question_qst_id;
145  } else {
146  $new_question_info = $mappings[$question_ref_id . '_question_' . $question_qst_id];
147  $new_question_arr = explode('_', $new_question_info);
148  if (!isset($new_question_arr[2]) or !$new_question_arr[2]) {
149  ilLoggerFactory::getLogger('crs')->debug('found invalid format of question id mapping: ' . print_r($new_question_arr, true));
150  continue;
151  }
152  $new_question_id = $new_question_arr[2];
153  ilLoggerFactory::getLogger('crs')->info('New question id is: ' . $new_question_id);
154  }
155 
156  ilLoggerFactory::getLogger('crs')->debug('Copying question assignments');
157  $new_question = new ilCourseObjectiveQuestion($a_new_objective);
158  $new_question->setTestRefId($new_ref_id);
159  $new_question->setTestObjId($new_obj_id);
160  $new_question->setQuestionId($new_question_id);
161  $new_question->add();
162  }
163 
164  // Copy tests
165  foreach ($this->getTests() as $test) {
166  $new_test_id = $mappings["$test[ref_id]"];
167 
168  $query = "UPDATE crs_objective_tst " .
169  "SET tst_status = " . $this->db->quote($test['tst_status'], 'integer') . ", " .
170  "tst_limit_p = " . $this->db->quote($test['tst_limit'], 'integer') . " " .
171  "WHERE objective_id = " . $this->db->quote($a_new_objective, 'integer') . " " .
172  "AND ref_id = " . $this->db->quote($new_test_id, 'integer');
173  $res = $ilDB->manipulate($query);
174  }
175  }
176 
185  public static function _getAssignableTests($a_container_ref_id)
186  {
187  global $DIC;
188 
189  $tree = $DIC['tree'];
190 
191  return $tree->getSubTree($tree->getNodeData($a_container_ref_id), true, 'tst');
192  }
193 
194  // ######################################################## Methods for test table
195  public function setTestStatus($a_status)
196  {
197  $this->tst_status = $a_status;
198  }
199  public function getTestStatus()
200  {
201  return (int) $this->tst_status;
202  }
203  public function setTestSuggestedLimit($a_limit)
204  {
205  $this->tst_limit = $a_limit;
206  }
207  public function getTestSuggestedLimit()
208  {
209  return (int) $this->tst_limit;
210  }
211  public function __addTest()
212  {
213  global $DIC;
214 
215  $ilDB = $DIC['ilDB'];
216 
217  $query = "UPDATE crs_objective_tst " .
218  "SET tst_status = " . $this->db->quote($this->getTestStatus(), 'integer') . " " .
219  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
220  "AND ref_id = " . $this->db->quote($this->getTestRefId(), 'integer') . " ";
221  $res = $ilDB->manipulate($query);
222 
223 
224  // CHECK if entry already exists
225  $query = "SELECT * FROM crs_objective_tst " .
226  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " " .
227  "AND ref_id = " . $ilDB->quote($this->getTestRefId(), 'integer') . "";
228 
229  $res = $this->db->query($query);
230  if ($res->numRows()) {
231  return false;
232  }
233 
234  // Check for existing limit
235  $query = "SELECT tst_limit_p FROM crs_objective_tst " .
236  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
237  "AND tst_status = " . $this->db->quote($this->getTestStatus(), 'integer') . " ";
238 
239  $res = $this->db->query($query);
240 
241  $limit = 100;
242  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
243  $limit = $row->tst_limit_p;
244  }
245 
246  $next_id = $ilDB->nextId('crs_objective_tst');
247  $query = "INSERT INTO crs_objective_tst (test_objective_id,objective_id,ref_id,obj_id,tst_status,tst_limit_p) " .
248  "VALUES( " .
249  $ilDB->quote($next_id, 'integer') . ", " .
250  $ilDB->quote($this->getObjectiveId(), 'integer') . ", " .
251  $ilDB->quote($this->getTestRefId(), 'integer') . ", " .
252  $ilDB->quote($this->getTestObjId(), 'integer') . ", " .
253  $ilDB->quote($this->getTestStatus(), 'integer') . ", " .
254  $this->db->quote($limit, 'integer') . " " .
255  ")";
256  $res = $ilDB->manipulate($query);
257 
258  return true;
259  }
260 
261  public function __deleteTest($a_test_ref_id)
262  {
263  global $DIC;
264 
265  $ilDB = $DIC['ilDB'];
266 
267  // Delete questions
268  $query = "DELETE FROM crs_objective_qst " .
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  // delete tst entries
274  $query = "DELETE FROM crs_objective_tst " .
275  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " " .
276  "AND ref_id = " . $ilDB->quote($a_test_ref_id, 'integer') . " ";
277  $res = $ilDB->manipulate($query);
278 
279  unset($this->tests[$a_test_ref_id]);
280 
281  return true;
282  }
283 
294  public static function _updateTestLimits($a_objective_id, $a_status, $a_limit)
295  {
296  global $DIC;
297 
298  $ilDB = $DIC['ilDB'];
299 
300  $query = "UPDATE crs_objective_tst " .
301  "SET tst_limit_p = " . $ilDB->quote($a_limit, 'integer') . " " .
302  "WHERE tst_status = " . $ilDB->quote($a_status, 'integer') . " " .
303  "AND objective_id = " . $ilDB->quote($a_objective_id, 'integer');
304  $res = $ilDB->manipulate($query);
305  return true;
306  }
307 
308  public function updateTest($a_objective_id)
309  {
310  global $DIC;
311 
312  $ilDB = $DIC['ilDB'];
313 
314  $query = "UPDATE crs_objective_tst " .
315  "SET tst_status = " . $ilDB->quote($this->getTestStatus(), 'integer') . ", " .
316  "tst_limit_p = " . $ilDB->quote($this->getTestSuggestedLimit(), 'integer') . " " .
317  "WHERE test_objective_id = " . $ilDB->quote($a_objective_id, 'integer') . "";
318  $res = $ilDB->manipulate($query);
319 
320  return true;
321  }
322 
323  public function getTests()
324  {
325  global $DIC;
326 
327  $ilDB = $DIC['ilDB'];
328 
329  $query = "SELECT * FROM crs_objective_tst cot " .
330  "JOIN object_data obd ON cot.obj_id = obd.obj_id " .
331  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " " .
332  "ORDER BY title ";
333 
334  $res = $this->db->query($query);
335  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
336  $test['test_objective_id'] = $row->test_objective_id;
337  $test['objective_id'] = $row->objective_id;
338  $test['ref_id'] = $row->ref_id;
339  $test['obj_id'] = $row->obj_id;
340  $test['tst_status'] = $row->tst_status;
341  $test['tst_limit'] = $row->tst_limit_p;
342  $test['title'] = $row->title;
343 
344  $tests[] = $test;
345  }
346 
347  return $tests ? $tests : array();
348  }
349 
357  public function getSelfAssessmentTests()
358  {
359  foreach ($this->tests as $test) {
360  if ($test['status'] == self::TYPE_SELF_ASSESSMENT) {
361  $self[] = $test;
362  }
363  }
364  return $self ? $self : array();
365  }
366 
373  public function getFinalTests()
374  {
375  foreach ($this->tests as $test) {
376  if ($test['status'] == self::TYPE_FINAL_TEST) {
377  $final[] = $test;
378  }
379  }
380  return $final ? $final : array();
381  }
382 
383  public static function _getTest($a_test_objective_id)
384  {
385  global $DIC;
386 
387  $ilDB = $DIC['ilDB'];
388 
389  $query = "SELECT * FROM crs_objective_tst " .
390  "WHERE test_objective_id = " . $ilDB->quote($a_test_objective_id, 'integer') . " ";
391 
392  $res = $ilDB->query($query);
393  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
394  $test['test_objective_id'] = $row->test_objective_id;
395  $test['objective_id'] = $row->objective_id;
396  $test['ref_id'] = $row->ref_id;
397  $test['obj_id'] = $row->obj_id;
398  $test['tst_status'] = $row->tst_status;
399  $test['tst_limit'] = $row->tst_limit_p;
400  }
401 
402  return $test ? $test : array();
403  }
404 
405  // ############################################################# METHODS for question table
406  public function getQuestions()
407  {
408  return $this->questions ? $this->questions : array();
409  }
410 
417  public function getSelfAssessmentQuestions()
418  {
419  foreach ($this->questions as $question) {
420  if ($question['test_type'] == self::TYPE_SELF_ASSESSMENT) {
421  $self[] = $question;
422  }
423  }
424  return $self ? $self : array();
425  }
426 
433  public function getSelfAssessmentPoints()
434  {
435  foreach ($this->getSelfAssessmentQuestions() as $question) {
436  $points += $question['points'];
437  }
438  return $points ? $points : 0;
439  }
440 
447  public function getFinalTestPoints()
448  {
449  foreach ($this->getFinalTestQuestions() as $question) {
450  $points += $question['points'];
451  }
452  return $points ? $points : 0;
453  }
454 
461  public function isSelfAssessmentQuestion($a_question_id)
462  {
463  foreach ($this->questions as $question) {
464  if ($question['question_id'] == $a_question_id) {
465  return $question['test_type'] == self::TYPE_SELF_ASSESSMENT;
466  }
467  }
468  return false;
469  }
470 
478  public function isFinalTestQuestion($a_question_id)
479  {
480  foreach ($this->questions as $question) {
481  if ($question['question_id'] == $a_question_id) {
482  return $question['test_type'] == self::TYPE_FINAL_TEST;
483  }
484  }
485  return false;
486  }
487 
494  public function getFinalTestQuestions()
495  {
496  foreach ($this->questions as $question) {
497  if ($question['test_type'] == self::TYPE_FINAL_TEST) {
498  $final[] = $question;
499  }
500  }
501  return $final ? $final : array();
502  }
503 
504 
505 
513  public function getQuestionsOfTest($a_test_id)
514  {
515  foreach ($this->getQuestions() as $qst) {
516  if ($a_test_id == $qst['obj_id']) {
517  $questions[] = $qst;
518  }
519  }
520  return $questions ? $questions : array();
521  }
522 
523  public function getQuestion($question_id)
524  {
525  return $this->questions[$question_id] ? $this->questions[$question_id] : array();
526  }
527 
528  public function getObjectiveId()
529  {
530  return $this->objective_id;
531  }
532 
533  public function setTestRefId($a_ref_id)
534  {
535  $this->tst_ref_id = $a_ref_id;
536  }
537  public function getTestRefId()
538  {
539  return $this->tst_ref_id ? $this->tst_ref_id : 0;
540  }
541  public function setTestObjId($a_obj_id)
542  {
543  $this->tst_obj_id = $a_obj_id;
544  }
545  public function getTestObjId()
546  {
547  return $this->tst_obj_id ? $this->tst_obj_id : 0;
548  }
549  public function setQuestionId($a_question_id)
550  {
551  $this->question_id = $a_question_id;
552  }
553  public function getQuestionId()
554  {
555  return $this->question_id;
556  }
557 
558 
559  public function getMaxPointsByObjective()
560  {
561  include_once './Modules/Test/classes/class.ilObjTest.php';
562 
563  $points = 0;
564  foreach ($this->getQuestions() as $question) {
565  $tmp_test = &ilObjectFactory::getInstanceByRefId($question['ref_id']);
566 
567  $tmp_question = &ilObjTest::_instanciateQuestion($question['question_id']);
568 
569  $points += $tmp_question->getMaximumPoints();
570 
571  unset($tmp_question);
572  unset($tmp_test);
573  }
574  return $points;
575  }
576 
577  public function getMaxPointsByTest($a_test_ref_id)
578  {
579  $points = 0;
580 
581  $tmp_test = &ilObjectFactory::getInstanceByRefId($a_test_ref_id);
582 
583  foreach ($this->getQuestions() as $question) {
584  if ($question['ref_id'] == $a_test_ref_id) {
585  $tmp_question = &ilObjTest::_instanciateQuestion($question['question_id']);
586 
587  $points += $tmp_question->getMaximumPoints();
588 
589  unset($tmp_question);
590  }
591  }
592  unset($tmp_test);
593 
594  return $points;
595  }
596 
605  public static function _lookupMaximumPointsOfQuestion($a_question_id)
606  {
607  include_once('Modules/TestQuestionPool/classes/class.assQuestion.php');
608  return assQuestion::_getMaximumPoints($a_question_id);
609  }
610 
611 
612  public function getNumberOfQuestionsByTest($a_test_ref_id)
613  {
614  $counter = 0;
615 
616  foreach ($this->getQuestions() as $question) {
617  if ($question['ref_id'] == $a_test_ref_id) {
618  ++$counter;
619  }
620  }
621  return $counter;
622  }
623 
624  public function getQuestionsByTest($a_test_ref_id)
625  {
626  foreach ($this->getQuestions() as $question) {
627  if ($question['ref_id'] == $a_test_ref_id) {
628  $qst[] = $question['question_id'];
629  }
630  }
631  return $qst ? $qst : array();
632  }
633 
641  public function updateLimits()
642  {
643  global $DIC;
644 
645  $ilDB = $DIC['ilDB'];
646 
647  foreach ($this->tests as $ref_id => $test_data) {
648  switch ($test_data['status']) {
650  $points = $this->getSelfAssessmentPoints();
651  break;
652 
653  case self::TYPE_FINAL_TEST:
654  $points = $this->getFinalTestPoints();
655  break;
656  }
657  if ($test_data['limit'] == -1 or $test_data['limit'] > $points) {
658  switch ($test_data['status']) {
660  $points = $this->getSelfAssessmentPoints();
661  break;
662 
663  case self::TYPE_FINAL_TEST:
664  $points = $this->getFinalTestPoints();
665  break;
666  }
667  $query = "UPDATE crs_objective_tst " .
668  "SET tst_limit = " . $this->db->quote($points, 'integer') . " " .
669  "WHERE test_objective_id = " . $this->db->quote($test_data['test_objective_id'], 'integer') . " ";
670  $res = $ilDB->manipulate($query);
671  }
672  }
673  }
674 
675 
676  public function add()
677  {
678  global $DIC;
679 
680  $ilDB = $DIC['ilDB'];
681 
682  $query = "DELETE FROM crs_objective_qst " .
683  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
684  "AND question_id = " . $this->db->quote($this->getQuestionId(), 'integer') . " ";
685  $res = $ilDB->manipulate($query);
686 
687  $next_id = $ilDB->nextId('crs_objective_qst');
688  $query = "INSERT INTO crs_objective_qst (qst_ass_id, objective_id,ref_id,obj_id,question_id) " .
689  "VALUES( " .
690  $ilDB->quote($next_id, 'integer') . ", " .
691  $ilDB->quote($this->getObjectiveId(), 'integer') . ", " .
692  $ilDB->quote($this->getTestRefId(), 'integer') . ", " .
693  $ilDB->quote($this->getTestObjId(), 'integer') . ", " .
694  $ilDB->quote($this->getQuestionId(), 'integer') .
695  ")";
696  $res = $ilDB->manipulate($query);
697 
698  $this->__addTest();
699 
700  $this->__read();
701 
702  return true;
703  }
704  public function delete($qst_id)
705  {
706  global $DIC;
707 
708  $ilDB = $DIC['ilDB'];
709 
710  if (!$qst_id) {
711  return false;
712  }
713 
714  $query = "SELECT * FROM crs_objective_qst " .
715  "WHERE qst_ass_id = " . $ilDB->quote($qst_id, 'integer') . " ";
716 
717  $res = $this->db->query($query);
718  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
719  $test_rid = $row->ref_id;
720  $test_oid = $row->obj_id;
721  }
722 
723  $query = "DELETE FROM crs_objective_qst " .
724  "WHERE qst_ass_id = " . $ilDB->quote($qst_id, 'integer') . " ";
725  $res = $ilDB->manipulate($query);
726 
727  // delete test if it was the last question
728  $query = "SELECT * FROM crs_objective_qst " .
729  "WHERE ref_id = " . $ilDB->quote($test_rid, 'integer') . " " .
730  "AND obj_id = " . $ilDB->quote($test_oid, 'integer') . " " .
731  "AND objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " ";
732 
733  $res = $this->db->query($query);
734  if (!$res->numRows()) {
735  $this->__deleteTest($test_rid);
736  }
737 
738  return true;
739  }
740 
741  // begin-patch lok
742  public static function deleteTest($a_tst_ref_id)
743  {
744  global $DIC;
745 
746  $ilDB = $DIC['ilDB'];
747 
748  $query = 'DELETE FROM crs_objective_tst ' .
749  'WHERE ref_id = ' . $ilDB->quote($a_tst_ref_id, 'integer');
750  $ilDB->manipulate($query);
751 
752  $query = 'DELETE FROM crs_objective_qst ' .
753  'WHERE ref_id = ' . $ilDB->quote($a_tst_ref_id, 'integer');
754  $ilDB->manipulate($query);
755  }
756 
757 
758  public function deleteByTestType($a_type)
759  {
760  global $DIC;
761 
762  $ilDB = $DIC['ilDB'];
763 
764 
765  // Read tests by type
766  $deletable_refs = array();
767  foreach ((array) $this->tests as $tst_data) {
768  if ($tst_data['status'] == $a_type) {
769  $deletable_refs[] = $tst_data['ref_id'];
770  }
771  }
772 
773  $query = 'DELETE from crs_objective_tst ' .
774  'WHERE objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer') . ' ' .
775  'AND tst_status = ' . $ilDB->quote($a_type, 'integer');
776  $ilDB->manipulate($query);
777 
778 
779  $query = 'DELETE from crs_objective_tst ' .
780  'WHERE objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer') . ' ' .
781  'AND ' . $ilDB->in('ref_id', $deletable_refs, false, 'integer');
782  $ilDB->manipulate($query);
783 
784  return true;
785  }
786  // end-patch lok
787 
788 
789  public function deleteAll()
790  {
791  global $DIC;
792 
793  $ilDB = $DIC['ilDB'];
794 
795  $query = "DELETE FROM crs_objective_qst " .
796  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " ";
797  $res = $ilDB->manipulate($query);
798 
799  $query = "DELETE FROM crs_objective_tst " .
800  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " ";
801  $res = $ilDB->manipulate($query);
802 
803  return true;
804  }
805 
806 
807  // PRIVATE
808  public function __read()
809  {
810  global $DIC;
811 
812  $ilDB = $DIC['ilDB'];
813  $tree = $DIC['tree'];
814 
815  include_once './Modules/Test/classes/class.ilObjTest.php';
816  include_once('Modules/Course/classes/class.ilCourseObjective.php');
817 
818  $container_ref_ids = ilObject::_getAllReferences(ilCourseObjective::_lookupContainerIdByObjectiveId($this->objective_id));
819  $container_ref_id = current($container_ref_ids);
820 
821  // Read test data
822  $query = "SELECT * FROM crs_objective_tst " .
823  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " ";
824  $res = $this->db->query($query);
825  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
826  $this->tests[$row->ref_id]['test_objective_id'] = $row->test_objective_id;
827  $this->tests[$row->ref_id]['ref_id'] = $row->ref_id;
828  $this->tests[$row->ref_id]['obj_id'] = $row->obj_id;
829  $this->tests[$row->ref_id]['status'] = $row->tst_status;
830  $this->tests[$row->ref_id]['limit'] = $row->tst_limit_p;
831  }
832 
833  $this->questions = array();
834  $query = "SELECT * FROM crs_objective_qst coq " .
835  "JOIN qpl_questions qq ON coq.question_id = qq.question_id " .
836  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " " .
837  "ORDER BY title";
838 
839  $res = $this->db->query($query);
840  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
841  if (!$tree->isInTree($row->ref_id) or !$tree->isGrandChild($container_ref_id, $row->ref_id)) {
842  $this->__deleteTest($row->ref_id);
843  continue;
844  }
845  if (!$question = ilObjTest::_instanciateQuestion($row->question_id)) {
846  $this->delete($row->question_id);
847  continue;
848  }
849 
850  $qst['ref_id'] = $row->ref_id;
851  $qst['obj_id'] = $row->obj_id;
852  $qst['question_id'] = $row->question_id;
853  $qst['qst_ass_id'] = $row->qst_ass_id;
854  $qst['title'] = $question->getTitle();
855  $qst['description'] = $question->getComment();
856  $qst['test_type'] = $this->tests[$row->ref_id]['status'];
857  $qst['points'] = $question->getPoints();
858 
859  $this->questions[$row->qst_ass_id] = $qst;
860  }
861 
862  return true;
863  }
864 
865  // STATIC
873  public static function _hasTests($a_course_id)
874  {
875  global $DIC;
876 
877  $ilDB = $DIC['ilDB'];
878 
879  $query = "SELECT co.objective_id FROM crs_objectives co JOIN " .
880  "crs_objective_tst cot ON co.objective_id = cot.objective_id " .
881  "WHERE crs_id = " . $ilDB->quote($a_course_id, 'integer') . " ";
882  $res = $ilDB->query($query);
883  return $res->numRows() ? true : false;
884  }
885 
886 
887  public static function _isAssigned($a_objective_id, $a_tst_ref_id, $a_question_id)
888  {
889  global $DIC;
890 
891  $ilDB = $DIC['ilDB'];
892 
893  $query = "SELECT crs_qst.objective_id objective_id FROM crs_objective_qst crs_qst, crs_objectives crs_obj " .
894  "WHERE crs_qst.objective_id = crs_obj.objective_id " .
895  "AND crs_qst.objective_id = " . $ilDB->quote($a_objective_id, 'integer') . " " .
896  "AND ref_id = " . $ilDB->quote($a_tst_ref_id, 'integer') . " " .
897  "AND question_id = " . $ilDB->quote($a_question_id, 'integer') . " ";
898 
899  $res = $ilDB->query($query);
900  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
901  $objective_id = $row->objective_id;
902  }
903 
904  return $objective_id ? $objective_id : 0;
905  }
906 
907  // begin-patch lok
908  public static function lookupQuestionsByObjective($a_test_id, $a_objective)
909  {
910  global $DIC;
911 
912  $ilDB = $DIC['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(ilDBConstants::FETCHMODE_OBJECT)) {
921  $questions[] = $row->question_id;
922  }
923  return (array) $questions;
924  }
925 
926  public static function loookupTestLimit($a_test_id, $a_objective_id)
927  {
928  global $DIC;
929 
930  $ilDB = $DIC['ilDB'];
931 
932  $query = 'SELECT tst_limit_p FROM crs_objective_tst ' .
933  'WHERE objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
934  'AND obj_id = ' . $ilDB->quote($a_test_id, 'integer');
935  $res = $ilDB->query($query);
936  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
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  include_once './Modules/Course/classes/Objectives/class.ilLOXmlWriter.php';
950  $writer->xmlStartTag(
951  'Test',
952  array(
953  'type' => ilLOXmlWriter::TYPE_TST_ALL,
954  'refId' => $test['ref_id'],
955  'testType' => $test['tst_status'],
956  'limit' => $test['tst_limit']
957  )
958  );
959 
960  // questions
961  foreach ($this->getQuestionsByTest($test['ref_id']) as $question_id) {
962  $writer->xmlElement('Question', array('id' => $question_id));
963  }
964  $writer->xmlEndTag('Test');
965  }
966  }
967 
968  // end-patch lok
969 }
static loookupTestLimit($a_test_id, $a_objective_id)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
static _lookupMaximumPointsOfQuestion($a_question_id)
lookup maximimum point
getQuestionsOfTest($a_test_id)
Get questions of test.
static _lookupContainerIdByObjectiveId($a_objective_id)
Get container of object.
global $DIC
Definition: saml.php:7
getSelfAssessmentPoints()
get self assessment points
cloneDependencies($a_new_objective, $a_copy_id)
clone objective questions
static _isAssigned($a_objective_id, $a_tst_ref_id, $a_question_id)
XML writer class.
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
static _getMaximumPoints($question_id)
Returns the maximum points, a learner can reach answering the question.
isFinalTestQuestion($a_question_id)
is final test question
static _getAllReferences($a_id)
get all reference ids of object
xmlEndTag($tag)
Writes an endtag.
getFinalTestQuestions()
get final test questions
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
$a_type
Definition: workflow.php:92
static _getInstance($a_copy_id)
Get instance of copy wizard options.
foreach($_POST as $key=> $value) $res
static _getTest($a_test_objective_id)
getSelfAssessmentQuestions()
get self assessment questions
$query
$row
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
__construct($a_objective_id)
Constructor type $ilDB.
global $ilDB
static _updateTestLimits($a_objective_id, $a_status, $a_limit)
update test limits
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
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:84