Add WP user segment selection to Notification and Standard newsletters

This commit is contained in:
Tautvidas Sipavičius
2016-06-14 17:52:12 +03:00
parent ca9b1e25a7
commit 2d45ab2e88
3 changed files with 18 additions and 9 deletions

View File

@@ -139,8 +139,8 @@ class Segment extends Model {
return $orm;
}
static function getSegmentsWithSubscriberCount() {
return self::selectMany(array(self::$_table.'.id', self::$_table.'.name'))
static function getSegmentsWithSubscriberCount($type = 'default') {
$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`'
@@ -154,9 +154,13 @@ class Segment extends Model {
->groupBy(self::$_table.'.id')
->groupBy(self::$_table.'.name')
->orderByAsc(self::$_table.'.name')
->where(self::$_table.'.type', 'default')
->whereNull(self::$_table.'.deleted_at')
->findArray();
->whereNull(self::$_table.'.deleted_at');
if (!empty($type)) {
$query->where(self::$_table.'.type', $type);
}
return $query->findArray();
}
static function getSegmentsForExport($withConfirmedSubscribers = false) {
@@ -226,4 +230,4 @@ class Segment extends Model {
->deleteMany();
});
}
}
}