forked from extern/egroupware
fix SQL error when ordering by custom-field
as $order_by parameter can contain more then just order by columns, eg. group by clause
This commit is contained in:
parent
22f015f301
commit
0206e1e09a
@ -536,6 +536,12 @@ class Storage extends Storage\Base
|
|||||||
// check if we order by a custom field --> join cf table for given cf and order by it's value
|
// 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)
|
if (strpos($order_by,self::CF_PREFIX) !== false)
|
||||||
{
|
{
|
||||||
|
// if $order_by contains more then order by columns (eg. group by) split it off before
|
||||||
|
if (($pos = stripos($order_by, 'order by')) !== false)
|
||||||
|
{
|
||||||
|
$group_by = substr($order_by, 0, $pos+9);
|
||||||
|
$order_by = substr($order_by, $pos+9);
|
||||||
|
}
|
||||||
// fields to order by, as cutomfields may have names with spaces, we examine each order by criteria
|
// fields to order by, as cutomfields may have names with spaces, we examine each order by criteria
|
||||||
$fields2order = explode(',',$order_by);
|
$fields2order = explode(',',$order_by);
|
||||||
foreach($fields2order as $v)
|
foreach($fields2order as $v)
|
||||||
@ -578,6 +584,11 @@ class Storage extends Storage\Base
|
|||||||
$join .= $this->extra_join_order.' AND extra_order.'.$this->extra_key.'='.$this->db->quote($key);
|
$join .= $this->extra_join_order.' AND extra_order.'.$this->extra_key.'='.$this->db->quote($key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// add group by again
|
||||||
|
if (isset($group_by))
|
||||||
|
{
|
||||||
|
$order_by = $group_by.$order_by;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// check if we filter by a custom field
|
// check if we filter by a custom field
|
||||||
if (is_array($filter))
|
if (is_array($filter))
|
||||||
|
Loading…
Reference in New Issue
Block a user