Major refactoring of listing/router/model relation
- updated Subscribers listing - udpated Segments listing - added Forms router
This commit is contained in:
95
lib/Router/Forms.php
Normal file
95
lib/Router/Forms.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace MailPoet\Router;
|
||||
use \MailPoet\Models\Form;
|
||||
use \MailPoet\Listing;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Forms {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : 0);
|
||||
|
||||
$form = Form::findOne($id);
|
||||
if($form === false) {
|
||||
wp_send_json(false);
|
||||
} else {
|
||||
wp_send_json($form->asArray());
|
||||
}
|
||||
}
|
||||
|
||||
function listing($data = array()) {
|
||||
$listing = new Listing\Handler(
|
||||
'\MailPoet\Models\Form',
|
||||
$data
|
||||
);
|
||||
|
||||
$listing_data = $listing->get();
|
||||
|
||||
wp_send_json($listing_data);
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
$collection = Form::findArray();
|
||||
wp_send_json($collection);
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
$result = Form::createOrUpdate($data);
|
||||
|
||||
if($result !== true) {
|
||||
wp_send_json($result);
|
||||
} else {
|
||||
wp_send_json(true);
|
||||
}
|
||||
}
|
||||
|
||||
function restore($id) {
|
||||
$form = Form::findOne($id);
|
||||
if($form !== false) {
|
||||
$form->set_expr('deleted_at', 'NULL');
|
||||
$result = $form->save();
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function delete($data = array()) {
|
||||
$form = Form::findOne($data['id']);
|
||||
$confirm_delete = filter_var($data['confirm'], FILTER_VALIDATE_BOOLEAN);
|
||||
if($form !== false) {
|
||||
if($confirm_delete) {
|
||||
$form->delete();
|
||||
$result = true;
|
||||
} else {
|
||||
$form->set_expr('deleted_at', 'NOW()');
|
||||
$result = $form->save();
|
||||
}
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function duplicate($id) {
|
||||
$result = false;
|
||||
|
||||
$form = Form::duplicate($id);
|
||||
if($form !== false) {
|
||||
$result = $form;
|
||||
}
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function bulk_action($data = array()) {
|
||||
$bulk_action = new Listing\BulkAction(
|
||||
'\MailPoet\Models\Form',
|
||||
$data
|
||||
);
|
||||
|
||||
wp_send_json($bulk_action->apply());
|
||||
}
|
||||
}
|
@ -66,7 +66,7 @@ class Segments {
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
$collection = Segment::find_array();
|
||||
$collection = Segment::findArray();
|
||||
wp_send_json($collection);
|
||||
}
|
||||
|
||||
@ -81,38 +81,62 @@ class Segments {
|
||||
}
|
||||
|
||||
function restore($id) {
|
||||
$result = false;
|
||||
|
||||
$segment = Segment::findOne($id);
|
||||
if($segment !== false) {
|
||||
$segment->set_expr('deleted_at', 'NULL');
|
||||
$result = $segment->save();
|
||||
} else {
|
||||
$result = false;
|
||||
$result = $segment->restore();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function delete($data = array()) {
|
||||
$segment = Segment::findOne($data['id']);
|
||||
$confirm_delete = filter_var($data['confirm'], FILTER_VALIDATE_BOOLEAN);
|
||||
function trash($id) {
|
||||
$result = false;
|
||||
|
||||
$segment = Segment::findOne($id);
|
||||
if($segment !== false) {
|
||||
if($confirm_delete) {
|
||||
$segment->delete();
|
||||
$result = true;
|
||||
} else {
|
||||
$segment->set_expr('deleted_at', 'NOW()');
|
||||
$result = $segment->save();
|
||||
}
|
||||
} else {
|
||||
$result = false;
|
||||
$result = $segment->trash();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function delete($id) {
|
||||
$result = false;
|
||||
|
||||
$segment = Segment::findOne($id);
|
||||
if($segment !== false) {
|
||||
$segment->delete();
|
||||
$result = 1;
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function duplicate($id) {
|
||||
$result = Segment::duplicate($id);
|
||||
$result = false;
|
||||
|
||||
$segment = Segment::findOne($id);
|
||||
if($segment !== false) {
|
||||
$data = array(
|
||||
'name' => sprintf(__('Copy of %s'), $segment->name)
|
||||
);
|
||||
$result = $segment->duplicate($data)->asArray();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function item_action($data = array()) {
|
||||
$item_action = new Listing\ItemAction(
|
||||
'\MailPoet\Models\Segment',
|
||||
$data
|
||||
);
|
||||
|
||||
wp_send_json($item_action->apply());
|
||||
}
|
||||
|
||||
function bulk_action($data = array()) {
|
||||
$bulk_action = new Listing\BulkAction(
|
||||
'\MailPoet\Models\Segment',
|
||||
|
@ -60,33 +60,48 @@ class Subscribers {
|
||||
}
|
||||
|
||||
function restore($id) {
|
||||
$result = false;
|
||||
|
||||
$subscriber = Subscriber::findOne($id);
|
||||
if($subscriber !== false) {
|
||||
$subscriber->set_expr('deleted_at', 'NULL');
|
||||
$result = array('subscribers' => (int)$subscriber->save());
|
||||
} else {
|
||||
$result = false;
|
||||
$result = $subscriber->restore();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function delete($data = array()) {
|
||||
$subscriber = Subscriber::findOne($data['id']);
|
||||
$confirm_delete = filter_var($data['confirm'], FILTER_VALIDATE_BOOLEAN);
|
||||
function trash($id) {
|
||||
$result = false;
|
||||
|
||||
$subscriber = Subscriber::findOne($id);
|
||||
if($subscriber !== false) {
|
||||
if($confirm_delete) {
|
||||
$subscriber->delete();
|
||||
$result = array('subscribers' => 1);
|
||||
} else {
|
||||
$subscriber->set_expr('deleted_at', 'NOW()');
|
||||
$result = array('subscribers' => (int)$subscriber->save());
|
||||
}
|
||||
} else {
|
||||
$result = false;
|
||||
$result = $subscriber->trash();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function delete($id) {
|
||||
$result = false;
|
||||
|
||||
$subscriber = Subscriber::findOne($id);
|
||||
if($subscriber !== false) {
|
||||
$subscriber->delete();
|
||||
$result = 1;
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function item_action($data = array()) {
|
||||
$item_action = new Listing\ItemAction(
|
||||
'\MailPoet\Models\Segment',
|
||||
$data
|
||||
);
|
||||
|
||||
wp_send_json($item_action->apply());
|
||||
}
|
||||
|
||||
function bulk_action($data = array()) {
|
||||
$bulk_action = new Listing\BulkAction(
|
||||
'\MailPoet\Models\Subscriber',
|
||||
|
Reference in New Issue
Block a user