dblayeroo : Add support to natural sort in ORDER
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4176 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -2048,7 +2048,8 @@ class dblayeroo
|
|||||||
/** Add a new ORDER sort. The multiple ORDERS are used from the first added to
|
/** Add a new ORDER sort. The multiple ORDERS are used from the first added to
|
||||||
* the last added
|
* the last added
|
||||||
* @param string $field The field to sort
|
* @param string $field The field to sort
|
||||||
* @param string|null $sort The sort order ("ASC", "DESC");
|
* @param string|null $sort The sort order ("ASC", "DESC", "NATASC",
|
||||||
|
* "NATDESC");
|
||||||
*/
|
*/
|
||||||
public function orderAdd ($field, $sort = "ASC")
|
public function orderAdd ($field, $sort = "ASC")
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
@@ -2059,13 +2060,23 @@ class dblayeroo
|
|||||||
if (! is_string ($sort))
|
if (! is_string ($sort))
|
||||||
$this->DBException ("Invalid sort provided (not string)");
|
$this->DBException ("Invalid sort provided (not string)");
|
||||||
$sort = strtoupper ($sort);
|
$sort = strtoupper ($sort);
|
||||||
if (! in_array ($sort, array ("ASC", "DESC")))
|
if (! in_array ($sort, array ("ASC", "DESC", "NATASC", "NATDESC")))
|
||||||
$this->DBException ("Invalid sort provided (not ASC nor DESC)");
|
$this->DBException (
|
||||||
|
"Invalid sort provided (not ASC nor DESC nor NATASC nor NATDESC)");
|
||||||
if (! array_key_exists ($field, $this->fields))
|
if (! array_key_exists ($field, $this->fields))
|
||||||
$this->DBException (sprintf (
|
$this->DBException (sprintf (
|
||||||
"Invalid field to orderAdd '%s' : not defined in table", $field));
|
"Invalid field to orderAdd '%s' : not defined in table", $field));
|
||||||
$this->orderExpression[$this->getSortOrder()] =
|
$plus = "";
|
||||||
|
if (substr ($sort, 0, 3) === "NAT")
|
||||||
|
{
|
||||||
|
$plus = "+0";
|
||||||
|
$sort = substr ($sort, 3);
|
||||||
|
}
|
||||||
|
$exp = $this->sep.$field.$this->sep.$plus." ".$sort;
|
||||||
|
if ($plus !== "")
|
||||||
|
$exp .= ",". $this->sep.$this->table.$this->sep.".".
|
||||||
$this->sep.$field.$this->sep." ".$sort;
|
$this->sep.$field.$this->sep." ".$sort;
|
||||||
|
$this->orderExpression[$this->getSortOrder()] = $exp;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|||||||
Reference in New Issue
Block a user