ILIAS  trunk Revision v5.2.0beta1-34132-g2d4d73d4a0
ilAssQuestionHintList Class Reference
+ Inheritance diagram for ilAssQuestionHintList:
+ Collaboration diagram for ilAssQuestionHintList:

Public Member Functions

 current ()
 
 rewind ()
 
 next ()
 
 key ()
 
 valid ()
 
 __construct ()
 
 addHint (ilAssQuestionHint $questionHint)
 
 getHint ($hintId)
 
 hintExists ($hintId)
 
 reIndex ()
 re-indexes the list's hints sequentially by current order (starting with index "1") ATTENTION: it also persists this index to db by performing an update of hint object via id. More...
 
 getTableData ()
 returns an array with data of the hints in this list that is adopted to be used as table gui data More...
 

Static Public Member Functions

static duplicateListForQuestion ($originalQuestionId, $duplicateQuestionId)
 duplicates a hint list from given original question id to given duplicate question id and returns an array of duplicate hint ids mapped to the corresponding original hint ids More...
 
static getListByQuestionId ($questionId)
 instantiates a question hint list for the passed question id More...
 
static getListByHintIds ($hintIds)
 instantiates a question hint list for the passed hint ids More...
 
static getNextIndexByQuestionId ($questionId)
 determines the next index to be used for a new hint that is to be added to the list of existing hints regarding to the question with passed question id More...
 
static deleteHintsByQuestionIds (array $questionIds)
 Deletes all question hints relating to questions included in given question ids. More...
 

Private Attributes

array $questionHints = []
 

Detailed Description

Definition at line 28 of file class.ilAssQuestionHintList.php.

Constructor & Destructor Documentation

◆ __construct()

ilAssQuestionHintList::__construct ( )

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

59  {
60  }

Member Function Documentation

◆ addHint()

ilAssQuestionHintList::addHint ( ilAssQuestionHint  $questionHint)

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

Referenced by ilAssQuestionHintsGUI\pasteFromOrderingClipboardAfterCmd().

62  : void
63  {
64  $this->questionHints[] = $questionHint;
65  }
+ Here is the caller graph for this function:

◆ current()

ilAssQuestionHintList::current ( )

Definition at line 33 of file class.ilAssQuestionHintList.php.

34  {
35  return current($this->questionHints);
36  }

◆ deleteHintsByQuestionIds()

static ilAssQuestionHintList::deleteHintsByQuestionIds ( array  $questionIds)
static

Deletes all question hints relating to questions included in given question ids.

Parameters
list<int>$questionIds

Definition at line 286 of file class.ilAssQuestionHintList.php.

References $DIC, and $ilDB.

Referenced by assQuestion\delete().

286  : int
287  {
288  global $DIC;
289  $ilDB = $DIC->database();
290 
291  $__qht_question_fi__IN__questionIds = $ilDB->in('qht_question_fi', $questionIds, false, 'integer');
292 
293  $query = "
294  DELETE FROM qpl_hints
295  WHERE $__qht_question_fi__IN__questionIds
296  ";
297 
298  return $ilDB->manipulate($query);
299  }
$DIC
Definition: xapitoken.php:62
+ Here is the caller graph for this function:

◆ duplicateListForQuestion()

static ilAssQuestionHintList::duplicateListForQuestion (   $originalQuestionId,
  $duplicateQuestionId 
)
static

duplicates a hint list from given original question id to given duplicate question id and returns an array of duplicate hint ids mapped to the corresponding original hint ids

Parameters
int$originalQuestionId
int$duplicateQuestionId
Returns
array<int, int> $hintIds containing the map from original hint ids to duplicate hint ids

Definition at line 124 of file class.ilAssQuestionHintList.php.

Referenced by assQuestion\duplicateQuestionHints().

124  : array
125  {
126  $hintIds = [];
127 
128  $questionHintList = self::getListByQuestionId($originalQuestionId);
129 
130  foreach ($questionHintList as $questionHint) {
131  /* @var $questionHint ilAssQuestionHint */
132 
133  $originalHintId = $questionHint->getId();
134 
135  $questionHint->setId(0);
136  $questionHint->setQuestionId($duplicateQuestionId);
137 
138  $questionHint->save();
139 
140  $duplicateHintId = $questionHint->getId();
141 
142  $hintIds[$originalHintId] = $duplicateHintId;
143  }
144 
145  return $hintIds;
146  }
+ Here is the caller graph for this function:

