Files
piratepoet/lib/Models/Subscriber.php
Jonathan Labreuille 7370d19be3 Segment listing
- fixed duplicate entry in Robofile for editor styles
- added Segment menu
- added Segment listing
- added listing methods to Segment model
- fixed syntax in both Segment & Subscriber models (MAX LINE 80!!!)
2015-09-04 13:02:23 +02:00

74 lines
1.7 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 = '') {
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'
);
}
}