Merge branch 'MDL-24255' of git://github.com/timhunt/moodle
authorSam Hemelryk <sam@moodle.com>
Mon, 20 Jun 2011 07:51:59 +0000 (15:51 +0800)
committerSam Hemelryk <sam@moodle.com>
Mon, 20 Jun 2011 07:51:59 +0000 (15:51 +0800)
question/behaviour/rendererbase.php
question/type/essay/renderer.php

index c8d6479..adf9363 100644 (file)
@@ -69,16 +69,40 @@ abstract class qbehaviour_renderer extends plugin_renderer_base {
     }
 
     public function manual_comment_fields(question_attempt $qa, question_display_options $options) {
+        $inputname = $qa->get_behaviour_field_name('comment');
+        $id = $inputname . '_id';
+        list($commenttext, $commentformat) = $qa->get_manual_comment();
 
-        $commentfield = $qa->get_behaviour_field_name('comment');
+        $editor = editors_get_preferred_editor($commentformat);
+        $strformats = format_text_menu();
+        $formats = $editor->get_supported_formats();
+        foreach ($formats as $fid) {
+            $formats[$fid] = $strformats[$fid];
+        }
+
+        $commenttext = format_text($commenttext, $commentformat, array('para' => false));
+
+        $editor->use_editor($id, array('context' => $options->context));
+
+        $commenteditor = html_writer::tag('div', html_writer::tag('textarea', s($commenttext),
+                array('id' => $id, 'name' => $inputname, 'rows' => 10, 'cols' => 60)));
+
+        $commenteditor .= html_writer::start_tag('div');
+        if (count($formats == 1)) {
+            reset($formats);
+            $commenteditor .= html_writer::empty_tag('input', array('type' => 'hidden',
+                    'name' => $inputname . 'format', 'value' => key($formats)));
+
+        } else {
+            $commenteditor .= html_writer::select(
+                    $formats, $inputname . 'format', $commentformat, '');
+        }
+        $commenteditor .= html_writer::end_tag('div');
 
-        list($commenttext, $commentformat) = $qa->get_manual_comment();
-        $comment = print_textarea(can_use_html_editor(), 10, 80, null, null,
-                $commentfield, $commenttext, 0, true);
         $comment = html_writer::tag('div', html_writer::tag('div',
                 html_writer::tag('label', get_string('comment', 'question'),
-                array('for' => $commentfield)), array('class' => 'fitemtitle')) .
-                html_writer::tag('div', $comment, array('class' => 'felement fhtmleditor')),
+                array('for' => $id)), array('class' => 'fitemtitle')) .
+                html_writer::tag('div', $commenteditor, array('class' => 'felement fhtmleditor')),
                 array('class' => 'fitem'));
 
         $mark = '';
index 24001a9..061d449 100644 (file)
@@ -189,8 +189,8 @@ class qtype_essay_format_editor_renderer extends plugin_renderer_base {
     }
 
     public function response_area_input($name, $qa, $step, $lines, $context) {
-        global $CFG, $PAGE;
-        require_once($CFG->dirroot.'/repository/lib.php');
+        global $CFG;
+        require_once($CFG->dirroot . '/repository/lib.php');
 
         $inputname = $qa->get_qt_field_name($name);
         $responseformat = $step->get_qt_var($name . 'format');