From 143dfc0da60e4e2fee5fd804fd591fac91e2bfc8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Carretero?=
 <frederic.carretero@veremes.com>
Date: Mon, 21 Jan 2019 09:46:52 +0100
Subject: [PATCH] =?UTF-8?q?Tri=20de=20la=20liste=20des=20sch=C3=A9mas=20da?=
 =?UTF-8?q?ns=20l'=C3=A9dition=20d'un=20objet=20m=C3=A9tier.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../vas/rest/ws/vitis/GenericQuerys.class.inc | 23 ++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/vitis/vas/rest/ws/vitis/GenericQuerys.class.inc b/src/vitis/vas/rest/ws/vitis/GenericQuerys.class.inc
index ae3ade89..7394491a 100644
--- a/src/vitis/vas/rest/ws/vitis/GenericQuerys.class.inc
+++ b/src/vitis/vas/rest/ws/vitis/GenericQuerys.class.inc
@@ -457,7 +457,6 @@ class GenericQuerys extends Vitis {
                 $this->aValues['password'] = '';
             }
         }
-
         $this->oBd = new BD($this->aValues['login'], $this->aValues['password'], $this->aValues['database'], $this->aValues['server'], $this->aValues['port'], $this->aValues['sgbd'], $this->aValues['encoding']);
         if ($this->oBd->erreurRencontree) {
             writeToErrorLog(ERROR_CONNECTION_PROBLEM);
@@ -525,6 +524,28 @@ class GenericQuerys extends Vitis {
         $this->oBd = new BD($this->aValues['login'], $this->aValues['password'], $sDatabase, $this->aValues['server'], $this->aValues['port'], $this->aValues['sgbd'], $this->aValues['encoding']);
         $sSql = $this->aSql[$this->aValues['sgbd']]['getSchemas'];
         $aSQLParams = array();
+        //order by
+        if (!empty($this->aValues['order_by'])) {
+            $aOrder = explode("|", $this->aValues['order_by']);
+            foreach ($aOrder as $value) {
+                $sColumnKey = 'column_' . vitisUniqId();
+                if (strpos($sSql, "ORDER BY") == FALSE)
+                    $sSql .= " ORDER BY " . str_replace("=", " ", "[" . $sColumnKey . "]");
+                else
+                    $sSql .= ", " . str_replace("=", " ", "[" . $sColumnKey . "]");
+                $aSQLParams[$sColumnKey] = array('value' => $value, 'type' => 'column_name');
+            }
+        }
+        // sort_order
+        if (!empty($this->aValues['sort_order'])) {
+            switch (strtoupper($this->aValues['sort_order'])) {
+                case 'DESC':
+                    $sSql .= " DESC";
+                    break;
+                default:
+                    $sSql .= " ASC";
+            }
+        }
         $oPDOresult = $this->oBd->executeWithParams($sSql, $aSQLParams);
         if ($this->oBd->enErreur()) {
             $oError = new VitisError(1, $this->oBd->getBDMessage());
-- 
GitLab