ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
145  public function getOriginalTaxonomyFilter()
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 
173  private function setOriginalTaxonomyFilterFromDbValue($value)
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  {
265  return $this->lifecycleFilter;
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 
292  /*
293  public function setOriginalFilterTaxId($originalFilterTaxId)
294  {
295  $this->originalFilterTaxId = $originalFilterTaxId;
296  }
297 
298  public function getOriginalFilterTaxId()
299  {
300  return $this->originalFilterTaxId;
301  }
302 
303  public function setOriginalFilterTaxNodeId($originalFilterNodeId)
304  {
305  $this->originalFilterTaxNodeId = $originalFilterNodeId;
306  }
307 
308  public function getOriginalFilterTaxNodeId()
309  {
310  return $this->originalFilterTaxNodeId;
311  }
312 
313  public function setMappedFilterTaxId($mappedFilterTaxId)
314  {
315  $this->mappedFilterTaxId = $mappedFilterTaxId;
316  }
317 
318  public function getMappedFilterTaxId()
319  {
320  return $this->mappedFilterTaxId;
321  }
322 
323  public function setMappedFilterTaxNodeId($mappedFilterTaxNodeId)
324  {
325  $this->mappedFilterTaxNodeId = $mappedFilterTaxNodeId;
326  }
327 
328  public function getMappedFilterTaxNodeId()
329  {
330  return $this->mappedFilterTaxNodeId;
331  }
332  */
333  // fau.
334 
336  {
337  $this->questionAmount = $questionAmount;
338  }
339 
340  public function getQuestionAmount()
341  {
342  return $this->questionAmount;
343  }
344 
346  {
347  $this->sequencePosition = $sequencePosition;
348  }
349 
350  public function getSequencePosition()
351  {
353  }
354 
355  // -----------------------------------------------------------------------------------------------------------------
356 
360  public function initFromArray($dataArray)
361  {
362  foreach ($dataArray as $field => $value) {
363  switch ($field) {
364  case 'def_id': $this->setId($value); break;
365  case 'pool_fi': $this->setPoolId($value); break;
366  case 'pool_ref_id': $this->setPoolRefId($value ? (int) $value : null); break;
367  case 'pool_title': $this->setPoolTitle($value); break;
368  case 'pool_path': $this->setPoolPath($value); break;
369  case 'pool_quest_count': $this->setPoolQuestionCount($value); break;
370  // fau: taxFilter - use new db fields
371  #case 'origin_tax_fi': $this->setOriginalFilterTaxId($value); break;
372  #case 'origin_node_fi': $this->setOriginalFilterTaxNodeId($value); break;
373  #case 'mapped_tax_fi': $this->setMappedFilterTaxId($value); break;
374  #case 'mapped_node_fi': $this->setMappedFilterTaxNodeId($value); break;
375  case 'origin_tax_filter': $this->setOriginalTaxonomyFilterFromDbValue($value); break;
376  case 'mapped_tax_filter': $this->setMappedTaxonomyFilterFromDbValue($value); break;
377  case 'type_filter': $this->setTypeFilterFromDbValue($value); break;
378  case 'lifecycle_filter': $this->setLifecycleFilterFromDbValue($value); break;
379  // fau.
380  case 'quest_amount': $this->setQuestionAmount($value); break;
381  case 'sequence_pos': $this->setSequencePosition($value); break;
382  }
383  }
384  }
385 
390  public function loadFromDb($id)
391  {
392  $res = $this->db->queryF(
393  "SELECT * FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
394  array('integer'),
395  array($id)
396  );
397 
398  while ($row = $this->db->fetchAssoc($res)) {
399  $this->initFromArray($row);
400 
401  return true;
402  }
403 
404  return false;
405  }
406 
407  public function saveToDb()
408  {
409  if ($this->getId()) {
410  $this->updateDbRecord($this->testOBJ->getTestId());
411  } else {
412  $this->insertDbRecord($this->testOBJ->getTestId());
413  }
414  }
415 
416  public function cloneToDbForTestId($testId)
417  {
418  $this->insertDbRecord($testId);
419  }
420 
421  public function deleteFromDb()
422  {
423  $this->db->manipulateF(
424  "DELETE FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
425  array('integer'),
426  array($this->getId())
427  );
428  }
429 
433  private function updateDbRecord($testId)
434  {
435  $this->db->update(
436  'tst_rnd_quest_set_qpls',
437  array(
438  'test_fi' => array('integer', $testId),
439  'pool_fi' => array('integer', $this->getPoolId()),
440  'pool_ref_id' => array('integer', $this->getPoolRefId()),
441  'pool_title' => array('text', $this->getPoolTitle()),
442  'pool_path' => array('text', $this->getPoolPath()),
443  'pool_quest_count' => array('integer', $this->getPoolQuestionCount()),
444  // fau: taxFilter/typeFilter - use new db fields
445  #'origin_tax_fi' => array('integer', $this->getOriginalFilterTaxId()),
446  #'origin_node_fi' => array('integer', $this->getOriginalFilterTaxNodeId()),
447  #'mapped_tax_fi' => array('integer', $this->getMappedFilterTaxId()),
448  #'mapped_node_fi' => array('integer', $this->getMappedFilterTaxNodeId()),
449  'origin_tax_filter' => array('text', $this->getOriginalTaxonomyFilterForDbValue()),
450  'mapped_tax_filter' => array('text', $this->getMappedTaxonomyFilterForDbValue()),
451  'type_filter' => array('text', $this->getTypeFilterForDbValue()),
452  'lifecycle_filter' => array('text', $this->getLifecycleFilterForDbValue()),
453  // fau.
454  'quest_amount' => array('integer', $this->getQuestionAmount()),
455  'sequence_pos' => array('integer', $this->getSequencePosition())
456  ),
457  array(
458  'def_id' => array('integer', $this->getId())
459  )
460  );
461  }
462 
466  private function insertDbRecord($testId)
467  {
468  $nextId = $this->db->nextId('tst_rnd_quest_set_qpls');
469 
470  $this->db->insert('tst_rnd_quest_set_qpls', array(
471  'def_id' => array('integer', $nextId),
472  'test_fi' => array('integer', $testId),
473  'pool_fi' => array('integer', $this->getPoolId()),
474  'pool_ref_id' => array('integer', $this->getPoolRefId()),
475  'pool_title' => array('text', $this->getPoolTitle()),
476  'pool_path' => array('text', $this->getPoolPath()),
477  'pool_quest_count' => array('integer', $this->getPoolQuestionCount()),
478  // fau: taxFilter/typeFilter - use new db fields
479  #'origin_tax_fi' => array('integer', $this->getOriginalFilterTaxId()),
480  #'origin_node_fi' => array('integer', $this->getOriginalFilterTaxNodeId()),
481  #'mapped_tax_fi' => array('integer', $this->getMappedFilterTaxId()),
482  #'mapped_node_fi' => array('integer', $this->getMappedFilterTaxNodeId()),
483  'origin_tax_filter' => array('text', $this->getOriginalTaxonomyFilterForDbValue()),
484  'mapped_tax_filter' => array('text', $this->getMappedTaxonomyFilterForDbValue()),
485  'type_filter' => array('text', $this->getTypeFilterForDbValue()),
486  'lifecycle_filter' => array('text', $this->getLifecycleFilterForDbValue()),
487  // fau.
488  'quest_amount' => array('integer', $this->getQuestionAmount()),
489  'sequence_pos' => array('integer', $this->getSequencePosition())
490  ));
491 
492  $this->setId($nextId);
493  }
494 
495  // -----------------------------------------------------------------------------------------------------------------
496 
498  {
499  $pool_path = $this->getPoolPath();
500  if (is_int($this->getPoolRefId()) && ilObject::_lookupObjId($this->getPoolRefId())) {
501  $path = new ilPathGUI();
502  $path->enableTextOnly(true);
503  $pool_path = $path->getPath(ROOT_FOLDER_ID, $this->getPoolRefId());
504  }
505 
506  $poolInfoLabel = sprintf(
507  $lng->txt('tst_dynamic_question_set_source_questionpool_summary_string'),
508  $this->getPoolTitle(),
509  $pool_path,
510  $this->getPoolQuestionCount()
511  );
512 
513  return $poolInfoLabel;
514  }
515 
516  // -----------------------------------------------------------------------------------------------------------------
517 }
Creates a path for a start and endnode.
setOriginalTaxonomyFilter($filter=array())
set the original taxonomy filter condition
setOriginalTaxonomyFilterFromDbValue($value)
get the original taxonomy filter from database value
setMappedTaxonomyFilterFromDbValue($value)
get the original taxonomy filter from database value
setTypeFilterFromDbValue($value)
get the question type filter from database value
Interface ilDBInterface.
setMappedTaxonomyFilter($filter=array())
set the original taxonomy filter condition
foreach($_POST as $key=> $value) $res
$lng
getOriginalTaxonomyFilterForDbValue()
get the original taxonomy filter for insert into the database
static _lookupObjId($a_id)
mapTaxonomyFilter(ilQuestionPoolDuplicatedTaxonomiesKeysMap $taxonomiesKeysMap)
set the mapped taxonomy filter from original by applying a keys map
language handling
getTypeFilterForDbValue()
get the question type filter for insert into the database
txt($a_topic, $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
getMappedTaxonomyFilterForDbValue()
get the original taxonomy filter for insert into the database