ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestFixedQuestionSetConfig.php
Go to the documentation of this file.
1 <?php
2 
28 {
34  public function isQuestionSetConfigured(): bool
35  {
36  if ($this->testOBJ->getQuestionCountWithoutReloading() > 0) {
37  return true;
38  }
39  return false;
40  }
41 
47  public function doesQuestionSetRelatedDataExist(): bool
48  {
49  return $this->isQuestionSetConfigured();
50  }
51 
52  public function removeQuestionSetRelatedData(): void
53  {
54  $res = $this->db->queryF(
55  'SELECT question_fi FROM tst_test_question WHERE test_fi = %s',
56  ['integer'],
57  [$this->testOBJ->getTestId()]
58  );
59 
60  while ($row = $this->db->fetchAssoc($res)) {
61  $this->testOBJ->removeQuestion((int) $row['question_fi']);
62  }
63 
64  $this->db->manipulateF(
65  'DELETE FROM tst_test_question WHERE test_fi = %s',
66  ['integer'],
67  [$this->testOBJ->getTestId()]
68  );
69 
70  $this->testOBJ->questions = [];
71 
72  $this->testOBJ->saveCompleteStatus($this);
73  }
74 
76  {
77  // nothing to do
78  }
79 
85  public function cloneQuestionSetRelatedData(ilObjTest $clone_test_obj)
86  {
87  global $DIC;
88  $ilLog = $DIC['ilLog'];
89 
91 
92  foreach ($this->testOBJ->questions as $key => $question_id) {
93  $question = assQuestion::instantiateQuestion($question_id);
94 
95  $clone_test_obj->questions[$key] = $question->duplicate(true, '', '', '', $clone_test_obj->getId());
96 
97  $original_id = assQuestion::_getOriginalId($question_id);
98 
99  $question = assQuestion::instantiateQuestion($clone_test_obj->questions[$key]);
100  $question->saveToDb($original_id);
101 
102  // Save the mapping of old question id <-> new question id
103  // This will be used in class.ilObjCourse::cloneDependencies to copy learning objectives
104  $originalKey = $this->testOBJ->getRefId() . '_question_' . $question_id;
105  $mappedKey = $clone_test_obj->getRefId() . '_question_' . $clone_test_obj->questions[$key];
106  $cwo->appendMapping($originalKey, $mappedKey);
107  $ilLog->write(__METHOD__ . ": Added question id mapping $originalKey <-> $mappedKey");
108  }
109  }
110 
114  public function loadFromDb()
115  {
116  // TODO: Implement loadFromDb() method.
117  }
118 
122  public function saveToDb()
123  {
124  // TODO: Implement saveToDb() method.
125  }
126 
128  {
129  $query = "
130  SELECT question_fi, sequence FROM tst_test_question
131  WHERE test_fi = %s
132  ORDER BY sequence ASC
133  ";
134 
135  $res = $this->db->queryF(
136  $query,
137  ['integer'],
138  [$this->testOBJ->getTestId()]
139  );
140 
141  $sequenceIndex = 0;
142 
143  $reindexedSequencePositionMap = new ilTestReindexedSequencePositionMap();
144 
145  while ($row = $this->db->fetchAssoc($res)) {
146  $sequenceIndex++; // start with 1
147 
148  $reindexedSequencePositionMap->addPositionMapping((int) $row['sequence'], $sequenceIndex);
149 
150  $this->db->update(
151  'tst_test_question',
152  ['sequence' => ['integer', $sequenceIndex]],
153  ['question_fi' => ['integer', $row['question_fi']]]
154  );
155  }
156 
157  return $reindexedSequencePositionMap;
158  }
159 
165  public function cloneToDbForTestId($testId)
166  {
167  // TODO: Implement saveToDbByTestId() method.
168  }
169 
173  public function deleteFromDb()
174  {
175  // TODO: Implement deleteFromDb() method.
176  }
177 
178  public function isResultTaxonomyFilterSupported(): bool
179  {
180  return false;
181  }
182 }
$res
Definition: ltiservices.php:69
isQuestionSetConfigured()
returns the fact wether a useable question set config exists or not
static _getOriginalId(int $question_id)
doesQuestionSetRelatedDataExist()
returns the fact wether a useable question set config exists or not
saveToDb()
saves the question set config for current test to the database
global $DIC
Definition: feed.php:28
static instantiateQuestion(int $question_id)
cloneQuestionSetRelatedData(ilObjTest $clone_test_obj)
removes all question set config related data for cloned/copied test
string $key
Consumer key/client ID value.
Definition: System.php:193
$query
loadFromDb()
loads the question set config for current test from the database
deleteFromDb()
deletes the question set config for current test from the database
static _getInstance(int $a_copy_id)
cloneToDbForTestId($testId)
saves the question set config for test with given id to the database