19 declare(strict_types=1);
44 $this->questions[] = $question;
49 $current =
current($this->questions);
50 return $current !==
false ? $current : null;
53 public function next(): void
55 next($this->questions);
58 public function key(): ?string
60 return (
string)
key($this->questions);
65 return key($this->questions) !== null;
70 reset($this->questions);
76 return count($this->questions) > $amount;
81 return count($this->questions) < $amount;
90 $difference = $requiredAmount - count($this->questions);
91 $missingCount = $difference < 0 ? 0 : $difference;
98 shuffle($this->questions);
103 $this->questions = array_merge($this->questions, $questionCollection->getQuestions());
108 $uniqueQuestions = [];
113 if (!isset($uniqueQuestions[$question->getQuestionId()])) {
114 $uniqueQuestions[$question->getQuestionId()] = $question;
118 $uniqueQuestionCollection =
new self();
119 $uniqueQuestionCollection->
setQuestions($uniqueQuestions);
121 return $uniqueQuestionCollection;
138 $questionIds = array_flip($questionCollection->getInvolvedQuestionIds());
140 $relativeComplementCollection =
new self();
143 if (!isset($questionIds[$question->getQuestionId()])) {
144 $relativeComplementCollection->
addQuestion($question);
148 return $relativeComplementCollection;
153 $questionIds = array_flip($questionCollection->getInvolvedQuestionIds());
155 $intersectionCollection =
new self();
158 if (!isset($questionIds[$question->getQuestionId()])) {
165 return $intersectionCollection;
179 $questionIds[] = $question->getQuestionId();
189 $randomQuestionCollection =
new self();
191 foreach ($randomKeys as $randomKey) {
192 $randomQuestionCollection->addQuestion($this->questions[$randomKey]);
195 return $randomQuestionCollection;
205 return array_rand($array, $numKeys);
208 return [ array_rand($array, $numKeys) ];
getIntersectionCollection(self $questionCollection)
mergeQuestionCollection(self $questionCollection)
setQuestions(array $questions)
getMissingCount($requiredAmount)
getRelativeComplementCollection(self $questionCollection)
addQuestion(ilTestRandomQuestionSetQuestion $question)
getUniqueQuestionCollection()
getRandomQuestionCollection(int $requiredAmount)
getRandomArrayKeys(array $array, int $numKeys)