ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestRandomQuestionSetSourcePoolDefinition.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 private ?int $id = null;
30 private ?int $pool_id = null;
31 private ?int $pool_ref_id = null;
32 private ?string $pool_title = null;
33 private ?string $pool_path = null;
34 private ?int $pool_question_count = null;
35
39 private array $original_taxonomy_filter = [];
40
44 private array $mapped_taxonomy_filter = [];
45
46 private array $type_filter = [];
47 private array $lifecycle_filter = [];
48
49 private ?int $question_amount = null;
50
51 private ?int $sequence_position = null;
52
53 public function __construct(
54 protected ilDBInterface $db,
55 protected ilObjTest $test_obj
56 ) {
57 }
58
59 public function setId(int $id): void
60 {
61 $this->id = $id;
62 }
63
64 public function getId(): ?int
65 {
66 return $this->id;
67 }
68
69 public function setPoolId(int $pool_id): void
70 {
71 $this->pool_id = $pool_id;
72 }
73
74 public function getPoolId(): ?int
75 {
76 return $this->pool_id;
77 }
78
79 public function getPoolRefId(): ?int
80 {
81 return $this->pool_ref_id;
82 }
83
84 public function setPoolRefId(?int $pool_ref_id): void
85 {
86 $this->pool_ref_id = $pool_ref_id;
87 }
88
89 public function setPoolTitle(string $pool_title): void
90 {
91 $this->pool_title = $pool_title;
92 }
93
94 public function getPoolTitle(): string
95 {
96 return $this->pool_title;
97 }
98
99 public function setPoolPath(?string $pool_path): void
100 {
101 $this->pool_path = $pool_path;
102 }
103
104 public function getPoolPath(): ?string
105 {
106 return $this->pool_path;
107 }
108
109 public function setPoolQuestionCount(?int $pool_question_count): void
110 {
111 $this->pool_question_count = $pool_question_count;
112 }
113
114 public function getPoolQuestionCount(): ?int
115 {
117 }
118
119 public function getOriginalTaxonomyFilter(): array
120 {
122 }
123
124 public function setOriginalTaxonomyFilter(array $filter = []): void
125 {
126 $this->original_taxonomy_filter = $filter;
127 }
128
129 private function getOriginalTaxonomyFilterForDbValue(): ?string
130 {
131 // TODO-RND2017: migrate to separate table for common selections by e.g. statistics
132 return empty($this->original_taxonomy_filter) ? null : serialize($this->original_taxonomy_filter);
133 }
134
135 private function setOriginalTaxonomyFilterFromDbValue(?string $value): void
136 {
137 // TODO-RND2017: migrate to separate table for common selections by e.g. statistics
138 $this->original_taxonomy_filter = empty($value) ? [] : unserialize($value);
139 }
140
145 public function getMappedTaxonomyFilter(): array
146 {
148 }
149
154 public function setMappedTaxonomyFilter(array $filter = []): void
155 {
156 $this->mapped_taxonomy_filter = $filter;
157 }
158
159 private function getMappedTaxonomyFilterForDbValue(): ?string
160 {
161 return empty($this->mapped_taxonomy_filter) ? null : serialize($this->mapped_taxonomy_filter);
162 }
163
164 private function setMappedTaxonomyFilterFromDbValue(?string $value): void
165 {
166 $this->mapped_taxonomy_filter = empty($value) ? [] : unserialize($value);
167 }
168
169 public function mapTaxonomyFilter(ilQuestionPoolDuplicatedTaxonomiesKeysMap $taxonomies_keys_map): void
170 {
171 $this->mapped_taxonomy_filter = [];
172 foreach ($this->original_taxonomy_filter as $tax_id => $node_ids) {
173 $mapped_node_ids = [];
174
175 $mapped_taxonomy_id = $taxonomies_keys_map->getMappedTaxonomyId($tax_id);
176 if ($mapped_taxonomy_id === null) {
177 continue;
178 }
179
180 foreach ($node_ids as $node_id) {
181 $mapped_node_id = $taxonomies_keys_map->getMappedTaxNodeId($node_id);
182 if ($mapped_node_id !== null) {
183 $mapped_node_ids[] = $mapped_node_id;
184 }
185 }
186 $this->mapped_taxonomy_filter[] = $mapped_node_ids;
187 }
188 }
189
190 public function setTypeFilter(array $type_filter = []): void
191 {
192 $this->type_filter = $type_filter;
193 }
194
195 public function getTypeFilter(): array
196 {
197 return $this->type_filter;
198 }
199
203 private function getTypeFilterForDbValue(): ?string
204 {
205 return empty($this->type_filter) ? null : serialize($this->type_filter);
206 }
207
211 private function setTypeFilterFromDbValue(?string $value): void
212 {
213 $this->type_filter = empty($value) ? [] : unserialize($value);
214 }
215
216 public function getLifecycleFilter(): array
217 {
219 }
220
221 public function setLifecycleFilter(array $lifecycle_filter): void
222 {
223 $this->lifecycle_filter = $lifecycle_filter;
224 }
225
226 public function getLifecycleFilterForDbValue(): ?string
227 {
228 return empty($this->lifecycle_filter) ? null : serialize($this->lifecycle_filter);
229 }
230
231 public function setLifecycleFilterFromDbValue(?string $db_value)
232 {
233 $this->lifecycle_filter = empty($db_value) ? [] : unserialize($db_value);
234 }
235
240 public function getTypeFilterAsTypeTags(): array
241 {
242 $map = [];
243 foreach (ilObjQuestionPool::_getQuestionTypes(true) as $row) {
244 $map[$row['question_type_id']] = $row['type_tag'];
245 }
246
247 $tags = [];
248 foreach ($this->type_filter as $type_id) {
249 if (isset($map[$type_id])) {
250 $tags[] = $map[$type_id];
251 }
252 }
253
254 return $tags;
255 }
256
261 public function setTypeFilterFromTypeTags(array $tags): void
262 {
263 $map = [];
264 foreach (ilObjQuestionPool::_getQuestionTypes(true) as $row) {
265 $map[$row['type_tag']] = $row['question_type_id'];
266 }
267
268 $this->type_filter = [];
269 foreach ($tags as $type_tag) {
270 if (isset($map[$type_tag])) {
271 $this->type_filter[] = $map[$type_tag];
272 }
273 }
274 }
275
276 public function setQuestionAmount(?int $question_amount): void
277 {
278 $this->question_amount = $question_amount;
279 }
280
281 public function getQuestionAmount(): ?int
282 {
284 }
285
286 public function setSequencePosition(int $sequence_position): void
287 {
288 $this->sequence_position = $sequence_position;
289 }
290
291 public function getSequencePosition(): ?int
292 {
294 }
295
296 // -----------------------------------------------------------------------------------------------------------------
297
298 public function initFromArray(array $data_array): void
299 {
300 foreach ($data_array as $field => $value) {
301 switch ($field) {
302 case 'def_id':
303 $this->setId($value);
304 break;
305 case 'pool_fi':
306 $this->setPoolId($value);
307 break;
308 case 'pool_ref_id':
309 $this->setPoolRefId($value ? (int) $value : null);
310 break;
311 case 'pool_title':
312 $this->setPoolTitle($value ?? '');
313 break;
314 case 'pool_path':
315 $this->setPoolPath($value);
316 break;
317 case 'pool_quest_count':
318 $this->setPoolQuestionCount($value);
319 break;
320 case 'origin_tax_filter':
322 break;
323 case 'mapped_tax_filter':
325 break;
326 case 'type_filter':
327 $this->setTypeFilterFromDbValue($value);
328 break;
329 case 'lifecycle_filter':
330 $this->setLifecycleFilterFromDbValue($value);
331 break;
332 // fau.
333 case 'quest_amount':
334 $this->setQuestionAmount($value);
335 break;
336 case 'sequence_pos':
337 $this->setSequencePosition($value);
338 break;
339 }
340 }
341 }
342
343 public function loadFromDb(int $id): bool
344 {
345 $res = $this->db->queryF(
346 "SELECT * FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
347 ['integer'],
348 [$id]
349 );
350
351 while ($row = $this->db->fetchAssoc($res)) {
352 $this->initFromArray($row);
353
354 return true;
355 }
356
357 return false;
358 }
359
360 public function saveToDb(): void
361 {
362 if ($this->getId()) {
363 $this->updateDbRecord($this->test_obj->getTestId());
364 return;
365 }
366
367 $this->insertDbRecord($this->test_obj->getTestId());
368 }
369
370 public function cloneToDbForTestId(int $test_id): void
371 {
372 $this->insertDbRecord($test_id);
373 }
374
375 public function deleteFromDb(): void
376 {
377 $this->db->manipulateF(
378 "DELETE FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
379 ['integer'],
380 [$this->getId()]
381 );
382 }
383
384 private function updateDbRecord(int $test_id): void
385 {
386 $this->db->update(
387 'tst_rnd_quest_set_qpls',
388 [
389 'test_fi' => ['integer', $test_id],
390 'pool_fi' => ['integer', $this->getPoolId()],
391 'pool_ref_id' => ['integer', $this->getPoolRefId()],
392 'pool_title' => ['text', $this->getPoolTitle()],
393 'pool_path' => ['text', $this->getPoolPath()],
394 'pool_quest_count' => ['integer', $this->getPoolQuestionCount()],
395 'origin_tax_filter' => ['text', $this->getOriginalTaxonomyFilterForDbValue()],
396 'mapped_tax_filter' => ['text', $this->getMappedTaxonomyFilterForDbValue()],
397 'type_filter' => ['text', $this->getTypeFilterForDbValue()],
398 'lifecycle_filter' => ['text', $this->getLifecycleFilterForDbValue()],
399 'quest_amount' => ['integer', $this->getQuestionAmount()],
400 'sequence_pos' => ['integer', $this->getSequencePosition()]
401 ],
402 [
403 'def_id' => ['integer', $this->getId()]
404 ]
405 );
406 }
407
408 private function insertDbRecord(int $test_id): void
409 {
410 $next_id = $this->db->nextId('tst_rnd_quest_set_qpls');
411
412 $this->db->insert('tst_rnd_quest_set_qpls', [
413 'def_id' => ['integer', $next_id],
414 'test_fi' => ['integer', $test_id],
415 'pool_fi' => ['integer', $this->getPoolId()],
416 'pool_ref_id' => ['integer', $this->getPoolRefId()],
417 'pool_title' => ['text', $this->getPoolTitle()],
418 'pool_path' => ['text', $this->getPoolPath()],
419 'pool_quest_count' => ['integer', $this->getPoolQuestionCount()],
420 'origin_tax_filter' => ['text', $this->getOriginalTaxonomyFilterForDbValue()],
421 'mapped_tax_filter' => ['text', $this->getMappedTaxonomyFilterForDbValue()],
422 'type_filter' => ['text', $this->getTypeFilterForDbValue()],
423 'lifecycle_filter' => ['text', $this->getLifecycleFilterForDbValue()],
424 'quest_amount' => ['integer', $this->getQuestionAmount()],
425 'sequence_pos' => ['integer', $this->getSequencePosition()]
426 ]);
427
428 $this->setId($next_id);
429 }
430
431 // -----------------------------------------------------------------------------------------------------------------
432
433 public function getPoolInfoLabel(ilLanguage $lng): string
434 {
435 $pool_path = $this->getPoolPath();
436 if (is_int($this->getPoolRefId()) && ilObject::_lookupObjId($this->getPoolRefId())) {
437 $path = new ilPathGUI();
438 $path->enableTextOnly(true);
439 $pool_path = $path->getPath(ROOT_FOLDER_ID, (int) $this->getPoolRefId());
440 }
441
442 $poolInfoLabel = sprintf(
443 $lng->txt('tst_random_question_set_source_questionpool_summary_string'),
444 $this->getPoolTitle(),
446 $this->getPoolQuestionCount()
447 );
448
449 return $poolInfoLabel;
450 }
451
452 // -----------------------------------------------------------------------------------------------------------------
453}
language handling
static _getQuestionTypes($all_tags=false, $fixOrder=false, $withDeprecatedTypes=true)
static _lookupObjId(int $ref_id)
setTypeFilterFromTypeTags(array $tags)
Set the type filter from a list of type tags.
setMappedTaxonomyFilter(array $filter=[])
set the original taxonomy filter condition
mapTaxonomyFilter(ilQuestionPoolDuplicatedTaxonomiesKeysMap $taxonomies_keys_map)
__construct(protected ilDBInterface $db, protected ilObjTest $test_obj)
getTypeFilterForDbValue()
get the question type filter for insert into the database
setTypeFilterFromDbValue(?string $value)
get the question type filter from database value
const ROOT_FOLDER_ID
Definition: constants.php:32
Interface ilDBInterface.
$path
Definition: ltiservices.php:30
$res
Definition: ltiservices.php:69
global $lng
Definition: privfeed.php:31