feature renamed the module_export_csv file and edited the iso and utf files to override the write_title and write_record functions to initialize EXPORT_CSV_FORCE_CHARSET

This commit is contained in:
FLIO 2023-02-07 12:13:34 +01:00
parent 28d0f492f4
commit c8c998044b
3 changed files with 74 additions and 4 deletions

View File

@ -21,7 +21,7 @@
* \brief File of class to build exports with CSV format
*/
require_once DOL_DOCUMENT_ROOT.'/core/modules/export/module_export_csv.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/export/export_csv.modules.php';
// avoid timeout for big export
set_time_limit(0);
@ -62,4 +62,40 @@ class ExportCsvIso extends ExportCsv
$this->label_lib = 'Dolibarr';
$this->version_lib = DOL_VERSION;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Output title line into file
*
* @param array $array_export_fields_label Array with list of label of fields
* @param array $array_selected_sorted Array with list of field to export
* @param Translate $outputlangs Object lang to translate values
* @param array $array_types Array with types of fields
* @return int <0 if KO, >0 if OK
*/
public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
{
global $conf;
$conf->global->EXPORT_CSV_FORCE_CHARSET = 'ISO-8859-1';
parent::write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Output record line into file
*
* @param array $array_selected_sorted Array with list of field to export
* @param resource $objp A record from a fetch with all fields from select
* @param Translate $outputlangs Object lang to translate values
* @param array $array_types Array with types of fields
* @return int <0 if KO, >0 if OK
*/
public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
{
global $conf;
$conf->global->EXPORT_CSV_FORCE_CHARSET = 'ISO-8859-1';
parent::write_record($array_selected_sorted, $objp, $outputlangs, $array_types);
}
}

View File

@ -21,7 +21,7 @@
* \brief File of class to build exports with CSV format
*/
require_once DOL_DOCUMENT_ROOT.'/core/modules/export/module_export_csv.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/export/export_csv.modules.php';
// avoid timeout for big export
set_time_limit(0);
@ -47,8 +47,6 @@ class ExportCsvUtf8 extends ExportCsv
$this->separator = $conf->global->EXPORT_CSV_SEPARATOR_TO_USE;
}
$conf->global->EXPORT_CSV_FORCE_CHARSET = 'UTF-8';
$this->escape = '"';
$this->enclosure = '"';
$this->id = 'csvutf8'; // Same value then xxx in file name export_xxx.modules.php
@ -62,4 +60,40 @@ class ExportCsvUtf8 extends ExportCsv
$this->label_lib = 'Dolibarr';
$this->version_lib = DOL_VERSION;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Output title line into file
*
* @param array $array_export_fields_label Array with list of label of fields
* @param array $array_selected_sorted Array with list of field to export
* @param Translate $outputlangs Object lang to translate values
* @param array $array_types Array with types of fields
* @return int <0 if KO, >0 if OK
*/
public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
{
global $conf;
$conf->global->EXPORT_CSV_FORCE_CHARSET = 'UTF-8';
parent::write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Output record line into file
*
* @param array $array_selected_sorted Array with list of field to export
* @param resource $objp A record from a fetch with all fields from select
* @param Translate $outputlangs Object lang to translate values
* @param array $array_types Array with types of fields
* @return int <0 if KO, >0 if OK
*/
public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
{
global $conf;
$conf->global->EXPORT_CSV_FORCE_CHARSET = 'UTF-8';
parent::write_record($array_selected_sorted, $objp, $outputlangs, $array_types);
}
}