Added "Subscribers without a segment" filter
- removed useless dependency in filters.jsx - fixed issue with Router\Subscribers::save() not updating segments
This commit is contained in:
@ -1,12 +1,10 @@
|
|||||||
define([
|
define([
|
||||||
'react',
|
'react',
|
||||||
'jquery',
|
'jquery'
|
||||||
'mailpoet'
|
|
||||||
],
|
],
|
||||||
function(
|
function(
|
||||||
React,
|
React,
|
||||||
jQuery,
|
jQuery
|
||||||
MailPoet
|
|
||||||
) {
|
) {
|
||||||
var ListingFilters = React.createClass({
|
var ListingFilters = React.createClass({
|
||||||
handleFilterAction: function() {
|
handleFilterAction: function() {
|
||||||
|
@ -33,12 +33,17 @@ class Subscriber extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addToSegments(array $segment_ids = array()) {
|
function addToSegments(array $segment_ids = array()) {
|
||||||
$segments = Segment::whereIn('id', $segment_ids)->findMany();
|
// delete all relations to segments
|
||||||
foreach($segments as $segment) {
|
SubscriberSegment::where('subscriber_id', $this->id)->deleteMany();
|
||||||
$association = SubscriberSegment::create();
|
|
||||||
$association->subscriber_id = $this->id;
|
if(!empty($segment_ids)) {
|
||||||
$association->segment_id = $segment->id;
|
$segments = Segment::whereIn('id', $segment_ids)->findMany();
|
||||||
$association->save();
|
foreach($segments as $segment) {
|
||||||
|
$association = SubscriberSegment::create();
|
||||||
|
$association->subscriber_id = $this->id;
|
||||||
|
$association->segment_id = $segment->id;
|
||||||
|
$association->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,20 +97,22 @@ class Subscriber extends Model {
|
|||||||
$segments = Segment::orderByAsc('name')->findMany();
|
$segments = Segment::orderByAsc('name')->findMany();
|
||||||
$segment_list = array();
|
$segment_list = array();
|
||||||
$segment_list[] = array(
|
$segment_list[] = array(
|
||||||
'label' => __('All lists'),
|
'label' => __('All segments'),
|
||||||
'value' => ''
|
'value' => ''
|
||||||
);
|
);
|
||||||
|
$segment_list[] = array(
|
||||||
|
'label' => __('Subscribers without a segment'),
|
||||||
|
'value' => 'none'
|
||||||
|
);
|
||||||
|
|
||||||
foreach($segments as $segment) {
|
foreach($segments as $segment) {
|
||||||
$subscribers_count = $segment->subscribers()
|
$subscribers_count = $segment->subscribers()
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->count();
|
->count();
|
||||||
if($subscribers_count > 0) {
|
$segment_list[] = array(
|
||||||
$segment_list[] = array(
|
'label' => sprintf('%s (%d)', $segment->name, $subscribers_count),
|
||||||
'label' => sprintf('%s (%d)', $segment->name, $subscribers_count),
|
'value' => $segment->id()
|
||||||
'value' => $segment->id()
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$filters = array(
|
$filters = array(
|
||||||
@ -121,9 +128,13 @@ class Subscriber extends Model {
|
|||||||
}
|
}
|
||||||
foreach($filters as $key => $value) {
|
foreach($filters as $key => $value) {
|
||||||
if($key === 'segment') {
|
if($key === 'segment') {
|
||||||
$segment = Segment::findOne($value);
|
if($value === 'none') {
|
||||||
if($segment !== false) {
|
return Subscriber::filter('withoutSegments');
|
||||||
return $segment->subscribers();
|
} else {
|
||||||
|
$segment = Segment::findOne($value);
|
||||||
|
if($segment !== false) {
|
||||||
|
return $segment->subscribers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -430,6 +441,19 @@ class Subscriber extends Model {
|
|||||||
->where('status', 'unconfirmed');
|
->where('status', 'unconfirmed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function withoutSegments($orm) {
|
||||||
|
return $orm->select(MP_SUBSCRIBERS_TABLE.'.*')
|
||||||
|
->leftOuterJoin(
|
||||||
|
MP_SUBSCRIBER_SEGMENT_TABLE,
|
||||||
|
array(
|
||||||
|
MP_SUBSCRIBERS_TABLE.'.id',
|
||||||
|
'=',
|
||||||
|
MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->whereNull(MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id');
|
||||||
|
}
|
||||||
|
|
||||||
static function createMultiple($columns, $values) {
|
static function createMultiple($columns, $values) {
|
||||||
return self::rawExecute(
|
return self::rawExecute(
|
||||||
'INSERT INTO `' . self::$_table . '` ' .
|
'INSERT INTO `' . self::$_table . '` ' .
|
||||||
|
@ -73,9 +73,8 @@ class Subscribers {
|
|||||||
'errors' => $errors
|
'errors' => $errors
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if(!empty($segment_ids)) {
|
$subscriber->addToSegments($segment_ids);
|
||||||
$subscriber->addToSegments($segment_ids);
|
|
||||||
}
|
|
||||||
return array(
|
return array(
|
||||||
'result' => true
|
'result' => true
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user