mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
- CSV import improvement: better guess of the possible reconciliation keys (esp. with ExternalKeys)
SVN:trunk[556]
This commit is contained in:
@@ -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("</table>\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(
|
||||
<<<EOF
|
||||
$('select[name^=field]').change( DoCheckMapping );
|
||||
|
||||
Reference in New Issue
Block a user