ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
30  private $poolTitle = null;
31 
32  private $poolPath = null;
33 
34  private $poolQuestionCount = null;
35 
36  // fau: taxFilter/typeFilter - new class variables
37  #private $originalFilterTaxId = null;
38 
39  #private $originalFilterTaxNodeId = null;
40 
41  #private $mappedFilterTaxId = null;
42 
43  #private $mappedFilterTaxNodeId = null;
44 
49 
54 
58  private $typeFilter = array();
59  // fau.
60  // fau.
61 
62  private $questionAmount = null;
63 
64  private $sequencePosition = null;
65 
67  {
68  $this->db = $db;
69  $this->testOBJ = $testOBJ;
70  }
71 
72  public function setId($id)
73  {
74  $this->id = $id;
75  }
76 
77  public function getId()
78  {
79  return $this->id;
80  }
81 
82  public function setPoolId($poolId)
83  {
84  $this->poolId = $poolId;
85  }
86 
87  public function getPoolId()
88  {
89  return $this->poolId;
90  }
91 
92  public function setPoolTitle($poolTitle)
93  {
94  $this->poolTitle = $poolTitle;
95  }
96 
97  public function getPoolTitle()
98  {
99  return $this->poolTitle;
100  }
101 
102  public function setPoolPath($poolPath)
103  {
104  $this->poolPath = $poolPath;
105  }
106 
107  public function getPoolPath()
108  {
109  return $this->poolPath;
110  }
111 
113  {
114  $this->poolQuestionCount = $poolQuestionCount;
115  }
116 
117  public function getPoolQuestionCount()
118  {
120  }
121 
122  // fau: taxFilter/typeFilter - new setters/getters
127  public function getOriginalTaxonomyFilter()
128  {
130  }
131 
136  public function setOriginalTaxonomyFilter($filter = array())
137  {
138  $this->originalTaxonomyFilter = $filter;
139  }
140 
146  {
147  // TODO-RND2017: migrate to separate table for common selections by e.g. statistics
148  return empty($this->originalTaxonomyFilter) ? null : serialize($this->originalTaxonomyFilter);
149  }
150 
155  private function setOriginalTaxonomyFilterFromDbValue($value)
156  {
157  // TODO-RND2017: migrate to separate table for common selections by e.g. statistics
158  $this->originalTaxonomyFilter = empty($value) ? array() : unserialize($value);
159  }
160 
165  public function getMappedTaxonomyFilter()
166  {
168  }
169 
174  public function setMappedTaxonomyFilter($filter = array())
175  {
176  $this->mappedTaxonomyFilter = $filter;
177  }
178 
184  {
185  return empty($this->mappedTaxonomyFilter) ? null : serialize($this->mappedTaxonomyFilter);
186  }
187 
192  private function setMappedTaxonomyFilterFromDbValue($value)
193  {
194  $this->mappedTaxonomyFilter = empty($value) ? array() : unserialize($value);
195  }
196 
197 
203  {
204  $this->mappedTaxonomyFilter = array();
205  foreach ($this->originalTaxonomyFilter as $taxId => $nodeIds) {
206  $mappedNodeIds = array();
207  foreach ($nodeIds as $nodeId) {
208  $mappedNodeIds[] = $taxonomiesKeysMap->getMappedTaxNodeId($nodeId);
209  }
210  $this->mappedTaxonomyFilter[$taxonomiesKeysMap->getMappedTaxonomyId($taxId)] = $mappedNodeIds;
211  }
212  }
213 
214  public function setTypeFilter($typeFilter = array())
215  {
216  $this->typeFilter = $typeFilter;
217  }
218 
219  public function getTypeFilter()
220  {
221  return $this->typeFilter;
222  }
223 
228  private function getTypeFilterForDbValue()
229  {
230  return empty($this->typeFilter) ? null : serialize($this->typeFilter);
231  }
232 
237  private function setTypeFilterFromDbValue($value)
238  {
239  $this->typeFilter = empty($value) ? array() : unserialize($value);
240  }
241  /*
242  public function setOriginalFilterTaxId($originalFilterTaxId)
243  {
244  $this->originalFilterTaxId = $originalFilterTaxId;
245  }
246 
247  public function getOriginalFilterTaxId()
248  {
249  return $this->originalFilterTaxId;
250  }
251 
252  public function setOriginalFilterTaxNodeId($originalFilterNodeId)
253  {
254  $this->originalFilterTaxNodeId = $originalFilterNodeId;
255  }
256 
257  public function getOriginalFilterTaxNodeId()
258  {
259  return $this->originalFilterTaxNodeId;
260  }
261 
262  public function setMappedFilterTaxId($mappedFilterTaxId)
263  {
264  $this->mappedFilterTaxId = $mappedFilterTaxId;
265  }
266 
267  public function getMappedFilterTaxId()
268  {
269  return $this->mappedFilterTaxId;
270  }
271 
272  public function setMappedFilterTaxNodeId($mappedFilterTaxNodeId)
273  {
274  $this->mappedFilterTaxNodeId = $mappedFilterTaxNodeId;
275  }
276 
277  public function getMappedFilterTaxNodeId()
278  {
279  return $this->mappedFilterTaxNodeId;
280  }
281  */
282  // fau.
283 
285  {
286  $this->questionAmount = $questionAmount;
287  }
288 
289  public function getQuestionAmount()
290  {
291  return $this->questionAmount;
292  }
293 
295  {
296  $this->sequencePosition = $sequencePosition;
297  }
298 
299  public function getSequencePosition()
300  {
302  }
303 
304  // -----------------------------------------------------------------------------------------------------------------
305 
309  public function initFromArray($dataArray)
310  {
311  foreach ($dataArray as $field => $value) {
312  switch ($field) {
313  case 'def_id': $this->setId($value); break;
314  case 'pool_fi': $this->setPoolId($value); break;
315  case 'pool_title': $this->setPoolTitle($value); break;
316  case 'pool_path': $this->setPoolPath($value); break;
317  case 'pool_quest_count': $this->setPoolQuestionCount($value); break;
318  // fau: taxFilter - use new db fields
319  #case 'origin_tax_fi': $this->setOriginalFilterTaxId($value); break;
320  #case 'origin_node_fi': $this->setOriginalFilterTaxNodeId($value); break;
321  #case 'mapped_tax_fi': $this->setMappedFilterTaxId($value); break;
322  #case 'mapped_node_fi': $this->setMappedFilterTaxNodeId($value); break;
323  case 'origin_tax_filter': $this->setOriginalTaxonomyFilterFromDbValue($value); break;
324  case 'mapped_tax_filter': $this->setMappedTaxonomyFilterFromDbValue($value); break;
325  case 'type_filter': $this->setTypeFilterFromDbValue($value); break;
326  // fau.
327  case 'quest_amount': $this->setQuestionAmount($value); break;
328  case 'sequence_pos': $this->setSequencePosition($value); break;
329  }
330  }
331  }
332 
337  public function loadFromDb($id)
338  {
339  $res = $this->db->queryF(
340  "SELECT * FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
341  array('integer'),
342  array($id)
343  );
344 
345  while ($row = $this->db->fetchAssoc($res)) {
346  $this->initFromArray($row);
347 
348  return true;
349  }
350 
351  return false;
352  }
353 
354  public function saveToDb()
355  {
356  if ($this->getId()) {
357  $this->updateDbRecord($this->testOBJ->getTestId());
358  } else {
359  $this->insertDbRecord($this->testOBJ->getTestId());
360  }
361  }
362 
363  public function cloneToDbForTestId($testId)
364  {
365  $this->insertDbRecord($testId);
366  }
367 
368  public function deleteFromDb()
369  {
370  $this->db->manipulateF(
371  "DELETE FROM tst_rnd_quest_set_qpls WHERE def_id = %s",
372  array('integer'),
373  array($this->getId())
374  );
375  }
376 
380  private function updateDbRecord($testId)
381  {
382  $this->db->update(
383  'tst_rnd_quest_set_qpls',
384  array(
385  'test_fi' => array('integer', $testId),
386  'pool_fi' => array('integer', $this->getPoolId()),
387  'pool_title' => array('text', $this->getPoolTitle()),
388  'pool_path' => array('text', $this->getPoolPath()),
389  'pool_quest_count' => array('integer', $this->getPoolQuestionCount()),
390  // fau: taxFilter/typeFilter - use new db fields
391  #'origin_tax_fi' => array('integer', $this->getOriginalFilterTaxId()),
392  #'origin_node_fi' => array('integer', $this->getOriginalFilterTaxNodeId()),
393  #'mapped_tax_fi' => array('integer', $this->getMappedFilterTaxId()),
394  #'mapped_node_fi' => array('integer', $this->getMappedFilterTaxNodeId()),
395  'origin_tax_filter' => array('text', $this->getOriginalTaxonomyFilterForDbValue()),
396  'mapped_tax_filter' => array('text', $this->getMappedTaxonomyFilterForDbValue()),
397  'type_filter' => array('text', $this->getTypeFilterForDbValue()),
398  // fau.
399  'quest_amount' => array('integer', $this->getQuestionAmount()),
400  'sequence_pos' => array('integer', $this->getSequencePosition())
401  ),
402  array(
403  'def_id' => array('integer', $this->getId())
404  )
405  );
406  }
407 
411  private function insertDbRecord($testId)
412  {
413  $nextId = $this->db->nextId('tst_rnd_quest_set_qpls');
414 
415  $this->db->insert('tst_rnd_quest_set_qpls', array(
416  'def_id' => array('integer', $nextId),
417  'test_fi' => array('integer', $testId),
418  'pool_fi' => array('integer', $this->getPoolId()),
419  'pool_title' => array('text', $this->getPoolTitle()),
420  'pool_path' => array('text', $this->getPoolPath()),
421  'pool_quest_count' => array('integer', $this->getPoolQuestionCount()),
422  // fau: taxFilter/typeFilter - use new db fields
423  #'origin_tax_fi' => array('integer', $this->getOriginalFilterTaxId()),
424  #'origin_node_fi' => array('integer', $this->getOriginalFilterTaxNodeId()),
425  #'mapped_tax_fi' => array('integer', $this->getMappedFilterTaxId()),
426  #'mapped_node_fi' => array('integer', $this->getMappedFilterTaxNodeId()),
427  'origin_tax_filter' => array('text', $this->getOriginalTaxonomyFilterForDbValue()),
428  'mapped_tax_filter' => array('text', $this->getMappedTaxonomyFilterForDbValue()),
429  'type_filter' => array('text', $this->getTypeFilterForDbValue()),
430  // fau.
431  'quest_amount' => array('integer', $this->getQuestionAmount()),
432  'sequence_pos' => array('integer', $this->getSequencePosition())
433  ));
434 
435  $this->setId($nextId);
436  }
437 
438  // -----------------------------------------------------------------------------------------------------------------
439 
441  {
442  $poolInfoLabel = sprintf(
443  $lng->txt('tst_dynamic_question_set_source_questionpool_summary_string'),
444  $this->getPoolTitle(),
445  $this->getPoolPath(),
446  $this->getPoolQuestionCount()
447  );
448 
449  return $poolInfoLabel;
450  }
451 
452  // -----------------------------------------------------------------------------------------------------------------
453 }
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
$dataArray
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
getOriginalTaxonomyFilterForDbValue()
get the original taxonomy filter for insert into the database
mapTaxonomyFilter(ilQuestionPoolDuplicatedTaxonomiesKeysMap $taxonomiesKeysMap)
set the mapped taxonomy filter from original by applying a keys map
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
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