Skip to content
Browse files

MDL-21625 Question bank: Add accessibility to table layout for viewin…

…g question list
  • Loading branch information...
1 parent 7e8ae12 commit d2c9169a4c3a47a998c3bb18a701bf4150b6c807 @rwijaya rwijaya committed Oct 19, 2012
Showing with 63 additions and 4 deletions.
  1. +9 −0 mod/quiz/editlib.php
  2. +54 −4 question/editlib.php
View
9 mod/quiz/editlib.php
@@ -1141,6 +1141,15 @@ protected function wanted_columns() {
'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'];
View
58 question/editlib.php
@@ -134,6 +134,9 @@ function question_can_delete_cat($todelete) {
*/
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 @@ public function __construct(question_bank_view $qbank) {
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 @@ public function display($question, $rowclasses) {
$this->display_end($question, $rowclasses);
}
+ /**
+ * Output the opening column tag. If it is set as heading, it will use <th> tag instead of <td>
+ *
+ * @param stdClass $question
+ * @param array $rowclasses
+ */
protected function display_start($question, $rowclasses) {
- echo '<td class="' . $this->get_classes() . '">';
+ $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 @@ public function get_extra_classes() {
*/
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 "</td>\n";
+ $tag = 'td';
+ if ($this->isheading) {
+ $tag = 'th';
+ }
+ echo html_writer::end_tag($tag);
}
/**
@@ -892,7 +924,7 @@ public function __construct($contexts, $pageurl, $course, $cm = null) {
$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();
}
@@ -906,6 +938,15 @@ protected function wanted_columns() {
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),
@@ -928,7 +969,13 @@ protected function init_column_types() {
}
}
- 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) {
@@ -943,6 +990,9 @@ protected function init_columns($wanted) {
}
}
$this->requiredcolumns = array_merge($this->visiblecolumns, $this->extrarows);
+ if (array_key_exists($heading, $this->requiredcolumns)) {
+ $this->requiredcolumns[$heading]->set_as_heading();
+ }
}
/**

0 comments on commit d2c9169

Please sign in to comment.
Something went wrong with that request. Please try again.