- Updates DB query for custom fields
- Updates models and tests for Subscribers and CustomFields
This commit is contained in:
@ -123,6 +123,29 @@ class Subscriber extends Model {
|
||||
return $orm->where('status', $group);
|
||||
}
|
||||
|
||||
static function withCustomFields($orm) {
|
||||
$orm = $orm->select(MP_SUBSCRIBERS_TABLE.'.*');
|
||||
$customFields = CustomField::findArray();
|
||||
foreach ($customFields as $customField) {
|
||||
$orm = $orm->select_expr(
|
||||
'IFNULL(GROUP_CONCAT(CASE WHEN ' .
|
||||
MP_CUSTOM_FIELDS_TABLE . '.id=' . $customField['id'] . ' THEN ' .
|
||||
MP_SUBSCRIBER_CUSTOM_FIELD_TABLE . '.value END), NULL) as ' .
|
||||
$customField['name']);
|
||||
}
|
||||
$orm = $orm
|
||||
->left_outer_join(
|
||||
MP_SUBSCRIBER_CUSTOM_FIELD_TABLE,
|
||||
array(MP_SUBSCRIBERS_TABLE.'.id', '=',
|
||||
MP_SUBSCRIBER_CUSTOM_FIELD_TABLE.'.subscriber_id'))
|
||||
->left_outer_join(
|
||||
MP_CUSTOM_FIELDS_TABLE,
|
||||
array(MP_CUSTOM_FIELDS_TABLE.'.id','=',
|
||||
MP_SUBSCRIBER_CUSTOM_FIELD_TABLE.'.custom_field_id'))
|
||||
->group_by(MP_SUBSCRIBERS_TABLE.'.id');
|
||||
return $orm;
|
||||
}
|
||||
|
||||
function segments() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__.'\Segment',
|
||||
|
Reference in New Issue
Block a user