本文整理汇总了PHP中MetaModel::GetClassFilterDefs方法的典型用法代码示例。如果您正苦于以下问题:PHP MetaModel::GetClassFilterDefs方法的具体用法?PHP MetaModel::GetClassFilterDefs怎么用?PHP MetaModel::GetClassFilterDefs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetaModel
的用法示例。
在下文中一共展示了MetaModel::GetClassFilterDefs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: AddLinkedObjects
/**
* Helper to link objects
*
* @param string sLinkAttCode
* @param string sLinkedClass
* @param array $aLinkList
* @param DBObject oTargetObj
* @param WebServiceResult oRes
*
* @return array List of objects that could not be found
*/
protected function AddLinkedObjects($sLinkAttCode, $sParamName, $sLinkedClass, $aLinkList, &$oTargetObj, &$oRes)
{
$oLinkAtt = MetaModel::GetAttributeDef(get_class($oTargetObj), $sLinkAttCode);
$sLinkClass = $oLinkAtt->GetLinkedClass();
$sExtKeyToItem = $oLinkAtt->GetExtKeyToRemote();
$aItemsFound = array();
$aItemsNotFound = array();
if (is_null($aLinkList)) {
return $aItemsNotFound;
}
foreach ($aLinkList as $aItemData) {
if (!array_key_exists('class', $aItemData)) {
$oRes->LogWarning("Parameter {$sParamName}: missing 'class' specification");
continue;
// skip
}
$sTargetClass = $aItemData['class'];
if (!MetaModel::IsValidClass($sTargetClass)) {
$oRes->LogError("Parameter {$sParamName}: invalid class '{$sTargetClass}'");
continue;
// skip
}
if (!MetaModel::IsParentClass($sLinkedClass, $sTargetClass)) {
$oRes->LogError("Parameter {$sParamName}: '{$sTargetClass}' is not a child class of '{$sLinkedClass}'");
continue;
// skip
}
$oReconFilter = new CMDBSearchFilter($sTargetClass);
$aCIStringDesc = array();
foreach ($aItemData['search'] as $sAttCode => $value) {
if (!MetaModel::IsValidFilterCode($sTargetClass, $sAttCode)) {
$aCodes = array_keys(MetaModel::GetClassFilterDefs($sTargetClass));
$oRes->LogError("Parameter {$sParamName}: '{$sAttCode}' is not a valid filter code for class '{$sTargetClass}', expecting a value in {" . implode(', ', $aCodes) . "}");
continue 2;
// skip the entire item
}
$aCIStringDesc[] = "{$sAttCode}: {$value}";
// The attribute is one of our reconciliation key
$oReconFilter->AddCondition($sAttCode, $value, '=');
}
if (count($aCIStringDesc) == 1) {
// take the last and unique value to describe the object
$sItemDesc = $value;
} else {
// describe the object by the given keys
$sItemDesc = $sTargetClass . '(' . implode('/', $aCIStringDesc) . ')';
}
$oExtObjects = new CMDBObjectSet($oReconFilter);
switch ($oExtObjects->Count()) {
case 0:
$oRes->LogWarning("Parameter {$sParamName}: object to link {$sLinkedClass} / {$sItemDesc} could not be found (searched: '" . $oReconFilter->ToOQL(true) . "')");
$aItemsNotFound[] = $sItemDesc;
break;
case 1:
$aItemsFound[] = array('object' => $oExtObjects->Fetch(), 'link_values' => @$aItemData['link_values'], 'desc' => $sItemDesc);
break;
default:
$oRes->LogWarning("Parameter {$sParamName}: Found " . $oExtObjects->Count() . " matches for item '{$sItemDesc}' (searched: '" . $oReconFilter->ToOQL(true) . "')");
$aItemsNotFound[] = $sItemDesc;
}
}
if (count($aItemsFound) > 0) {
$aLinks = array();
foreach ($aItemsFound as $aItemData) {
$oLink = MetaModel::NewObject($sLinkClass);
$oLink->Set($sExtKeyToItem, $aItemData['object']->GetKey());
foreach ($aItemData['link_values'] as $sKey => $value) {
if (!MetaModel::IsValidAttCode($sLinkClass, $sKey)) {
$oRes->LogWarning("Parameter {$sParamName}: Attaching item '" . $aItemData['desc'] . "', the attribute code '{$sKey}' is not valid ; check the class '{$sLinkClass}'");
} else {
$oLink->Set($sKey, $value);
}
}
$aLinks[] = $oLink;
}
$oImpactedInfraSet = DBObjectSet::FromArray($sLinkClass, $aLinks);
$oTargetObj->Set($sLinkAttCode, $oImpactedInfraSet);
}
return $aItemsNotFound;
}
示例2: AddCondition
public function AddCondition($sFilterCode, $value, $sOpCode = null)
{
MyHelpers::CheckKeyInArray('filter code in class: ' . $this->GetClass(), $sFilterCode, MetaModel::GetClassFilterDefs($this->GetClass()));
$oFilterDef = MetaModel::GetClassFilterDef($this->GetClass(), $sFilterCode);
$oField = new FieldExpression($sFilterCode, $this->GetClassAlias());
if (empty($sOpCode)) {
if ($sFilterCode == 'id') {
$sOpCode = '=';
} else {
$oAttDef = MetaModel::GetAttributeDef($this->GetClass(), $sFilterCode);
$oNewCondition = $oAttDef->GetSmartConditionExpression($value, $oField, $this->m_aParams);
$this->AddConditionExpression($oNewCondition);
return;
}
}
MyHelpers::CheckKeyInArray('operator', $sOpCode, $oFilterDef->GetOperators());
// Preserve backward compatibility - quick n'dirty way to change that API semantic
//
switch ($sOpCode) {
case 'SameDay':
case 'SameMonth':
case 'SameYear':
case 'Today':
case '>|':
case '<|':
case '=|':
throw new CoreException('Deprecated operator, please consider using OQL (SQL) expressions like "(TO_DAYS(NOW()) - TO_DAYS(x)) AS AgeDays"', array('operator' => $sOpCode));
break;
case "IN":
if (!is_array($value)) {
$value = array($value);
}
$sListExpr = '(' . implode(', ', CMDBSource::Quote($value)) . ')';
$sOQLCondition = $oField->Render() . " IN {$sListExpr}";
break;
case "NOTIN":
if (!is_array($value)) {
$value = array($value);
}
$sListExpr = '(' . implode(', ', CMDBSource::Quote($value)) . ')';
$sOQLCondition = $oField->Render() . " NOT IN {$sListExpr}";
break;
case 'Contains':
$this->m_aParams[$sFilterCode] = "%{$value}%";
$sOperator = 'LIKE';
break;
case 'Begins with':
$this->m_aParams[$sFilterCode] = "{$value}%";
$sOperator = 'LIKE';
break;
case 'Finishes with':
$this->m_aParams[$sFilterCode] = "%{$value}";
$sOperator = 'LIKE';
break;
default:
$this->m_aParams[$sFilterCode] = $value;
$sOperator = $sOpCode;
}
switch ($sOpCode) {
case "IN":
case "NOTIN":
$oNewCondition = Expression::FromOQL($sOQLCondition);
break;
case 'Contains':
case 'Begins with':
case 'Finishes with':
default:
$oRightExpr = new VariableExpression($sFilterCode);
$oNewCondition = new BinaryExpression($oField, $sOperator, $oRightExpr);
}
$this->AddConditionExpression($oNewCondition);
}
示例3: GetRenderContent
public function GetRenderContent(WebPage $oPage, $aExtraParams = array(), $sId)
{
$sHtml = '';
// Add the extra params into the filter if they make sense for such a filter
$bDoSearch = utils::ReadParam('dosearch', false);
if ($this->m_oSet == null) {
$aQueryParams = array();
if (isset($aExtraParams['query_params'])) {
$aQueryParams = $aExtraParams['query_params'];
}
if ($this->m_sStyle != 'links') {
$oAppContext = new ApplicationContext();
$sClass = $this->m_oFilter->GetClass();
$aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($sClass));
$aCallSpec = array($sClass, 'MapContextParam');
if (is_callable($aCallSpec)) {
foreach ($oAppContext->GetNames() as $sContextParam) {
$sParamCode = call_user_func($aCallSpec, $sContextParam);
//Map context parameter to the value/filter code depending on the class
if (!is_null($sParamCode)) {
$sParamValue = $oAppContext->GetCurrentValue($sContextParam, null);
if (!is_null($sParamValue)) {
$aExtraParams[$sParamCode] = $sParamValue;
}
}
}
}
foreach ($aFilterCodes as $sFilterCode) {
$externalFilterValue = utils::ReadParam($sFilterCode, '', false, 'raw_data');
$condition = null;
if (isset($aExtraParams[$sFilterCode])) {
$condition = $aExtraParams[$sFilterCode];
}
if ($bDoSearch && $externalFilterValue != "") {
// Search takes precedence over context params...
unset($aExtraParams[$sFilterCode]);
if (!is_array($externalFilterValue)) {
$condition = trim($externalFilterValue);
} else {
if (count($externalFilterValue) == 1) {
$condition = trim($externalFilterValue[0]);
} else {
$condition = $externalFilterValue;
}
}
}
if (!is_null($condition)) {
$sOpCode = null;
// default operator
if (is_array($condition)) {
// Multiple values, add them as AND X IN (v1, v2, v3...)
$sOpCode = 'IN';
}
$this->AddCondition($sFilterCode, $condition, $sOpCode);
}
}
if ($bDoSearch) {
// Keep the table_id identifying this table if we're performing a search
$sTableId = utils::ReadParam('_table_id_', null, false, 'raw_data');
if ($sTableId != null) {
$aExtraParams['table_id'] = $sTableId;
}
}
}
$aOrderBy = array();
if (isset($aExtraParams['order_by'])) {
// Convert the string describing the order_by parameter into an array
// The syntax is +attCode1,-attCode2
// attCode1 => ascending, attCode2 => descending
$aTemp = explode(',', $aExtraParams['order_by']);
foreach ($aTemp as $sTemp) {
$aMatches = array();
if (preg_match('/^([+-])?(.+)$/', $sTemp, $aMatches)) {
$bAscending = true;
if ($aMatches[1] == '-') {
$bAscending = false;
}
$aOrderBy[$aMatches[2]] = $bAscending;
}
}
}
$this->m_oSet = new CMDBObjectSet($this->m_oFilter, $aOrderBy, $aQueryParams);
}
switch ($this->m_sStyle) {
case 'count':
if (isset($aExtraParams['group_by'])) {
if (isset($aExtraParams['group_by_label'])) {
$oGroupByExp = Expression::FromOQL($aExtraParams['group_by']);
$sGroupByLabel = $aExtraParams['group_by_label'];
} else {
// Backward compatibility: group_by is simply a field id
$sAlias = $this->m_oFilter->GetClassAlias();
$oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias);
$sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']);
}
$aGroupBy = array();
$aGroupBy['grouped_by_1'] = $oGroupByExp;
$sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true);
$aRes = CMDBSource::QueryToArray($sSql);
$aGroupBy = array();
//.........这里部分代码省略.........
示例4: DisplayClassDetails
/**
* Display the details of a given class of objects
*/
function DisplayClassDetails($oPage, $sClass, $sContext)
{
$oPage->add("<h2>" . MetaModel::GetName($sClass) . " ({$sClass}) - " . MetaModel::GetClassDescription($sClass) . "</h2>\n");
if (MetaModel::IsAbstract($sClass)) {
$oPage->p(Dict::S('UI:Schema:AbstractClass'));
} else {
$oPage->p(Dict::S('UI:Schema:NonAbstractClass'));
}
// $oPage->p("<h3>".Dict::S('UI:Schema:ClassHierarchyTitle')."</h3>");
$aParentClasses = array();
foreach (MetaModel::EnumParentClasses($sClass) as $sParentClass) {
$aParentClasses[] = MakeClassHLink($sParentClass, $sContext);
}
if (count($aParentClasses) > 0) {
$sParents = implode(' >> ', $aParentClasses) . " >> <b>{$sClass}</b>";
} else {
$sParents = '';
}
$oPage->p("[<a href=\"schema.php?operation=list{$sContext}\">" . Dict::S('UI:Schema:AllClasses') . "</a>] {$sParents}");
if (MetaModel::HasChildrenClasses($sClass)) {
$oPage->add("<ul id=\"ClassHierarchy\">");
$oPage->add("<li class=\"closed\">" . $sClass . "\n");
DisplaySubclasses($oPage, $sClass, $sContext);
$oPage->add("</li>\n");
$oPage->add("</ul>\n");
$oPage->add_ready_script('$("#ClassHierarchy").treeview();');
}
$oPage->p('');
$oPage->AddTabContainer('details');
$oPage->SetCurrentTabContainer('details');
// List the attributes of the object
$aForwardChangeTracking = MetaModel::GetTrackForwardExternalKeys($sClass);
$aDetails = array();
foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
if ($oAttDef->IsExternalKey()) {
$sValue = Dict::Format('UI:Schema:ExternalKey_To', MakeClassHLink($oAttDef->GetTargetClass(), $sContext));
if (array_key_exists($sAttCode, $aForwardChangeTracking)) {
$oLinkSet = $aForwardChangeTracking[$sAttCode];
$sRemoteClass = $oLinkSet->GetHostClass();
$sValue = $sValue . "<span title=\"Forward changes to {$sRemoteClass}\">*</span>";
}
} elseif ($oAttDef->IsLinkSet()) {
$sValue = MakeClassHLink($oAttDef->GetLinkedClass(), $sContext);
} else {
$sValue = $oAttDef->GetDescription();
}
$sType = $oAttDef->GetType() . ' (' . $oAttDef->GetTypeDesc() . ')';
$sOrigin = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
$sAllowedValues = "";
$sMoreInfo = "";
$aCols = array();
foreach ($oAttDef->GetSQLColumns() as $sCol => $sFieldDesc) {
$aCols[] = "{$sCol}: {$sFieldDesc}";
}
if (count($aCols) > 0) {
$sCols = implode(', ', $aCols);
$aMoreInfo = array();
$aMoreInfo[] = Dict::Format('UI:Schema:Columns_Description', $sCols);
$aMoreInfo[] = Dict::Format('UI:Schema:Default_Description', $oAttDef->GetDefaultValue());
$aMoreInfo[] = $oAttDef->IsNullAllowed() ? Dict::S('UI:Schema:NullAllowed') : Dict::S('UI:Schema:NullNotAllowed');
$sMoreInfo .= implode(', ', $aMoreInfo);
}
if ($oAttDef instanceof AttributeEnum) {
// Display localized values for the enum (which depend on the localization provided by the class)
$aLocalizedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array());
$aDescription = array();
foreach ($aLocalizedValues as $val => $sDisplay) {
$aDescription[] = htmlentities("{$val} => ", ENT_QUOTES, 'UTF-8') . $sDisplay;
}
$sAllowedValues = implode(', ', $aDescription);
} else {
$sAllowedValues = '';
}
$aDetails[] = array('code' => $oAttDef->GetCode(), 'type' => $sType, 'origin' => $sOrigin, 'label' => $oAttDef->GetLabel(), 'description' => $sValue, 'values' => $sAllowedValues, 'moreinfo' => $sMoreInfo);
}
$oPage->SetCurrentTab(Dict::S('UI:Schema:Attributes'));
$aConfig = array('code' => array('label' => Dict::S('UI:Schema:AttributeCode'), 'description' => Dict::S('UI:Schema:AttributeCode+')), 'label' => array('label' => Dict::S('UI:Schema:Label'), 'description' => Dict::S('UI:Schema:Label+')), 'type' => array('label' => Dict::S('UI:Schema:Type'), 'description' => Dict::S('UI:Schema:Type+')), 'origin' => array('label' => Dict::S('UI:Schema:Origin'), 'description' => Dict::S('UI:Schema:Origin+')), 'description' => array('label' => Dict::S('UI:Schema:Description'), 'description' => Dict::S('UI:Schema:Description+')), 'values' => array('label' => Dict::S('UI:Schema:AllowedValues'), 'description' => Dict::S('UI:Schema:AllowedValues+')), 'moreinfo' => array('label' => Dict::S('UI:Schema:MoreInfo'), 'description' => Dict::S('UI:Schema:MoreInfo+')));
$oPage->table($aConfig, $aDetails);
// List the search criteria for this object
$aDetails = array();
foreach (MetaModel::GetClassFilterDefs($sClass) as $sFilterCode => $oFilterDef) {
$aOpDescs = array();
foreach ($oFilterDef->GetOperators() as $sOpCode => $sOpDescription) {
$sIsTheLooser = $sOpCode == $oFilterDef->GetLooseOperator() ? " (loose search)" : "";
$aOpDescs[] = "{$sOpCode} ({$sOpDescription}){$sIsTheLooser}";
}
$aDetails[] = array('code' => $sFilterCode, 'description' => $oFilterDef->GetLabel(), 'operators' => implode(" / ", $aOpDescs));
}
$oPage->SetCurrentTab(Dict::S('UI:Schema:SearchCriteria'));
$aConfig = array('code' => array('label' => Dict::S('UI:Schema:FilterCode'), 'description' => Dict::S('UI:Schema:FilterCode+')), 'description' => array('label' => Dict::S('UI:Schema:FilterDescription'), 'description' => Dict::S('UI:Schema:FilterDescription+')), 'operators' => array('label' => Dict::S('UI:Schema:AvailOperators'), 'description' => Dict::S('UI:Schema:AvailOperators+')));
$oPage->table($aConfig, $aDetails);
$oPage->SetCurrentTab(Dict::S('UI:Schema:ChildClasses'));
DisplaySubclasses($oPage, $sClass, $sContext);
$oPage->SetCurrentTab(Dict::S('UI:Schema:ReferencingClasses'));
DisplayReferencingClasses($oPage, $sClass, $sContext);
$oPage->SetCurrentTab(Dict::S('UI:Schema:RelatedClasses'));
DisplayRelatedClasses($oPage, $sClass, $sContext);
//.........这里部分代码省略.........