mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
Importexport - handle select values that are label,value pairs as well as name => value
This commit is contained in:
parent
3e03f77339
commit
0c9904a21a
@ -32,7 +32,7 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
* @var array array with conversions to be done in form: egw_field_name => conversion_string
|
* @var array array with conversions to be done in form: egw_field_name => conversion_string
|
||||||
*/
|
*/
|
||||||
protected $conversion = array();
|
protected $conversion = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Current record being processed
|
* @var Current record being processed
|
||||||
*/
|
*/
|
||||||
@ -42,22 +42,22 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
* @var array holding the current record
|
* @var array holding the current record
|
||||||
*/
|
*/
|
||||||
protected $record_array = array();
|
protected $record_array = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var translation holds (charset) Api\Translation object
|
* @var translation holds (charset) Api\Translation object
|
||||||
*/
|
*/
|
||||||
protected $translation;
|
protected $translation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string charset of csv file
|
* @var string charset of csv file
|
||||||
*/
|
*/
|
||||||
protected $csv_charset;
|
protected $csv_charset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int holds number of exported records
|
* @var int holds number of exported records
|
||||||
*/
|
*/
|
||||||
protected $num_of_records = 0;
|
protected $num_of_records = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int holds max. number of records allowed to be exported
|
* @var int holds max. number of records allowed to be exported
|
||||||
*/
|
*/
|
||||||
@ -67,7 +67,7 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
* @var stream stream resource of csv file
|
* @var stream stream resource of csv file
|
||||||
*/
|
*/
|
||||||
protected $handle;
|
protected $handle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array csv specific options
|
* @var array csv specific options
|
||||||
*/
|
*/
|
||||||
@ -85,7 +85,7 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
'date' => array(),
|
'date' => array(),
|
||||||
'select-cat' => array('cat_id')
|
'select-cat' => array('cat_id')
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache of parsed custom field parameters
|
* Cache of parsed custom field parameters
|
||||||
*/
|
*/
|
||||||
@ -116,7 +116,7 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
if($this->export_limit == 'no') throw new Api\Exception\NoPermission\Admin('Export disabled');
|
if($this->export_limit == 'no') throw new Api\Exception\NoPermission\Admin('Export disabled');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets field mapping
|
* sets field mapping
|
||||||
*
|
*
|
||||||
@ -136,7 +136,7 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
}
|
}
|
||||||
$this->mapping = $_mapping;
|
$this->mapping = $_mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets conversion.
|
* Sets conversion.
|
||||||
* @see importexport_helper_functions::conversion.
|
* @see importexport_helper_functions::conversion.
|
||||||
@ -146,7 +146,7 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
public function set_conversion( array $_conversion) {
|
public function set_conversion( array $_conversion) {
|
||||||
$this->conversion = $_conversion;
|
$this->conversion = $_conversion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* exports a record into resource of handle
|
* exports a record into resource of handle
|
||||||
*
|
*
|
||||||
@ -156,7 +156,7 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
public function export_record( importexport_iface_egw_record $_record ) {
|
public function export_record( importexport_iface_egw_record $_record ) {
|
||||||
$this->record = $_record;
|
$this->record = $_record;
|
||||||
$this->record_array = $_record->get_record_array();
|
$this->record_array = $_record->get_record_array();
|
||||||
|
|
||||||
// begin with fieldnames ?
|
// begin with fieldnames ?
|
||||||
if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) {
|
if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) {
|
||||||
if($this->csv_options['begin_with_fieldnames'] == 'label') {
|
if($this->csv_options['begin_with_fieldnames'] == 'label') {
|
||||||
@ -198,12 +198,12 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
if($this->export_limit && $this->num_of_records >= $this->export_limit) {
|
if($this->export_limit && $this->num_of_records >= $this->export_limit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do conversions
|
// do conversions
|
||||||
if ( !empty( $this->conversion )) {
|
if ( !empty( $this->conversion )) {
|
||||||
$this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion );
|
$this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion );
|
||||||
}
|
}
|
||||||
|
|
||||||
// do fieldmapping
|
// do fieldmapping
|
||||||
if ( !empty( $this->mapping ) ) {
|
if ( !empty( $this->mapping ) ) {
|
||||||
$record_data = $this->record_array;
|
$record_data = $this->record_array;
|
||||||
@ -212,7 +212,7 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
$this->record_array[$csv_field] = $record_data[$egw_field];
|
$this->record_array[$csv_field] = $record_data[$egw_field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self::fputcsv( $this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure'] );
|
self::fputcsv( $this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure'] );
|
||||||
$this->num_of_records++;
|
$this->num_of_records++;
|
||||||
}
|
}
|
||||||
@ -322,7 +322,8 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
if(is_array($record->$name)) {
|
if(is_array($record->$name)) {
|
||||||
$names = array();
|
$names = array();
|
||||||
foreach($record->$name as $_name) {
|
foreach($record->$name as $_name) {
|
||||||
$names[] = lang($selects[$name][$_name]);
|
$option = $selects[$name][$_name];
|
||||||
|
$names[] = lang(is_array($option) && $option['label'] ? $option['label'] : $option);
|
||||||
}
|
}
|
||||||
$record->$name = implode(', ', $names);
|
$record->$name = implode(', ', $names);
|
||||||
} else {
|
} else {
|
||||||
@ -445,7 +446,7 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public function __destruct() {
|
public function __destruct() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -466,12 +467,12 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
$writeDelimiter = true;
|
$writeDelimiter = true;
|
||||||
}
|
}
|
||||||
$string .= "\n";
|
$string .= "\n";
|
||||||
|
|
||||||
// do charset translation
|
// do charset translation
|
||||||
$string = $this->translation->convert( $string, $this->translation->charset(), $this->csv_charset );
|
$string = $this->translation->convert( $string, $this->translation->charset(), $this->csv_charset );
|
||||||
|
|
||||||
fwrite($filePointer, $string);
|
fwrite($filePointer, $string);
|
||||||
|
|
||||||
}
|
}
|
||||||
} // end export_csv_record
|
} // end export_csv_record
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user