ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestRandomQuestionSetBuilderWithAmountPerPool.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  public function checkBuildable(): bool
28  {
29  global $DIC; /* @var ILIAS\DI\Container $DIC */
30  $lng = $DIC['lng'];
31 
32  require_once 'Modules/Test/classes/class.ilTestRandomQuestionsQuantitiesDistribution.php';
33  $quantitiesDistribution = new ilTestRandomQuestionsQuantitiesDistribution($this);
34  $quantitiesDistribution->setSourcePoolDefinitionList($this->sourcePoolDefinitionList);
35  $quantitiesDistribution->initialise();
36 
37  $isBuildable = true;
38  foreach ($this->sourcePoolDefinitionList as $definition) {
39  $quantityCalculation = $quantitiesDistribution->calculateQuantities($definition);
40  if ($quantityCalculation->isRequiredAmountGuaranteedAvailable()) {
41  continue;
42  }
43 
44  $isBuildable = false;
45  $this->checkMessages[] = $quantityCalculation->getDistributionReport($lng);
46  }
47 
48  return $isBuildable;
49  }
50 
51  public function performBuild(ilTestSession $testSession)
52  {
53  $questionSet = new ilTestRandomQuestionSetQuestionCollection();
54 
55  foreach ($this->sourcePoolDefinitionList as $definition) {
58  $requiredQuestionAmount = $definition->getQuestionAmount();
59 
60  $potentialQuestionStage = $this->getSrcPoolDefRelatedQuestCollection($definition);
61 
62  $actualQuestionStage = $potentialQuestionStage->getRelativeComplementCollection($questionSet);
63 
64  if ($actualQuestionStage->isGreaterThan($requiredQuestionAmount)) {
65  $questions = $this->fetchQuestionsFromStageRandomly($actualQuestionStage, $requiredQuestionAmount);
66  } else {
67  // fau: fixRandomTestBuildable - log missing questions for a random test rule
68  if ($actualQuestionStage->isSmallerThan($requiredQuestionAmount)) {
69  global $DIC;
70  $ilDB = $DIC['ilDB'];
71  $ilLog = $DIC['ilLog'];
72  if (!isset($translator)) {
73  require_once("./Modules/Test/classes/class.ilTestTaxonomyFilterLabelTranslater.php");
74  $translator = new ilTestTaxonomyFilterLabelTranslater($ilDB);
75  $translator->loadLabels($this->sourcePoolDefinitionList);
76  }
77  $ilLog->write("RANDOM TEST: missing questions for: "
78  . implode(" - ", array($definition->getPoolTitle(), $translator->getTaxonomyFilterLabel($definition->getMappedTaxonomyFilter()))));
79  }
80  // fau.
81  $questions = $actualQuestionStage;
82  }
83 
84  $questionSet->mergeQuestionCollection($questions);
85  }
86 
87  $requiredQuestionAmount = $this->sourcePoolDefinitionList->getQuestionAmount();
88 
89  if ($questionSet->isSmallerThan($requiredQuestionAmount)) {
90  $missingQuestionCount = $questionSet->getMissingCount($requiredQuestionAmount);
91  // fau: fixRandomTestBuildable - avoid already chosen questions being used as fillers
92  $potentialQuestionStage = $this->getSrcPoolDefListRelatedQuestUniqueCollection($this->sourcePoolDefinitionList);
93  $actualQuestionStage = $potentialQuestionStage->getRelativeComplementCollection($questionSet);
94  $questions = $this->fetchQuestionsFromStageRandomly($actualQuestionStage, $missingQuestionCount);
95  // fau.
96  $questionSet->mergeQuestionCollection($questions);
97  }
98 
99  $this->handleQuestionOrdering($questionSet);
100 
101  $this->storeQuestionSet($testSession, $questionSet);
102  }
103 }
getSrcPoolDefListRelatedQuestUniqueCollection(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
$lng
handleQuestionOrdering(ilTestRandomQuestionSetQuestionCollection $questionSet)
global $DIC
Definition: feed.php:28
getSrcPoolDefRelatedQuestCollection(ilTestRandomQuestionSetSourcePoolDefinition $definition)
fetchQuestionsFromStageRandomly(ilTestRandomQuestionSetQuestionCollection $questionStage, $requiredQuestionAmount)
performBuild(ilTestSession $testSession)
storeQuestionSet(ilTestSession $testSession, $questionSet)