ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilTestRandomQuestionsQuantitiesDistribution.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
33 
38 
39  // -----------------------------------------------------------------------------------------------------------------
40 
41  public function __construct(
42  private ilDBInterface $db,
43  private ilTestRandomSourcePoolDefinitionQuestionCollectionProvider $question_collection_provider,
44  private ilTestRandomQuestionSetSourcePoolDefinitionList $source_pool_definition_list
45  ) {
46  }
47 
49  {
50  $any_test_object = new ilObjTest();
51  $non_required_db = $this->db;
52  $non_used_factory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory($non_required_db, $any_test_object);
53  return new ilTestRandomQuestionSetSourcePoolDefinitionList($non_required_db, $any_test_object, $non_used_factory);
54  }
55 
60  {
62  }
63 
68  {
70  }
71 
76  {
78  }
79 
80  // -----------------------------------------------------------------------------------------------------------------
81 
83  {
84  $this->quest_related_src_pool_def_register = [];
85  }
86 
87  protected function registerQuestRelatedSrcPoolDef(int $question_id, ilTestRandomQuestionSetSourcePoolDefinition $definition)
88  {
89  if (!array_key_exists($question_id, $this->quest_related_src_pool_def_register)) {
90  $this->quest_related_src_pool_def_register[$question_id] = $this->buildSourcePoolDefinitionListInstance();
91  }
92 
93  $this->quest_related_src_pool_def_register[$question_id]->addDefinition($definition);
94  }
95 
101  {
102  if (isset($this->quest_related_src_pool_def_register[$questionId])) {
103  return $this->quest_related_src_pool_def_register[$questionId];
104  }
105 
106  return null;
107  }
108 
110  {
111  $this->src_pool_def_related_quest_register = [];
112  }
113 
114  protected function registerSrcPoolDefRelatedQuest(int $definition_id, ilTestRandomQuestionSetQuestion $random_set_question): void
115  {
116  if (!isset($this->src_pool_def_related_quest_register[$definition_id])) {
117  $this->src_pool_def_related_quest_register[$definition_id] = $this->buildRandomQuestionCollectionInstance();
118  }
119 
120  $this->src_pool_def_related_quest_register[$definition_id]->addQuestion($random_set_question);
121  }
122 
124  {
125  if (isset($this->src_pool_def_related_quest_register[$definition_id])) {
126  return $this->src_pool_def_related_quest_register[$definition_id];
127  }
128 
130  }
131 
132  protected function initialiseRegisters(): void
133  {
134  foreach ($this->getSrcPoolDefQuestionCombinationCollection() as $random_question) {
135  $source_pool_definition = $this->source_pool_definition_list->getDefinition(
136  $random_question->getSourcePoolDefinitionId()
137  );
138 
140  $random_question->getSourcePoolDefinitionId(),
141  $random_question
142  );
143 
144  if ($source_pool_definition && $random_question->getQuestionId()) {
146  $random_question->getQuestionId(),
147  $source_pool_definition
148  );
149  }
150  }
151  }
152 
153  protected function resetRegisters(): void
154  {
157  }
158 
160  {
161  return $this->question_collection_provider->getSrcPoolDefListRelatedQuestCombinationCollection(
162  $this->source_pool_definition_list
163  );
164  }
165 
167  {
168  $exclusiveQstCollection = $this->buildRandomQuestionCollectionInstance();
169 
170  foreach ($this->getSrcPoolDefRelatedQuestionCollection($definition_id) as $question) {
171  if ($this->isQuestionUsedByMultipleSrcPoolDefinitions($question)) {
172  continue;
173  }
174 
175  $exclusiveQstCollection->addQuestion($question);
176  }
177 
178  return $exclusiveQstCollection;
179  }
180 
182  {
183  $srcPoolDefRelatedQstCollection = $this->getSrcPoolDefRelatedQuestionCollection($definition_id);
184  $exclusiveQstCollection = $this->getExclusiveQuestionCollection($definition_id);
185  return $srcPoolDefRelatedQstCollection->getRelativeComplementCollection($exclusiveQstCollection);
186  }
187 
189  int $this_definition_id,
190  int $that_definition_id
192  $this_def_related_shared_qst_collection = $this->getSharedQuestionCollection($this_definition_id);
193  $that_def_related_shared_qst_collection = $this->getSharedQuestionCollection($that_definition_id);
194 
195  return $this_def_related_shared_qst_collection->getIntersectionCollection(
196  $that_def_related_shared_qst_collection
197  );
198  }
199 
205  ): array {
206  $intersectionQstCollectionsByDefId = [];
207 
208  $sharedQuestionCollection = $this->getSharedQuestionCollection($definition->getId());
209  foreach ($sharedQuestionCollection as $sharedQuestion) {
210  $relatedSrcPoolDefList = $this->getQuestRelatedSrcPoolDefinitionList($sharedQuestion->getQuestionId());
211  foreach ($relatedSrcPoolDefList as $otherDefinition) {
212  if ($otherDefinition->getId() == $definition->getId()) {
213  continue;
214  }
215 
216  if (isset($intersectionQstCollectionsByDefId[$otherDefinition->getId()])) {
217  continue;
218  }
219 
220  $intersectionQuestionCollection = $this->getIntersectionQuestionCollection(
221  $definition->getId(),
222  $otherDefinition->getId()
223  );
224 
225  $intersectionQstCollectionsByDefId[$otherDefinition->getId()] = $intersectionQuestionCollection;
226  }
227  }
228 
229  return $intersectionQstCollectionsByDefId;
230  }
231 
237  {
238  $qstCollectionSubsetApplicationList = $this->buildQuestionCollectionSubsetApplicationListInstance();
239 
240  $intersectionQstCollectionByDefIdMap = $this->getIntersectionQstCollectionByDefinitionMap($definition);
241  foreach ($intersectionQstCollectionByDefIdMap as $otherDefinitionId => $intersectionCollection) {
242  /* @var ilTestRandomQuestionSetQuestionCollection $intersectionCollection */
243 
244  $qstCollectionSubsetApplication = $this->buildQuestionCollectionSubsetApplicationInstance();
245  $qstCollectionSubsetApplication->setQuestions($intersectionCollection->getQuestions());
246  $qstCollectionSubsetApplication->setApplicantId($otherDefinitionId);
247 
248  $qstCollectionSubsetApplication->setRequiredAmount(
249  $this->source_pool_definition_list->getDefinition($otherDefinitionId)->getQuestionAmount()
250  );
251 
252  $qstCollectionSubsetApplicationList->addCollectionSubsetApplication($qstCollectionSubsetApplication);
253  }
254 
255  return $qstCollectionSubsetApplicationList;
256  }
257 
258  // -----------------------------------------------------------------------------------------------------------------
259 
265  {
266  $intersectionSharingDefinitionList = $this->buildSourcePoolDefinitionListInstance();
267 
268  $sharedQuestionCollection = $this->getSharedQuestionCollection($definition->getId());
269  foreach ($sharedQuestionCollection as $sharedQuestion) {
270  $relatedSrcPoolDefList = $this->getQuestRelatedSrcPoolDefinitionList($sharedQuestion->getQuestionId());
271  foreach ($relatedSrcPoolDefList as $otherDefinition) {
272  if ($otherDefinition->getId() == $definition->getId()) {
273  continue;
274  }
275 
276  if ($intersectionSharingDefinitionList->hasDefinition($otherDefinition->getId())) {
277  continue;
278  }
279 
280  $intersectionSharingDefinitionList->addDefinition($otherDefinition);
281  }
282  }
283 
284  return $intersectionSharingDefinitionList;
285  }
286 
292  {
293  /* @var ilTestRandomQuestionSetSourcePoolDefinitionList $qstRelatedSrcPoolDefList */
294  $qstRelatedSrcPoolDefList = $this->quest_related_src_pool_def_register[$question->getQuestionId()];
295  return $qstRelatedSrcPoolDefList->getDefinitionCount() > 1;
296  }
297 
302  {
303  return $this->getSrcPoolDefRelatedQuestionCollection($definition->getId())->getQuestionAmount();
304  }
305 
311  {
312  return $this->getExclusiveQuestionCollection($definition->getId())->getQuestionAmount();
313  }
314 
320  {
321  $intersectionSubsetApplicationList = $this->getIntersectionQuestionCollectionSubsetApplicationList($definition);
322 
323  foreach ($this->getSharedQuestionCollection($definition->getId()) as $sharedQuestion) {
324  $intersectionSubsetApplicationList->handleQuestionRequest($sharedQuestion);
325  }
326 
327  return $intersectionSubsetApplicationList->getNonReservedQuestionAmount();
328  }
329 
335  {
336  $exclusiveQstCollection = $this->getExclusiveQuestionCollection($definition->getId());
337  $missingExclsuiveQstCount = $exclusiveQstCollection->getMissingCount($definition->getQuestionAmount());
338  return $missingExclsuiveQstCount;
339  }
340 
346  {
347  return $this->getRequiredSharedQuestionAmount($definition) > 0;
348  }
349 
350  // -----------------------------------------------------------------------------------------------------------------
351 
352  public function initialise()
353  {
354  $this->initialiseRegisters();
355  }
356 
357  public function reset()
358  {
359  $this->resetRegisters();
360  }
361 
362  // -----------------------------------------------------------------------------------------------------------------
363 
369  {
370  $quantityCalculation = new ilTestRandomQuestionsSrcPoolDefinitionQuantitiesCalculation($definition);
371 
372  $quantityCalculation->setOverallQuestionAmount($this->getSrcPoolDefRelatedQuestionAmount($definition));
373  $quantityCalculation->setExclusiveQuestionAmount($this->getExclusiveQuestionAmount($definition));
374  $quantityCalculation->setAvailableSharedQuestionAmount($this->getAvailableSharedQuestionAmount($definition));
375 
376  $quantityCalculation->setIntersectionQuantitySharingDefinitionList(
377  $this->getIntersectionSharingDefinitionList($definition)
378  );
379 
380  return $quantityCalculation;
381  }
382 
383  // -----------------------------------------------------------------------------------------------------------------
384 }
getIntersectionQuestionCollectionSubsetApplicationList(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getIntersectionQstCollectionByDefinitionMap(ilTestRandomQuestionSetSourcePoolDefinition $definition)
__construct(private ilDBInterface $db, private ilTestRandomSourcePoolDefinitionQuestionCollectionProvider $question_collection_provider, private ilTestRandomQuestionSetSourcePoolDefinitionList $source_pool_definition_list)
getRequiredSharedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getIntersectionSharingDefinitionList(ilTestRandomQuestionSetSourcePoolDefinition $definition)
requiresSharedQuestions(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getAvailableSharedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isQuestionUsedByMultipleSrcPoolDefinitions(ilTestRandomQuestionSetQuestion $question)
calculateQuantities(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getExclusiveQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getSrcPoolDefRelatedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
registerSrcPoolDefRelatedQuest(int $definition_id, ilTestRandomQuestionSetQuestion $random_set_question)
getIntersectionQuestionCollection(int $this_definition_id, int $that_definition_id)
registerQuestRelatedSrcPoolDef(int $question_id, ilTestRandomQuestionSetSourcePoolDefinition $definition)