本文整理汇总了PHP中MetaModel::HasTable方法的典型用法代码示例。如果您正苦于以下问题:PHP MetaModel::HasTable方法的具体用法?PHP MetaModel::HasTable怎么用?PHP MetaModel::HasTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetaModel
的用法示例。
在下文中一共展示了MetaModel::HasTable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: MakeDictionaryTemplate
function MakeDictionaryTemplate($sModules = '', $sLanguage = 'EN US')
{
$sRes = '';
Dict::SetDefaultLanguage($sLanguage);
$aAvailableLanguages = Dict::GetLanguages();
$sDesc = $aAvailableLanguages[$sLanguage]['description'];
$sLocalizedDesc = $aAvailableLanguages[$sLanguage]['localized_description'];
$sRes .= "// Dictionary conventions\n";
$sRes .= htmlentities("// Class:<class_name>\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>+\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>+\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>/Value:<value>\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>/Value:<value>+\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Stimulus:<stimulus_code>\n", ENT_QUOTES, 'UTF-8');
$sRes .= htmlentities("// Class:<class_name>/Stimulus:<stimulus_code>+\n", ENT_QUOTES, 'UTF-8');
$sRes .= "\n";
// Note: I did not use EnumCategories(), because a given class maybe found in several categories
// Need to invent the "module", to characterize the origins of a class
if (strlen($sModules) == 0) {
$aModules = array('bizmodel', 'core/cmdb', 'gui', 'application', 'addon/userrights', 'monitoring');
} else {
$aModules = explode(', ', $sModules);
}
$sRes .= "//////////////////////////////////////////////////////////////////////\n";
$sRes .= "// Note: The classes have been grouped by categories: " . implode(', ', $aModules) . "\n";
$sRes .= "//////////////////////////////////////////////////////////////////////\n";
foreach ($aModules as $sCategory) {
$sRes .= "//////////////////////////////////////////////////////////////////////\n";
$sRes .= "// Classes in '{$sCategory}'\n";
$sRes .= "//////////////////////////////////////////////////////////////////////\n";
$sRes .= "//\n";
$sRes .= "\n";
foreach (MetaModel::GetClasses($sCategory) as $sClass) {
if (!MetaModel::HasTable($sClass)) {
continue;
}
$bNotInDico = false;
$bNotImportant = true;
$sClassRes = "//\n";
$sClassRes .= "// Class: {$sClass}\n";
$sClassRes .= "//\n";
$sClassRes .= "\n";
$sClassRes .= "Dict::Add('{$sLanguage}', '{$sDesc}', '{$sLocalizedDesc}', array(\n";
$sClassRes .= MakeDictEntry("Class:{$sClass}", MetaModel::GetName_Obsolete($sClass), $sClass, $bNotInDico);
$sClassRes .= MakeDictEntry("Class:{$sClass}+", MetaModel::GetClassDescription_Obsolete($sClass), '', $bNotImportant);
foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
if ($sAttCode == 'friendlyname') {
continue;
}
// Skip this attribute if not originaly defined in this class
if (MetaModel::GetAttributeOrigin($sClass, $sAttCode) != $sClass) {
continue;
}
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}", $oAttDef->GetLabel_Obsolete(), $sAttCode, $bNotInDico);
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}+", $oAttDef->GetDescription_Obsolete(), '', $bNotImportant);
if ($oAttDef instanceof AttributeEnum) {
if (MetaModel::GetStateAttributeCode($sClass) == $sAttCode) {
foreach (MetaModel::EnumStates($sClass) as $sStateCode => $aStateData) {
if (array_key_exists('label', $aStateData)) {
$sValue = $aStateData['label'];
} else {
$sValue = MetaModel::GetStateLabel($sClass, $sStateCode);
}
if (array_key_exists('description', $aStateData)) {
$sValuePlus = $aStateData['description'];
} else {
$sValuePlus = MetaModel::GetStateDescription($sClass, $sStateCode);
}
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sStateCode}", $sValue, '', $bNotInDico);
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sStateCode}+", $sValuePlus, '', $bNotImportant);
}
} else {
foreach ($oAttDef->GetAllowedValues() as $sKey => $value) {
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sKey}", $value, '', $bNotInDico);
$sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sKey}+", $value, '', $bNotImportant);
}
}
}
}
foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) {
$sClassRes .= MakeDictEntry("Class:{$sClass}/Stimulus:{$sStimulusCode}", $oStimulus->GetLabel_Obsolete(), '', $bNotInDico);
$sClassRes .= MakeDictEntry("Class:{$sClass}/Stimulus:{$sStimulusCode}+", $oStimulus->GetDescription_Obsolete(), '', $bNotImportant);
}
$sClassRes .= "));\n";
$sClassRes .= "\n";
$sRes .= $sClassRes;
}
}
return $sRes;
}
示例2: MakeSQLObjectQuery
//.........这里部分代码省略.........
//
$sAliasForAttribute = $sClassAlias;
} else {
// The attribute will be available from an additional outer join
// For each subclass (table) one single join is enough
//
if (!array_key_exists($sClassOfAttribute, $aFNJoinAlias)) {
$sAliasForAttribute = $oBuild->GenerateClassAlias($sClassAlias . '_fn_' . $sClassOfAttribute, $sClassOfAttribute);
$aFNJoinAlias[$sClassOfAttribute] = $sAliasForAttribute;
} else {
$sAliasForAttribute = $aFNJoinAlias[$sClassOfAttribute];
}
}
$aTranslateNameFields[$sSubClass][$sAttCode] = new FieldExpression($sAttCode, $sAliasForAttribute);
}
}
$oNameExpression = $oNameExpression->Translate($aTranslateNameFields, false);
$aTranslateNow = array();
$aTranslateNow[$sClassAlias]['friendlyname'] = $oNameExpression;
$oBuild->m_oQBExpressions->Translate($aTranslateNow, false);
}
// Add the ext fields used in the select (eventually adds an external key)
foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
if ($oAttDef->IsExternalField() || $oAttDef instanceof AttributeFriendlyName) {
if (array_key_exists($sAttCode, $aExpectedAtts)) {
$sKeyAttCode = $oAttDef->GetKeyAttCode();
if ($sKeyAttCode != 'id') {
// Add the external attribute
$sKeyTableClass = MetaModel::GetAttributeOrigin($sClass, $sKeyAttCode);
$aExtKeys[$sKeyTableClass][$sKeyAttCode][$sAttCode] = $oAttDef;
}
}
}
}
// First query built upon on the leaf (ie current) class
//
self::DbgTrace("Main (=leaf) class, call MakeSQLObjectQuerySingleTable()");
if (MetaModel::HasTable($sClass)) {
$oSelectBase = $this->MakeSQLObjectQuerySingleTable($oBuild, $aAttToLoad, $sClass, $aExtKeys, $aValues);
} else {
$oSelectBase = null;
// As the join will not filter on the expected classes, we have to specify it explicitely
$sExpectedClasses = implode("', '", MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL));
$oFinalClassRestriction = Expression::FromOQL("`{$sClassAlias}`.finalclass IN ('{$sExpectedClasses}')");
$oBuild->m_oQBExpressions->AddCondition($oFinalClassRestriction);
}
// Then we join the queries of the eventual parent classes (compound model)
foreach (MetaModel::EnumParentClasses($sClass) as $sParentClass) {
if (!MetaModel::HasTable($sParentClass)) {
continue;
}
self::DbgTrace("Parent class: {$sParentClass}... let's call MakeSQLObjectQuerySingleTable()");
$oSelectParentTable = $this->MakeSQLObjectQuerySingleTable($oBuild, $aAttToLoad, $sParentClass, $aExtKeys, $aValues);
if (is_null($oSelectBase)) {
$oSelectBase = $oSelectParentTable;
} else {
$oSelectBase->AddInnerJoin($oSelectParentTable, $sKeyField, MetaModel::DBGetKey($sParentClass));
}
}
// Filter on objects referencing me
foreach ($this->GetCriteria_ReferencedBy() as $sForeignClass => $aKeysAndFilters) {
foreach ($aKeysAndFilters as $sForeignKeyAttCode => $oForeignFilter) {
$oForeignKeyAttDef = MetaModel::GetAttributeDef($sForeignClass, $sForeignKeyAttCode);
self::DbgTrace("Referenced by foreign key: {$sForeignKeyAttCode}... let's call MakeSQLObjectQuery()");
//self::DbgTrace($oForeignFilter);
//self::DbgTrace($oForeignFilter->ToOQL());
//self::DbgTrace($oSelectForeign);
//self::DbgTrace($oSelectForeign->RenderSelect(array()));
$sForeignClassAlias = $oForeignFilter->GetFirstJoinedClassAlias();
$oBuild->m_oQBExpressions->PushJoinField(new FieldExpression($sForeignKeyAttCode, $sForeignClassAlias));
if ($oForeignKeyAttDef instanceof AttributeObjectKey) {
$sClassAttCode = $oForeignKeyAttDef->Get('class_attcode');
// Add the condition: `$sForeignClassAlias`.$sClassAttCode IN (subclasses of $sClass')
$oClassListExpr = ListExpression::FromScalars(MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL));
$oClassExpr = new FieldExpression($sClassAttCode, $sForeignClassAlias);
$oClassRestriction = new BinaryExpression($oClassExpr, 'IN', $oClassListExpr);
$oBuild->m_oQBExpressions->AddCondition($oClassRestriction);
}
$oSelectForeign = $oForeignFilter->MakeSQLObjectQuery($oBuild, $aAttToLoad);
$oJoinExpr = $oBuild->m_oQBExpressions->PopJoinField();
$sForeignKeyTable = $oJoinExpr->GetParent();
$sForeignKeyColumn = $oJoinExpr->GetName();
$oSelectBase->AddInnerJoin($oSelectForeign, $sKeyField, $sForeignKeyColumn, $sForeignKeyTable);
}
}
// Additional JOINS for Friendly names
//
foreach ($aFNJoinAlias as $sSubClass => $sSubClassAlias) {
$oSubClassFilter = new DBObjectSearch($sSubClass, $sSubClassAlias);
$oSelectFN = $oSubClassFilter->MakeSQLObjectQuerySingleTable($oBuild, $aAttToLoad, $sSubClass, $aExtKeys, array());
$oSelectBase->AddLeftJoin($oSelectFN, $sKeyField, MetaModel::DBGetKey($sSubClass));
}
// That's all... cross fingers and we'll get some working query
//MyHelpers::var_dump_html($oSelectBase, true);
//MyHelpers::var_dump_html($oSelectBase->RenderSelect(), true);
if (self::$m_bDebugQuery) {
$oSelectBase->DisplayHtml();
}
return $oSelectBase;
}
示例3: DoExecute
protected function DoExecute()
{
foreach (MetaModel::GetClasses() as $sClassName) {
if (MetaModel::HasTable($sClassName)) {
continue;
}
$oNobody = MetaModel::GetObject($sClassName, 123);
$oBaby = new $sClassName();
$oFilter = new DBObjectSearch($sClassName);
// Challenge reversibility of OQL / filter object
//
$sExpr1 = $oFilter->ToOQL();
$oNewFilter = DBObjectSearch::FromOQL($sExpr1);
$sExpr2 = $oNewFilter->ToOQL();
if ($sExpr1 != $sExpr2) {
$this->ReportError("Found two different OQL expression out of the (same?) filter: <em>{$sExpr1}</em> != <em>{$sExpr2}</em>");
}
// Use the filter (perform the query)
//
$oSet = new CMDBObjectSet($oFilter);
$this->ReportSuccess('Found ' . $oSet->Count() . " objects of class {$sClassName}");
}
return true;
}