ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4require_once 'Modules/Test/classes/class.ilObjTest.php';
5require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
6require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
7require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetQuestionCollection.php';
8require_once 'Modules/Test/classes/class.ilTestRandomQuestionCollectionSubsetApplicationList.php';
9require_once 'Modules/Test/classes/class.ilTestRandomQuestionsSrcPoolDefinitionQuantitiesCalculation.php';
10
18{
19 // -----------------------------------------------------------------------------------------------------------------
20
25
30
31 // -----------------------------------------------------------------------------------------------------------------
32
37
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
83 {
85 }
86
87 // -----------------------------------------------------------------------------------------------------------------
88
93 {
94 $anyTestObject = new ilObjTest();
95 $nonRequiredDb = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['ilDB'] : $GLOBALS['ilDB'];
96 $nonUsedFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory($nonRequiredDb, $anyTestObject);
97 return new ilTestRandomQuestionSetSourcePoolDefinitionList($nonRequiredDb, $anyTestObject, $nonUsedFactory);
98 }
99
104 {
106 }
107
112 {
114 }
115
120 {
122 }
123
124 // -----------------------------------------------------------------------------------------------------------------
125
130 {
131 $this->questRelatedSrcPoolDefRegister = array();
132 }
133
139 {
140 if (!$this->questRelatedSrcPoolDefRegister[$questionId]) {
141 $this->questRelatedSrcPoolDefRegister[$questionId] = $this->buildSourcePoolDefinitionListInstance();
142 }
143
144 $this->questRelatedSrcPoolDefRegister[$questionId]->addDefinition($definition);
145 }
146
151 protected function getQuestRelatedSrcPoolDefinitionList($questionId)
152 {
153 if (isset($this->questRelatedSrcPoolDefRegister[$questionId])) {
154 return $this->questRelatedSrcPoolDefRegister[$questionId];
155 }
156
157 return null;
158 }
159
164 {
165 $this->srcPoolDefRelatedQuestRegister = array();
166 }
167
172 protected function registerSrcPoolDefRelatedQuest($definitionId, ilTestRandomQuestionSetQuestion $randomSetQuestion)
173 {
174 if (!isset($this->srcPoolDefRelatedQuestRegister[$definitionId])) {
175 $this->srcPoolDefRelatedQuestRegister[$definitionId] = $this->buildRandomQuestionCollectionInstance();
176 }
177
178 $this->srcPoolDefRelatedQuestRegister[$definitionId]->addQuestion($randomSetQuestion);
179 }
180
185 protected function getSrcPoolDefRelatedQuestionCollection($definitionId)
186 {
187 if (isset($this->srcPoolDefRelatedQuestRegister[$definitionId])) {
188 return $this->srcPoolDefRelatedQuestRegister[$definitionId];
189 }
190
192 }
193
194 // -----------------------------------------------------------------------------------------------------------------
195
199 protected function initialiseRegisters()
200 {
201 foreach ($this->getSrcPoolDefQuestionCombinationCollection() as $randomQuestion) {
202 $sourcePoolDefinition = $this->getSourcePoolDefinitionList()->getDefinition(
203 $randomQuestion->getSourcePoolDefinitionId()
204 );
205
207 $randomQuestion->getSourcePoolDefinitionId(),
208 $randomQuestion
209 );
210
212 $randomQuestion->getQuestionId(),
213 $sourcePoolDefinition
214 );
215 }
216 }
217
221 protected function resetRegisters()
222 {
225 }
226
227 // -----------------------------------------------------------------------------------------------------------------
228
233 {
234 $qstCollectionProvider = $this->getQuestionCollectionProvider();
235 $srcPoolDefinitionList = $this->getSourcePoolDefinitionList();
236
237 $defQstCombinationCollection = $qstCollectionProvider->getSrcPoolDefListRelatedQuestCombinationCollection(
238 $srcPoolDefinitionList
239 );
240
241 return $defQstCombinationCollection;
242 }
243
248 protected function getExclusiveQuestionCollection($definitionId)
249 {
250 $exclusiveQstCollection = $this->buildRandomQuestionCollectionInstance();
251
252 foreach ($this->getSrcPoolDefRelatedQuestionCollection($definitionId) as $question) {
253 if ($this->isQuestionUsedByMultipleSrcPoolDefinitions($question)) {
254 continue;
255 }
256
257 $exclusiveQstCollection->addQuestion($question);
258 }
259
260 return $exclusiveQstCollection;
261 }
262
267 protected function getSharedQuestionCollection($definitionId)
268 {
269 $srcPoolDefRelatedQstCollection = $this->getSrcPoolDefRelatedQuestionCollection($definitionId);
270 $exclusiveQstCollection = $this->getExclusiveQuestionCollection($definitionId);
271 return $srcPoolDefRelatedQstCollection->getRelativeComplementCollection($exclusiveQstCollection);
272 }
273
279 protected function getIntersectionQuestionCollection($thisDefinitionId, $thatDefinitionId)
280 {
281 $thisDefRelatedSharedQstCollection = $this->getSharedQuestionCollection($thisDefinitionId);
282 $thatDefRelatedSharedQstCollection = $this->getSharedQuestionCollection($thatDefinitionId);
283
284 $intersectionQstCollection = $thisDefRelatedSharedQstCollection->getIntersectionCollection(
285 $thatDefRelatedSharedQstCollection
286 );
287
288 return $intersectionQstCollection;
289 }
290
296 {
297 $intersectionQstCollectionsByDefId = array();
298
299 $sharedQuestionCollection = $this->getSharedQuestionCollection($definition->getId());
300 foreach ($sharedQuestionCollection as $sharedQuestion) {
301 $relatedSrcPoolDefList = $this->getQuestRelatedSrcPoolDefinitionList($sharedQuestion->getQuestionId());
302 foreach ($relatedSrcPoolDefList as $otherDefinition) {
303 if ($otherDefinition->getId() == $definition->getId()) {
304 continue;
305 }
306
307 if (isset($intersectionQstCollectionsByDefId[$otherDefinition->getId()])) {
308 continue;
309 }
310
311 $intersectionQuestionCollection = $this->getIntersectionQuestionCollection(
312 $definition->getId(),
313 $otherDefinition->getId()
314 );
315
316 $intersectionQstCollectionsByDefId[$otherDefinition->getId()] = $intersectionQuestionCollection;
317 }
318 }
319
320 return $intersectionQstCollectionsByDefId;
321 }
322
328 {
329 $qstCollectionSubsetApplicationList = $this->buildQuestionCollectionSubsetApplicationListInstance();
330
331 $intersectionQstCollectionByDefIdMap = $this->getIntersectionQstCollectionByDefinitionMap($definition);
332 foreach ($intersectionQstCollectionByDefIdMap as $otherDefinitionId => $intersectionCollection) {
333 /* @var ilTestRandomQuestionSetQuestionCollection $intersectionCollection */
334
335 $qstCollectionSubsetApplication = $this->buildQuestionCollectionSubsetApplicationInstance();
336 $qstCollectionSubsetApplication->setQuestions($intersectionCollection->getQuestions());
337 $qstCollectionSubsetApplication->setApplicantId($otherDefinitionId);
338
339 #$qstCollectionSubsetApplication->setRequiredAmount($this->getRequiredSharedQuestionAmount(
340 # $this->getSourcePoolDefinitionList()->getDefinition($otherDefinitionId)
341 #));
342
343 $qstCollectionSubsetApplication->setRequiredAmount(
344 $this->getSourcePoolDefinitionList()->getDefinition($otherDefinitionId)->getQuestionAmount()
345 );
346
347 $qstCollectionSubsetApplicationList->addCollectionSubsetApplication($qstCollectionSubsetApplication);
348 }
349
350 return $qstCollectionSubsetApplicationList;
351 }
352
353 // -----------------------------------------------------------------------------------------------------------------
354
360 {
361 $intersectionSharingDefinitionList = $this->buildSourcePoolDefinitionListInstance();
362
363 $sharedQuestionCollection = $this->getSharedQuestionCollection($definition->getId());
364 foreach ($sharedQuestionCollection as $sharedQuestion) {
365 $relatedSrcPoolDefList = $this->getQuestRelatedSrcPoolDefinitionList($sharedQuestion->getQuestionId());
366 foreach ($relatedSrcPoolDefList as $otherDefinition) {
367 if ($otherDefinition->getId() == $definition->getId()) {
368 continue;
369 }
370
371 if ($intersectionSharingDefinitionList->hasDefinition($otherDefinition->getId())) {
372 continue;
373 }
374
375 $intersectionSharingDefinitionList->addDefinition($otherDefinition);
376 }
377 }
378
379 return $intersectionSharingDefinitionList;
380 }
381
387 {
388 /* @var ilTestRandomQuestionSetSourcePoolDefinitionList $qstRelatedSrcPoolDefList */
389 $qstRelatedSrcPoolDefList = $this->questRelatedSrcPoolDefRegister[$question->getQuestionId()];
390 return $qstRelatedSrcPoolDefList->getDefinitionCount() > 1;
391 }
392
397 {
398 return $this->getSrcPoolDefRelatedQuestionCollection($definition->getId())->getQuestionAmount();
399 }
400
406 {
407 return $this->getExclusiveQuestionCollection($definition->getId())->getQuestionAmount();
408 }
409
415 {
416 $intersectionSubsetApplicationList = $this->getIntersectionQuestionCollectionSubsetApplicationList($definition);
417
418 foreach ($this->getSharedQuestionCollection($definition->getId()) as $sharedQuestion) {
419 $intersectionSubsetApplicationList->handleQuestionRequest($sharedQuestion);
420 }
421
422 return $intersectionSubsetApplicationList->getNonReservedQuestionAmount();
423 }
424
430 {
431 $exclusiveQstCollection = $this->getExclusiveQuestionCollection($definition->getId());
432 $missingExclsuiveQstCount = $exclusiveQstCollection->getMissingCount($definition->getQuestionAmount());
433 return $missingExclsuiveQstCount;
434 }
435
441 {
442 return $this->getRequiredSharedQuestionAmount($definition) > 0;
443 }
444
445 // -----------------------------------------------------------------------------------------------------------------
446
447 public function initialise()
448 {
449 $this->initialiseRegisters();
450 }
451
452 public function reset()
453 {
454 $this->resetRegisters();
455 }
456
457 // -----------------------------------------------------------------------------------------------------------------
458
464 {
465 $quantityCalculation = new ilTestRandomQuestionsSrcPoolDefinitionQuantitiesCalculation($definition);
466
467 $quantityCalculation->setOverallQuestionAmount($this->getSrcPoolDefRelatedQuestionAmount($definition));
468 $quantityCalculation->setExclusiveQuestionAmount($this->getExclusiveQuestionAmount($definition));
469 $quantityCalculation->setAvailableSharedQuestionAmount($this->getAvailableSharedQuestionAmount($definition));
470
471 $quantityCalculation->setIntersectionQuantitySharingDefinitionList(
472 $this->getIntersectionSharingDefinitionList($definition)
473 );
474
475 return $quantityCalculation;
476 }
477
478 // -----------------------------------------------------------------------------------------------------------------
479}
An exception for terminatinating execution or to throw for unit testing.
getIntersectionQstCollectionByDefinitionMap(ilTestRandomQuestionSetSourcePoolDefinition $definition)
setQuestionCollectionProvider(ilTestRandomSourcePoolDefinitionQuestionCollectionProvider $questionCollectionProvider)
resetSrcPoolDefRelatedQuestRegister()
re-setter the srcPoolDefRelatedQuestRegister
getAvailableSharedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getRequiredSharedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
registerQuestRelatedSrcPoolDef($questionId, ilTestRandomQuestionSetSourcePoolDefinition $definition)
isQuestionUsedByMultipleSrcPoolDefinitions(ilTestRandomQuestionSetQuestion $question)
__construct(ilTestRandomSourcePoolDefinitionQuestionCollectionProvider $questionCollectionProvider)
getExclusiveQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
registerSrcPoolDefRelatedQuest($definitionId, ilTestRandomQuestionSetQuestion $randomSetQuestion)
getSrcPoolDefRelatedQuestionAmount(ilTestRandomQuestionSetSourcePoolDefinition $definition)
requiresSharedQuestions(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getIntersectionQuestionCollectionSubsetApplicationList(ilTestRandomQuestionSetSourcePoolDefinition $definition)
getIntersectionSharingDefinitionList(ilTestRandomQuestionSetSourcePoolDefinition $definition)
calculateQuantities(ilTestRandomQuestionSetSourcePoolDefinition $definition)
resetQuestRelatedSrcPoolDefRegister()
re-setter for questRelatedSrcPoolDefRegister
$GLOBALS['loaded']
Global hash that tracks already loaded includes.