ILIAS  release_8 Revision v8.24
ilTestRandomQuestionSetQuestionCollection Class Reference
+ Inheritance diagram for ilTestRandomQuestionSetQuestionCollection:
+ Collaboration diagram for ilTestRandomQuestionSetQuestionCollection:

Public Member Functions

 setQuestions ($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 = array()
 

Detailed Description

Member Function Documentation

◆ addQuestion()

ilTestRandomQuestionSetQuestionCollection::addQuestion ( ilTestRandomQuestionSetQuestion  $question)

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

43 {
44 $this->questions[] = $question;
45 }

◆ current()

ilTestRandomQuestionSetQuestionCollection::current ( )
Returns
ilTestRandomQuestionSetQuestion|false

Definition at line 50 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 159 of file class.ilTestRandomQuestionSetQuestionCollection.php.

160 {
161 $questionIds = array_flip($questionCollection->getInvolvedQuestionIds());
162
163 $intersectionCollection = new self();
164
165 foreach ($this->getQuestions() as $question) {
166 if (!isset($questionIds[$question->getQuestionId()])) {
167 continue;
168 }
169
170 $intersectionCollection->addQuestion($question);
171 }
172
173 return $intersectionCollection;
174 }

References getQuestions().

+ Here is the call graph for this function:

◆ getInvolvedQuestionIds()

ilTestRandomQuestionSetQuestionCollection::getInvolvedQuestionIds ( )

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

182 : array
183 {
184 $questionIds = array();
185
186 foreach ($this->getQuestions() as $question) {
187 $questionIds[] = $question->getQuestionId();
188 }
189
190 return $questionIds;
191 }

References getQuestions().

+ Here is the call graph for this function:

◆ getMissingCount()

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

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

95 : int
96 {
97 // hey: fixRandomTestBuildable - fix returning missing count instead of difference (neg values!)
98 $difference = $requiredAmount - count($this->questions);
99 $missingCount = $difference < 0 ? 0 : $difference;
100 return $missingCount;
101 // hey.
102 }

◆ getQuestionAmount()

ilTestRandomQuestionSetQuestionCollection::getQuestionAmount ( )

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

176 : int
177 {
178 return count($this->getQuestions());
179 }

References getQuestions().

+ Here is the call graph for this function:

◆ getQuestions()

ilTestRandomQuestionSetQuestionCollection::getQuestions ( )

◆ getRandomArrayKeys()

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

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

207 {
208 if ($numKeys < 1) {
209 return array();
210 }
211
212 if ($numKeys > 1) {
213 return array_rand($array, $numKeys);
214 }
215
216 return array( array_rand($array, $numKeys) );
217 }

Referenced by getRandomQuestionCollection().

+ Here is the caller graph for this function:

◆ getRandomQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::getRandomQuestionCollection (   $requiredAmount)

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

194 {
195 $randomKeys = $this->getRandomArrayKeys($this->questions, $requiredAmount);
196
197 $randomQuestionCollection = new self();
198
199 foreach ($randomKeys as $randomKey) {
200 $randomQuestionCollection->addQuestion($this->questions[$randomKey]);
201 }
202
203 return $randomQuestionCollection;
204 }

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 132 of file class.ilTestRandomQuestionSetQuestionCollection.php.

133 {
134 // hey: fixRandomTestBuildable - comment for refactoring
144 // hey.
145
146 $questionIds = array_flip($questionCollection->getInvolvedQuestionIds());
147
148 $relativeComplementCollection = new self();
149
150 foreach ($this->getQuestions() as $question) {
151 if (!isset($questionIds[$question->getQuestionId()])) {
152 $relativeComplementCollection->addQuestion($question);
153 }
154 }
155
156 return $relativeComplementCollection;
157 }

References getQuestions().

+ Here is the call graph for this function:

◆ getUniqueQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::getUniqueQuestionCollection ( )

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

115 {
116 $uniqueQuestions = array();
117
118 foreach ($this->getQuestions() as $question) {
119 /* @var ilTestRandomQuestionSetQuestion $question */
120
121 if (!isset($uniqueQuestions[$question->getQuestionId()])) {
122 $uniqueQuestions[$question->getQuestionId()] = $question;
123 }
124 }
125
126 $uniqueQuestionCollection = new self();
127 $uniqueQuestionCollection->setQuestions($uniqueQuestions);
128
129 return $uniqueQuestionCollection;
130 }

References getQuestions().

+ Here is the call graph for this function:

◆ isGreaterThan()

ilTestRandomQuestionSetQuestionCollection::isGreaterThan (   $amount)

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

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

◆ isSmallerThan()

ilTestRandomQuestionSetQuestionCollection::isSmallerThan (   $amount)

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

87 : bool
88 {
89 return count($this->questions) < $amount;
90 }

◆ key()

ilTestRandomQuestionSetQuestionCollection::key ( )

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

63 : string
64 {
65 return key($this->questions);
66 }

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 109 of file class.ilTestRandomQuestionSetQuestionCollection.php.

110 {
111 $this->questions = array_merge($this->questions, $questionCollection->getQuestions());
112 }

◆ next()

ilTestRandomQuestionSetQuestionCollection::next ( )
Returns
ilTestRandomQuestionSetQuestion|false

Definition at line 58 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 ( )
Returns
ilTestRandomQuestionSetQuestion|false

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

77 {
78 return reset($this->questions);
79 }

◆ setQuestions()

ilTestRandomQuestionSetQuestionCollection::setQuestions (   $questions)

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

33 {
34 $this->questions = $questions;
35 }

References $questions.

◆ shuffleQuestions()

ilTestRandomQuestionSetQuestionCollection::shuffleQuestions ( )

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

105 {
106 shuffle($this->questions);
107 }

Referenced by ilTestRandomQuestionSetBuilder\handleQuestionOrdering().

+ Here is the caller graph for this function:

◆ valid()

ilTestRandomQuestionSetQuestionCollection::valid ( )

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

68 : bool
69 {
70 return key($this->questions) !== null;
71 }

References key().

+ Here is the call graph for this function:

Field Documentation

◆ $questions

ilTestRandomQuestionSetQuestionCollection::$questions = array()
private

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