ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilTestRandomQuestionSetQuestionCollection Class Reference
+ Inheritance diagram for ilTestRandomQuestionSetQuestionCollection:
+ Collaboration diagram for ilTestRandomQuestionSetQuestionCollection:

Public Member Functions

 setQuestions (array $questions)
 
 getQuestions ()
 
 addQuestion (ilTestRandomQuestionSetQuestion $question)
 
 current ()
 
 next ()
 
 key ()
 
 valid ()
 
 rewind ()
 
 isGreaterThan ($amount)
 
 isSmallerThan ($amount)
 
 getMissingCount ($requiredAmount)
 
 shuffleQuestions ()
 
 mergeQuestionCollection (self $questionCollection)
 
 getUniqueQuestionCollection ()
 
 getRelativeComplementCollection (self $questionCollection)
 
 getIntersectionCollection (self $questionCollection)
 
 getQuestionAmount ()
 
 getInvolvedQuestionIds ()
 
 getRandomQuestionCollection ($requiredAmount)
 

Private Member Functions

 getRandomArrayKeys ($array, $numKeys)
 

Private Attributes

 $questions = []
 

Detailed Description

Member Function Documentation

◆ addQuestion()

ilTestRandomQuestionSetQuestionCollection::addQuestion ( ilTestRandomQuestionSetQuestion  $question)

Definition at line 44 of file class.ilTestRandomQuestionSetQuestionCollection.php.

45 {
46 $this->questions[] = $question;
47 }

◆ current()

ilTestRandomQuestionSetQuestionCollection::current ( )

Definition at line 49 of file class.ilTestRandomQuestionSetQuestionCollection.php.

References current().

Referenced by current().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIntersectionCollection()

ilTestRandomQuestionSetQuestionCollection::getIntersectionCollection ( self  $questionCollection)

Definition at line 153 of file class.ilTestRandomQuestionSetQuestionCollection.php.

154 {
155 $questionIds = array_flip($questionCollection->getInvolvedQuestionIds());
156
157 $intersectionCollection = new self();
158
159 foreach ($this->getQuestions() as $question) {
160 if (!isset($questionIds[$question->getQuestionId()])) {
161 continue;
162 }
163
164 $intersectionCollection->addQuestion($question);
165 }
166
167 return $intersectionCollection;
168 }

References getQuestions().

+ Here is the call graph for this function:

◆ getInvolvedQuestionIds()

ilTestRandomQuestionSetQuestionCollection::getInvolvedQuestionIds ( )

Definition at line 176 of file class.ilTestRandomQuestionSetQuestionCollection.php.

176 : array
177 {
178 $questionIds = [];
179
180 foreach ($this->getQuestions() as $question) {
181 $questionIds[] = $question->getQuestionId();
182 }
183
184 return $questionIds;
185 }

References getQuestions().

+ Here is the call graph for this function:

◆ getMissingCount()

ilTestRandomQuestionSetQuestionCollection::getMissingCount (   $requiredAmount)
Parameters
int$requiredAmount

Definition at line 89 of file class.ilTestRandomQuestionSetQuestionCollection.php.

89 : int
90 {
91 // hey: fixRandomTestBuildable - fix returning missing count instead of difference (neg values!)
92 $difference = $requiredAmount - count($this->questions);
93 $missingCount = $difference < 0 ? 0 : $difference;
94 return $missingCount;
95 // hey.
96 }

◆ getQuestionAmount()

ilTestRandomQuestionSetQuestionCollection::getQuestionAmount ( )

Definition at line 170 of file class.ilTestRandomQuestionSetQuestionCollection.php.

170 : int
171 {
172 return count($this->getQuestions());
173 }

References getQuestions().

+ Here is the call graph for this function:

◆ getQuestions()

ilTestRandomQuestionSetQuestionCollection::getQuestions ( )

◆ getRandomArrayKeys()

ilTestRandomQuestionSetQuestionCollection::getRandomArrayKeys (   $array,
  $numKeys 
)
private

Definition at line 200 of file class.ilTestRandomQuestionSetQuestionCollection.php.

201 {
202 if ($numKeys < 1) {
203 return [];
204 }
205
206 if ($numKeys > 1) {
207 return array_rand($array, $numKeys);
208 }
209
210 return [ array_rand($array, $numKeys) ];
211 }

Referenced by getRandomQuestionCollection().

+ Here is the caller graph for this function:

◆ getRandomQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::getRandomQuestionCollection (   $requiredAmount)

Definition at line 187 of file class.ilTestRandomQuestionSetQuestionCollection.php.

188 {
189 $randomKeys = $this->getRandomArrayKeys($this->questions, $requiredAmount);
190
191 $randomQuestionCollection = new self();
192
193 foreach ($randomKeys as $randomKey) {
194 $randomQuestionCollection->addQuestion($this->questions[$randomKey]);
195 }
196
197 return $randomQuestionCollection;
198 }

