ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilTestRandomQuestionSetBuilderWithAmountPerPool.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  public function checkBuildable(): bool
30  {
31  $quantitiesDistribution = new ilTestRandomQuestionsQuantitiesDistribution(
32  $this->db,
33  $this,
34  $this->sourcePoolDefinitionList
35  );
36  $quantitiesDistribution->initialise();
37 
38  $is_buildable = true;
39  foreach ($this->sourcePoolDefinitionList as $definition) {
40  $quantityCalculation = $quantitiesDistribution->calculateQuantities($definition);
41  if ($quantityCalculation->isRequiredAmountGuaranteedAvailable()) {
42  continue;
43  }
44  $is_buildable = false;
45  $this->checkMessages[] = $quantityCalculation->getDistributionReport($this->lng);
46  }
47 
48  return $is_buildable;
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  if (!isset($translator)) {
70  $translator = new ilTestQuestionFilterLabelTranslator($this->db, $this->lng);
71  $translator->loadLabels($this->sourcePoolDefinitionList);
72  }
73  $this->logger->info("RANDOM TEST: missing questions for: "
74  . implode(" - ", [$definition->getPoolTitle(), $translator->getTaxonomyFilterLabel($definition->getMappedTaxonomyFilter())]));
75  }
76  // fau.
77  $questions = $actualQuestionStage;
78  }
79 
80  $questionSet->mergeQuestionCollection($questions);
81  }
82 
83  $requiredQuestionAmount = $this->sourcePoolDefinitionList->getQuestionAmount();
84 
85  if ($questionSet->isSmallerThan($requiredQuestionAmount)) {
86  $missingQuestionCount = $questionSet->getMissingCount($requiredQuestionAmount);
87  // fau: fixRandomTestBuildable - avoid already chosen questions being used as fillers
88  $potentialQuestionStage = $this->getSrcPoolDefListRelatedQuestUniqueCollection($this->sourcePoolDefinitionList);
89  $actualQuestionStage = $potentialQuestionStage->getRelativeComplementCollection($questionSet);
90  $questions = $this->fetchQuestionsFromStageRandomly($actualQuestionStage, $missingQuestionCount);
91  // fau.
92  $questionSet->mergeQuestionCollection($questions);
93  }
94 
95  $this->handleQuestionOrdering($questionSet);
96 
97  $this->storeQuestionSet($testSession, $questionSet);
98  }
99 }
getSrcPoolDefListRelatedQuestUniqueCollection(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
handleQuestionOrdering(ilTestRandomQuestionSetQuestionCollection $questionSet)
getSrcPoolDefRelatedQuestCollection(ilTestRandomQuestionSetSourcePoolDefinition $definition)
fetchQuestionsFromStageRandomly(ilTestRandomQuestionSetQuestionCollection $questionStage, $requiredQuestionAmount)
performBuild(ilTestSession $testSession)
storeQuestionSet(ilTestSession $testSession, $questionSet)