Skip to content

Commit e7af510

Browse files
committed
Sort parameters
1 parent 2df9e73 commit e7af510

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

admin/component/orders.php

+23-11
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@
2929

3030
class Orders extends ComponentBase {
3131
public static $defaultOptions = [
32-
'start' => 0,
33-
'limit' => 10,
34-
'language_id' => NULL,
35-
'site_id' => NULL,
36-
'user_id' => NULL,
37-
'email' => NULL,
38-
'phone_number' => NULL,
39-
'search' => NULL,
40-
'id_manufacturer' => NULL,
41-
'order_status' => NULL,
42-
'order_status_id' => NULL,
32+
'start' => 0,
33+
'limit' => 10,
34+
'language_id' => NULL,
35+
'site_id' => NULL,
36+
'user_id' => NULL,
37+
'email' => NULL,
38+
'phone_number' => NULL,
39+
'search' => NULL,
40+
'id_manufacturer' => NULL,
41+
'order_status' => NULL,
42+
'order_status_id' => NULL,
43+
'order_by' => NULL,
44+
'direction' => ['url', 'asc', 'desc'],
4345
];
4446

4547
public $options = [];
@@ -49,6 +51,16 @@ function results() {
4951

5052
$results = $orders->getAll($this->options);
5153

54+
if (isset($this->options['order_by']) &&
55+
! in_array($this->options['order_by'], ['order_id', 'customer_order_id', 'order_status_id', 'created_at'])) {
56+
unset($this->options['order_by']);
57+
}
58+
59+
if (isset($this->options['direction']) &&
60+
! in_array($this->options['direction'], ['asc', 'desc'])) {
61+
unset($this->options['direction']);
62+
}
63+
5264
if ($results['order']) {
5365
$currency = Currency::getInstance();
5466

admin/component/users.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929

3030
class Users extends ComponentBase {
3131
public static $defaultOptions = [
32-
'start' => 0,
33-
'limit' => 10,
34-
'site_id' => null,
35-
'user_id' => 'url',
36-
'user' => ['url', 'price asc'],
37-
'id' => NULL,
32+
'start' => 0,
33+
'limit' => 10,
34+
'site_id' => null,
35+
'user_id' => 'url',
36+
'user' => ['url', 'price asc'],
37+
'order_by' => NULL,
38+
'direction' => ['url', 'asc', 'desc'],
3839
];
3940

4041
public $options = [];
@@ -44,6 +45,16 @@ function results() {
4445

4546
$results = $users->getAll($this->options);
4647

48+
if (isset($this->options['order_by']) &&
49+
! in_array($this->options['order_by'], ['user_id', 'created_at', 'email', 'username'])) {
50+
unset($this->options['order_by']);
51+
}
52+
53+
if (isset($this->options['direction']) &&
54+
! in_array($this->options['direction'], ['asc', 'desc'])) {
55+
unset($this->options['direction']);
56+
}
57+
4758
if (isset($results['user'])) {
4859
foreach ($results['user'] as $id => &$user) {
4960
if (isset($user['images'])) {

0 commit comments

Comments
 (0)