Subscriber Edit page
This commit is contained in:
@@ -10,6 +10,17 @@ class Subscribers {
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : 0);
|
||||
|
||||
$subscriber = Subscriber::findOne($id);
|
||||
if($subscriber === false) {
|
||||
wp_send_json(false);
|
||||
} else {
|
||||
wp_send_json($subscriber->asArray());
|
||||
}
|
||||
}
|
||||
|
||||
function listing($data = array()) {
|
||||
$listing = new Listing\Handler(
|
||||
\Model::factory('\MailPoet\Models\Subscriber'),
|
||||
$data
|
||||
@@ -18,23 +29,33 @@ class Subscribers {
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
$collection = Subscriber::find_array();
|
||||
$collection = Subscriber::findArray();
|
||||
wp_send_json($collection);
|
||||
}
|
||||
|
||||
function save($args) {
|
||||
$model = Subscriber::create();
|
||||
$model->hydrate($args);
|
||||
$saved = $model->save();
|
||||
function save($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : 0);
|
||||
|
||||
if(!$saved) {
|
||||
wp_send_json($model->getValidationErrors());
|
||||
if($id > 0) {
|
||||
// update
|
||||
$model = Subscriber::findOne($id);
|
||||
$model->hydrate($data);
|
||||
$saved = $model->save();
|
||||
} else {
|
||||
// new
|
||||
$model = Subscriber::create();
|
||||
$model->hydrate($data);
|
||||
$saved = $model->save();
|
||||
}
|
||||
|
||||
wp_send_json(true);
|
||||
if($saved === false) {
|
||||
wp_send_json($model->getValidationErrors());
|
||||
} else {
|
||||
wp_send_json(true);
|
||||
}
|
||||
}
|
||||
|
||||
function update($args) {
|
||||
function update($data) {
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user