ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
65  private $questionAmount = null;
66 
67  private $sequencePosition = null;
68 
70  {
71  $this->db = $db;
72  $this->testOBJ = $testOBJ;
73  }
74 
75  public function setId($id)
76  {
77  $this->id = $id;
78  }
79 
80  public function getId()
81  {
82  return $this->id;
83  }
84 
85  public function setPoolId($poolId)
86  {
87  $this->poolId = $poolId;
88  }
89 
90  public function getPoolId()
91  {
92  return $this->poolId;
93  }
94 
95  public function getPoolRefId() : ?int
96  {
97  return $this->poolRefId;
98  }
99 
100  public function setPoolRefId(?int $poolRefId) : void
101  {
102  $this->poolRefId = $poolRefId;
103  }
104 
105  public function setPoolTitle($poolTitle)
106  {
107  $this->poolTitle = $poolTitle;
108  }
109 
110  public function getPoolTitle()
111  {
112  return $this->poolTitle;
113  }
114 
115  public function setPoolPath($poolPath)
116  {
117  $this->poolPath = $poolPath;
118  }
119 
120  public function getPoolPath()
121  {
122  return $this->poolPath;
123  }
124 
126  {
127  $this->poolQuestionCount = $poolQuestionCount;
128  }
129 
130  public function getPoolQuestionCount()
131  {
133  }
134 
135  // fau: taxFilter/typeFilter - new setters/getters
140  public function getOriginalTaxonomyFilter()
141  {
143  }
144 
149  public function setOriginalTaxonomyFilter($filter = array())
150  {
151  $this->originalTaxonomyFilter = $filter;
152  }
153 
159  {
160  // TODO-RND2017: migrate to separate table for common selections by e.g. statistics
161  return empty($this->originalTaxonomyFilter) ? null : serialize($this->originalTaxonomyFilter);
162  }
163 
168  private function setOriginalTaxonomyFilterFromDbValue($value)
169  {
170  // TODO-RND2017: migrate to separate table for common selections by e.g. statistics
171  $this->originalTaxonomyFilter = empty($value) ? array() : unserialize($value);
172  }
173 
178  public function getMappedTaxonomyFilter()
179  {
181  }
182 
187  public function setMappedTaxonomyFilter($filter = array())
188  {
189  $this->mappedTaxonomyFilter = $filter;
190  }
191 
197  {
198  return empty($this->mappedTaxonomyFilter) ? null : serialize($this->mappedTaxonomyFilter);
199  }
200 
205  private function setMappedTaxonomyFilterFromDbValue($value)
206  {
207  $this->mappedTaxonomyFilter = empty($value) ? array() : unserialize($value);
208  }
209 
210 
216  {
217  $this->mappedTaxonomyFilter = array();
218  foreach ($this->originalTaxonomyFilter as $taxId => $nodeIds) {
219  $mappedNodeIds = array();
220  foreach ($nodeIds as $nodeId) {
221  $mappedNodeIds[] = $taxonomiesKeysMap->getMappedTaxNodeId($nodeId);
222  }
223  $this->mappedTaxonomyFilter[$taxonomiesKeysMap->getMappedTaxonomyId($taxId)] = $mappedNodeIds;
224  }
225  }
226 
227  public function setTypeFilter($typeFilter = array())
228  {
229  $this->typeFilter = $typeFilter;
230  }
231 
232  public function getTypeFilter()
233  {
234  return $this->typeFilter;
235  }
236 
241  private function getTypeFilterForDbValue()
242  {
243  return empty($this->typeFilter) ? null : serialize($this->typeFilter);
244  }
245 
250  private function setTypeFilterFromDbValue($value)
251  {
252  $this->typeFilter = empty($value) ? array() : unserialize($value);
253  }
254  /*
255  public function setOriginalFilterTaxId($originalFilterTaxId)
256  {
257  $this->originalFilterTaxId = $originalFilterTaxId;
258  }
259 
260  public function getOriginalFilterTaxId()
261  {
262  return $this->originalFilterTaxId;
263  }
264 
265  public function setOriginalFilterTaxNodeId($originalFilterNodeId)
266  {
267  $this->originalFilterTaxNodeId = $originalFilterNodeId;
268  }
269 
270  public function getOriginalFilterTaxNodeId()
271  {
272  return $this->originalFilterTaxNodeId;
273  }
274 
275  public function setMappedFilterTaxId($mappedFilterTaxId)
276  {
277  $this->mappedFilterTaxId = $mappedFilterTaxId;
278  }
279 
280  public function getMappedFilterTaxId()
281  {
282  return $this->mappedFilterTaxId;
283  }
284 
285  public function setMappedFilterTaxNodeId($mappedFilterTaxNodeId)
286  {
287  $this->mappedFilterTaxNodeId = $mappedFilterTaxNodeId;
288  }
289 
290  public function getMappedFilterTaxNodeId()
291  {
292  return $this->mappedFilterTaxNodeId;
293  }
294  */
295  // fau.
296 
298  {
299  $this->questionAmount = $questionAmount;
300  }
301 
302  public function getQuestionAmount()
303  {
304  return $this->questionAmount;
305  }
306 
308  {
309  $this->sequencePosition = $sequencePosition;
310  }
311 
312  public function getSequencePosition()
313  {
315  }
316 
317  // -----------------------------------------------------------------------------------------------------------------
318 
322  public function initFromArray($dataArray)
323  {
324  foreach ($dataArray as $field => $value) {
325  switch ($field) {
326  case 'def_id': $this->setId($value); break;
327  case 'pool_fi': $this->setPoolId($value); break;
328  case 'pool_ref_id': $this->setPoolRefId($value ? (int) $value : null); break;
329  case 'pool_title': $this->setPoolTitle($value); break;
330  case 'pool_path': $this->setPoolPath($value); break;
331  case 'pool_quest_count': $this->setPoolQuestionCount($value); break;
332  // fau: taxFilter - use new db fields
333  #case 'origin_tax_fi': $this->setOriginalFilterTaxId($value); break;
334  #case 'origin_node_fi': $this->setOriginalFilterTaxNodeId($value); break;
335  #case 'mapped_tax_fi': $this->setMappedFilterTaxId($value); break;
336  #case 'mapped_node_fi': $this->setMappedFilterTaxNodeId($value); break;
337  case 'origin_tax_filter': $this->setOriginalTaxonomyFilterFromDbValue($value); break;
338  case 'mapped_tax_filter': $this->setMappedTaxonomyFilterFromDbValue($value); break;
339  case 'type_filter': $this->setTypeFilterFromDbValue($value); break;
340  // fau.
341  case 'quest_amount': $this->setQuestionAmount($value); break;
342  case 'sequence_pos': $this->setSequencePosition($value); break;
343  }
344  }
345  }
346 
351  public function loadFromDb($id)
352  {
353  $res = $this->db->queryF(
354  "SELECT * FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
355  array('integer'),
356  array($id)
357  );
358 
359  while ($row = $this->db->fetchAssoc($res)) {
360  $this->initFromArray($row);
361 
362  return true;
363  }
364 
365  return false;
366  }
367 
368  public function saveToDb()
369  {
370  if ($this->getId()) {
371  $this->updateDbRecord($this->testOBJ->getTestId());
372  } else {
373  $this->insertDbRecord($this->testOBJ->getTestId());
374  }
375  }
376 
377  public function cloneToDbForTestId($testId)
378  {
379  $this->insertDbRecord($testId);
380  }
381 
382  public function deleteFromDb()
383  {
384  $this->db->manipulateF(
385  "DELETE FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
386  array('integer'),
387  array($this->getId())
388  );
389  }
390 
394  private function updateDbRecord($testId)
395  {
396  $this->db->update(
397  'tst_rnd_quest_set_qpls',
398  array(
399  'test_fi' => array('integer', $testId),
400  'pool_fi' => array('integer', $this->getPoolId()),
401  'pool_ref_id' => array('integer', $this->getPoolRefId()),
402  'pool_title' => array('text', $this->getPoolTitle()),
403  'pool_path' => array('text', $this->getPoolPath()),
404  'pool_quest_count' => array('integer', $this->getPoolQuestionCount()),
405  // fau: taxFilter/typeFilter - use new db fields
406  #'origin_tax_fi' => array('integer', $this->getOriginalFilterTaxId()),
407  #'origin_node_fi' => array('integer', $this->getOriginalFilterTaxNodeId()),
408  #'mapped_tax_fi' => array('integer', $this->getMappedFilterTaxId()),
409  #'mapped_node_fi' => array('integer', $this->getMappedFilterTaxNodeId()),
410  'origin_tax_filter' => array('text', $this->getOriginalTaxonomyFilterForDbValue()),
411  'mapped_tax_filter' => array('text', $this->getMappedTaxonomyFilterForDbValue()),
412  'type_filter' => array('text', $this->getTypeFilterForDbValue()),
413  // fau.
414  'quest_amount' => array('integer', $this->getQuestionAmount()),
415  'sequence_pos' => array('integer', $this->getSequencePosition())
416  ),
417  array(
418  'def_id' => array('integer', $this->getId())
419  )
420  );
421  }
422 
426  private function insertDbRecord($testId)
427  {
428  $nextId = $this->db->nextId('tst_rnd_quest_set_qpls');
429 
430  $this->db->insert('tst_rnd_quest_set_qpls', array(
431  'def_id' => array('integer', $nextId),
432  'test_fi' => array('integer', $testId),
433  'pool_fi' => array('integer', $this->getPoolId()),
434  'pool_ref_id' => array('integer', $this->getPoolRefId()),
435  'pool_title' => array('text', $this->getPoolTitle()),
436  'pool_path' => array('text', $this->getPoolPath()),
437  'pool_quest_count' => array('integer', $this->getPoolQuestionCount()),
438  // fau: taxFilter/typeFilter - use new db fields
439  #'origin_tax_fi' => array('integer', $this->getOriginalFilterTaxId()),
440  #'origin_node_fi' => array('integer', $this->getOriginalFilterTaxNodeId()),
441  #'mapped_tax_fi' => array('integer', $this->getMappedFilterTaxId()),
442  #'mapped_node_fi' => array('integer', $this->getMappedFilterTaxNodeId()),
443  'origin_tax_filter' => array('text', $this->getOriginalTaxonomyFilterForDbValue()),
444  'mapped_tax_filter' => array('text', $this->getMappedTaxonomyFilterForDbValue()),
445  'type_filter' => array('text', $this->getTypeFilterForDbValue()),
446  // fau.
447  'quest_amount' => array('integer', $this->getQuestionAmount()),
448  'sequence_pos' => array('integer', $this->getSequencePosition())
449  ));
450 
451  $this->setId($nextId);
452  }
453 
454  // -----------------------------------------------------------------------------------------------------------------
455 
457  {
458  $pool_path = $this->getPoolPath();
459  if (is_int($this->getPoolRefId()) && ilObject::_lookupObjId($this->getPoolRefId())) {
460  $path = new ilPathGUI();
461  $path->enableTextOnly(true);
462  $pool_path = $path->getPath(ROOT_FOLDER_ID, $this->getPoolRefId());
463  }
464 
465  $poolInfoLabel = sprintf(
466  $lng->txt('tst_dynamic_question_set_source_questionpool_summary_string'),
467  $this->getPoolTitle(),
468  $pool_path,
469  $this->getPoolQuestionCount()
470  );
471 
472  return $poolInfoLabel;
473  }
474 
475  // -----------------------------------------------------------------------------------------------------------------
476 }
Creates a path for a start and endnode.
$path
Definition: aliased.php:25
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
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
$row
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