ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilCourseObjectiveQuestion.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
26{
27 public const TYPE_SELF_ASSESSMENT = 0;
28 public const TYPE_FINAL_TEST = 1;
29
30 private int $objective_id = 0;
31 private array $questions = [];
32 private array $tests = [];
33 private int $tst_status = 0;
34 private int $tst_limit = 0;
35 private int $tst_ref_id = 0;
36 private int $tst_obj_id = 0;
37 private int $question_id = 0;
38
39 protected ilLogger $logger;
40 protected ilDBInterface $db;
42 protected ilTree $tree;
43
44 public function __construct(int $a_objective_id = 0)
45 {
46 global $DIC;
47
48 $this->logger = $DIC->logger()->crs();
49 $this->objectDataCache = $DIC['ilObjDataCache'];
50 $this->db = $DIC->database();
51 $this->tree = $DIC->repositoryTree();
52
53 $this->objective_id = $a_objective_id;
54 $this->__read();
55 }
56
60 public static function lookupObjectivesOfQuestion(int $a_qid): array
61 {
62 global $DIC;
63
64 $ilDB = $DIC->database();
65 $query = 'SELECT objective_id FROM crs_objective_qst ' .
66 'WHERE question_id = ' . $ilDB->quote($a_qid, 'integer');
67 $res = $ilDB->query($query);
68 $objectiveIds = array();
69 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
70 $objectiveIds[] = (int) $row->objective_id;
71 }
72 return $objectiveIds;
73 }
74
75 public static function _isTestAssignedToObjective(int $a_test_id, int $a_objective_id): bool
76 {
77 global $DIC;
78
79 $ilDB = $DIC->database();
80
81 $query = "SELECT qst_ass_id FROM crs_objective_qst " .
82 "WHERE ref_id = " . $ilDB->quote($a_test_id, 'integer') . " " .
83 "AND objective_id = " . $ilDB->quote($a_objective_id, 'integer');
84 $res = $ilDB->query($query);
85 return (bool) $res->numRows();
86 }
87
88 public function cloneDependencies(int $a_new_objective, int $a_copy_id): void
89 {
90 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
91 $mappings = $cwo->getMappings();
92 foreach ($this->getQuestions() as $question) {
93 $mapping_key = $question['ref_id'] . '_question_' . $question['question_id'];
94 if (!isset($mappings[$mapping_key]) || !$mappings[$mapping_key]) {
95 continue;
96 }
97 $question_ref_id = $question['ref_id'];
98 $question_obj_id = $question['obj_id'];
99 $question_qst_id = $question['question_id'];
100 $new_ref_id = (int) $mappings[$question_ref_id];
101 $new_obj_id = $this->objectDataCache->lookupObjId($new_ref_id);
102
103 if ($new_obj_id == $question_obj_id) {
104 $this->logger->info('Test has been linked. Keeping question id');
105 // Object has been linked
106 $new_question_id = $question_qst_id;
107 } else {
108 $new_question_info = $mappings[$question_ref_id . '_question_' . $question_qst_id];
109 $new_question_arr = explode('_', $new_question_info);
110 if (!isset($new_question_arr[2]) || !$new_question_arr[2]) {
111 $this->logger->debug('found invalid format of question id mapping: ' . print_r(
112 $new_question_arr,
113 true
114 ));
115 continue;
116 }
117 $new_question_id = $new_question_arr[2];
118 $this->logger->info('New question id is: ' . $new_question_id);
119 }
120
121 ilLoggerFactory::getLogger('crs')->debug('Copying question assignments');
122 $new_question = new ilCourseObjectiveQuestion($a_new_objective);
123 $new_question->setTestRefId($new_ref_id);
124 $new_question->setTestObjId($new_obj_id);
125 $new_question->setQuestionId($new_question_id);
126 $new_question->add();
127 }
128
129 // Copy tests
130 foreach ($this->getTests() as $test) {
131 if (!isset($mappings["$test[ref_id]"])) {
132 continue;
133 }
134 $new_test_id = $mappings["$test[ref_id]"];
135
136 $query = "UPDATE crs_objective_tst " .
137 "SET tst_status = " . $this->db->quote($test['tst_status'], 'integer') . ", " .
138 "tst_limit_p = " . $this->db->quote($test['tst_limit'], 'integer') . " " .
139 "WHERE objective_id = " . $this->db->quote($a_new_objective, 'integer') . " " .
140 "AND ref_id = " . $this->db->quote($new_test_id, 'integer');
141 $res = $this->db->manipulate($query);
142 }
143 }
144
145 public static function _getAssignableTests(int $a_container_ref_id): array
146 {
147 global $DIC;
148
149 $tree = $DIC->repositoryTree();
150 return $tree->getSubTree($tree->getNodeData($a_container_ref_id), true, ['tst']);
151 }
152
153 // ######################################################## Methods for test table
154 public function setTestStatus(int $a_status): void
155 {
156 $this->tst_status = $a_status;
157 }
158
159 public function getTestStatus(): int
160 {
161 return $this->tst_status;
162 }
163
164 public function setTestSuggestedLimit(int $a_limit): void
165 {
166 $this->tst_limit = $a_limit;
167 }
168
169 public function getTestSuggestedLimit(): int
170 {
171 return $this->tst_limit;
172 }
173
174 public function __addTest(): void
175 {
176 $query = "UPDATE crs_objective_tst " .
177 "SET tst_status = " . $this->db->quote($this->getTestStatus(), 'integer') . " " .
178 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
179 "AND ref_id = " . $this->db->quote($this->getTestRefId(), 'integer') . " ";
180 $res = $this->db->manipulate($query);
181
182 // CHECK if entry already exists
183 $query = "SELECT * FROM crs_objective_tst " .
184 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
185 "AND ref_id = " . $this->db->quote($this->getTestRefId(), 'integer') . "";
186
187 $res = $this->db->query($query);
188 if ($res->numRows()) {
189 return;
190 }
191
192 // Check for existing limit
193 $query = "SELECT tst_limit_p FROM crs_objective_tst " .
194 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
195 "AND tst_status = " . $this->db->quote($this->getTestStatus(), 'integer') . " ";
196
197 $res = $this->db->query($query);
198
199 $limit = 100;
200 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
201 $limit = (int) $row->tst_limit_p;
202 }
203
204 $next_id = $this->db->nextId('crs_objective_tst');
205 $query = "INSERT INTO crs_objective_tst (test_objective_id,objective_id,ref_id,obj_id,tst_status,tst_limit_p) " .
206 "VALUES( " .
207 $this->db->quote($next_id, 'integer') . ", " .
208 $this->db->quote($this->getObjectiveId(), 'integer') . ", " .
209 $this->db->quote($this->getTestRefId(), 'integer') . ", " .
210 $this->db->quote($this->getTestObjId(), 'integer') . ", " .
211 $this->db->quote($this->getTestStatus(), 'integer') . ", " .
212 $this->db->quote($limit, 'integer') . " " .
213 ")";
214 $res = $this->db->manipulate($query);
215 }
216
217 public function __deleteTest(int $a_test_ref_id): void
218 {
219 // Delete questions
220 $query = "DELETE FROM crs_objective_qst " .
221 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
222 "AND ref_id = " . $this->db->quote($a_test_ref_id, 'integer') . " ";
223 $res = $this->db->manipulate($query);
224
225 // delete tst entries
226 $query = "DELETE FROM crs_objective_tst " .
227 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
228 "AND ref_id = " . $this->db->quote($a_test_ref_id, 'integer') . " ";
229 $res = $this->db->manipulate($query);
230 unset($this->tests[$a_test_ref_id]);
231 }
232
233 public static function _updateTestLimits(int $a_objective_id, int $a_status, int $a_limit): void
234 {
235 global $DIC;
236
237 $ilDB = $DIC['ilDB'];
238
239 $query = "UPDATE crs_objective_tst " .
240 "SET tst_limit_p = " . $ilDB->quote($a_limit, 'integer') . " " .
241 "WHERE tst_status = " . $ilDB->quote($a_status, 'integer') . " " .
242 "AND objective_id = " . $ilDB->quote($a_objective_id, 'integer');
243 $res = $ilDB->manipulate($query);
244 }
245
246 public function updateTest(int $a_objective_id): void
247 {
248 $query = "UPDATE crs_objective_tst " .
249 "SET tst_status = " . $this->db->quote($this->getTestStatus(), 'integer') . ", " .
250 "tst_limit_p = " . $this->db->quote($this->getTestSuggestedLimit(), 'integer') . " " .
251 "WHERE test_objective_id = " . $this->db->quote($a_objective_id, 'integer') . "";
252 $res = $this->db->manipulate($query);
253 }
254
255 public function getTests(): array
256 {
257 $query = "SELECT * FROM crs_objective_tst cot " .
258 "JOIN object_data obd ON cot.obj_id = obd.obj_id " .
259 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
260 "ORDER BY title ";
261
262 $res = $this->db->query($query);
263 $tests = [];
264 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
265 $test['test_objective_id'] = (int) $row->test_objective_id;
266 $test['objective_id'] = (int) $row->objective_id;
267 $test['ref_id'] = (int) $row->ref_id;
268 $test['obj_id'] = (int) $row->obj_id;
269 $test['tst_status'] = (int) $row->tst_status;
270 $test['tst_limit'] = (int) $row->tst_limit_p;
271 $test['title'] = (string) $row->title;
272
273 $tests[] = $test;
274 }
275 return $tests;
276 }
277
278 public function getSelfAssessmentTests(): array
279 {
280 $self = [];
281 foreach ($this->tests as $test) {
282 if ($test['status'] == self::TYPE_SELF_ASSESSMENT) {
283 $self[] = $test;
284 }
285 }
286 return $self;
287 }
288
289 public function getFinalTests(): array
290 {
291 $final = [];
292 foreach ($this->tests as $test) {
293 if ($test['status'] == self::TYPE_FINAL_TEST) {
294 $final[] = $test;
295 }
296 }
297 return $final;
298 }
299
300 public static function _getTest(int $a_test_objective_id): array
301 {
302 global $DIC;
303
304 $ilDB = $DIC->database();
305 $query = "SELECT * FROM crs_objective_tst " .
306 "WHERE test_objective_id = " . $ilDB->quote($a_test_objective_id, 'integer') . " ";
307
308 $res = $ilDB->query($query);
309 $test = [];
310 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
311 $test['test_objective_id'] = (int) $row->test_objective_id;
312 $test['objective_id'] = (int) $row->objective_id;
313 $test['ref_id'] = (int) $row->ref_id;
314 $test['obj_id'] = (int) $row->obj_id;
315 $test['tst_status'] = (int) $row->tst_status;
316 $test['tst_limit'] = (int) $row->tst_limit_p;
317 }
318
319 return $test;
320 }
321
322 public function getQuestions(): array
323 {
324 return $this->questions;
325 }
326
327 public function getSelfAssessmentQuestions(): array
328 {
329 $self = [];
330 foreach ($this->questions as $question) {
331 if ($question['test_type'] == self::TYPE_SELF_ASSESSMENT) {
332 $self[] = $question;
333 }
334 }
335 return $self;
336 }
337
338 public function getSelfAssessmentPoints(): int
339 {
340 $points = 0;
341 foreach ($this->getSelfAssessmentQuestions() as $question) {
342 $points += $question['points'];
343 }
344 return $points;
345 }
346
347 public function getFinalTestPoints(): int
348 {
349 $points = 0;
350 foreach ($this->getFinalTestQuestions() as $question) {
351 $points += $question['points'];
352 }
353 return $points;
354 }
355
356 public function isSelfAssessmentQuestion(int $a_question_id): bool
357 {
358 foreach ($this->questions as $question) {
359 if ($question['question_id'] == $a_question_id) {
360 return $question['test_type'] === self::TYPE_SELF_ASSESSMENT;
361 }
362 }
363 return false;
364 }
365
366 public function isFinalTestQuestion(int $a_question_id): bool
367 {
368 foreach ($this->questions as $question) {
369 if ($question['question_id'] == $a_question_id) {
370 return $question['test_type'] === self::TYPE_FINAL_TEST;
371 }
372 }
373 return false;
374 }
375
376 public function getFinalTestQuestions(): array
377 {
378 $final = [];
379 foreach ($this->questions as $question) {
380 if ($question['test_type'] == self::TYPE_FINAL_TEST) {
381 $final[] = $question;
382 }
383 }
384 return $final;
385 }
386
387 public function getQuestionsOfTest(int $a_test_id): array
388 {
389 $questions = [];
390 foreach ($this->getQuestions() as $qst) {
391 if ($a_test_id == $qst['obj_id']) {
392 $questions[] = $qst;
393 }
394 }
395 return $questions;
396 }
397
398 public function getQuestion(int $question_id): array
399 {
400 if ($this->questions[$question_id]) {
401 return $this->questions[$question_id];
402 } else {
403 return array();
404 }
405 }
406
407 public function getObjectiveId(): int
408 {
409 return $this->objective_id;
410 }
411
412 public function setTestRefId(int $a_ref_id): void
413 {
414 $this->tst_ref_id = $a_ref_id;
415 }
416
417 public function getTestRefId(): int
418 {
419 return $this->tst_ref_id;
420 }
421
422 public function setTestObjId(int $a_obj_id): void
423 {
424 $this->tst_obj_id = $a_obj_id;
425 }
426
427 public function getTestObjId(): int
428 {
429 return $this->tst_obj_id;
430 }
431
432 public function setQuestionId(int $a_question_id): void
433 {
434 $this->question_id = $a_question_id;
435 }
436
437 public function getQuestionId(): int
438 {
439 return $this->question_id;
440 }
441
442 public function getMaxPointsByObjective(): int
443 {
444 $points = 0;
445 foreach ($this->getQuestions() as $question) {
446 $tmp_test = ilObjectFactory::getInstanceByRefId($question['ref_id']);
447 $tmp_question = ilObjTest::_instanciateQuestion($question['question_id']);
448 $points += $tmp_question->getMaximumPoints();
449 }
450 return $points;
451 }
452
453 public function getMaxPointsByTest(int $a_test_ref_id): int
454 {
455 $points = 0;
456 $tmp_test = ilObjectFactory::getInstanceByRefId($a_test_ref_id);
457 foreach ($this->getQuestions() as $question) {
458 if ($question['ref_id'] == $a_test_ref_id) {
459 $tmp_question = ilObjTest::_instanciateQuestion($question['question_id']);
460 $points += $tmp_question->getMaximumPoints();
461 }
462 }
463 return $points;
464 }
465
466 public static function _lookupMaximumPointsOfQuestion(int $a_question_id): float
467 {
468 return assQuestion::_getMaximumPoints($a_question_id);
469 }
470
471 public function getNumberOfQuestionsByTest(int $a_test_ref_id): int
472 {
473 $counter = 0;
474 foreach ($this->getQuestions() as $question) {
475 if ($question['ref_id'] == $a_test_ref_id) {
476 ++$counter;
477 }
478 }
479 return $counter;
480 }
481
482 public function getQuestionsByTest(int $a_test_ref_id): array
483 {
484 $qst = [];
485 foreach ($this->getQuestions() as $question) {
486 if ($question['ref_id'] == $a_test_ref_id) {
487 $qst[] = $question['question_id'];
488 }
489 }
490 return $qst;
491 }
492
493 public function updateLimits(): void
494 {
495 $points = 0;
496 foreach ($this->tests as $test_data) {
497 switch ($test_data['status']) {
499 $points = $this->getSelfAssessmentPoints();
500 break;
501
503 $points = $this->getFinalTestPoints();
504 break;
505 }
506 if ($test_data['limit'] == -1 || $test_data['limit'] > $points) {
507 switch ($test_data['status']) {
509 $points = $this->getSelfAssessmentPoints();
510 break;
511
513 $points = $this->getFinalTestPoints();
514 break;
515 }
516 $query = "UPDATE crs_objective_tst " .
517 "SET tst_limit = " . $this->db->quote($points, 'integer') . " " .
518 "WHERE test_objective_id = " . $this->db->quote($test_data['test_objective_id'], 'integer') . " ";
519 $res = $this->db->manipulate($query);
520 }
521 }
522 }
523
524 public function add(): void
525 {
526 $query = "DELETE FROM crs_objective_qst " .
527 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
528 "AND question_id = " . $this->db->quote($this->getQuestionId(), 'integer') . " ";
529 $res = $this->db->manipulate($query);
530
531 $next_id = $this->db->nextId('crs_objective_qst');
532 $query = "INSERT INTO crs_objective_qst (qst_ass_id, objective_id,ref_id,obj_id,question_id) " .
533 "VALUES( " .
534 $this->db->quote($next_id, 'integer') . ", " .
535 $this->db->quote($this->getObjectiveId(), 'integer') . ", " .
536 $this->db->quote($this->getTestRefId(), 'integer') . ", " .
537 $this->db->quote($this->getTestObjId(), 'integer') . ", " .
538 $this->db->quote($this->getQuestionId(), 'integer') .
539 ")";
540 $res = $this->db->manipulate($query);
541
542 $this->__addTest();
543 $this->__read();
544 }
545
546 public function delete(int $qst_id): void
547 {
548 if (!$qst_id) {
549 return;
550 }
551
552 $query = "SELECT * FROM crs_objective_qst " .
553 "WHERE qst_ass_id = " . $this->db->quote($qst_id, 'integer') . " ";
554
555 $test_rid = $test_oid = 0;
556 $res = $this->db->query($query);
557 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
558 $test_rid = (int) $row->ref_id;
559 $test_oid = (int) $row->obj_id;
560 }
561
562 $query = "DELETE FROM crs_objective_qst " .
563 "WHERE qst_ass_id = " . $this->db->quote($qst_id, 'integer') . " ";
564 $res = $this->db->manipulate($query);
565
566 // delete test if it was the last question
567 $query = "SELECT * FROM crs_objective_qst " .
568 "WHERE ref_id = " . $this->db->quote($test_rid, 'integer') . " " .
569 "AND obj_id = " . $this->db->quote($test_oid, 'integer') . " " .
570 "AND objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
571
572 $res = $this->db->query($query);
573 if ($res->numRows() === 0) {
574 $this->__deleteTest($test_rid);
575 }
576 }
577
578 // begin-patch lok
579 public static function deleteTest(int $a_tst_ref_id): void
580 {
581 global $DIC;
582
583 $ilDB = $DIC->database();
584 $query = 'DELETE FROM crs_objective_tst ' .
585 'WHERE ref_id = ' . $ilDB->quote($a_tst_ref_id, 'integer');
586 $ilDB->manipulate($query);
587
588 $query = 'DELETE FROM crs_objective_qst ' .
589 'WHERE ref_id = ' . $ilDB->quote($a_tst_ref_id, 'integer');
590 $ilDB->manipulate($query);
591 }
592
593 public function deleteByTestType(int $a_type): void
594 {
595 // Read tests by type
596 $deletable_refs = array();
597 foreach ($this->tests as $tst_data) {
598 if ($tst_data['status'] == $a_type) {
599 $deletable_refs[] = $tst_data['ref_id'];
600 }
601 }
602
603 $query = 'DELETE from crs_objective_tst ' .
604 'WHERE objective_id = ' . $this->db->quote($this->getObjectiveId(), 'integer') . ' ' .
605 'AND tst_status = ' . $this->db->quote($a_type, 'integer');
606 $this->db->manipulate($query);
607
608 $query = 'DELETE from crs_objective_tst ' .
609 'WHERE objective_id = ' . $this->db->quote($this->getObjectiveId(), 'integer') . ' ' .
610 'AND ' . $this->db->in('ref_id', $deletable_refs, false, 'integer');
611 $this->db->manipulate($query);
612 }
613
614 public function deleteAll(): void
615 {
616 $query = "DELETE FROM crs_objective_qst " .
617 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
618 $res = $this->db->manipulate($query);
619
620 $query = "DELETE FROM crs_objective_tst " .
621 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
622 $res = $this->db->manipulate($query);
623 }
624
625 public function __read(): void
626 {
628 $container_ref_id = current($container_ref_ids);
629
630 // Read test data
631 $query = "SELECT * FROM crs_objective_tst " .
632 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
633 $res = $this->db->query($query);
634 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
635 $this->tests[(int) $row->ref_id]['test_objective_id'] = (int) $row->test_objective_id;
636 $this->tests[(int) $row->ref_id]['ref_id'] = (int) $row->ref_id;
637 $this->tests[(int) $row->ref_id]['obj_id'] = (int) $row->obj_id;
638 $this->tests[(int) $row->ref_id]['status'] = (int) $row->tst_status;
639 $this->tests[(int) $row->ref_id]['limit'] = (int) $row->tst_limit_p;
640 }
641
642 $this->questions = array();
643 $query = "SELECT * FROM crs_objective_qst coq " .
644 "JOIN qpl_questions qq ON coq.question_id = qq.question_id " .
645 "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
646 "ORDER BY title";
647
648 $res = $this->db->query($query);
649 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
650 if (!$this->tree->isInTree((int) $row->ref_id) || !$this->tree->isGrandChild(
651 $container_ref_id,
652 (int) $row->ref_id
653 )) {
654 $this->__deleteTest((int) $row->ref_id);
655 continue;
656 }
657 if (($question = ilObjTest::_instanciateQuestion((int) $row->question_id)) === null) {
658 $this->delete((int) $row->question_id);
659 continue;
660 }
661 $qst['ref_id'] = (int) $row->ref_id;
662 $qst['obj_id'] = (int) $row->obj_id;
663 $qst['question_id'] = (int) $row->question_id;
664 $qst['qst_ass_id'] = (int) $row->qst_ass_id;
665 $qst['title'] = $question->getTitle();
666 $qst['description'] = $question->getComment();
667 $qst['test_type'] = (int) $this->tests[(int) $row->ref_id]['status'];
668 $qst['points'] = (float) $question->getPoints();
669
670 $this->questions[(int) $row->qst_ass_id] = $qst;
671 }
672 }
673
674 public static function _hasTests(int $a_course_id): bool
675 {
676 global $DIC;
677
678 $ilDB = $DIC['ilDB'];
679
680 $query = "SELECT co.objective_id FROM crs_objectives co JOIN " .
681 "crs_objective_tst cot ON co.objective_id = cot.objective_id " .
682 "WHERE crs_id = " . $ilDB->quote($a_course_id, 'integer') . " ";
683 $res = $ilDB->query($query);
684 return (bool) $res->numRows();
685 }
686
687 public static function _isAssigned(int $a_objective_id, int $a_tst_ref_id, int $a_question_id): int
688 {
689 global $DIC;
690
691 $ilDB = $DIC->database();
692 $query = "SELECT crs_qst.objective_id objective_id FROM crs_objective_qst crs_qst, crs_objectives crs_obj " .
693 "WHERE crs_qst.objective_id = crs_obj.objective_id " .
694 "AND crs_qst.objective_id = " . $ilDB->quote($a_objective_id, 'integer') . " " .
695 "AND ref_id = " . $ilDB->quote($a_tst_ref_id, 'integer') . " " .
696 "AND question_id = " . $ilDB->quote($a_question_id, 'integer') . " ";
697
698 $res = $ilDB->query($query);
699 $objective_id = 0;
700 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
701 $objective_id = (int) $row->objective_id;
702 }
703 return $objective_id;
704 }
705
706 public static function lookupQuestionsByObjective(int $a_test_id, int $a_objective): array
707 {
708 global $DIC;
709
710 $ilDB = $DIC->database();
711 $query = 'SELECT question_id FROM crs_objective_qst ' .
712 'WHERE objective_id = ' . $ilDB->quote($a_objective, 'integer') . ' ' .
713 'AND obj_id = ' . $ilDB->quote($a_test_id, 'integer');
714 $res = $ilDB->query($query);
715
716 $questions = array();
717 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
718 $questions[] = $row->question_id;
719 }
720 return $questions;
721 }
722
723 public static function loookupTestLimit(int $a_test_id, int $a_objective_id): int
724 {
725 global $DIC;
726
727 $ilDB = $DIC['ilDB'];
728 $query = 'SELECT tst_limit_p FROM crs_objective_tst ' .
729 'WHERE objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
730 'AND obj_id = ' . $ilDB->quote($a_test_id, 'integer');
731 $res = $ilDB->query($query);
732 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
733 return (int) $row->tst_limit_p;
734 }
735 return 0;
736 }
737
738 public function toXml(ilXmlWriter $writer): void
739 {
740 foreach ($this->getTests() as $test) {
741 $writer->xmlStartTag(
742 'Test',
743 array(
745 'refId' => $test['ref_id'],
746 'testType' => $test['tst_status'],
747 'limit' => $test['tst_limit']
748 )
749 );
750
751 // questions
752 foreach ($this->getQuestionsByTest($test['ref_id']) as $question_id) {
753 $writer->xmlElement('Question', array('id' => $question_id));
754 }
755 $writer->xmlEndTag('Test');
756 }
757 }
758
759 // end-patch lok
760}
static _getMaximumPoints(int $question_id)
Returns the maximum points, a learner can reach answering the question.
static _getInstance(int $a_copy_id)
class ilcourseobjectiveQuestion
static lookupQuestionsByObjective(int $a_test_id, int $a_objective)
static _isAssigned(int $a_objective_id, int $a_tst_ref_id, int $a_question_id)
static _isTestAssignedToObjective(int $a_test_id, int $a_objective_id)
static _lookupMaximumPointsOfQuestion(int $a_question_id)
static loookupTestLimit(int $a_test_id, int $a_objective_id)
static _getTest(int $a_test_objective_id)
cloneDependencies(int $a_new_objective, int $a_copy_id)
static _getAssignableTests(int $a_container_ref_id)
static _updateTestLimits(int $a_objective_id, int $a_status, int $a_limit)
static _lookupContainerIdByObjectiveId(int $a_objective_id)
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getAllReferences(int $id)
get all reference ids for object ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
global $DIC
Definition: feed.php:28
const TYPE_SELF_ASSESSMENT
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query