ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilTestRandomQuestionSetStagingPoolBuilder Class Reference
+ Collaboration diagram for ilTestRandomQuestionSetStagingPoolBuilder:

Public Member Functions

 __construct (ilDBInterface $db, ilObjTest $testOBJ)
 
 rebuild (ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
 
 reset ()
 

Data Fields

 $db = null
 
 $testOBJ = null
 

Private Member Functions

 removeMirroredTaxonomies ()
 
 removeStagedQuestions ()
 
 build (ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
 
 stageQuestionsFromSourcePool ($sourcePoolId)
 
 buildCheap (ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
 
 stageQuestionsFromSourcePoolCheap ($sourcePoolId, $questionIdMappingPerPool, $filterIds=null, $typeFilter=null)
 
 mirrorSourcePoolTaxonomies ($sourcePoolId, $questionIdMapping)
 
 cleanupTestSettings ()
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilTestRandomQuestionSetStagingPoolBuilder::__construct ( ilDBInterface  $db,
ilObjTest  $testOBJ 
)

Member Function Documentation

◆ build()

ilTestRandomQuestionSetStagingPoolBuilder::build ( ilTestRandomQuestionSetSourcePoolDefinitionList  $sourcePoolDefinitionList)
private

Definition at line 89 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

References mirrorSourcePoolTaxonomies(), and stageQuestionsFromSourcePool().

90  {
91  $involvedSourcePoolIds = $sourcePoolDefinitionList->getInvolvedSourcePoolIds();
92 
93  foreach ($involvedSourcePoolIds as $sourcePoolId) {
94  $questionIdMapping = $this->stageQuestionsFromSourcePool($sourcePoolId);
95 
96  $taxonomiesKeysMap = $this->mirrorSourcePoolTaxonomies($sourcePoolId, $questionIdMapping);
97 
98  $this->applyMappedTaxonomiesKeys($sourcePoolDefinitionList, $taxonomiesKeysMap, $sourcePoolId);
99  }
100  }
+ Here is the call graph for this function:

◆ buildCheap()

ilTestRandomQuestionSetStagingPoolBuilder::buildCheap ( ilTestRandomQuestionSetSourcePoolDefinitionList  $sourcePoolDefinitionList)
private

Definition at line 128 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

References array, ilObjTaxonomy\getSubTreeItems(), mirrorSourcePoolTaxonomies(), and stageQuestionsFromSourcePoolCheap().

Referenced by rebuild().

129  {
130  // TODO-RND2017: refactor using assQuestionList and wrap with assQuestionListCollection for unioning
131 
132  $questionIdMappingPerPool = array();
133 
134  // select questions to be copied by the definitions
135  // note: a question pool may appear many times in this list
136 
137  /* @var ilTestRandomQuestionSetSourcePoolDefinition $definition */
138  foreach ($sourcePoolDefinitionList as $definition) {
139  $taxFilter = $definition->getOriginalTaxonomyFilter();
140  $typeFilter = $definition->getTypeFilter();
141 
142  if (!empty($taxFilter)) {
143  require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
144 
145  $filterItems = null;
146  foreach ($taxFilter as $taxId => $nodeIds) {
147  $taxItems = array();
148  foreach ($nodeIds as $nodeId) {
149  $nodeItems = ilObjTaxonomy::getSubTreeItems(
150  'qpl',
151  $definition->getPoolId(),
152  'quest',
153  $taxId,
154  $nodeId
155  );
156 
157  foreach ($nodeItems as $nodeItem) {
158  $taxItems[] = $nodeItem['item_id'];
159  }
160  }
161 
162  $filterItems = isset($filterItems) ? array_intersect($filterItems, array_unique($taxItems)) : array_unique($taxItems);
163  }
164 
165  // stage only the questions applying to the tax/type filter
166  // and save the duplication map for later use
167 
168  $questionIdMappingPerPool = $this->stageQuestionsFromSourcePoolCheap(
169  $definition->getPoolId(),
170  $questionIdMappingPerPool,
171  array_values($filterItems),
172  $typeFilter
173  );
174  } else {
175  // stage only the questions applying to the tax/type filter
176  // and save the duplication map for later use
177 
178  $questionIdMappingPerPool = $this->stageQuestionsFromSourcePoolCheap(
179  $definition->getPoolId(),
180  $questionIdMappingPerPool,
181  null,
182  $typeFilter
183  );
184  }
185  }
186 
187  // copy the taxonomies to the test and map them
188  foreach ($questionIdMappingPerPool as $sourcePoolId => $questionIdMapping) {
189  $taxonomiesKeysMap = $this->mirrorSourcePoolTaxonomies($sourcePoolId, $questionIdMapping);
190  $this->applyMappedTaxonomiesKeys($sourcePoolDefinitionList, $taxonomiesKeysMap, $sourcePoolId);
191  }
192  }
stageQuestionsFromSourcePoolCheap($sourcePoolId, $questionIdMappingPerPool, $filterIds=null, $typeFilter=null)
Create styles array
The data for the language used.
static getSubTreeItems($a_comp, $a_obj_id, $a_item_type, $a_tax_id, $a_node)
Get all assigned items under a node.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cleanupTestSettings()

ilTestRandomQuestionSetStagingPoolBuilder::cleanupTestSettings ( )
private

Definition at line 270 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

References array.

Referenced by reset().

271  {
272  $this->testOBJ->setResultFilterTaxIds(array());
273  $this->testOBJ->saveToDb(true);
274  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ mirrorSourcePoolTaxonomies()

ilTestRandomQuestionSetStagingPoolBuilder::mirrorSourcePoolTaxonomies (   $sourcePoolId,
  $questionIdMapping 
)
private

Definition at line 229 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

Referenced by build(), and buildCheap().

230  {
231  $duplicator = new ilQuestionPoolTaxonomiesDuplicator();
232 
233  $duplicator->setSourceObjId($sourcePoolId);
234  $duplicator->setSourceObjType('qpl');
235  $duplicator->setTargetObjId($this->testOBJ->getId());
236  $duplicator->setTargetObjType($this->testOBJ->getType());
237  $duplicator->setQuestionIdMapping($questionIdMapping);
238 
239  $duplicator->duplicate($duplicator->getAllTaxonomiesForSourceObject());
240 
241  return $duplicator->getDuplicatedTaxonomiesKeysMap();
242  }
+ Here is the caller graph for this function:

◆ rebuild()

ilTestRandomQuestionSetStagingPoolBuilder::rebuild ( ilTestRandomQuestionSetSourcePoolDefinitionList  $sourcePoolDefinitionList)

Definition at line 34 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

References buildCheap(), and reset().

35  {
36  $this->reset();
37 
38  // fau: taxFilter/typeFilter - copy only the needed questions, and copy every question only once
39  // TODO-RND2017: remove non cheap methods and rename cheap ones
40  #$this->build($sourcePoolDefinitionList);
41  $this->buildCheap($sourcePoolDefinitionList);
42  // fau.
43  }
buildCheap(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
+ Here is the call graph for this function:

◆ removeMirroredTaxonomies()

ilTestRandomQuestionSetStagingPoolBuilder::removeMirroredTaxonomies ( )
private

Definition at line 54 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

References ilObjTaxonomy\getUsageOfObject().

Referenced by reset().

55  {
56  $taxonomyIds = ilObjTaxonomy::getUsageOfObject($this->testOBJ->getId());
57 
58  foreach ($taxonomyIds as $taxId) {
59  $taxonomy = new ilObjTaxonomy($taxId);
60  $taxonomy->delete();
61  }
62  }
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeStagedQuestions()

ilTestRandomQuestionSetStagingPoolBuilder::removeStagedQuestions ( )
private

Definition at line 64 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

References $GLOBALS, $query, $res, $row, assQuestion\_instanciateQuestion(), and array.

Referenced by reset().

65  {
66  $query = 'SELECT * FROM tst_rnd_cpy WHERE tst_fi = %s';
67  $res = $this->db->queryF(
68  $query,
69  array('integer'),
70  array($this->testOBJ->getTestId())
71  );
72 
73  while ($row = $this->db->fetchAssoc($res)) {
74  $question = assQuestion::_instanciateQuestion($row['qst_fi']);
75 
76  if ($question instanceof assQuestion) {
77  $question->delete($row['qst_fi']);
78  } else {
79  $GLOBALS['ilLog']->warning(
80  "could not delete staged random question (ref={$this->testOBJ->getRefId()} / qst={$row['qst_fi']})"
81  );
82  }
83  }
84 
85  $query = "DELETE FROM tst_rnd_cpy WHERE tst_fi = %s";
86  $this->db->manipulateF($query, array('integer'), array($this->testOBJ->getTestId()));
87  }
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
Abstract basic class which is to be extended by the concrete assessment question type classes...
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

ilTestRandomQuestionSetStagingPoolBuilder::reset ( )

◆ stageQuestionsFromSourcePool()

ilTestRandomQuestionSetStagingPoolBuilder::stageQuestionsFromSourcePool (   $sourcePoolId)
private

Definition at line 102 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

References $query, $res, $row, assQuestion\_instanciateQuestion(), and array.

Referenced by build().

103  {
104  $questionIdMapping = array();
105 
106  $query = 'SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND complete = %s AND original_id IS NULL';
107  $res = $this->db->queryF($query, array('integer', 'text'), array($sourcePoolId, 1));
108 
109  while ($row = $this->db->fetchAssoc($res)) {
110  $question = assQuestion::_instanciateQuestion($row['question_id']);
111  $duplicateId = $question->duplicate(true, null, null, null, $this->testOBJ->getId());
112 
113  $nextId = $this->db->nextId('tst_rnd_cpy');
114  $this->db->insert('tst_rnd_cpy', array(
115  'copy_id' => array('integer', $nextId),
116  'tst_fi' => array('integer', $this->testOBJ->getTestId()),
117  'qst_fi' => array('integer', $duplicateId),
118  'qpl_fi' => array('integer', $sourcePoolId)
119  ));
120 
121  $questionIdMapping[ $row['question_id'] ] = $duplicateId;
122  }
123 
124  return $questionIdMapping;
125  }
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stageQuestionsFromSourcePoolCheap()

ilTestRandomQuestionSetStagingPoolBuilder::stageQuestionsFromSourcePoolCheap (   $sourcePoolId,
  $questionIdMappingPerPool,
  $filterIds = null,
  $typeFilter = null 
)
private

Definition at line 194 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

References $query, $res, $row, assQuestion\_instantiateQuestion(), and array.

Referenced by buildCheap().

195  {
196  $query = 'SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND complete = %s AND original_id IS NULL';
197  if (!empty($filterIds)) {
198  $query .= ' AND ' . $this->db->in('question_id', $filterIds, false, 'integer');
199  }
200  if (!empty($typeFilter)) {
201  $query .= ' AND ' . $this->db->in('question_type_fi', $typeFilter, false, 'integer');
202  }
203  $res = $this->db->queryF($query, array('integer', 'text'), array($sourcePoolId, 1));
204 
205  while ($row = $this->db->fetchAssoc($res)) {
206  if (!isset($questionIdMappingPerPool[$sourcePoolId])) {
207  $questionIdMappingPerPool[$sourcePoolId] = array();
208  }
209  if (!isset($questionIdMappingPerPool[$sourcePoolId][ $row['question_id'] ])) {
210  $question = assQuestion::_instantiateQuestion($row['question_id']);
211  $duplicateId = $question->duplicate(true, null, null, null, $this->testOBJ->getId());
212 
213  $nextId = $this->db->nextId('tst_rnd_cpy');
214  $this->db->insert('tst_rnd_cpy', array(
215  'copy_id' => array('integer', $nextId),
216  'tst_fi' => array('integer', $this->testOBJ->getTestId()),
217  'qst_fi' => array('integer', $duplicateId),
218  'qpl_fi' => array('integer', $sourcePoolId)
219  ));
220 
221  $questionIdMappingPerPool[$sourcePoolId][ $row['question_id'] ] = $duplicateId;
222  }
223  }
224 
225  return $questionIdMappingPerPool;
226  }
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
static _instantiateQuestion($question_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilTestRandomQuestionSetStagingPoolBuilder::$db = null

Definition at line 19 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

Referenced by __construct().

◆ $testOBJ

ilTestRandomQuestionSetStagingPoolBuilder::$testOBJ = null

Definition at line 24 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

Referenced by __construct().


The documentation for this class was generated from the following file: