From 25cbec1e40ba2582e3da8674b4c7c185e1272743 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 12 Jan 2017 17:21:15 -0500 Subject: [PATCH] Fix questions with right results - refs BT#11024 --- main/exercise/exercise.class.php | 11 +++++++++ main/exercise/matching.class.php | 25 ++++++++++++++++++++ main/inc/lib/exercise.lib.php | 22 +++++++++-------- main/template/default/exercise/submit.js.tpl | 16 +++++-------- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index 558366623a..aefdd90d59 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -8487,6 +8487,17 @@ class Exercise case FILL_IN_BLANKS: $isCorrect = FillBlanks::isCorrect($answer['answer']); break; + case MATCHING: + //no break + case DRAGGABLE: + //no break + case MATCHING_DRAGGABLE: + $isCorrect = Matching::isCorrect( + $answer['position'], + $answer['answer'], + $answer['question_id'] + ); + break; default: $isCorrect = $objAnswer->isCorrectByAutoId($answer['answer']); } diff --git a/main/exercise/matching.class.php b/main/exercise/matching.class.php index e39b721024..0c74109d84 100755 --- a/main/exercise/matching.class.php +++ b/main/exercise/matching.class.php @@ -275,4 +275,29 @@ class Matching extends Question return $header; } + + /** + * Check if a answer is correct + * @param int $position + * @param int $answer + * @return bool + */ + public static function isCorrect($position, $answer, $questionId) + { + $em = Database::getManager(); + + $count = $em + ->createQuery(' + SELECT COUNT(a) From ChamiloCourseBundle:CQuizAnswer a + WHERE a.iid = :position AND a.correct = :answer AND a.questionId = :question + ') + ->setParameters([ + 'position' => $position, + 'answer' => $answer, + 'question' => $questionId + ]) + ->getSingleScalarResult(); + + return $count ? true : false; + } } diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 830c14595c..3f0175c5db 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -848,6 +848,7 @@ class ExerciseLib ] ); $selectedValue = 0; + $selectedKey = 0; $draggableSelectOptions = []; foreach ($select_items as $key => $val) { @@ -861,6 +862,7 @@ class ExerciseLib isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer'] ) { + $selectedKey = $key; $selectedValue = $val['id']; } @@ -880,16 +882,16 @@ class ExerciseLib ); if (!empty($answerCorrect) && !empty($selectedValue)) { - $s .= << - $(function() { - DraggableAnswer.deleteItem( - $('#{$questionId}_{$selectedValue}'), - $('#drop_$windowId') - ); - }); - -JAVASCRIPT; + $s .= " + + "; } if (isset($select_items[$lines_count])) { diff --git a/main/template/default/exercise/submit.js.tpl b/main/template/default/exercise/submit.js.tpl index 338fd4474f..25e20c1636 100644 --- a/main/template/default/exercise/submit.js.tpl +++ b/main/template/default/exercise/submit.js.tpl @@ -11,8 +11,6 @@ var DraggableAnswer = { item.fadeOut(function () { var $list = $('