Fix questions with right results - refs BT#11024

pull/2487/head
Angel Fernando Quiroz Campos 9 years ago
parent d6274561e9
commit 25cbec1e40
  1. 11
      main/exercise/exercise.class.php
  2. 25
      main/exercise/matching.class.php
  3. 10
      main/inc/lib/exercise.lib.php
  4. 16
      main/template/default/exercise/submit.js.tpl

@ -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']);
}

@ -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;
}
}

@ -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 .= <<<JAVASCRIPT
$s .= "
<script>
$(function() {
DraggableAnswer.deleteItem(
$('#{$questionId}_{$selectedValue}'),
$('#drop_$windowId')
$('#{$questionId}_{$lines_count}'),
$('#drop_{$questionId}_{$selectedKey}')
);
});
</script>
JAVASCRIPT;
";
}
if (isset($select_items[$lines_count])) {

@ -11,8 +11,6 @@ var DraggableAnswer = {
item.fadeOut(function () {
var $list = $('<ul>').addClass('gallery ui-helper-reset').appendTo(insertHere);
item.find('a.btn').remove();
var droppedId = item.attr('id'),
dropedOnId = insertHere.attr('id'),
originSelectId = 'window_' + droppedId + '_select',
@ -20,9 +18,11 @@ var DraggableAnswer = {
$('#' + originSelectId + ' option')
.filter(function (index) {
return index === parseInt(value);
var position = insertHere.prop('id').split('_')[2];
return index === parseInt(position);
})
.attr("selected", true);
.prop("selected", true);
item.appendTo($list).fadeIn();
});
@ -30,11 +30,6 @@ var DraggableAnswer = {
recycleItem: function (item) {
item.fadeOut(function () {
item
.find('a.btn')
.remove()
.end()
.find("img")
.end()
.appendTo(DraggableAnswer.gallery)
.fadeIn();
});
@ -42,7 +37,8 @@ var DraggableAnswer = {
var droppedId = item.attr('id'),
originSelectId = 'window_' + droppedId + '_select';
$('#' + originSelectId + ' option:first').attr('selected', 'selected');
$('#' + originSelectId + ' option').prop('selected', false);
$('#' + originSelectId + ' option:first').prop('selected', true);
},
init: function (gallery, trash) {
this.gallery = gallery;

Loading…
Cancel
Save