MDL-55941 output: Refactor and improve initialbar UX to use templates
This commit is contained in:
+26
-33
@@ -907,8 +907,12 @@ class flexible_table {
|
||||
/**
|
||||
* This function is not part of the public api.
|
||||
* @return string initial of first name we are currently filtering by
|
||||
*
|
||||
* @deprecated since Moodle 3.3
|
||||
*/
|
||||
function get_initial_first() {
|
||||
debugging('Method get_initial_first() is no longer used and has been deprecated, ' .
|
||||
'to print initials bar call print_initials_bar()', DEBUG_DEVELOPER);
|
||||
if (!$this->use_initials) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -919,8 +923,12 @@ class flexible_table {
|
||||
/**
|
||||
* This function is not part of the public api.
|
||||
* @return string initial of last name we are currently filtering by
|
||||
*
|
||||
* @deprecated since Moodle 3.3
|
||||
*/
|
||||
function get_initial_last() {
|
||||
debugging('Method get_initial_last() is no longer used and has been deprecated, ' .
|
||||
'to print initials bar call print_initials_bar()', DEBUG_DEVELOPER);
|
||||
if (!$this->use_initials) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -935,44 +943,29 @@ class flexible_table {
|
||||
* @param string $class class name to add to this initial bar.
|
||||
* @param string $title the name to put in front of this initial bar.
|
||||
* @param string $urlvar URL parameter name for this initial.
|
||||
*
|
||||
* @deprecated since Moodle 3.3
|
||||
*/
|
||||
protected function print_one_initials_bar($alpha, $current, $class, $title, $urlvar) {
|
||||
|
||||
debugging('Method print_one_initials_bar() is no longer used and has been deprecated, ' .
|
||||
'to print initials bar call print_initials_bar()', DEBUG_DEVELOPER);
|
||||
|
||||
echo html_writer::start_tag('div', array('class' => 'initialbar ' . $class)) .
|
||||
html_writer::tag('span', $title . ': ', array('class' => 'initialbarlabel'));
|
||||
$title . ' : ';
|
||||
if ($current) {
|
||||
echo html_writer::link($this->baseurl->out(false, array($urlvar => '')),
|
||||
get_string('all'), array('class' => 'initialbarall'));
|
||||
echo html_writer::link($this->baseurl->out(false, array($urlvar => '')), get_string('all'));
|
||||
} else {
|
||||
echo html_writer::tag('strong', get_string('all'), array('class' => 'initialbarall'));
|
||||
echo html_writer::tag('strong', get_string('all'));
|
||||
}
|
||||
|
||||
// We want to find a letter grouping size which suits the language so
|
||||
// find the largest group size which is less than 15 chars. By always
|
||||
// using a max number of groups which is a factor of 2, we always get
|
||||
// nice wrapping, and the last row is always the shortest.
|
||||
$groupsize = count($alpha);
|
||||
$groups = 1;
|
||||
while ($groupsize > 15) {
|
||||
$groups *= 2;
|
||||
$groupsize = ceil(count($alpha) / $groups);
|
||||
}
|
||||
|
||||
echo html_writer::start_tag('span', array('class' => 'initialbargroups'));
|
||||
echo html_writer::start_tag('span', array('class' => 'initialbargroup'));
|
||||
$c = 0;
|
||||
foreach ($alpha as $letter) {
|
||||
if ($c++ > 0 && $c % $groupsize == 1) {
|
||||
echo html_writer::end_tag('span') . ' ';
|
||||
echo html_writer::start_tag('span', array('class' => 'initialbargroup'));
|
||||
}
|
||||
if ($letter === $current) {
|
||||
echo html_writer::tag('strong', $letter);
|
||||
} else {
|
||||
echo html_writer::link($this->baseurl->out(false, array($urlvar => $letter)), $letter);
|
||||
}
|
||||
}
|
||||
echo html_writer::end_tag('span');
|
||||
echo html_writer::end_tag('span');
|
||||
|
||||
echo html_writer::end_tag('div');
|
||||
}
|
||||
@@ -981,29 +974,29 @@ class flexible_table {
|
||||
* This function is not part of the public api.
|
||||
*/
|
||||
function print_initials_bar() {
|
||||
global $OUTPUT;
|
||||
|
||||
if ((!empty($this->prefs['i_last']) || !empty($this->prefs['i_first']) ||$this->use_initials)
|
||||
&& isset($this->columns['fullname'])) {
|
||||
&& isset($this->columns['fullname'])) {
|
||||
|
||||
$alpha = explode(',', get_string('alphabet', 'langconfig'));
|
||||
|
||||
// Bar of first initials
|
||||
if (!empty($this->prefs['i_first'])) {
|
||||
$ifirst = $this->prefs['i_first'];
|
||||
} else {
|
||||
$ifirst = '';
|
||||
}
|
||||
$this->print_one_initials_bar($alpha, $ifirst, 'firstinitial',
|
||||
get_string('firstname'), $this->request[TABLE_VAR_IFIRST]);
|
||||
|
||||
// Bar of last initials
|
||||
if (!empty($this->prefs['i_last'])) {
|
||||
$ilast = $this->prefs['i_last'];
|
||||
} else {
|
||||
$ilast = '';
|
||||
}
|
||||
$this->print_one_initials_bar($alpha, $ilast, 'lastinitial',
|
||||
get_string('lastname'), $this->request[TABLE_VAR_ILAST]);
|
||||
|
||||
$prefixfirst = $this->request[TABLE_VAR_IFIRST];
|
||||
$prefixlast = $this->request[TABLE_VAR_ILAST];
|
||||
echo $OUTPUT->initials_bar($ifirst, 'firstinitial', get_string('firstname'), $prefixfirst, $this->baseurl);
|
||||
echo $OUTPUT->initials_bar($ilast, 'lastinitial', get_string('lastname'), $prefixlast, $this->baseurl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user