ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  $questionStage = $this->getQuestionStageForSourcePoolDefinitionList($this->sourcePoolDefinitionList);
58  $questions = $this->fetchQuestionsFromStageRandomly($questionStage, $missingQuestionCount);
59 
60  $questionSet->mergeQuestionCollection($questions);
61  }
62 
63  $this->handleQuestionOrdering($questionSet);
64 
65  $this->storeQuestionSet($testSession, $questionSet);
66  }
67 }