ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestRandomQuestionSetBuilder.php
Go to the documentation of this file.
1 <?php
2 
26 {
30  protected $db = null;
31 
35  protected $testOBJ = null;
36 
40  protected $questionSetConfig = null;
41 
45  protected $sourcePoolDefinitionList = null;
46 
50  protected $stagingPoolQuestionList = null;
51 
52  //fau: fixRandomTestBuildable - variable for messages
53  protected $checkMessages = array();
54  // fau.
55 
63  protected function __construct(
69  ) {
70  $this->db = $db;
71  $this->testOBJ = $testOBJ;
72  $this->questionSetConfig = $questionSetConfig;
73  $this->sourcePoolDefinitionList = $sourcePoolDefinitionList;
74  $this->stagingPoolQuestionList = $stagingPoolQuestionList;
75  $this->stagingPoolQuestionList->setTestObjId($this->testOBJ->getId());
76  $this->stagingPoolQuestionList->setTestId($this->testOBJ->getTestId());
77  }
78 
79  abstract public function checkBuildable();
80 
81  abstract public function performBuild(ilTestSession $testSession);
82 
84  {
85  $questionStage = new ilTestRandomQuestionSetQuestionCollection();
86 
87  foreach ($sourcePoolDefinitionList as $definition) {
88  $questions = $this->getSrcPoolDefRelatedQuestCollection($definition);
89  $questionStage->mergeQuestionCollection($questions);
90  }
91 
92  return $questionStage;
93  }
94 
100  {
101  $questionIds = $this->getQuestionIdsForSourcePoolDefinitionIds($definition);
102  $questionStage = $this->buildSetQuestionCollection($definition, $questionIds);
103 
104  return $questionStage;
105  }
106 
107  // hey: fixRandomTestBuildable - rename/public-access to be aware for building interface
113  {
114  $combinationCollection = $this->getSrcPoolDefListRelatedQuestCombinationCollection($sourcePoolDefinitionList);
115  return $combinationCollection->getUniqueQuestionCollection();
116  }
117  // hey.
118 
120  {
121  $this->stagingPoolQuestionList->resetQuestionList();
122 
123  $this->stagingPoolQuestionList->setPoolId($definition->getPoolId());
124 
125  if ($this->hasTaxonomyFilter($definition)) {
126  foreach ($definition->getMappedTaxonomyFilter() as $taxId => $nodeIds) {
127  $this->stagingPoolQuestionList->addTaxonomyFilter($taxId, $nodeIds);
128  }
129  }
130 
131  if (count($definition->getLifecycleFilter())) {
132  $this->stagingPoolQuestionList->setLifecycleFilter($definition->getLifecycleFilter());
133  }
134 
135  // fau: taxFilter/typeFilter - use type filter
136  if ($this->hasTypeFilter($definition)) {
137  $this->stagingPoolQuestionList->setTypeFilter($definition->getTypeFilter());
138  }
139  // fau.
140 
141  $this->stagingPoolQuestionList->loadQuestions();
142 
143  return $this->stagingPoolQuestionList->getQuestions();
144  }
145 
147  {
148  $setQuestionCollection = new ilTestRandomQuestionSetQuestionCollection();
149 
150  foreach ($questionIds as $questionId) {
151  $setQuestion = new ilTestRandomQuestionSetQuestion();
152 
153  $setQuestion->setQuestionId($questionId);
154  $setQuestion->setSourcePoolDefinitionId($definition->getId());
155 
156  $setQuestionCollection->addQuestion($setQuestion);
157  }
158 
159  return $setQuestionCollection;
160  }
161 
163  {
164  if (!count($definition->getMappedTaxonomyFilter())) {
165  return false;
166  }
167  return true;
168  }
169 
170  // fau: typeFilter - check for existing type filter
171  private function hasTypeFilter(ilTestRandomQuestionSetSourcePoolDefinition $definition): bool
172  {
173  if (count($definition->getTypeFilter())) {
174  return true;
175  }
176 
177  return false;
178  }
179  // fau.
180 
181  protected function storeQuestionSet(ilTestSession $testSession, $questionSet)
182  {
183  $position = 0;
184 
185  foreach ($questionSet->getQuestions() as $setQuestion) {
186  /* @var ilTestRandomQuestionSetQuestion $setQuestion */
187 
188  $setQuestion->setSequencePosition($position++);
189 
190  $this->storeQuestion($testSession, $setQuestion);
191  }
192  }
193 
194  private function storeQuestion(ilTestSession $testSession, ilTestRandomQuestionSetQuestion $setQuestion)
195  {
196  $nextId = $this->db->nextId('tst_test_rnd_qst');
197 
198  $this->db->insert('tst_test_rnd_qst', array(
199  'test_random_question_id' => array('integer', $nextId),
200  'active_fi' => array('integer', $testSession->getActiveId()),
201  'question_fi' => array('integer', $setQuestion->getQuestionId()),
202  'sequence' => array('integer', $setQuestion->getSequencePosition()),
203  'pass' => array('integer', $testSession->getPass()),
204  'tstamp' => array('integer', time()),
205  'src_pool_def_fi' => array('integer', $setQuestion->getSourcePoolDefinitionId())
206  ));
207  }
208 
210  {
211  $questionSet = $questionStage->getRandomQuestionCollection($requiredQuestionAmount);
212 
213  return $questionSet;
214  }
215 
217  {
218  if ($this->testOBJ->getShuffleQuestions()) {
219  $questionSet->shuffleQuestions();
220  }
221  }
222 
223  // =================================================================================================================
224 
225  final public static function getInstance(
231  ) {
232  if ($questionSetConfig->isQuestionAmountConfigurationModePerPool()) {
233  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetBuilderWithAmountPerPool.php';
234 
236  $db,
237  $testOBJ,
238  $questionSetConfig,
239  $sourcePoolDefinitionList,
240  $stagingPoolQuestionList
241  );
242  }
243 
244  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetBuilderWithAmountPerTest.php';
245 
247  $db,
248  $testOBJ,
249  $questionSetConfig,
250  $sourcePoolDefinitionList,
251  $stagingPoolQuestionList
252  );
253  }
254 
255  //fau: fixRandomTestBuildable - function to get messages
259  public function getCheckMessages(): array
260  {
261  return $this->checkMessages;
262  }
263  // fau.
264 }
getSrcPoolDefListRelatedQuestUniqueCollection(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
handleQuestionOrdering(ilTestRandomQuestionSetQuestionCollection $questionSet)
buildSetQuestionCollection(ilTestRandomQuestionSetSourcePoolDefinition $definition, $questionIds)
getQuestionIdsForSourcePoolDefinitionIds(ilTestRandomQuestionSetSourcePoolDefinition $definition)
hasTypeFilter(ilTestRandomQuestionSetSourcePoolDefinition $definition)
static getInstance(ilDBInterface $db, ilObjTest $testOBJ, ilTestRandomQuestionSetConfig $questionSetConfig, ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList, ilTestRandomQuestionSetStagingPoolQuestionList $stagingPoolQuestionList)
getSrcPoolDefRelatedQuestCollection(ilTestRandomQuestionSetSourcePoolDefinition $definition)
hasTaxonomyFilter(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getSrcPoolDefListRelatedQuestCombinationCollection(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
__construct(ilDBInterface $db, ilObjTest $testOBJ, ilTestRandomQuestionSetConfig $questionSetConfig, ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList, ilTestRandomQuestionSetStagingPoolQuestionList $stagingPoolQuestionList)
fetchQuestionsFromStageRandomly(ilTestRandomQuestionSetQuestionCollection $questionStage, $requiredQuestionAmount)
performBuild(ilTestSession $testSession)
storeQuestionSet(ilTestSession $testSession, $questionSet)
storeQuestion(ilTestSession $testSession, ilTestRandomQuestionSetQuestion $setQuestion)