Compare commits

...

7 Commits

16 changed files with 84 additions and 60 deletions

View File

@ -89,10 +89,17 @@ function(
if(this.props.field['selected'] !== undefined) {
return this.props.field['selected'](this.props.item);
} else if(this.props.item !== undefined && this.props.field.name !== undefined) {
return this.props.item[this.props.field.name];
} else {
return null;
if (this.allowMultipleValues()) {
if (Array.isArray(this.props.item[this.props.field.name])) {
return this.props.item[this.props.field.name].map(function(item) {
return item.id;
});
}
} else {
return this.props.item[this.props.field.name];
}
}
return null;
},
loadCachedItems: function() {
if(typeof(window['mailpoet_'+this.props.field.endpoint]) !== 'undefined') {

View File

@ -40,11 +40,7 @@ define(
return !!(!segment.deleted_at);
},
getLabel: function(segment) {
var name = segment.name;
if (segment.subscribers > 0) {
name += ' (%$1s)'.replace('%$1s', parseInt(segment.subscribers).toLocaleString());
}
return name;
return segment.name + ' (' + parseInt(segment.subscribers).toLocaleString() + ')';
},
validation: {
'data-parsley-required': true,

View File

@ -346,11 +346,7 @@ define(
return !!(!segment.deleted_at);
},
getLabel: function(segment) {
var name = segment.name;
if (segment.subscribers > 0) {
name += ' (%$1s)'.replace('%$1s', parseInt(segment.subscribers).toLocaleString());
}
return name;
return segment.name + ' (' + parseInt(segment.subscribers).toLocaleString() + ')';
},
validation: {
'data-parsley-required': true,

View File

@ -27,10 +27,7 @@ const events = {
const availableSegmentValues = _.object(_.map(
availableSegments,
function(segment) {
let name = segment.name;
if (segment.subscribers > 0) {
name += ' (%$1s)'.replace('%$1s', parseInt(segment.subscribers).toLocaleString());
}
let name = segment.name + ' (' + parseInt(segment.subscribers).toLocaleString() + ')';
return [segment.id, name];
}
));

View File

@ -75,6 +75,9 @@ define(
filter: function(segment) {
return !!(!segment.deleted_at && segment.type === 'default');
},
getLabel: function(segment) {
return segment.name + ' ('+ segment.subscribers +')';
},
getSearchLabel: function(segment, subscriber) {
let label = '';

View File

@ -530,15 +530,11 @@ define(
width: '20em',
templateResult: function (item) {
item.subscriberCount = parseInt(item.subscriberCount);
return (item.subscriberCount > 0)
? item.name + ' (' + item.subscriberCount.toLocaleString() + ')'
: item.name;
return item.name + ' (' + item.subscriberCount.toLocaleString() + ')';
},
templateSelection: function (item) {
item.subscriberCount = parseInt(item.subscriberCount);
return (item.subscriberCount > 0)
? item.name + ' (' + item.subscriberCount.toLocaleString() + ')'
: item.name;
return item.name + ' (' + item.subscriberCount.toLocaleString() + ')';
}
})
.change(function () {

View File

@ -259,7 +259,7 @@ class Menu {
$data = array(
'settings' => $settings,
'segments' => Segment::getPublic()->findArray(),
'segments' => Segment::getSegmentsWithSubscriberCount(),
'cron_trigger' => CronTrigger::getAvailableMethods(),
'pages' => Pages::getAll(),
'flags' => $flags,
@ -303,7 +303,7 @@ class Menu {
$data = array();
$data['items_per_page'] = $this->getLimitPerPage('subscribers');
$data['segments'] = Segment::findArray();
$data['segments'] = Segment::getSegmentsWithSubscriberCount($type = false);
$data['custom_fields'] = array_map(function($field) {
$field['params'] = unserialize($field['params']);
@ -416,7 +416,7 @@ class Menu {
$data = array(
'form' => $form,
'pages' => Pages::getAll(),
'segments' => Segment::getPublic()->findArray(),
'segments' => Segment::getSegmentsWithSubscriberCount(),
'styles' => FormRenderer::getStyles($form),
'date_types' => Block\Date::getDateTypes(),
'date_formats' => Block\Date::getDateFormats(),

View File

@ -143,7 +143,41 @@ class Segment extends Model {
$query = self::selectMany(array(self::$_table.'.id', self::$_table.'.name'))
->selectExpr(
self::$_table.'.*, ' .
'COUNT(IF('.MP_SUBSCRIBER_SEGMENT_TABLE.'.status="' . Subscriber::STATUS_SUBSCRIBED .'" AND '.MP_SUBSCRIBERS_TABLE.'.deleted_at IS NULL,1,NULL)) `subscribers`'
'COUNT(IF('.
MP_SUBSCRIBER_SEGMENT_TABLE.'.status="'.Subscriber::STATUS_SUBSCRIBED.'"'
.' AND '.
MP_SUBSCRIBERS_TABLE.'.deleted_at IS NULL'
.' AND '.
MP_SUBSCRIBERS_TABLE.'.status="'.Subscriber::STATUS_SUBSCRIBED.'"'
.', 1, NULL)) `subscribers`'
)
->leftOuterJoin(
MP_SUBSCRIBER_SEGMENT_TABLE,
array(self::$_table.'.id', '=', MP_SUBSCRIBER_SEGMENT_TABLE.'.segment_id'))
->leftOuterJoin(
MP_SUBSCRIBERS_TABLE,
array(MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id', '=', MP_SUBSCRIBERS_TABLE.'.id'))
->groupBy(self::$_table.'.id')
->groupBy(self::$_table.'.name')
->orderByAsc(self::$_table.'.name')
->whereNull(self::$_table.'.deleted_at');
if(!empty($type)) {
$query->where(self::$_table.'.type', $type);
}
return $query->findArray();
}
static function getSegmentsForImport() {
$query = self::selectMany(array(self::$_table.'.id', self::$_table.'.name'))
->selectExpr(
self::$_table.'.*, ' .
'COUNT(IF('.
MP_SUBSCRIBER_SEGMENT_TABLE.'.status="'.Subscriber::STATUS_SUBSCRIBED.'"'
.' AND '.
MP_SUBSCRIBERS_TABLE.'.deleted_at IS NULL'
.', 1, NULL)) `subscribers`'
)
->leftOuterJoin(
MP_SUBSCRIBER_SEGMENT_TABLE,

View File

@ -75,6 +75,10 @@ class Subscriber extends Model {
function sendConfirmationEmail() {
$signup_confirmation = Setting::getValue('signup_confirmation');
if((bool)$signup_confirmation['enabled'] === false) {
return false;
}
$segments = $this->segments()->findMany();
$segment_names = array_map(function($segment) {
return $segment->name;

View File

@ -14,7 +14,7 @@ class ImportExportFactory {
function getSegments($with_confirmed_subscribers = false) {
$segments = ($this->action === 'import') ?
Segment::getSegmentsWithSubscriberCount() :
Segment::getSegmentsForImport() :
Segment::getSegmentsForExport($with_confirmed_subscribers);
return array_map(function($segment) {
if(!$segment['name']) $segment['name'] = __('Not In List');

View File

@ -4,7 +4,7 @@ if(!defined('ABSPATH')) exit;
use \MailPoet\Config\Initializer;
/*
* Plugin Name: MailPoet
* Version: 0.0.46
* Version: 0.0.47
* Plugin URI: http://www.mailpoet.com
* Description: MailPoet Newsletters.
* Author: MailPoet
@ -22,7 +22,7 @@ use \MailPoet\Config\Initializer;
require 'vendor/autoload.php';
define('MAILPOET_VERSION', '0.0.46');
define('MAILPOET_VERSION', '0.0.47');
$initializer = new Initializer(array(
'file' => __FILE__,

View File

@ -18,13 +18,13 @@ class SegmentTest extends MailPoetTest {
array(
'first_name' => 'John',
'last_name' => 'Mailer',
'status' => 'unsubscribed',
'status' => Subscriber::STATUS_UNSUBSCRIBED,
'email' => 'john@mailpoet.com'
),
array(
'first_name' => 'Mike',
'last_name' => 'Smith',
'status' => 'subscribed',
'status' => Subscriber::STATUS_SUBSCRIBED,
'email' => 'mike@maipoet.com'
)
);
@ -168,8 +168,8 @@ class SegmentTest extends MailPoetTest {
$association->segment_id = $this->segment->id;
$association->save();
}
$segment = Segment::getSegmentsWithSubscriberCount();
expect($segment[0]['subscribers'])->equals(2);
$segments = Segment::getSegmentsWithSubscriberCount();
expect($segments[0]['subscribers'])->equals(1);
}
function testItCanGetSegmentsForExport() {

View File

@ -14,14 +14,14 @@ class ImportExportFactoryTest extends MailPoetTest {
$subscriber_1 = Subscriber::createOrUpdate(array(
'first_name' => 'John',
'last_name' => 'Mailer',
'status' => 'unconfirmed',
'status' => Subscriber::STATUS_UNCONFIRMED,
'email' => 'john@mailpoet.com'
));
$subscriber_2 = Subscriber::createOrUpdate(array(
'first_name' => 'Mike',
'last_name' => 'Smith',
'status' => 'subscribed',
'status' => Subscriber::STATUS_SUBSCRIBED,
'email' => 'mike@maipoet.com'
));

View File

@ -58,7 +58,7 @@
required
>
<% for segment in segments %>
<option value="<%= segment.id %>"><%= segment.name %></option>
<option value="<%= segment.id %>"><%= segment.name %> (<%= segment.subscribers %>)</option>
<% endfor %>
</select>
</div>

View File

@ -132,7 +132,7 @@
<% if(segment.id in settings.subscribe.on_comment.segments) %>
selected="selected"
<% endif %>
><%= segment.name %></option>
><%= segment.name %> (<%= segment.subscribers %>)</option>
<% endfor %>
</select>
</p>
@ -196,7 +196,7 @@
<% if(segment.id in settings.subscribe.on_register.segments) %>
selected="selected"
<% endif %>
><%= segment.name %></option>
><%= segment.name %> (<%= segment.subscribers %>)</option>
<% endfor %>
</select>
</p>
@ -257,7 +257,7 @@
<% if(segment.id in settings.subscription.segments) %>
selected="selected"
<% endif %>
><%= segment.name %></option>
><%= segment.name %> (<%= segment.subscribers %>)</option>
<% endfor %>
</select>
</p>
@ -330,7 +330,7 @@
multiple
>
<% for segment in segments %>
<option value="<%= segment.id %>"><%= segment.name %></option>
<option value="<%= segment.id %>"><%= segment.name %> (<%= segment.subscribers %>)</option>
<% endfor %>
</select>
</p>
@ -366,7 +366,7 @@
multiple
>
<% for segment in segments %>
<option value="<%= segment.id %>"><%= segment.name %></option>
<option value="<%= segment.id %>"><%= segment.name %> (<%= segment.subscribers %>)</option>
<% endfor %>
</select>
</p>

View File

@ -23,6 +23,15 @@
<div id="mailpoet-changelog" clas="feature-section one-col">
<h2><%= __("List of Changes") %></h2>
<h3>0.0.47 - 2016-10-04</h3>
<ul>
<li>Fixed subscription form to not send confirmation email when sending one is disabled in settings;</li>
<li>Fixed segment selection field to preselect previously used segments on last newsletter creation step;</li>
<li>Fixed segment subscriber count to be always displayed;</li>
<li>Changed segment subscriber count to not include unsubscribed or unconfirmed subscribers.</li>
</ul>
<br>
<h3>0.0.46 - 2016-09-27</h3>
<ul>
<li>Fixed subscription forms.</li>
@ -31,24 +40,6 @@
</ul>
<br>
<h3>0.0.45 - 2016-09-20</h3>
<ul>
<li>Refactored Cron Scheduler worker and added unit tests.</li>
<li>Fixed some language strings.</li>
</ul>
<br>
<h3>0.0.44 - 2016-09-13</h3>
<ul>
<li>Updated API response formats for Forms, Newsletters, Segments, Subscribers.</li>
<li>Fixed "Subject" and "Email preview" text in newsletter editor.</li>
<li>Added unit tests for Cron.</li>
<li>Fixed class instantiation issues for PHP 5.3.</li>
<li>Updated links to KB articles.</li>
<li>Added a subscribers limit of 2000 subscribers.</li>
</ul>
<br>
</div>
<hr>