Include list column for excel subscribers export
MAILPOET-3852
This commit is contained in:
committed by
Veljko V
parent
69da013483
commit
1cdbf31b50
@@ -19,6 +19,7 @@ class Export {
|
||||
public $subscriberFields;
|
||||
public $subscriberCustomFields;
|
||||
public $formattedSubscriberFields;
|
||||
public $formattedSubscriberFieldsWithList;
|
||||
public $exportPath;
|
||||
public $exportFile;
|
||||
public $exportFileURL;
|
||||
@@ -64,6 +65,8 @@ class Export {
|
||||
$this->subscriberFields,
|
||||
$this->subscriberCustomFields
|
||||
);
|
||||
$this->formattedSubscriberFieldsWithList = $this->formattedSubscriberFields;
|
||||
$this->formattedSubscriberFieldsWithList[] = WPFunctions::get()->__('List', 'mailpoet');
|
||||
$this->exportPath = self::getExportPath();
|
||||
$this->exportFile = $this->getExportFile($this->exportFormatOption);
|
||||
$this->exportFileURL = $this->getExportFileURL($this->exportFile);
|
||||
@@ -105,7 +108,7 @@ class Export {
|
||||
|
||||
public function generateCSV(): int {
|
||||
$processedSubscribers = 0;
|
||||
$formattedSubscriberFields = $this->formattedSubscriberFields;
|
||||
$formattedSubscriberFields = $this->formattedSubscriberFieldsWithList;
|
||||
$cSVFile = fopen($this->exportFile, 'w');
|
||||
if ($cSVFile === false) {
|
||||
throw new \Exception(__('Failed opening file for export.', 'mailpoet'));
|
||||
@@ -113,7 +116,6 @@ class Export {
|
||||
$formatCSV = function($row) {
|
||||
return '"' . str_replace('"', '\"', $row) . '"';
|
||||
};
|
||||
$formattedSubscriberFields[] = WPFunctions::get()->__('List', 'mailpoet');
|
||||
// add UTF-8 BOM (3 bytes, hex EF BB BF) at the start of the file for
|
||||
// Excel to automatically recognize the encoding
|
||||
fwrite($cSVFile, chr(0xEF) . chr(0xBB) . chr(0xBF));
|
||||
@@ -165,7 +167,7 @@ class Export {
|
||||
$this->writeXLSX(
|
||||
$xLSXWriter,
|
||||
$subscriber['segment_name'],
|
||||
$this->formattedSubscriberFields
|
||||
$this->formattedSubscriberFieldsWithList
|
||||
);
|
||||
$processedSegments[] = $currentSegment;
|
||||
}
|
||||
@@ -174,14 +176,18 @@ class Export {
|
||||
$rTLRegex = '/\p{Arabic}|\p{Hebrew}/u';
|
||||
if (!$xLSXWriter->rtl && (
|
||||
preg_grep($rTLRegex, $subscriber) ||
|
||||
preg_grep($rTLRegex, $this->formattedSubscriberFields))
|
||||
preg_grep($rTLRegex, $this->formattedSubscriberFieldsWithList))
|
||||
) {
|
||||
$xLSXWriter->rtl = true;
|
||||
}
|
||||
|
||||
$xlsxData = $this->formatSubscriberData($subscriber);
|
||||
$xlsxData[] = ucwords($subscriber['segment_name']);
|
||||
|
||||
$this->writeXLSX(
|
||||
$xLSXWriter,
|
||||
$lastSegment,
|
||||
$this->formatSubscriberData($subscriber)
|
||||
$xlsxData
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -153,6 +153,13 @@ class ExportTest extends \MailPoetTest {
|
||||
$this->export->subscriberCustomFields
|
||||
)
|
||||
);
|
||||
expect($this->export->formattedSubscriberFieldsWithList)
|
||||
->equals(
|
||||
\array_merge(
|
||||
$this->export->formattedSubscriberFields,
|
||||
[\MailPoet\WP\Functions::get()->__('List', 'mailpoet')]
|
||||
)
|
||||
);
|
||||
expect(
|
||||
preg_match(
|
||||
'|' .
|
||||
|
Reference in New Issue
Block a user