Skip to content

Commit

Permalink
MDL-24255 Use the proper editor element for manual grading comments.
Browse files Browse the repository at this point in the history
It would be nice if someone imporoved the API for using the HTML editor outside formslib.
  • Loading branch information
timhunt committed Jun 18, 2011
1 parent 7a7d34f commit 2d68297
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
36 changes: 30 additions & 6 deletions question/behaviour/rendererbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,40 @@ public function feedback(question_attempt $qa, question_display_options $options
}

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 = '';
Expand Down
4 changes: 2 additions & 2 deletions question/type/essay/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ public function response_area_read_only($name, $qa, $step, $lines, $context) {
}

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');
Expand Down

0 comments on commit 2d68297

Please sign in to comment.