Refactored filtering (groups / status / type)
- standard listing close to completion (missing item actions) - enabled tracking by default on install
This commit is contained in:
@ -75,11 +75,6 @@ var columns = [
|
||||
name: 'statistics',
|
||||
label: MailPoet.I18n.t('statistics')
|
||||
},
|
||||
{
|
||||
name: 'created_at',
|
||||
label: MailPoet.I18n.t('createdOn'),
|
||||
sortable: true
|
||||
},
|
||||
{
|
||||
name: 'updated_at',
|
||||
label: MailPoet.I18n.t('lastModifiedOn'),
|
||||
@ -266,7 +261,9 @@ const NewsletterListStandard = React.createClass({
|
||||
<div>
|
||||
<td className={ rowClasses }>
|
||||
<strong>
|
||||
<a>{ newsletter.subject }</a>
|
||||
<a href={ `?page=mailpoet-newsletter-editor&id=${ newsletter.id }` }>
|
||||
{ newsletter.subject }
|
||||
</a>
|
||||
</strong>
|
||||
{ actions }
|
||||
</td>
|
||||
@ -279,9 +276,6 @@ const NewsletterListStandard = React.createClass({
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('statistics') }>
|
||||
{ this.renderStatistics(newsletter) }
|
||||
</td>
|
||||
<td className="column-date" data-colname={ MailPoet.I18n.t('createdOn') }>
|
||||
<abbr>{ MailPoet.Date.format(newsletter.created_at) }</abbr>
|
||||
</td>
|
||||
<td className="column-date" data-colname={ MailPoet.I18n.t('lastModifiedOn') }>
|
||||
<abbr>{ MailPoet.Date.format(newsletter.updated_at) }</abbr>
|
||||
</td>
|
||||
|
@ -10,8 +10,14 @@ class Newsletter extends Model {
|
||||
const TYPE_WELCOME = 'welcome';
|
||||
const TYPE_NOTIFICATION = 'notification';
|
||||
|
||||
// standard newsletters
|
||||
const STATUS_DRAFT = 'draft';
|
||||
const STATUS_SCHEDULED = 'scheduled';
|
||||
const STATUS_SENDING = 'sending';
|
||||
const STATUS_SENT = 'sent';
|
||||
// automatic newsletters status
|
||||
const STATUS_ACTIVE = 'active';
|
||||
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
@ -34,6 +40,30 @@ class Newsletter extends Model {
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
function duplicate($data = array()) {
|
||||
$data = $this->asArray();
|
||||
unset($data['id']);
|
||||
|
||||
$duplicate = self::create();
|
||||
$duplicate->hydrate($data);
|
||||
$duplicate->set_expr('created_at', 'NOW()');
|
||||
$duplicate->set_expr('updated_at', 'NOW()');
|
||||
$duplicate->set_expr('deleted_at', 'NULL');
|
||||
|
||||
// reset status
|
||||
$duplicate->set('status', self::STATUS_DRAFT);
|
||||
|
||||
// duplicate segments linked (if need be)
|
||||
|
||||
// duplicate options (if need be)
|
||||
|
||||
if($duplicate->save()) {
|
||||
return $duplicate;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function asArray() {
|
||||
$model = parent::asArray();
|
||||
|
||||
@ -202,63 +232,129 @@ class Newsletter extends Model {
|
||||
}
|
||||
|
||||
static function groups($data = array()) {
|
||||
return array(
|
||||
$type = isset($data['tab']) ? $data['tab'] : self::TYPE_STANDARD;
|
||||
|
||||
$groups = array(
|
||||
array(
|
||||
'name' => 'all',
|
||||
'label' => __('All'),
|
||||
'count' => Newsletter::getPublished()->where('type', $data['tab'])->count()
|
||||
),
|
||||
'count' => Newsletter::getPublished()
|
||||
->filter('filterType', $type)
|
||||
->count()
|
||||
)
|
||||
);
|
||||
|
||||
switch($type) {
|
||||
case self::TYPE_STANDARD:
|
||||
$groups = array_merge($groups, array(
|
||||
array(
|
||||
'name' => self::STATUS_DRAFT,
|
||||
'label' => __('Draft'),
|
||||
'count' => Newsletter::filter('filterDraft', $data)->count()
|
||||
'count' => Newsletter::getPublished()
|
||||
->filter('filterType', $type)
|
||||
->filter('filterStatus', self::STATUS_DRAFT)
|
||||
->count()
|
||||
),
|
||||
array(
|
||||
'name' => self::STATUS_SCHEDULED,
|
||||
'label' => __('Scheduled'),
|
||||
'count' => Newsletter::getPublished()
|
||||
->filter('filterType', $type)
|
||||
->filter('filterStatus', self::STATUS_SCHEDULED)
|
||||
->count()
|
||||
),
|
||||
array(
|
||||
'name' => self::STATUS_SENDING,
|
||||
'label' => __('Sending'),
|
||||
'count' => Newsletter::getPublished()
|
||||
->filter('filterType', $type)
|
||||
->filter('filterStatus', self::STATUS_SENDING)
|
||||
->count()
|
||||
),
|
||||
array(
|
||||
'name' => self::STATUS_SENT,
|
||||
'label' => __('Sent'),
|
||||
'count' => Newsletter::filter('filterSent', $data)->count()
|
||||
'count' => Newsletter::getPublished()
|
||||
->filter('filterType', $type)
|
||||
->filter('filterStatus', self::STATUS_SENT)
|
||||
->count()
|
||||
)
|
||||
));
|
||||
break;
|
||||
|
||||
case self::TYPE_WELCOME:
|
||||
$groups = array_merge($groups, array(
|
||||
array(
|
||||
'name' => self::STATUS_DRAFT,
|
||||
'label' => __('Not active'),
|
||||
'count' => Newsletter::filter('filterType', $type)
|
||||
->filter('filterStatus', self::STATUS_DRAFT)
|
||||
->count()
|
||||
),
|
||||
array(
|
||||
'name' => self::STATUS_ACTIVE,
|
||||
'label' => __('Active'),
|
||||
'count' => Newsletter::filter('filterType', $type)
|
||||
->filter('filterStatus', self::STATUS_ACTIVE)
|
||||
->count()
|
||||
)
|
||||
));
|
||||
break;
|
||||
|
||||
case self::TYPE_NOTIFICATION:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$groups[] = array(
|
||||
'name' => 'trash',
|
||||
'label' => __('Trash'),
|
||||
'count' => Newsletter::getTrashed()->where('type', $data['tab'])->count()
|
||||
)
|
||||
'count' => Newsletter::getTrashed()
|
||||
->filter('filterType', $type)
|
||||
->count()
|
||||
);
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
static function groupBy($orm, $data = array()) {
|
||||
$type = (!empty($data['type'])) ? $data['type'] : false;
|
||||
$group = (!empty($data['group'])) ? $data['group'] : 'all';
|
||||
|
||||
switch($group) {
|
||||
case self::STATUS_DRAFT:
|
||||
$orm->filter('filterDraft', $data);
|
||||
break;
|
||||
case self::STATUS_SCHEDULED:
|
||||
case self::STATUS_SENDING:
|
||||
case self::STATUS_SENT:
|
||||
$orm->filter('filterSent', $data);
|
||||
case self::STATUS_ACTIVE:
|
||||
$orm
|
||||
->whereNull('deleted_at')
|
||||
->filter('filterType', $type)
|
||||
->filter('filterStatus', $group);
|
||||
break;
|
||||
|
||||
case 'trash':
|
||||
$orm->whereNotNull('deleted_at');
|
||||
break;
|
||||
|
||||
default:
|
||||
$orm->whereNull('deleted_at');
|
||||
}
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function filterDraft($orm, $data = array()) {
|
||||
$type = isset($data['tab']) ? $data['tab'] : self::TYPE_STANDARD;
|
||||
|
||||
return $orm
|
||||
->where('type', $type)
|
||||
->where('status', self::STATUS_DRAFT);
|
||||
static function filterStatus($orm, $status = false) {
|
||||
if($status !== false) {
|
||||
$orm->where('status', $status);
|
||||
}
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function filterSent($orm, $data = array()) {
|
||||
$type = isset($data['tab']) ? $data['tab'] : self::TYPE_STANDARD;
|
||||
|
||||
return $orm
|
||||
->where('type', $type)
|
||||
->where('status', self::STATUS_SENT);
|
||||
static function filterType($orm, $type = false) {
|
||||
if($type !== false) {
|
||||
$orm->where('type', $type);
|
||||
}
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function listingQuery($data = array()) {
|
||||
|
@ -41,7 +41,10 @@ class Setting extends Model {
|
||||
'signup_confirmation' => array(
|
||||
'enabled' => true,
|
||||
'subject' => sprintf(__('Confirm your subscription to %1$s'), get_option('blogname')),
|
||||
'body' => __("Hello!\n\nHurray! You've subscribed to our site.\n\nPlease confirm your subscription to the list(s): [lists_to_confirm] by clicking the link below: \n\n[activation_link]Click here to confirm your subscription.[/activation_link]\n\nThank you,\n\nThe team!")
|
||||
'body' => __("Hello!\n\nHurray! You've subscribed to our site.\n\nPlease confirm your subscription to the list(s): [lists_to_confirm] by clicking the link below: \n\n[activation_link]Click here to confirm your subscription.[/activation_link]\n\nThank you,\n\nThe Team")
|
||||
),
|
||||
'tracking' => array(
|
||||
'enabled' => true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user