diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 8c707e16bc..53c4de5b81 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -946,35 +946,36 @@ class ExerciseLib HTML; - $selectedValue = 0; - $selectedPosition = 0; - $questionOptions = []; - $iTempt = 0; + $draggableSelectOptions = []; + $selectedValue = 0; + $selectedIndex = 0; - foreach ($select_items as $key => $val) { - if ($debug_mark_answer) { - if ($val['id'] == $answerCorrect) { - $selectedValue = $val['id']; - $selectedPosition = $iTempt; + if ($user_choice) { + foreach ($user_choice as $chosen) { + if ($answerCorrect != $chosen['answer']) { + continue; } + + $selectedValue = $chosen['answer']; } + } - if ( - isset($user_choice[$matching_correct_answer]) && - $val['id'] == $user_choice[$matching_correct_answer]['answer'] - ) { - $selectedValue = $val['id']; - $selectedPosition = $iTempt; + foreach ($select_items as $key => $select_item) { + $draggableSelectOptions[$select_item['id']] = $select_item['letter']; + } + + foreach ($draggableSelectOptions as $value => $text) { + if ($value == $selectedValue) { + break; } - $questionOptions[$val['id']] = $val['letter']; - $iTempt++; + $selectedIndex++; } $s .= Display::select( "choice[$questionId][$numAnswer]", - $questionOptions, + $draggableSelectOptions, $selectedValue, [ 'id' => "window_{$windowId}_select", @@ -986,25 +987,25 @@ HTML; if (!empty($answerCorrect) && !empty($selectedValue)) { // Show connect if is not freeze (question preview) if (!$freeze) { - $s .= << - $(document).on('ready', function () { - jsPlumb.ready(function() { - jsPlumb.connect({ - source: 'window_$windowId', - target: 'window_{$questionId}_{$selectedPosition}_answer', - endpoint: ['Blank', {radius: 15}], - anchors: ['RightMiddle', 'LeftMiddle'], - paintStyle: {strokeStyle: '#8A8888', lineWidth: 8}, - connector: [ - MatchingDraggable.connectorType, - {curvines: MatchingDraggable.curviness} - ] + $s .= " + -JAVASCRIPT; + + "; } }