Bläddra i källkod

Fixed issue with 1.x datamodels: dashlets of type "badge" not working (preventing from editing an existing dashboard), since 2.0.2

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3113 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 år sedan
förälder
incheckning
9132aa5299
3 ändrade filer med 51 tillägg och 2 borttagningar
  1. 43 0
      core/metamodel.class.php
  2. 1 1
      core/modelreflection.class.inc.php
  3. 7 1
      setup/compiler.class.inc.php

+ 43 - 0
core/metamodel.class.php

@@ -5138,6 +5138,12 @@ abstract class MetaModel
 		}
 		return $aResult;
 	}
+
+	/**
+	 * It is not recommended to use this function: call GetLinkClasses instead
+	 * Return classes having at least to external keys (thus too many classes as compared to GetLinkClasses)	 
+	 * The only difference with EnumLinkingClasses is the output format
+	 */	 	
 	public static function EnumLinksClasses()
 	{
 		// Returns a flat array of classes having at least two external keys
@@ -5160,6 +5166,11 @@ abstract class MetaModel
 		}
 		return $aResult;
 	}
+	/**
+	 * It is not recommended to use this function: call GetLinkClasses instead
+	 * Return classes having at least to external keys (thus too many classes as compared to GetLinkClasses)	 
+	 * The only difference with EnumLinksClasses is the output format
+	 */	 	
 	public static function EnumLinkingClasses($sClass = "")
 	{
 		// N-N links, array of sLinkClass => (array of sAttCode=>sClass)
@@ -5196,6 +5207,38 @@ abstract class MetaModel
 		return $aResult;
 	}
 
+	/**
+	 * This function has two siblings that will be soon deprecated:
+	 * EnumLinkingClasses and EnumLinkClasses
+	 * 	 
+	 * Using GetLinkClasses is the recommended way to determine if a class is
+	 * actually an N-N relation because it is based on the decision made by the
+	 * designer the data model
+	 */	 	
+	public static function GetLinkClasses()
+	{
+		$aRet = array();
+		foreach(self::GetClasses() as $sClass)
+		{
+			if (isset(self::$m_aClassParams[$sClass]["is_link"]))
+			{
+				if (self::$m_aClassParams[$sClass]["is_link"])
+				{
+					$aExtKeys = array();
+					foreach (self::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
+					{
+						if ($oAttDef->IsExternalKey())
+						{
+							$aExtKeys[$sAttCode] = $oAttDef->GetTargetClass();
+						}
+					}
+					$aRet[$sClass] = $aExtKeys;
+				}
+			}
+		}
+		return $aRet;
+	}
+
 	public static function GetLinkLabel($sLinkClass, $sAttCode)
 	{
 		self::_check_subclass($sLinkClass);	

+ 1 - 1
core/modelreflection.class.inc.php

@@ -178,7 +178,7 @@ class ModelReflectionRuntime extends ModelReflection
 		$aClasses = MetaModel::GetClasses($sCategories);
 		if ($bExcludeLinks)
 		{
-			$aExcluded = ProfilesConfig::GetLinkClasses(); // table computed at compile time
+			$aExcluded = MetaModel::GetLinkClasses();
 			$aRes = array();
 			foreach ($aClasses as $sClass)
 			{

+ 7 - 1
setup/compiler.class.inc.php

@@ -617,7 +617,11 @@ EOF;
 		$aClassParams = array();
 		$aClassParams['category'] = $this->GetPropString($oProperties, 'category', '');
 		$aClassParams['key_type'] = "'autoincrement'";
-	
+		if ((bool) $this->GetPropNumber($oProperties, 'is_link', 0))
+		{
+			$aClassParams['is_link'] = 'true';
+		}
+
 		if ($oNaming = $oProperties->GetOptionalElement('naming'))
 		{
 			$oNameAttributes = $oNaming->GetUniqueElement('attributes');
@@ -1462,6 +1466,8 @@ class ProfilesConfig
 
 	protected static \$aLINKTOCLASSES = $sLinkToClasses;
 
+	// Now replaced by MetaModel::GetLinkClasses (working with 1.x)
+	// This function could be deprecated
 	public static function GetLinkClasses()
 	{
 		return self::\$aLINKTOCLASSES;