From 4e2edaabfa89559da1b226ef34b76355cbca7632 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Wed, 14 Apr 2010 08:14:08 +0000 Subject: [PATCH] Added constructor for DBObjectSet: FromArrayAssoc SVN:trunk[331] --- core/dbobjectset.class.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/dbobjectset.class.php b/core/dbobjectset.class.php index 903663afd..b87e04b16 100644 --- a/core/dbobjectset.class.php +++ b/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);