fixed widget + test + split get method in sub router
This commit is contained in:
committed by
marco
parent
703fd17932
commit
d81c4e7aa1
@@ -9,8 +9,9 @@ class Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
add_action('widgets_init', array($this, 'registerWidget'));
|
||||||
|
|
||||||
if(!is_admin()) {
|
if(!is_admin()) {
|
||||||
add_action('widgets_init', array($this, 'registerWidget'));
|
|
||||||
add_action('widgets_init', array($this, 'setupActions'));
|
add_action('widgets_init', array($this, 'setupActions'));
|
||||||
add_action('widgets_init', array($this, 'setupDependencies'));
|
add_action('widgets_init', array($this, 'setupDependencies'));
|
||||||
}
|
}
|
||||||
|
@@ -8,34 +8,41 @@ class Subscribers {
|
|||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get() {
|
function get($data = array()) {
|
||||||
if(isset($_POST['data'])) {
|
$offset = (isset($data['offset']) ? (int)$data['offset'] : 0);
|
||||||
$data = $_POST['data'];
|
$limit = (isset($data['limit']) ? (int)$data['limit'] : 50);
|
||||||
$offset = (isset($data['offset']) ? (int)$data['offset'] : 0);
|
$search = (isset($data['search']) ? $data['search'] : null);
|
||||||
$limit = (isset($data['limit']) ? (int)$data['limit'] : 50);
|
$sort_by = (isset($data['sort_by']) ? $data['sort_by'] : 'id');
|
||||||
$search = (isset($data['search']) ? $data['search'] : null);
|
$sort_order = (isset($data['sort_order']) ? $data['sort_order'] : 'desc');
|
||||||
$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) {
|
if($search !== null) {
|
||||||
$collection->where_raw(
|
$collection->where_raw(
|
||||||
'(`email` LIKE ? OR `first_name` LIKE ? OR `last_name` LIKE ?)',
|
'(`email` LIKE ? OR `first_name` LIKE ? OR `last_name` LIKE ?)',
|
||||||
array('%'.$search.'%', '%'.$search.'%', '%'.$search.'%')
|
array('%'.$search.'%', '%'.$search.'%', '%'.$search.'%')
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$collection = array(
|
|
||||||
'count' => $collection->count(),
|
|
||||||
'items' => $collection
|
|
||||||
->offset($offset)
|
|
||||||
->limit($limit)
|
|
||||||
->find_array()
|
|
||||||
);
|
);
|
||||||
} 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);
|
wp_send_json($collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user