From 7b090d1662eeb45b06f0ab06382ff3388d2282af Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Fri, 23 Mar 2018 14:55:43 +0000 Subject: [PATCH] dblayeroo : Add support to natural sort in ORDER git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4176 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- dblayeroo.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/dblayeroo.php b/dblayeroo.php index 84beb69..98f31da 100644 --- a/dblayeroo.php +++ b/dblayeroo.php @@ -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; } /* }}} */