Conflicts between Segment and Subscriber status.
This commit is contained in:
@ -1,64 +1,68 @@
|
||||
<?php
|
||||
namespace MailPoet\Models;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
class Subscriber extends Model {
|
||||
public static $_table = MP_SUBSCRIBERS_TABLE;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addValidations('email', array(
|
||||
'required' => __('You need to enter your email address.'),
|
||||
'isEmail' => __('Your email address is invalid.')
|
||||
));
|
||||
}
|
||||
|
||||
static function search($orm, $search = '') {
|
||||
if(strlen(trim($search) === 0)) {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
return $orm->where_raw(
|
||||
'(`email` LIKE ? OR `first_name` LIKE ? OR `last_name` LIKE ?)',
|
||||
array('%'.$search.'%', '%'.$search.'%', '%'.$search.'%')
|
||||
);
|
||||
}
|
||||
|
||||
static function groups() {
|
||||
return array(
|
||||
array(
|
||||
'name' => 'all',
|
||||
'label' => __('All'),
|
||||
'count' => Subscriber::count()
|
||||
),
|
||||
array(
|
||||
'name' => 'subscribed',
|
||||
'label' => __('Subscribed'),
|
||||
'count' => Subscriber::where('status', 'subscribed')->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'unconfirmed',
|
||||
'label' => __('Unconfirmed'),
|
||||
'count' => Subscriber::where('status', 'unconfirmed')->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'unsubscribed',
|
||||
'label' => __('Unsubscribed'),
|
||||
'count' => Subscriber::where('status', 'unsubscribed')->count()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
static function group($orm, $group = null) {
|
||||
if($group === null or !in_array(
|
||||
$group,
|
||||
array('subscribed', 'unconfirmed', 'unsubscribed')
|
||||
)) {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
return $orm->where('status', $group);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
namespace MailPoet\Models;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Subscriber extends Model {
|
||||
public static $_table = MP_SUBSCRIBERS_TABLE;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addValidations('email', array(
|
||||
'required' => __('You need to enter your email address.'),
|
||||
'isEmail' => __('Your email address is invalid.')
|
||||
));
|
||||
}
|
||||
|
||||
static function search($orm, $search = '') {
|
||||
if(strlen(trim($search) === 0)) {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
return $orm->where_raw(
|
||||
'(`email` LIKE ? OR `first_name` LIKE ? OR `last_name` LIKE ?)',
|
||||
array('%'.$search.'%', '%'.$search.'%', '%'.$search.'%')
|
||||
);
|
||||
}
|
||||
|
||||
static function groups() {
|
||||
return array(
|
||||
array(
|
||||
'name' => 'all',
|
||||
'label' => __('All'),
|
||||
'count' => Subscriber::count()
|
||||
),
|
||||
array(
|
||||
'name' => 'subscribed',
|
||||
'label' => __('Subscribed'),
|
||||
'count' => Subscriber::where('status', 'subscribed')->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'unconfirmed',
|
||||
'label' => __('Unconfirmed'),
|
||||
'count' => Subscriber::where('status', 'unconfirmed')->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'unsubscribed',
|
||||
'label' => __('Unsubscribed'),
|
||||
'count' => Subscriber::where('status', 'unsubscribed')->count()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
static function group($orm, $group = null) {
|
||||
if($group === null or !in_array(
|
||||
$group,
|
||||
array('subscribed', 'unconfirmed', 'unsubscribed')
|
||||
)) {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
return $orm->where('status', $group);
|
||||
}
|
||||
|
||||
public function segments() {
|
||||
return $this->has_many_through(__NAMESPACE__ . '\Segment', __NAMESPACE__ . '\SubscriberSegment', 'subscriber_id', 'segment_id');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user