* All apps: nummeric custom-fields (float or new integer) sort nummeric in lists

This commit is contained in:
Ralf Becker 2015-03-23 08:41:51 +00:00
parent cb463d1492
commit 6f804b58e8
5 changed files with 52 additions and 5 deletions

View File

@ -45,6 +45,7 @@ class customfields_widget
*/
var $cf_types = array(
'text' => 'Text',
'int' => 'Integer',
'float' => 'Float',
'label' => 'Label',
'select' => 'Selectbox',
@ -333,6 +334,7 @@ class customfields_widget
}
break;
case 'float':
case 'int':
$known_options = array('min'=>null, 'max'=>null,'size' => $field['len'], 'precision' => null);
$options = array_merge($known_options, $field['values']);
$input =& boetemplate::empty_cell($field['type'],$this->prefix.$lname,array(

View File

@ -29,6 +29,7 @@ class etemplate_widget_customfields extends etemplate_widget_transformer
*/
protected static $cf_types = array(
'text' => 'Text',
'int' => 'Integer',
'float' => 'Float',
'label' => 'Label',
'select' => 'Selectbox',

View File

@ -534,8 +534,21 @@ class so_sql_cf extends so_sql
// 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);
$key = substr(trim(implode(' ',$buff)), 1);
switch($this->customfields[$key]['type'])
{
case 'int':
$order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,'.
$this->db->to_int('extra_order.'.$this->extra_value).' '.$orderDir, $order_by);
break;
case 'float':
$order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,'.
$this->db->to_double('extra_order.'.$this->extra_value).' '.$orderDir, $order_by);
break;
default:
$order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,extra_order.'.
$this->extra_value.' '.$orderDir, $order_by);
}
// postgres requires that expressions in order by appear in the columns of a distinct select
if ($this->db->Type != 'mysql')
{
@ -546,7 +559,7 @@ class so_sql_cf extends so_sql
$extra_cols[] = 'extra_order.'.$this->extra_value;
$extra_cols[] = 'extra_order.'.$this->extra_value.' IS NULL';
}
$join .= $this->extra_join_order.' AND extra_order.'.$this->extra_key.'='.$this->db->quote(substr($key,1));
$join .= $this->extra_join_order.' AND extra_order.'.$this->extra_key.'='.$this->db->quote($key);
}
}
}

View File

@ -712,7 +712,7 @@ class infolog_so
if ($val[0] == '#')
{
$sortbycf = substr($val,1);
$val = "cfsortcrit";
$val = "cfsortcrit IS NULL,cfsortcrit";
}
else
{
@ -862,7 +862,18 @@ class infolog_so
$info_customfield = '';
if ($sortbycf != '')
{
$info_customfield = ", (SELECT DISTINCT info_extra_value FROM $this->extra_table sub2 WHERE sub2.info_id=main.info_id AND info_extra_name=".$this->db->quote($sortbycf).") AS cfsortcrit ";
$sort_col = "(SELECT DISTINCT info_extra_value FROM $this->extra_table sub2 WHERE sub2.info_id=main.info_id AND info_extra_name=".$this->db->quote($sortbycf).")";
if (!isset($custom_fields)) $custom_fields = config::get_customfields('infolog');
switch($custom_fields[$sortbycf]['type'])
{
case 'int':
$sort_col = $this->db->to_int($sort_col);
break;
case 'float':
$sort_col = $this->db->to_double($sort_col);
break;
}
$info_customfield = ", $sort_col AS cfsortcrit ";
}
//echo "SELECT $distinct main.* $info_customfield $sql_query $ordermethod"."<br>";
do

View File

@ -1300,6 +1300,24 @@ class egw_db
return false;
}
/**
* Cast a column or sql expression to integer, necessary at least for postgreSQL or MySQL for sorting
*
* @param string $expr
* @return string
*/
function to_double($expr)
{
switch($this->Type)
{
case 'pgsql':
return $expr.'::double';
case 'mysql':
return 'CAST('.$expr.' AS DECIMAL(24,3))';
}
return $expr;
}
/**
* Cast a column or sql expression to integer, necessary at least for postgreSQL
*
@ -1312,6 +1330,8 @@ class egw_db
{
case 'pgsql':
return $expr.'::integer';
case 'mysql':
return 'CAST('.$expr.' AS SIGNED)';
}
return $expr;
}