◆ getHint()

ilAssQuestionHintList::getHint (   $hintId)
Parameters
int$hintId

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

71  {
72  foreach ($this as $questionHint) {
73  /* @var $questionHint ilAssQuestionHint */
74 
75  if ($questionHint->getId() == $hintId) {
76  return $questionHint;
77  }
78  }
79 
80  throw new ilTestQuestionPoolException("hint with id $hintId does not exist in this list");
81  }

◆ getListByHintIds()

static ilAssQuestionHintList::getListByHintIds (   $hintIds)
static

instantiates a question hint list for the passed hint ids

Parameters
list<int>$hintIds

Definition at line 217 of file class.ilAssQuestionHintList.php.

References $DIC, $ilDB, $res, and ilAssQuestionHint\assignDbRow().

Referenced by ilAssQuestionPreviewHintTracking\getRequestedHintsList(), and ilAssQuestionHintTracking\getRequestedHintsList().

218  {
219  global $DIC;
220  $ilDB = $DIC->database();
221 
222  $qht_hint_id__IN__hintIds = $ilDB->in('qht_hint_id', (array) $hintIds, false, 'integer');
223 
224  $query = "
225  SELECT qht_hint_id,
226  qht_question_fi,
227  qht_hint_index,
228  qht_hint_points,
229  qht_hint_text
230 
231  FROM qpl_hints
232 
233  WHERE $qht_hint_id__IN__hintIds
234 
235  ORDER BY qht_hint_index ASC
236  ";
237 
238  $res = $ilDB->query($query);
239 
240  $questionHintList = new self();
241 
242  while ($row = $ilDB->fetchAssoc($res)) {
243  $questionHint = new ilAssQuestionHint();
244 
245  ilAssQuestionHint::assignDbRow($questionHint, $row);
246 
247  $questionHintList->addHint($questionHint);
248  }
249 
250  return $questionHintList;
251  }
$res
Definition: ltiservices.php:67
$DIC
Definition: xapitoken.php:62
static assignDbRow(self $questionHint, $hintDbRow)
assigns the field elements of passed hint db row array to the corresponding hint object properties of...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getListByQuestionId()

static ilAssQuestionHintList::getListByQuestionId (   $questionId)
static

instantiates a question hint list for the passed question id

Parameters
int$questionId

Definition at line 175 of file class.ilAssQuestionHintList.php.

References $DIC, $ilDB, $res, and ilAssQuestionHint\assignDbRow().

Referenced by assQuestionExport\addSolutionHints(), ilAssQuestionHintsGUI\checkForExistingHintRelatingToCurrentQuestionAndRedirectOnFailure(), ilAssQuestionHintsGUI\confirmDeleteCmd(), assQuestion\getRTETextWithMediaObjects(), ilAssQuestionList\hasHints(), ilAssQuestionHintsGUI\pasteFromOrderingClipboardAfterCmd(), ilAssQuestionHintsGUI\pasteFromOrderingClipboardBeforeCmd(), ilAssQuestionHintsGUI\performDeleteCmd(), ilAssQuestionHintsGUI\saveListOrderCmd(), and ilAssQuestionHintsGUI\showListCmd().

176  {
177  global $DIC;
178  $ilDB = $DIC->database();
179 
180  $query = "
181  SELECT qht_hint_id,
182  qht_question_fi,
183  qht_hint_index,
184  qht_hint_points,
185  qht_hint_text
186 
187  FROM qpl_hints
188 
189  WHERE qht_question_fi = %s
190 
191  ORDER BY qht_hint_index ASC
192  ";
193 
194  $res = $ilDB->queryF(
195  $query,
196  ['integer'],
197  [(int) $questionId]
198  );
199 
200  $questionHintList = new self();
201 
202  while ($row = $ilDB->fetchAssoc($res)) {
203  $questionHint = new ilAssQuestionHint();
204 
205  ilAssQuestionHint::assignDbRow($questionHint, $row);
206 
207  $questionHintList->addHint($questionHint);
208  }
209 
210  return $questionHintList;
211  }
$res
Definition: ltiservices.php:67
$DIC
Definition: xapitoken.php:62
static assignDbRow(self $questionHint, $hintDbRow)
assigns the field elements of passed hint db row array to the corresponding hint object properties of...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNextIndexByQuestionId()

