ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLORandomTestQuestionPools.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
26 {
27  protected int $container_id = 0;
28  protected int $objective_id = 0;
29  protected int $test_type = 0;
30  protected int $test_id = 0;
31  protected int $qpl_seq = 0;
32  protected int $limit = 50;
33 
34  protected ilDBInterface $db;
35 
36  public function __construct(int $a_container_id, int $a_objective_id, int $a_test_type, int $a_qpl_sequence)
37  {
38  global $DIC;
39 
40  $this->db = $DIC->database();
41 
42  $this->container_id = $a_container_id;
43  $this->objective_id = $a_objective_id;
44  $this->test_type = $a_test_type;
45  $this->qpl_seq = $a_qpl_sequence;
46 
47  $this->read();
48  }
49 
50  public static function lookupLimit(int $a_container_id, int $a_objective_id, int $a_test_type): int
51  {
52  global $DIC;
53 
54  $ilDB = $DIC->database();
55  $query = 'SELECT * FROM loc_rnd_qpl ' .
56  'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
57  'AND objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
58  'AND tst_type = ' . $ilDB->quote($a_test_type, 'integer');
59  $res = $ilDB->query($query);
60  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
61  return $row->percentage;
62  }
63  return 0;
64  }
65 
66  public static function lookupSequences(int $a_container_id, int $a_objective_id, int $a_test_id): array
67  {
68  global $DIC;
69 
70  $ilDB = $DIC->database();
71  $query = 'SELECT * FROM loc_rnd_qpl ' .
72  'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
73  'AND objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
74  'AND tst_id = ' . $ilDB->quote($a_test_id, 'integer');
75 
76  $res = $ilDB->query($query);
77  $sequences = [];
78  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
79  $sequences[] = $row->qp_seq;
80  }
81  return $sequences;
82  }
83 
84  public static function lookupSequencesByType(
85  int $a_container_id,
86  int $a_objective_id,
87  int $a_test_id,
88  int $a_test_type
89  ): array {
90  global $DIC;
91 
92  $ilDB = $DIC->database();
93  $query = 'SELECT * FROM loc_rnd_qpl ' .
94  'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
95  'AND objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
96  'AND tst_id = ' . $ilDB->quote($a_test_id, 'integer') . ' ' .
97  'AND tst_type = ' . $ilDB->quote($a_test_type, 'integer');
98 
99  $res = $ilDB->query($query);
100  $sequences = [];
101  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
102  $sequences[] = (int) $row->qp_seq;
103  }
104  return $sequences;
105  }
106 
107  public static function lookupObjectiveIdsBySequence(int $a_container_id, int $a_seq_id): array
108  {
109  global $DIC;
110 
111  $ilDB = $DIC->database();
112  $query = 'SELECT objective_id FROM loc_rnd_qpl ' .
113  'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
114  'AND qp_seq = ' . $ilDB->quote($a_seq_id, 'integer');
115  $res = $ilDB->query($query);
116  $objectiveIds = array();
117  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
118  $objectiveIds[] = $row->objective_id;
119  }
120  return $objectiveIds;
121  }
122 
123  public function setContainerId(int $a_id): void
124  {
125  $this->container_id = $a_id;
126  }
127 
128  public function getContainerId(): int
129  {
130  return $this->container_id;
131  }
132 
133  public function setObjectiveId(int $a_id): void
134  {
135  $this->objective_id = $a_id;
136  }
137 
138  public function getObjectiveId(): int
139  {
140  return $this->objective_id;
141  }
142 
143  public function setTestType(int $a_type): void
144  {
145  $this->test_type = $a_type;
146  }
147 
148  public function getTestType(): int
149  {
150  return $this->test_type;
151  }
152 
153  public function setTestId(int $a_id): void
154  {
155  $this->test_id = $a_id;
156  }
157 
158  public function getTestId(): int
159  {
160  return $this->test_id;
161  }
162 
163  public function setQplSequence(int $a_id): void
164  {
165  $this->qpl_seq = $a_id;
166  }
167 
168  public function getQplSequence(): int
169  {
170  return $this->qpl_seq;
171  }
172 
173  public function setLimit(int $a_id): void
174  {
175  $this->limit = $a_id;
176  }
177 
178  public function getLimit(): int
179  {
180  return $this->limit;
181  }
182 
183  public function copy(int $a_copy_id, int $a_new_course_id, int $a_new_objective_id): void
184  {
185  $options = ilCopyWizardOptions::_getInstance($a_copy_id);
186  $mappings = $options->getMappings();
187 
188  foreach (self::lookupSequences(
189  $this->getContainerId(),
190  $this->getContainerId(),
191  $this->getTestId()
192  ) as $sequence) {
193  // not nice
194  $this->setQplSequence($sequence);
195  $this->read();
196 
197  $mapped_id = 0;
198  $test_ref_id = 0;
199  foreach (ilObject::_getAllReferences($this->getTestId()) as $ref_id) {
200  $test_ref_id = $ref_id;
201  $mapped_id = $mappings[$ref_id];
202  }
203  if (!$mapped_id) {
204  ilLoggerFactory::getLogger('crs')->debug('No test mapping found for random question pool assignment: ' . $this->getTestId() . ' ' . $sequence);
205  continue;
206  }
207 
208  // Mapping for sequence
209  $new_question_info = $mappings[$test_ref_id . '_rndSelDef_' . $this->getQplSequence()];
210  $new_question_arr = explode('_', $new_question_info);
211  if (!isset($new_question_arr[2]) || !$new_question_arr[2]) {
212  //ilLoggerFactory::getLogger('crs')->debug(print_r($mappings,TRUE));
213  ilLoggerFactory::getLogger('crs')->debug('Found invalid or no mapping format of random question id mapping: ' . print_r(
214  $new_question_arr,
215  true
216  ));
217  continue;
218  }
219 
220  $new_ass = new self(
221  $a_new_course_id,
222  $a_new_objective_id,
223  $this->getTestType(),
224  $new_question_arr[2]
225  );
226  $new_ass->setTestId($mapped_id);
227  $new_ass->setLimit($this->getLimit());
228  $new_ass->create();
229  }
230  }
231 
232  public function read(): void
233  {
234  $query = 'SELECT * FROM loc_rnd_qpl ' .
235  'WHERE container_id = ' . $this->db->quote($this->getContainerId(), 'integer') . ' ' .
236  'AND objective_id = ' . $this->db->quote($this->getObjectiveId(), 'integer') . ' ' .
237  'AND tst_type = ' . $this->db->quote($this->getTestType(), 'integer') . ' ' .
238  'AND qp_seq = ' . $this->db->quote($this->getQplSequence(), 'integer');
239 
240  $res = $this->db->query($query);
241  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
242  $this->setLimit($row->percentage);
243  $this->setTestId($row->tst_id);
244  }
245  }
246 
247  public function delete(): void
248  {
249  $query = 'DELETE FROM loc_rnd_qpl ' .
250  'WHERE container_id = ' . $this->db->quote($this->getContainerId(), 'integer') . ' ' .
251  'AND objective_id = ' . $this->db->quote($this->getObjectiveId(), 'integer') . ' ' .
252  'AND tst_type = ' . $this->db->quote($this->getTestType(), 'integer') . ' ' .
253  'AND qp_seq = ' . $this->db->quote($this->getQplSequence(), 'integer');
254  $this->db->manipulate($query);
255  }
256 
257  public static function deleteForObjectiveAndTestType(int $a_course_id, int $a_objective_id, int $a_tst_type): void
258  {
259  $db = $GLOBALS['DIC']->database();
260 
261  $query = 'DELETE FROM loc_rnd_qpl ' .
262  'WHERE container_id = ' . $db->quote($a_course_id, 'integer') . ' ' .
263  'AND objective_id = ' . $db->quote($a_objective_id, 'integer') . ' ' .
264  'AND tst_type = ' . $db->quote($a_tst_type, 'integer');
265  $db->manipulate($query);
266  }
267 
268  public function create(): void
269  {
270  $query = 'INSERT INTO loc_rnd_qpl ' .
271  '(container_id, objective_id, tst_type, tst_id, qp_seq, percentage) ' .
272  'VALUES ( ' .
273  $this->db->quote($this->getContainerId(), 'integer') . ', ' .
274  $this->db->quote($this->getObjectiveId(), 'integer') . ', ' .
275  $this->db->quote($this->getTestType(), 'integer') . ', ' .
276  $this->db->quote($this->getTestId(), 'integer') . ', ' .
277  $this->db->quote($this->getQplSequence(), 'integer') . ', ' .
278  $this->db->quote($this->getLimit(), ilDBConstants::T_INTEGER) . ' ' .
279  ')';
280  $this->db->manipulate($query);
281  }
282 
283  public static function toXml(ilXmlWriter $writer, int $a_objective_id): void
284  {
285  global $DIC;
286 
287  $ilDB = $DIC->database();
288  $query = 'SELECT * FROM loc_rnd_qpl ' .
289  'WHERE objective_id = ' . $ilDB->quote($a_objective_id, 'integer');
290  $res = $ilDB->query($query);
291  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
292  $writer->xmlElement(
293  'Test',
294  array(
295  'type' => ilLOXmlWriter::TYPE_TST_RND,
296  'objId' => $row->tst_id,
297  'testType' => $row->tst_type,
298  'limit' => $row->percentage,
299  'poolId' => $row->qp_seq
300  )
301  );
302  }
303  }
304  // end-patch optes_lok_export
305 }
static lookupLimit(int $a_container_id, int $a_objective_id, int $a_test_type)
$res
Definition: ltiservices.php:69
static lookupSequences(int $a_container_id, int $a_objective_id, int $a_test_id)
static lookupObjectiveIdsBySequence(int $a_container_id, int $a_seq_id)
static getLogger(string $a_component_id)
Get component logger.
__construct(int $a_container_id, int $a_objective_id, int $a_test_type, int $a_qpl_sequence)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
quote($value, string $type)
static toXml(ilXmlWriter $writer, int $a_objective_id)
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$query
static lookupSequencesByType(int $a_container_id, int $a_objective_id, int $a_test_id, int $a_test_type)
copy(int $a_copy_id, int $a_new_course_id, int $a_new_objective_id)
static _getInstance(int $a_copy_id)
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
manipulate(string $query)
Run a (write) Query on the database.
static deleteForObjectiveAndTestType(int $a_course_id, int $a_objective_id, int $a_tst_type)