Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDL-71602 qtype_essay: label essay question's answer area
  • Loading branch information
rezaies committed Aug 23, 2021
1 parent 65b6e86 commit 6227246
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
2 changes: 2 additions & 0 deletions question/type/essay/lang/en/qtype_essay.php
Expand Up @@ -26,6 +26,8 @@
$string['acceptedfiletypes'] = 'Accepted file types';
$string['acceptedfiletypes_help'] = 'Accepted file types can be restricted by entering a list of file extensions. If the field is left empty, then all file types are allowed.';
$string['allowattachments'] = 'Allow attachments';
$string['answerfiles'] = 'Answer files';
$string['answertext'] = 'Answer text';
$string['attachedfiles'] = 'Attachments: {$a}';
$string['attachmentsoptional'] = 'Attachments are optional';
$string['attachmentsrequired'] = 'Require attachments';
Expand Down
71 changes: 55 additions & 16 deletions question/type/essay/renderer.php
Expand Up @@ -87,14 +87,23 @@ public function formulation_and_controls(question_attempt $qa,
*/
public function files_read_only(question_attempt $qa, question_display_options $options) {
$files = $qa->get_last_qt_files('attachments', $options->context->id);
$output = array();
$filelist = [];

foreach ($files as $file) {
$output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file),
$this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),
'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename())));
$out = html_writer::link($qa->get_response_file_url($file),
$this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),
'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename()));
$filelist[] = html_writer::tag('li', $out, ['class' => 'mb-2']);
}
return implode($output);

$labelbyid = $qa->get_qt_field_name('attachments') . '_label';

$output = html_writer::tag('h4', get_string('answerfiles', 'qtype_essay'), ['id' => $labelbyid, 'class' => 'sr-only']);
$output .= html_writer::tag('ul', implode($filelist), [
'aria-labelledby' => $labelbyid,
'class' => 'list-unstyled m-0',
]);
return $output;
}

/**
Expand Down Expand Up @@ -138,9 +147,19 @@ public function files_input(question_attempt $qa, $numallowed,
$filetypedescriptions = $filetypesutil->describe_file_types($filetypes);
$text .= $this->render_from_template('core_form/filetypes-descriptions', $filetypedescriptions);
}
return $filesrenderer->render($fm). html_writer::empty_tag(
'input', array('type' => 'hidden', 'name' => $qa->get_qt_field_name('attachments'),
'value' => $pickeroptions->itemid)) . $text;

$output = html_writer::start_tag('fieldset');
$output .= html_writer::tag('legend', get_string('answerfiles', 'qtype_essay'), ['class' => 'sr-only']);
$output .= $filesrenderer->render($fm);
$output .= html_writer::empty_tag('input', [
'type' => 'hidden',
'name' => $qa->get_qt_field_name('attachments'),
'value' => $pickeroptions->itemid,
]);
$output .= $text;
$output .= html_writer::end_tag('fieldset');

return $output;
}

public function manual_comment(question_attempt $qa, question_display_options $options) {
Expand Down Expand Up @@ -230,11 +249,20 @@ protected function class_name() {
}

public function response_area_read_only($name, $qa, $step, $lines, $context) {
return html_writer::tag('div', $this->prepare_response($name, $qa, $step, $context),
['class' => $this->class_name() . ' qtype_essay_response readonly',
'style' => 'min-height: ' . ($lines * 1.5) . 'em;']);
$labelbyid = $qa->get_qt_field_name($name) . '_label';

$output = html_writer::tag('h4', get_string('answertext', 'qtype_essay'), ['id' => $labelbyid, 'class' => 'sr-only']);
$output .= html_writer::tag('div', $this->prepare_response($name, $qa, $step, $context), [
'role' => 'textbox',
'aria-readonly' => 'true',
'aria-labelledby' => $labelbyid,
'class' => $this->class_name() . ' qtype_essay_response readonly',
'style' => 'min-height: ' . ($lines * 1.5) . 'em;',
]);
// Height $lines * 1.5 because that is a typical line-height on web pages.
// That seems to give results that look OK.

return $output;
}

public function response_area_input($name, $qa, $step, $lines, $context) {
Expand All @@ -259,7 +287,10 @@ public function response_area_input($name, $qa, $step, $lines, $context) {
$editor->use_editor($id, $this->get_editor_options($context),
$this->get_filepicker_options($context, $draftitemid));

$output = '';
$output = html_writer::tag('label', get_string('answertext', 'qtype_essay'), [
'class' => 'sr-only',
'for' => $id,
]);
$output .= html_writer::start_tag('div', array('class' =>
$this->class_name() . ' qtype_essay_response'));

Expand Down Expand Up @@ -466,14 +497,22 @@ protected function class_name() {
}

public function response_area_read_only($name, $qa, $step, $lines, $context) {
return $this->textarea($step->get_qt_var($name), $lines, array('readonly' => 'readonly'));
$id = $qa->get_qt_field_name($name) . '_id';

$output = html_writer::tag('label', get_string('answertext', 'qtype_essay'), ['class' => 'sr-only', 'for' => $id]);
$output .= $this->textarea($step->get_qt_var($name), $lines, ['id' => $id, 'readonly' => 'readonly']);
return $output;
}

public function response_area_input($name, $qa, $step, $lines, $context) {
$inputname = $qa->get_qt_field_name($name);
return $this->textarea($step->get_qt_var($name), $lines, array('name' => $inputname)) .
html_writer::empty_tag('input', array('type' => 'hidden',
'name' => $inputname . 'format', 'value' => FORMAT_PLAIN));
$id = $inputname . '_id';

$output = html_writer::tag('label', get_string('answertext', 'qtype_essay'), ['class' => 'sr-only', 'for' => $id]);
$output .= $this->textarea($step->get_qt_var($name), $lines, ['name' => $inputname, 'id' => $id]);
$output .= html_writer::empty_tag('input', ['type' => 'hidden', 'name' => $inputname . 'format', 'value' => FORMAT_PLAIN]);

return $output;
}
}

Expand Down

0 comments on commit 6227246

Please sign in to comment.