From 83690170be379e8819e194bdbfede4a5dc899ac8 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Tue, 31 Jul 2012 17:40:06 +0800 Subject: [PATCH 1/3] 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 adf93634c3e91..78de4dba79fc1 100644 --- a/question/behaviour/rendererbase.php +++ b/question/behaviour/rendererbase.php @@ -88,12 +88,13 @@ public function manual_comment_fields(question_attempt $qa, question_display_opt 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 6110d2761822b..81b2f2354ad61 100644 --- a/question/format/xhtml/format.php +++ b/question/format/xhtml/format.php @@ -95,12 +95,14 @@ protected function writequestion($question) { break; case 'shortanswer': $expout .= "\n"; break; case 'numerical': $expout .= "\n"; break; case 'match': @@ -114,7 +116,8 @@ protected function writequestion($question) { 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 e5492eb94aaa3..ddbadfce123fb 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 36e2d1d25e3f1..a27d9bea6e746 100644 --- a/question/type/calculated/lang/en/qtype_calculated.php +++ b/question/type/calculated/lang/en/qtype_calculated.php @@ -49,6 +49,7 @@ $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['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 2ffb7d5f8b62a..cc1b773e56de6 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -751,11 +751,13 @@ public function custom_generator_tools($datasetdef) { ? '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 2e8d524ca45f8..735a968b389f8 100644 --- a/question/type/essay/lang/en/qtype_essay.php +++ b/question/type/essay/lang/en/qtype_essay.php @@ -38,3 +38,4 @@ $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 ac2bac96c8fc4..a189b2426cdfb 100644 --- a/question/type/essay/renderer.php +++ b/question/type/essay/renderer.php @@ -219,12 +219,13 @@ public function response_area_input($name, $qa, $step, $lines, $context) { 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 a096607bbc8f7..4b7bc71cc1cbb 100644 --- a/question/type/match/lang/en/qtype_match.php +++ b/question/type/match/lang/en/qtype_match.php @@ -40,3 +40,4 @@ $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 8a3372c843331..0a464ef04a520 100644 --- a/question/type/match/renderer.php +++ b/question/type/match/renderer.php @@ -80,6 +80,7 @@ public function formulation_and_controls(question_attempt $qa, } $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 547a370dc7631..b4c0650f0248b 100644 --- a/question/type/multianswer/renderer.php +++ b/question/type/multianswer/renderer.php @@ -223,7 +223,7 @@ public function subquestion(question_attempt $qa, question_display_options $opti 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 @@ public function subquestion(question_attempt $qa, question_display_options $opti $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 7689a2c9b218b..2486740636d65 100644 --- a/question/type/numerical/renderer.php +++ b/question/type/numerical/renderer.php @@ -76,7 +76,8 @@ public function formulation_and_controls(question_attempt $qa, $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 @@ public function formulation_and_controls(question_attempt $qa, 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 e7879bfb68039..0595b57e5e26f 100644 --- a/question/type/shortanswer/renderer.php +++ b/question/type/shortanswer/renderer.php @@ -71,8 +71,8 @@ public function formulation_and_controls(question_attempt $qa, $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, From c3cdf1e4cb773e06b129232af15b235b2da46f75 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Thu, 23 Aug 2012 15:54:39 +0800 Subject: [PATCH 2/3] MDL-34570 Accessibility: Adding labels on text inputs and selects to questions --- question/behaviour/rendererbase.php | 20 +++++++++++------- question/format/xhtml/format.php | 21 +++++++++++-------- .../format/xhtml/lang/en/qformat_xhtml.php | 1 - question/type/essay/lang/en/qtype_essay.php | 1 - question/type/essay/renderer.php | 3 ++- question/type/match/lang/en/qtype_match.php | 2 +- question/type/match/renderer.php | 4 +++- question/type/multianswer/renderer.php | 11 +++++----- .../numerical/lang/en/qtype_numerical.php | 1 + question/type/numerical/renderer.php | 14 +++++++------ question/type/shortanswer/renderer.php | 13 +++++++----- 11 files changed, 53 insertions(+), 38 deletions(-) diff --git a/question/behaviour/rendererbase.php b/question/behaviour/rendererbase.php index 78de4dba79fc1..e04a638c1f0c9 100644 --- a/question/behaviour/rendererbase.php +++ b/question/behaviour/rendererbase.php @@ -86,25 +86,30 @@ public function manual_comment_fields(question_attempt $qa, question_display_opt $commenteditor = html_writer::tag('div', html_writer::tag('textarea', s($commenttext), array('id' => $id, 'name' => $inputname, 'rows' => 10, 'cols' => 60))); + $commenteditor .= html_writer::end_tag('div'); - $commenteditor .= html_writer::start_tag('div'); + $editorformat = ''; if (count($formats) == 1) { reset($formats); - $commenteditor .= html_writer::empty_tag('input', array('type' => 'hidden', + $editorformat .= 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, ''); + $editorformat = html_writer::start_tag('div', array('class' => 'fitem')); + $editorformat .= html_writer::start_tag('div', array('class' => 'fitemtitle')); + $editorformat .= html_writer::tag('label', get_string('format'), array('for'=>'menu'.$inputname.'format')); + $editorformat .= html_writer::end_tag('div'); + $editorformat .= html_writer::start_tag('div', array('class' => 'felement fhtmleditor')); + $editorformat .= html_writer::select($formats, $inputname.'format', $commentformat, ''); + $editorformat .= html_writer::end_tag('div'); + $editorformat .= html_writer::end_tag('div'); } - $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' => $id)), array('class' => 'fitemtitle')) . html_writer::tag('div', $commenteditor, array('class' => 'felement fhtmleditor')), array('class' => 'fitem')); + $comment .= $editorformat; $mark = ''; if ($qa->get_max_mark()) { @@ -118,6 +123,7 @@ public function manual_comment_fields(question_attempt $qa, question_display_opt 'type' => 'text', 'size' => $fieldsize, 'name' => $markfield, + 'id'=> $markfield ); if (!is_null($currentmark)) { $attributes['value'] = $qa->format_fraction_as_mark( diff --git a/question/format/xhtml/format.php b/question/format/xhtml/format.php index 81b2f2354ad61..a7581e36200e8 100644 --- a/question/format/xhtml/format.php +++ b/question/format/xhtml/format.php @@ -115,19 +115,22 @@ protected function writequestion($question) { } shuffle( $ans_list ); // random display order - // build drop down for answers - $dropdown = html_writer::label(get_string('selectansweroption'), 'quest_'.$id, false, array('class' => 'accesshide')); - $dropdown .= "\n"; - // finally display + // display + $option = 0; foreach($question->options->subquestions as $subquestion) { - $quest_text = $this->repchar( $subquestion->questiontext ); - $expout .= "
  • $quest_text
  • \n"; - $expout .= $dropdown; + // build drop down for answers + $quest_text = $this->repchar( $subquestion->questiontext ); + $dropdown = html_writer::label(get_string('answer', 'qtype_match', $option+1), 'quest_'.$id.'_'.$option, false, array('class' => 'accesshide')); + $dropdown .= "\n"; + $expout .= "
  • $quest_text
  • \n"; + $expout .= $dropdown; + $option++; } $expout .= "\n"; break; diff --git a/question/format/xhtml/lang/en/qformat_xhtml.php b/question/format/xhtml/lang/en/qformat_xhtml.php index ddbadfce123fb..e5492eb94aaa3 100644 --- a/question/format/xhtml/lang/en/qformat_xhtml.php +++ b/question/format/xhtml/lang/en/qformat_xhtml.php @@ -26,4 +26,3 @@ $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/essay/lang/en/qtype_essay.php b/question/type/essay/lang/en/qtype_essay.php index 735a968b389f8..2e8d524ca45f8 100644 --- a/question/type/essay/lang/en/qtype_essay.php +++ b/question/type/essay/lang/en/qtype_essay.php @@ -38,4 +38,3 @@ $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 a189b2426cdfb..1905e2ecd5ca0 100644 --- a/question/type/essay/renderer.php +++ b/question/type/essay/renderer.php @@ -225,7 +225,8 @@ public function response_area_input($name, $qa, $step, $lines, $context) { 'name' => $inputname . 'format', 'value' => key($formats))); } else { - $output .= html_writer::label(get_string('selectanswerformat'), 'menu' . $inputname . 'format', false, array("class" => 'accesshide')); + $output .= html_writer::label(get_string('format'), 'menu' . $inputname . 'format', false); + $output .= ' '; $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 4b7bc71cc1cbb..5dd3c4ad3297c 100644 --- a/question/type/match/lang/en/qtype_match.php +++ b/question/type/match/lang/en/qtype_match.php @@ -24,6 +24,7 @@ */ $string['addmoreqblanks'] = '{no} More Sets of Blanks'; +$string['answer'] = 'Answer {$a}'; $string['availablechoices'] = 'Available choices'; $string['correctansweris'] = 'The correct answer is: {$a}'; $string['filloutthreeqsandtwoas'] = 'You must provide at least two questions and three answers. You can provide extra wrong answers by giving an answer with a blank question. Entries where both the question and the answer are blank will be ignored.'; @@ -40,4 +41,3 @@ $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 0a464ef04a520..2cadb7ef93c5f 100644 --- a/question/type/match/renderer.php +++ b/question/type/match/renderer.php @@ -53,6 +53,7 @@ public function formulation_and_controls(question_attempt $qa, $result .= html_writer::start_tag('tbody'); $parity = 0; + $i = 1; foreach ($stemorder as $key => $stemid) { $result .= html_writer::start_tag('tr', array('class' => 'r' . $parity)); @@ -80,13 +81,14 @@ public function formulation_and_controls(question_attempt $qa, } $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::label(get_string('answer', 'qtype_match', $i), '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)); $result .= html_writer::end_tag('tr'); $parity = 1 - $parity; + $i++; } $result .= html_writer::end_tag('tbody'); $result .= html_writer::end_tag('table'); diff --git a/question/type/multianswer/renderer.php b/question/type/multianswer/renderer.php index b4c0650f0248b..86d5646f06c00 100644 --- a/question/type/multianswer/renderer.php +++ b/question/type/multianswer/renderer.php @@ -223,11 +223,11 @@ public function subquestion(question_attempt $qa, question_display_options $opti s($correctanswer->answer), $options); $output = ''; - $output .= html_writer::start_tag('label', array('class' => 'subq', 'for' => $inputattributes['id'])); + $output .= html_writer::tag('label', get_string('answer'), + array('class' => 'subq accesshide', 'for' => $inputattributes['id'])); $output .= html_writer::empty_tag('input', $inputattributes); $output .= $feedbackimg; $output .= $feedbackpopup; - $output .= html_writer::end_tag('label'); return $output; } @@ -274,8 +274,7 @@ public function subquestion(question_attempt $qa, question_display_options $opti $inputattributes['class'] = $this->feedback_class($matchinganswer->fraction); $feedbackimg = $this->feedback_image($matchinganswer->fraction); } - $select = html_writer::label($response, $inputattributes['id'], false, array('class' => 'accesshide')); - $select .= html_writer::select($choices, $qa->get_qt_field_name($fieldname), + $select = html_writer::select($choices, $qa->get_qt_field_name($fieldname), $response, array('' => ''), $inputattributes); $order = $subq->get_order($qa); @@ -288,11 +287,11 @@ public function subquestion(question_attempt $qa, question_display_options $opti $qa, 'question', 'answer', $rightanswer->id), $options); $output = ''; - $output .= html_writer::start_tag('label', array('class' => 'subq')); + $output .= html_writer::tag('label', get_string('answer'), + array('class' => 'subq accesshide', 'for' => $inputattributes['id'])); $output .= $select; $output .= $feedbackimg; $output .= $feedbackpopup; - $output .= html_writer::end_tag('label'); return $output; } diff --git a/question/type/numerical/lang/en/qtype_numerical.php b/question/type/numerical/lang/en/qtype_numerical.php index 75dc4570c0504..fb4784b6c7718 100644 --- a/question/type/numerical/lang/en/qtype_numerical.php +++ b/question/type/numerical/lang/en/qtype_numerical.php @@ -26,6 +26,7 @@ $string['acceptederror'] = 'Accepted error'; $string['addmoreanswerblanks'] = 'Blanks for {no} More Answers'; $string['addmoreunitblanks'] = 'Blanks for {no} More Units'; +$string['answercolon'] = 'Answer:'; $string['answermustbenumberorstar'] = 'The answer must be a number, for example -1.234 or 3e8, or \'*\'.'; $string['answerno'] = 'Answer {$a}'; $string['decfractionofquestiongrade'] = 'as a fraction (0-1) of the question grade'; diff --git a/question/type/numerical/renderer.php b/question/type/numerical/renderer.php index 2486740636d65..d1b7c0ad30cad 100644 --- a/question/type/numerical/renderer.php +++ b/question/type/numerical/renderer.php @@ -76,8 +76,7 @@ public function formulation_and_controls(question_attempt $qa, $inputattributes['size'] = round(strlen($placeholder) * 1.1); } - $input = html_writer::label($inputattributes['name'], $inputattributes['id'], false, array('class' => 'accesshide')); - $input .= html_writer::empty_tag('input', $inputattributes) . $feedbackimg; + $input = html_writer::empty_tag('input', $inputattributes) . $feedbackimg; if ($question->has_separate_unit_field()) { if ($question->unitdisplay == qtype_numerical::UNITRADIO) { @@ -99,7 +98,7 @@ public function formulation_and_controls(question_attempt $qa, array('class' => 'unitchoices')); } else if ($question->unitdisplay == qtype_numerical::UNITSELECT) { - $unitchoice = html_writer::label(get_string('selectunits', 'qtype_numerical'), + $unitchoice = html_writer::label(get_string('selectunit', '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'), @@ -114,7 +113,10 @@ public function formulation_and_controls(question_attempt $qa, } if ($placeholder) { - $questiontext = substr_replace($questiontext, $input, + $inputinplace = html_writer::tag('label', get_string('answer'), + array('for' => $inputattributes['id'], 'class' => 'accesshide')); + $inputinplace .= $input; + $questiontext = substr_replace($questiontext, $inputinplace, strpos($questiontext, $placeholder), strlen($placeholder)); } @@ -122,8 +124,8 @@ public function formulation_and_controls(question_attempt $qa, if (!$placeholder) { $result .= html_writer::start_tag('div', array('class' => 'ablock')); - $result .= get_string('answer', 'qtype_shortanswer', - html_writer::tag('div', $input, array('class' => 'answer'))); + $result .= html_writer::tag('label', get_string('answercolon', 'qtype_numerical'), array('for' => $inputattributes['id'])); + $result .= html_writer::tag('span', $input, array('class' => 'answer')); $result .= html_writer::end_tag('div'); } diff --git a/question/type/shortanswer/renderer.php b/question/type/shortanswer/renderer.php index 0595b57e5e26f..cfdca17d8265c 100644 --- a/question/type/shortanswer/renderer.php +++ b/question/type/shortanswer/renderer.php @@ -71,11 +71,13 @@ public function formulation_and_controls(question_attempt $qa, $placeholder = $matches[0]; $inputattributes['size'] = round(strlen($placeholder) * 1.1); } - $input = html_writer::label($inputattributes['name'], $inputattributes['id'], false, array('class' => 'accesshide')); - $input .= html_writer::empty_tag('input', $inputattributes) . $feedbackimg; + $input = html_writer::empty_tag('input', $inputattributes) . $feedbackimg; if ($placeholder) { - $questiontext = substr_replace($questiontext, $input, + $inputinplace = html_writer::tag('label', get_string('answer'), + array('for' => $inputattributes['id'], 'class' => 'accesshide')); + $inputinplace .= $input; + $questiontext = substr_replace($questiontext, $inputinplace, strpos($questiontext, $placeholder), strlen($placeholder)); } @@ -83,8 +85,9 @@ public function formulation_and_controls(question_attempt $qa, if (!$placeholder) { $result .= html_writer::start_tag('div', array('class' => 'ablock')); - $result .= get_string('answer', 'qtype_shortanswer', - html_writer::tag('div', $input, array('class' => 'answer'))); + $result .= html_writer::tag('label', get_string('answer', 'qtype_shortanswer', + html_writer::tag('span', $input, array('class' => 'answer'))), + array('for' => $inputattributes['id'])); $result .= html_writer::end_tag('div'); } From b825e6c613eb3251bda470518804eabd49d5c552 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 12 Sep 2012 16:24:27 +0800 Subject: [PATCH 3/3] MDL-35171 Question: Export to HTML uses more of html_writer --- question/format/xhtml/format.php | 38 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/question/format/xhtml/format.php b/question/format/xhtml/format.php index a7581e36200e8..7b3d9b657c4ec 100644 --- a/question/format/xhtml/format.php +++ b/question/format/xhtml/format.php @@ -93,20 +93,24 @@ protected function writequestion($question) { } $expout .= "\n"; break; - case 'shortanswer': - $expout .= "
      \n"; - $expout .= "
    • " . html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide')); - $expout .= "
    • \n"; - $expout .= "
    \n"; + case SHORTANSWER: + $expout .= html_writer::start_tag('ul', array('class' => 'shortanswer')); + $expout .= html_writer::start_tag('li'); + $expout .= html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide')); + $expout .= html_writer::empty_tag('input', array('id' => "quest_$id", 'name' => "quest_$id", 'type' => 'text')); + $expout .= html_writer::end_tag('li'); + $expout .= html_writer::end_tag('ul'); break; - case 'numerical': - $expout .= "
      \n"; - $expout .= "
    • " . html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide')); - $expout .= "
    • \n"; - $expout .= "
    \n"; + case NUMERICAL: + $expout .= html_writer::start_tag('ul', array('class' => 'numerical')); + $expout .= html_writer::start_tag('li'); + $expout .= html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide')); + $expout .= html_writer::empty_tag('input', array('id' => "quest_$id", 'name' => "quest_$id", 'type' => 'text')); + $expout .= html_writer::end_tag('li'); + $expout .= html_writer::end_tag('ul'); break; - case 'match': - $expout .= "
      \n"; + case MATCH: + $expout .= html_writer::start_tag('ul', array('class' => 'match')); // build answer list $ans_list = array(); @@ -116,9 +120,9 @@ protected function writequestion($question) { shuffle( $ans_list ); // random display order // Build select options. - $selectoptions = ''; + $selectoptions = array(); foreach($ans_list as $ans) { - $selectoptions .= "\n"; + $selectoptions[s($ans)] = s($ans); } // display @@ -127,12 +131,12 @@ protected function writequestion($question) { // build drop down for answers $quest_text = $this->repchar( $subquestion->questiontext ); $dropdown = html_writer::label(get_string('answer', 'qtype_match', $option+1), 'quest_'.$id.'_'.$option, false, array('class' => 'accesshide')); - $dropdown .= "\n"; - $expout .= "
    • $quest_text
    • \n"; + $dropdown .= html_writer::select($selectoptions, "quest_{$id}_{$option}", '', false, array('id' => "quest_{$id}_{$option}")); + $expout .= html_writer::tag('li', $quest_text);; $expout .= $dropdown; $option++; } - $expout .= "
    \n"; + $expout .= html_writer::end_tag('ul'); break; case 'description': break;