ILIAS  release_8 Revision v8.24
class.ilTestRandomQuestionSetSourcePoolDefinition.php
Go to the documentation of this file.
1<?php
2
26{
32 protected $db = null;
33
39 protected $testOBJ = null;
40
41 private $id = null;
42
43 private $poolId = null;
44
46 private $poolRefId = null;
47
48 private $poolTitle = null;
49
50 private $poolPath = null;
51
52 private $poolQuestionCount = null;
53
54 // fau: taxFilter/typeFilter - new class variables
55 #private $originalFilterTaxId = null;
56
57 #private $originalFilterTaxNodeId = null;
58
59 #private $mappedFilterTaxId = null;
60
61 #private $mappedFilterTaxNodeId = null;
62
66 private $originalTaxonomyFilter = array();
67
71 private $mappedTaxonomyFilter = array();
72
76 private $typeFilter = array();
77 // fau.
78 // fau.
79
83 private $lifecycleFilter = array();
84
85 private $questionAmount = null;
86
87 private $sequencePosition = null;
88
90 {
91 $this->db = $db;
92 $this->testOBJ = $testOBJ;
93 }
94
95 public function setId($id)
96 {
97 $this->id = $id;
98 }
99
100 public function getId()
101 {
102 return $this->id;
103 }
104
105 public function setPoolId($poolId)
106 {
107 $this->poolId = $poolId;
108 }
109
110 public function getPoolId()
111 {
112 return $this->poolId;
113 }
114
115 public function getPoolRefId(): ?int
116 {
117 return $this->poolRefId;
118 }
119
120 public function setPoolRefId(?int $poolRefId): void
121 {
122 $this->poolRefId = $poolRefId;
123 }
124
125 public function setPoolTitle($poolTitle)
126 {
127 $this->poolTitle = $poolTitle;
128 }
129
130 public function getPoolTitle()
131 {
132 return $this->poolTitle;
133 }
134
135 public function setPoolPath($poolPath)
136 {
137 $this->poolPath = $poolPath;
138 }
139
140 public function getPoolPath()
141 {
142 return $this->poolPath;
143 }
144
146 {
147 $this->poolQuestionCount = $poolQuestionCount;
148 }
149
150 public function getPoolQuestionCount()
151 {
153 }
154
155 // fau: taxFilter/typeFilter - new setters/getters
160 public function getOriginalTaxonomyFilter(): array
161 {
163 }
164
169 public function setOriginalTaxonomyFilter($filter = array())
170 {
171 $this->originalTaxonomyFilter = $filter;
172 }
173
178 private function getOriginalTaxonomyFilterForDbValue(): ?string
179 {
180 // TODO-RND2017: migrate to separate table for common selections by e.g. statistics
181 return empty($this->originalTaxonomyFilter) ? null : serialize($this->originalTaxonomyFilter);
182 }
183
189 {
190 // TODO-RND2017: migrate to separate table for common selections by e.g. statistics
191 $this->originalTaxonomyFilter = empty($value) ? array() : unserialize($value);
192 }
193
198 public function getMappedTaxonomyFilter(): array
199 {
201 }
202
207 public function setMappedTaxonomyFilter($filter = array())
208 {
209 $this->mappedTaxonomyFilter = $filter;
210 }
211
216 private function getMappedTaxonomyFilterForDbValue(): ?string
217 {
218 return empty($this->mappedTaxonomyFilter) ? null : serialize($this->mappedTaxonomyFilter);
219 }
220
225 private function setMappedTaxonomyFilterFromDbValue($value)
226 {
227 $this->mappedTaxonomyFilter = empty($value) ? array() : unserialize($value);
228 }
229
230
236 {
237 $this->mappedTaxonomyFilter = array();
238 foreach ($this->originalTaxonomyFilter as $taxId => $nodeIds) {
239 $mappedNodeIds = array();
240 foreach ($nodeIds as $nodeId) {
241 $mappedNodeIds[] = $taxonomiesKeysMap->getMappedTaxNodeId($nodeId);
242 }
243 $this->mappedTaxonomyFilter[$taxonomiesKeysMap->getMappedTaxonomyId($taxId)] = $mappedNodeIds;
244 }
245 }
246
247 public function setTypeFilter($typeFilter = array())
248 {
249 $this->typeFilter = $typeFilter;
250 }
251
252 public function getTypeFilter(): array
253 {
254 return $this->typeFilter;
255 }
256
261 private function getTypeFilterForDbValue(): ?string
262 {
263 return empty($this->typeFilter) ? null : serialize($this->typeFilter);
264 }
265
270 private function setTypeFilterFromDbValue($value)
271 {
272 $this->typeFilter = empty($value) ? array() : unserialize($value);
273 }
274
278 public function getLifecycleFilter(): array
279 {
281 }
282
287 {
288 $this->lifecycleFilter = $lifecycleFilter;
289 }
290
294 public function getLifecycleFilterForDbValue(): ?string
295 {
296 return empty($this->lifecycleFilter) ? null : serialize($this->lifecycleFilter);
297 }
298
302 public function setLifecycleFilterFromDbValue($dbValue)
303 {
304 $this->lifecycleFilter = empty($dbValue) ? array() : unserialize($dbValue);
305 }
306
311 public function getTypeFilterAsTypeTags(): array
312 {
313 $map = [];
314 foreach (ilObjQuestionPool::_getQuestionTypes(true) as $row) {
315 $map[$row['question_type_id']] = $row['type_tag'];
316 }
317
318 $tags = [];
319 foreach ($this->typeFilter as $type_id) {
320 if (isset($map[$type_id])) {
321 $tags[] = $map[$type_id];
322 }
323 }
324
325 return $tags;
326 }
327
332 public function setTypeFilterFromTypeTags(array $tags)
333 {
334 $map = [];
335 foreach (ilObjQuestionPool::_getQuestionTypes(true) as $row) {
336 $map[$row['type_tag']] = $row['question_type_id'];
337 }
338
339 $this->typeFilter = [];
340 foreach ($tags as $type_tag) {
341 if (isset($map[$type_tag])) {
342 $this->typeFilter[] = $map[$type_tag];
343 }
344 }
345 }
346
348 {
349 $this->questionAmount = $questionAmount;
350 }
351
352 public function getQuestionAmount()
353 {
355 }
356
358 {
359 $this->sequencePosition = $sequencePosition;
360 }
361
362 public function getSequencePosition()
363 {
365 }
366
367 // -----------------------------------------------------------------------------------------------------------------
368
372 public function initFromArray($dataArray)
373 {
374 foreach ($dataArray as $field => $value) {
375 switch ($field) {
376 case 'def_id':
377 $this->setId($value);
378 break;
379 case 'pool_fi':
380 $this->setPoolId($value);
381 break;
382 case 'pool_ref_id':
383 $this->setPoolRefId($value ? (int) $value : null);
384 break;
385 case 'pool_title':
386 $this->setPoolTitle($value);
387 break;
388 case 'pool_path':
389 $this->setPoolPath($value);
390 break;
391 case 'pool_quest_count':
392 $this->setPoolQuestionCount($value);
393 break;
394 case 'origin_tax_filter':
396 break;
397 case 'mapped_tax_filter':
399 break;
400 case 'type_filter':
401 $this->setTypeFilterFromDbValue($value);
402 break;
403 case 'lifecycle_filter':
404 $this->setLifecycleFilterFromDbValue($value);
405 break;
406 // fau.
407 case 'quest_amount':
408 $this->setQuestionAmount($value);
409 break;
410 case 'sequence_pos':
411 $this->setSequencePosition($value);
412 break;
413 }
414 }
415 }
416
421 public function loadFromDb($id): bool
422 {
423 $res = $this->db->queryF(
424 "SELECT * FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
425 array('integer'),
426 array($id)
427 );
428
429 while ($row = $this->db->fetchAssoc($res)) {
430 $this->initFromArray($row);
431
432 return true;
433 }
434
435 return false;
436 }
437
438 public function saveToDb()
439 {
440 if ($this->getId()) {
441 $this->updateDbRecord($this->testOBJ->getTestId());
442 } else {
443 $this->insertDbRecord($this->testOBJ->getTestId());
444 }
445 }
446
447 public function cloneToDbForTestId($testId)
448 {
449 $this->insertDbRecord($testId);
450 }
451
452 public function deleteFromDb()
453 {
454 $this->db->manipulateF(
455 "DELETE FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
456 array('integer'),
457 array($this->getId())
458 );
459 }
460
464 private function updateDbRecord($testId)
465 {
466 $this->db->update(
467 'tst_rnd_quest_set_qpls',
468 array(
469 'test_fi' => array('integer', $testId),
470 'pool_fi' => array('integer', $this->getPoolId()),
471 'pool_ref_id' => array('integer', $this->getPoolRefId()),
472 'pool_title' => array('text', $this->getPoolTitle()),
473 'pool_path' => array('text', $this->getPoolPath()),
474 'pool_quest_count' => array('integer', $this->getPoolQuestionCount()),
475 'origin_tax_filter' => array('text', $this->getOriginalTaxonomyFilterForDbValue()),
476 'mapped_tax_filter' => array('text', $this->getMappedTaxonomyFilterForDbValue()),
477 'type_filter' => array('text', $this->getTypeFilterForDbValue()),
478 'lifecycle_filter' => array('text', $this->getLifecycleFilterForDbValue()),
479 'quest_amount' => array('integer', $this->getQuestionAmount()),
480 'sequence_pos' => array('integer', $this->getSequencePosition())
481 ),
482 array(
483 'def_id' => array('integer', $this->getId())
484 )
485 );
486 }
487
491 private function insertDbRecord($testId)
492 {
493 $nextId = $this->db->nextId('tst_rnd_quest_set_qpls');
494
495 $this->db->insert('tst_rnd_quest_set_qpls', array(
496 'def_id' => array('integer', $nextId),
497 'test_fi' => array('integer', $testId),
498 'pool_fi' => array('integer', $this->getPoolId()),
499 'pool_ref_id' => array('integer', $this->getPoolRefId()),
500 'pool_title' => array('text', $this->getPoolTitle()),
501 'pool_path' => array('text', $this->getPoolPath()),
502 'pool_quest_count' => array('integer', $this->getPoolQuestionCount()),
503 'origin_tax_filter' => array('text', $this->getOriginalTaxonomyFilterForDbValue()),
504 'mapped_tax_filter' => array('text', $this->getMappedTaxonomyFilterForDbValue()),
505 'type_filter' => array('text', $this->getTypeFilterForDbValue()),
506 'lifecycle_filter' => array('text', $this->getLifecycleFilterForDbValue()),
507 'quest_amount' => array('integer', $this->getQuestionAmount()),
508 'sequence_pos' => array('integer', $this->getSequencePosition())
509 ));
510
511 $this->setId($nextId);
512 }
513
514 // -----------------------------------------------------------------------------------------------------------------
515
516 public function getPoolInfoLabel(ilLanguage $lng): string
517 {
518 $pool_path = $this->getPoolPath();
519 if (is_int($this->getPoolRefId()) && ilObject::_lookupObjId($this->getPoolRefId())) {
520 $path = new ilPathGUI();
521 $path->enableTextOnly(true);
522 $pool_path = $path->getPath(ROOT_FOLDER_ID, (int) $this->getPoolRefId());
523 }
524
525 $poolInfoLabel = sprintf(
526 $lng->txt('tst_dynamic_question_set_source_questionpool_summary_string'),
527 $this->getPoolTitle(),
528 $pool_path,
529 $this->getPoolQuestionCount()
530 );
531
532 return $poolInfoLabel;
533 }
534
535 // -----------------------------------------------------------------------------------------------------------------
536}
language handling
static _getQuestionTypes($all_tags=false, $fixOrder=false, $withDeprecatedTypes=true)
static _lookupObjId(int $ref_id)
Creates a path for a start and endnode.
getOriginalTaxonomyFilterForDbValue()
get the original taxonomy filter for insert into the database
setTypeFilterFromTypeTags(array $tags)
Set the type filter from a list of type tags.
setTypeFilterFromDbValue($value)
get the question type filter from database value
mapTaxonomyFilter(ilQuestionPoolDuplicatedTaxonomiesKeysMap $taxonomiesKeysMap)
set the mapped taxonomy filter from original by applying a keys map
setOriginalTaxonomyFilter($filter=array())
set the original taxonomy filter condition
setMappedTaxonomyFilter($filter=array())
set the original taxonomy filter condition
getMappedTaxonomyFilterForDbValue()
get the original taxonomy filter for insert into the database
setOriginalTaxonomyFilterFromDbValue($value)
get the original taxonomy filter from database value
setMappedTaxonomyFilterFromDbValue($value)
get the original taxonomy filter from database value
getTypeFilterForDbValue()
get the question type filter for insert into the database
const ROOT_FOLDER_ID
Definition: constants.php:32
Interface ilDBInterface.
$path
Definition: ltiservices.php:32
$res
Definition: ltiservices.php:69
$lng