ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $objectiveIds[] = $row->objective_id;
79  }
80  return $objectiveIds;
81  }
82 
93  public static function _isTestAssignedToObjective($a_test_id, $a_objective_id)
94  {
95  global $ilDB;
96 
97  $query = "SELECT qst_ass_id FROM crs_objective_qst " .
98  "WHERE ref_id = " . $ilDB->quote($a_test_id, 'integer') . " " .
99  "AND objective_id = " . $ilDB->quote($a_objective_id, 'integer');
100  $res = $ilDB->query($query);
101  return $res->numRows() ? true : false;
102  }
103 
113  public function cloneDependencies($a_new_objective, $a_copy_id)
114  {
115  global $ilObjDataCache,$ilLog,$ilDB;
116 
117  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
118  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
119  $mappings = $cwo->getMappings();
120  foreach ($this->getQuestions() as $question) {
121  $mapping_key = $question['ref_id'] . '_question_' . $question['question_id'];
122  if (!isset($mappings[$mapping_key]) or !$mappings[$mapping_key]) {
123  continue;
124  }
125  $question_ref_id = $question['ref_id'];
126  $question_obj_id = $question['obj_id'];
127  $question_qst_id = $question['question_id'];
128  $new_ref_id = $mappings[$question_ref_id];
129  $new_obj_id = $ilObjDataCache->lookupObjId($new_ref_id);
130 
131  if ($new_obj_id == $question_obj_id) {
132  ilLoggerFactory::getLogger('crs')->info('Test has been linked. Keeping question id');
133  // Object has been linked
134  $new_question_id = $question_qst_id;
135  } else {
136  $new_question_info = $mappings[$question_ref_id . '_question_' . $question_qst_id];
137  $new_question_arr = explode('_', $new_question_info);
138  if (!isset($new_question_arr[2]) or !$new_question_arr[2]) {
139  ilLoggerFactory::getLogger('crs')->debug('found invalid format of question id mapping: ' . print_r($new_question_arr, true));
140  continue;
141  }
142  $new_question_id = $new_question_arr[2];
143  ilLoggerFactory::getLogger('crs')->info('New question id is: ' . $new_question_id);
144  }
145 
146  ilLoggerFactory::getLogger('crs')->debug('Copying question assignments');
147  $new_question = new ilCourseObjectiveQuestion($a_new_objective);
148  $new_question->setTestRefId($new_ref_id);
149  $new_question->setTestObjId($new_obj_id);
150  $new_question->setQuestionId($new_question_id);
151  $new_question->add();
152  }
153 
154  // Copy tests
155  foreach ($this->getTests() as $test) {
156  $new_test_id = $mappings["$test[ref_id]"];
157 
158  $query = "UPDATE crs_objective_tst " .
159  "SET tst_status = " . $this->db->quote($test['tst_status'], 'integer') . ", " .
160  "tst_limit_p = " . $this->db->quote($test['tst_limit'], 'integer') . " " .
161  "WHERE objective_id = " . $this->db->quote($a_new_objective, 'integer') . " " .
162  "AND ref_id = " . $this->db->quote($new_test_id, 'integer');
163  $res = $ilDB->manipulate($query);
164  }
165  }
166 
175  public static function _getAssignableTests($a_container_ref_id)
176  {
177  global $tree;
178 
179  return $tree->getSubTree($tree->getNodeData($a_container_ref_id), true, 'tst');
180  }
181 
182  // ######################################################## Methods for test table
183  public function setTestStatus($a_status)
184  {
185  $this->tst_status = $a_status;
186  }
187  public function getTestStatus()
188  {
189  return (int) $this->tst_status;
190  }
191  public function setTestSuggestedLimit($a_limit)
192  {
193  $this->tst_limit = $a_limit;
194  }
195  public function getTestSuggestedLimit()
196  {
197  return (int) $this->tst_limit;
198  }
199  public function __addTest()
200  {
201  global $ilDB;
202 
203  $query = "UPDATE crs_objective_tst " .
204  "SET tst_status = " . $this->db->quote($this->getTestStatus(), 'integer') . " " .
205  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
206  "AND ref_id = " . $this->db->quote($this->getTestRefId(), 'integer') . " ";
207  $res = $ilDB->manipulate($query);
208 
209 
210  // CHECK if entry already exists
211  $query = "SELECT * FROM crs_objective_tst " .
212  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " " .
213  "AND ref_id = " . $ilDB->quote($this->getTestRefId(), 'integer') . "";
214 
215  $res = $this->db->query($query);
216  if ($res->numRows()) {
217  return false;
218  }
219 
220  // Check for existing limit
221  $query = "SELECT tst_limit_p FROM crs_objective_tst " .
222  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
223  "AND tst_status = " . $this->db->quote($this->getTestStatus(), 'integer') . " ";
224 
225  $res = $this->db->query($query);
226 
227  $limit = 100;
228  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
229  $limit = $row->tst_limit_p;
230  }
231 
232  $next_id = $ilDB->nextId('crs_objective_tst');
233  $query = "INSERT INTO crs_objective_tst (test_objective_id,objective_id,ref_id,obj_id,tst_status,tst_limit_p) " .
234  "VALUES( " .
235  $ilDB->quote($next_id, 'integer') . ", " .
236  $ilDB->quote($this->getObjectiveId(), 'integer') . ", " .
237  $ilDB->quote($this->getTestRefId(), 'integer') . ", " .
238  $ilDB->quote($this->getTestObjId(), 'integer') . ", " .
239  $ilDB->quote($this->getTestStatus(), 'integer') . ", " .
240  $this->db->quote($limit, 'integer') . " " .
241  ")";
242  $res = $ilDB->manipulate($query);
243 
244  return true;
245  }
246 
247  public function __deleteTest($a_test_ref_id)
248  {
249  global $ilDB;
250 
251  // Delete questions
252  $query = "DELETE FROM crs_objective_qst " .
253  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " " .
254  "AND ref_id = " . $ilDB->quote($a_test_ref_id, 'integer') . " ";
255  $res = $ilDB->manipulate($query);
256 
257  // delete tst entries
258  $query = "DELETE FROM crs_objective_tst " .
259  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " " .
260  "AND ref_id = " . $ilDB->quote($a_test_ref_id, 'integer') . " ";
261  $res = $ilDB->manipulate($query);
262 
263  unset($this->tests[$a_test_ref_id]);
264 
265  return true;
266  }
267 
278  public static function _updateTestLimits($a_objective_id, $a_status, $a_limit)
279  {
280  global $ilDB;
281 
282  $query = "UPDATE crs_objective_tst " .
283  "SET tst_limit_p = " . $ilDB->quote($a_limit, 'integer') . " " .
284  "WHERE tst_status = " . $ilDB->quote($a_status, 'integer') . " " .
285  "AND objective_id = " . $ilDB->quote($a_objective_id, 'integer');
286  $res = $ilDB->manipulate($query);
287  return true;
288  }
289 
290  public function updateTest($a_objective_id)
291  {
292  global $ilDB;
293 
294  $query = "UPDATE crs_objective_tst " .
295  "SET tst_status = " . $ilDB->quote($this->getTestStatus(), 'integer') . ", " .
296  "tst_limit_p = " . $ilDB->quote($this->getTestSuggestedLimit(), 'integer') . " " .
297  "WHERE test_objective_id = " . $ilDB->quote($a_objective_id, 'integer') . "";
298  $res = $ilDB->manipulate($query);
299 
300  return true;
301  }
302 
303  public function getTests()
304  {
305  global $ilDB;
306 
307  $query = "SELECT * FROM crs_objective_tst cot " .
308  "JOIN object_data obd ON cot.obj_id = obd.obj_id " .
309  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " " .
310  "ORDER BY title ";
311 
312  $res = $this->db->query($query);
313  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
314  $test['test_objective_id'] = $row->test_objective_id;
315  $test['objective_id'] = $row->objective_id;
316  $test['ref_id'] = $row->ref_id;
317  $test['obj_id'] = $row->obj_id;
318  $test['tst_status'] = $row->tst_status;
319  $test['tst_limit'] = $row->tst_limit_p;
320  $test['title'] = $row->title;
321 
322  $tests[] = $test;
323  }
324 
325  return $tests ? $tests : array();
326  }
327 
335  public function getSelfAssessmentTests()
336  {
337  foreach ($this->tests as $test) {
338  if ($test['status'] == self::TYPE_SELF_ASSESSMENT) {
339  $self[] = $test;
340  }
341  }
342  return $self ? $self : array();
343  }
344 
351  public function getFinalTests()
352  {
353  foreach ($this->tests as $test) {
354  if ($test['status'] == self::TYPE_FINAL_TEST) {
355  $final[] = $test;
356  }
357  }
358  return $final ? $final : array();
359  }
360 
361  public static function _getTest($a_test_objective_id)
362  {
363  global $ilDB;
364 
365  $query = "SELECT * FROM crs_objective_tst " .
366  "WHERE test_objective_id = " . $ilDB->quote($a_test_objective_id, 'integer') . " ";
367 
368  $res = $ilDB->query($query);
369  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
370  $test['test_objective_id'] = $row->test_objective_id;
371  $test['objective_id'] = $row->objective_id;
372  $test['ref_id'] = $row->ref_id;
373  $test['obj_id'] = $row->obj_id;
374  $test['tst_status'] = $row->tst_status;
375  $test['tst_limit'] = $row->tst_limit_p;
376  }
377 
378  return $test ? $test : array();
379  }
380 
381  // ############################################################# METHODS for question table
382  public function getQuestions()
383  {
384  return $this->questions ? $this->questions : array();
385  }
386 
393  public function getSelfAssessmentQuestions()
394  {
395  foreach ($this->questions as $question) {
396  if ($question['test_type'] == self::TYPE_SELF_ASSESSMENT) {
397  $self[] = $question;
398  }
399  }
400  return $self ? $self : array();
401  }
402 
409  public function getSelfAssessmentPoints()
410  {
411  foreach ($this->getSelfAssessmentQuestions() as $question) {
412  $points += $question['points'];
413  }
414  return $points ? $points : 0;
415  }
416 
423  public function getFinalTestPoints()
424  {
425  foreach ($this->getFinalTestQuestions() as $question) {
426  $points += $question['points'];
427  }
428  return $points ? $points : 0;
429  }
430 
437  public function isSelfAssessmentQuestion($a_question_id)
438  {
439  foreach ($this->questions as $question) {
440  if ($question['question_id'] == $a_question_id) {
441  return $question['test_type'] == self::TYPE_SELF_ASSESSMENT;
442  }
443  }
444  return false;
445  }
446 
454  public function isFinalTestQuestion($a_question_id)
455  {
456  foreach ($this->questions as $question) {
457  if ($question['question_id'] == $a_question_id) {
458  return $question['test_type'] == self::TYPE_FINAL_TEST;
459  }
460  }
461  return false;
462  }
463 
470  public function getFinalTestQuestions()
471  {
472  foreach ($this->questions as $question) {
473  if ($question['test_type'] == self::TYPE_FINAL_TEST) {
474  $final[] = $question;
475  }
476  }
477  return $final ? $final : array();
478  }
479 
480 
481 
489  public function getQuestionsOfTest($a_test_id)
490  {
491  foreach ($this->getQuestions() as $qst) {
492  if ($a_test_id == $qst['obj_id']) {
493  $questions[] = $qst;
494  }
495  }
496  return $questions ? $questions : array();
497  }
498 
499  public function getQuestion($question_id)
500  {
501  return $this->questions[$question_id] ? $this->questions[$question_id] : array();
502  }
503 
504  public function getObjectiveId()
505  {
506  return $this->objective_id;
507  }
508 
509  public function setTestRefId($a_ref_id)
510  {
511  $this->tst_ref_id = $a_ref_id;
512  }
513  public function getTestRefId()
514  {
515  return $this->tst_ref_id ? $this->tst_ref_id : 0;
516  }
517  public function setTestObjId($a_obj_id)
518  {
519  $this->tst_obj_id = $a_obj_id;
520  }
521  public function getTestObjId()
522  {
523  return $this->tst_obj_id ? $this->tst_obj_id : 0;
524  }
525  public function setQuestionId($a_question_id)
526  {
527  $this->question_id = $a_question_id;
528  }
529  public function getQuestionId()
530  {
531  return $this->question_id;
532  }
533 
534 
535  public function getMaxPointsByObjective()
536  {
537  include_once './Modules/Test/classes/class.ilObjTest.php';
538 
539  $points = 0;
540  foreach ($this->getQuestions() as $question) {
541  $tmp_test =&ilObjectFactory::getInstanceByRefId($question['ref_id']);
542 
543  $tmp_question =&ilObjTest::_instanciateQuestion($question['question_id']);
544 
545  $points += $tmp_question->getMaximumPoints();
546 
547  unset($tmp_question);
548  unset($tmp_test);
549  }
550  return $points;
551  }
552 
553  public function getMaxPointsByTest($a_test_ref_id)
554  {
555  $points = 0;
556 
557  $tmp_test =&ilObjectFactory::getInstanceByRefId($a_test_ref_id);
558 
559  foreach ($this->getQuestions() as $question) {
560  if ($question['ref_id'] == $a_test_ref_id) {
561  $tmp_question =&ilObjTest::_instanciateQuestion($question['question_id']);
562 
563  $points += $tmp_question->getMaximumPoints();
564 
565  unset($tmp_question);
566  }
567  }
568  unset($tmp_test);
569 
570  return $points;
571  }
572 
581  public static function _lookupMaximumPointsOfQuestion($a_question_id)
582  {
583  include_once('Modules/TestQuestionPool/classes/class.assQuestion.php');
584  return assQuestion::_getMaximumPoints($a_question_id);
585  }
586 
587 
588  public function getNumberOfQuestionsByTest($a_test_ref_id)
589  {
590  $counter = 0;
591 
592  foreach ($this->getQuestions() as $question) {
593  if ($question['ref_id'] == $a_test_ref_id) {
594  ++$counter;
595  }
596  }
597  return $counter;
598  }
599 
600  public function getQuestionsByTest($a_test_ref_id)
601  {
602  foreach ($this->getQuestions() as $question) {
603  if ($question['ref_id'] == $a_test_ref_id) {
604  $qst[] = $question['question_id'];
605  }
606  }
607  return $qst ? $qst : array();
608  }
609 
617  public function updateLimits()
618  {
619  global $ilDB;
620 
621  foreach ($this->tests as $ref_id => $test_data) {
622  switch ($test_data['status']) {
624  $points = $this->getSelfAssessmentPoints();
625  break;
626 
627  case self::TYPE_FINAL_TEST:
628  $points = $this->getFinalTestPoints();
629  break;
630  }
631  if ($test_data['limit'] == -1 or $test_data['limit'] > $points) {
632  switch ($test_data['status']) {
634  $points = $this->getSelfAssessmentPoints();
635  break;
636 
637  case self::TYPE_FINAL_TEST:
638  $points = $this->getFinalTestPoints();
639  break;
640  }
641  $query = "UPDATE crs_objective_tst " .
642  "SET tst_limit = " . $this->db->quote($points, 'integer') . " " .
643  "WHERE test_objective_id = " . $this->db->quote($test_data['test_objective_id'], 'integer') . " ";
644  $res = $ilDB->manipulate($query);
645  }
646  }
647  }
648 
649 
650  public function add()
651  {
652  global $ilDB;
653 
654  $query = "DELETE FROM crs_objective_qst " .
655  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
656  "AND question_id = " . $this->db->quote($this->getQuestionId(), 'integer') . " ";
657  $res = $ilDB->manipulate($query);
658 
659  $next_id = $ilDB->nextId('crs_objective_qst');
660  $query = "INSERT INTO crs_objective_qst (qst_ass_id, objective_id,ref_id,obj_id,question_id) " .
661  "VALUES( " .
662  $ilDB->quote($next_id, 'integer') . ", " .
663  $ilDB->quote($this->getObjectiveId(), 'integer') . ", " .
664  $ilDB->quote($this->getTestRefId(), 'integer') . ", " .
665  $ilDB->quote($this->getTestObjId(), 'integer') . ", " .
666  $ilDB->quote($this->getQuestionId(), 'integer') .
667  ")";
668  $res = $ilDB->manipulate($query);
669 
670  $this->__addTest();
671 
672  $this->__read();
673 
674  return true;
675  }
676  public function delete($qst_id)
677  {
678  global $ilDB;
679 
680  if (!$qst_id) {
681  return false;
682  }
683 
684  $query = "SELECT * FROM crs_objective_qst " .
685  "WHERE qst_ass_id = " . $ilDB->quote($qst_id, 'integer') . " ";
686 
687  $res = $this->db->query($query);
688  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
689  $test_rid = $row->ref_id;
690  $test_oid = $row->obj_id;
691  }
692 
693  $query = "DELETE FROM crs_objective_qst " .
694  "WHERE qst_ass_id = " . $ilDB->quote($qst_id, 'integer') . " ";
695  $res = $ilDB->manipulate($query);
696 
697  // delete test if it was the last question
698  $query = "SELECT * FROM crs_objective_qst " .
699  "WHERE ref_id = " . $ilDB->quote($test_rid, 'integer') . " " .
700  "AND obj_id = " . $ilDB->quote($test_oid, 'integer') . " " .
701  "AND objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " ";
702 
703  $res = $this->db->query($query);
704  if (!$res->numRows()) {
705  $this->__deleteTest($test_rid);
706  }
707 
708  return true;
709  }
710 
711  // begin-patch lok
712  public static function deleteTest($a_tst_ref_id)
713  {
714  global $ilDB;
715 
716  $query = 'DELETE FROM crs_objective_tst ' .
717  'WHERE ref_id = ' . $ilDB->quote($a_tst_ref_id, 'integer');
718  $ilDB->manipulate($query);
719 
720  $query = 'DELETE FROM crs_objective_qst ' .
721  'WHERE ref_id = ' . $ilDB->quote($a_tst_ref_id, 'integer');
722  $ilDB->manipulate($query);
723  }
724 
725 
726  public function deleteByTestType($a_type)
727  {
728  global $ilDB;
729 
730 
731  // Read tests by type
732  $deletable_refs = array();
733  foreach ((array) $this->tests as $tst_data) {
734  if ($tst_data['status'] == $a_type) {
735  $deletable_refs[] = $tst_data['ref_id'];
736  }
737  }
738 
739  $query = 'DELETE from crs_objective_tst ' .
740  'WHERE objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer') . ' ' .
741  'AND tst_status = ' . $ilDB->quote($a_type, 'integer');
742  $ilDB->manipulate($query);
743 
744 
745  $query = 'DELETE from crs_objective_tst ' .
746  'WHERE objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer') . ' ' .
747  'AND ' . $ilDB->in('ref_id', $deletable_refs, false, 'integer');
748  $ilDB->manipulate($query);
749 
750  return true;
751  }
752  // end-patch lok
753 
754 
755  public function deleteAll()
756  {
757  global $ilDB;
758 
759  $query = "DELETE FROM crs_objective_qst " .
760  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " ";
761  $res = $ilDB->manipulate($query);
762 
763  $query = "DELETE FROM crs_objective_tst " .
764  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " ";
765  $res = $ilDB->manipulate($query);
766 
767  return true;
768  }
769 
770 
771  // PRIVATE
772  public function __read()
773  {
774  global $ilDB,$tree;
775 
776  include_once './Modules/Test/classes/class.ilObjTest.php';
777  include_once('Modules/Course/classes/class.ilCourseObjective.php');
778 
779  $container_ref_ids = ilObject::_getAllReferences(ilCourseObjective::_lookupContainerIdByObjectiveId($this->objective_id));
780  $container_ref_id = current($container_ref_ids);
781 
782  // Read test data
783  $query = "SELECT * FROM crs_objective_tst " .
784  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " ";
785  $res = $this->db->query($query);
786  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
787  $this->tests[$row->ref_id]['test_objective_id'] = $row->test_objective_id;
788  $this->tests[$row->ref_id]['ref_id'] = $row->ref_id;
789  $this->tests[$row->ref_id]['obj_id'] = $row->obj_id;
790  $this->tests[$row->ref_id]['status'] = $row->tst_status;
791  $this->tests[$row->ref_id]['limit'] = $row->tst_limit_p;
792  }
793 
794  $this->questions = array();
795  $query = "SELECT * FROM crs_objective_qst coq " .
796  "JOIN qpl_questions qq ON coq.question_id = qq.question_id " .
797  "WHERE objective_id = " . $ilDB->quote($this->getObjectiveId(), 'integer') . " " .
798  "ORDER BY title";
799 
800  $res = $this->db->query($query);
801  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
802  if (!$tree->isInTree($row->ref_id) or !$tree->isGrandChild($container_ref_id, $row->ref_id)) {
803  $this->__deleteTest($row->ref_id);
804  continue;
805  }
806  if (!$question = ilObjTest::_instanciateQuestion($row->question_id)) {
807  $this->delete($row->question_id);
808  continue;
809  }
810 
811  $qst['ref_id'] = $row->ref_id;
812  $qst['obj_id'] = $row->obj_id;
813  $qst['question_id'] = $row->question_id;
814  $qst['qst_ass_id'] = $row->qst_ass_id;
815  $qst['title'] = $question->getTitle();
816  $qst['description'] = $question->getComment();
817  $qst['test_type'] = $this->tests[$row->ref_id]['status'];
818  $qst['points'] = $question->getPoints();
819 
820  $this->questions[$row->qst_ass_id] = $qst;
821  }
822 
823  return true;
824  }
825 
826  // STATIC
834  public static function _hasTests($a_course_id)
835  {
836  global $ilDB;
837 
838  $query = "SELECT co.objective_id FROM crs_objectives co JOIN " .
839  "crs_objective_tst cot ON co.objective_id = cot.objective_id " .
840  "WHERE crs_id = " . $ilDB->quote($a_course_id, 'integer') . " ";
841  $res = $ilDB->query($query);
842  return $res->numRows() ? true : false;
843  }
844 
845 
846  public static function _isAssigned($a_objective_id, $a_tst_ref_id, $a_question_id)
847  {
848  global $ilDB;
849 
850  $query = "SELECT crs_qst.objective_id objective_id FROM crs_objective_qst crs_qst, crs_objectives crs_obj " .
851  "WHERE crs_qst.objective_id = crs_obj.objective_id " .
852  "AND crs_qst.objective_id = " . $ilDB->quote($a_objective_id, 'integer') . " " .
853  "AND ref_id = " . $ilDB->quote($a_tst_ref_id, 'integer') . " " .
854  "AND question_id = " . $ilDB->quote($a_question_id, 'integer') . " ";
855 
856  $res = $ilDB->query($query);
857  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
858  $objective_id = $row->objective_id;
859  }
860 
861  return $objective_id ? $objective_id : 0;
862  }
863 
864  // begin-patch lok
865  public static function lookupQuestionsByObjective($a_test_id, $a_objective)
866  {
867  global $ilDB;
868 
869  $query = 'SELECT question_id FROM crs_objective_qst ' .
870  'WHERE objective_id = ' . $ilDB->quote($a_objective, 'integer') . ' ' .
871  'AND obj_id = ' . $ilDB->quote($a_test_id, 'integer');
872  $res = $ilDB->query($query);
873 
874  $questions = array();
875  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
876  $questions[] = $row->question_id;
877  }
878  return (array) $questions;
879  }
880 
881  public static function loookupTestLimit($a_test_id, $a_objective_id)
882  {
883  global $ilDB;
884 
885  $query = 'SELECT tst_limit_p FROM crs_objective_tst ' .
886  'WHERE objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
887  'AND obj_id = ' . $ilDB->quote($a_test_id, 'integer');
888  $res = $ilDB->query($query);
889  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
890  return (int) $row->tst_limit_p;
891  }
892  return 0;
893  }
894 
899  public function toXml(ilXmlWriter $writer)
900  {
901  foreach ($this->getTests() as $test) {
902  include_once './Modules/Course/classes/Objectives/class.ilLOXmlWriter.php';
903  $writer->xmlStartTag(
904  'Test',
905  array(
906  'type' => ilLOXmlWriter::TYPE_TST_ALL,
907  'refId' => $test['ref_id'],
908  'testType' => $test['tst_status'],
909  'limit' => $test['tst_limit']
910  )
911  );
912 
913  // questions
914  foreach ($this->getQuestionsByTest($test['ref_id']) as $question_id) {
915  $writer->xmlElement('Question', array('id' => $question_id));
916  }
917  $writer->xmlEndTag('Test');
918  }
919  }
920 
921  // end-patch lok
922 }
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.
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.
$counter
$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
Create styles array
The data for the language used.
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