From 89c209789403edb8a54d92fe047674579db54b94 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 5 Aug 2011 22:04:05 +0000 Subject: [PATCH] Add new import translation function list(sep,field,index) to explode a field and pick one part --- .../inc/class.importexport_definitions_ui.inc.php | 2 +- .../inc/class.importexport_helper_functions.inc.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/importexport/inc/class.importexport_definitions_ui.inc.php b/importexport/inc/class.importexport_definitions_ui.inc.php index 3a18135428..7b017f9176 100644 --- a/importexport/inc/class.importexport_definitions_ui.inc.php +++ b/importexport/inc/class.importexport_definitions_ui.inc.php @@ -368,7 +368,7 @@ class importexport_definitions_ui $bodefinitions->save($definition); } catch (Exception $ex) { $failed++; - $msg .= lang('Duplicate name'); + $msg .= lang('Duplicate name, please choose another.'); continue; } } diff --git a/importexport/inc/class.importexport_helper_functions.inc.php b/importexport/inc/class.importexport_helper_functions.inc.php index 8375ce90a1..58567b2f74 100755 --- a/importexport/inc/class.importexport_helper_functions.inc.php +++ b/importexport/inc/class.importexport_helper_functions.inc.php @@ -218,10 +218,13 @@ class importexport_helper_functions { * This constructs something like * Company: FamilyName, GivenName or FamilyName, GivenName if 'Company' is empty. * - * Moreover the two helper function cat() and account() can be used. + * Moreover the following helper functions can be used: * cat(Cat1,...,CatN) returns a (','-separated) list with the cat_id's. If a * category isn't found, it will be automaticaly added. * + * account(name) returns an account ID, if found in the system + * list(sep, data, index) lets you explode a field on sep, then select just one part (index) + * * Patterns as well as the replacement can be regular expressions (the replacement is done * via str_replace). * @@ -259,7 +262,7 @@ class importexport_helper_functions { // conversion list may be longer than $_record aka (no_csv) $val = array_key_exists( $idx, $_record ) ? $_record[$idx] : ''; - $c_functions = array('cat', 'account', 'strtotime'); + $c_functions = array('cat', 'account', 'strtotime', 'list'); if($_cclass) { // Add in additional methods $reflection = new ReflectionClass(get_class($_cclass)); @@ -310,6 +313,11 @@ class importexport_helper_functions { case 'strtotime' : list( $string, $format ) = explode( ',', $data ); return self::custom_strtotime( trim( $string ), trim( $format ) ); + case 'list': + list( $split, $data, $index) = explode(',',$data); + $exploded = explode($split, $data); + // 1 based indexing for user ease + return $exploded[$index - 1]; default : if(self::$cclass && method_exists(self::$cclass, $action)) { $class = get_class(self::$cclass);