References getRandomArrayKeys().

Referenced by ilTestRandomQuestionSetBuilder\fetchQuestionsFromStageRandomly().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRelativeComplementCollection()

ilTestRandomQuestionSetQuestionCollection::getRelativeComplementCollection ( self  $questionCollection)

actually i would like to consider $this as quantity A passed $questionCollection is should be considered as quantity B

--> relative complement usually means all element from B missing in A

indeed we are considering $questionCollection as A and $this as B currently (!) when changing, do not forget to switch caller and param for all usages (!)

Definition at line 126 of file class.ilTestRandomQuestionSetQuestionCollection.php.

127 {
128 // hey: fixRandomTestBuildable - comment for refactoring
138 // hey.
139
140 $questionIds = array_flip($questionCollection->getInvolvedQuestionIds());
141
142 $relativeComplementCollection = new self();
143
144 foreach ($this->getQuestions() as $question) {
145 if (!isset($questionIds[$question->getQuestionId()])) {
146 $relativeComplementCollection->addQuestion($question);
147 }
148 }
149
150 return $relativeComplementCollection;
151 }

References getQuestions().

+ Here is the call graph for this function:

◆ getUniqueQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::getUniqueQuestionCollection ( )

Definition at line 108 of file class.ilTestRandomQuestionSetQuestionCollection.php.

109 {
110 $uniqueQuestions = [];
111
112 foreach ($this->getQuestions() as $question) {
113 /* @var ilTestRandomQuestionSetQuestion $question */
114
115 if (!isset($uniqueQuestions[$question->getQuestionId()])) {
116 $uniqueQuestions[$question->getQuestionId()] = $question;
117 }
118 }
119
120 $uniqueQuestionCollection = new self();
121 $uniqueQuestionCollection->setQuestions($uniqueQuestions);
122
123 return $uniqueQuestionCollection;
124 }

References getQuestions(), and setQuestions().

+ Here is the call graph for this function:

◆ isGreaterThan()

ilTestRandomQuestionSetQuestionCollection::isGreaterThan (   $amount)

Definition at line 76 of file class.ilTestRandomQuestionSetQuestionCollection.php.

76 : bool
77 {
78 return count($this->questions) > $amount;
79 }

◆ isSmallerThan()

ilTestRandomQuestionSetQuestionCollection::isSmallerThan (   $amount)

Definition at line 81 of file class.ilTestRandomQuestionSetQuestionCollection.php.

81 : bool
82 {
83 return count($this->questions) < $amount;
84 }

◆ key()

ilTestRandomQuestionSetQuestionCollection::key ( )

Definition at line 60 of file class.ilTestRandomQuestionSetQuestionCollection.php.

60 : ?string
61 {
62 return (string) key($this->questions);
63 }

References key().

Referenced by key(), and valid().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mergeQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::mergeQuestionCollection ( self  $questionCollection)

Definition at line 103 of file class.ilTestRandomQuestionSetQuestionCollection.php.

104 {
105 $this->questions = array_merge($this->questions, $questionCollection->getQuestions());
106 }

◆ next()

ilTestRandomQuestionSetQuestionCollection::next ( )

Definition at line 55 of file class.ilTestRandomQuestionSetQuestionCollection.php.

References next().

Referenced by next().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rewind()

ilTestRandomQuestionSetQuestionCollection::rewind ( )

Definition at line 70 of file class.ilTestRandomQuestionSetQuestionCollection.php.

70 : void
71 {
72 reset($this->questions);
73 }

◆ setQuestions()

ilTestRandomQuestionSetQuestionCollection::setQuestions ( array  $questions)

Definition at line 34 of file class.ilTestRandomQuestionSetQuestionCollection.php.

34 : void
35 {
36 $this->questions = $questions;
37 }

References $questions.

Referenced by getUniqueQuestionCollection().

+ Here is the caller graph for this function:

◆ shuffleQuestions()

ilTestRandomQuestionSetQuestionCollection::shuffleQuestions ( )

Definition at line 98 of file class.ilTestRandomQuestionSetQuestionCollection.php.

99 {
100 shuffle($this->questions);
101 }

Referenced by ilTestRandomQuestionSetBuilder\handleQuestionOrdering().

+ Here is the caller graph for this function:

◆ valid()

ilTestRandomQuestionSetQuestionCollection::valid ( )

Definition at line 65 of file class.ilTestRandomQuestionSetQuestionCollection.php.

65 : bool
66 {
67 return key($this->questions) !== null;
68 }

References key().

+ Here is the call graph for this function:

Field Documentation

◆ $questions

ilTestRandomQuestionSetQuestionCollection::$questions = []
private

The documentation for this class was generated from the following file: