Skip to content

Commit

Permalink
Exercises: Fix wrong score when using shuffle answers + global questions
Browse files Browse the repository at this point in the history
See BT#18017
  • Loading branch information
jmontoyaa committed Nov 24, 2020
1 parent 3141828 commit cdf65d2
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions main/exercise/exercise.class.php
Expand Up @@ -3620,6 +3620,7 @@ public function manage_answer(
error_log('$learnpath_id: '.$learnpath_id);
error_log('$learnpath_item_id: '.$learnpath_item_id);
error_log('$choice: '.print_r($choice, 1));
error_log('-----------------------------');
}

$final_overlap = 0;
Expand Down Expand Up @@ -3717,7 +3718,7 @@ public function manage_answer(
}

$user_answer = '';
// Get answer list for matching
// Get answer list for matching.
$sql = "SELECT id_auto, id, answer
FROM $table_ans
WHERE c_id = $course_id AND question_id = $questionId";
Expand All @@ -3728,12 +3729,24 @@ public function manage_answer(
$answerMatching[$real_answer['id_auto']] = $real_answer['answer'];
}

$real_answers = [];
$quiz_question_options = Question::readQuestionOption(
$questionId,
$course_id
);
// Get first answer needed for global question, no matter the answer shuffle option;
$firstAnswer = [];
if ($answerType == MULTIPLE_ANSWER_COMBINATION ||
$answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE
) {
$sql = "SELECT *
FROM $table_ans
WHERE c_id = $course_id AND question_id = $questionId
ORDER BY position
LIMIT 1";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$firstAnswer = Database::fetch_array($result);
}
}

$real_answers = [];
$quiz_question_options = Question::readQuestionOption($questionId, $course_id);
$organs_at_risk_hit = 0;
$questionScore = 0;
$orderedHotSpots = [];
Expand Down Expand Up @@ -3769,7 +3782,7 @@ public function manage_answer(
error_log("answerWeighting: $answerWeighting");
}

// Delineation
// Delineation.
$delineation_cord = $objAnswerTmp->selectHotspotCoordinates(1);
$answer_delineation_destination = $objAnswerTmp->selectDestination(1);

Expand Down Expand Up @@ -5626,13 +5639,16 @@ public function manage_answer(
}
}

//we add the total score after dealing with the answers
// We add the total score after dealing with the answers.
if ($answerType == MULTIPLE_ANSWER_COMBINATION ||
$answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE
) {
if ($final_answer) {
//getting only the first score where we save the weight of all the question
$answerWeighting = $objAnswerTmp->selectWeighting(1);
if (empty($answerWeighting) && !empty($firstAnswer) && isset($firstAnswer['ponderation'])) {
$answerWeighting = $firstAnswer['ponderation'];
}
$questionScore += $answerWeighting;
}
}
Expand Down

0 comments on commit cdf65d2

Please sign in to comment.