ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 29 of file class.ilTestRandomQuestionSetQuestionCollection.php.

30  {
31  $this->questions[] = $question;
32  }

◆ current()

ilTestRandomQuestionSetQuestionCollection::current ( )

◆ getIntersectionCollection()

ilTestRandomQuestionSetQuestionCollection::getIntersectionCollection ( self  $questionCollection)
Parameters
ilTestRandomQuestionSetQuestionCollection$questionCollection
Returns
ilTestRandomQuestionSetQuestionCollection

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

References getQuestions().

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

◆ getInvolvedQuestionIds()

ilTestRandomQuestionSetQuestionCollection::getInvolvedQuestionIds ( )

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

References array, and getQuestions().

172  {
173  $questionIds = array();
174 
175  foreach ($this->getQuestions() as $question) {
176  $questionIds[] = $question->getQuestionId();
177  }
178 
179  return $questionIds;
180  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ getMissingCount()

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

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

77  {
78  // hey: fixRandomTestBuildable - fix returning missing count instead of difference (neg values!)
79  $difference = $requiredAmount - count($this->questions);
80  $missingCount = $difference < 0 ? 0 : $difference;
81  return $missingCount;
82  // hey.
83  }

◆ getQuestionAmount()

ilTestRandomQuestionSetQuestionCollection::getQuestionAmount ( )
Returns
int

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

References getQuestions().

+ Here is the call graph for this function:

◆ getQuestions()

ilTestRandomQuestionSetQuestionCollection::getQuestions ( )

◆ getRandomArrayKeys()

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

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

References array.

Referenced by getRandomQuestionCollection().

196  {
197  if ($numKeys < 1) {
198  return array();
199  }
200 
201  if ($numKeys > 1) {
202  return array_rand($array, $numKeys);
203  }
204 
205  return array( array_rand($array, $numKeys) );
206  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getRandomQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::getRandomQuestionCollection (   $requiredAmount)

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

References getRandomArrayKeys().

Referenced by ilTestRandomQuestionSetBuilder\fetchQuestionsFromStageRandomly().

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

References getQuestions().

114  {
115  // hey: fixRandomTestBuildable - comment for refactoring
125  // hey.
126 
127  $questionIds = array_flip($questionCollection->getInvolvedQuestionIds());
128 
129  $relativeComplementCollection = new self();
130 
131  foreach ($this->getQuestions() as $question) {
132  if (!isset($questionIds[$question->getQuestionId()])) {
133  $relativeComplementCollection->addQuestion($question);
134  }
135  }
136 
137  return $relativeComplementCollection;
138  }
+ Here is the call graph for this function:

◆ getUniqueQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::getUniqueQuestionCollection ( )

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

References array, and getQuestions().

96  {
97  $uniqueQuestions = array();
98 
99  foreach ($this->getQuestions() as $question) {
100  /* @var ilTestRandomQuestionSetQuestion $question */
101 
102  if (!isset($uniqueQuestions[$question->getQuestionId()])) {
103  $uniqueQuestions[$question->getQuestionId()] = $question;
104  }
105  }
106 
107  $uniqueQuestionCollection = new self();
108  $uniqueQuestionCollection->setQuestions($uniqueQuestions);
109 
110  return $uniqueQuestionCollection;
111  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ isGreaterThan()

ilTestRandomQuestionSetQuestionCollection::isGreaterThan (   $amount)

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

63  {
64  return count($this->questions) > $amount;
65  }

◆ isSmallerThan()

ilTestRandomQuestionSetQuestionCollection::isSmallerThan (   $amount)

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

68  {
69  return count($this->questions) < $amount;
70  }

◆ key()

ilTestRandomQuestionSetQuestionCollection::key ( )

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

Referenced by valid().

+ Here is the caller graph for this function:

◆ mergeQuestionCollection()

ilTestRandomQuestionSetQuestionCollection::mergeQuestionCollection ( self  $questionCollection)

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

91  {
92  $this->questions = array_merge($this->questions, $questionCollection->getQuestions());
93  }

◆ next()

ilTestRandomQuestionSetQuestionCollection::next ( )

◆ rewind()

ilTestRandomQuestionSetQuestionCollection::rewind ( )

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

57  {
58  return reset($this->questions);
59  }

◆ setQuestions()

ilTestRandomQuestionSetQuestionCollection::setQuestions (   $questions)

◆ shuffleQuestions()

ilTestRandomQuestionSetQuestionCollection::shuffleQuestions ( )

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

Referenced by ilTestRandomQuestionSetBuilder\handleQuestionOrdering().

86  {
87  shuffle($this->questions);
88  }
+ Here is the caller graph for this function:

◆ valid()

ilTestRandomQuestionSetQuestionCollection::valid ( )

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

References key().

52  {
53  return key($this->questions) !== null;
54  }
+ 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: