From ed2fac0f6343bf10f8ca5f75be57ca95e4ffc2a3 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 24 Apr 2015 15:58:23 -0500 Subject: [PATCH] Fix resolve the question and show results - refs #7612 --- main/exercice/Draggable.php | 31 ++++---------------- main/exercice/exercise.class.php | 13 ++++---- main/inc/lib/exercise.lib.php | 3 +- main/template/default/exercise/submit.js.tpl | 4 +-- 4 files changed, 15 insertions(+), 36 deletions(-) diff --git a/main/exercice/Draggable.php b/main/exercice/Draggable.php index 4617407339..dc52c7ba35 100644 --- a/main/exercice/Draggable.php +++ b/main/exercice/Draggable.php @@ -35,22 +35,6 @@ class Draggable extends Question $matches = array(); $answer = null; - $counter = 1; - - if (isset($this->id)) { - $answer = new Answer($this->id); - $answer->read(); - - if (count($answer->nbrAnswers) > 0) { - for ($i = 1; $i <= $answer->nbrAnswers; $i++) { - $correct = $answer->isCorrect($i); - if (empty($correct)) { - $matches[$answer->selectAutoId($i)] = chr(64 + $counter); - $counter++; - } - } - } - } if ($form->isSubmitted()) { $nb_matches = $form->getSubmitValue('nb_matches'); @@ -72,6 +56,9 @@ class Draggable extends Question $nb_options++; } } else if (!empty($this->id)) { + $answer = new Answer($this->id); + $answer->read(); + if (count($answer->nbrAnswers) > 0) { $nb_matches = $nb_options = 0; @@ -95,16 +82,8 @@ class Draggable extends Question $defaults['option[2]'] = get_lang('DefaultMatchingOptB'); } - if (empty($matches)) { - for ($i = 1; $i <= $nb_options; ++$i) { - // fill the array with A, B, C..... - $matches[$i] = chr(64 + $i); - } - } else { - for ($i = $counter; $i <= $nb_options; ++$i) { - // fill the array with A, B, C..... - $matches[$i] = chr(64 + $i); - } + for ($i = 1; $i <= $nb_matches; ++$i) { + $matches[$i] = $i; } $form->addElement('hidden', 'nb_matches', $nb_matches); diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 36dd4356e3..7984d8321f 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -2812,12 +2812,12 @@ class Exercise if ($s_user_answer == $i_answer_correct_answer) { $questionScore += $i_answerWeighting; $totalScore += $i_answerWeighting; + if ($answerType == DRAGGABLE) { + $user_answer = Display::label(get_lang('Correct'), 'success'); + } else { if (isset($real_list[$i_answer_id])) { - if ($answerType == DRAGGABLE) { - $user_answer = Display::label(get_lang('Correct'), 'success'); - } else { $user_answer = ''.$real_list[$i_answer_id].''; - } + } } } else { if ($answerType == DRAGGABLE) { @@ -2834,9 +2834,11 @@ class Exercise echo ''; echo ''.$s_answer_label.''; echo ''.$user_answer; + if ($answerType == MATCHING) { if (isset($real_list[$i_answer_correct_answer])) { echo ' '.$real_list[$i_answer_correct_answer].' '; } + } echo ''; echo ''; } @@ -2956,9 +2958,6 @@ class Exercise ) || $answerCorrect ) { - - } - if ($answerType != MATCHING || $answerCorrect) { if ( in_array( $answerType, diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 6f8615a55e..ae85f44e84 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -955,7 +955,8 @@ class ExerciseLib 'id' => "window_{$windowId}_select", 'class' => 'select_option', 'style' => 'display: none;' - ] + ], + false ); if (!empty($answerCorrect) && !empty($selectedValue)) { diff --git a/main/template/default/exercise/submit.js.tpl b/main/template/default/exercise/submit.js.tpl index 468b096761..4706c58faf 100644 --- a/main/template/default/exercise/submit.js.tpl +++ b/main/template/default/exercise/submit.js.tpl @@ -18,8 +18,8 @@ value = dropedOnId.split('_')[2]; $('#' + originSelectId + ' option') - .filter(function () { - return $(this).val() == value; + .filter(function (index) { + return index === parseInt(value); }) .attr("selected", true);