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.
This commit is contained in:
defacer 2005-06-20 03:47:19 +00:00
parent f45ea97457
commit a5a3f48a4a
2 changed files with 12 additions and 3 deletions

View File

@ -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]];

View File

@ -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');