forked from extern/egroupware
Add default implementation of equal and less_than condition functions, fix problem with blanks in mapping
This commit is contained in:
parent
2b1215af8b
commit
e7caf2a9f0
@ -54,7 +54,7 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected static $conditions = array( 'exists', 'greater', 'greater or equal', );
|
protected static $conditions = array( 'exists', 'equal', 'less_than');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the definition that will be used to deal with the CSV file
|
* This is the definition that will be used to deal with the CSV file
|
||||||
@ -211,23 +211,16 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
|
|||||||
{
|
{
|
||||||
if ( $this->_definition->plugin_options['conditions'] ) {
|
if ( $this->_definition->plugin_options['conditions'] ) {
|
||||||
foreach ( $this->_definition->plugin_options['conditions'] as $condition ) {
|
foreach ( $this->_definition->plugin_options['conditions'] as $condition ) {
|
||||||
|
$result = false;
|
||||||
switch ( $condition['type'] ) {
|
switch ( $condition['type'] ) {
|
||||||
// exists
|
// exists
|
||||||
case 'exists' :
|
case 'exists' :
|
||||||
// Check for that record
|
// Check for that record
|
||||||
$result = $this->exists($record, array($contition['string']), $matches);
|
$result = $this->exists($record, $condition, $matches);
|
||||||
if($result)
|
break;
|
||||||
{
|
case 'equal':
|
||||||
// Apply true action to any matching records found
|
// Match on field
|
||||||
$action = $condition['true'];
|
$result = $this->equal($record, $condition, $matches);
|
||||||
$success = ($this->action( $action['action'], $record, $import_csv->get_current_position() ));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Apply false action if no matching records found
|
|
||||||
$action = $condition['false'];
|
|
||||||
$success = ($this->action( $action['action'], $record, $import_csv->get_current_position() ));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// not supported action
|
// not supported action
|
||||||
@ -235,6 +228,18 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
|
|||||||
die('condition / action not supported!!!');
|
die('condition / action not supported!!!');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if($result)
|
||||||
|
{
|
||||||
|
// Apply true action to any matching records found
|
||||||
|
$action = $condition['true'];
|
||||||
|
$success = ($this->action( $action['action'], $record, $import_csv->get_current_position() ));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Apply false action if no matching records found
|
||||||
|
$action = $condition['false'];
|
||||||
|
$success = ($this->action( $action['action'], $record, $import_csv->get_current_position() ));
|
||||||
|
}
|
||||||
if ($action['stop']) break;
|
if ($action['stop']) break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -254,10 +259,38 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
|
|||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected function exists(iface_egw_record &$record, Array &$condition, &$matches = array())
|
protected function exists(importexport_iface_egw_record &$record, Array &$condition, &$matches = array())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for records where the selected field matches the given value
|
||||||
|
*
|
||||||
|
* @param record
|
||||||
|
* @param condition array = array('string' => field name, 'type' => Type of condition, 'op_2' => second operand)
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected function equal(importexport_iface_egw_record &$record, Array &$condition)
|
||||||
|
{
|
||||||
|
$field = $condition['string'];
|
||||||
|
return $record->$field == $condition['op_2'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for records where the selected field is less than the given value.
|
||||||
|
* PHP's concept of 'less than' is used.
|
||||||
|
*
|
||||||
|
* @param record
|
||||||
|
* @param condition array = array('string' => field name, 'type' => Type of condition, 'op_2' => second operand)
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected function less_than(importexport_iface_egw_record &$record, Array &$condition)
|
||||||
|
{
|
||||||
|
$field = $condition['string'];
|
||||||
|
return $record->$field < $condition['op_2'];
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* perform the required action
|
* perform the required action
|
||||||
*
|
*
|
||||||
|
@ -276,7 +276,7 @@ class importexport_wizard_basic_import_csv
|
|||||||
$index = $field['index'];
|
$index = $field['index'];
|
||||||
foreach(array('conversion'=>'field_conversion', 'field' => 'field_mapping') as $id => $dest)
|
foreach(array('conversion'=>'field_conversion', 'field' => 'field_mapping') as $id => $dest)
|
||||||
{
|
{
|
||||||
if(trim($field[$id]) != '')
|
if(trim($field[$id]) != '' && $field[$id] !== '--NONE--')
|
||||||
{
|
{
|
||||||
$content[$dest][$index] = trim($field[$id]);
|
$content[$dest][$index] = trim($field[$id]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user