From 735280b159f77332f2170b2da66a5c6ed497ea58 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Tue, 31 Jul 2012 17:40:06 +0800 Subject: [PATCH] MDL-34570 accessibility compliance for question: edit string label --- question/behaviour/rendererbase.php | 3 ++- question/format/xhtml/format.php | 9 ++++++--- question/format/xhtml/lang/en/qformat_xhtml.php | 1 + question/type/calculated/lang/en/qtype_calculated.php | 2 ++ question/type/calculated/questiontype.php | 6 ++++-- question/type/essay/lang/en/qtype_essay.php | 1 + question/type/essay/renderer.php | 3 ++- question/type/match/lang/en/qtype_match.php | 1 + question/type/match/renderer.php | 1 + question/type/multianswer/renderer.php | 6 +++--- question/type/numerical/renderer.php | 7 +++++-- question/type/shortanswer/renderer.php | 4 ++-- 12 files changed, 30 insertions(+), 14 deletions(-) diff --git a/question/behaviour/rendererbase.php b/question/behaviour/rendererbase.php index adf93634c3e..78de4dba79f 100644 --- a/question/behaviour/rendererbase.php +++ b/question/behaviour/rendererbase.php @@ -88,12 +88,13 @@ abstract class qbehaviour_renderer extends plugin_renderer_base { array('id' => $id, 'name' => $inputname, 'rows' => 10, 'cols' => 60))); $commenteditor .= html_writer::start_tag('div'); - if (count($formats == 1)) { + 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::label(get_string('formattexttype'), 'menu' . $inputname . 'format', false, array('class' => 'accesshide')); $commenteditor .= html_writer::select( $formats, $inputname . 'format', $commentformat, ''); } diff --git a/question/format/xhtml/format.php b/question/format/xhtml/format.php index 0b70c45010d..a289ae6d5ac 100644 --- a/question/format/xhtml/format.php +++ b/question/format/xhtml/format.php @@ -95,12 +95,14 @@ class qformat_xhtml extends qformat_default { break; case SHORTANSWER: $expout .= "\n"; break; case NUMERICAL: $expout .= "\n"; break; case MATCH: @@ -114,7 +116,8 @@ class qformat_xhtml extends qformat_default { shuffle( $ans_list ); // random display order // build drop down for answers - $dropdown = "\n"; foreach($ans_list as $ans) { $dropdown .= "\n"; } diff --git a/question/format/xhtml/lang/en/qformat_xhtml.php b/question/format/xhtml/lang/en/qformat_xhtml.php index e5492eb94aa..ddbadfce123 100644 --- a/question/format/xhtml/lang/en/qformat_xhtml.php +++ b/question/format/xhtml/lang/en/qformat_xhtml.php @@ -26,3 +26,4 @@ $string['pluginname'] = 'XHTML format'; $string['pluginname_help'] = 'XHTML format enables all questions in the category to be exported to a single page of strict XHTML for possible use in another application.'; $string['pluginname_link'] = 'qformat/xhtml'; +$string['selectansweroption'] = 'Select answer option'; diff --git a/question/type/calculated/lang/en/qtype_calculated.php b/question/type/calculated/lang/en/qtype_calculated.php index 36e2d1d25e3..a27d9bea6e7 100644 --- a/question/type/calculated/lang/en/qtype_calculated.php +++ b/question/type/calculated/lang/en/qtype_calculated.php @@ -49,6 +49,7 @@ $string['datasetrole']= ' The wild cards {x..} will be substitu $string['decimals'] = 'with {$a}'; $string['deleteitem'] = 'Delete item'; $string['deletelastitem'] = 'Delete last item'; +$string['distributionoption'] = 'Select distribution option'; $string['editdatasets'] = 'Edit the wildcards datasets'; $string['editdatasets_help'] = 'Wildcard values may be created by entering a number in each wild card field then clicking the add button. To automatically generate 10 or more values, select the number of values required before clicking the add button. A uniform distribution means any value between the limits is equally likely to be generated; a loguniform distribution means that values towards the lower limit are more likely.'; $string['editdatasets_link'] = 'question/type/calculated'; @@ -79,6 +80,7 @@ $string['keptlocal1'] = 'will use the same existing private dataset as before'; $string['keptlocal2'] = 'a file from the same question private set of files as before'; $string['keptlocal3'] = 'a link from the same question private set of links as before'; $string['lastitem(s)'] = 'last items(s)'; +$string['lengthoption'] = 'Select length option'; $string['loguniform'] = 'Loguniform'; $string['loguniformbit'] = 'digits, from a loguniform distribution'; $string['makecopynextpage'] = 'Next page (new question)'; diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index ae0dd0d2a5f..32c815f4e46 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -749,11 +749,13 @@ class qtype_calculated extends question_type { ? 'decimals' : 'significantfigures'), 'qtype_calculated', $i); } - $menu1 = html_writer::select($lengthoptions, 'calclength[]', $regs[4], null); + $menu1 = html_writer::label(get_string('lengthoption', 'qtype_calculated'), 'menucalclength', false, array('class' => 'accesshide')); + $menu1 .= html_writer::select($lengthoptions, 'calclength[]', $regs[4], null); $options = array('uniform' => get_string('uniformbit', 'qtype_calculated'), 'loguniform' => get_string('loguniformbit', 'qtype_calculated')); - $menu2 = html_writer::select($options, 'calcdistribution[]', $regs[1], null); + $menu2 = html_writer::label(get_string('distributionoption', 'qtype_calculated'), 'menucalcdistribution', false, array('class' => 'accesshide')); + $menu2 .= html_writer::select($options, 'calcdistribution[]', $regs[1], null); return '
' diff --git a/question/type/essay/lang/en/qtype_essay.php b/question/type/essay/lang/en/qtype_essay.php index 2e8d524ca45..735a968b389 100644 --- a/question/type/essay/lang/en/qtype_essay.php +++ b/question/type/essay/lang/en/qtype_essay.php @@ -38,3 +38,4 @@ $string['pluginnameediting'] = 'Editing an Essay question'; $string['pluginnamesummary'] = 'Allows a response of a few sentences or paragraphs. This must then be graded manually.'; $string['responsefieldlines'] = 'Input box size'; $string['responseformat'] = 'Response format'; +$string['selectanswerformat'] = 'Select answer format'; diff --git a/question/type/essay/renderer.php b/question/type/essay/renderer.php index 061d4492de1..8b44811a5ea 100644 --- a/question/type/essay/renderer.php +++ b/question/type/essay/renderer.php @@ -217,12 +217,13 @@ class qtype_essay_format_editor_renderer extends plugin_renderer_base { array('id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60))); $output .= html_writer::start_tag('div'); - if (count($formats == 1)) { + if (count($formats) == 1) { reset($formats); $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $inputname . 'format', 'value' => key($formats))); } else { + $output .= html_writer::label(get_string('selectanswerformat'), 'menu' . $inputname . 'format', false, array("class" => 'accesshide')); $output .= html_writer::select($formats, $inputname . 'format', $responseformat, ''); } $output .= html_writer::end_tag('div'); diff --git a/question/type/match/lang/en/qtype_match.php b/question/type/match/lang/en/qtype_match.php index a096607bbc8..4b7bc71cc1c 100644 --- a/question/type/match/lang/en/qtype_match.php +++ b/question/type/match/lang/en/qtype_match.php @@ -40,3 +40,4 @@ $string['pluginname_link'] = 'question/type/match'; $string['pluginnameadding'] = 'Adding a Matching question'; $string['pluginnameediting'] = 'Editing a Matching question'; $string['pluginnamesummary'] = 'The answer to each of a number of sub-question must be selected from a list of possibilities.'; +$string['selectananswer'] = 'Select an answer'; diff --git a/question/type/match/renderer.php b/question/type/match/renderer.php index 8a3372c8433..0a464ef04a5 100644 --- a/question/type/match/renderer.php +++ b/question/type/match/renderer.php @@ -80,6 +80,7 @@ class qtype_match_renderer extends qtype_with_combined_feedback_renderer { } $result .= html_writer::tag('td', + html_writer::label(get_string('selectananswer', 'qtype_match'), 'menu' . $qa->get_qt_field_name('sub' . $key), false, array('class' => 'accesshide')) . html_writer::select($choices, $qa->get_qt_field_name('sub' . $key), $selected, array('0' => 'choose'), array('disabled' => $options->readonly)) . ' ' . $feedbackimage, array('class' => $classes)); diff --git a/question/type/multianswer/renderer.php b/question/type/multianswer/renderer.php index 29c23d68560..992cccd69d3 100644 --- a/question/type/multianswer/renderer.php +++ b/question/type/multianswer/renderer.php @@ -223,7 +223,7 @@ class qtype_multianswer_textfield_renderer extends qtype_multianswer_subq_render s($correctanswer->answer), $options); $output = ''; - $output .= html_writer::start_tag('label', array('class' => 'subq')); + $output .= html_writer::start_tag('label', array('class' => 'subq', 'for' => $inputattributes['id'])); $output .= html_writer::empty_tag('input', $inputattributes); $output .= $feedbackimg; $output .= $feedbackpopup; @@ -274,8 +274,8 @@ class qtype_multianswer_multichoice_inline_renderer $inputattributes['class'] = $this->feedback_class($matchinganswer->fraction); $feedbackimg = $this->feedback_image($matchinganswer->fraction); } - - $select = html_writer::select($choices, $qa->get_qt_field_name($fieldname), + $select = html_writer::label($response, $inputattributes['id'], false, array('class' => 'accesshide')); + $select .= html_writer::select($choices, $qa->get_qt_field_name($fieldname), $response, array('' => ''), $inputattributes); $order = $subq->get_order($qa); diff --git a/question/type/numerical/renderer.php b/question/type/numerical/renderer.php index 7689a2c9b21..2486740636d 100644 --- a/question/type/numerical/renderer.php +++ b/question/type/numerical/renderer.php @@ -76,7 +76,8 @@ class qtype_numerical_renderer extends qtype_renderer { $inputattributes['size'] = round(strlen($placeholder) * 1.1); } - $input = html_writer::empty_tag('input', $inputattributes) . $feedbackimg; + $input = html_writer::label($inputattributes['name'], $inputattributes['id'], false, array('class' => 'accesshide')); + $input .= html_writer::empty_tag('input', $inputattributes) . $feedbackimg; if ($question->has_separate_unit_field()) { if ($question->unitdisplay == qtype_numerical::UNITRADIO) { @@ -98,7 +99,9 @@ class qtype_numerical_renderer extends qtype_renderer { array('class' => 'unitchoices')); } else if ($question->unitdisplay == qtype_numerical::UNITSELECT) { - $unitchoice = html_writer::select($question->ap->get_unit_options(), + $unitchoice = html_writer::label(get_string('selectunits', 'qtype_numerical'), + 'menu' . $qa->get_qt_field_name('unit'), false, array('class' => 'accesshide')); + $unitchoice .= html_writer::select($question->ap->get_unit_options(), $qa->get_qt_field_name('unit'), $selectedunit, array(''=>'choosedots'), array('disabled' => $options->readonly)); } diff --git a/question/type/shortanswer/renderer.php b/question/type/shortanswer/renderer.php index e7879bfb680..0595b57e5e2 100644 --- a/question/type/shortanswer/renderer.php +++ b/question/type/shortanswer/renderer.php @@ -71,8 +71,8 @@ class qtype_shortanswer_renderer extends qtype_renderer { $placeholder = $matches[0]; $inputattributes['size'] = round(strlen($placeholder) * 1.1); } - - $input = html_writer::empty_tag('input', $inputattributes) . $feedbackimg; + $input = html_writer::label($inputattributes['name'], $inputattributes['id'], false, array('class' => 'accesshide')); + $input .= html_writer::empty_tag('input', $inputattributes) . $feedbackimg; if ($placeholder) { $questiontext = substr_replace($questiontext, $input,