Count subscribers that are not in wp list

[MAILPOET2631]
This commit is contained in:
Pavel Dohnal
2020-01-17 15:25:53 +01:00
committed by Jack Kitterhing
parent 5e2559c0ae
commit 32c71f130c

View File

@ -221,42 +221,51 @@ class Subscriber extends Model {
return $orm;
}
public static function groups() {
private static function updateGroupsQuery($data, $query) {
$wpSegment = Segment::getWPSegment();
if (isset($data['filter']['segment']) && $data['filter']['segment'] === $wpSegment->id) {
return $query;
}
$query->whereNull('wp_user_id');
return $query;
}
public static function groups($data) {
return [
[
'name' => 'all',
'label' => WPFunctions::get()->__('All', 'mailpoet'),
'count' => self::getPublished()->count(),
'count' => self::updateGroupsQuery($data, self::getPublished())->count(),
],
[
'name' => self::STATUS_SUBSCRIBED,
'label' => WPFunctions::get()->__('Subscribed', 'mailpoet'),
'count' => self::filter(self::STATUS_SUBSCRIBED)->count(),
'count' => self::updateGroupsQuery($data, self::filter(self::STATUS_SUBSCRIBED))->count(),
],
[
'name' => self::STATUS_UNCONFIRMED,
'label' => WPFunctions::get()->__('Unconfirmed', 'mailpoet'),
'count' => self::filter(self::STATUS_UNCONFIRMED)->count(),
'count' => self::updateGroupsQuery($data, self::filter(self::STATUS_UNCONFIRMED))->count(),
],
[
'name' => self::STATUS_UNSUBSCRIBED,
'label' => WPFunctions::get()->__('Unsubscribed', 'mailpoet'),
'count' => self::filter(self::STATUS_UNSUBSCRIBED)->count(),
'count' => self::updateGroupsQuery($data, self::filter(self::STATUS_UNSUBSCRIBED))->count(),
],
[
'name' => self::STATUS_INACTIVE,
'label' => WPFunctions::get()->__('Inactive', 'mailpoet'),
'count' => self::filter(self::STATUS_INACTIVE)->count(),
'count' => self::updateGroupsQuery($data, self::filter(self::STATUS_INACTIVE))->count(),
],
[
'name' => self::STATUS_BOUNCED,
'label' => WPFunctions::get()->__('Bounced', 'mailpoet'),
'count' => self::filter(self::STATUS_BOUNCED)->count(),
'count' => self::updateGroupsQuery($data, self::filter(self::STATUS_BOUNCED))->count(),
],
[
'name' => 'trash',
'label' => WPFunctions::get()->__('Trash', 'mailpoet'),
'count' => self::getTrashed()->count(),
'count' => self::updateGroupsQuery($data, self::getTrashed())->count(),
],
];
}