当前位置: 首页>>代码示例>>PHP>>正文


PHP DBObjectSet::ToArray方法代码示例

本文整理汇总了PHP中DBObjectSet::ToArray方法的典型用法代码示例。如果您正苦于以下问题:PHP DBObjectSet::ToArray方法的具体用法?PHP DBObjectSet::ToArray怎么用?PHP DBObjectSet::ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBObjectSet的用法示例。


在下文中一共展示了DBObjectSet::ToArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: DoExecScenario

 protected function DoExecScenario($aSingleScenario)
 {
     echo "<div style=\"padding: 10;\">\n";
     echo "<h3 style=\"background-color: #ddddff; padding: 10;\">{$aSingleScenario['desc']}</h3>\n";
     $sClass = $aSingleScenario['target_class'];
     $aTargetData = $aSingleScenario['target_data'];
     $aSourceData = $aSingleScenario['source_data'];
     $aTargetAttributes = array_shift($aTargetData);
     $aSourceAttributes = array_shift($aSourceData);
     if (count($aSourceData) + 1 != count($aTargetData)) {
         throw new Exception("Target data must contain exactly " . (count($aSourceData) + 1) . " items, found " . count($aTargetData));
     }
     // Create the data source
     //
     $oDataSource = new SynchroDataSource();
     $oDataSource->Set('name', 'Test data sync ' . time());
     $oDataSource->Set('description', 'unit test - created automatically');
     $oDataSource->Set('status', 'production');
     $oDataSource->Set('user_id', 0);
     $oDataSource->Set('scope_class', $sClass);
     $oDataSource->Set('scope_restriction', '');
     $oDataSource->Set('full_load_periodicity', $aSingleScenario['full_load_periodicity']);
     $oDataSource->Set('reconciliation_policy', $aSingleScenario['reconciliation_policy']);
     $oDataSource->Set('action_on_zero', $aSingleScenario['action_on_zero']);
     $oDataSource->Set('action_on_one', $aSingleScenario['action_on_one']);
     $oDataSource->Set('action_on_multiple', $aSingleScenario['action_on_multiple']);
     $oDataSource->Set('delete_policy', $aSingleScenario['delete_policy']);
     $oDataSource->Set('delete_policy_update', $aSingleScenario['delete_policy_update']);
     $oDataSource->Set('delete_policy_retention', $aSingleScenario['delete_policy_retention']);
     $iDataSourceId = $this->ObjectToDB($oDataSource, true);
     $oAttributeSet = $oDataSource->Get('attribute_list');
     while ($oAttribute = $oAttributeSet->Fetch()) {
         if (array_key_exists($oAttribute->Get('attcode'), $aSingleScenario['attributes'])) {
             $aAttribInfo = $aSingleScenario['attributes'][$oAttribute->Get('attcode')];
             if (array_key_exists('reconciliation_attcode', $aAttribInfo)) {
                 $oAttribute->Set('reconciliation_attcode', $aAttribInfo['reconciliation_attcode']);
             }
             $oAttribute->Set('update', $aAttribInfo['do_update']);
             $oAttribute->Set('reconcile', $aAttribInfo['do_reconcile']);
         } else {
             $oAttribute->Set('update', false);
             $oAttribute->Set('reconcile', false);
         }
         $this->UpdateObjectInDB($oAttribute);
     }
     // Prepare list of prefixes -> make sure objects are unique with regard to the reconciliation scheme
     $aPrefixes = array();
     // attcode => prefix
     foreach ($aSourceAttributes as $iDummy => $sAttCode) {
         $aPrefixes[$sAttCode] = '';
         // init with something
     }
     foreach ($aSingleScenario['attributes'] as $sAttCode => $aAttribInfo) {
         if (isset($aAttribInfo['automatic_prefix']) && $aAttribInfo['automatic_prefix']) {
             $aPrefixes[$sAttCode] = 'TEST_' . $iDataSourceId . '_';
         }
     }
     // List existing objects (to be ignored in the analysis
     //
     $oAllObjects = new DBObjectSet(new DBObjectSearch($sClass));
     $aExisting = $oAllObjects->ToArray(true);
     $sExistingIds = implode(', ', array_keys($aExisting));
     // Create the initial object list
     //
     $aInitialTarget = $aTargetData[0];
     foreach ($aInitialTarget as $aObjFields) {
         $oNewTarget = MetaModel::NewObject($sClass);
         foreach ($aTargetAttributes as $iAtt => $sAttCode) {
             $oNewTarget->Set($sAttCode, $aPrefixes[$sAttCode] . $aObjFields[$iAtt]);
         }
         $this->ObjectToDB($oNewTarget);
     }
     foreach ($aTargetData as $iRow => $aExpectedObjects) {
         sleep(2);
         // Check the status (while ignoring existing objects)
         //
         if (empty($sExistingIds)) {
             $oObjects = new DBObjectSet(DBObjectSearch::FromOQL("SELECT {$sClass}"));
         } else {
             $oObjects = new DBObjectSet(DBObjectSearch::FromOQL("SELECT {$sClass} WHERE id NOT IN({$sExistingIds})"));
         }
         $aFound = $oObjects->ToArray();
         $aErrors_Unexpected = array();
         foreach ($aFound as $iObj => $oObj) {
             // Is this object in the expected objects list
             $bFoundMatch = false;
             foreach ($aExpectedObjects as $iExp => $aValues) {
                 $bDoesMatch = true;
                 foreach ($aTargetAttributes as $iCol => $sAttCode) {
                     if ($oObj->Get($sAttCode) != $aPrefixes[$sAttCode] . $aValues[$iCol]) {
                         $bDoesMatch = false;
                         break;
                     }
                 }
                 if ($bDoesMatch) {
                     $bFoundMatch = true;
                     unset($aExpectedObjects[$iExp]);
                     break;
                 }
             }
//.........这里部分代码省略.........
开发者ID:besmirzanaj,项目名称:itop-code,代码行数:101,代码来源:testlist.inc.php


注:本文中的DBObjectSet::ToArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。