Skip to content
Snippets Groups Projects
Commit 3f4e4813 authored by falcon's avatar falcon
Browse files

#818644: Added: Multichoice questions will give a negative score to wrong answers by default

parent aba85d30
No related branches found
No related tags found
No related merge requests found
......@@ -40,8 +40,14 @@ class MultichoiceQuestion extends QuizQuestion {
$short['score_if_not_chosen'] = 0;
}
else {
$short['score_if_chosen'] = 0;
$short['score_if_not_chosen'] = 1;
if (variable_get('multichoice_def_scoring', 0) == 0) {
$short['score_if_chosen'] = -1;
$short['score_if_not_chosen'] = 0;
}
elseif (variable_get('multichoice_def_scoring', 0) == 1) {
$short['score_if_chosen'] = 0;
$short['score_if_not_chosen'] = 1;
}
}
}
}
......@@ -494,7 +500,7 @@ class MultichoiceQuestion extends QuizQuestion {
'#type' => 'checkbox',
'#title' => t('Correct'),
'#default_value' => $correct_default,
'#attributes' => array('onchange' => 'refreshScores(this)'),
'#attributes' => array('onchange' => 'refreshScores(this, ' . variable_get('multichoice_def_scoring', 0) . ')'),
);
// We add id to be able to update the correct alternatives if the node is updated, without destroying
// existing answer reports
......
......@@ -9,20 +9,31 @@
* @param checkbox
* The checkbox that was clicked
*/
function refreshScores(checkbox) {
function refreshScores(checkbox, scoring) {
var prefix = '#' + getCorrectIdPrefix(checkbox.id);
if (checkbox.checked) {
$(prefix + 'score-if-chosen').val('1');
$(prefix + 'score-if-not-chosen').val('0');
}
else {
$(prefix + 'score-if-chosen').val('0');
if ($('#edit-choice-multi').attr('checked')) {
$(prefix + 'score-if-not-chosen').val('1');
}
else {
$(prefix + 'score-if-not-chosen').val('0');
}
if (scoring == 0) {
$(prefix + 'score-if-not-chosen').val('0');
if ($('#edit-choice-multi').attr('checked')) {
$(prefix + 'score-if-chosen').val('-1');
}
else {
$(prefix + 'score-if-chosen').val('0');
}
}
else if (scoring == 1) {
$(prefix + 'score-if-chosen').val('0');
if ($('#edit-choice-multi').attr('checked')) {
$(prefix + 'score-if-not-chosen').val('1');
}
else {
$(prefix + 'score-if-not-chosen').val('0');
}
}
}
}
......
......@@ -58,6 +58,16 @@ function multichoice_config() {
'#title' => t('Default number of alternatives'),
'#default_value' => variable_get('multichoice_def_num_of_alts', 2),
);
$form['multichoice_def_scoring'] = array(
'#type' => 'radios',
'#title' => t('Default scoring method'),
'#description' => t('Choose the default scoring method for questions with multiple correct answers.'),
'#options' => array(
0 => t('Give minus one point for incorrect answers'),
1 => t("Give one point for each incorrect option that haven't been chosen"),
),
'#default_value' => variable_get('multichoice_def_scoring', 0),
);
$form['#validate'] = 'multichoice_config_validate';
return $form;
}
......
......@@ -397,7 +397,7 @@ function quiz_question_delete_result($rid, $nid, $vid) {
/**
* Get the configuration form for all enabled question types.
*/
function quiz_question_config($context, $type) {
function quiz_question_config($context) {
$q_types = _quiz_question_get_implementations();
$form = array();
// Go through all question types and merge their config forms
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment