Add new import translation function list(sep,field,index) to explode a field and pick one part

This commit is contained in:
Nathan Gray 2011-08-05 22:04:05 +00:00
parent 8b2dae28f7
commit 89c2097894
2 changed files with 11 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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);