static ilAssQuestionHintList::getNextIndexByQuestionId (   $questionId)
static

determines the next index to be used for a new hint that is to be added to the list of existing hints regarding to the question with passed question id

Parameters
int$questionId

Definition at line 259 of file class.ilAssQuestionHintList.php.

References $DIC, $ilDB, $res, and ILIAS\Repository\int().

Referenced by ilAssQuestionHintGUI\saveFormCmd().

259  : int
260  {
261  global $DIC;
262  $ilDB = $DIC->database();
263 
264  $query = "
265  SELECT 1 + COALESCE( MAX(qht_hint_index), 0 ) next_index
266 
267  FROM qpl_hints
268 
269  WHERE qht_question_fi = %s
270  ";
271 
272  $res = $ilDB->queryF(
273  $query,
274  ['integer'],
275  [(int) $questionId]
276  );
277  $row = $ilDB->fetchAssoc($res);
278 
279  return is_array($row) ? (int) $row['next_index'] : 1;
280  }
$res
Definition: ltiservices.php:67
$DIC
Definition: xapitoken.php:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTableData()

ilAssQuestionHintList::getTableData ( )

returns an array with data of the hints in this list that is adopted to be used as table gui data

Returns
list<array{hint_id: null|int, hint_index: null|int, hint_points: null|float, hint_text: null|int}>

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

Referenced by ilAssQuestionHintsTableGUI\__construct().

153  : array
154  {
155  $tableData = [];
156 
157  foreach ($this as $questionHint) {
158  /* @var $questionHint ilAssQuestionHint */
159 
160  $tableData[] = [
161  'hint_id' => $questionHint->getId(),
162  'hint_index' => $questionHint->getIndex(),
163  'hint_points' => $questionHint->getPoints(),
164  'hint_text' => $questionHint->getText()
165  ];
166  }
167 
168  return $tableData;
169  }
+ Here is the caller graph for this function:

◆ hintExists()

ilAssQuestionHintList::hintExists (   $hintId)
Parameters
int$hintId

Definition at line 86 of file class.ilAssQuestionHintList.php.

86  : bool
87  {
88  foreach ($this as $questionHint) {
89  /* @var ilAssQuestionHint $questionHint */
90  if ($questionHint->getId() == $hintId) {
91  return true;
92  }
93  }
94 
95  return false;
96  }

◆ key()

ilAssQuestionHintList::key ( )

Definition at line 48 of file class.ilAssQuestionHintList.php.

Referenced by valid().

48  : int
49  {
50  return key($this->questionHints);
51  }
+ Here is the caller graph for this function:

◆ next()

ilAssQuestionHintList::next ( )

Definition at line 43 of file class.ilAssQuestionHintList.php.

43  : void
44  {
45  next($this->questionHints);
46  }

◆ reIndex()

ilAssQuestionHintList::reIndex ( )

re-indexes the list's hints sequentially by current order (starting with index "1") ATTENTION: it also persists this index to db by performing an update of hint object via id.

do not re-index any hint list objects unless this lists contain ALL hint objects for a SINGLE question and no more hints apart of that.

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

104  : void
105  {
106  $counter = 0;
107 
108  foreach ($this as $questionHint) {
109  /* @var $questionHint ilAssQuestionHint */
110 
111  $questionHint->setIndex(++$counter);
112  $questionHint->save();
113  }
114  }

◆ rewind()

ilAssQuestionHintList::rewind ( )

Definition at line 38 of file class.ilAssQuestionHintList.php.

38  : void
39  {
40  reset($this->questionHints);
41  }

◆ valid()

ilAssQuestionHintList::valid ( )

Definition at line 53 of file class.ilAssQuestionHintList.php.

References key().

53  : bool
54  {
55  return key($this->questionHints) !== null;
56  }
+ Here is the call graph for this function:

Field Documentation

◆ $questionHints

array ilAssQuestionHintList::$questionHints = []
private

Definition at line 31 of file class.ilAssQuestionHintList.php.


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