40 include_once(
"./Services/JSON/classes/class.ilJsonUtil.php");
42 $tries = $answer->tries;
43 $passed = $answer->passed;
44 $choice = $answer->choice;
46 $ilLog->write(
"Points: ".$points);
48 $set =
$ilDB->query(
"SELECT * FROM page_qst_answer WHERE ".
49 " qst_id = ".
$ilDB->quote($a_id,
"integer").
" AND ".
50 " user_id = ".$ilDB->quote(
$ilUser->getId(),
"integer")
78 if (!
$ilDB->fetchAssoc($set))
80 $ilDB->replace(
"page_qst_answer",
82 "qst_id" => array(
"integer", $a_id),
83 "user_id" => array(
"integer",
$ilUser->getId())
86 "try" => array(
"integer", 1),
87 "passed" => array(
"integer", $passed),
88 "points" => array(
"float", $points)
94 $ilDB->manipulate(
"UPDATE page_qst_answer SET ".
96 " passed = ".
$ilDB->quote($passed,
"integer").
",".
97 " points = ".$ilDB->quote($points,
"float").
98 " WHERE qst_id = ".$ilDB->quote($a_id,
"integer").
99 " AND user_id = ".$ilDB->quote(
$ilUser->getId(),
"integer")
114 $set =
$ilDB->query(
"SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE ".
115 " qst_id = ".
$ilDB->quote($a_q_id,
"integer")
117 $rec =
$ilDB->fetchAssoc($set);
118 $all = $rec[
"usr_cnt"];
122 $third_or_more =
false;
126 $set =
$ilDB->query(
"SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE ".
127 " qst_id = ".
$ilDB->quote($a_q_id,
"integer").
" AND ".
128 " passed = ".$ilDB->quote(1,
"integer").
" AND ".
129 " try = ".$ilDB->quote(1,
"integer")
131 $rec =
$ilDB->fetchAssoc($set);
132 $first = $rec[
"usr_cnt"];
134 $set =
$ilDB->query(
"SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE ".
135 " qst_id = ".
$ilDB->quote($a_q_id,
"integer").
" AND ".
136 " passed = ".$ilDB->quote(1,
"integer").
" AND ".
137 " try = ".$ilDB->quote(2,
"integer")
139 $rec =
$ilDB->fetchAssoc($set);
140 $second = $rec[
"usr_cnt"];
142 $set =
$ilDB->query($q =
"SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE ".
143 " qst_id = ".
$ilDB->quote($a_q_id,
"integer").
" AND ".
144 " passed = ".$ilDB->quote(1,
"integer").
" AND ".
145 " try >= ".$ilDB->quote(3,
"integer")
147 $rec =
$ilDB->fetchAssoc($set);
148 $third_or_more = $rec[
"usr_cnt"];
151 return array(
"all" => $all,
"first" => $first,
"second" => $second,
"third_or_more" => $third_or_more);
170 case "assSingleChoice":
171 include_once(
"./Modules/TestQuestionPool/classes/class.assSingleChoice.php");
173 $q->loadFromDb($a_id);
175 foreach ($q->getAnswers() as $key => $answer)
177 if (isset($a_choice[0]) && $key == $a_choice[0])
179 $points += $answer->getPoints();
184 case "assMultipleChoice":
185 include_once(
"./Modules/TestQuestionPool/classes/class.assMultipleChoice.php");
187 $q->loadFromDb($a_id);
189 foreach ($q->getAnswers() as $key => $answer)
191 if (is_array($a_choice) && in_array($key, $a_choice))
193 $points += $answer->getPoints();
197 $points += $answer->getPointsUnchecked();
203 include_once(
"./Modules/TestQuestionPool/classes/class.assClozeTest.php");
205 $q->loadFromDb($a_id);
207 foreach ($q->getGaps() as $id => $gap)
209 $choice = $a_choice[$id];
210 switch ($gap->getType())
214 for ($order = 0; $order < $gap->getItemCount(); $order++)
216 $answer = $gap->getItem($order);
217 $gotpoints = $q->getTextgapPoints($answer->getAnswertext(),
218 $choice, $answer->getPoints());
219 if ($gotpoints > $gappoints) $gappoints = $gotpoints;
221 $points += $gappoints;
227 for ($order = 0; $order < $gap->getItemCount(); $order++)
229 $answer = $gap->getItem($order);
230 $gotpoints = $q->getNumericgapPoints($answer->getAnswertext(),
231 $choice, $answer->getPoints(),
232 $answer->getLowerBound(), $answer->getUpperBound());
233 if ($gotpoints > $gappoints) $gappoints = $gotpoints;
235 $points += $gappoints;
240 for ($order = 0; $order < $gap->getItemCount(); $order++)
242 $answer = $gap->getItem($order);
243 if ($choice == $answer->getOrder())
245 $answerpoints = $answer->getPoints();
246 $points += $answerpoints;
255 case "assMatchingQuestion":
256 include_once(
"./Modules/TestQuestionPool/classes/class.assMatchingQuestion.php");
258 $q->loadFromDb($a_id);
260 for ($i = 0; $i < $q->getMatchingPairCount(); $i++)
262 $pair = $q->getMatchingPair($i);
263 if (is_array($a_choice) && in_array($pair->definition->identifier.
"-".$pair->term->identifier, $a_choice))
265 $points += $pair->points;
270 case "assOrderingQuestion":
274 include_once(
"./Modules/TestQuestionPool/classes/class.assOrderingQuestion.php");
276 $q->loadFromDb($a_id);
280 foreach ( $q->getOrderElements() as $answer)
282 if ($a_choice[$cnt - 1] != $cnt)
290 $points = $q->getPoints();
294 case "assImagemapQuestion":
295 include_once(
"./Modules/TestQuestionPool/classes/class.assImagemapQuestion.php");
297 $q->loadFromDb($a_id);
300 foreach ($q->getAnswers() as $key => $answer)
302 if (is_array($a_choice) && in_array($key, $a_choice))
304 $points += $answer->getPoints();
316 return (
int) $points;
329 $qst = (is_array($a_q_id))
330 ?
$ilDB->in(
"qst_id", $a_q_id,
false,
"integer")
331 :
" qst_id = ".$ilDB->quote($a_q_id,
"integer");
333 $and = ($a_user_id > 0)
334 ?
" AND user_id = ".
$ilDB->quote($a_user_id,
"integer")
337 $set =
$ilDB->query(
"SELECT * FROM page_qst_answer WHERE ".
342 if (is_array($a_q_id) || $a_user_id == 0)
345 while ($rec =
$ilDB->fetchAssoc($set))
347 $key = ($a_user_id == 0)
348 ? $rec[
"qst_id"].
":".$rec[
"user_id"]
356 return $ilDB->fetchAssoc($set);
370 $ilDB->manipulate($q =
"UPDATE page_qst_answer SET ".
371 " try = ".
$ilDB->quote(0,
"integer").
",".
372 " passed = ".$ilDB->quote(0,
"integer").
",".
373 " points = ".$ilDB->quote(0,
"integer").
",".
374 " unlocked = ".$ilDB->quote(0,
"integer").
375 " WHERE qst_id = ".$ilDB->quote($a_q_id,
"integer").
376 " AND user_id = ".$ilDB->quote($a_user_id,
"integer")
386 static function unlock($a_q_id, $a_user_id)
390 $ilDB->manipulate($q =
"UPDATE page_qst_answer SET ".
391 " unlocked = ".
$ilDB->quote(1,
"integer").
392 " WHERE qst_id = ".$ilDB->quote($a_q_id,
"integer").
393 " AND user_id = ".$ilDB->quote($a_user_id,
"integer")
An exception for terminatinating execution or to throw for unit testing.
Class for image map questions.
Class for matching questions.
Class for multiple choice tests.
Class for ordering questions.
Class for single choice questions.
static decode($json_notated_string, $suppress_native=false)
static getQuestionStatistics($a_q_id)
Get statistics for question.
static resetTries($a_q_id, $a_user_id)
Reset tries.
static calculatePoints($a_type, $a_id, $a_choice)
Calculate points.
static getAnswerStatus($a_q_id, $a_user_id=0)
Get statistics for question.
static saveQuestionAnswer($a_type, $a_id, $a_answer)
Save question answer.
static unlock($a_q_id, $a_user_id)
Reset tries.
const CLOZE_TEXT
Cloze question constants.