ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestRandomQuestionsQuantitiesDistribution.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  // -----------------------------------------------------------------------------------------------------------------
28 
33 
38 
39  // -----------------------------------------------------------------------------------------------------------------
40 
44  protected $questRelatedSrcPoolDefRegister = array();
45 
49  protected $srcPoolDefRelatedQuestRegister = array();
50 
51  // -----------------------------------------------------------------------------------------------------------------
52 
57  {
58  if ($questionCollectionProvider !== null) {
59  $this->setQuestionCollectionProvider($questionCollectionProvider);
60  }
61  }
62 
67  {
68  $this->questionCollectionProvider = $questionCollectionProvider;
69  }
70 
75  {
77  }
78 
83  {
84  $this->sourcePoolDefinitionList = $sourcePoolDefinitionList;
85  }
86 
91  {
93  }
94 
95  // -----------------------------------------------------------------------------------------------------------------
96 
101  {
102  global $DIC; /* @var ILIAS\DI\Container $DIC */
103  $anyTestObject = new ilObjTest();
104  $nonRequiredDb = $DIC['ilDB'];
105  $nonUsedFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory($nonRequiredDb, $anyTestObject);
106  return new ilTestRandomQuestionSetSourcePoolDefinitionList($nonRequiredDb, $anyTestObject, $nonUsedFactory);
107  }
108 
113  {
115  }
116 
121  {
123  }
124 
129  {
131  }
132 
133  // -----------------------------------------------------------------------------------------------------------------
134 
139  {
140  $this->questRelatedSrcPoolDefRegister = array();
141  }
142 
143  protected function registerQuestRelatedSrcPoolDef(int $questionId, ilTestRandomQuestionSetSourcePoolDefinition $definition): void
144  {
145  if (!array_key_exists($questionId, $this->questRelatedSrcPoolDefRegister)) {
146  $this->questRelatedSrcPoolDefRegister[$questionId] = $this->buildSourcePoolDefinitionListInstance();
147  }
148 
149  $this->questRelatedSrcPoolDefRegister[$questionId]->addDefinition($definition);
150  }
151 
157  {
158  if (isset($this->questRelatedSrcPoolDefRegister[$questionId])) {
159  return $this->questRelatedSrcPoolDefRegister[$questionId];
160  }
161 
162  return null;
163  }
164 
169  {
170  $this->srcPoolDefRelatedQuestRegister = array();
171  }
172 
177  protected function registerSrcPoolDefRelatedQuest($definitionId, ilTestRandomQuestionSetQuestion $randomSetQuestion)
178  {
179  if (!isset($this->srcPoolDefRelatedQuestRegister[$definitionId])) {
180  $this->srcPoolDefRelatedQuestRegister[$definitionId] = $this->buildRandomQuestionCollectionInstance();
181  }
182 
183  $this->srcPoolDefRelatedQuestRegister[$definitionId]->addQuestion($randomSetQuestion);
184  }
185 
191  {
192  if (isset($this->srcPoolDefRelatedQuestRegister[$definitionId])) {
193  return $this->srcPoolDefRelatedQuestRegister[$definitionId];
194  }
195 
197  }
198 
199  // -----------------------------------------------------------------------------------------------------------------
200 
204  protected function initialiseRegisters()
205  {
206  foreach ($this->getSrcPoolDefQuestionCombinationCollection() as $randomQuestion) {
207  $sourcePoolDefinition = $this->getSourcePoolDefinitionList()->getDefinition(
208  $randomQuestion->getSourcePoolDefinitionId()
209  );
210 
212  $randomQuestion->getSourcePoolDefinitionId(),
213  $randomQuestion
214  );
215 
216  if ($sourcePoolDefinition && $randomQuestion->getQuestionId()) {
218  $randomQuestion->getQuestionId(),
219  $sourcePoolDefinition
220  );
221  }
222 
223  }
224  }
225 
229  protected function resetRegisters()
230  {
233  }
234 
235  // -----------------------------------------------------------------------------------------------------------------
236 
241  {
242  return $this->getQuestionCollectionProvider()->getSrcPoolDefListRelatedQuestCombinationCollection(
244  );
245  }
246 
252  {
253  $exclusiveQstCollection = $this->buildRandomQuestionCollectionInstance();
254 
255  foreach ($this->getSrcPoolDefRelatedQuestionCollection($definitionId) as $question) {
256  if ($this->isQuestionUsedByMultipleSrcPoolDefinitions($question)) {
257  continue;
258  }
259 
260  $exclusiveQstCollection->addQuestion($question);
261  }
262 
263  return $exclusiveQstCollection;
264  }
265 
271  {
272  $srcPoolDefRelatedQstCollection = $this->getSrcPoolDefRelatedQuestionCollection($definitionId);
273  $exclusiveQstCollection = $this->getExclusiveQuestionCollection($definitionId);
274  return $srcPoolDefRelatedQstCollection->getRelativeComplementCollection($exclusiveQstCollection);
275  }
276 
282  protected function getIntersectionQuestionCollection($thisDefinitionId, $thatDefinitionId): ilTestRandomQuestionSetQuestionCollection
283  {
284  $thisDefRelatedSharedQstCollection = $this->getSharedQuestionCollection($thisDefinitionId);
285  $thatDefRelatedSharedQstCollection = $this->getSharedQuestionCollection($thatDefinitionId);
286 
287  $intersectionQstCollection = $thisDefRelatedSharedQstCollection->getIntersectionCollection(
288  $thatDefRelatedSharedQstCollection
289  );
290 
291  return $intersectionQstCollection;
292  }
293 
299  {
300  $intersectionQstCollectionsByDefId = array();
301 
302  $sharedQuestionCollection = $this->getSharedQuestionCollection($definition->getId());
303  foreach ($sharedQuestionCollection as $sharedQuestion) {
304  $relatedSrcPoolDefList = $this->getQuestRelatedSrcPoolDefinitionList($sharedQuestion->getQuestionId());
305  foreach ($relatedSrcPoolDefList as $otherDefinition) {
306  if ($otherDefinition->getId() == $definition->getId()) {
307  continue;
308  }
309 
310  if (isset($intersectionQstCollectionsByDefId[$otherDefinition->getId()])) {
311  continue;
312  }
313 
314  $intersectionQuestionCollection = $this->getIntersectionQuestionCollection(
315  $definition->getId(),
316  $otherDefinition->getId()
317  );
318 
319  $intersectionQstCollectionsByDefId[$otherDefinition->getId()] = $intersectionQuestionCollection;
320  }
321  }
322 
323  return $intersectionQstCollectionsByDefId;
324  }
325 
331  {
332  $qstCollectionSubsetApplicationList = $this->buildQuestionCollectionSubsetApplicationListInstance();
333 
334  $intersectionQstCollectionByDefIdMap = $this->getIntersectionQstCollectionByDefinitionMap($definition);
335  foreach ($intersectionQstCollectionByDefIdMap as $otherDefinitionId => $intersectionCollection) {
336  /* @var ilTestRandomQuestionSetQuestionCollection $intersectionCollection */
337 
338  $qstCollectionSubsetApplication = $this->buildQuestionCollectionSubsetApplicationInstance();
339  $qstCollectionSubsetApplication->setQuestions($intersectionCollection->getQuestions());
340  $qstCollectionSubsetApplication->setApplicantId($otherDefinitionId);
341 
342  #$qstCollectionSubsetApplication->setRequiredAmount($this->getRequiredSharedQuestionAmount(
343  # $this->getSourcePoolDefinitionList()->getDefinition($otherDefinitionId)
344  #));
345 
346  $qstCollectionSubsetApplication->setRequiredAmount(
347  $this->getSourcePoolDefinitionList()->getDefinition($otherDefinitionId)->getQuestionAmount()
348  );
349 
350  $qstCollectionSubsetApplicationList->addCollectionSubsetApplication($qstCollectionSubsetApplication);
351  }
352 
353  return $qstCollectionSubsetApplicationList;
354  }
355 
356  // -----------------------------------------------------------------------------------------------------------------
357 
363  {
364  $intersectionSharingDefinitionList = $this->buildSourcePoolDefinitionListInstance();
365 
366  $sharedQuestionCollection = $this->getSharedQuestionCollection($definition->getId());
367  foreach ($sharedQuestionCollection as $sharedQuestion) {
368  $relatedSrcPoolDefList = $this->getQuestRelatedSrcPoolDefinitionList($sharedQuestion->getQuestionId());
369  foreach ($relatedSrcPoolDefList as $otherDefinition) {
370  if ($otherDefinition->getId() == $definition->getId()) {
371  continue;
372  }
373 
374  if ($intersectionSharingDefinitionList->hasDefinition($otherDefinition->getId())) {
375  continue;
376  }
377 
378  $intersectionSharingDefinitionList->addDefinition($otherDefinition);
379  }
380  }
381 
382  return $intersectionSharingDefinitionList;
383  }
384 
390  {
391  /* @var ilTestRandomQuestionSetSourcePoolDefinitionList $qstRelatedSrcPoolDefList */
392  $qstRelatedSrcPoolDefList = $this->questRelatedSrcPoolDefRegister[$question->getQuestionId()];
393  return $qstRelatedSrcPoolDefList->getDefinitionCount() > 1;
394  }
395 
400  {
401  return $this->getSrcPoolDefRelatedQuestionCollection($definition->getId())->getQuestionAmount();
402  }
403 
409  {
410  return $this->getExclusiveQuestionCollection($definition->getId())->getQuestionAmount();
411  }
412 
418  {
419  $intersectionSubsetApplicationList = $this->getIntersectionQuestionCollectionSubsetApplicationList($definition);
420 
421  foreach ($this->getSharedQuestionCollection($definition->getId()) as $sharedQuestion) {
422  $intersectionSubsetApplicationList->handleQuestionRequest($sharedQuestion);
423  }
424 
425  return $intersectionSubsetApplicationList->getNonReservedQuestionAmount();
426  }
427 
433  {
434  $exclusiveQstCollection = $this->getExclusiveQuestionCollection($definition->getId());
435  $missingExclsuiveQstCount = $exclusiveQstCollection->getMissingCount($definition->getQuestionAmount());
436  return $missingExclsuiveQstCount;
437  }
438 
444  {
445  return $this->getRequiredSharedQuestionAmount($definition) > 0;
446  }
447 
448  // -----------------------------------------------------------------------------------------------------------------
449 
450  public function initialise()
451  {
452  $this->initialiseRegisters();
453  }
454 
455  public function reset()
456  {
457  $this->resetRegisters();
458  }
459 
460  // -----------------------------------------------------------------------------------------------------------------
461 
467  {
468  $quantityCalculation = new ilTestRandomQuestionsSrcPoolDefinitionQuantitiesCalculation($definition);
469 
470  $quantityCalculation->setOverallQuestionAmount($this->getSrcPoolDefRelatedQuestionAmount($definition));
471  $quantityCalculation->setExclusiveQuestionAmount($this->getExclusiveQuestionAmount($definition));
472  $quantityCalculation->setAvailableSharedQuestionAmount($this->getAvailableSharedQuestionAmount($definition));
473 
474  $quantityCalculation->setIntersectionQuantitySharingDefinitionList(
475  $this->getIntersectionSharingDefinitionList($definition)
476  );
477 
478  return $quantityCalculation;
479  }
480 
481  // -----------------------------------------------------------------------------------------------------------------
482 }
getIntersectionQuestionCollectionSubsetApplicationList(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getIntersectionQstCollectionByDefinitionMap(ilTestRandomQuestionSetSourcePoolDefinition $definition)
resetQuestRelatedSrcPoolDefRegister()
re-setter for questRelatedSrcPoolDefRegister
resetSrcPoolDefRelatedQuestRegister()
re-setter the srcPoolDefRelatedQuestRegister
getRequiredSharedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getIntersectionSharingDefinitionList(ilTestRandomQuestionSetSourcePoolDefinition $definition)
registerSrcPoolDefRelatedQuest($definitionId, ilTestRandomQuestionSetQuestion $randomSetQuestion)
initialiseRegisters()
initialise the src-pool-def/question registers
requiresSharedQuestions(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getAvailableSharedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
global $DIC
Definition: feed.php:28
setQuestionCollectionProvider(ilTestRandomSourcePoolDefinitionQuestionCollectionProvider $questionCollectionProvider)
isQuestionUsedByMultipleSrcPoolDefinitions(ilTestRandomQuestionSetQuestion $question)
calculateQuantities(ilTestRandomQuestionSetSourcePoolDefinition $definition)
__construct(ilTestRandomSourcePoolDefinitionQuestionCollectionProvider $questionCollectionProvider)
getExclusiveQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getSrcPoolDefRelatedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
registerQuestRelatedSrcPoolDef(int $questionId, ilTestRandomQuestionSetSourcePoolDefinition $definition)