From d6a73a3bb7e7f33252a61bd7ec3bbcb01434910b Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Mon, 5 Jul 2010 13:29:48 +0000 Subject: [PATCH] - CSV import improvement: better guess of the possible reconciliation keys (esp. with ExternalKeys) SVN:trunk[556] --- pages/ajax.csvimport.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/pages/ajax.csvimport.php b/pages/ajax.csvimport.php index f519ab3f9..f169bd968 100644 --- a/pages/ajax.csvimport.php +++ b/pages/ajax.csvimport.php @@ -55,6 +55,25 @@ function IsIdField($sClassName, $sFieldCode) return $bResult; } +/** + * Get all the fields xxx->yyy based on the field xxx which is an external key + * @param string $sExtKeyAttCode Attribute code of the external key + * @return Ash List of codes=>display name: xxx->yyy where yyy are the reconciliation keys for the object xxx + */ +function GetMappingsForExtKey($sAttCode, AttributeDefinition $oExtKeyAttDef) +{ + $aResult = array(); + $sTargetClass = $oExtKeyAttDef->GetTargetClass(); + foreach(MetaModel::ListAttributeDefs($sTargetClass) as $sTargetAttCode => $oTargetAttDef) + { + if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode)) + { + $aResult[$sAttCode.'->'.$sTargetAttCode] = $oExtKeyAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel(); + } + } + return $aResult; +} + /** * Helper function to build the mapping drop-down list for a field * Spec: Possible choices are "writable" fields in this class plus external fields that are listed as reconciliation keys @@ -100,7 +119,7 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode)) { $aChoices[$sAttCode.'->'.$sTargetAttCode] = $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel(); - if (($sFieldName == $aChoices[$sAttCode.'->'.$sTargetAttCode]) || ($sFieldName == ($sAttCode.'->'.$sTargetAttCode)) ) + if ((strcasecmp($sFieldName, $aChoices[$sAttCode.'->'.$sTargetAttCode]) == 0) || (strcasecmp($sFieldName, ($sAttCode.'->'.$sTargetAttCode)) == 0) ) { $sFieldCode = $sAttCode.'->'.$sTargetAttCode; } @@ -288,7 +307,16 @@ switch($sOperation) } $oPage->add("\n"); $aReconciliationKeys = MetaModel::GetReconcKeys($sClassName); - $sDefaultKeys = '"'.implode('", "',$aReconciliationKeys).'"'; + $aMoreReconciliationKeys = array(); + foreach($aReconciliationKeys as $sAttCode) + { + $oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode); + if ($oAttDef->IsExternalKey()) + { + $aMoreReconciliationKeys = array_keys(GetMappingsForExtKey($sAttCode, $oAttDef)); + } + } + $sDefaultKeys = '"'.implode('", "',array_merge($aReconciliationKeys,$aMoreReconciliationKeys)).'"'; $oPage->add_ready_script( <<