Commit 24f7485b authored by jamiesensei's avatar jamiesensei
Browse files

some extra validaton for multichoice and some bug fixes for multichoice and random qtype.

parent 0d905d9f
......@@ -11,6 +11,8 @@ $string['choices'] = 'Available choices';
$string['clozeaid'] = 'Enter missing word';
$string['correctfeedback'] = 'For any correct answer';
$string['editingmultichoice'] = 'Editing a Multiple Choice question';
$string['errfractionsaddwrong'] = 'The positive grades you have chosen do not add up to 100%%<br />Instead, they add up to $a%%';
$string['errfractionsnomax'] = 'One of the answers should be 100%%, so that it is<br />possible to get a full grade for this question.';
$string['feedback'] = 'Feedback';
$string['fillouttwochoices'] = 'You must fill out at least two choices. Choices left blank will not be used.';
$string['fractionsaddwrong'] = 'The positive grades you have chosen do not add up to 100%%<br />Instead, they add up to $a%%<br />Do you want to go back and fix this question?';
......
......@@ -78,7 +78,7 @@ class question_edit_multichoice_form extends question_edit_form {
$default_values['shuffleanswers'] = $question->options->shuffleanswers;
$default_values['correctfeedback'] = $question->options->correctfeedback;
$default_values['partiallycorrectfeedback'] = $question->options->partiallycorrectfeedback;
$default_values['overallincorrectfeedback'] = $question->options->overallincorrectfeedback;
$default_values['incorrectfeedback'] = $question->options->incorrectfeedback;
$question = (object)((array)$question + $default_values);
}
parent::set_defaults($question);
......@@ -92,12 +92,27 @@ class question_edit_multichoice_form extends question_edit_form {
$errors = array();
$answers = $data['answer'];
$answercount = 0;
foreach ($answers as $answer){
$totalfraction = 0;
$maxfraction = -1;
foreach ($answers as $key => $answer){
//check no of choices
$trimmedanswer = trim($answer);
if (!empty($trimmedanswer)){
$answercount++;
}
//check grades
if ($answer != '') {
if ($data['fraction'][$key] > 0) {
$totalfraction += $data['fraction'][$key];
}
if ($data['fraction'][$key] > $maxfraction) {
$maxfraction = $data['fraction'][$key];
}
}
}
if ($answercount==0){
$errors['answer[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
$errors['answer[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
......@@ -105,6 +120,20 @@ class question_edit_multichoice_form extends question_edit_form {
$errors['answer[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
}
/// Perform sanity checks on fractional grades
if ($data['single']) {
if ($maxfraction != 1) {
$maxfraction = $maxfraction * 100;
$errors['fraction[0]'] = get_string('errfractionsnomax', 'qtype_multichoice', $maxfraction);
}
} else {
$totalfraction = round($totalfraction,2);
if ($totalfraction != 1) {
$totalfraction = $totalfraction * 100;
$errors['fraction[0]'] = get_string('errfractionsaddwrong', 'qtype_multichoice', $totalfraction);
}
}
return $errors;
}
}
......
......@@ -41,6 +41,9 @@ class question_edit_random_form extends question_edit_form {
$mform->addElement('advcheckbox', 'questiontext', get_string("recurse", "quiz"), null, null, array(0, 1));
// Standard fields at the end of the form.
$mform->addElement('hidden', 'questiontextformat', 0);
$mform->setType('questiontextformat', PARAM_INT);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
......@@ -55,9 +58,7 @@ class question_edit_random_form extends question_edit_form {
$buttonarray = array();
$buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
if (!empty($this->question->id)) {
$buttonarray[] = &$mform->createElement('submit', 'makecopy', get_string('makecopy', 'quiz'));
}
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment