|
@@ -108,6 +108,15 @@ class MySQL_CRUD_API {
|
108
|
108
|
}
|
109
|
109
|
return $key;
|
110
|
110
|
}
|
|
111
|
+
|
|
112
|
+ private function processOrderParameter($order,$table,$database,$mysqli) {
|
|
113
|
+ if ($order) {
|
|
114
|
+ $order = explode(',',$order,2);
|
|
115
|
+ if (count($order)<2) $order[1]='ASC';
|
|
116
|
+ $order[1] = strtoupper($order[1])=='DESC'?'DESC':'ASC';
|
|
117
|
+ }
|
|
118
|
+ return $order;
|
|
119
|
+ }
|
111
|
120
|
|
112
|
121
|
private function processFilterParameter($filter,$match,$mysqli) {
|
113
|
122
|
if ($filter) {
|
|
@@ -189,18 +198,20 @@ class MySQL_CRUD_API {
|
189
|
198
|
$page = $this->parseGetParameter('page', '0-9,', false);
|
190
|
199
|
$filter = $this->parseGetParameter('filter', false, 'start');
|
191
|
200
|
$match = $this->parseGetParameter('match', 'a-z', false);
|
|
201
|
+ $order = $this->parseGetParameter('order', 'a-zA-Z0-9\-_*,', false);
|
192
|
202
|
|
193
|
203
|
$table = $this->processTableParameter($table,$database,$mysqli);
|
194
|
204
|
$key = $this->processKeyParameter($key,$table,$database,$mysqli);
|
195
|
205
|
$filter = $this->processFilterParameter($filter,$match,$mysqli);
|
196
|
206
|
$page = $this->processPageParameter($page);
|
197
|
|
-
|
|
207
|
+ $order = $this->processOrderParameter($order,$table,$database,$mysqli);
|
|
208
|
+
|
198
|
209
|
$table = $this->applyWhitelistAndBlacklist($table,$action,$whitelist,$blacklist);
|
199
|
210
|
|
200
|
211
|
$object = $this->retrieveObject($key,$table,$mysqli);
|
201
|
212
|
$input = json_decode(file_get_contents('php://input'));
|
202
|
213
|
|
203
|
|
- return compact('action','table','key','callback','page','filter','match','mysqli','object','input');
|
|
214
|
+ return compact('action','table','key','callback','page','filter','match','order','mysqli','object','input');
|
204
|
215
|
}
|
205
|
216
|
|
206
|
217
|
private function listCommand($parameters) {
|
|
@@ -223,6 +234,7 @@ class MySQL_CRUD_API {
|
223
|
234
|
echo '"columns":';
|
224
|
235
|
$sql = "SELECT * FROM `$table`";
|
225
|
236
|
if ($t==0 && is_array($filter)) $sql .= " WHERE `$filter[0]` $filter[2] $filter[1]";
|
|
237
|
+ if ($t==0 && is_array($order)) $sql .= " ORDER BY `$order[0]` $order[1]";
|
226
|
238
|
if ($t==0 && is_array($page)) $sql .= " LIMIT $page[1] OFFSET $page[0]";
|
227
|
239
|
if ($result = $mysqli->query($sql)) {
|
228
|
240
|
$fields = array();
|