- 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:
@ -66,8 +66,7 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
'assets/css/src/newsletter_editor/newsletter_editor.styl',
|
'assets/css/src/newsletter_editor/newsletter_editor.styl',
|
||||||
'assets/css/src/public.styl',
|
'assets/css/src/public.styl',
|
||||||
'assets/css/src/rtl.styl',
|
'assets/css/src/rtl.styl',
|
||||||
'assets/css/src/import.styl',
|
'assets/css/src/importExport.styl'
|
||||||
'assets/css/src/export.styl'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->_exec(join(' ', array(
|
$this->_exec(join(' ', array(
|
||||||
|
@ -16,7 +16,122 @@ define(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
jQuery(document).ready(function () {
|
jQuery(document).ready(function () {
|
||||||
|
// halt operation if there are no lists with subscribers found
|
||||||
|
if (!exportData.lists) return;
|
||||||
|
|
||||||
|
var subscribers_export_template = Handlebars.compile($('#mailpoet_subscribers_export_template').html());
|
||||||
|
|
||||||
|
//render template
|
||||||
|
jQuery('#mailpoet_subscribers_export > div.inside').html(subscribers_export_template(exportData));
|
||||||
|
|
||||||
|
// define reusable variables
|
||||||
|
var segmentsContainerElement = jQuery("#export_lists"),
|
||||||
|
subscriberFieldsContainerElement = jQuery("#export_columns"),
|
||||||
|
exportConfirmedOptionElement = jQuery(':radio[name="option_confirmed"]'),
|
||||||
|
groupBySegmentOptionElement = jQuery(':checkbox[name="option_group_by_list"]'),
|
||||||
|
nextStepElement = jQuery("a.mailpoet_export_process"),
|
||||||
|
renderSegmentsAndFields = function (container, data) {
|
||||||
|
if (container.data('select2')) {
|
||||||
|
container
|
||||||
|
.html('')
|
||||||
|
.select2('destroy');
|
||||||
|
}
|
||||||
|
container
|
||||||
|
.select2({
|
||||||
|
data: data,
|
||||||
|
width: '20em',
|
||||||
|
templateResult: function (item) {
|
||||||
|
return (item.subscriberCount > 0)
|
||||||
|
? item.name + ' (' + item.subscriberCount + ')'
|
||||||
|
: item.name;
|
||||||
|
},
|
||||||
|
templateSelection: function (item) {
|
||||||
|
return (item.subscriberCount > 0)
|
||||||
|
? item.name + ' (' + item.subscriberCount + ')'
|
||||||
|
: item.name;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on('select2:selecting', function (selectEvent) {
|
||||||
|
var selectElement = this,
|
||||||
|
selectedOptionId = selectEvent.params.args.data.id;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
/* .change(function (event) {
|
||||||
|
var trigger_element = this;
|
||||||
|
|
||||||
|
if (event.added && event.added.id === 'deselect_all') jQuery(trigger_element).select2('val', '');
|
||||||
|
if (event.added && event.added.id === 'select_all') jQuery(trigger_element).select2('val', columns_ids);
|
||||||
|
|
||||||
|
if ((exportData.lists && segmentsContainerElement.select2('data').length && subscriberFieldsContainerElement.select2('data').length)
|
||||||
|
||
|
||||||
|
(!exportData.lists && subscriberFieldsContainerElement.select2('data').length)
|
||||||
|
) {
|
||||||
|
jQuery(nextStepElement).removeClass('button-disabled');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
jQuery(nextStepElement).addClass('button-disabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (segmentsContainerElement.select2('data').length > 1 && exportData.group_by_list) {
|
||||||
|
jQuery('.mailpoet_group_by_list').show();
|
||||||
|
}
|
||||||
|
else if (exportData.group_by_list) jQuery('.mailpoet_group_by_list').hide();
|
||||||
|
})*/
|
||||||
|
};
|
||||||
|
|
||||||
|
// render lists and columns
|
||||||
|
renderSegmentsAndFields(subscriberFieldsContainerElement, columns);
|
||||||
|
renderSegmentsAndFields(segmentsContainerElement, lists);
|
||||||
|
|
||||||
|
// pre-select columns
|
||||||
|
// subscriberFieldsContainerElement.select2('val', ['subscriber_state', 'subscriber_email', 'subscriber_firstname', 'subscriber_lastname']);
|
||||||
|
|
||||||
|
// handle confirmed/unconfirmed behavior
|
||||||
|
exportConfirmedOptionElement.change(function () {
|
||||||
|
if (this.value == 1) {
|
||||||
|
exportData.confirmed_option = true;
|
||||||
|
renderSegmentsAndFields(segmentsContainerElement, lists_confirmed);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
exportData.confirmed_option = false;
|
||||||
|
renderSegmentsAndFields(segmentsContainerElement, lists);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
// process export
|
||||||
|
nextStepElement.click(function () {
|
||||||
|
if (jQuery(this).hasClass('button-disabled')) return;
|
||||||
|
MailPoet.Modal.loading(true);
|
||||||
|
mailpoet_post_json(
|
||||||
|
'subscribers_export.php',
|
||||||
|
{
|
||||||
|
'option_confirmed': exportData.confirmed_option,
|
||||||
|
'option_format': jQuery(':radio[name="option_format"]:checked').val(),
|
||||||
|
'option_group_by_list': (groupBySegmentOptionElement.is(":visible")) ? groupBySegmentOptionElement.prop('checked') : false,
|
||||||
|
'lists': (exportData.lists) ? segmentsContainerElement.select2('val') : false,
|
||||||
|
'columns': subscriberFieldsContainerElement.select2('data'),
|
||||||
|
'export_directory': export_directory
|
||||||
|
},
|
||||||
|
function (response) {
|
||||||
|
if (response.result === true) {
|
||||||
|
response.message = "<?php _e('%1$s subscribers were exported. Get the exported file [link]here[/link].'); ?>"
|
||||||
|
.replace('%1$s', '<strong>' + response.total + '</strong>')
|
||||||
|
.replace('[link]', '<a href="' + export_url + response.filename + '" target="_blank" >')
|
||||||
|
.replace('[/link]', '</a>')
|
||||||
|
jQuery('#export_result_notice > ul > li').html(response.message)
|
||||||
|
jQuery('#export_result_notice').show();
|
||||||
|
window.location.href = export_url + response.filename;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MailPoet.Notice.error(response.message);
|
||||||
|
}
|
||||||
|
MailPoet.Modal.loading(false);
|
||||||
|
},
|
||||||
|
function (response) {
|
||||||
|
MailPoet.Modal.loading(false);
|
||||||
|
MailPoet.Notice.error('<?php _e("Server error:"); ?> ' + response.statusText.toLowerCase() + '.', {scroll: true});
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})*/
|
||||||
|
});
|
||||||
});
|
});
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
|
||||||
|
use MailPoet\ImportExport\BootStrapMenu;
|
||||||
use \MailPoet\Models\Segment;
|
use \MailPoet\Models\Segment;
|
||||||
use \MailPoet\Models\Setting;
|
use \MailPoet\Models\Setting;
|
||||||
use \MailPoet\Models\Form;
|
use \MailPoet\Models\Form;
|
||||||
@ -236,13 +237,15 @@ class Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function import() {
|
function import() {
|
||||||
$import = new \MailPoet\Import\BootstrapMenu();
|
$import = new BootStrapMenu('import');
|
||||||
$data = $import->bootstrap();
|
$data = $import->bootstrap();
|
||||||
echo $this->renderer->render('import.html', $data);
|
echo $this->renderer->render('import.html', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function export() {
|
function export() {
|
||||||
echo $this->renderer->render('export.html');
|
$export = new BootStrapMenu('export');
|
||||||
|
$data = $export->bootstrap();
|
||||||
|
echo $this->renderer->render('export.html', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formEditor() {
|
function formEditor() {
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace MailPoet\Export;
|
|
||||||
|
|
||||||
class BootstrapMenu {
|
|
||||||
|
|
||||||
function __construct() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function bootstrap() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,112 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace MailPoet\Import;
|
|
||||||
|
|
||||||
use MailPoet\Models\CustomField;
|
|
||||||
use MailPoet\Models\Segment;
|
|
||||||
use MailPoet\Util\Helpers;
|
|
||||||
|
|
||||||
class BootstrapMenu {
|
|
||||||
|
|
||||||
function __construct() {
|
|
||||||
$this->subscriberFields = $this->getSubscriberFields();
|
|
||||||
$this->subscriberCustomFields = $this->getSubscriberCustomFields();
|
|
||||||
$this->segments = $this->getSegments();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSubscriberFields() {
|
|
||||||
return array(
|
|
||||||
'email' => __('Email'),
|
|
||||||
'first_name' => __('First name'),
|
|
||||||
'last_name' => __('Last name'),
|
|
||||||
'status' => __('Status')
|
|
||||||
/* 'confirmed_ip' => __('IP address')
|
|
||||||
'confirmed_at' => __('Subscription date')*/
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSegments() {
|
|
||||||
return array_map(function ($segment) {
|
|
||||||
return array(
|
|
||||||
'id' => $segment['id'],
|
|
||||||
'name' => $segment['name'],
|
|
||||||
'subscriberCount' => $segment['subscribers']
|
|
||||||
);
|
|
||||||
}, Segment::filter('filterWithSubscriberCount')
|
|
||||||
->findArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSubscriberCustomFields() {
|
|
||||||
return CustomField::findArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatSubscriberFields($subscriberFields) {
|
|
||||||
return array_map(function ($fieldId, $fieldName) {
|
|
||||||
return array(
|
|
||||||
'id' => $fieldId,
|
|
||||||
'name' => $fieldName,
|
|
||||||
'type' => ($fieldId === 'confirmed_at') ? 'date' : null,
|
|
||||||
'custom' => false
|
|
||||||
);
|
|
||||||
}, array_keys($subscriberFields), $subscriberFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatSubscriberCustomFields($subscriberCustomFields) {
|
|
||||||
return array_map(function ($field) {
|
|
||||||
return array(
|
|
||||||
'id' => $field['id'],
|
|
||||||
'name' => $field['name'],
|
|
||||||
'type' => $field['type'],
|
|
||||||
'custom' => true
|
|
||||||
);
|
|
||||||
}, $subscriberCustomFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatFieldsForSelect2(
|
|
||||||
$subscriberFields,
|
|
||||||
$subscriberCustomFields) {
|
|
||||||
$select2Fields = array(
|
|
||||||
array(
|
|
||||||
'name' => __('Actions'),
|
|
||||||
'children' => array(
|
|
||||||
array(
|
|
||||||
'id' => 'ignore',
|
|
||||||
'name' => __('Ignore column...'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'id' => 'create',
|
|
||||||
'name' => __('Create new column...')
|
|
||||||
),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'name' => __('System columns'),
|
|
||||||
'children' => $this->formatSubscriberFields($subscriberFields)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if($this->subscriberCustomFields) {
|
|
||||||
array_push($select2Fields, array(
|
|
||||||
'name' => __('User columns'),
|
|
||||||
'children' => $this->formatSubscriberCustomFields(
|
|
||||||
$subscriberCustomFields
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
return $select2Fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bootstrap() {
|
|
||||||
$data['segments'] = $this->segments;
|
|
||||||
$data['subscriberFields'] = array_merge(
|
|
||||||
$this->formatSubscriberFields($this->subscriberFields),
|
|
||||||
$this->formatSubscriberCustomFields($this->subscriberCustomFields)
|
|
||||||
);
|
|
||||||
$data['subscriberFieldsSelect2'] = $this->formatFieldsForSelect2(
|
|
||||||
$this->subscriberFields,
|
|
||||||
$this->subscriberCustomFields
|
|
||||||
);
|
|
||||||
$data = array_map('json_encode', $data);
|
|
||||||
$data['maxPostSizeBytes'] = Helpers::getMaxPostSize('bytes');
|
|
||||||
$data['maxPostSize'] = Helpers::getMaxPostSize();
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
}
|
|
135
lib/ImportExport/BootstrapMenu.php
Normal file
135
lib/ImportExport/BootstrapMenu.php
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
namespace MailPoet\ImportExport;
|
||||||
|
|
||||||
|
use MailPoet\Models\CustomField;
|
||||||
|
use MailPoet\Models\Segment;
|
||||||
|
use MailPoet\Util\Helpers;
|
||||||
|
|
||||||
|
class BootStrapMenu {
|
||||||
|
function __construct($action) {
|
||||||
|
$this->action = $action;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSegments($withConfirmedSubscribers = false) {
|
||||||
|
$segments = ($this->action === 'import') ?
|
||||||
|
Segment::getSegmentsForImport() :
|
||||||
|
Segment::getSegmentsForExport($withConfirmedSubscribers);
|
||||||
|
return array_map(function ($segment) {
|
||||||
|
return array(
|
||||||
|
'id' => $segment['id'],
|
||||||
|
'name' => $segment['name'],
|
||||||
|
'subscriberCount' => $segment['subscribers']
|
||||||
|
);
|
||||||
|
}, $segments);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSubscriberFields() {
|
||||||
|
return array(
|
||||||
|
'email' => __('Email'),
|
||||||
|
'first_name' => __('First name'),
|
||||||
|
'last_name' => __('Last name'),
|
||||||
|
'status' => __('Status')
|
||||||
|
/*
|
||||||
|
'confirmed_ip' => __('IP address')
|
||||||
|
'confirmed_at' => __('Subscription date')
|
||||||
|
*/
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSubscriberFields($subscriberFields) {
|
||||||
|
return array_map(function ($fieldId, $fieldName) {
|
||||||
|
return array(
|
||||||
|
'id' => $fieldId,
|
||||||
|
'name' => $fieldName,
|
||||||
|
'type' => ($fieldId === 'confirmed_at') ? 'date' : null,
|
||||||
|
'custom' => false
|
||||||
|
);
|
||||||
|
}, array_keys($subscriberFields), $subscriberFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSubscriberCustomFields() {
|
||||||
|
return CustomField::findArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSubscriberCustomFields($subscriberCustomFields) {
|
||||||
|
return array_map(function ($field) {
|
||||||
|
return array(
|
||||||
|
'id' => $field['id'],
|
||||||
|
'name' => $field['name'],
|
||||||
|
'type' => $field['type'],
|
||||||
|
'custom' => true
|
||||||
|
);
|
||||||
|
}, $subscriberCustomFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatFieldsForSelect2(
|
||||||
|
$subscriberFields,
|
||||||
|
$subscriberCustomFields) {
|
||||||
|
$actions = ($this->action === 'import') ?
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'id' => 'ignore',
|
||||||
|
'name' => __('Ignore column...'),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'id' => 'create',
|
||||||
|
'name' => __('Create new column...')
|
||||||
|
),
|
||||||
|
) :
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'id' => 'select',
|
||||||
|
'name' => __('Select all...'),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'id' => 'deselect',
|
||||||
|
'name' => __('Deselect all...')
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$select2Fields = array(
|
||||||
|
array(
|
||||||
|
'name' => __('Actions'),
|
||||||
|
'children' => $actions
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => __('System columns'),
|
||||||
|
'children' => $this->formatSubscriberFields($subscriberFields)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if($subscriberCustomFields) {
|
||||||
|
array_push($select2Fields, array(
|
||||||
|
'name' => __('User columns'),
|
||||||
|
'children' => $this->formatSubscriberCustomFields(
|
||||||
|
$subscriberCustomFields
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return $select2Fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bootstrap() {
|
||||||
|
$subscriberFields = $this->getSubscriberFields();
|
||||||
|
$subscriberCustomFields = $this->getSubscriberCustomFields();
|
||||||
|
$data['segments'] = json_encode($this->getSegments());
|
||||||
|
$data['subscriberFieldsSelect2'] = json_encode(
|
||||||
|
$this->formatFieldsForSelect2(
|
||||||
|
$subscriberFields,
|
||||||
|
$subscriberCustomFields
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if($this->action === 'import') {
|
||||||
|
$data['subscriberFields'] = json_encode(
|
||||||
|
array_merge(
|
||||||
|
$this->formatSubscriberFields($subscriberFields),
|
||||||
|
$this->formatSubscriberCustomFields($subscriberCustomFields)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$data['maxPostSizeBytes'] = Helpers::getMaxPostSize('bytes');
|
||||||
|
$data['maxPostSize'] = Helpers::getMaxPostSize();
|
||||||
|
} else {
|
||||||
|
$data['segmentsWithConfirmedSubscribers'] =
|
||||||
|
json_encode($this->getSegments($withConfirmedSubscribers = true));
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Export;
|
namespace MailPoet\ImportExport\ImportExport\Export;
|
||||||
|
|
||||||
class Export {
|
class Export {
|
||||||
public function __construct($data) {
|
public function __construct($data) {
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Import;
|
namespace MailPoet\ImportExport\Import;
|
||||||
|
|
||||||
|
use MailPoet\ImportExport\BootStrapMenu;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Models\SubscriberCustomField;
|
use MailPoet\Models\SubscriberCustomField;
|
||||||
use MailPoet\Models\SubscriberSegment;
|
use MailPoet\Models\SubscriberSegment;
|
||||||
@ -66,7 +67,7 @@ class Import {
|
|||||||
'error' => $e->getMessage()
|
'error' => $e->getMessage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$segments = new BootstrapMenu();
|
$segments = new BootStrapMenu('import');
|
||||||
return array(
|
return array(
|
||||||
'result' => true,
|
'result' => true,
|
||||||
'data' => array(
|
'data' => array(
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Import;
|
namespace MailPoet\ImportExport\Import;
|
||||||
|
|
||||||
use MailPoet\Util\Helpers;
|
use MailPoet\Util\Helpers;
|
||||||
|
|
@ -94,16 +94,39 @@ class Segment extends Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static function filterWithSubscriberCount($orm) {
|
static function getSegmentsForImport() {
|
||||||
$orm = $orm
|
return self::selectMany(array(self::$_table.'.id', self::$_table.'.name'))
|
||||||
->selectMany(array(self::$_table.'.id', self::$_table.'.name'))
|
->select_expr(
|
||||||
->select_expr('COUNT('.MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id)', 'subscribers')
|
'COUNT('.MP_SUBSCRIBER_SEGMENT_TABLE.'.subscriber_id)', 'subscribers'
|
||||||
|
)
|
||||||
->left_outer_join(
|
->left_outer_join(
|
||||||
MP_SUBSCRIBER_SEGMENT_TABLE,
|
MP_SUBSCRIBER_SEGMENT_TABLE,
|
||||||
array(self::$_table.'.id', '=', MP_SUBSCRIBER_SEGMENT_TABLE.'.segment_id'))
|
array(self::$_table.'.id', '=', MP_SUBSCRIBER_SEGMENT_TABLE.'.segment_id'))
|
||||||
->group_by(self::$_table.'.id')
|
->group_by(self::$_table.'.id')
|
||||||
->group_by(self::$_table.'.name');
|
->group_by(self::$_table.'.name')
|
||||||
return $orm;
|
->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()) {
|
static function createOrUpdate($data = array()) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Router;
|
namespace MailPoet\Router;
|
||||||
|
|
||||||
use MailPoet\Import\MailChimp;
|
use MailPoet\ImportExport\Import\MailChimp;
|
||||||
use MailPoet\Models\CustomField;
|
use MailPoet\Models\CustomField;
|
||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ class Import {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function process($data) {
|
function process($data) {
|
||||||
$import = new \MailPoet\Import\Import(json_decode($data, true));
|
$import = new \MailPoet\ImportExport\Import\Import(json_decode($data, true));
|
||||||
wp_send_json($import->process());
|
wp_send_json($import->process());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -55,6 +55,7 @@ class Segments {
|
|||||||
)
|
)
|
||||||
->findOne()->asArray();
|
->findOne()->asArray();
|
||||||
|
|
||||||
|
!d(\ORM::get_last_query());exit;
|
||||||
$item = array_merge($item, $stats);
|
$item = array_merge($item, $stats);
|
||||||
|
|
||||||
$item['subscribers_url'] = admin_url(
|
$item['subscribers_url'] = admin_url(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use MailPoet\Import\BootstrapMenu;
|
use MailPoet\ImportExport\BootStrapMenu;
|
||||||
use MailPoet\Models\CustomField;
|
use MailPoet\Models\CustomField;
|
||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
@ -22,11 +22,13 @@ class BootStrapMenuCest {
|
|||||||
array(
|
array(
|
||||||
'first_name' => 'John',
|
'first_name' => 'John',
|
||||||
'last_name' => 'Mailer',
|
'last_name' => 'Mailer',
|
||||||
|
'status' => 0,
|
||||||
'email' => 'john@mailpoet.com'
|
'email' => 'john@mailpoet.com'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'first_name' => 'Mike',
|
'first_name' => 'Mike',
|
||||||
'last_name' => 'Smith',
|
'last_name' => 'Smith',
|
||||||
|
'status' => 1,
|
||||||
'email' => 'mike@maipoet.com'
|
'email' => 'mike@maipoet.com'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -37,20 +39,39 @@ class BootStrapMenuCest {
|
|||||||
$customField = CustomField::create();
|
$customField = CustomField::create();
|
||||||
$customField->hydrate($this->customFieldsData);
|
$customField->hydrate($this->customFieldsData);
|
||||||
$customField->save();
|
$customField->save();
|
||||||
$this->bootStrapMenu = new BootstrapMenu();
|
$this->bootStrapImportMenu = new BootStrapMenu('import');
|
||||||
|
$this->bootStrapExportMenu = new BootStrapMenu('export');
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSegments() {
|
function itCanGetSegmentsForImport() {
|
||||||
$this->_createSegmentsAndSubscribers();
|
$this->_createSegmentsAndSubscribers();
|
||||||
$segments = $this->bootStrapMenu->getSegments();
|
$segments = $this->bootStrapImportMenu->getSegments();
|
||||||
expect(count($segments))->equals(2);
|
expect(count($segments))->equals(2);
|
||||||
expect($segments[0]['name'])->equals($this->segmentsData[0]['name']);
|
expect($segments[0]['name'])->equals($this->segmentsData[0]['name']);
|
||||||
expect($segments[0]['subscriberCount'])->equals(1);
|
expect($segments[0]['subscriberCount'])->equals(1);
|
||||||
expect($segments[1]['subscriberCount'])->equals(0);
|
expect($segments[1]['subscriberCount'])->equals(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetSegmentsForExport() {
|
||||||
|
$this->_createSegmentsAndSubscribers();
|
||||||
|
$segments = $this->bootStrapExportMenu->getSegments();
|
||||||
|
expect(count($segments))->equals(2);
|
||||||
|
expect($segments[0]['name'])->equals($this->segmentsData[0]['name']);
|
||||||
|
expect($segments[0]['subscriberCount'])->equals(1);
|
||||||
|
expect($segments[1]['subscriberCount'])->equals(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetSegmentsWithConfirmedSubscribersForExport() {
|
||||||
|
$this->_createSegmentsAndSubscribers();
|
||||||
|
$segments = $this->bootStrapExportMenu->getSegments(
|
||||||
|
$withConfirmedSubscribers = true
|
||||||
|
);
|
||||||
|
expect(count($segments))->equals(1);
|
||||||
|
expect($segments[0]['name'])->equals($this->segmentsData[1]['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSubscriberFields() {
|
function itCanGetSubscriberFields() {
|
||||||
$subsriberFields = $this->bootStrapMenu->getSubscriberFields();
|
$subsriberFields = $this->bootStrapImportMenu->getSubscriberFields();
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'email',
|
'email',
|
||||||
'first_name',
|
'first_name',
|
||||||
@ -64,8 +85,8 @@ class BootStrapMenuCest {
|
|||||||
|
|
||||||
function itCanFormatSubsciberFields() {
|
function itCanFormatSubsciberFields() {
|
||||||
$formattedSubscriberFields =
|
$formattedSubscriberFields =
|
||||||
$this->bootStrapMenu->formatSubscriberFields(
|
$this->bootStrapImportMenu->formatSubscriberFields(
|
||||||
$this->bootStrapMenu->getSubscriberFields()
|
$this->bootStrapImportMenu->getSubscriberFields()
|
||||||
);
|
);
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'id',
|
'id',
|
||||||
@ -82,7 +103,7 @@ class BootStrapMenuCest {
|
|||||||
|
|
||||||
function itCanGetSubsciberCustomFields() {
|
function itCanGetSubsciberCustomFields() {
|
||||||
$subscriberCustomFields =
|
$subscriberCustomFields =
|
||||||
$this->bootStrapMenu
|
$this->bootStrapImportMenu
|
||||||
->getSubscriberCustomFields();
|
->getSubscriberCustomFields();
|
||||||
expect($subscriberCustomFields[0]['type'])
|
expect($subscriberCustomFields[0]['type'])
|
||||||
->equals($this->customFieldsData['type']);
|
->equals($this->customFieldsData['type']);
|
||||||
@ -90,8 +111,8 @@ class BootStrapMenuCest {
|
|||||||
|
|
||||||
function itCanFormatSubsciberCustomFields() {
|
function itCanFormatSubsciberCustomFields() {
|
||||||
$formattedSubscriberCustomFields =
|
$formattedSubscriberCustomFields =
|
||||||
$this->bootStrapMenu->formatSubscriberCustomFields(
|
$this->bootStrapImportMenu->formatSubscriberCustomFields(
|
||||||
$this->bootStrapMenu->getSubscriberCustomFields()
|
$this->bootStrapImportMenu->getSubscriberCustomFields()
|
||||||
);
|
);
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'id',
|
'id',
|
||||||
@ -106,8 +127,8 @@ class BootStrapMenuCest {
|
|||||||
expect($formattedSubscriberCustomFields[0]['custom'])->true();
|
expect($formattedSubscriberCustomFields[0]['custom'])->true();
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanFormatFieldsForSelect2() {
|
function itCanFormatFieldsForSelect2Import() {
|
||||||
$bootStrapMenu = clone($this->bootStrapMenu);
|
$bootStrapMenu = clone($this->bootStrapImportMenu);
|
||||||
$select2FieldsWithoutCustomFields = array(
|
$select2FieldsWithoutCustomFields = array(
|
||||||
array(
|
array(
|
||||||
'name' => 'Actions',
|
'name' => 'Actions',
|
||||||
@ -140,50 +161,112 @@ class BootStrapMenuCest {
|
|||||||
)
|
)
|
||||||
));
|
));
|
||||||
$formattedFieldsForSelect2 = $bootStrapMenu->formatFieldsForSelect2(
|
$formattedFieldsForSelect2 = $bootStrapMenu->formatFieldsForSelect2(
|
||||||
$bootStrapMenu->subscriberFields,
|
$bootStrapMenu->getSubscriberFields(),
|
||||||
$bootStrapMenu->subscriberCustomFields
|
$bootStrapMenu->getSubscriberCustomFields()
|
||||||
);
|
);
|
||||||
expect($formattedFieldsForSelect2)->equals($select2FieldsWithCustomFields);
|
expect($formattedFieldsForSelect2)->equals($select2FieldsWithCustomFields);
|
||||||
$bootStrapMenu->subscriberCustomFields = false;
|
$bootStrapMenu->subscriberCustomFields = false;
|
||||||
$formattedFieldsForSelect2 = $bootStrapMenu->formatFieldsForSelect2(
|
$formattedFieldsForSelect2 = $bootStrapMenu->formatFieldsForSelect2(
|
||||||
$bootStrapMenu->subscriberFields,
|
$bootStrapMenu->getSubscriberFields(),
|
||||||
$bootStrapMenu->subscriberCustomFields
|
$bootStrapMenu->getSubscriberCustomFields()
|
||||||
);
|
);
|
||||||
expect($formattedFieldsForSelect2)->equals($select2FieldsWithoutCustomFields);
|
expect($formattedFieldsForSelect2)->equals($select2FieldsWithoutCustomFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanBootstrap() {
|
function itCanFormatFieldsForSelect2Export() {
|
||||||
|
$bootStrapMenu = clone($this->bootStrapExportMenu);
|
||||||
|
$select2FieldsWithoutCustomFields = array(
|
||||||
|
array(
|
||||||
|
'name' => 'Actions',
|
||||||
|
'children' => array(
|
||||||
|
array(
|
||||||
|
'id' => 'select',
|
||||||
|
'name' => __('Select all...'),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'id' => 'deselect',
|
||||||
|
'name' => __('Deselect all...')
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'System columns',
|
||||||
|
'children' => $bootStrapMenu->formatSubscriberFields(
|
||||||
|
$bootStrapMenu->subscriberFields
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$select2FieldsWithCustomFields = array_merge(
|
||||||
|
$select2FieldsWithoutCustomFields,
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'name' => __('User columns'),
|
||||||
|
'children' => $bootStrapMenu->formatSubscriberCustomFields(
|
||||||
|
$bootStrapMenu->subscriberCustomFields
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$formattedFieldsForSelect2 = $bootStrapMenu->formatFieldsForSelect2(
|
||||||
|
$bootStrapMenu->getSubscriberFields(),
|
||||||
|
$bootStrapMenu->getSubscriberCustomFields()
|
||||||
|
);
|
||||||
|
expect($formattedFieldsForSelect2)->equals($select2FieldsWithCustomFields);
|
||||||
|
$bootStrapMenu->subscriberCustomFields = false;
|
||||||
|
$formattedFieldsForSelect2 = $bootStrapMenu->formatFieldsForSelect2(
|
||||||
|
$bootStrapMenu->getSubscriberFields(),
|
||||||
|
$bootStrapMenu->getSubscriberCustomFields()
|
||||||
|
);
|
||||||
|
expect($formattedFieldsForSelect2)->equals($select2FieldsWithoutCustomFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanBootStrapImport() {
|
||||||
$customField = CustomField::create();
|
$customField = CustomField::create();
|
||||||
$customField->hydrate($this->customFieldsData);
|
$customField->hydrate($this->customFieldsData);
|
||||||
$customField->save();
|
$customField->save();
|
||||||
$bootstrap = clone($this->bootStrapMenu);
|
|
||||||
$this->_createSegmentsAndSubscribers();
|
$this->_createSegmentsAndSubscribers();
|
||||||
$bootstrap->segments = $bootstrap->getSegments();
|
$import = clone($this->bootStrapImportMenu);
|
||||||
$menu = $bootstrap->bootstrap();
|
$importMenu = $import->bootstrap();
|
||||||
expect(count(json_decode($menu['segments'], true)))->equals(2);
|
expect(count(json_decode($importMenu['segments'], true)))
|
||||||
|
->equals(2);
|
||||||
// email, first_name, last_name, status + 1 custom field
|
// email, first_name, last_name, status + 1 custom field
|
||||||
expect(count(json_decode($menu['subscriberFields'], true)))->equals(5);
|
expect(count(json_decode($importMenu['subscriberFields'], true)))
|
||||||
|
->equals(5);
|
||||||
// action, system columns, user columns
|
// action, system columns, user columns
|
||||||
expect(count(json_decode($menu['subscriberFieldsSelect2'], true)))->equals(3);
|
expect(count(json_decode($importMenu['subscriberFieldsSelect2'], true)))
|
||||||
expect($menu['maxPostSize'])->equals(ini_get('post_max_size'));
|
->equals(3);
|
||||||
expect($menu['maxPostSizeBytes'])->equals(
|
expect($importMenu['maxPostSize'])->equals(ini_get('post_max_size'));
|
||||||
|
expect($importMenu['maxPostSizeBytes'])->equals(
|
||||||
(int) ini_get('post_max_size') * 1048576
|
(int) ini_get('post_max_size') * 1048576
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function itCanBootStrapExport() {
|
||||||
|
$customField = CustomField::create();
|
||||||
|
$customField->hydrate($this->customFieldsData);
|
||||||
|
$customField->save();
|
||||||
|
$this->_createSegmentsAndSubscribers();
|
||||||
|
$export = clone($this->bootStrapImportMenu);
|
||||||
|
$exportMenu = $export->bootstrap();
|
||||||
|
expect(count(json_decode($exportMenu['segments'], true)))
|
||||||
|
->equals(2);
|
||||||
|
// action, system columns, user columns
|
||||||
|
expect(count(json_decode($exportMenu['subscriberFieldsSelect2'], true)))
|
||||||
|
->equals(3);
|
||||||
|
}
|
||||||
|
|
||||||
function _createSegmentsAndSubscribers() {
|
function _createSegmentsAndSubscribers() {
|
||||||
foreach ($this->segmentsData as $segmentData) {
|
foreach ($this->segmentsData as $segmentData) {
|
||||||
$segment = Segment::create();
|
$segment = Segment::create();
|
||||||
$segment->hydrate($segmentData);
|
$segment->hydrate($segmentData);
|
||||||
$segment->save();
|
$segment->save();
|
||||||
}
|
}
|
||||||
foreach ($this->subscribersData as $index => $subscriberData) {
|
foreach ($this->subscribersData as $subscriberData) {
|
||||||
$subscriber = Subscriber::create();
|
$subscriber = Subscriber::create();
|
||||||
$subscriber->hydrate($subscriberData);
|
$subscriber->hydrate($subscriberData);
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
$association = SubscriberSegment::create();
|
$association = SubscriberSegment::create();
|
||||||
$association->subscriber_id = $subscriber->id;
|
$association->subscriber_id = $subscriber->id;
|
||||||
$association->segment_id = $index;
|
$association->segment_id = $subscriber->id;
|
||||||
$association->save();
|
$association->save();
|
||||||
};
|
};
|
||||||
}
|
}
|
23
tests/unit/ImportExport/Export/ExportCest.php
Normal file
23
tests/unit/ImportExport/Export/ExportCest.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use MailPoet\ImportExport\Export;
|
||||||
|
|
||||||
|
class ExportCest {
|
||||||
|
function __construct() {
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanConstruct() {
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanProcess() {
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
ORM::forTable(Subscriber::$_table)
|
||||||
|
->deleteMany();
|
||||||
|
ORM::forTable(SubscriberCustomField::$_table)
|
||||||
|
->deleteMany();
|
||||||
|
ORM::forTable(SubscriberSegment::$_table)
|
||||||
|
->deleteMany();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use MailPoet\Import\Import;
|
use MailPoet\ImportExport\Import\Import;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Models\SubscriberCustomField;
|
use MailPoet\Models\SubscriberCustomField;
|
||||||
use MailPoet\Models\SubscriberSegment;
|
use MailPoet\Models\SubscriberSegment;
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use MailPoet\Import\MailChimp;
|
use MailPoet\ImportExport\Import\MailChimp;
|
||||||
|
|
||||||
class MailChimpCest {
|
class MailChimpCest {
|
||||||
function __construct() {
|
function __construct() {
|
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use MailPoet\Models\SubscriberSegment;
|
|
||||||
use MailPoet\Models\Subscriber;
|
|
||||||
use MailPoet\Models\Segment;
|
|
||||||
use MailPoet\Models\Newsletter;
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Models\NewsletterSegment;
|
use MailPoet\Models\NewsletterSegment;
|
||||||
|
use MailPoet\Models\Segment;
|
||||||
|
use MailPoet\Models\Subscriber;
|
||||||
|
use MailPoet\Models\SubscriberSegment;
|
||||||
|
|
||||||
class SegmentCest {
|
class SegmentCest {
|
||||||
function _before() {
|
function _before() {
|
||||||
@ -17,11 +17,13 @@ class SegmentCest {
|
|||||||
array(
|
array(
|
||||||
'first_name' => 'John',
|
'first_name' => 'John',
|
||||||
'last_name' => 'Mailer',
|
'last_name' => 'Mailer',
|
||||||
|
'status' => 0,
|
||||||
'email' => 'john@mailpoet.com'
|
'email' => 'john@mailpoet.com'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'first_name' => 'Mike',
|
'first_name' => 'Mike',
|
||||||
'last_name' => 'Smith',
|
'last_name' => 'Smith',
|
||||||
|
'status' => 1,
|
||||||
'email' => 'mike@maipoet.com'
|
'email' => 'mike@maipoet.com'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -104,14 +106,17 @@ class SegmentCest {
|
|||||||
expect($is_created)->notEquals(false);
|
expect($is_created)->notEquals(false);
|
||||||
expect($is_created->getValidationErrors())->isEmpty();
|
expect($is_created->getValidationErrors())->isEmpty();
|
||||||
|
|
||||||
$segment = Segment::where('name', 'new list')->findOne();
|
$segment = Segment::where('name', 'new list')
|
||||||
|
->findOne();
|
||||||
expect($segment->name)->equals('new list');
|
expect($segment->name)->equals('new list');
|
||||||
|
|
||||||
$is_updated = Segment::createOrUpdate(array(
|
$is_updated = Segment::createOrUpdate(
|
||||||
|
array(
|
||||||
'id' => $segment->id,
|
'id' => $segment->id,
|
||||||
'name' => 'updated list'
|
'name' => 'updated list'
|
||||||
));
|
));
|
||||||
$segment = Segment::where('name', 'updated list')->findOne();
|
$segment = Segment::where('name', 'updated list')
|
||||||
|
->findOne();
|
||||||
expect($segment->name)->equals('updated list');
|
expect($segment->name)->equals('updated list');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,9 +130,9 @@ class SegmentCest {
|
|||||||
$association->segment_id = $this->segment->id;
|
$association->segment_id = $this->segment->id;
|
||||||
$association->save();
|
$association->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$segment = Segment::findOne($this->segment->id);
|
$segment = Segment::findOne($this->segment->id);
|
||||||
$subscribers = $segment->subscribers()->findArray();
|
$subscribers = $segment->subscribers()
|
||||||
|
->findArray();
|
||||||
|
|
||||||
expect(count($subscribers))->equals(2);
|
expect(count($subscribers))->equals(2);
|
||||||
}
|
}
|
||||||
@ -142,14 +147,14 @@ class SegmentCest {
|
|||||||
$association->segment_id = $this->segment->id;
|
$association->segment_id = $this->segment->id;
|
||||||
$association->save();
|
$association->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$segment = Segment::findOne($this->segment->id);
|
$segment = Segment::findOne($this->segment->id);
|
||||||
$newsletters = $segment->newsletters()->findArray();
|
$newsletters = $segment->newsletters()
|
||||||
|
->findArray();
|
||||||
|
|
||||||
expect(count($newsletters))->equals(2);
|
expect(count($newsletters))->equals(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanReturnSubscriberCount() {
|
function itCanGetSegmentsForImport() {
|
||||||
foreach ($this->subscribersData as $subscriberData) {
|
foreach ($this->subscribersData as $subscriberData) {
|
||||||
$subscriber = Subscriber::create();
|
$subscriber = Subscriber::create();
|
||||||
$subscriber->hydrate($subscriberData);
|
$subscriber->hydrate($subscriberData);
|
||||||
@ -159,11 +164,29 @@ class SegmentCest {
|
|||||||
$association->segment_id = $this->segment->id;
|
$association->segment_id = $this->segment->id;
|
||||||
$association->save();
|
$association->save();
|
||||||
}
|
}
|
||||||
|
$segment = Segment::getSegmentsForImport();
|
||||||
$segment = Segment::filter('filterWithSubscriberCount')->findArray();
|
|
||||||
expect($segment[0]['subscribers'])->equals(2);
|
expect($segment[0]['subscribers'])->equals(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function itCanGetSegmentsForExport() {
|
||||||
|
foreach ($this->subscribersData as $index => $subscriberData) {
|
||||||
|
$subscriber = Subscriber::create();
|
||||||
|
$subscriber->hydrate($subscriberData);
|
||||||
|
$subscriber->save();
|
||||||
|
if(!$index) {
|
||||||
|
$association = SubscriberSegment::create();
|
||||||
|
$association->subscriber_id = $subscriber->id;
|
||||||
|
$association->segment_id = $this->segment->id;
|
||||||
|
$association->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$segments = Segment::getSegmentsForExport();
|
||||||
|
expect(count($segments))->equals(2);
|
||||||
|
expect($segments[0]['name'])->equals('Not In List');
|
||||||
|
$segments = Segment::getSegmentsForExport($withConfirmedSubscribers = true);
|
||||||
|
expect(count($segments))->equals(1);
|
||||||
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
ORM::forTable(Segment::$_table)
|
ORM::forTable(Segment::$_table)
|
||||||
->deleteMany();
|
->deleteMany();
|
||||||
|
@ -3,13 +3,126 @@
|
|||||||
<% block content %>
|
<% block content %>
|
||||||
<div id="mailpoet_subscribers_export" class="wrap">
|
<div id="mailpoet_subscribers_export" class="wrap">
|
||||||
<h2 class="title"><%= __('Export') %></h2>
|
<h2 class="title"><%= __('Export') %></h2>
|
||||||
|
<% if segments is empty %>
|
||||||
|
<div class="notice">
|
||||||
|
<ul>
|
||||||
|
<li><%= __("Yikes! Couldn't find any subscribers.") %></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<% endif %>
|
||||||
|
<div class="inside">
|
||||||
|
<!-- Template data -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script id="mailpoet_subscribers_export_template" type="text/x-handlebars-template">
|
||||||
|
<div id="export_result_notice" class="notice mailpoet_hidden">
|
||||||
|
<ul>
|
||||||
|
<li></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<table class="form-table">
|
||||||
|
<tbody>
|
||||||
|
{{#if segments}}
|
||||||
|
<tr>
|
||||||
|
<th scope="row">
|
||||||
|
<label for="s2id_autogen2">
|
||||||
|
<%= __('Pick a list') %>
|
||||||
|
</label>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<select id="export_lists" data-placeholder="<%= __('Select') %>" multiple="multiple"></select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
<tr>
|
||||||
|
<th scope="row">
|
||||||
|
<label for="s2id_autogen1">
|
||||||
|
<%= __('List of fields to export') %>
|
||||||
|
</label>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<select id="export_columns" data-placeholder="<%= __('Select') %>" multiple="multiple"></select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{#if groupBySegmentOption}}
|
||||||
|
<tr class="mailpoet_group_by_list mailpoet_hidden">
|
||||||
|
<th scope="row">
|
||||||
|
<%= __('Group subscribers by list') %>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" name="option_group_by_list" checked>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if exportConfirmedOption}}
|
||||||
|
<tr>
|
||||||
|
<th scope="row">
|
||||||
|
<%= __('Export confirmed subscribers only') %>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<div>
|
||||||
|
<label>
|
||||||
|
<input type="radio"
|
||||||
|
name="option_confirmed" value=1><%= __('Yes') %>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input type="radio"
|
||||||
|
name="option_confirmed" value=0 checked><%= __('No') %>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
<tr>
|
||||||
|
<th scope="row">
|
||||||
|
<%= __('Format') %>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="option_format"
|
||||||
|
value="csv"
|
||||||
|
checked><%= __('CSV file') %>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="option_format"
|
||||||
|
value="xlsx"><%= __('Excel') %>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="mailpoet_export_process">
|
||||||
|
<th scope="row">
|
||||||
|
<a href="javascript:;"
|
||||||
|
class="button-primary button-disabled wysija mailpoet_export_process"><%= __('Export') %></a>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= stylesheet('export.css') %>
|
<%= stylesheet('importExport.css') %>
|
||||||
|
|
||||||
<%= localize({
|
<%= localize({
|
||||||
}) %>
|
}) %>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
// define data variables
|
||||||
|
var
|
||||||
|
segments = <%= segments|raw %>,
|
||||||
|
segmentsWithConfirmedSubscribers =
|
||||||
|
<%= segmentsWithConfirmedSubscribers|raw %>,
|
||||||
|
subscriberFieldsSelect2 =
|
||||||
|
<%= subscriberFieldsSelect2|raw %>,
|
||||||
|
exportData = {
|
||||||
|
segments: segments.length || null,
|
||||||
|
segmentsWithConfirmedSubscribers: segmentsWithConfirmedSubscribers.length || null,
|
||||||
|
exportConfirmedOption: false,
|
||||||
|
groupBySegmentOption: (segments.length > 1 || segmentsWithConfirmedSubscribers.length > 1) ? true : null
|
||||||
|
},
|
||||||
|
export_location = '',
|
||||||
|
export_directory = '',
|
||||||
|
export_url = '';
|
||||||
</script>
|
</script>
|
||||||
<% endblock %>
|
<% endblock %>
|
@ -11,7 +11,7 @@
|
|||||||
<% include 'import/step3.html' %>
|
<% include 'import/step3.html' %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= stylesheet('import.css') %>
|
<%= stylesheet('importExport.css') %>
|
||||||
|
|
||||||
<%= localize({
|
<%= localize({
|
||||||
'noMailChimpLists': __('No active lists found.'),
|
'noMailChimpLists': __('No active lists found.'),
|
||||||
|
Reference in New Issue
Block a user