Prechádzať zdrojové kódy

Added constructor for DBObjectSet: FromArrayAssoc

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@331 a333f486-631f-4898-b8df-5754b55c2be0
romainq 15 rokov pred
rodič
commit
36f550d9a8
1 zmenil súbory, kde vykonal 24 pridanie a 0 odobranie
  1. 24 0
      core/dbobjectset.class.php

+ 24 - 0
core/dbobjectset.class.php

@@ -72,6 +72,8 @@ class DBObjectSet
 		return $oRetSet;
 	} 
 
+	// create an object set ex nihilo
+	// input = array of objects
 	static public function FromArray($sClass, $aObjects)
 	{
 		$oFilter = new CMDBSearchFilter($sClass);
@@ -81,6 +83,28 @@ class DBObjectSet
 		return $oRetSet;
 	} 
 
+	// create an object set ex nihilo
+	// aClasses = array of (alias => class)
+	// input = array of (array of (classalias => object))
+	static public function FromArrayAssoc($aClasses, $aObjects)
+	{
+		// In a perfect world, we should create a complete tree of DBObjectSearch,
+		// but as we lack most of the information related to the objects,
+		// let's create one search definition
+		$sClass = reset($this->m_aClasses);
+		$sAlias = key($this->m_aClasses);
+		$oFilter = new CMDBSearchFilter($sClass, $sAlias);
+
+		$oRetSet = new self($oFilter);
+		$oRetSet->m_bLoaded = true; // no DB load
+
+		foreach($aObjects as $rowIndex => $aObjectsByClassAlias)
+		{
+			$oRetSet->AddObjectExtended($aObjectsByClassAlias);
+		}
+		return $oRetSet;
+	} 
+
 	static public function FromLinkSet($oObject, $sLinkSetAttCode, $sExtKeyToRemote)
 	{
 		$oLinkAttCode = MetaModel::GetAttributeDef(get_class($oObject), $sLinkSetAttCode);