|
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 00039 abstract class qbehaviour_renderer extends plugin_renderer_base { 00052 public function controls(question_attempt $qa, question_display_options $options) { 00053 return ''; 00054 } 00055 00067 public function feedback(question_attempt $qa, question_display_options $options) { 00068 return ''; 00069 } 00070 00071 public function manual_comment_fields(question_attempt $qa, question_display_options $options) { 00072 $inputname = $qa->get_behaviour_field_name('comment'); 00073 $id = $inputname . '_id'; 00074 list($commenttext, $commentformat) = $qa->get_manual_comment(); 00075 00076 $editor = editors_get_preferred_editor($commentformat); 00077 $strformats = format_text_menu(); 00078 $formats = $editor->get_supported_formats(); 00079 foreach ($formats as $fid) { 00080 $formats[$fid] = $strformats[$fid]; 00081 } 00082 00083 $commenttext = format_text($commenttext, $commentformat, array('para' => false)); 00084 00085 $editor->use_editor($id, array('context' => $options->context)); 00086 00087 $commenteditor = html_writer::tag('div', html_writer::tag('textarea', s($commenttext), 00088 array('id' => $id, 'name' => $inputname, 'rows' => 10, 'cols' => 60))); 00089 00090 $commenteditor .= html_writer::start_tag('div'); 00091 if (count($formats == 1)) { 00092 reset($formats); 00093 $commenteditor .= html_writer::empty_tag('input', array('type' => 'hidden', 00094 'name' => $inputname . 'format', 'value' => key($formats))); 00095 00096 } else { 00097 $commenteditor .= html_writer::select( 00098 $formats, $inputname . 'format', $commentformat, ''); 00099 } 00100 $commenteditor .= html_writer::end_tag('div'); 00101 00102 $comment = html_writer::tag('div', html_writer::tag('div', 00103 html_writer::tag('label', get_string('comment', 'question'), 00104 array('for' => $id)), array('class' => 'fitemtitle')) . 00105 html_writer::tag('div', $commenteditor, array('class' => 'felement fhtmleditor')), 00106 array('class' => 'fitem')); 00107 00108 $mark = ''; 00109 if ($qa->get_max_mark()) { 00110 $currentmark = $qa->get_current_manual_mark(); 00111 $maxmark = $qa->get_max_mark(); 00112 00113 $fieldsize = strlen($qa->format_max_mark($options->markdp)) - 1; 00114 $markfield = $qa->get_behaviour_field_name('mark'); 00115 00116 $attributes = array( 00117 'type' => 'text', 00118 'size' => $fieldsize, 00119 'name' => $markfield, 00120 ); 00121 if (!is_null($currentmark)) { 00122 $attributes['value'] = $qa->format_fraction_as_mark( 00123 $currentmark / $maxmark, $options->markdp); 00124 } 00125 $a = new stdClass(); 00126 $a->max = $qa->format_max_mark($options->markdp); 00127 $a->mark = html_writer::empty_tag('input', $attributes); 00128 00129 $markrange = html_writer::empty_tag('input', array( 00130 'type' => 'hidden', 00131 'name' => $qa->get_behaviour_field_name('maxmark'), 00132 'value' => $maxmark, 00133 )) . html_writer::empty_tag('input', array( 00134 'type' => 'hidden', 00135 'name' => $qa->get_control_field_name('minfraction'), 00136 'value' => $qa->get_min_fraction(), 00137 )); 00138 00139 $errorclass = ''; 00140 $error = ''; 00141 if ($currentmark > $maxmark || $currentmark < $maxmark * $qa->get_min_fraction()) { 00142 $errorclass = ' error'; 00143 $error = html_writer::tag('span', get_string('manualgradeoutofrange', 'question'), 00144 array('class' => 'error')) . html_writer::empty_tag('br'); 00145 } 00146 00147 $mark = html_writer::tag('div', html_writer::tag('div', 00148 html_writer::tag('label', get_string('mark', 'question'), 00149 array('for' => $markfield)), 00150 array('class' => 'fitemtitle')) . 00151 html_writer::tag('div', $error . get_string('xoutofmax', 'question', $a) . 00152 $markrange, array('class' => 'felement ftext' . $errorclass) 00153 ), array('class' => 'fitem')); 00154 } 00155 00156 return html_writer::tag('fieldset', html_writer::tag('div', $comment . $mark, 00157 array('class' => 'fcontainer clearfix')), array('class' => 'hidden')); 00158 } 00159 00160 public function manual_comment_view(question_attempt $qa, question_display_options $options) { 00161 $output = ''; 00162 if ($qa->has_manual_comment()) { 00163 $output .= get_string('commentx', 'question', $qa->get_behaviour()->format_comment()); 00164 } 00165 if ($options->manualcommentlink) { 00166 $url = new moodle_url($options->manualcommentlink, array('slot' => $qa->get_slot())); 00167 $link = $this->output->action_link($url, get_string('commentormark', 'question'), 00168 new popup_action('click', $url, 'commentquestion', 00169 array('width' => 600, 'height' => 800))); 00170 $output .= html_writer::tag('div', $link, array('class' => 'commentlink')); 00171 } 00172 return $output; 00173 } 00174 00182 public function manual_comment(question_attempt $qa, question_display_options $options) { 00183 if ($options->manualcomment == question_display_options::EDITABLE) { 00184 return $this->manual_comment_fields($qa, $options); 00185 00186 } else if ($options->manualcomment == question_display_options::VISIBLE) { 00187 return $this->manual_comment_view($qa, $options); 00188 00189 } else { 00190 return ''; 00191 } 00192 } 00193 00200 protected function submit_button(question_attempt $qa, question_display_options $options) { 00201 $attributes = array( 00202 'type' => 'submit', 00203 'id' => $qa->get_behaviour_field_name('submit'), 00204 'name' => $qa->get_behaviour_field_name('submit'), 00205 'value' => get_string('check', 'question'), 00206 'class' => 'submit btn', 00207 ); 00208 if ($options->readonly) { 00209 $attributes['disabled'] = 'disabled'; 00210 } 00211 $output = html_writer::empty_tag('input', $attributes); 00212 if (!$options->readonly) { 00213 $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', 00214 array($attributes['id'], $qa->get_slot())); 00215 } 00216 return $output; 00217 } 00218 00225 public function head_code(question_attempt $qa) { 00226 return ''; 00227 } 00228 }