瀏覽代碼

#777 mandatory fields that are external keys are now displayed with a star before the arrow: ExtkeyName*->ReconciliationField. In import the old syntax is supported as well.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2908 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 11 年之前
父節點
當前提交
eee21a7dec
共有 4 個文件被更改,包括 23 次插入18 次删除
  1. 1 6
      application/cmdbabstract.class.inc.php
  2. 7 4
      core/metamodel.class.php
  3. 8 7
      pages/ajax.csvimport.php
  4. 7 1
      webservices/import.php

+ 1 - 6
application/cmdbabstract.class.inc.php

@@ -1041,12 +1041,7 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
 			}
 			foreach($aList[$sAlias] as $sAttCodeEx => $oAttDef)
 			{
-				$sStar = '';
-				if (!$oAttDef->IsNullAllowed() && isset($aParams['showMandatoryFields']))
-				{
-					$sStar = '*';
-				}
-				$aHeader[] = ($bLocalize ? MetaModel::GetLabel($sClassName, $sAttCodeEx) : $sAttCodeEx).$sStar;
+				$aHeader[] = $bLocalize ? MetaModel::GetLabel($sClassName, $sAttCodeEx, isset($aParams['showMandatoryFields'])) : $sAttCodeEx;
 			}
 		}
 		$sHtml = implode($sSeparator, $aHeader)."\n";

+ 7 - 4
core/metamodel.class.php

@@ -913,9 +913,10 @@ abstract class MetaModel
 	 * Get the attribute label
 	 * @param string sClass	Persistent class
 	 * @param string sAttCodeEx Extended attribute code: attcode[->attcode]	 
+	 * @param bool $bShowMandatory If true, add a star character (at the end or before the ->) to show that the field is mandatory
 	 * @return string A user friendly format of the string: AttributeName or AttributeName->ExtAttributeName
 	 */	 	
-	public static function GetLabel($sClass, $sAttCodeEx)
+	public static function GetLabel($sClass, $sAttCodeEx, $bShowMandatory = false)
 	{
 		$sLabel = '';
 		if (preg_match('/(.+)->(.+)/', $sAttCodeEx, $aMatches) > 0)
@@ -923,16 +924,17 @@ abstract class MetaModel
 			$sAttribute = $aMatches[1];
 			$sField = $aMatches[2];
 			$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttribute);
+			$sMandatory = ($bShowMandatory && !$oAttDef->IsNullAllowed()) ? '*' : '';
 			if ($oAttDef->IsExternalKey())
 			{
 				$sTargetClass = $oAttDef->GetTargetClass();
 				$oTargetAttDef = MetaModel::GetAttributeDef($sTargetClass, $sField);
-				$sLabel = $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
+				$sLabel = $oAttDef->GetLabel().$sMandatory.'->'.$oTargetAttDef->GetLabel();
 			}
 			else
 			{
 				// Let's return something displayable... but this should never happen!
-				$sLabel = $oAttDef->GetLabel().'->'.$aMatches[2];
+				$sLabel = $oAttDef->GetLabel().$sMandatory.'->'.$aMatches[2];
 			}
 		}
 		else
@@ -944,7 +946,8 @@ abstract class MetaModel
 			else
 			{
 				$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCodeEx);
-				$sLabel = $oAttDef->GetLabel();
+				$sMandatory = ($bShowMandatory && !$oAttDef->IsNullAllowed()) ? '*' : '';
+				$sLabel = $oAttDef->GetLabel().$sMandatory;
 			}
 		}
 		return $sLabel;

+ 8 - 7
pages/ajax.csvimport.php

@@ -113,6 +113,12 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo
 		// A star character at the end can be used to indicate a mandatory field
 		$sFieldName = $aMatches[1];
 	}
+	else if (preg_match('/^(.+)\*->(.+)$/', $sFieldName, $aMatches))
+	{
+		// Remove any trailing "star" character before the arrow (->)
+		// A star character at the end can be used to indicate a mandatory field
+		$sFieldName = $aMatches[1].'->'.$aMatches[2];
+	}
 	if ($sFieldName == 'id')
 	{
 		$sFieldCode = 'id';
@@ -155,7 +161,7 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo
 					{
 					
 						// When not in advanced mode do not allow to use reconciliation keys (on external keys) if they are themselves external keys !
-						$aChoices[$sAttCode.'->'.$sTargetAttCode] = $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel().$sSuffix.$sStar;
+						$aChoices[$sAttCode.'->'.$sTargetAttCode] = MetaModel::GetLabel($sClassName, $sAttCode.'->'.$sTargetAttCode, true);
 						if ((strcasecmp($sFieldName, $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel().$sSuffix) == 0) || (strcasecmp($sFieldName, ($sAttCode.'->'.$sTargetAttCode.$sSuffix)) == 0) )
 						{
 							$sFieldCode = $sAttCode.'->'.$sTargetAttCode;
@@ -166,12 +172,7 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo
 		}
 		else if ($oAttDef->IsWritable() && (!$oAttDef->IsLinkset() || ($bAdvancedMode && $oAttDef->IsIndirect())))
 		{
-			
-			if (!$oAttDef->IsNullAllowed())
-			{
-				$sStar = '*';
-			}
-			$aChoices[$sAttCode] = $oAttDef->GetLabel().$sStar;
+			$aChoices[$sAttCode] = MetaModel::GetLabel($sClassName, $sAttCode, true);
 			if ( ($sFieldName == $oAttDef->GetLabel()) || ($sFieldName == $sAttCode))
 			{
 				$sFieldCode = $sAttCode;

+ 7 - 1
webservices/import.php

@@ -463,6 +463,12 @@ try
 			// Ignore any trailing "star" (*) that simply indicates a mandatory field
 			$sFieldName = $aMatches[1];
 		}
+		else if (preg_match('/^(.+)\*->(.+)$/', $sFieldName, $aMatches))
+		{
+			// Remove any trailing "star" character before the arrow (->)
+			// A star character at the end can be used to indicate a mandatory field
+			$sFieldName = $aMatches[1].'->'.$aMatches[2];
+		}	
 		if (array_key_exists(strtolower($sFieldName), $aKnownColumnNames))
 		{
 			$aColumns = $aKnownColumnNames[strtolower($sFieldName)];
@@ -481,7 +487,7 @@ try
 		{
 			// Protect against XSS injection
 			$sSafeName = str_replace(array('"', '<', '>'), '', $sFieldName);
-			throw new BulkLoadException("Unknown column: '$sSafeName'");
+			throw new BulkLoadException("Unknown column: '$sSafeName'. Possible columns: ".implode(', ', array_keys($aKnownColumnNames)));
 		}
 	}
 	// Note: at this stage the list of fields is supposed to be made of attcodes (and the symbol '->')