ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestFixedQuestionSetConfig.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30{
31 public function isQuestionSetConfigured(): bool
32 {
33 if ($this->test_obj->getQuestionCountWithoutReloading() > 0) {
34 return true;
35 }
36 return false;
37 }
38
39 public function doesQuestionSetRelatedDataExist(): bool
40 {
41 return $this->isQuestionSetConfigured();
42 }
43
44 public function removeQuestionSetRelatedData(): void
45 {
46 $res = $this->db->queryF(
47 'SELECT question_fi FROM tst_test_question WHERE test_fi = %s',
48 ['integer'],
49 [$this->test_obj->getTestId()]
50 );
51
52 while ($row = $this->db->fetchAssoc($res)) {
53 $this->test_obj->removeQuestion((int) $row['question_fi']);
54 }
55
56 $this->db->manipulateF(
57 'DELETE FROM tst_test_question WHERE test_fi = %s',
58 ['integer'],
59 [$this->test_obj->getTestId()]
60 );
61
62 $this->test_obj->questions = [];
63
64 $this->test_obj->saveCompleteStatus($this);
65 }
66
67 public function cloneQuestionSetRelatedData(ilObjTest $clone_test_obj): void
68 {
70
71 foreach ($this->test_obj->questions as $key => $question_id) {
72 $question_orig = assQuestion::instantiateQuestion($question_id);
73
74 $clone_test_obj->questions[$key] = $question_orig->duplicate(true, '', '', -1, $clone_test_obj->getId());
75
76 $original_id = $this->questionrepository->getForQuestionId($question_id)->getOriginalId();
77
78 $question_clone = assQuestion::instantiateQuestion($clone_test_obj->questions[$key]);
79 $question_clone->saveToDb($original_id);
80
81 // Save the mapping of old question id <-> new question id
82 // This will be used in class.ilObjCourse::cloneDependencies to copy learning objectives
83 $original_key = $this->test_obj->getRefId() . '_question_' . $question_id;
84 $mapped_key = $clone_test_obj->getRefId() . '_question_' . $clone_test_obj->questions[$key];
85 $cwo->appendMapping($original_key, $mapped_key);
86 $this->logger->info(__METHOD__ . ": Added question id mapping $original_key <-> $mapped_key");
87 }
88 }
89
90 public function loadFromDb(): void
91 {
92 // TODO: Implement loadFromDb() method.
93 }
94
95 public function saveToDb(): void
96 {
97 // TODO: Implement saveToDb() method.
98 }
99
101 {
102 $query = "
103 SELECT question_fi, sequence FROM tst_test_question
104 WHERE test_fi = %s
105 ORDER BY sequence ASC
106 ";
107
108 $res = $this->db->queryF(
109 $query,
110 ['integer'],
111 [$this->test_obj->getTestId()]
112 );
113
114 $sequenceIndex = 0;
115
116 $reindexedSequencePositionMap = new ilTestReindexedSequencePositionMap();
117
118 while ($row = $this->db->fetchAssoc($res)) {
119 $sequenceIndex++; // start with 1
120
121 $reindexedSequencePositionMap->addPositionMapping((int) $row['sequence'], $sequenceIndex);
122
123 $this->db->update(
124 'tst_test_question',
125 ['sequence' => ['integer', $sequenceIndex]],
126 ['question_fi' => ['integer', $row['question_fi']]]
127 );
128 }
129
130 return $reindexedSequencePositionMap;
131 }
132
133 public function cloneToDbForTestId(int $test_id): void
134 {
135 // TODO: Implement saveToDbByTestId() method.
136 }
137
138 public function deleteFromDb(): void
139 {
140 // TODO: Implement deleteFromDb() method.
141 }
142
143 public function isResultTaxonomyFilterSupported(): bool
144 {
145 return false;
146 }
147}
static instantiateQuestion(int $question_id)
static _getInstance(int $a_copy_id)
cloneQuestionSetRelatedData(ilObjTest $clone_test_obj)
$res
Definition: ltiservices.php:69