diff -Naur old/edit_multichoice_form.php new/edit_multichoice_form.php --- old/edit_multichoice_form.php 2012-02-13 15:34:35.000000000 +0530 +++ new/edit_multichoice_form.php 2012-03-05 12:35:18.000000000 +0530 @@ -39,7 +39,7 @@ function definition_inner(&$mform) { global $QTYPES; - $menu = array(get_string('answersingleno', 'qtype_multichoice'), get_string('answersingleyes', 'qtype_multichoice')); + $menu = array(get_string('answersingleno', 'qtype_multichoice'), get_string('answersingleyes', 'qtype_multichoice'), get_string('answertwo', 'qtype_multichoice'), get_string('answerthree', 'qtype_multichoice')); $mform->addElement('select', 'single', get_string('answerhowmany', 'qtype_multichoice'), $menu); $mform->setDefault('single', 1); @@ -158,18 +158,22 @@ } /// Perform sanity checks on fractional grades - if ($data['single']) { + if ($data['single']==1) { if ($maxfraction != 1) { $maxfraction = $maxfraction * 100; $errors['fraction[0]'] = get_string('errfractionsnomax', 'qtype_multichoice', $maxfraction); - } - } else { + } + } + + + else { + $totalfraction = round($totalfraction,2); if ($totalfraction != 1) { $totalfraction = $totalfraction * 100; $errors['fraction[0]'] = get_string('errfractionsaddwrong', 'qtype_multichoice', $totalfraction); } - } + } return $errors; } } diff -Naur old/qtype_multichoice.php new/qtype_multichoice.php --- old/qtype_multichoice.php 2012-02-13 15:34:35.000000000 +0530 +++ new/qtype_multichoice.php 2012-03-05 10:48:42.000000000 +0530 @@ -26,6 +26,8 @@ $string['addingmultichoice'] = 'Adding a Multiple choice question'; $string['addmorechoiceblanks'] = 'Blanks for {no} more choices'; $string['answerhowmany'] = 'One or multiple answers?'; +$string['answertwo'] = 'Two answers only'; +$string['answerthree'] = 'Three answers only'; $string['answernumbering'] = 'Number the choices?'; $string['answernumberingabc'] = 'a., b., c., ...'; $string['answernumberingABCD'] = 'A., B., C., ...'; @@ -58,3 +60,8 @@ $string['shuffleanswers'] = 'Shuffle the choices?'; $string['shuffleanswers_help'] = 'If enabled, the order of the answers is randomly shuffled for each attempt, provided that "Shuffle within questions" in the quiz settings is also enabled.'; $string['singleanswer'] = 'Choose one answer.'; +$string['twoanswer'] = 'Choose exactly two answers.'; +$string['threeanswer'] = 'Choose exactly three answers.'; + + + diff -Naur old/questiontype.php new/questiontype.php --- old/questiontype.php 2012-02-13 15:34:35.000000000 +0530 +++ new/questiontype.php 2012-03-05 12:37:09.000000000 +0530 @@ -134,12 +134,15 @@ $DB->update_record('question_multichoice', $options); /// Perform sanity checks on fractional grades - if ($options->single) { + if ($options->single==1) { if ($maxfraction != 1) { $result->noticeyesno = get_string('fractionsnomax', 'qtype_multichoice', $maxfraction * 100); return $result; } - } else { + } + + +else { $totalfraction = round($totalfraction, 2); if ($totalfraction != 1) { $result->noticeyesno = get_string('fractionsaddwrong', 'qtype_multichoice', $totalfraction * 100); @@ -272,8 +275,35 @@ // Print formulation $questiontext = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course); - $answerprompt = ($question->options->single) ? get_string('singleanswer', 'quiz') : - get_string('multipleanswers', 'quiz'); + //$answerprompt = ($question->options->single) ? get_string('singleanswer', 'quiz') : + // get_string('multipleanswers', 'quiz'); + + + +if($question->options->single==1) +{ + $answerprompt = get_string('singleanswer', 'quiz'); +} + +else if($question->options->single==2) +{ + $answerprompt = get_string('twoanswer', 'quiz'); +} + +else if($question->options->single==3) +{ + $answerprompt = get_string('threeanswer', 'quiz'); +} + +else +{ + $answerprompt = get_string('multipleanswers', 'quiz'); +} + + + + + // Print each answer in a separate row foreach ($state->options->order as $key => $aid) { @@ -281,30 +311,142 @@ $checked = ''; $chosen = false; - if ($question->options->single) { + + $a = new stdClass; + $a->id = $question->name_prefix . $aid; + $a->class = ''; + $a->feedbackimg = ''; + + + + + if ($question->options->single==1) { $type = 'type="radio"'; $name = "name=\"{$question->name_prefix}\""; if (isset($state->responses['']) and $aid == $state->responses['']) { $checked = 'checked="checked"'; $chosen = true; } - } else { + +$a->control = "id\" $name $checked $type value=\"$aid\" />"; + + + + + } + + + +/*else */ if ($question->options->single==2){ + $type = ' type="checkbox" '; $name = "name=\"{$question->name_prefix}{$aid}\""; if (isset($state->responses[$aid])) { $checked = 'checked="checked"'; $chosen = true; } + +?> + + + + + +control = "id\" $name $checked $type onclick=\"Checks1(this)\" value=\"$aid\" />"; + +?> + +id = $question->name_prefix . $aid; - $a->class = ''; - $a->feedbackimg = ''; +if ($question->options->single==3){ - // Print the control - $a->control = "id\" $name $checked $type value=\"$aid\" />"; + $type = ' type="checkbox" '; + $name = "name=\"{$question->name_prefix}{$aid}\""; + if (isset($state->responses[$aid])) { + $checked = 'checked="checked"'; + $chosen = true; + } + +?> + + + + + +control = "id\" $name $checked $type onclick=\"Checks(this)\" value=\"$aid\" />"; + +?> + +options->single==0) { + $type = ' type="checkbox" '; + $name = "name=\"{$question->name_prefix}{$aid}\""; + if (isset($state->responses[$aid])) { + $checked = 'checked="checked"'; + $chosen = true; + } + +$a->control = "id\" $name $checked $type value=\"$aid\" />"; + +} + +?> +correct_responses && $answer->fraction > 0) { $a->class = question_get_feedback_class(1); } @@ -372,12 +514,16 @@ function grade_responses(&$question, &$state, $cmoptions) { $state->raw_grade = 0; - if($question->options->single) { + if($question->options->single==1) { $response = reset($state->responses); if ($response) { $state->raw_grade = $question->options->answers[$response]->fraction; } - } else { + } + + + + if($question->options->single==0) { foreach ($state->responses as $response) { if ($response) { $state->raw_grade += $question->options->answers[$response]->fraction; @@ -385,6 +531,32 @@ } } + if($question->options->single==2) { + foreach ($state->responses as $response) { + if ($response) { + $state->raw_grade += $question->options->answers[$response]->fraction; + } + } + } + + + if($question->options->single==3) { + foreach ($state->responses as $response) { + if ($response) { + $state->raw_grade += $question->options->answers[$response]->fraction; + } + } + } + + +/* else { + foreach ($state->responses as $response) { + if ($response) { + $state->raw_grade += $question->options->answers[$response]->fraction; + } + } + } */ + // Make sure we don't assign negative or too high marks $state->raw_grade = min(max((float) $state->raw_grade, 0.0), 1.0) * $question->maxgrade; diff -Naur old/quiz.php new/quiz.php --- old/quiz.php 2012-02-13 15:34:35.000000000 +0530 +++ new/quiz.php 2012-03-05 10:43:04.000000000 +0530 @@ -798,6 +798,8 @@ $string['significantfigures'] = 'with {$a}'; $string['significantfiguresformat'] = 'significant figures'; $string['singleanswer'] = 'Choose one answer.'; +$string['twoanswer'] = 'Choose exactly two answers.'; +$string['threeanswer'] = 'Choose exactly three answers.'; $string['sortage'] = 'Sort by age'; $string['sortalpha'] = 'Sort by name'; $string['sortquestionsbyx'] = 'Sort questions by: {$a}';