forked from extern/egroupware
* All apps: nummeric custom-fields (float or new integer) sort nummeric in lists
This commit is contained in:
parent
cb463d1492
commit
6f804b58e8
@ -45,6 +45,7 @@ class customfields_widget
|
|||||||
*/
|
*/
|
||||||
var $cf_types = array(
|
var $cf_types = array(
|
||||||
'text' => 'Text',
|
'text' => 'Text',
|
||||||
|
'int' => 'Integer',
|
||||||
'float' => 'Float',
|
'float' => 'Float',
|
||||||
'label' => 'Label',
|
'label' => 'Label',
|
||||||
'select' => 'Selectbox',
|
'select' => 'Selectbox',
|
||||||
@ -333,6 +334,7 @@ class customfields_widget
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'float':
|
case 'float':
|
||||||
|
case 'int':
|
||||||
$known_options = array('min'=>null, 'max'=>null,'size' => $field['len'], 'precision' => null);
|
$known_options = array('min'=>null, 'max'=>null,'size' => $field['len'], 'precision' => null);
|
||||||
$options = array_merge($known_options, $field['values']);
|
$options = array_merge($known_options, $field['values']);
|
||||||
$input =& boetemplate::empty_cell($field['type'],$this->prefix.$lname,array(
|
$input =& boetemplate::empty_cell($field['type'],$this->prefix.$lname,array(
|
||||||
|
@ -29,6 +29,7 @@ class etemplate_widget_customfields extends etemplate_widget_transformer
|
|||||||
*/
|
*/
|
||||||
protected static $cf_types = array(
|
protected static $cf_types = array(
|
||||||
'text' => 'Text',
|
'text' => 'Text',
|
||||||
|
'int' => 'Integer',
|
||||||
'float' => 'Float',
|
'float' => 'Float',
|
||||||
'label' => 'Label',
|
'label' => 'Label',
|
||||||
'select' => 'Selectbox',
|
'select' => 'Selectbox',
|
||||||
|
@ -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
|
// we found a customfield, so we split that part by space char in order to get Sorting Direction and Fieldname
|
||||||
$buff = explode(' ',trim($v));
|
$buff = explode(' ',trim($v));
|
||||||
$orderDir = array_pop($buff);
|
$orderDir = array_pop($buff);
|
||||||
$key = trim(implode(' ',$buff));
|
$key = substr(trim(implode(' ',$buff)), 1);
|
||||||
$order_by = str_replace($v,'extra_order.'.$this->extra_value.' IS NULL,extra_order.'.$this->extra_value.' '.$orderDir,$order_by);
|
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
|
// postgres requires that expressions in order by appear in the columns of a distinct select
|
||||||
if ($this->db->Type != 'mysql')
|
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;
|
||||||
$extra_cols[] = 'extra_order.'.$this->extra_value.' IS NULL';
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -712,7 +712,7 @@ class infolog_so
|
|||||||
if ($val[0] == '#')
|
if ($val[0] == '#')
|
||||||
{
|
{
|
||||||
$sortbycf = substr($val,1);
|
$sortbycf = substr($val,1);
|
||||||
$val = "cfsortcrit";
|
$val = "cfsortcrit IS NULL,cfsortcrit";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -862,7 +862,18 @@ class infolog_so
|
|||||||
$info_customfield = '';
|
$info_customfield = '';
|
||||||
if ($sortbycf != '')
|
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>";
|
//echo "SELECT $distinct main.* $info_customfield $sql_query $ordermethod"."<br>";
|
||||||
do
|
do
|
||||||
|
@ -1300,6 +1300,24 @@ class egw_db
|
|||||||
return false;
|
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
|
* Cast a column or sql expression to integer, necessary at least for postgreSQL
|
||||||
*
|
*
|
||||||
@ -1312,6 +1330,8 @@ class egw_db
|
|||||||
{
|
{
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
return $expr.'::integer';
|
return $expr.'::integer';
|
||||||
|
case 'mysql':
|
||||||
|
return 'CAST('.$expr.' AS SIGNED)';
|
||||||
}
|
}
|
||||||
return $expr;
|
return $expr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user