Improve human friendly value handling

This commit is contained in:
Nathan Gray 2011-04-06 23:12:50 +00:00
parent 927528e2ad
commit cdf246b0dc
3 changed files with 31 additions and 8 deletions

View File

@ -22,6 +22,14 @@ class calendar_egw_record implements importexport_iface_egw_record
private $record = array(); private $record = array();
private static $bo; private static $bo;
public static $types = array(
'select-cat' => array('category'),
'select-account'=> array('owner','creator', 'modifier'),
'date-time' => array('modified', 'created','start','end','recur_date'),
'select-bool' => array('public', 'non_blocking'),
'select' => array('priority'),
);
/** /**
* constructor * constructor
* reads record from backend if identifier is given. * reads record from backend if identifier is given.

View File

@ -48,13 +48,19 @@ class calendar_export_csv implements importexport_iface_export_plugin {
$export_object = new importexport_export_csv($_stream, (array)$options); $export_object = new importexport_export_csv($_stream, (array)$options);
$export_object->set_mapping($options['mapping']); $export_object->set_mapping($options['mapping']);
$convert_fields = importexport_export_csv::$types; $convert_fields = calendar_egw_record::$types;
$convert_fields['select-account'][] = 'owner';
$convert_fields['date-time'][] = 'start';
$convert_fields['date-time'][] = 'end';
$recurrence = $this->bo->recur_types; $recurrence = $this->bo->recur_types;
$lookups = array(
'priority' => Array(
0 => '',
1 => lang('Low'),
2 => lang('Normal'),
3 => lang('High')
),
);
// $options['selection'] is array of identifiers as this plugin doesn't // $options['selection'] is array of identifiers as this plugin doesn't
// support other selectors atm. // support other selectors atm.
$record = new calendar_egw_record(); $record = new calendar_egw_record();
@ -72,7 +78,7 @@ class calendar_export_csv implements importexport_iface_export_plugin {
// Standard stuff // Standard stuff
if($options['convert']) { if($options['convert']) {
importexport_export_csv::convert($record, $convert_fields, 'calendar'); importexport_export_csv::convert($record, $convert_fields, 'calendar', $lookups);
} else { } else {
// Implode arrays, so they don't say 'Array' // Implode arrays, so they don't say 'Array'
foreach($record->get_record_array() as $key => $value) { foreach($record->get_record_array() as $key => $value) {

View File

@ -149,12 +149,24 @@ class calendar_import_csv implements importexport_iface_import_plugin {
$status_map = array_flip($this->bo->verbose_status); $status_map = array_flip($this->bo->verbose_status);
$role_map = array_flip($this->bo->roles); $role_map = array_flip($this->bo->roles);
$lookups = array(
'priority' => Array(
0 => '',
1 => lang('Low'),
2 => lang('Normal'),
3 => lang('High')
),
);
while ( $record = $import_csv->get_record() ) { while ( $record = $import_csv->get_record() ) {
$success = false; $success = false;
// don't import empty records // don't import empty records
if( count( array_unique( $record ) ) < 2 ) continue; if( count( array_unique( $record ) ) < 2 ) continue;
// Automatic conversions
importexport_import_csv::convert($record, calendar_egw_record::$types, 'calendar', $lookups);
// Set owner, unless it's supposed to come from CSV file // Set owner, unless it's supposed to come from CSV file
if($_definition->plugin_options['owner_from_csv']) { if($_definition->plugin_options['owner_from_csv']) {
if(!is_numeric($record['owner'])) { if(!is_numeric($record['owner'])) {
@ -169,9 +181,6 @@ class calendar_import_csv implements importexport_iface_import_plugin {
$record['owner'] = $_definition->plugin_options['owner']; $record['owner'] = $_definition->plugin_options['owner'];
} }
// Automatically handle text categories without explicit translation
$record['cat_id'] = importexport_helper_functions::cat_name2id($record['cat_id']);
if ($record['participants'] && !is_array($record['participants'])) { if ($record['participants'] && !is_array($record['participants'])) {
// Importing participants in human friendly format // Importing participants in human friendly format
preg_match_all('/(([^(]+?)( \(([0-9]+)\))? \((.+?)\) ([^,]+)),?/',$record['participants'],$participants); preg_match_all('/(([^(]+?)( \(([0-9]+)\))? \((.+?)\) ([^,]+)),?/',$record['participants'],$participants);