Add export data conversion to a parent class so it can be used by other apps

This commit is contained in:
Nathan Gray 2010-11-04 17:26:30 +00:00
parent e0a2ab959d
commit 70d0e8dad1
2 changed files with 73 additions and 1 deletions

View File

@ -61,6 +61,16 @@ class importexport_export_csv implements importexport_iface_export_record
'delimiter' => ';',
'enclosure' => '"',
);
/**
* List of fields for data conversion
*/
public static $types = array(
'select-account' => array('creator', 'modifier'),
'date-time' => array('modified', 'created'),
'date' => array(),
'select-cat' => array('cat_id')
);
/**
* constructor
@ -149,6 +159,68 @@ class importexport_export_csv implements importexport_iface_export_record
return $this->num_of_records;
}
/**
* Convert system info into a format with a little more transferrable meaning
*
* Uses the static variable $types to convert various datatypes.
*
* @param record Record to be converted
* @parem fields List of field types => field names to be converted
* @param appname Current appname if you want to do custom fields too
*/
public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null) {
if($appname) {
$custom = config::get_customfields($appname);
foreach($custom as $name => $c_field) {
$name = '#' . $name;
switch($c_field['type']) {
case 'date':
$fields['date'][] = $name;
break;
case 'date-time':
$fields['date-time'][] = $name;
break;
case 'select-account':
$fields['select-account'][] = $name;
break;
}
}
}
foreach($fields['select-account'] as $name) {
if ($record->$name) {
if(is_array($record->$name)) {
$names = array();
foreach($record->$name as $_name) {
$names[] = $GLOBALS['egw']->common->grab_owner_name($_name);
}
$record->$name = implode(', ', $names);
} else {
$record->$name = $GLOBALS['egw']->common->grab_owner_name($record->$name);
}
}
}
foreach($fields['date-time'] as $name) {
//if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name); // Standard date format
if ($record->$name) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '.
($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H' : 'h').':m:s',$record->$name); // User date format
}
foreach($fields['date'] as $name) {
//if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format
if ($record->$name) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format
}
foreach($fields['select-cat'] as $name) {
if($record->$name) {
$cats = array();
$ids = is_array($record->$name) ? $record->$name : explode(',', $record->$name);
foreach($ids as $n => $cat_id) {
if ($cat_id) $cats[] = $GLOBALS['egw']->categories->id2name($cat_id);
}
$record->$name = implode(', ',$cats);
}
}
}
/**
* destructor
*

View File

@ -66,7 +66,7 @@ class importexport_wizard_basic_export_csv
*/
function wizard_step30(&$content, &$sel_options, &$readonlys, &$preserv)
{
if($this->debug || true) error_log(get_class($this) . '::wizard_step30->$content '.print_r($content,true));
if($this->debug) error_log(get_class($this) . '::wizard_step30->$content '.print_r($content,true));
// return from step30
if ($content['step'] == 'wizard_step30')
{