From 2628f0bc161fc2b93caaea29f65a182a27dbafb6 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Mon, 29 Oct 2007 15:25:09 +0000 Subject: [PATCH] MDL-11416 - Support for nonsortable columns in table lib. Backported from MOODLE_19_STABLE so that the fix for MDL-5262 works. --- lib/tablelib.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/tablelib.php b/lib/tablelib.php index d0d9e91e885..bdeef5e3934 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -16,6 +16,7 @@ class flexible_table { var $column_style = array(); var $column_class = array(); var $column_suppress = array(); + var $column_nosort = array('userpic'); var $setup = false; var $sess = NULL; var $baseurl = NULL; @@ -51,6 +52,29 @@ class flexible_table { $this->sort_default_order = $defaultorder; } + /** + * Do not sort using this column + * @param string column name + */ + function no_sorting($column) { + $this->column_nosort[] = $column; + } + + /** + * Is the column sortable? + * @param string column name, null means table + * @return bool + */ + function is_sortable($column=null) { + if (empty($column)) { + return $this->is_sortable; + } + if (!$this->is_sortable) { + return false; + } + return !in_array($column, $this->column_nosort); + } + function collapsible($bool) { $this->is_collapsible = $bool; } @@ -201,7 +225,7 @@ class flexible_table { } if( - !empty($_GET[$this->request[TABLE_VAR_SORT]]) && + !empty($_GET[$this->request[TABLE_VAR_SORT]]) && $this->is_sortable($_GET[$this->request[TABLE_VAR_SORT]]) && (isset($this->columns[$_GET[$this->request[TABLE_VAR_SORT]]]) || (($_GET[$this->request[TABLE_VAR_SORT]] == 'firstname' || $_GET[$this->request[TABLE_VAR_SORT]] == 'lastname') && isset($this->columns['fullname'])) )) @@ -479,7 +503,7 @@ class flexible_table { switch($column) { case 'fullname': - if($this->is_sortable) { + if($this->is_sortable($column)) { $icon_sort_first = $icon_sort_last = ''; if($primary_sort_column == 'firstname') { $lsortorder = get_string('asc'); @@ -516,7 +540,7 @@ class flexible_table { break; default: - if($this->is_sortable) { + if($this->is_sortable($column)) { if($primary_sort_column == $column) { if($primary_sort_order == SORT_ASC) { $icon_sort = ' '.get_string('asc').'';