ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestRandomQuestionsQuantitiesDistribution.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.ilObjTest.php';
5 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
6 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
7 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetQuestionCollection.php';
8 require_once 'Modules/Test/classes/class.ilTestRandomQuestionCollectionSubsetApplicationList.php';
9 require_once 'Modules/Test/classes/class.ilTestRandomQuestionsSrcPoolDefinitionQuantitiesCalculation.php';
10 
18 {
19  // -----------------------------------------------------------------------------------------------------------------
20 
25 
30 
31  // -----------------------------------------------------------------------------------------------------------------
32 
36  protected $questRelatedSrcPoolDefRegister = array();
37 
41  protected $srcPoolDefRelatedQuestRegister = array();
42 
43  // -----------------------------------------------------------------------------------------------------------------
44 
49  {
50  if ($questionCollectionProvider !== null) {
51  $this->setQuestionCollectionProvider($questionCollectionProvider);
52  }
53  }
54 
59  {
60  $this->questionCollectionProvider = $questionCollectionProvider;
61  }
62 
67  {
69  }
70 
75  {
76  $this->sourcePoolDefinitionList = $sourcePoolDefinitionList;
77  }
78 
82  public function getSourcePoolDefinitionList()
83  {
85  }
86 
87  // -----------------------------------------------------------------------------------------------------------------
88 
93  {
94  global $DIC; /* @var ILIAS\DI\Container $DIC */
95  $anyTestObject = new ilObjTest();
96  $nonRequiredDb = $DIC['ilDB'];
97  $nonUsedFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory($nonRequiredDb, $anyTestObject);
98  return new ilTestRandomQuestionSetSourcePoolDefinitionList($nonRequiredDb, $anyTestObject, $nonUsedFactory);
99  }
100 
105  {
107  }
108 
113  {
115  }
116 
121  {
123  }
124 
125  // -----------------------------------------------------------------------------------------------------------------
126 
131  {
132  $this->questRelatedSrcPoolDefRegister = array();
133  }
134 
140  {
141  if (!$this->questRelatedSrcPoolDefRegister[$questionId]) {
142  $this->questRelatedSrcPoolDefRegister[$questionId] = $this->buildSourcePoolDefinitionListInstance();
143  }
144 
145  $this->questRelatedSrcPoolDefRegister[$questionId]->addDefinition($definition);
146  }
147 
152  protected function getQuestRelatedSrcPoolDefinitionList($questionId)
153  {
154  if (isset($this->questRelatedSrcPoolDefRegister[$questionId])) {
155  return $this->questRelatedSrcPoolDefRegister[$questionId];
156  }
157 
158  return null;
159  }
160 
165  {
166  $this->srcPoolDefRelatedQuestRegister = array();
167  }
168 
173  protected function registerSrcPoolDefRelatedQuest($definitionId, ilTestRandomQuestionSetQuestion $randomSetQuestion)
174  {
175  if (!isset($this->srcPoolDefRelatedQuestRegister[$definitionId])) {
176  $this->srcPoolDefRelatedQuestRegister[$definitionId] = $this->buildRandomQuestionCollectionInstance();
177  }
178 
179  $this->srcPoolDefRelatedQuestRegister[$definitionId]->addQuestion($randomSetQuestion);
180  }
181 
186  protected function getSrcPoolDefRelatedQuestionCollection($definitionId)
187  {
188  if (isset($this->srcPoolDefRelatedQuestRegister[$definitionId])) {
189  return $this->srcPoolDefRelatedQuestRegister[$definitionId];
190  }
191 
193  }
194 
195  // -----------------------------------------------------------------------------------------------------------------
196 
200  protected function initialiseRegisters()
201  {
202  foreach ($this->getSrcPoolDefQuestionCombinationCollection() as $randomQuestion) {
203  $sourcePoolDefinition = $this->getSourcePoolDefinitionList()->getDefinition(
204  $randomQuestion->getSourcePoolDefinitionId()
205  );
206 
208  $randomQuestion->getSourcePoolDefinitionId(),
209  $randomQuestion
210  );
211 
213  $randomQuestion->getQuestionId(),
214  $sourcePoolDefinition
215  );
216  }
217  }
218 
222  protected function resetRegisters()
223  {
226  }
227 
228  // -----------------------------------------------------------------------------------------------------------------
229 
234  {
235  $qstCollectionProvider = $this->getQuestionCollectionProvider();
236  $srcPoolDefinitionList = $this->getSourcePoolDefinitionList();
237 
238  $defQstCombinationCollection = $qstCollectionProvider->getSrcPoolDefListRelatedQuestCombinationCollection(
239  $srcPoolDefinitionList
240  );
241 
242  return $defQstCombinationCollection;
243  }
244 
249  protected function getExclusiveQuestionCollection($definitionId)
250  {
251  $exclusiveQstCollection = $this->buildRandomQuestionCollectionInstance();
252 
253  foreach ($this->getSrcPoolDefRelatedQuestionCollection($definitionId) as $question) {
254  if ($this->isQuestionUsedByMultipleSrcPoolDefinitions($question)) {
255  continue;
256  }
257 
258  $exclusiveQstCollection->addQuestion($question);
259  }
260 
261  return $exclusiveQstCollection;
262  }
263 
268  protected function getSharedQuestionCollection($definitionId)
269  {
270  $srcPoolDefRelatedQstCollection = $this->getSrcPoolDefRelatedQuestionCollection($definitionId);
271  $exclusiveQstCollection = $this->getExclusiveQuestionCollection($definitionId);
272  return $srcPoolDefRelatedQstCollection->getRelativeComplementCollection($exclusiveQstCollection);
273  }
274 
280  protected function getIntersectionQuestionCollection($thisDefinitionId, $thatDefinitionId)
281  {
282  $thisDefRelatedSharedQstCollection = $this->getSharedQuestionCollection($thisDefinitionId);
283  $thatDefRelatedSharedQstCollection = $this->getSharedQuestionCollection($thatDefinitionId);
284 
285  $intersectionQstCollection = $thisDefRelatedSharedQstCollection->getIntersectionCollection(
286  $thatDefRelatedSharedQstCollection
287  );
288 
289  return $intersectionQstCollection;
290  }
291 
297  {
298  $intersectionQstCollectionsByDefId = array();
299 
300  $sharedQuestionCollection = $this->getSharedQuestionCollection($definition->getId());
301  foreach ($sharedQuestionCollection as $sharedQuestion) {
302  $relatedSrcPoolDefList = $this->getQuestRelatedSrcPoolDefinitionList($sharedQuestion->getQuestionId());
303  foreach ($relatedSrcPoolDefList as $otherDefinition) {
304  if ($otherDefinition->getId() == $definition->getId()) {
305  continue;
306  }
307 
308  if (isset($intersectionQstCollectionsByDefId[$otherDefinition->getId()])) {
309  continue;
310  }
311 
312  $intersectionQuestionCollection = $this->getIntersectionQuestionCollection(
313  $definition->getId(),
314  $otherDefinition->getId()
315  );
316 
317  $intersectionQstCollectionsByDefId[$otherDefinition->getId()] = $intersectionQuestionCollection;
318  }
319  }
320 
321  return $intersectionQstCollectionsByDefId;
322  }
323 
329  {
330  $qstCollectionSubsetApplicationList = $this->buildQuestionCollectionSubsetApplicationListInstance();
331 
332  $intersectionQstCollectionByDefIdMap = $this->getIntersectionQstCollectionByDefinitionMap($definition);
333  foreach ($intersectionQstCollectionByDefIdMap as $otherDefinitionId => $intersectionCollection) {
334  /* @var ilTestRandomQuestionSetQuestionCollection $intersectionCollection */
335 
336  $qstCollectionSubsetApplication = $this->buildQuestionCollectionSubsetApplicationInstance();
337  $qstCollectionSubsetApplication->setQuestions($intersectionCollection->getQuestions());
338  $qstCollectionSubsetApplication->setApplicantId($otherDefinitionId);
339 
340  #$qstCollectionSubsetApplication->setRequiredAmount($this->getRequiredSharedQuestionAmount(
341  # $this->getSourcePoolDefinitionList()->getDefinition($otherDefinitionId)
342  #));
343 
344  $qstCollectionSubsetApplication->setRequiredAmount(
345  $this->getSourcePoolDefinitionList()->getDefinition($otherDefinitionId)->getQuestionAmount()
346  );
347 
348  $qstCollectionSubsetApplicationList->addCollectionSubsetApplication($qstCollectionSubsetApplication);
349  }
350 
351  return $qstCollectionSubsetApplicationList;
352  }
353 
354  // -----------------------------------------------------------------------------------------------------------------
355 
361  {
362  $intersectionSharingDefinitionList = $this->buildSourcePoolDefinitionListInstance();
363 
364  $sharedQuestionCollection = $this->getSharedQuestionCollection($definition->getId());
365  foreach ($sharedQuestionCollection as $sharedQuestion) {
366  $relatedSrcPoolDefList = $this->getQuestRelatedSrcPoolDefinitionList($sharedQuestion->getQuestionId());
367  foreach ($relatedSrcPoolDefList as $otherDefinition) {
368  if ($otherDefinition->getId() == $definition->getId()) {
369  continue;
370  }
371 
372  if ($intersectionSharingDefinitionList->hasDefinition($otherDefinition->getId())) {
373  continue;
374  }
375 
376  $intersectionSharingDefinitionList->addDefinition($otherDefinition);
377  }
378  }
379 
380  return $intersectionSharingDefinitionList;
381  }
382 
388  {
389  /* @var ilTestRandomQuestionSetSourcePoolDefinitionList $qstRelatedSrcPoolDefList */
390  $qstRelatedSrcPoolDefList = $this->questRelatedSrcPoolDefRegister[$question->getQuestionId()];
391  return $qstRelatedSrcPoolDefList->getDefinitionCount() > 1;
392  }
393 
398  {
399  return $this->getSrcPoolDefRelatedQuestionCollection($definition->getId())->getQuestionAmount();
400  }
401 
407  {
408  return $this->getExclusiveQuestionCollection($definition->getId())->getQuestionAmount();
409  }
410 
416  {
417  $intersectionSubsetApplicationList = $this->getIntersectionQuestionCollectionSubsetApplicationList($definition);
418 
419  foreach ($this->getSharedQuestionCollection($definition->getId()) as $sharedQuestion) {
420  $intersectionSubsetApplicationList->handleQuestionRequest($sharedQuestion);
421  }
422 
423  return $intersectionSubsetApplicationList->getNonReservedQuestionAmount();
424  }
425 
431  {
432  $exclusiveQstCollection = $this->getExclusiveQuestionCollection($definition->getId());
433  $missingExclsuiveQstCount = $exclusiveQstCollection->getMissingCount($definition->getQuestionAmount());
434  return $missingExclsuiveQstCount;
435  }
436 
442  {
443  return $this->getRequiredSharedQuestionAmount($definition) > 0;
444  }
445 
446  // -----------------------------------------------------------------------------------------------------------------
447 
448  public function initialise()
449  {
450  $this->initialiseRegisters();
451  }
452 
453  public function reset()
454  {
455  $this->resetRegisters();
456  }
457 
458  // -----------------------------------------------------------------------------------------------------------------
459 
465  {
466  $quantityCalculation = new ilTestRandomQuestionsSrcPoolDefinitionQuantitiesCalculation($definition);
467 
468  $quantityCalculation->setOverallQuestionAmount($this->getSrcPoolDefRelatedQuestionAmount($definition));
469  $quantityCalculation->setExclusiveQuestionAmount($this->getExclusiveQuestionAmount($definition));
470  $quantityCalculation->setAvailableSharedQuestionAmount($this->getAvailableSharedQuestionAmount($definition));
471 
472  $quantityCalculation->setIntersectionQuantitySharingDefinitionList(
473  $this->getIntersectionSharingDefinitionList($definition)
474  );
475 
476  return $quantityCalculation;
477  }
478 
479  // -----------------------------------------------------------------------------------------------------------------
480 }
getIntersectionQuestionCollectionSubsetApplicationList(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getIntersectionQstCollectionByDefinitionMap(ilTestRandomQuestionSetSourcePoolDefinition $definition)
resetQuestRelatedSrcPoolDefRegister()
re-setter for questRelatedSrcPoolDefRegister
resetSrcPoolDefRelatedQuestRegister()
re-setter the srcPoolDefRelatedQuestRegister
global $DIC
Definition: saml.php:7
getRequiredSharedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getIntersectionSharingDefinitionList(ilTestRandomQuestionSetSourcePoolDefinition $definition)
registerSrcPoolDefRelatedQuest($definitionId, ilTestRandomQuestionSetQuestion $randomSetQuestion)
initialiseRegisters()
initialise the src-pool-def/question registers
requiresSharedQuestions(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getAvailableSharedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
setQuestionCollectionProvider(ilTestRandomSourcePoolDefinitionQuestionCollectionProvider $questionCollectionProvider)
isQuestionUsedByMultipleSrcPoolDefinitions(ilTestRandomQuestionSetQuestion $question)
registerQuestRelatedSrcPoolDef($questionId, ilTestRandomQuestionSetSourcePoolDefinition $definition)
calculateQuantities(ilTestRandomQuestionSetSourcePoolDefinition $definition)
__construct(ilTestRandomSourcePoolDefinitionQuestionCollectionProvider $questionCollectionProvider)
getExclusiveQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getSrcPoolDefRelatedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)