From d2d17341e8eff08767cc7dd4e830d0855433487a Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Fri, 19 Oct 2012 13:21:03 +0800 Subject: [PATCH] MDL-21625 Question bank: Add accessibility to table layout for viewing question list --- mod/quiz/editlib.php | 9 +++++++ question/editlib.php | 58 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index 6d16aa752d2..f64e28203d2 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -1138,6 +1138,15 @@ class quiz_question_bank_view extends question_bank_view { 'editaction', 'previewaction'); } + /** + * Specify the column heading + * + * @return string Column name for the heading + */ + protected function heading_column() { + return 'questionnametext'; + } + protected function default_sort() { $this->requiredcolumns['qtype'] = $this->knowncolumntypes['qtype']; $this->requiredcolumns['questionnametext'] = $this->knowncolumntypes['questionnametext']; diff --git a/question/editlib.php b/question/editlib.php index e688add6419..e4f811e86ff 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -134,6 +134,9 @@ abstract class question_bank_column_base { */ protected $qbank; + /** @var bool determine whether the column is td or th. */ + protected $isheading = false; + /** * Constructor. * @param $qbank the question_bank_view we are helping to render. @@ -150,6 +153,13 @@ abstract class question_bank_column_base { protected function init() { } + /** + * Set the column as heading + */ + public function set_as_heading() { + $this->isheading = true; + } + public function is_extra_row() { return false; } @@ -258,8 +268,20 @@ abstract class question_bank_column_base { $this->display_end($question, $rowclasses); } + /** + * Output the opening column tag. If it is set as heading, it will use tag instead of + * + * @param stdClass $question + * @param array $rowclasses + */ protected function display_start($question, $rowclasses) { - echo ''; + $tag = 'td'; + $attr = array('class' => $this->get_classes()); + if ($this->isheading) { + $tag = 'th'; + $attr['scope'] = 'row'; + } + echo html_writer::start_tag($tag, $attr); } /** @@ -292,8 +314,18 @@ abstract class question_bank_column_base { */ protected abstract function display_content($question, $rowclasses); + /** + * Output the closing column tag + * + * @param type $question + * @param type $rowclasses + */ protected function display_end($question, $rowclasses) { - echo "\n"; + $tag = 'td'; + if ($this->isheading) { + $tag = 'th'; + } + echo html_writer::end_tag($tag); } /** @@ -885,7 +917,7 @@ class question_bank_view { $this->lastchangedid = optional_param('lastchanged',0,PARAM_INT); $this->init_column_types(); - $this->init_columns($this->wanted_columns()); + $this->init_columns($this->wanted_columns(), $this->heading_column()); $this->init_sort(); $PAGE->requires->yui2_lib('container'); @@ -901,6 +933,15 @@ class question_bank_view { return $columns; } + /** + * Specify the column heading + * + * @return string Column name for the heading + */ + protected function heading_column() { + return 'questionname'; + } + protected function known_field_types() { return array( new question_bank_checkbox_column($this), @@ -923,7 +964,13 @@ class question_bank_view { } } - protected function init_columns($wanted) { + /** + * Initializing table columns + * + * @param array $wanted Collection of column names + * @param string $heading The name of column that is set as heading + */ + protected function init_columns($wanted, $heading = '') { $this->visiblecolumns = array(); $this->extrarows = array(); foreach ($wanted as $colname) { @@ -938,6 +985,9 @@ class question_bank_view { } } $this->requiredcolumns = array_merge($this->visiblecolumns, $this->extrarows); + if (array_key_exists($heading, $this->requiredcolumns)) { + $this->requiredcolumns[$heading]->set_as_heading(); + } } /**