Set empty fields to '' instead of retaining their value (null or 0)

This commit is contained in:
Nathan Gray 2012-04-17 16:36:31 +00:00
parent dff86e4842
commit c200bfa403

View File

@ -218,7 +218,7 @@ class importexport_export_csv implements importexport_iface_export_record
* @param selects Lookup values for select boxes * @param selects Lookup values for select boxes
* @param links Appnames for links to fetch the title * @param links Appnames for links to fetch the title
* @param methods Method will be called with the record's value * @param methods Method will be called with the record's value
* *
* @return Array of fields to be added to list of fields needing conversion * @return Array of fields to be added to list of fields needing conversion
*/ */
public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) { public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) {
@ -302,6 +302,10 @@ class importexport_export_csv implements importexport_iface_export_record
$record->$name = lang($selects[$name][$record->$name]); $record->$name = lang($selects[$name][$record->$name]);
} }
} }
else
{
$record->$name = '';
}
} }
foreach((array)$fields['links'] as $name) { foreach((array)$fields['links'] as $name) {
if($record->$name) { if($record->$name) {
@ -314,6 +318,10 @@ class importexport_export_csv implements importexport_iface_export_record
$record->$name = egw_link::title($links[$name], $record->$name); $record->$name = egw_link::title($links[$name], $record->$name);
} }
} }
else
{
$record->$name = '';
}
} }
foreach((array)$fields['select-account'] as $name) { foreach((array)$fields['select-account'] as $name) {
// Compare against null to deal with empty arrays // Compare against null to deal with empty arrays
@ -328,6 +336,10 @@ class importexport_export_csv implements importexport_iface_export_record
$record->$name = common::grab_owner_name($record->$name); $record->$name = common::grab_owner_name($record->$name);
} }
} }
else
{
$record->$name = '';
}
} }
foreach((array)$fields['select-bool'] as $name) { foreach((array)$fields['select-bool'] as $name) {
if($record->$name != null) { if($record->$name != null) {
@ -339,11 +351,13 @@ class importexport_export_csv implements importexport_iface_export_record
if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '. if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '.
($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format
if (!$record->$name) $record->$name = '';
} }
foreach((array)$fields['date'] as $name) { foreach((array)$fields['date'] as $name) {
//if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format //if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format
if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format
if (!$record->$name) $record->$name = '';
} }
// Some custom methods for conversion // Some custom methods for conversion
@ -360,13 +374,17 @@ class importexport_export_csv implements importexport_iface_export_record
} }
$record->$name = implode(', ',$cats); $record->$name = implode(', ',$cats);
} }
else
{
$record->$name = '';
}
} }
} }
/** /**
* destructor * destructor
* *
* @return * @return
*/ */
public function __destruct() { public function __destruct() {
@ -388,7 +406,7 @@ class importexport_export_csv implements importexport_iface_export_record
if($writeDelimiter) $string .= $delimiter; if($writeDelimiter) $string .= $delimiter;
$string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure; $string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure;
$writeDelimiter = true; $writeDelimiter = true;
} }
$string .= "\n"; $string .= "\n";
// do charset translation // do charset translation