36 $ilDB = $DIC->database();
43 include_once(
"./Services/JSON/classes/class.ilJsonUtil.php");
45 $tries = $answer->tries;
46 $passed = $answer->passed;
47 $choice = $answer->choice;
48 $points = self::calculatePoints(
$a_type, $a_id, $choice);
49 $ilLog->write(
"Points: " . $points);
52 "SELECT * FROM page_qst_answer WHERE " .
53 " qst_id = " .
$ilDB->quote($a_id,
"integer") .
" AND " .
54 " user_id = " .
$ilDB->quote(
$ilUser->getId(),
"integer")
82 if (!
$ilDB->fetchAssoc($set)) {
86 "qst_id" =>
array(
"integer", $a_id),
90 "try" =>
array(
"integer", 1),
91 "passed" =>
array(
"integer", $passed),
92 "points" =>
array(
"float", $points)
97 "UPDATE page_qst_answer SET " .
99 " passed = " .
$ilDB->quote($passed,
"integer") .
"," .
100 " points = " .
$ilDB->quote($points,
"float") .
101 " WHERE qst_id = " .
$ilDB->quote($a_id,
"integer") .
102 " AND user_id = " .
$ilDB->quote(
$ilUser->getId(),
"integer")
117 $ilDB = $DIC->database();
120 "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
121 " qst_id = " .
$ilDB->quote($a_q_id,
"integer")
123 $rec =
$ilDB->fetchAssoc($set);
124 $all = $rec[
"usr_cnt"];
128 $third_or_more =
false;
132 "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
133 " qst_id = " .
$ilDB->quote($a_q_id,
"integer") .
" AND " .
134 " passed = " .
$ilDB->quote(1,
"integer") .
" AND " .
135 " try = " .
$ilDB->quote(1,
"integer")
137 $rec =
$ilDB->fetchAssoc($set);
138 $first = $rec[
"usr_cnt"];
141 "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
142 " qst_id = " .
$ilDB->quote($a_q_id,
"integer") .
" AND " .
143 " passed = " .
$ilDB->quote(1,
"integer") .
" AND " .
144 " try = " .
$ilDB->quote(2,
"integer")
146 $rec =
$ilDB->fetchAssoc($set);
147 $second = $rec[
"usr_cnt"];
150 $q =
"SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
151 " qst_id = " .
$ilDB->quote($a_q_id,
"integer") .
" AND " .
152 " passed = " .
$ilDB->quote(1,
"integer") .
" AND " .
153 " try >= " .
$ilDB->quote(3,
"integer")
155 $rec =
$ilDB->fetchAssoc($set);
156 $third_or_more = $rec[
"usr_cnt"];
159 return array(
"all" => $all,
"first" => $first,
"second" => $second,
"third_or_more" => $third_or_more);
179 case "assSingleChoice":
180 include_once(
"./Modules/TestQuestionPool/classes/class.assSingleChoice.php");
182 $q->loadFromDb($a_id);
184 foreach ($q->getAnswers() as
$key => $answer) {
185 if (isset($a_choice[0]) && $key == $a_choice[0]) {
186 $points += $answer->getPoints();
191 case "assMultipleChoice":
192 include_once(
"./Modules/TestQuestionPool/classes/class.assMultipleChoice.php");
194 $q->loadFromDb($a_id);
196 foreach ($q->getAnswers() as $key => $answer) {
197 if (is_array($a_choice) && in_array($key, $a_choice)) {
198 $points += $answer->getPoints();
200 $points += $answer->getPointsUnchecked();
206 include_once(
"./Modules/TestQuestionPool/classes/class.assClozeTest.php");
208 $q->loadFromDb($a_id);
210 foreach ($q->getGaps() as
$id => $gap) {
211 $choice = $a_choice[
$id];
212 switch ($gap->getType()) {
215 for ($order = 0; $order < $gap->getItemCount(); $order++) {
216 $answer = $gap->getItem($order);
217 $gotpoints = $q->getTextgapPoints(
218 $answer->getAnswertext(),
222 if ($gotpoints > $gappoints) {
223 $gappoints = $gotpoints;
226 $points += $gappoints;
232 for ($order = 0; $order < $gap->getItemCount(); $order++) {
233 $answer = $gap->getItem($order);
234 $gotpoints = $q->getNumericgapPoints(
235 $answer->getAnswertext(),
237 $answer->getPoints(),
238 $answer->getLowerBound(),
239 $answer->getUpperBound()
241 if ($gotpoints > $gappoints) {
242 $gappoints = $gotpoints;
245 $points += $gappoints;
250 for ($order = 0; $order < $gap->getItemCount(); $order++) {
251 $answer = $gap->getItem($order);
252 if ($choice == $answer->getOrder()) {
253 $answerpoints = $answer->getPoints();
254 $points += $answerpoints;
263 case "assMatchingQuestion":
264 include_once(
"./Modules/TestQuestionPool/classes/class.assMatchingQuestion.php");
266 $q->loadFromDb($a_id);
268 for (
$i = 0;
$i < $q->getMatchingPairCount();
$i++) {
269 $pair = $q->getMatchingPair(
$i);
270 if (is_array($a_choice) && in_array($pair->definition->identifier .
"-" . $pair->term->identifier, $a_choice)) {
271 $points += $pair->points;
276 case "assOrderingQuestion":
280 include_once(
"./Modules/TestQuestionPool/classes/class.assOrderingQuestion.php");
282 $q->loadFromDb($a_id);
286 foreach ($q->getOrderElements() as $answer) {
287 if ($a_choice[$cnt - 1] != $cnt) {
293 $points = $q->getPoints();
297 case "assImagemapQuestion":
298 include_once(
"./Modules/TestQuestionPool/classes/class.assImagemapQuestion.php");
300 $q->loadFromDb($a_id);
303 foreach ($q->getAnswers() as $key => $answer) {
304 if (is_array($a_choice) && in_array($key, $a_choice)) {
305 $points += $answer->getPoints();
316 return (
int) $points;
329 $ilDB = $DIC->database();
331 $qst = (is_array($a_q_id))
332 ?
$ilDB->in(
"qst_id", $a_q_id,
false,
"integer")
333 :
" qst_id = " .
$ilDB->quote($a_q_id,
"integer");
335 $and = ($a_user_id > 0)
336 ?
" AND user_id = " .
$ilDB->quote($a_user_id,
"integer")
340 "SELECT * FROM page_qst_answer WHERE " .
345 if (is_array($a_q_id) || $a_user_id == 0) {
347 while ($rec =
$ilDB->fetchAssoc($set)) {
348 $key = ($a_user_id == 0)
349 ? $rec[
"qst_id"] .
":" . $rec[
"user_id"]
355 return $ilDB->fetchAssoc($set);
369 $ilDB = $DIC->database();
372 $q =
"UPDATE page_qst_answer SET " .
373 " try = " .
$ilDB->quote(0,
"integer") .
"," .
374 " passed = " .
$ilDB->quote(0,
"integer") .
"," .
375 " points = " .
$ilDB->quote(0,
"integer") .
"," .
376 " unlocked = " .
$ilDB->quote(0,
"integer") .
377 " WHERE qst_id = " .
$ilDB->quote($a_q_id,
"integer") .
378 " AND user_id = " .
$ilDB->quote($a_user_id,
"integer")
388 public static function unlock($a_q_id, $a_user_id)
392 $ilDB = $DIC->database();
395 $q =
"UPDATE page_qst_answer SET " .
396 " unlocked = " .
$ilDB->quote(1,
"integer") .
397 " WHERE qst_id = " .
$ilDB->quote($a_q_id,
"integer") .
398 " AND user_id = " .
$ilDB->quote($a_user_id,
"integer")
static resetTries($a_q_id, $a_user_id)
Reset tries.
static calculatePoints($a_type, $a_id, $a_choice)
Calculate points.
const CLOZE_TEXT
Cloze question constants.
if(!array_key_exists('StateId', $_REQUEST)) $id
Class for multiple choice tests.
Class for matching questions.
static getQuestionStatistics($a_q_id)
Get statistics for question.
static getAnswerStatus($a_q_id, $a_user_id=0)
Get statistics for question.
Class for single choice questions.
static decode($json_notated_string, $suppress_native=false)
Class for image map questions.
Create styles array
The data for the language used.
static unlock($a_q_id, $a_user_id)
Reset tries.
Class for ordering questions.
static saveQuestionAnswer($a_type, $a_id, $a_answer)
Save question answer.