From a5a3f48a4a7fb384a42edd46eee3778d654ea53d Mon Sep 17 00:00:00 2001 From: defacer Date: Mon, 20 Jun 2005 03:47:19 +0000 Subject: [PATCH] Merging from STABLE: Augment tablelib so that it can accept a default sort order. Adding default sort order to participant lists to reinstate 1.4-style behavior. --- lib/tablelib.php | 11 ++++++++++- user/index.php | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/tablelib.php b/lib/tablelib.php index 5092eb5edcf..fdbdbc549f6 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -30,6 +30,8 @@ class flexible_table { var $pagesize = 30; var $currpage = 0; var $totalrows = 0; + var $sort_default_column = NULL; + var $sort_default_order = SORT_ASC; function flexible_table($uniqueid) { $this->uniqueid = $uniqueid; @@ -43,8 +45,10 @@ class flexible_table { ); } - function sortable($bool) { + function sortable($bool, $defaultcolumn = NULL, $defaultorder = SORT_ASC) { $this->is_sortable = $bool; + $this->sort_default_column = $defaultcolumn; + $this->sort_default_order = $defaultorder; } function collapsible($bool) { @@ -222,6 +226,11 @@ class flexible_table { } } + // If we didn't sort just now, then use the default sort order if one is defined and the column exists + if(empty($this->sess->sortby) && !empty($this->sort_default_column) && isset($this->columns[$this->sort_default_column])) { + $this->sess->sortby = array ($this->sort_default_column => ($this->sort_default_order == SORT_DESC ? SORT_DESC : SORT_ASC)); + } + if(isset($_GET[$this->request[TABLE_VAR_ILAST]])) { if(empty($_GET[$this->request[TABLE_VAR_ILAST]]) || is_numeric(strpos(get_string('alphabet'), $_GET[$this->request[TABLE_VAR_ILAST]]))) { $this->sess->i_last = $_GET[$this->request[TABLE_VAR_ILAST]]; diff --git a/user/index.php b/user/index.php index e09fcf0fc3a..5f1478d35e9 100644 --- a/user/index.php +++ b/user/index.php @@ -142,7 +142,7 @@ $table->define_headers($tableheaders); $table->define_baseurl($baseurl); - $table->sortable(true); + $table->sortable(true, 'lastaccess', SORT_DESC); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'teachers'); @@ -252,7 +252,7 @@ $table->define_headers($tableheaders); $table->define_baseurl($baseurl); - $table->sortable(true); + $table->sortable(true, 'lastaccess', SORT_DESC); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'students');