ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  // hey: fixRandomTestBuildable - improvment of improved pass build check
18  public function checkBuildableNewer()
19  {
20  global $DIC; /* @var ILIAS\DI\Container $DIC */
21  $lng = $DIC['lng'];
22 
23  $isBuildable = true;
24 
25  require_once 'Modules/Test/classes/class.ilTestRandomQuestionsQuantitiesDistribution.php';
26  $quantitiesDistribution = new ilTestRandomQuestionsQuantitiesDistribution($this);
27  $quantitiesDistribution->setSourcePoolDefinitionList($this->sourcePoolDefinitionList);
28  $quantitiesDistribution->initialise();
29 
30  // perhaps not every with every BUT every with any next ??!
31  // perhaps exactly like this !!? I dont know :-)
32  // it should be about vice versa rule conflict reporting
33 
34  foreach ($this->sourcePoolDefinitionList as $definition) {
37  $quantityCalculation = $quantitiesDistribution->calculateQuantities($definition);
38 
39  if ($quantityCalculation->isRequiredAmountGuaranteedAvailable()) {
40  continue;
41  }
42 
43  $isBuildable = false;
44 
45  $this->checkMessages[] = $quantityCalculation->getDistributionReport($lng);
46  }
47 
48  return $isBuildable;
49  }
50  // hey.
51 
55  public function checkBuildable()
56  {
57  // hey: fixRandomTestBuildable - improved the buildable check improvement
58  return $this->checkBuildableNewer();
59  // hey.
60 
61  $questionStage = $this->getSrcPoolDefListRelatedQuestUniqueCollection($this->sourcePoolDefinitionList);
62 
63  if ($questionStage->isSmallerThan($this->sourcePoolDefinitionList->getQuestionAmount())) {
64  return false;
65  }
66 
67  return true;
68  }
69 
70  public function performBuild(ilTestSession $testSession)
71  {
72  $questionSet = new ilTestRandomQuestionSetQuestionCollection();
73 
74  foreach ($this->sourcePoolDefinitionList as $definition) {
77  $requiredQuestionAmount = $definition->getQuestionAmount();
78 
79  $potentialQuestionStage = $this->getSrcPoolDefRelatedQuestCollection($definition);
80 
81  $actualQuestionStage = $potentialQuestionStage->getRelativeComplementCollection($questionSet);
82 
83  if ($actualQuestionStage->isGreaterThan($requiredQuestionAmount)) {
84  $questions = $this->fetchQuestionsFromStageRandomly($actualQuestionStage, $requiredQuestionAmount);
85  } else {
86  // fau: fixRandomTestBuildable - log missing questions for a random test rule
87  if ($actualQuestionStage->isSmallerThan($requiredQuestionAmount)) {
88  global $DIC;
89  $ilDB = $DIC['ilDB'];
90  $ilLog = $DIC['ilLog'];
91  if (!isset($translator)) {
92  require_once("./Modules/Test/classes/class.ilTestTaxonomyFilterLabelTranslater.php");
94  $translator->loadLabels($this->sourcePoolDefinitionList);
95  }
96  $ilLog->write("RANDOM TEST: missing questions for: "
97  . implode(" - ", array($definition->getPoolTitle(), $translator->getTaxonomyFilterLabel($definition->getMappedTaxonomyFilter()))));
98  }
99  // fau.
100  $questions = $actualQuestionStage;
101  }
102 
103  $questionSet->mergeQuestionCollection($questions);
104  }
105 
106  $requiredQuestionAmount = $this->sourcePoolDefinitionList->getQuestionAmount();
107 
108  if ($questionSet->isSmallerThan($requiredQuestionAmount)) {
109  $missingQuestionCount = $questionSet->getMissingCount($requiredQuestionAmount);
110  // fau: fixRandomTestBuildable - avoid already chosen questions being used as fillers
111  $potentialQuestionStage = $this->getSrcPoolDefListRelatedQuestUniqueCollection($this->sourcePoolDefinitionList);
112  $actualQuestionStage = $potentialQuestionStage->getRelativeComplementCollection($questionSet);
113  $questions = $this->fetchQuestionsFromStageRandomly($actualQuestionStage, $missingQuestionCount);
114  // fau.
115  $questionSet->mergeQuestionCollection($questions);
116  }
117 
118  $this->handleQuestionOrdering($questionSet);
119 
120  $this->storeQuestionSet($testSession, $questionSet);
121  }
122 }
getSrcPoolDefListRelatedQuestUniqueCollection(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
global $DIC
Definition: saml.php:7
handleQuestionOrdering(ilTestRandomQuestionSetQuestionCollection $questionSet)
$lng
Test session handler.
getSrcPoolDefRelatedQuestCollection(ilTestRandomQuestionSetSourcePoolDefinition $definition)
global $ilDB
fetchQuestionsFromStageRandomly(ilTestRandomQuestionSetQuestionCollection $questionStage, $requiredQuestionAmount)
performBuild(ilTestSession $testSession)
$translator
Definition: getconsent.php:119
storeQuestionSet(ilTestSession $testSession, $questionSet)