From 0887f755877a90d5310155d1c6542e2319c5c21e Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Tue, 11 Dec 2012 14:47:33 +0800 Subject: [PATCH] MDL-30700 Assignment 2.2: Added text_sorting function to tablelib Allows oracle to sort by text (clob) columns (should be used sparingly). --- lib/tablelib.php | 17 +++++++++++++++-- mod/assignment/lib.php | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/tablelib.php b/lib/tablelib.php index 2a08616859e..57796bbc52e 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -60,6 +60,7 @@ class flexible_table { var $column_class = array(); var $column_suppress = array(); var $column_nosort = array('userpic'); + private $column_textsort = array(); var $setup = false; var $sess = NULL; var $baseurl = NULL; @@ -214,6 +215,14 @@ class flexible_table { $this->sort_default_order = $defaultorder; } + /** + * Use text sorting functions for this column (required for text columns with Oracle). + * @param string column name + */ + function text_sorting($column) { + $this->column_textsort[] = $column; + } + /** * Do not sort using this column * @param string column name @@ -513,10 +522,14 @@ class flexible_table { * @param array $cols column name => SORT_ASC or SORT_DESC * @return SQL fragment that can be used in an ORDER BY clause. */ - public static function construct_order_by($cols) { + public static function construct_order_by($cols, $textsortcols=array()) { + global $DB; $bits = array(); foreach ($cols as $column => $order) { + if (in_array($column, $textsortcols)) { + $column = $DB->sql_order_by_text($column); + } if ($order == SORT_ASC) { $bits[] = $column . ' ASC'; } else { @@ -531,7 +544,7 @@ class flexible_table { * @return SQL fragment that can be used in an ORDER BY clause. */ public function get_sql_sort() { - return self::construct_order_by($this->get_sort_columns()); + return self::construct_order_by($this->get_sort_columns(), $this->column_textsort); } /** diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 01043317038..3688ac9590f 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -1380,6 +1380,7 @@ class assignment_base { $table->no_sorting('finalgrade'); $table->no_sorting('outcome'); + $table->text_sorting('submissioncomment'); // Start working -- this is necessary as soon as the niceties are over $table->setup();