- Moves Import and Export under ImportExport namespace

- Cretes a single BootStrapMenu class for Import and Export
- Updates tests
- Adds 2 new methods to Segments model
This commit is contained in:
MrCasual
2015-11-11 17:18:02 -05:00
parent 1625e1771b
commit 0fedd1779f
21 changed files with 589 additions and 193 deletions

View File

@@ -94,16 +94,39 @@ class Segment extends Model {
}
}
static function filterWithSubscriberCount($orm) {
$orm = $orm
->selectMany(array(self::$_table.'.id', self::$_table.'.name'))
->select_expr('COUNT('.MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id)', 'subscribers')
static function getSegmentsForImport() {
return self::selectMany(array(self::$_table.'.id', self::$_table.'.name'))
->select_expr(
'COUNT('.MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id)', 'subscribers'
)
->left_outer_join(
MP_SUBSCRIBER_SEGMENT_TABLE,
array(self::$_table.'.id', '=', MP_SUBSCRIBER_SEGMENT_TABLE.'.segment_id'))
->group_by(self::$_table.'.id')
->group_by(self::$_table.'.name');
return $orm;
->group_by(self::$_table.'.name')
->findArray();
}
static function getSegmentsForExport($withConfirmedSubscribers = false) {
return self::raw_query(
'(SELECT segments.id, segments.name, COUNT(relation.subscriber_id) as subscribers ' .
'FROM ' . MP_SUBSCRIBER_SEGMENT_TABLE . ' relation ' .
'LEFT JOIN ' . self::$_table . ' segments ON segments.id = relation.segment_id ' .
'LEFT JOIN ' . MP_SUBSCRIBERS_TABLE . ' subscribers ON subscribers.id = relation.subscriber_id ' .
(($withConfirmedSubscribers) ?
'WHERE subscribers.status = 1 ' :
'WHERE relation.segment_id IS NOT NULL ') .
'GROUP BY segments.id) ' .
'UNION ALL ' .
'(SELECT 0 as id, "' . __('Not In List') . '" as name, COUNT(*) as subscribers ' .
'FROM ' . MP_SUBSCRIBERS_TABLE . ' subscribers ' .
'LEFT JOIN ' . MP_SUBSCRIBER_SEGMENT_TABLE . ' relation on relation.subscriber_id = subscribers.id ' .
(($withConfirmedSubscribers) ?
'WHERE relation.subscriber_id is NULL AND subscribers.status = 1 ' :
'WHERE relation.subscriber_id is NULL ') .
'HAVING subscribers) ' .
'ORDER BY name'
)->findArray();
}
static function createOrUpdate($data = array()) {