mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-37864 lib: Help icon work correctly in table header with sorting
This commit is contained in:
parent
20d38830ae
commit
f1e1477142
@ -55,6 +55,11 @@ class flexible_table {
|
||||
var $uniqueid = NULL;
|
||||
var $attributes = array();
|
||||
var $headers = array();
|
||||
|
||||
/**
|
||||
* @var string For create header with help icon.
|
||||
*/
|
||||
private $helpforheaders = array();
|
||||
var $columns = array();
|
||||
var $column_style = array();
|
||||
var $column_class = array();
|
||||
@ -422,6 +427,19 @@ class flexible_table {
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called after {@link define_headers()}.
|
||||
* Always use this function if you need to create header with sorting and help icon.
|
||||
* @param int $index of header.
|
||||
* @param string $identifier the keyword that defines a help page.
|
||||
* @param string $component component name.
|
||||
* @param string|bool $linktext true means use $title as link text, string means link text value.
|
||||
*/
|
||||
public function define_help_for_header($index, $identifier, $component = 'moodle', $linktext = '') {
|
||||
global $OUTPUT;
|
||||
$this->helpforheaders[$index] = $OUTPUT->help_icon($identifier, $component, $linktext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called after table is defined. Use methods above first. Cannot
|
||||
* use functions below till after calling this method.
|
||||
@ -1225,8 +1243,12 @@ class flexible_table {
|
||||
// Done this way for the possibility of more than two sortable full name display fields.
|
||||
$this->headers[$index] = '';
|
||||
foreach ($requirednames as $name) {
|
||||
$helpicon = '';
|
||||
if (isset($this->helpforheaders[$index])) {
|
||||
$helpicon = $this->helpforheaders[$index];
|
||||
}
|
||||
$sortname = $this->sort_link(get_string($name),
|
||||
$name, $primarysortcolumn === $name, $primarysortorder);
|
||||
$name, $primarysortcolumn === $name, $primarysortorder, $helpicon);
|
||||
$this->headers[$index] .= $sortname . ' / ';
|
||||
}
|
||||
$this->headers[$index] = substr($this->headers[$index], 0, -3);
|
||||
@ -1240,8 +1262,12 @@ class flexible_table {
|
||||
|
||||
default:
|
||||
if ($this->is_sortable($column)) {
|
||||
$helpicon = '';
|
||||
if (isset($this->helpforheaders[$index])) {
|
||||
$helpicon = $this->helpforheaders[$index];
|
||||
}
|
||||
$this->headers[$index] = $this->sort_link($this->headers[$index],
|
||||
$column, $primarysortcolumn == $column, $primarysortorder);
|
||||
$column, $primarysortcolumn == $column, $primarysortorder, $helpicon);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1257,7 +1283,11 @@ class flexible_table {
|
||||
if (is_array($this->column_style[$column])) {
|
||||
$attributes['style'] = $this->make_styles_string($this->column_style[$column]);
|
||||
}
|
||||
$content = $this->headers[$index] . html_writer::tag('div',
|
||||
$helpicon = '';
|
||||
if (isset($this->helpforheaders[$index]) && !$this->is_sortable($column)) {
|
||||
$helpicon = $this->helpforheaders[$index];
|
||||
}
|
||||
$content = $this->headers[$index] . $helpicon . html_writer::tag('div',
|
||||
$icon_hide, array('class' => 'commands'));
|
||||
}
|
||||
echo html_writer::tag('th', $content, $attributes);
|
||||
@ -1310,14 +1340,15 @@ class flexible_table {
|
||||
* @param string $column the column name, may be a fake column like 'firstname' or a real one.
|
||||
* @param bool $isprimary whether the is column is the current primary sort column.
|
||||
* @param int $order SORT_ASC or SORT_DESC
|
||||
* @param string $helpicon if the header contains helpicon must be used exactly this param.
|
||||
* @return string HTML fragment.
|
||||
*/
|
||||
protected function sort_link($text, $column, $isprimary, $order) {
|
||||
protected function sort_link($text, $column, $isprimary, $order, $helpicon = '') {
|
||||
return html_writer::link($this->baseurl->out(false,
|
||||
array($this->request[TABLE_VAR_SORT] => $column)),
|
||||
$text . get_accesshide(get_string('sortby') . ' ' .
|
||||
$text . ' ' . $this->sort_order_name($isprimary, $order))) . ' ' .
|
||||
$this->sort_icon($isprimary, $order);
|
||||
$helpicon . ' ' . $this->sort_icon($isprimary, $order);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user