diff --git a/question/type/missingtype/edit_missingtype_form.php b/question/type/missingtype/edit_missingtype_form.php new file mode 100644 index 00000000000..15a3cda209f --- /dev/null +++ b/question/type/missingtype/edit_missingtype_form.php @@ -0,0 +1,102 @@ +gradeoptionsfull; + $repeated = array(); + $repeated[] =& $mform->createElement('header', 'choicehdr', get_string('choiceno', 'qtype_multichoice', '{no}')); + $repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz')); + $repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions); + $repeated[] =& $mform->createElement('htmleditor', 'feedback', get_string('feedback', 'quiz')); + + if (isset($this->question->options)){ + $countanswers = count($this->question->options->answers); + } else { + $countanswers = 0; + } + $repeatsatstart = (QUESTION_NUMANS_START > ($countanswers + QUESTION_NUMANS_ADD))? + QUESTION_NUMANS_START : ($countanswers + QUESTION_NUMANS_ADD); + $repeatedoptions = array(); + $repeatedoptions['answer']['type'] = PARAM_NOTAGS;//text with no multilang support + $repeatedoptions['fraction']['default'] = 0; + $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', QUESTION_NUMANS_ADD, get_string('addmorechoiceblanks', 'qtype_multichoice')); + } + + function set_data($question) { + if (isset($question->options)){ + $answers = $question->options->answers; + if (count($answers)) { + $key = 0; + foreach ($answers as $answer){ + $default_values['answer['.$key.']'] = $answer->answer; + $default_values['fraction['.$key.']'] = $answer->fraction; + $default_values['feedback['.$key.']'] = $answer->feedback; + $key++; + } + } + $question = (object)((array)$question + $default_values); + } + parent::set_data($question); + } + + function qtype() { + return 'missingtype'; + } + + function validation($data){ + $errors = array(); + $answers = $data['answer']; + $answercount = 0; + + $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', 1); + } + + + $totalfraction = round($totalfraction, 2); + if ($totalfraction != 1) { + $totalfraction = $totalfraction * 100; + $errors['fraction[0]'] = get_string('errfractionsaddwrong', 'qtype_multichoice', $totalfraction); + } + + return $errors; + } +} +?> \ No newline at end of file diff --git a/question/type/missingtype/editquestion.html b/question/type/missingtype/editquestion.html deleted file mode 100644 index 23cfade0d2a..00000000000 --- a/question/type/missingtype/editquestion.html +++ /dev/null @@ -1,41 +0,0 @@ -qtype]->print_question_form_start($question, array(), $course, $usehtmleditor); - -for ($i=1; $i<=count($answers); $i++) { - if (!isset($answers[$i-1]->fraction)) { - $answers[$i-1]->answer = ''; - $answers[$i-1]->fraction = 0; - $answers[$i-1]->feedback = ''; - } -?> - -