From 6f0d3480c75cad8fd7824704ddaa136f3a44d06c Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 16 Feb 2011 11:55:12 +0000 Subject: [PATCH] MDL-26425 tablelib change print_initials_bar to remove duplication, and to use html_writer. --- lib/tablelib.php | 56 +++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/lib/tablelib.php b/lib/tablelib.php index 6cfaa96cdc0..8fe68328ae5 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -815,50 +815,52 @@ class flexible_table { return $this->sess->i_last; } + protected function print_one_initials_bar($alpha, $current, $class, $title, $urlvar) { + echo html_writer::start_tag('div', array('class' => 'initialbar ' . $class)) . + $title . ' : '; + if ($current) { + echo html_writer::link($this->baseurl->out(false, array($urlvar => '')), get_string('all')); + } else { + echo html_writer::tag('strong', get_string('all')); + } + + foreach ($alpha as $letter) { + 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('div'); + } + /** * This function is not part of the public api. */ function print_initials_bar() { - if ((!empty($this->sess->i_last) || !empty($this->sess->i_first) || $this->use_initials) + if ((!empty($this->sess->i_last) || !empty($this->sess->i_first) ||$this->use_initials) && isset($this->columns['fullname'])) { - $strall = get_string('all'); $alpha = explode(',', get_string('alphabet', 'langconfig')); // Bar of first initials - - echo '
'.get_string('firstname').' : '; if (!empty($this->sess->i_first)) { - echo ''.$strall.''; + $ifirst = $this->sess->i_first; } else { - echo ''.$strall.''; + $ifirst = ''; } - foreach ($alpha as $letter) { - if (isset($this->sess->i_first) && $letter == $this->sess->i_first) { - echo ' '.$letter.''; - } else { - echo ' '.$letter.''; - } - } - echo '
'; + $this->print_one_initials_bar($alpha, $ifirst, 'firstinitial', + get_string('firstname'), $this->request[TABLE_VAR_IFIRST]); // Bar of last initials - - echo '
'.get_string('lastname').' : '; if (!empty($this->sess->i_last)) { - echo ''.$strall.''; + $ilast = $this->sess->i_last; } else { - echo ''.$strall.''; + $ilast = ''; } - foreach ($alpha as $letter) { - if (isset($this->sess->i_last) && $letter == $this->sess->i_last) { - echo ' '.$letter.''; - } else { - echo ' '.$letter.''; - } - } - echo '
'; - + $this->print_one_initials_bar($alpha, $ilast, 'lastinitial', + get_string('lastname'), $this->request[TABLE_VAR_ILAST]); } }