Commit a9b5089c authored by Chenu Denis's avatar Chenu Denis
Browse files

[feature] 5.X compatible version

[feature] Allow to strip new line only on content
parent 131cda76
......@@ -5,7 +5,7 @@
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2018 Denis Chenu <http://www.sondages.pro>
* @license GPL v3
* @version 0.0.0
* @version 0.2.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -29,13 +29,13 @@ class CsvFixedWriter extends Writer
/* @var boolean */
public $striptag;
/* @var boolean|string */
public $stripnewline;
public $stripnewline = false;
/* @var boolean */
public $addnewline;
/* @var string */
public $addnewline = false;
/* @var null|string */
private $output;
/* @var boolean */
private $hasOutputHeader;
private $hasOutputHeader = false;
/**
* Output file, can be a file or php://output
......@@ -88,7 +88,7 @@ class CsvFixedWriter extends Writer
if ($this->doHeaders === true) {
$index = 0;
foreach ($headers as $header) {
$headers[$index] = $this->updateValues($header);
$headers[$index] = $this->updateValues($header, true);
$index++;
}
//Output the header...once and only once.
......@@ -120,10 +120,11 @@ class CsvFixedWriter extends Writer
* @param string $value
* @return string
*/
protected function updateValues($string)
protected function updateValues($string, $header = false)
{
$string = preg_replace(array('~\R~u'), array("\n"), $string);
if($this->striptag || $this->stripnewline) {
$stripnewline = (($header && $this->stripnewline == "header") || $this->stripnewline == "always");
if($this->striptag || $stripnewline) {
$string = str_replace("\n"," ", $string);
}
if($this->striptag) {
......
<?xml version="1.0" encoding="UTF-8"?>
<config>
<metadata>
<name>exportCsvFixed</name>
<type>plugin</type>
<creationDate>2018-08-04</creationDate>
<last_update>2022-10-19</last_update>
<author>Denis Chenu</author>
<authorUrl>https://www.sondages.pro</authorUrl>
<license>GNU Affero General Public License version 3 or later</license>
<version>0.2.0</version>
<description><![CDATA[Allow to configure some csv options globally.]]></description>
</metadata>
<compatibility>
<version>3</version>
<version>4</version>
<version>5</version>
</compatibility>
<updaters disabled="disabled"></updaters>
</config>
......@@ -3,9 +3,9 @@
* exportCsvConfigurable
*
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2018 Denis Chenu <http://www.sondages.pro>
* @copyright 2018-2022 Denis Chenu <http://www.sondages.pro>
* @license GPL v3
* @version 0.0.0
* @version 0.2.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -42,7 +42,7 @@ class exportCsvFixed extends PluginBase
"\t" => "Tabulation",
),
'label'=>'Separator',
'default'=>"\t",
'default'=>",",
),
'enclosure'=>array(
'type'=>'select',
......@@ -62,7 +62,8 @@ class exportCsvFixed extends PluginBase
'stripnewline'=>array(
'type'=>'select',
'options'=>array(
//'survey' => "On survey text (not for user entered tex)",
//'survey' => 'On survey part, not user data', // Need to check question type … @todo
'header' => "On header, not on data",
'always' => "Yes (always)",
),
'htmlOptions' => array(
......@@ -78,6 +79,17 @@ class exportCsvFixed extends PluginBase
),
);
/**
* @inheritdoc
* Remove settings according to version
*/
public function getPluginSettings($getValues = true)
{
if (intval(App()->getConfig('versionnumber') >= 5)) {
unset($pluginSettings['delimiter']);
}
}
/** @inheritdoc */
public function init() {
$this->subscribe('listExportPlugins');
$this->subscribe('listExportOptions');
......@@ -88,7 +100,7 @@ class exportCsvFixed extends PluginBase
{
$event = $this->getEvent();
$type = $event->get('type');
$label = $this->gT("fixed csv");
$label = $this->gT("Fixed csv");
if($this->get('replace',null,null,$this->settings['replace']['default'])) {
$label = $this->gT("CSV");
}
......@@ -102,6 +114,7 @@ class exportCsvFixed extends PluginBase
break;
}
}
/**
* Registers this export type
*/
......@@ -124,7 +137,11 @@ class exportCsvFixed extends PluginBase
switch ($type) {
case 'csv-fixed':
$writer = new CsvFixedWriter();
$writer->delimiter=$this->get('delimiter',null,null,$this->settings['delimiter']['default']);
if (intval(App()->getConfig('versionnumber') >= 5)) {
$writer->delimiter = App()->getRequest()->getPost('csvfieldseparator',',');
} else {
$writer->delimiter = $this->get('delimiter',null,null,$this->settings['delimiter']['default']);
}
$writer->enclosure=$this->get('enclosure',null,null,$this->settings['enclosure']['default']);
$writer->striptag=$this->get('striptag',null,null,$this->settings['striptag']['default']);
$writer->stripnewline=$this->get('stripnewline',null,null,$this->settings['stripnewline']['default']);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment