fixed widget + test + split get method in sub router
This commit is contained in:
committed by
marco
parent
703fd17932
commit
d81c4e7aa1
@@ -8,34 +8,41 @@ class Subscribers {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function get() {
|
||||
if(isset($_POST['data'])) {
|
||||
$data = $_POST['data'];
|
||||
$offset = (isset($data['offset']) ? (int)$data['offset'] : 0);
|
||||
$limit = (isset($data['limit']) ? (int)$data['limit'] : 50);
|
||||
$search = (isset($data['search']) ? $data['search'] : null);
|
||||
$sort_by = (isset($data['sort_by']) ? $data['sort_by'] : 'id');
|
||||
$sort_order = (isset($data['sort_order']) ? $data['sort_order'] : 'desc');
|
||||
function get($data = array()) {
|
||||
$offset = (isset($data['offset']) ? (int)$data['offset'] : 0);
|
||||
$limit = (isset($data['limit']) ? (int)$data['limit'] : 50);
|
||||
$search = (isset($data['search']) ? $data['search'] : null);
|
||||
$sort_by = (isset($data['sort_by']) ? $data['sort_by'] : 'id');
|
||||
$sort_order = (isset($data['sort_order']) ? $data['sort_order'] : 'desc');
|
||||
|
||||
$collection = Subscriber::{'order_by_'.$sort_order}($sort_by);
|
||||
$collection = Subscriber::{'order_by_'.$sort_order}($sort_by);
|
||||
|
||||
if($search !== null) {
|
||||
$collection->where_raw(
|
||||
'(`email` LIKE ? OR `first_name` LIKE ? OR `last_name` LIKE ?)',
|
||||
array('%'.$search.'%', '%'.$search.'%', '%'.$search.'%')
|
||||
);
|
||||
}
|
||||
|
||||
$collection = array(
|
||||
'count' => $collection->count(),
|
||||
'items' => $collection
|
||||
->offset($offset)
|
||||
->limit($limit)
|
||||
->find_array()
|
||||
if($search !== null) {
|
||||
$collection->where_raw(
|
||||
'(`email` LIKE ? OR `first_name` LIKE ? OR `last_name` LIKE ?)',
|
||||
array('%'.$search.'%', '%'.$search.'%', '%'.$search.'%')
|
||||
);
|
||||
} else {
|
||||
$collection = Subscriber::find_array();
|
||||
}
|
||||
|
||||
// filters
|
||||
$filters = array(
|
||||
|
||||
);
|
||||
|
||||
$collection = array(
|
||||
'count' => $collection->count(),
|
||||
'filters' => $filters,
|
||||
'items' => $collection
|
||||
->offset($offset)
|
||||
->limit($limit)
|
||||
->find_array()
|
||||
);
|
||||
|
||||
wp_send_json($collection);
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
$collection = Subscriber::find_array();
|
||||
wp_send_json($collection);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user