38         $ilUser = $DIC->user();
    39         $ilLog = $DIC[
"ilLog"];
    40         $ilDB = $DIC->database();
    41         $ilLog->write($a_type);
    43         $ilLog->write($a_answer);
    44         $answer = json_decode($a_answer, 
false, 512, JSON_THROW_ON_ERROR);
    45         $passed = $answer->passed;
    46         $choice = $answer->choice ?? [];
    47         $points = self::calculatePoints($a_type, $a_id, $choice);
    48         $ilLog->write(
"Points: " . $points);
    51             "SELECT * FROM page_qst_answer WHERE " .
    52             " qst_id = " . 
$ilDB->quote($a_id, 
"integer") . 
" AND " .
    53             " user_id = " . 
$ilDB->quote($ilUser->getId(), 
"integer")
    57         if (!
$ilDB->fetchAssoc($set)) {
    61                     "qst_id" => array(
"integer", $a_id),
    62                     "user_id" => array(
"integer", $ilUser->getId())
    65                     "try" => array(
"integer", 1),
    66                     "passed" => array(
"integer", $passed),
    67                     "points" => array(
"float", $points)
    72                 "UPDATE page_qst_answer SET " .
    74                 " passed = " . 
$ilDB->quote($passed, 
"integer") . 
"," .
    75                 " points = " . 
$ilDB->quote($points, 
"float") .
    76                 " WHERE qst_id = " . 
$ilDB->quote($a_id, 
"integer") .
    77                 " AND user_id = " . 
$ilDB->quote($ilUser->getId(), 
"integer")
    87         $ilDB = $DIC->database();
    90             "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
    91             " qst_id = " . 
$ilDB->quote($a_q_id, 
"integer")
    93         $rec = 
$ilDB->fetchAssoc($set);
    94         $all = $rec[
"usr_cnt"];
    98         $third_or_more = 
false;
   102                 "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
   103                 " qst_id = " . 
$ilDB->quote($a_q_id, 
"integer") . 
" AND " .
   104                 " passed = " . 
$ilDB->quote(1, 
"integer") . 
" AND " .
   105                 " try = " . 
$ilDB->quote(1, 
"integer")
   107             $rec = 
$ilDB->fetchAssoc($set);
   108             $first = $rec[
"usr_cnt"];
   111                 "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
   112                 " qst_id = " . 
$ilDB->quote($a_q_id, 
"integer") . 
" AND " .
   113                 " passed = " . 
$ilDB->quote(1, 
"integer") . 
" AND " .
   114                 " try = " . 
$ilDB->quote(2, 
"integer")
   116             $rec = 
$ilDB->fetchAssoc($set);
   117             $second = $rec[
"usr_cnt"];
   120                 $q = 
"SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
   121                 " qst_id = " . 
$ilDB->quote($a_q_id, 
"integer") . 
" AND " .
   122                 " passed = " . 
$ilDB->quote(1, 
"integer") . 
" AND " .
   123                 " try >= " . 
$ilDB->quote(3, 
"integer")
   125             $rec = 
$ilDB->fetchAssoc($set);
   126             $third_or_more = $rec[
"usr_cnt"];
   129         return array(
"all" => $all, 
"first" => $first, 
"second" => $second, 
"third_or_more" => $third_or_more);
   147             case "assSingleChoice":
   149                 $q->loadFromDb($a_id);
   151                 foreach (
$q->getAnswers() as 
$key => $answer) {
   152                     if (isset($a_choice[0]) && $key == $a_choice[0]) {
   153                         $points += $answer->getPoints();
   158             case "assMultipleChoice":
   160                 $q->loadFromDb($a_id);
   162                 foreach (
$q->getAnswers() as $key => $answer) {
   163                     if (is_array($a_choice) && in_array($key, $a_choice)) {
   164                         $points += $answer->getPoints();
   166                         $points += $answer->getPointsUnchecked();
   173                 $q->loadFromDb($a_id);
   175                 foreach (
$q->getGaps() as 
$id => $gap) {
   176                     $choice = $a_choice[
$id];
   177                     switch ($gap->getType()) {
   180                             for ($order = 0; $order < $gap->getItemCount(); $order++) {
   181                                 $answer = $gap->getItem($order);
   182                                 $gotpoints = 
$q->getTextgapPoints(
   183                                     $answer->getAnswertext(),
   187                                 if ($gotpoints > $gappoints) {
   188                                     $gappoints = $gotpoints;
   191                             $points += $gappoints;
   197                             for ($order = 0; $order < $gap->getItemCount(); $order++) {
   198                                 $answer = $gap->getItem($order);
   199                                 $gotpoints = 
$q->getNumericgapPoints(
   200                                     $answer->getAnswertext(),
   202                                     $answer->getPoints(),
   203                                     $answer->getLowerBound(),
   204                                     $answer->getUpperBound()
   206                                 if ($gotpoints > $gappoints) {
   207                                     $gappoints = $gotpoints;
   210                             $points += $gappoints;
   215                             for ($order = 0; $order < $gap->getItemCount(); $order++) {
   216                                 $answer = $gap->getItem($order);
   217                                 if ($choice == $answer->getOrder()) {
   218                                     $answerpoints = $answer->getPoints();
   219                                     $points += $answerpoints;
   228             case "assMatchingQuestion":
   230                 $q->loadFromDb($a_id);
   232                 for ($i = 0; $i < 
$q->getMatchingPairCount(); $i++) {
   233                     $pair = 
$q->getMatchingPair($i);
   234                     if (is_array($a_choice) && in_array($pair->getDefinition()->getIdentifier() . 
"-" . $pair->getTerm()->getIdentifier(), $a_choice)) {
   235                         $points += $pair->points;
   240             case "assOrderingQuestion":
   245                 $q->loadFromDb($a_id);
   249                 foreach (
$q->getOrderElements() as $answer) {
   250                     if ($a_choice[$cnt - 1] != $cnt) {
   256                     $points = 
$q->getPoints();
   260             case "assImagemapQuestion":
   262                 $q->loadFromDb($a_id);
   265                 foreach (
$q->getAnswers() as $key => $answer) {
   266                     if (is_array($a_choice) && in_array($key, $a_choice)) {
   267                         $points += $answer->getPoints();
   277         return (
int) $points;
   289         $ilDB = $DIC->database();
   291         $qst = (is_array($a_q_id))
   292             ? 
$ilDB->in(
"qst_id", $a_q_id, 
false, 
"integer")
   293             : 
" qst_id = " . 
$ilDB->quote($a_q_id, 
"integer");
   295         $and = ($a_user_id > 0)
   296             ? 
" AND user_id = " . 
$ilDB->quote($a_user_id, 
"integer")
   300             "SELECT * FROM page_qst_answer WHERE " .
   305         if (is_array($a_q_id) || $a_user_id == 0) {
   307             while ($rec = 
$ilDB->fetchAssoc($set)) {
   308                 $key = ($a_user_id == 0)
   309                     ? $rec[
"qst_id"] . 
":" . $rec[
"user_id"]
   316         if ($rec = 
$ilDB->fetchAssoc($set)) {
   334         $ilDB = $DIC->database();
   337             $q = 
"UPDATE page_qst_answer SET " .
   338                 " try = " . 
$ilDB->quote(0, 
"integer") . 
"," .
   339                 " passed = " . 
$ilDB->quote(0, 
"integer") . 
"," .
   340                 " points = " . 
$ilDB->quote(0, 
"integer") . 
"," .
   341                 " unlocked = " . 
$ilDB->quote(0, 
"integer") .
   342                 " WHERE qst_id = " . 
$ilDB->quote($a_q_id, 
"integer") .
   343                 " AND user_id = " . 
$ilDB->quote($a_user_id, 
"integer")
   356         $ilDB = $DIC->database();
   359             $q = 
"UPDATE page_qst_answer SET " .
   360                 " unlocked = " . 
$ilDB->quote(1, 
"integer") .
   361                 " WHERE qst_id = " . 
$ilDB->quote($a_q_id, 
"integer") .
   362                 " AND user_id = " . 
$ilDB->quote($a_user_id, 
"integer")
 static resetTries(int $a_q_id, int $a_user_id)
Reset tries for user and question. 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
const CLOZE_TEXT
Cloze question constants. 
 
static getAnswerStatus( $a_q_id, int $a_user_id=0)
 
static saveQuestionAnswer(string $a_type, int $a_id, string $a_answer)
 
Class for multiple choice tests. 
 
Class for matching questions. 
 
Class for single choice questions. 
 
static getQuestionStatistics(int $a_q_id)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
static unlock(int $a_q_id, int $a_user_id)
Unlock question for user. 
 
static calculatePoints(string $a_type, int $a_id, array $a_choice)
Calculate points. 
 
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...