diff --git a/assets/js/src/newsletters/listings/standard.jsx b/assets/js/src/newsletters/listings/standard.jsx
index 39241dad4e..2bdc654778 100644
--- a/assets/js/src/newsletters/listings/standard.jsx
+++ b/assets/js/src/newsletters/listings/standard.jsx
@@ -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({
- { newsletter.subject }
+
+ { newsletter.subject }
+
{ actions }
|
@@ -279,9 +276,6 @@ const NewsletterListStandard = React.createClass({
{ this.renderStatistics(newsletter) }
|
-
- { MailPoet.Date.format(newsletter.created_at) }
- |
{ MailPoet.Date.format(newsletter.updated_at) }
|
diff --git a/lib/Models/Newsletter.php b/lib/Models/Newsletter.php
index 27f96b6fad..c1b56a45e6 100644
--- a/lib/Models/Newsletter.php
+++ b/lib/Models/Newsletter.php
@@ -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()
- ),
- array(
- 'name' => self::STATUS_DRAFT,
- 'label' => __('Draft'),
- 'count' => Newsletter::filter('filterDraft', $data)->count()
- ),
- array(
- 'name' => self::STATUS_SENT,
- 'label' => __('Sent'),
- 'count' => Newsletter::filter('filterSent', $data)->count()
- ),
- array(
- 'name' => 'trash',
- 'label' => __('Trash'),
- 'count' => Newsletter::getTrashed()->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::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::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()
+ ->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()) {
diff --git a/lib/Models/Setting.php b/lib/Models/Setting.php
index 4d3c807806..19874a8bbd 100644
--- a/lib/Models/Setting.php
+++ b/lib/Models/Setting.php
@@ -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
)
);
}