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