ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilTestRandomQuestionSetBuilder.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetQuestionCollection.php';
5 require_once 'Modules/Test/interfaces/interface.ilTestRandomSourcePoolDefinitionQuestionCollectionProvider.php';
13 {
17  protected $db = null;
18 
22  protected $testOBJ = null;
23 
27  protected $questionSetConfig = null;
28 
32  protected $sourcePoolDefinitionList = null;
33 
37  protected $stagingPoolQuestionList = null;
38 
39  //fau: fixRandomTestBuildable - variable for messages
40  protected $checkMessages = array();
41  // fau.
42 
50  protected function __construct(
56  ) {
57  $this->db = $db;
58  $this->testOBJ = $testOBJ;
59  $this->questionSetConfig = $questionSetConfig;
60  $this->sourcePoolDefinitionList = $sourcePoolDefinitionList;
61  $this->stagingPoolQuestionList = $stagingPoolQuestionList;
62  }
63 
64  abstract public function checkBuildable();
65 
66  abstract public function performBuild(ilTestSession $testSession);
67 
68 
69  // hey: fixRandomTestBuildable - rename/public-access to be aware for building interface
71  // hey.
72  {
73  $questionStage = new ilTestRandomQuestionSetQuestionCollection();
74 
75  foreach ($sourcePoolDefinitionList as $definition) {
78  // hey: fixRandomTestBuildable - rename/public-access to be aware for building interface
79  $questions = $this->getSrcPoolDefRelatedQuestCollection($definition);
80  // hey.
81  $questionStage->mergeQuestionCollection($questions);
82  }
83 
84  return $questionStage;
85  }
86 
87  // hey: fixRandomTestBuildable - rename/public-access to be aware for building interface
93  // hey.
94  {
95  $questionIds = $this->getQuestionIdsForSourcePoolDefinitionIds($definition);
96  $questionStage = $this->buildSetQuestionCollection($definition, $questionIds);
97 
98  return $questionStage;
99  }
100 
101  // hey: fixRandomTestBuildable - rename/public-access to be aware for building interface
107  {
108  $combinationCollection = $this->getSrcPoolDefListRelatedQuestCombinationCollection($sourcePoolDefinitionList);
109  return $combinationCollection->getUniqueQuestionCollection();
110  }
111  // hey.
112 
114  {
115  $this->stagingPoolQuestionList->resetQuestionList();
116 
117  $this->stagingPoolQuestionList->setTestObjId($this->testOBJ->getId());
118  $this->stagingPoolQuestionList->setTestId($this->testOBJ->getTestId());
119  $this->stagingPoolQuestionList->setPoolId($definition->getPoolId());
120 
121  if ($this->hasTaxonomyFilter($definition)) {
122  // fau: taxFilter/typeFilter - use new taxonomy filter
123  foreach ($definition->getMappedTaxonomyFilter() as $taxId => $nodeIds) {
124  $this->stagingPoolQuestionList->addTaxonomyFilter($taxId, $nodeIds);
125  }
126  #$this->stagingPoolQuestionList->addTaxonomyFilter(
127  # $definition->getMappedFilterTaxId(), array($definition->getMappedFilterTaxNodeId())
128  #);
129  // fau.
130  }
131 
132  // fau: taxFilter/typeFilter - use type filter
133  if ($this->hasTypeFilter($definition)) {
134  $this->stagingPoolQuestionList->setTypeFilter($definition->getTypeFilter());
135  }
136  // fau.
137 
138  $this->stagingPoolQuestionList->loadQuestions();
139 
140  return $this->stagingPoolQuestionList->getQuestions();
141  }
142 
144  {
145  $setQuestionCollection = new ilTestRandomQuestionSetQuestionCollection();
146 
147  foreach ($questionIds as $questionId) {
148  $setQuestion = new ilTestRandomQuestionSetQuestion();
149 
150  $setQuestion->setQuestionId($questionId);
151  $setQuestion->setSourcePoolDefinitionId($definition->getId());
152 
153  $setQuestionCollection->addQuestion($setQuestion);
154  }
155 
156  return $setQuestionCollection;
157  }
158 
160  {
161  // fau: taxFilter - check for existing taxonomy filter
162  if (!count($definition->getMappedTaxonomyFilter())) {
163  return false;
164  }
165  #if( !(int)$definition->getMappedFilterTaxId() )
166  #{
167  # return false;
168  #}
169  #
170  #if( !(int)$definition->getMappedFilterTaxNodeId() )
171  #{
172  # return false;
173  #}
174  // fau.
175  return true;
176  }
177 
178  // fau: typeFilter - check for existing type filter
180  {
181  if (count($definition->getTypeFilter())) {
182  return true;
183  }
184 
185  return false;
186  }
187  // fau.
188 
189  protected function storeQuestionSet(ilTestSession $testSession, $questionSet)
190  {
191  $position = 0;
192 
193  foreach ($questionSet->getQuestions() as $setQuestion) {
194  /* @var ilTestRandomQuestionSetQuestion $setQuestion */
195 
196  $setQuestion->setSequencePosition($position++);
197 
198  $this->storeQuestion($testSession, $setQuestion);
199  }
200  }
201 
202  private function storeQuestion(ilTestSession $testSession, ilTestRandomQuestionSetQuestion $setQuestion)
203  {
204  $nextId = $this->db->nextId('tst_test_rnd_qst');
205 
206  $this->db->insert('tst_test_rnd_qst', array(
207  'test_random_question_id' => array('integer', $nextId),
208  'active_fi' => array('integer', $testSession->getActiveId()),
209  'question_fi' => array('integer', $setQuestion->getQuestionId()),
210  'sequence' => array('integer', $setQuestion->getSequencePosition()),
211  'pass' => array('integer', $testSession->getPass()),
212  'tstamp' => array('integer', time()),
213  'src_pool_def_fi' => array('integer', $setQuestion->getSourcePoolDefinitionId())
214  ));
215  }
216 
217  protected function fetchQuestionsFromStageRandomly(ilTestRandomQuestionSetQuestionCollection $questionStage, $requiredQuestionAmount)
218  {
219  $questionSet = $questionStage->getRandomQuestionCollection($requiredQuestionAmount);
220 
221  return $questionSet;
222  }
223 
225  {
226  if ($this->testOBJ->getShuffleQuestions()) {
227  $questionSet->shuffleQuestions();
228  }
229  }
230 
231  // =================================================================================================================
232 
233  final public static function getInstance(
237  ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList,
239  ) {
240  if ($questionSetConfig->isQuestionAmountConfigurationModePerPool()) {
241  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetBuilderWithAmountPerPool.php';
242 
244  $db,
245  $testOBJ,
246  $questionSetConfig,
247  $sourcePoolDefinitionList,
248  $stagingPoolQuestionList
249  );
250  }
251 
252  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetBuilderWithAmountPerTest.php';
253 
255  $db,
256  $testOBJ,
257  $questionSetConfig,
258  $sourcePoolDefinitionList,
259  $stagingPoolQuestionList
260  );
261  }
262 
263  //fau: fixRandomTestBuildable - function to get messages
267  public function getCheckMessages()
268  {
269  return $this->checkMessages;
270  }
271  // fau.
272 }
getSrcPoolDefListRelatedQuestUniqueCollection(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
handleQuestionOrdering(ilTestRandomQuestionSetQuestionCollection $questionSet)
buildSetQuestionCollection(ilTestRandomQuestionSetSourcePoolDefinition $definition, $questionIds)
Interface ilDBInterface.
getQuestionIdsForSourcePoolDefinitionIds(ilTestRandomQuestionSetSourcePoolDefinition $definition)
hasTypeFilter(ilTestRandomQuestionSetSourcePoolDefinition $definition)
static getInstance(ilDBInterface $db, ilObjTest $testOBJ, ilTestRandomQuestionSetConfig $questionSetConfig, ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList, ilTestRandomQuestionSetStagingPoolQuestionList $stagingPoolQuestionList)
Test session handler.
getSrcPoolDefRelatedQuestCollection(ilTestRandomQuestionSetSourcePoolDefinition $definition)
hasTaxonomyFilter(ilTestRandomQuestionSetSourcePoolDefinition $definition)
Create styles array
The data for the language used.
__construct(ilDBInterface $db, ilObjTest $testOBJ, ilTestRandomQuestionSetConfig $questionSetConfig, ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList, ilTestRandomQuestionSetStagingPoolQuestionList $stagingPoolQuestionList)
fetchQuestionsFromStageRandomly(ilTestRandomQuestionSetQuestionCollection $questionStage, $requiredQuestionAmount)
performBuild(ilTestSession $testSession)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
getSrcPoolDefListRelatedQuestCombinationCollection(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
storeQuestionSet(ilTestSession $testSession, $questionSet)
storeQuestion(ilTestSession $testSession, ilTestRandomQuestionSetQuestion $setQuestion)