From b78a9865cc2ad37154cb7c0dc6f25245d013e163 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Thu, 8 Jul 2010 11:37:56 +0000 Subject: [PATCH] explicitly process fields to order by, as cutomfields may have names with spaces, so we examine each order by criteria, as our preg did not do the job properly --- etemplate/inc/class.so_sql_cf.inc.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/etemplate/inc/class.so_sql_cf.inc.php b/etemplate/inc/class.so_sql_cf.inc.php index 285b0ba149..2be41db2f4 100644 --- a/etemplate/inc/class.so_sql_cf.inc.php +++ b/etemplate/inc/class.so_sql_cf.inc.php @@ -497,15 +497,24 @@ class so_sql_cf extends so_sql } } } - // check if we order by a custom field --> join cf table for given cf and order by it's value - if (strpos($order_by,self::CF_PREFIX) !== false && - preg_match('/'.self::CF_PREFIX.'([^ ]+) (asc|desc)/i',$order_by,$matches)) + if (strpos($order_by,self::CF_PREFIX) !== false) { - $order_by = str_replace($matches[0],'extra_order.'.$this->extra_value.' IS NULL,extra_order.'.$this->extra_value.' '.$matches[2],$order_by); - $join .= $this->extra_join_order.' AND extra_order.'.$this->extra_key.'='.$this->db->quote($matches[1]); + // fields to order by, as cutomfields may have names with spaces, we examine each order by criteria + $fields2order = explode(',',$order_by); + foreach($fields2order as $k => $v) + { + if (strpos($v,self::CF_PREFIX) !== false) + { + // we found a customfield, so we split that part by space char in order to get Sorting Direction and Fieldname + $buff = explode(' ',trim($v)); + $orderDir = array_pop($buff); + $key = trim(implode(' ',$buff)); + $order_by = str_replace($v,'extra_order.'.$this->extra_value.' IS NULL,extra_order.'.$this->extra_value.' '.$orderDir,$order_by); + $join .= $this->extra_join_order.' AND extra_order.'.$this->extra_key.'='.$this->db->quote(substr($key,1)); + } + } } - // check if we filter by a custom field if (is_array($filter)) {