Fix resolve the question and show results - refs #7612

1.10.x
Angel Fernando Quiroz Campos 11 years ago
parent 7a6b5cf7e1
commit ed2fac0f63
  1. 31
      main/exercice/Draggable.php
  2. 13
      main/exercice/exercise.class.php
  3. 3
      main/inc/lib/exercise.lib.php
  4. 4
      main/template/default/exercise/submit.js.tpl

@ -35,22 +35,6 @@ class Draggable extends Question
$matches = array(); $matches = array();
$answer = null; $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()) { if ($form->isSubmitted()) {
$nb_matches = $form->getSubmitValue('nb_matches'); $nb_matches = $form->getSubmitValue('nb_matches');
@ -72,6 +56,9 @@ class Draggable extends Question
$nb_options++; $nb_options++;
} }
} else if (!empty($this->id)) { } else if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0) { if (count($answer->nbrAnswers) > 0) {
$nb_matches = $nb_options = 0; $nb_matches = $nb_options = 0;
@ -95,16 +82,8 @@ class Draggable extends Question
$defaults['option[2]'] = get_lang('DefaultMatchingOptB'); $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
} }
if (empty($matches)) { for ($i = 1; $i <= $nb_matches; ++$i) {
for ($i = 1; $i <= $nb_options; ++$i) { $matches[$i] = $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);
}
} }
$form->addElement('hidden', 'nb_matches', $nb_matches); $form->addElement('hidden', 'nb_matches', $nb_matches);

@ -2812,12 +2812,12 @@ class Exercise
if ($s_user_answer == $i_answer_correct_answer) { if ($s_user_answer == $i_answer_correct_answer) {
$questionScore += $i_answerWeighting; $questionScore += $i_answerWeighting;
$totalScore += $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 (isset($real_list[$i_answer_id])) {
if ($answerType == DRAGGABLE) {
$user_answer = Display::label(get_lang('Correct'), 'success');
} else {
$user_answer = '<span>'.$real_list[$i_answer_id].'</span>'; $user_answer = '<span>'.$real_list[$i_answer_id].'</span>';
} }
} }
} else { } else {
if ($answerType == DRAGGABLE) { if ($answerType == DRAGGABLE) {
@ -2834,9 +2834,11 @@ class Exercise
echo '<tr>'; echo '<tr>';
echo '<td>'.$s_answer_label.'</td>'; echo '<td>'.$s_answer_label.'</td>';
echo '<td>'.$user_answer; echo '<td>'.$user_answer;
if ($answerType == MATCHING) {
if (isset($real_list[$i_answer_correct_answer])) { if (isset($real_list[$i_answer_correct_answer])) {
echo ' <b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b> '; echo ' <b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b> ';
} }
}
echo '</td>'; echo '</td>';
echo '</tr>'; echo '</tr>';
} }
@ -2956,9 +2958,6 @@ class Exercise
) || ) ||
$answerCorrect $answerCorrect
) { ) {
}
if ($answerType != MATCHING || $answerCorrect) {
if ( if (
in_array( in_array(
$answerType, $answerType,

@ -955,7 +955,8 @@ class ExerciseLib
'id' => "window_{$windowId}_select", 'id' => "window_{$windowId}_select",
'class' => 'select_option', 'class' => 'select_option',
'style' => 'display: none;' 'style' => 'display: none;'
] ],
false
); );
if (!empty($answerCorrect) && !empty($selectedValue)) { if (!empty($answerCorrect) && !empty($selectedValue)) {

@ -18,8 +18,8 @@
value = dropedOnId.split('_')[2]; value = dropedOnId.split('_')[2];
$('#' + originSelectId + ' option') $('#' + originSelectId + ' option')
.filter(function () { .filter(function (index) {
return $(this).val() == value; return index === parseInt(value);
}) })
.attr("selected", true); .attr("selected", true);

Loading…
Cancel
Save