|
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 00028 defined('MOODLE_INTERNAL') || die(); 00029 00030 00038 class qbehaviour_deferredcbm_renderer extends qbehaviour_renderer { 00039 protected function certainly_choices($controlname, $selected, $readonly) { 00040 $attributes = array( 00041 'type' => 'radio', 00042 'name' => $controlname, 00043 ); 00044 if ($readonly) { 00045 $attributes['disabled'] = 'disabled'; 00046 } 00047 00048 $choices = ''; 00049 foreach (question_cbm::$certainties as $certainty) { 00050 $id = $controlname . $certainty; 00051 $attributes['id'] = $id; 00052 $attributes['value'] = $certainty; 00053 if ($selected == $certainty) { 00054 $attributes['checked'] = 'checked'; 00055 } else { 00056 unset($attributes['checked']); 00057 } 00058 $choices .= ' ' . html_writer::empty_tag('input', $attributes) . ' ' . 00059 html_writer::tag('label', question_cbm::get_string($certainty), 00060 array('for' => $id)); 00061 } 00062 return $choices; 00063 } 00064 00065 public function controls(question_attempt $qa, question_display_options $options) { 00066 return html_writer::tag('div', get_string('howcertainareyou', 'qbehaviour_deferredcbm', 00067 $this->certainly_choices($qa->get_behaviour_field_name('certainty'), 00068 $qa->get_last_behaviour_var('certainty'), $options->readonly)), 00069 array('class' => 'certaintychoices')); 00070 } 00071 00072 public function feedback(question_attempt $qa, question_display_options $options) { 00073 if (!$options->feedback) { 00074 return ''; 00075 } 00076 00077 if ($qa->get_state() == question_state::$gaveup || $qa->get_state() == 00078 question_state::$mangaveup) { 00079 return ''; 00080 } 00081 00082 $feedback = ''; 00083 if (!$qa->get_last_behaviour_var('certainty') && 00084 $qa->get_last_behaviour_var('_assumedcertainty')) { 00085 $feedback .= html_writer::tag('p', 00086 get_string('assumingcertainty', 'qbehaviour_deferredcbm', 00087 question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty')))); 00088 } 00089 00090 if ($options->marks >= question_display_options::MARK_AND_MAX) { 00091 $a = new stdClass(); 00092 $a->rawmark = format_float($qa->get_last_behaviour_var('_rawfraction') * 00093 $qa->get_max_mark(), $options->markdp); 00094 $a->mark = $qa->format_mark($options->markdp); 00095 $feedback .= html_writer::tag('p', 00096 get_string('markadjustment', 'qbehaviour_deferredcbm', $a)); 00097 } 00098 00099 return $feedback; 00100 } 00101 }