|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 00036 class qtype_shortanswer_edit_form extends question_edit_form { 00037 00038 protected function definition_inner($mform) { 00039 $menu = array( 00040 get_string('caseno', 'qtype_shortanswer'), 00041 get_string('caseyes', 'qtype_shortanswer') 00042 ); 00043 $mform->addElement('select', 'usecase', 00044 get_string('casesensitive', 'qtype_shortanswer'), $menu); 00045 00046 $mform->addElement('static', 'answersinstruct', 00047 get_string('correctanswers', 'qtype_shortanswer'), 00048 get_string('filloutoneanswer', 'qtype_shortanswer')); 00049 $mform->closeHeaderBefore('answersinstruct'); 00050 00051 $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_shortanswer', '{no}'), 00052 question_bank::fraction_options()); 00053 00054 $this->add_interactive_settings(); 00055 } 00056 00057 protected function data_preprocessing($question) { 00058 $question = parent::data_preprocessing($question); 00059 $question = $this->data_preprocessing_answers($question); 00060 $question = $this->data_preprocessing_hints($question); 00061 00062 return $question; 00063 } 00064 00065 public function validation($data, $files) { 00066 $errors = parent::validation($data, $files); 00067 $answers = $data['answer']; 00068 $answercount = 0; 00069 $maxgrade = false; 00070 foreach ($answers as $key => $answer) { 00071 $trimmedanswer = trim($answer); 00072 if ($trimmedanswer !== '') { 00073 $answercount++; 00074 if ($data['fraction'][$key] == 1) { 00075 $maxgrade = true; 00076 } 00077 } else if ($data['fraction'][$key] != 0 || 00078 !html_is_blank($data['feedback'][$key]['text'])) { 00079 $errors["answer[$key]"] = get_string('answermustbegiven', 'qtype_shortanswer'); 00080 $answercount++; 00081 } 00082 } 00083 if ($answercount==0) { 00084 $errors['answer[0]'] = get_string('notenoughanswers', 'qtype_shortanswer', 1); 00085 } 00086 if ($maxgrade == false) { 00087 $errors['fraction[0]'] = get_string('fractionsnomax', 'question'); 00088 } 00089 return $errors; 00090 } 00091 00092 public function qtype() { 00093 return 'shortanswer'; 00094 } 00095 }