Skip to content

Commit

Permalink
Exercise: Fix result for multi_answer_false
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Nov 5, 2021
1 parent c2e44d7 commit 26884d9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions main/exercise/exercise.class.php
Expand Up @@ -3954,8 +3954,8 @@ public function manage_answer(
if ($studentChoice == $answerCorrect) {
$questionScore += $true_score;
} else {
if ($quiz_question_options[$studentChoice]['name'] === "Don't know" ||
$quiz_question_options[$studentChoice]['name'] === "DoubtScore"
if ($quiz_question_options[$studentChoice - 1]['name'] === "Don't know" ||
$quiz_question_options[$studentChoice - 1]['name'] === "DoubtScore"
) {
$questionScore += $doubt_score;
} else {
Expand Down
9 changes: 5 additions & 4 deletions main/exercise/multiple_answer_true_false.class.php
Expand Up @@ -112,14 +112,15 @@ public function createAnswersForm($form)
$answer_number->freeze();

if (is_object($answer)) {
$defaults['answer['.$i.']'] = $answer->answer[$i];
$defaults['comment['.$i.']'] = $answer->comment[$i];
$correct = $answer->correct[$i];
$defaults['answer['.$i.']'] = $answer->answer[$i] ?? '';
$defaults['comment['.$i.']'] = $answer->comment[$i] ?? '';
$correct = $answer->correct[$i] ?? 0;
$defaults['correct['.$i.']'] = $correct;

$j = 1;
if (!empty($optionData)) {
foreach ($optionData as $id => $data) {
$id++;
$rdoCorrect = $form->addElement('radio', 'correct['.$i.']', null, null, $id);

if (isset($_POST['correct']) && isset($_POST['correct'][$i]) && $id == $_POST['correct'][$i]) {
Expand Down Expand Up @@ -298,7 +299,7 @@ public function processAnswersCreation($form, $exercise)
if (empty($options)) {
//If this is the first time that the question is created when
// change the default values from the form 1 and 2 by the correct "option id" registered
$goodAnswer = isset($sortedByPosition[$goodAnswer]) ? $sortedByPosition[$goodAnswer]['iid'] : '';
// $goodAnswer = isset($sortedByPosition[$goodAnswer]) ? $sortedByPosition[$goodAnswer]['iid'] : '';
}
$questionWeighting += $extra_values[0]; //By default 0 has the correct answers
$objAnswer->createAnswer($answer, $goodAnswer, $comment, '', $i);
Expand Down
2 changes: 1 addition & 1 deletion main/inc/lib/exercise.lib.php
Expand Up @@ -754,7 +754,7 @@ class="exercise-unique-answer-image col-xs-6 col-md-3"
Display::input(
'radio',
'choice['.$questionId.']['.$numAnswer.']',
$id,
$id + 1,
$attributes
),
['style' => '']
Expand Down
10 changes: 5 additions & 5 deletions main/inc/lib/exercise_show_functions.lib.php
Expand Up @@ -564,8 +564,8 @@ public static function display_multiple_answer_true_false(
$course_id = api_get_course_int_id();
$new_options = Question::readQuestionOption($questionId, $course_id);
// Your choice
if (isset($new_options[$studentChoice])) {
$content .= get_lang($new_options[$studentChoice]['name']);
if (isset($new_options[$studentChoice - 1])) {
$content .= get_lang($new_options[$studentChoice - 1]['name']);
} else {
$content .= '-';
}
Expand All @@ -576,8 +576,8 @@ public static function display_multiple_answer_true_false(
if ($exercise->showExpectedChoiceColumn()) {
if (!$hide_expected_answer) {
$content .= '<td width="5%">';
if (isset($new_options[$answerCorrect])) {
$content .= get_lang($new_options[$answerCorrect]['name']);
if (isset($new_options[$answerCorrect - 1])) {
$content .= get_lang($new_options[$answerCorrect - 1]['name']);
} else {
$content .= '-';
}
Expand Down Expand Up @@ -605,7 +605,7 @@ public static function display_multiple_answer_true_false(
if (EXERCISE_FEEDBACK_TYPE_EXAM != $feedbackType) {
$content .= '<td width="20%">';
$color = 'black';
if (isset($new_options[$studentChoice]) || in_array(
if (isset($new_options[$studentChoice - 1]) || in_array(
$exercise->results_disabled,
[
RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
Expand Down

0 comments on commit 26884d9

Please sign in to comment.