Major refactoring of listing/router/model relation
- updated Subscribers listing - udpated Segments listing - added Forms router
This commit is contained in:
@@ -5,15 +5,17 @@ if(!defined('ABSPATH')) exit;
|
||||
|
||||
class BulkAction {
|
||||
private $listing = null;
|
||||
private $action = null;
|
||||
private $data = null;
|
||||
private $model_class = null;
|
||||
|
||||
function __construct($model_class, $data) {
|
||||
$this->model_class = $model_class;
|
||||
$this->action = $data['action'];
|
||||
unset($data['action']);
|
||||
$this->data = $data;
|
||||
|
||||
$this->model_class = $model_class;
|
||||
$this->listing = new Handler(
|
||||
$this->model_class,
|
||||
$model_class,
|
||||
$this->data['listing']
|
||||
);
|
||||
return $this;
|
||||
@@ -21,8 +23,9 @@ class BulkAction {
|
||||
|
||||
function apply() {
|
||||
return call_user_func_array(
|
||||
array($this->model_class, $this->data['action']),
|
||||
array($this->listing, $this->data)
|
||||
array($this->model_class, 'bulk'.ucfirst($this->action)),
|
||||
array($this->listing->getSelection(), $this->data)
|
||||
);
|
||||
return $models->count();
|
||||
}
|
||||
}
|
@@ -4,16 +4,13 @@ namespace MailPoet\Listing;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Handler {
|
||||
|
||||
private $data = array();
|
||||
private $model = null;
|
||||
|
||||
function __construct($model_class, $data = array()) {
|
||||
$class = new \ReflectionClass($model_class);
|
||||
$this->table_name = $class->getStaticPropertyValue('_table');
|
||||
|
||||
$this->model = \Model::factory($model_class);
|
||||
|
||||
$this->model = $model_class::select('*');
|
||||
$this->data = array(
|
||||
// pagination
|
||||
'offset' => (isset($data['offset']) ? (int)$data['offset'] : 0),
|
||||
@@ -31,7 +28,7 @@ class Handler {
|
||||
'selection' => (isset($data['selection']) ? $data['selection'] : null)
|
||||
);
|
||||
|
||||
$this->model = $this->setFilter();
|
||||
$this->setFilter();
|
||||
$this->setSearch();
|
||||
$this->setGroup();
|
||||
$this->setOrder();
|
||||
@@ -59,9 +56,9 @@ class Handler {
|
||||
|
||||
private function setFilter() {
|
||||
if($this->data['filter'] === null) {
|
||||
return $this->model;
|
||||
return;
|
||||
}
|
||||
return $this->model->filter('filterBy', $this->data['filter']);
|
||||
$this->model = $this->model->filter('filterBy', $this->data['filter']);
|
||||
}
|
||||
|
||||
function getSelection() {
|
||||
|
36
lib/Listing/ItemAction.php
Normal file
36
lib/Listing/ItemAction.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace MailPoet\Listing;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class ItemAction {
|
||||
private $model = null;
|
||||
private $action = null;
|
||||
private $data = null;
|
||||
|
||||
function __construct($model_class, $data) {
|
||||
$id = (int)$data['id'];
|
||||
unset($data['id']);
|
||||
$this->action = $data['action'];
|
||||
unset($data['action']);
|
||||
$this->model = $model_class::findOne($id);
|
||||
if(!empty($data)) {
|
||||
$this->data = $data;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
function apply() {
|
||||
if($this->data === null) {
|
||||
return call_user_func_array(
|
||||
array($this->model, $this->action),
|
||||
array()
|
||||
);
|
||||
} else {
|
||||
return call_user_func_array(
|
||||
array($this->model, $this->action),
|
||||
array($this->data)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,6 +9,10 @@ class Model extends \Sudzy\ValidModel {
|
||||
parent::__construct($customValidators->init());
|
||||
}
|
||||
|
||||
static function create() {
|
||||
return parent::create();
|
||||
}
|
||||
|
||||
function save() {
|
||||
$this->setTimestamp();
|
||||
try {
|
||||
@@ -21,29 +25,54 @@ class Model extends \Sudzy\ValidModel {
|
||||
}
|
||||
}
|
||||
|
||||
static function restore($orm) {
|
||||
$models = $orm->findResultSet();
|
||||
if(empty($models)) return false;
|
||||
function trash() {
|
||||
return $this->set_expr('deleted_at', 'NOW()')->save();
|
||||
}
|
||||
|
||||
$models->setExpr('deleted_at', 'NULL')->save();
|
||||
static function bulkTrash($orm) {
|
||||
$models = $orm->findResultSet();
|
||||
$models->set_expr('deleted_at', 'NOW()')->save();
|
||||
return $models->count();
|
||||
}
|
||||
|
||||
static function trash($orm, $confirm = false) {
|
||||
$models = $orm->findResultSet();
|
||||
if(empty($models)) return false;
|
||||
|
||||
if($confirm === true) {
|
||||
foreach($models as $model) {
|
||||
$model->delete();
|
||||
}
|
||||
} else {
|
||||
$models = $orm->findResultSet();
|
||||
$models->setExpr('deleted_at', 'NOW()')->save();
|
||||
static function bulkDelete($orm) {
|
||||
$models = $orm->findMany();
|
||||
$count = 0;
|
||||
foreach($models as $model) {
|
||||
$model->delete();
|
||||
$count++;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
function restore() {
|
||||
return $this->set_expr('deleted_at', 'NULl')->save();
|
||||
}
|
||||
|
||||
static function bulkRestore($orm) {
|
||||
$models = $orm->findResultSet();
|
||||
$models->set_expr('deleted_at', 'NULL')->save();
|
||||
return $models->count();
|
||||
}
|
||||
|
||||
function duplicate($data = array()) {
|
||||
$model = get_called_class();
|
||||
$model_data = array_merge($this->asArray(), $data);
|
||||
unset($model_data['id']);
|
||||
|
||||
$duplicate = $model::create();
|
||||
$duplicate->hydrate($model_data);
|
||||
$duplicate->set_expr('created_at', 'NOW()');
|
||||
$duplicate->set_expr('updated_at', 'NOW()');
|
||||
$duplicate->set_expr('deleted_at', 'NULL');
|
||||
|
||||
if($duplicate->save()) {
|
||||
return $duplicate;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function setTimestamp() {
|
||||
if($this->created_at === null) {
|
||||
$this->set_expr('created_at', 'NOW()');
|
||||
|
@@ -143,46 +143,4 @@ class Newsletter extends Model {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static function trash($listing, $data = array()) {
|
||||
$confirm_delete = filter_var($data['confirm'], FILTER_VALIDATE_BOOLEAN);
|
||||
if($confirm_delete) {
|
||||
// delete relations with all segments
|
||||
$newsletters = $listing->getSelection()->findResultSet();
|
||||
|
||||
if(!empty($newsletters)) {
|
||||
$newsletters_count = 0;
|
||||
foreach($newsletters as $newsletter) {
|
||||
if($newsletter->delete()) {
|
||||
$newsletters_count++;
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'newsletters' => $newsletters_count
|
||||
);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
// soft delete
|
||||
$newsletters = $listing->getSelection()
|
||||
->findResultSet()
|
||||
->set_expr('deleted_at', 'NOW()')
|
||||
->save();
|
||||
|
||||
return array(
|
||||
'newsletters' => $newsletters->count()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static function restore($listing, $data = array()) {
|
||||
$newsletters = $listing->getSelection()
|
||||
->findResultSet()
|
||||
->set_expr('deleted_at', 'NULL')
|
||||
->save();
|
||||
|
||||
return array(
|
||||
'newsletters' => $newsletters->count()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -17,48 +17,7 @@ class Segment extends Model {
|
||||
function delete() {
|
||||
// delete all relations to subscribers
|
||||
SubscriberSegment::where('segment_id', $this->id)->deleteMany();
|
||||
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
static function duplicate($id) {
|
||||
$segment = self::findOne($id)->asArray();
|
||||
|
||||
if($segment !== false) {
|
||||
unset($segment['id']);
|
||||
$new_segment = self::create();
|
||||
$new_segment->hydrate($segment);
|
||||
|
||||
$new_segment->set(
|
||||
'name',
|
||||
sprintf(__('Copy of %s'), $new_segment->name)
|
||||
);
|
||||
$new_segment->set_expr('created_at', 'NOW()');
|
||||
$new_segment->set_expr('updated_at', 'NOW()');
|
||||
$new_segment->save();
|
||||
|
||||
$relations = SubscriberSegment::select('subscriber_id')
|
||||
->where('segment_id', $id)
|
||||
->findResultSet();
|
||||
|
||||
foreach($relations as $relation) {
|
||||
$new_relation = SubscriberSegment::create();
|
||||
$new_relation->set('subscriber_id', $relation->subscriber_id);
|
||||
$new_relation->set('segment_id', $new_segment->id());
|
||||
$new_relation->save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function subscribers() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__.'\Subscriber',
|
||||
__NAMESPACE__.'\SubscriberSegment',
|
||||
'segment_id',
|
||||
'subscriber_id'
|
||||
);
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
function newsletters() {
|
||||
@@ -125,45 +84,28 @@ class Segment extends Model {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function trash($listing, $data = array()) {
|
||||
$confirm_delete = filter_var($data['confirm'], FILTER_VALIDATE_BOOLEAN);
|
||||
if($confirm_delete) {
|
||||
// delete relations with all segments
|
||||
$segments = $listing->getSelection()->findResultSet();
|
||||
function duplicate($data = array()) {
|
||||
$duplicate = parent::duplicate($data);
|
||||
|
||||
if(!empty($segments)) {
|
||||
$segments_count = 0;
|
||||
foreach($segments as $segment) {
|
||||
if($segment->delete()) {
|
||||
$segments_count++;
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'segments' => $segments_count
|
||||
);
|
||||
if($duplicate !== false) {
|
||||
foreach($this->subscribers()->findResultSet() as $relation) {
|
||||
$new_relation = SubscriberSegment::create();
|
||||
$new_relation->set('subscriber_id', $relation->id);
|
||||
$new_relation->set('segment_id', $duplicate->id);
|
||||
$new_relation->save();
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
// soft delete
|
||||
$segments = $listing->getSelection()
|
||||
->findResultSet()
|
||||
->set_expr('deleted_at', 'NOW()')
|
||||
->save();
|
||||
|
||||
return array(
|
||||
'segments' => $segments->count()
|
||||
);
|
||||
return $duplicate;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static function restore($listing, $data = array()) {
|
||||
$segments = $listing->getSelection()
|
||||
->findResultSet()
|
||||
->set_expr('deleted_at', 'NULL')
|
||||
->save();
|
||||
|
||||
return array(
|
||||
'segments' => $segments->count()
|
||||
function subscribers() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__.'\Subscriber',
|
||||
__NAMESPACE__.'\SubscriberSegment',
|
||||
'segment_id',
|
||||
'subscriber_id'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ class Subscriber extends Model {
|
||||
if($key === 'segment') {
|
||||
$segment = Segment::findOne($value);
|
||||
if($segment !== false) {
|
||||
$orm = $segment->subscribers();
|
||||
return $segment->subscribers();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,12 +189,11 @@ class Subscriber extends Model {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function moveToList($listing, $data = array()) {
|
||||
static function bulkMoveToList($orm, $data = array()) {
|
||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||
$segment = Segment::findOne($segment_id);
|
||||
if($segment !== false) {
|
||||
$subscribers_count = 0;
|
||||
$subscribers = $listing->getSelection()->findResultSet();
|
||||
$subscribers = $orm->findResultSet();
|
||||
foreach($subscribers as $subscriber) {
|
||||
// remove subscriber from all segments
|
||||
SubscriberSegment::where('subscriber_id', $subscriber->id)->deleteMany();
|
||||
@@ -204,37 +203,37 @@ class Subscriber extends Model {
|
||||
$association->subscriber_id = $subscriber->id;
|
||||
$association->segment_id = $segment->id;
|
||||
$association->save();
|
||||
|
||||
$subscribers_count++;
|
||||
}
|
||||
return array(
|
||||
'subscribers' => $subscribers_count,
|
||||
'subscribers' => $subscribers->count(),
|
||||
'segment' => $segment->name
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static function removeFromList($listing, $data = array()) {
|
||||
static function bulkRemoveFromList($orm, $data = array()) {
|
||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||
$segment = Segment::findOne($segment_id);
|
||||
|
||||
if($segment !== false) {
|
||||
// delete relations with segment
|
||||
$subscriber_ids = $listing->getSelectionIds();
|
||||
SubscriberSegment::whereIn('subscriber_id', $subscriber_ids)
|
||||
->where('segment_id', $segment->id)
|
||||
->deleteMany();
|
||||
$subscribers = $orm->findResultSet();
|
||||
foreach($subscribers as $subscriber) {
|
||||
SubscriberSegment::where('subscriber_id', $subscriber->id)
|
||||
->where('segment_id', $segment->id)
|
||||
->deleteMany();
|
||||
}
|
||||
|
||||
return array(
|
||||
'subscribers' => count($subscriber_ids),
|
||||
'subscribers' => $subscribers->count(),
|
||||
'segment' => $segment->name
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static function removeFromAllLists($listing) {
|
||||
static function bulkRemoveFromAllLists($orm) {
|
||||
$segments = Segment::findMany();
|
||||
$segment_ids = array_map(function($segment) {
|
||||
return $segment->id();
|
||||
@@ -242,62 +241,48 @@ class Subscriber extends Model {
|
||||
|
||||
if(!empty($segment_ids)) {
|
||||
// delete relations with segment
|
||||
$subscriber_ids = $listing->getSelectionIds();
|
||||
SubscriberSegment::whereIn('subscriber_id', $subscriber_ids)
|
||||
->whereIn('segment_id', $segment_ids)
|
||||
->deleteMany();
|
||||
|
||||
return array(
|
||||
'subscribers' => count($subscriber_ids)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static function confirmUnconfirmed($listing) {
|
||||
$subscriber_ids = $listing->getSelectionIds();
|
||||
$subscribers = Subscriber::whereIn('id', $subscriber_ids)
|
||||
->where('status', 'unconfirmed')
|
||||
->findMany();
|
||||
|
||||
if(!empty($subscribers)) {
|
||||
$subscribers_count = 0;
|
||||
$subscribers = $orm->findResultSet();
|
||||
foreach($subscribers as $subscriber) {
|
||||
$subscriber->set('status', 'subscribed');
|
||||
if($subscriber->save() === true) {
|
||||
$subscribers_count++;
|
||||
}
|
||||
SubscriberSegment::where('subscriber_id', $subscriber->id)
|
||||
->whereIn('segment_id', $segment_ids)
|
||||
->deleteMany();
|
||||
}
|
||||
|
||||
return array(
|
||||
'subscribers' => $subscribers_count
|
||||
);
|
||||
return $subscribers->count();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static function resendConfirmationEmail($listing) {
|
||||
$subscriber_ids = $listing->getSelectionIds();
|
||||
$subscribers = Subscriber::whereIn('id', $subscriber_ids)
|
||||
static function bulkConfirmUnconfirmed($orm) {
|
||||
$subscribers = $orm->findResultSet();
|
||||
$subscribers->set('status', 'subscribed')->save();
|
||||
return $subscribers->count();
|
||||
}
|
||||
|
||||
static function bulkResendConfirmationEmail($orm) {
|
||||
$subscribers = $orm
|
||||
->where('status', 'unconfirmed')
|
||||
->findMany();
|
||||
->findResultSet();
|
||||
|
||||
if(!empty($subscribers)) {
|
||||
foreach($subscribers as $subscriber) {
|
||||
// TODO: resend confirmation email
|
||||
// TODO: send confirmation email
|
||||
// $subscriber->sendConfirmationEmail()
|
||||
}
|
||||
return true;
|
||||
|
||||
return $subscribers->count();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static function addToList($listing, $data = array()) {
|
||||
static function bulkAddToList($orm, $data = array()) {
|
||||
|
||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||
$segment = Segment::findOne($segment_id);
|
||||
|
||||
if($segment !== false) {
|
||||
$subscribers_count = 0;
|
||||
$subscribers = $listing->getSelection()->findMany();
|
||||
$subscribers = $orm->findMany();
|
||||
foreach($subscribers as $subscriber) {
|
||||
// create relation with segment
|
||||
$association = \MailPoet\Models\SubscriberSegment::create();
|
||||
@@ -314,46 +299,4 @@ class Subscriber extends Model {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static function trash($listing, $data = array()) {
|
||||
$confirm_delete = filter_var($data['confirm'], FILTER_VALIDATE_BOOLEAN);
|
||||
if($confirm_delete) {
|
||||
// delete relations with all segments
|
||||
$subscribers = $listing->getSelection()->findResultSet();
|
||||
|
||||
if(!empty($subscribers)) {
|
||||
$subscribers_count = 0;
|
||||
foreach($subscribers as $subscriber) {
|
||||
if($subscriber->delete()) {
|
||||
$subscribers_count++;
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'subscribers' => $subscribers_count
|
||||
);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
// soft delete
|
||||
$subscribers = $listing->getSelection()
|
||||
->findResultSet()
|
||||
->set_expr('deleted_at', 'NOW()')
|
||||
->save();
|
||||
|
||||
return array(
|
||||
'subscribers' => $subscribers->count()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static function restore($listing, $data = array()) {
|
||||
$subscribers = $listing->getSelection()
|
||||
->findResultSet()
|
||||
->set_expr('deleted_at', 'NULL')
|
||||
->save();
|
||||
|
||||
return array(
|
||||
'subscribers' => $subscribers->count()
|
||||
);
|
||||
}
|
||||
}
|
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