|
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_essay extends question_type { 00037 public function is_manual_graded() { 00038 return true; 00039 } 00040 00041 public function response_file_areas() { 00042 return array('attachments', 'answer'); 00043 } 00044 00045 public function get_question_options($question) { 00046 global $DB; 00047 $question->options = $DB->get_record('qtype_essay_options', 00048 array('questionid' => $question->id), '*', MUST_EXIST); 00049 parent::get_question_options($question); 00050 } 00051 00052 public function save_question_options($formdata) { 00053 global $DB; 00054 $context = $formdata->context; 00055 00056 $options = $DB->get_record('qtype_essay_options', array('questionid' => $formdata->id)); 00057 if (!$options) { 00058 $options = new stdClass(); 00059 $options->questionid = $formdata->id; 00060 $options->id = $DB->insert_record('qtype_essay_options', $options); 00061 } 00062 00063 $options->responseformat = $formdata->responseformat; 00064 $options->responsefieldlines = $formdata->responsefieldlines; 00065 $options->attachments = $formdata->attachments; 00066 $options->graderinfo = $this->import_or_save_files($formdata->graderinfo, 00067 $context, 'qtype_essay', 'graderinfo', $formdata->id); 00068 $options->graderinfoformat = $formdata->graderinfo['format']; 00069 $DB->update_record('qtype_essay_options', $options); 00070 } 00071 00072 protected function initialise_question_instance(question_definition $question, $questiondata) { 00073 parent::initialise_question_instance($question, $questiondata); 00074 $question->responseformat = $questiondata->options->responseformat; 00075 $question->responsefieldlines = $questiondata->options->responsefieldlines; 00076 $question->attachments = $questiondata->options->attachments; 00077 $question->graderinfo = $questiondata->options->graderinfo; 00078 $question->graderinfoformat = $questiondata->options->graderinfoformat; 00079 } 00080 00085 public function response_formats() { 00086 return array( 00087 'editor' => get_string('formateditor', 'qtype_essay'), 00088 'editorfilepicker' => get_string('formateditorfilepicker', 'qtype_essay'), 00089 'plain' => get_string('formatplain', 'qtype_essay'), 00090 'monospaced' => get_string('formatmonospaced', 'qtype_essay'), 00091 ); 00092 } 00093 00097 public function response_sizes() { 00098 $choices = array(); 00099 for ($lines = 5; $lines <= 40; $lines += 5) { 00100 $choices[$lines] = get_string('nlines', 'qtype_essay', $lines); 00101 } 00102 return $choices; 00103 } 00104 00108 public function attachment_options() { 00109 return array( 00110 0 => get_string('no'), 00111 1 => '1', 00112 2 => '2', 00113 3 => '3', 00114 -1 => get_string('unlimited'), 00115 ); 00116 } 00117 00118 public function move_files($questionid, $oldcontextid, $newcontextid) { 00119 parent::move_files($questionid, $oldcontextid, $newcontextid); 00120 $fs = get_file_storage(); 00121 $fs->move_area_files_to_new_context($oldcontextid, 00122 $newcontextid, 'qtype_essay', 'graderinfo', $questionid); 00123 } 00124 00125 protected function delete_files($questionid, $contextid) { 00126 parent::delete_files($questionid, $contextid); 00127 $fs = get_file_storage(); 00128 $fs->delete_area_files($contextid, 'qtype_essay', 'graderinfo', $questionid); 00129 } 00130 }