ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 (int $requiredAmount)
 

Private Member Functions

 getRandomArrayKeys (array $array, int $numKeys)
 

Private Attributes

 $questions = []
 

Detailed Description

Member Function Documentation

◆ addQuestion()

ilTestRandomQuestionSetQuestionCollection::addQuestion ( ilTestRandomQuestionSetQuestion  $question)

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

Referenced by getIntersectionCollection(), and getRelativeComplementCollection().

43  {
44  $this->questions[] = $question;
45  }
+ Here is the caller graph for this function:

◆ current()

ilTestRandomQuestionSetQuestionCollection::current ( )

◆ getIntersectionCollection()

ilTestRandomQuestionSetQuestionCollection::getIntersectionCollection ( self  $questionCollection)

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

References addQuestion(), and getQuestions().

152  {
153  $questionIds = array_flip($questionCollection->getInvolvedQuestionIds());
154 
155  $intersectionCollection = new self();
156 
157  foreach ($this->getQuestions() as $question) {
158  if (!isset($questionIds[$question->getQuestionId()])) {
159  continue;
160  }
161 
162  $intersectionCollection->addQuestion($question);
163  }
164 
165  return $intersectionCollection;
166  }
+ Here is the call graph for this function:

◆ getInvolvedQuestionIds()

ilTestRandomQuestionSetQuestionCollection::getInvolvedQuestionIds ( )

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

References getQuestions().

174  : array
175  {
176  $questionIds = [];
177 
178  foreach ($this->getQuestions() as $question) {
179  $questionIds[] = $question->getQuestionId();
180  }
181 
182  return $questionIds;
183  }
+ Here is the call graph for this function:

◆ getMissingCount()

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

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

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

◆ getQuestionAmount()

ilTestRandomQuestionSetQuestionCollection::getQuestionAmount ( )

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

References getQuestions().

168  : int
169  {
170  return count($this->getQuestions());
171  }
+ Here is the call graph for this function:

◆ getQuestions()

◆ getRandomArrayKeys()

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

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

Referenced by getRandomQuestionCollection().

199  {
200  if ($numKeys < 1) {
201  return [];
202  }
203 
204  if ($numKeys > 1) {
205  return array_rand($array, $numKeys);
206  }
207 
208  return [ array_rand($array, $numKeys) ];
209  }
+ Here is the caller graph for this function:

◆ getRandomQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::getRandomQuestionCollection ( int  $requiredAmount)

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

References getRandomArrayKeys().

Referenced by ilTestRandomQuestionSetBuilder\fetchQuestionsFromStageRandomly().

186  {
187  $randomKeys = $this->getRandomArrayKeys($this->questions, $requiredAmount);
188 
189  $randomQuestionCollection = new self();
190 
191  foreach ($randomKeys as $randomKey) {
192  $randomQuestionCollection->addQuestion($this->questions[$randomKey]);
193  }
194 
195  return $randomQuestionCollection;
196  }
+ 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 124 of file class.ilTestRandomQuestionSetQuestionCollection.php.

References addQuestion(), and getQuestions().

125  {
126  // hey: fixRandomTestBuildable - comment for refactoring
136  // hey.
137 
138  $questionIds = array_flip($questionCollection->getInvolvedQuestionIds());
139 
140  $relativeComplementCollection = new self();
141 
142  foreach ($this->getQuestions() as $question) {
143  if (!isset($questionIds[$question->getQuestionId()])) {
144  $relativeComplementCollection->addQuestion($question);
145  }
146  }
147 
148  return $relativeComplementCollection;
149  }
+ Here is the call graph for this function:

◆ getUniqueQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::getUniqueQuestionCollection ( )

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

References getQuestions(), and setQuestions().

107  {
108  $uniqueQuestions = [];
109 
110  foreach ($this->getQuestions() as $question) {
111  /* @var ilTestRandomQuestionSetQuestion $question */
112 
113  if (!isset($uniqueQuestions[$question->getQuestionId()])) {
114  $uniqueQuestions[$question->getQuestionId()] = $question;
115  }
116  }
117 
118  $uniqueQuestionCollection = new self();
119  $uniqueQuestionCollection->setQuestions($uniqueQuestions);
120 
121  return $uniqueQuestionCollection;
122  }
+ Here is the call graph for this function:

◆ isGreaterThan()

ilTestRandomQuestionSetQuestionCollection::isGreaterThan (   $amount)

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

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

◆ isSmallerThan()

ilTestRandomQuestionSetQuestionCollection::isSmallerThan (   $amount)

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

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

◆ key()

ilTestRandomQuestionSetQuestionCollection::key ( )

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

Referenced by valid().

58  : ?string
59  {
60  return (string) key($this->questions);
61  }
+ Here is the caller graph for this function:

◆ mergeQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::mergeQuestionCollection ( self  $questionCollection)

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

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

◆ next()

ilTestRandomQuestionSetQuestionCollection::next ( )

◆ rewind()

ilTestRandomQuestionSetQuestionCollection::rewind ( )

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

68  : void
69  {
70  reset($this->questions);
71  }

◆ setQuestions()

ilTestRandomQuestionSetQuestionCollection::setQuestions ( array  $questions)

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

References $questions.

Referenced by getUniqueQuestionCollection().

+ Here is the caller graph for this function:

◆ shuffleQuestions()

ilTestRandomQuestionSetQuestionCollection::shuffleQuestions ( )

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

Referenced by ilTestRandomQuestionSetBuilder\handleQuestionOrdering().

97  {
98  shuffle($this->questions);
99  }
+ Here is the caller graph for this function:

◆ valid()

ilTestRandomQuestionSetQuestionCollection::valid ( )

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

References key().

63  : bool
64  {
65  return key($this->questions) !== null;
66  }
+ 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: