本文整理汇总了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;
}
}
//.........这里部分代码省略.........