ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTestRandomQuestionSetSourcePoolDefinition.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
17 protected $db = null;
18
24 protected $testOBJ = null;
25
26 private $id = null;
27
28 private $poolId = null;
29
31 private $poolRefId = null;
32
33 private $poolTitle = null;
34
35 private $poolPath = null;
36
37 private $poolQuestionCount = null;
38
39 // fau: taxFilter/typeFilter - new class variables
40 #private $originalFilterTaxId = null;
41
42 #private $originalFilterTaxNodeId = null;
43
44 #private $mappedFilterTaxId = null;
45
46 #private $mappedFilterTaxNodeId = null;
47
51 private $originalTaxonomyFilter = array();
52
56 private $mappedTaxonomyFilter = array();
57
61 private $typeFilter = array();
62 // fau.
63 // fau.
64
68 private $lifecycleFilter = array();
69
70 private $questionAmount = null;
71
72 private $sequencePosition = null;
73
75 {
76 $this->db = $db;
77 $this->testOBJ = $testOBJ;
78 }
79
80 public function setId($id)
81 {
82 $this->id = $id;
83 }
84
85 public function getId()
86 {
87 return $this->id;
88 }
89
90 public function setPoolId($poolId)
91 {
92 $this->poolId = $poolId;
93 }
94
95 public function getPoolId()
96 {
97 return $this->poolId;
98 }
99
100 public function getPoolRefId() : ?int
101 {
102 return $this->poolRefId;
103 }
104
105 public function setPoolRefId(?int $poolRefId) : void
106 {
107 $this->poolRefId = $poolRefId;
108 }
109
110 public function setPoolTitle($poolTitle)
111 {
112 $this->poolTitle = $poolTitle;
113 }
114
115 public function getPoolTitle()
116 {
117 return $this->poolTitle;
118 }
119
120 public function setPoolPath($poolPath)
121 {
122 $this->poolPath = $poolPath;
123 }
124
125 public function getPoolPath()
126 {
127 return $this->poolPath;
128 }
129
131 {
132 $this->poolQuestionCount = $poolQuestionCount;
133 }
134
135 public function getPoolQuestionCount()
136 {
138 }
139
140 // fau: taxFilter/typeFilter - new setters/getters
146 {
148 }
149
154 public function setOriginalTaxonomyFilter($filter = array())
155 {
156 $this->originalTaxonomyFilter = $filter;
157 }
158
164 {
165 // TODO-RND2017: migrate to separate table for common selections by e.g. statistics
166 return empty($this->originalTaxonomyFilter) ? null : serialize($this->originalTaxonomyFilter);
167 }
168
174 {
175 // TODO-RND2017: migrate to separate table for common selections by e.g. statistics
176 $this->originalTaxonomyFilter = empty($value) ? array() : unserialize($value);
177 }
178
183 public function getMappedTaxonomyFilter()
184 {
186 }
187
192 public function setMappedTaxonomyFilter($filter = array())
193 {
194 $this->mappedTaxonomyFilter = $filter;
195 }
196
202 {
203 return empty($this->mappedTaxonomyFilter) ? null : serialize($this->mappedTaxonomyFilter);
204 }
205
210 private function setMappedTaxonomyFilterFromDbValue($value)
211 {
212 $this->mappedTaxonomyFilter = empty($value) ? array() : unserialize($value);
213 }
214
215
221 {
222 $this->mappedTaxonomyFilter = array();
223 foreach ($this->originalTaxonomyFilter as $taxId => $nodeIds) {
224 $mappedNodeIds = array();
225 foreach ($nodeIds as $nodeId) {
226 $mappedNodeIds[] = $taxonomiesKeysMap->getMappedTaxNodeId($nodeId);
227 }
228 $this->mappedTaxonomyFilter[$taxonomiesKeysMap->getMappedTaxonomyId($taxId)] = $mappedNodeIds;
229 }
230 }
231
232 public function setTypeFilter($typeFilter = array())
233 {
234 $this->typeFilter = $typeFilter;
235 }
236
237 public function getTypeFilter()
238 {
239 return $this->typeFilter;
240 }
241
246 private function getTypeFilterForDbValue()
247 {
248 return empty($this->typeFilter) ? null : serialize($this->typeFilter);
249 }
250
255 private function setTypeFilterFromDbValue($value)
256 {
257 $this->typeFilter = empty($value) ? array() : unserialize($value);
258 }
259
263 public function getLifecycleFilter()
264 {
266 }
267
272 {
273 $this->lifecycleFilter = $lifecycleFilter;
274 }
275
280 {
281 return empty($this->lifecycleFilter) ? null : serialize($this->lifecycleFilter);
282 }
283
287 public function setLifecycleFilterFromDbValue($dbValue)
288 {
289 $this->lifecycleFilter = empty($dbValue) ? array() : unserialize($dbValue);
290 }
291
296 public function getTypeFilterAsTypeTags() : array
297 {
298 $map = [];
299 foreach (ilObjQuestionPool::_getQuestionTypes(true) as $row) {
300 $map[$row['question_type_id']] = $row['type_tag'];
301 }
302
303 $tags = [];
304 foreach ($this->typeFilter as $type_id) {
305 if (isset($map[$type_id])) {
306 $tags[] = $map[$type_id];
307 }
308 }
309
310 return $tags;
311 }
312
317 public function setTypeFilterFromTypeTags(array $tags)
318 {
319 $map = [];
320 foreach (ilObjQuestionPool::_getQuestionTypes(true) as $row) {
321 $map[$row['type_tag']] = $row['question_type_id'];
322 }
323
324 $this->typeFilter = [];
325 foreach ($tags as $type_tag) {
326 if (isset($map[$type_tag])) {
327 $this->typeFilter[] = $map[$type_tag];
328 }
329 }
330 }
331
332
333 /*
334 public function setOriginalFilterTaxId($originalFilterTaxId)
335 {
336 $this->originalFilterTaxId = $originalFilterTaxId;
337 }
338
339 public function getOriginalFilterTaxId()
340 {
341 return $this->originalFilterTaxId;
342 }
343
344 public function setOriginalFilterTaxNodeId($originalFilterNodeId)
345 {
346 $this->originalFilterTaxNodeId = $originalFilterNodeId;
347 }
348
349 public function getOriginalFilterTaxNodeId()
350 {
351 return $this->originalFilterTaxNodeId;
352 }
353
354 public function setMappedFilterTaxId($mappedFilterTaxId)
355 {
356 $this->mappedFilterTaxId = $mappedFilterTaxId;
357 }
358
359 public function getMappedFilterTaxId()
360 {
361 return $this->mappedFilterTaxId;
362 }
363
364 public function setMappedFilterTaxNodeId($mappedFilterTaxNodeId)
365 {
366 $this->mappedFilterTaxNodeId = $mappedFilterTaxNodeId;
367 }
368
369 public function getMappedFilterTaxNodeId()
370 {
371 return $this->mappedFilterTaxNodeId;
372 }
373 */
374 // fau.
375
377 {
378 $this->questionAmount = $questionAmount;
379 }
380
381 public function getQuestionAmount()
382 {
384 }
385
387 {
388 $this->sequencePosition = $sequencePosition;
389 }
390
391 public function getSequencePosition()
392 {
394 }
395
396 // -----------------------------------------------------------------------------------------------------------------
397
401 public function initFromArray($dataArray)
402 {
403 foreach ($dataArray as $field => $value) {
404 switch ($field) {
405 case 'def_id': $this->setId($value); break;
406 case 'pool_fi': $this->setPoolId($value); break;
407 case 'pool_ref_id': $this->setPoolRefId($value ? (int) $value : null); break;
408 case 'pool_title': $this->setPoolTitle($value); break;
409 case 'pool_path': $this->setPoolPath($value); break;
410 case 'pool_quest_count': $this->setPoolQuestionCount($value); break;
411 // fau: taxFilter - use new db fields
412 #case 'origin_tax_fi': $this->setOriginalFilterTaxId($value); break;
413 #case 'origin_node_fi': $this->setOriginalFilterTaxNodeId($value); break;
414 #case 'mapped_tax_fi': $this->setMappedFilterTaxId($value); break;
415 #case 'mapped_node_fi': $this->setMappedFilterTaxNodeId($value); break;
416 case 'origin_tax_filter': $this->setOriginalTaxonomyFilterFromDbValue($value); break;
417 case 'mapped_tax_filter': $this->setMappedTaxonomyFilterFromDbValue($value); break;
418 case 'type_filter': $this->setTypeFilterFromDbValue($value); break;
419 case 'lifecycle_filter': $this->setLifecycleFilterFromDbValue($value); break;
420 // fau.
421 case 'quest_amount': $this->setQuestionAmount($value); break;
422 case 'sequence_pos': $this->setSequencePosition($value); break;
423 }
424 }
425 }
426
431 public function loadFromDb($id)
432 {
433 $res = $this->db->queryF(
434 "SELECT * FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
435 array('integer'),
436 array($id)
437 );
438
439 while ($row = $this->db->fetchAssoc($res)) {
440 $this->initFromArray($row);
441
442 return true;
443 }
444
445 return false;
446 }
447
448 public function saveToDb()
449 {
450 if ($this->getId()) {
451 $this->updateDbRecord($this->testOBJ->getTestId());
452 } else {
453 $this->insertDbRecord($this->testOBJ->getTestId());
454 }
455 }
456
457 public function cloneToDbForTestId($testId)
458 {
459 $this->insertDbRecord($testId);
460 }
461
462 public function deleteFromDb()
463 {
464 $this->db->manipulateF(
465 "DELETE FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
466 array('integer'),
467 array($this->getId())
468 );
469 }
470
474 private function updateDbRecord($testId)
475 {
476 $this->db->update(
477 'tst_rnd_quest_set_qpls',
478 array(
479 'test_fi' => array('integer', $testId),
480 'pool_fi' => array('integer', $this->getPoolId()),
481 'pool_ref_id' => array('integer', $this->getPoolRefId()),
482 'pool_title' => array('text', $this->getPoolTitle()),
483 'pool_path' => array('text', $this->getPoolPath()),
484 'pool_quest_count' => array('integer', $this->getPoolQuestionCount()),
485 'origin_tax_filter' => array('text', $this->getOriginalTaxonomyFilterForDbValue()),
486 'mapped_tax_filter' => array('text', $this->getMappedTaxonomyFilterForDbValue()),
487 'type_filter' => array('text', $this->getTypeFilterForDbValue()),
488 'lifecycle_filter' => array('text', $this->getLifecycleFilterForDbValue()),
489 'quest_amount' => array('integer', $this->getQuestionAmount()),
490 'sequence_pos' => array('integer', $this->getSequencePosition())
491 ),
492 array(
493 'def_id' => array('integer', $this->getId())
494 )
495 );
496 }
497
501 private function insertDbRecord($testId)
502 {
503 $nextId = $this->db->nextId('tst_rnd_quest_set_qpls');
504
505 $this->db->insert('tst_rnd_quest_set_qpls', array(
506 'def_id' => array('integer', $nextId),
507 'test_fi' => array('integer', $testId),
508 'pool_fi' => array('integer', $this->getPoolId()),
509 'pool_ref_id' => array('integer', $this->getPoolRefId()),
510 'pool_title' => array('text', $this->getPoolTitle()),
511 'pool_path' => array('text', $this->getPoolPath()),
512 'pool_quest_count' => array('integer', $this->getPoolQuestionCount()),
513 'origin_tax_filter' => array('text', $this->getOriginalTaxonomyFilterForDbValue()),
514 'mapped_tax_filter' => array('text', $this->getMappedTaxonomyFilterForDbValue()),
515 'type_filter' => array('text', $this->getTypeFilterForDbValue()),
516 'lifecycle_filter' => array('text', $this->getLifecycleFilterForDbValue()),
517 'quest_amount' => array('integer', $this->getQuestionAmount()),
518 'sequence_pos' => array('integer', $this->getSequencePosition())
519 ));
520
521 $this->setId($nextId);
522 }
523
524 // -----------------------------------------------------------------------------------------------------------------
525
527 {
528 $pool_path = $this->getPoolPath();
529 if (is_int($this->getPoolRefId()) && ilObject::_lookupObjId($this->getPoolRefId())) {
530 $path = new ilPathGUI();
531 $path->enableTextOnly(true);
532 $pool_path = $path->getPath(ROOT_FOLDER_ID, $this->getPoolRefId());
533 }
534
535 $poolInfoLabel = sprintf(
536 $lng->txt('tst_dynamic_question_set_source_questionpool_summary_string'),
537 $this->getPoolTitle(),
538 $pool_path,
539 $this->getPoolQuestionCount()
540 );
541
542 return $poolInfoLabel;
543 }
544
545 // -----------------------------------------------------------------------------------------------------------------
546}
An exception for terminatinating execution or to throw for unit testing.
language handling
static _getQuestionTypes($all_tags=false, $fixOrder=false, $withDeprecatedTypes=true)
static _lookupObjId($a_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:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$lng
foreach($_POST as $key=> $value) $res