From 2d6829727dc47ca0550c9bcb2413d3330e99099a Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Sat, 18 Jun 2011 20:40:02 +0100 Subject: [PATCH] MDL-24255 Use the proper editor element for manual grading comments. It would be nice if someone imporoved the API for using the HTML editor outside formslib. --- question/behaviour/rendererbase.php | 38 +++++++++++++++++++++++------ question/type/essay/renderer.php | 4 +-- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/question/behaviour/rendererbase.php b/question/behaviour/rendererbase.php index c8d64794a76..adf93634c3e 100644 --- a/question/behaviour/rendererbase.php +++ b/question/behaviour/rendererbase.php @@ -69,16 +69,40 @@ abstract class qbehaviour_renderer extends plugin_renderer_base { } public function manual_comment_fields(question_attempt $qa, question_display_options $options) { - - $commentfield = $qa->get_behaviour_field_name('comment'); - + $inputname = $qa->get_behaviour_field_name('comment'); + $id = $inputname . '_id'; list($commenttext, $commentformat) = $qa->get_manual_comment(); - $comment = print_textarea(can_use_html_editor(), 10, 80, null, null, - $commentfield, $commenttext, 0, true); + + $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'); + $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 = ''; diff --git a/question/type/essay/renderer.php b/question/type/essay/renderer.php index 24001a99175..061d4492de1 100644 --- a/question/type/essay/renderer.php +++ b/question/type/essay/renderer.php @@ -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');