Skip to content

Commit

Permalink
MDL-11416 - Support for nonsortable columns in table lib. Backported …
Browse files Browse the repository at this point in the history
…from MOODLE_19_STABLE so that the fix for MDL-5262 works.
  • Loading branch information
tjhunt committed Oct 29, 2007
1 parent 691d35e commit ce26bd1
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions lib/tablelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,6 +52,29 @@ function sortable($bool, $defaultcolumn = NULL, $defaultorder = SORT_ASC) {
$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;
}
Expand Down Expand Up @@ -201,7 +225,7 @@ function setup() {
}

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']))
))
Expand Down Expand Up @@ -464,7 +488,7 @@ function print_html() {
switch($column) {

case 'fullname':
if($this->is_sortable) {
if($this->is_sortable($column)) {
$icon_sort_first = $icon_sort_last = '';
if($primary_sort_column == 'firstname') {
if($primary_sort_order == SORT_ASC) {
Expand All @@ -488,7 +512,7 @@ function print_html() {
break;

default:
if($this->is_sortable) {
if($this->is_sortable($column)) {
if($primary_sort_column == $column) {
if($primary_sort_order == SORT_ASC) {
$icon_sort = ' <img src="'.$CFG->pixpath.'/t/down.gif" />';
Expand Down

0 comments on commit ce26bd1

Please sign in to comment.