ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTestRandomQuestionSetBuilderWithAmountPerPool.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.ilTestRandomQuestionSetBuilder.php';
5 
13 {
14  public function checkBuildable()
15  {
16  $questionStage = $this->getQuestionStageForSourcePoolDefinitionList($this->sourcePoolDefinitionList);
17 
18  if( $questionStage->isSmallerThan($this->sourcePoolDefinitionList->getQuestionAmount()) )
19  {
20  return false;
21  }
22 
23  return true;
24  }
25 
26  public function performBuild(ilTestSession $testSession)
27  {
28  $questionSet = new ilTestRandomQuestionSetQuestionCollection();
29 
30  foreach($this->sourcePoolDefinitionList as $definition)
31  {
34  $requiredQuestionAmount = $definition->getQuestionAmount();
35 
36  $potentialQuestionStage = $this->getQuestionStageForSourcePoolDefinition($definition);
37 
38  $actualQuestionStage = $potentialQuestionStage->getRelativeComplementCollection($questionSet);
39 
40  if( $actualQuestionStage->isGreaterThan($requiredQuestionAmount) )
41  {
42  $questions = $this->fetchQuestionsFromStageRandomly($actualQuestionStage, $requiredQuestionAmount);
43  }
44  else
45  {
46  $questions = $actualQuestionStage;
47  }
48 
49  $questionSet->mergeQuestionCollection($questions);
50  }
51 
52  $requiredQuestionAmount = $this->sourcePoolDefinitionList->getQuestionAmount();
53 
54  if( $questionSet->isSmallerThan($requiredQuestionAmount) )
55  {
56  $missingQuestionCount = $questionSet->getMissingCount($requiredQuestionAmount);
57  $potentialQuestionStage = $this->getQuestionStageForSourcePoolDefinitionList($this->sourcePoolDefinitionList);
58  $actualQuestionStage = $potentialQuestionStage->getRelativeComplementCollection($questionSet);
59  $questions = $this->fetchQuestionsFromStageRandomly($actualQuestionStage, $missingQuestionCount);
60 
61  $questionSet->mergeQuestionCollection($questions);
62  }
63 
64  $this->handleQuestionOrdering($questionSet);
65 
66  $this->storeQuestionSet($testSession, $questionSet);
67  }
68 }
getQuestionStageForSourcePoolDefinition(ilTestRandomQuestionSetSourcePoolDefinition $definition)
handleQuestionOrdering(ilTestRandomQuestionSetQuestionCollection $questionSet)
Test session handler.
fetchQuestionsFromStageRandomly(ilTestRandomQuestionSetQuestionCollection $questionStage, $requiredQuestionAmount)
performBuild(ilTestSession $testSession)
storeQuestionSet(ilTestSession $testSession, $questionSet)