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:
2018-03-23 14:55:43 +00:00
parent fdb90a0816
commit 7b090d1662

View File

@@ -2048,7 +2048,8 @@ class dblayeroo
/** Add a new ORDER sort. The multiple ORDERS are used from the first added to
* the last added
* @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")
/* {{{ */
@@ -2059,13 +2060,23 @@ class dblayeroo
if (! is_string ($sort))
$this->DBException ("Invalid sort provided (not string)");
$sort = strtoupper ($sort);
if (! in_array ($sort, array ("ASC", "DESC")))
$this->DBException ("Invalid sort provided (not ASC nor DESC)");
if (! in_array ($sort, array ("ASC", "DESC", "NATASC", "NATDESC")))
$this->DBException (
"Invalid sort provided (not ASC nor DESC nor NATASC nor NATDESC)");
if (! array_key_exists ($field, $this->fields))
$this->DBException (sprintf (
"Invalid field to orderAdd '%s' : not defined in table", $field));
$this->orderExpression[$this->getSortOrder()] =
$this->sep.$field.$this->sep." ".$sort;
$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->orderExpression[$this->getSortOrder()] = $exp;
return $this;
}
/* }}} */