|
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 abstract class qtype_renderer extends plugin_renderer_base { 00047 public function formulation_and_controls(question_attempt $qa, 00048 question_display_options $options) { 00049 return $qa->get_question()->format_questiontext($qa); 00050 } 00051 00058 public function formulation_heading() { 00059 return get_string('questiontext', 'question'); 00060 } 00061 00069 public function clear_wrong(question_attempt $qa) { 00070 $response = $qa->get_last_qt_data(); 00071 if (!$response) { 00072 return ''; 00073 } 00074 $cleanresponse = $qa->get_question()->clear_wrong_from_response($response); 00075 $output = ''; 00076 foreach ($cleanresponse as $name => $value) { 00077 $attr = array( 00078 'type' => 'hidden', 00079 'name' => $qa->get_qt_field_name($name), 00080 'value' => s($value), 00081 ); 00082 $output .= html_writer::empty_tag('input', $attr); 00083 } 00084 return $output; 00085 } 00086 00100 public function feedback(question_attempt $qa, question_display_options $options) { 00101 $output = ''; 00102 $hint = null; 00103 00104 if ($options->feedback) { 00105 $output .= html_writer::nonempty_tag('div', $this->specific_feedback($qa), 00106 array('class' => 'specificfeedback')); 00107 $hint = $qa->get_applicable_hint(); 00108 } 00109 00110 if ($options->numpartscorrect) { 00111 $output .= html_writer::nonempty_tag('div', $this->num_parts_correct($qa), 00112 array('class' => 'numpartscorrect')); 00113 } 00114 00115 if ($hint) { 00116 $output .= $this->hint($qa, $hint); 00117 } 00118 00119 if ($options->generalfeedback) { 00120 $output .= html_writer::nonempty_tag('div', $this->general_feedback($qa), 00121 array('class' => 'generalfeedback')); 00122 } 00123 00124 if ($options->rightanswer) { 00125 $output .= html_writer::nonempty_tag('div', $this->correct_response($qa), 00126 array('class' => 'rightanswer')); 00127 } 00128 00129 return $output; 00130 } 00131 00138 protected function specific_feedback(question_attempt $qa) { 00139 return ''; 00140 } 00141 00148 protected function num_parts_correct(question_attempt $qa) { 00149 $a = new stdClass(); 00150 list($a->num, $a->outof) = $qa->get_question()->get_num_parts_right( 00151 $qa->get_last_qt_data()); 00152 if (is_null($a->outof)) { 00153 return ''; 00154 } else { 00155 return get_string('yougotnright', 'question', $a); 00156 } 00157 } 00158 00165 protected function hint(question_attempt $qa, question_hint $hint) { 00166 return html_writer::nonempty_tag('div', 00167 $qa->get_question()->format_hint($hint, $qa), array('class' => 'hint')); 00168 } 00169 00176 protected function general_feedback(question_attempt $qa) { 00177 return $qa->get_question()->format_generalfeedback($qa); 00178 } 00179 00188 protected function correct_response(question_attempt $qa) { 00189 return ''; 00190 } 00191 00200 public function manual_comment(question_attempt $qa, question_display_options $options) { 00201 return ''; 00202 } 00203 00210 public function head_code(question_attempt $qa) { 00211 // This method is used by the Opaque question type. The remote question 00212 // engine can send back arbitrary CSS that we have to link to in the 00213 // page header. If it was not for that, we might be able to eliminate 00214 // this method and load the required CSS and JS some other way. 00215 $qa->get_question()->qtype->find_standard_scripts(); 00216 } 00217 00218 protected function feedback_class($fraction) { 00219 return question_state::graded_state_for_fraction($fraction)->get_feedback_class(); 00220 } 00221 00228 protected function feedback_image($fraction, $selected = true) { 00229 $state = question_state::graded_state_for_fraction($fraction); 00230 00231 if ($state == question_state::$gradedright) { 00232 $icon = 'tick_green'; 00233 } else if ($state == question_state::$gradedpartial) { 00234 $icon = 'tick_amber'; 00235 } else { 00236 $icon = 'cross_red'; 00237 } 00238 if ($selected) { 00239 $icon .= '_big'; 00240 } else { 00241 $icon .= '_small'; 00242 } 00243 00244 $attributes = array( 00245 'src' => $this->output->pix_url('i/' . $icon), 00246 'alt' => get_string($state->get_feedback_class(), 'question'), 00247 'class' => 'questioncorrectnessicon', 00248 ); 00249 00250 return html_writer::empty_tag('img', $attributes); 00251 } 00252 } 00253 00260 abstract class qtype_with_combined_feedback_renderer extends qtype_renderer { 00261 protected function combined_feedback(question_attempt $qa) { 00262 $question = $qa->get_question(); 00263 00264 $state = $qa->get_state(); 00265 00266 if (!$state->is_finished()) { 00267 $response = $qa->get_last_qt_data(); 00268 if (!$qa->get_question()->is_gradable_response($response)) { 00269 return ''; 00270 } 00271 list($notused, $state) = $qa->get_question()->grade_response($response); 00272 } 00273 00274 $feedback = ''; 00275 $field = $state->get_feedback_class() . 'feedback'; 00276 $format = $state->get_feedback_class() . 'feedbackformat'; 00277 if ($question->$field) { 00278 $feedback .= $question->format_text($question->$field, $question->$format, 00279 $qa, 'question', $field, $question->id); 00280 } 00281 00282 return $feedback; 00283 } 00284 }