ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 90 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

References mirrorSourcePoolTaxonomies(), and stageQuestionsFromSourcePool().

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

◆ buildCheap()

ilTestRandomQuestionSetStagingPoolBuilder::buildCheap ( ilTestRandomQuestionSetSourcePoolDefinitionList  $sourcePoolDefinitionList)
private

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

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

Referenced by rebuild().

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

Referenced by reset().

272  {
273  $this->testOBJ->setResultFilterTaxIds(array());
274  $this->testOBJ->saveToDb(true);
275  }
+ Here is the caller graph for this function:

◆ mirrorSourcePoolTaxonomies()

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

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

Referenced by build(), and buildCheap().

231  {
232  $duplicator = new ilQuestionPoolTaxonomiesDuplicator();
233 
234  $duplicator->setSourceObjId($sourcePoolId);
235  $duplicator->setSourceObjType('qpl');
236  $duplicator->setTargetObjId($this->testOBJ->getId());
237  $duplicator->setTargetObjType($this->testOBJ->getType());
238  $duplicator->setQuestionIdMapping($questionIdMapping);
239 
240  $duplicator->duplicate($duplicator->getAllTaxonomiesForSourceObject());
241 
242  return $duplicator->getDuplicatedTaxonomiesKeysMap();
243  }
+ 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 $DIC, $query, $res, $row, and assQuestion\_instanciateQuestion().

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  global $DIC; /* @var ILIAS\DI\Container $DIC */
80  $DIC['ilLog']->warning(
81  "could not delete staged random question (ref={$this->testOBJ->getRefId()} / qst={$row['qst_fi']})"
82  );
83  }
84  }
85 
86  $query = "DELETE FROM tst_rnd_cpy WHERE tst_fi = %s";
87  $this->db->manipulateF($query, array('integer'), array($this->testOBJ->getTestId()));
88  }
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
global $DIC
Definition: saml.php:7
Abstract basic class which is to be extended by the concrete assessment question type classes...
foreach($_POST as $key=> $value) $res
$query
$row
+ 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 103 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

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

Referenced by build().

104  {
105  $questionIdMapping = array();
106 
107  $query = 'SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND complete = %s AND original_id IS NULL';
108  $res = $this->db->queryF($query, array('integer', 'text'), array($sourcePoolId, 1));
109 
110  while ($row = $this->db->fetchAssoc($res)) {
111  $question = assQuestion::_instanciateQuestion($row['question_id']);
112  $duplicateId = $question->duplicate(true, null, null, null, $this->testOBJ->getId());
113 
114  $nextId = $this->db->nextId('tst_rnd_cpy');
115  $this->db->insert('tst_rnd_cpy', array(
116  'copy_id' => array('integer', $nextId),
117  'tst_fi' => array('integer', $this->testOBJ->getTestId()),
118  'qst_fi' => array('integer', $duplicateId),
119  'qpl_fi' => array('integer', $sourcePoolId)
120  ));
121 
122  $questionIdMapping[ $row['question_id'] ] = $duplicateId;
123  }
124 
125  return $questionIdMapping;
126  }
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
foreach($_POST as $key=> $value) $res
$query
$row
+ 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 195 of file class.ilTestRandomQuestionSetStagingPoolBuilder.php.

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

Referenced by buildCheap().

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