Browse Source

Do not rely on MetaModel::GetRootClass() to check the data model, use the abstraction of ModelReflection instead to keep the code portable.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3797 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 9 years ago
parent
commit
46fe2f3221
3 changed files with 31 additions and 16 deletions
  1. 0 12
      core/metamodel.class.php
  2. 28 1
      core/modelreflection.class.inc.php
  3. 3 3
      core/oql/oqlquery.class.inc.php

+ 0 - 12
core/metamodel.class.php

@@ -45,18 +45,6 @@ require_once(APPROOT.'core/relationgraph.class.inc.php');
  *
  * @package     iTopORM
  */
-define('ENUM_CHILD_CLASSES_EXCLUDETOP', 1);
-/**
- * add some description here... 
- *
- * @package     iTopORM
- */
-define('ENUM_CHILD_CLASSES_ALL', 2);
-/**
- * add some description here... 
- *
- * @package     iTopORM
- */
 define('ENUM_PARENT_CLASSES_EXCLUDELEAF', 1);
 /**
  * add some description here... 

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

@@ -23,7 +23,21 @@
  * @copyright   Copyright (C) 2013 Combodo SARL
  * @license     http://opensource.org/licenses/AGPL-3.0
  */
- 
+
+/**
+ * Exclude the parent class from the list
+ *
+ * @package     iTopORM
+ */
+define('ENUM_CHILD_CLASSES_EXCLUDETOP', 1);
+/**
+ * Include the parent class in the list
+ *
+ * @package     iTopORM
+*/
+define('ENUM_CHILD_CLASSES_ALL', 2);
+
+
 abstract class ModelReflection
 {
 	abstract public function GetClassIcon($sClass, $bImgTag = true); 
@@ -62,6 +76,9 @@ abstract class ModelReflection
 	}
 
 	abstract public function GetIconSelectionField($sCode, $sLabel = '', $defaultValue = '');
+	
+	abstract public function GetRootClass($sClass);
+	abstract public function EnumChildClasses($sClass, $iOption = ENUM_CHILD_CLASSES_EXCLUDETOP);
 }
 
 abstract class QueryReflection
@@ -234,6 +251,16 @@ class ModelReflectionRuntime extends ModelReflection
 	{
 		return new RunTimeIconSelectionField($sCode, $sLabel, $defaultValue);
 	}
+	
+	public function GetRootClass($sClass)
+	{
+		return MetaModel::GetRootClass($sClass);
+	}
+	
+	public function EnumChildClasses($sClass, $iOption = ENUM_CHILD_CLASSES_EXCLUDETOP)
+	{
+		return MetaModel::EnumChildClasses($sClass, $iOption);
+	}
 }
 
 

+ 3 - 3
core/oql/oqlquery.class.inc.php

@@ -580,13 +580,13 @@ class OqlUnionQuery extends OqlQuery
 				if ($iQuery == 0)
 				{
 					// Establish the reference
-					$sRootClass = MetaModel::GetRootClass($aData['class']);
+					$sRootClass = $oModelReflection->GetRootClass($aData['class']);
 				}
 				else
 				{
-					if (MetaModel::GetRootClass($aData['class']) != $sRootClass)
+					if ($oModelReflection->GetRootClass($aData['class']) != $sRootClass)
 					{
-						$aSubclasses = MetaModel::EnumChildClasses($sRootClass, ENUM_CHILD_CLASSES_ALL);
+						$aSubclasses = $oModelReflection->EnumChildClasses($sRootClass, ENUM_CHILD_CLASSES_ALL);
 						throw new OqlNormalizeException('Incompatible classes: could not find a common ancestor', $sSourceQuery, $aData['class_name'], $aSubclasses);
 					}
 				}