- updated migration for subscribers status column from int to varchar - updated Subscriber model to reflect the change
56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?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 = '') {
|
|
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(in_array($group, array('subscribed', 'unconfirmed', 'unsubscribed'))) {
|
|
return $orm->where('status', $group);
|
|
}
|
|
}
|
|
}
|