MDL-11416 support for nonsortable columns in table lib
authorskodak <skodak>
Sun, 23 Sep 2007 15:54:33 +0000 (15:54 +0000)
committerskodak <skodak>
Sun, 23 Sep 2007 15:54:33 +0000 (15:54 +0000)
lib/tablelib.php

index 8cf011b254e532b6a3837b243a61d9d362b79b08..6494965c429bdcb28532ff8d63b3e214cac09323 100644 (file)
@@ -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;
@@ -64,6 +65,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);
+    }
+
     /**
      * Sets the is_collapsible variable to the given boolean.
      * @param bool $bool
@@ -297,7 +321,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']))
             ))
@@ -603,7 +627,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');
@@ -640,7 +664,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 = ' <img src="'.$CFG->pixpath.'/t/down.gif" alt="'.get_string('asc').'" />';