本文整理汇总了PHP中MetaModel::IsValidFilterCode方法的典型用法代码示例。如果您正苦于以下问题:PHP MetaModel::IsValidFilterCode方法的具体用法?PHP MetaModel::IsValidFilterCode怎么用?PHP MetaModel::IsValidFilterCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetaModel
的用法示例。
在下文中一共展示了MetaModel::IsValidFilterCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: IsValidFilterCode
public function IsValidFilterCode($sClass, $sFilterCode)
{
return MetaModel::IsValidFilterCode($sClass, $sFilterCode);
}
示例3: DBObjectSearch
$oP->add('<div class="page_header"><h1>' . Dict::S('UI:Audit:InteractiveAudit') . '</h1><img style="margin-top: -20px; margin-right: 10px; float: right;" src="../images/clean.png"/></div>');
$oAuditFilter = new DBObjectSearch('AuditCategory');
$oCategoriesSet = new DBObjectSet($oAuditFilter);
$oP->add("<table style=\"margin-top: 1em; padding: 0px; border-top: 3px solid #f6f6f1; border-left: 3px solid #f6f6f1; border-bottom: 3px solid #e6e6e1;\tborder-right: 3px solid #e6e6e1;\">\n");
$oP->add("<tr><td>\n");
$oP->add("<table>\n");
$oP->add("<tr>\n");
$oP->add("<th><img src=\"../images/minus.gif\"></th><th class=\"alignLeft\">" . Dict::S('UI:Audit:HeaderAuditRule') . "</th><th>" . Dict::S('UI:Audit:HeaderNbObjects') . "</th><th>" . Dict::S('UI:Audit:HeaderNbErrors') . "</th><th>" . Dict::S('UI:Audit:PercentageOk') . "</th>\n");
$oP->add("</tr>\n");
while ($oAuditCategory = $oCategoriesSet->fetch()) {
try {
$oDefinitionFilter = DBObjectSearch::FromOQL($oAuditCategory->Get('definition_set'));
FilterByContext($oDefinitionFilter, $oAppContext);
$aObjectsWithErrors = array();
if (!empty($currentOrganization)) {
if (MetaModel::IsValidFilterCode($oDefinitionFilter->GetClass(), 'org_id')) {
$oDefinitionFilter->AddCondition('org_id', $currentOrganization, '=');
}
}
$aResults = array();
$oDefinitionSet = new CMDBObjectSet($oDefinitionFilter);
$iCount = $oDefinitionSet->Count();
$oRulesFilter = new DBObjectSearch('AuditRule');
$oRulesFilter->AddCondition('category_id', $oAuditCategory->GetKey(), '=');
$oRulesSet = new DBObjectSet($oRulesFilter);
while ($oAuditRule = $oRulesSet->fetch()) {
$aRow = array();
$aRow['description'] = $oAuditRule->GetName();
if ($iCount == 0) {
// nothing to check, really !
$aRow['nb_errors'] = "<a href=\"audit.php?operation=errors&category=" . $oAuditCategory->GetKey() . "&rule=" . $oAuditRule->GetKey() . "\">0</a>";
示例4: GetRenderContent
//.........这里部分代码省略.........
$oAttDef = MetaModel::GetAttributeDef($sClass, $this->m_aParams['target_attr']);
$sTargetClass = $oAttDef->GetTargetClass();
$sHtml .= $oPage->GetP(Dict::Format('UI:NoObject_Class_ToDisplay', MetaModel::GetName($sTargetClass)));
$bDisplayMenu = isset($this->m_aParams['menu']) ? $this->m_aParams['menu'] == true : true;
if ($bDisplayMenu) {
if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) {
$oAppContext = new ApplicationContext();
$sParams = $oAppContext->GetForLink();
$sDefaults = '';
if (isset($this->m_aParams['default'])) {
foreach ($this->m_aParams['default'] as $sName => $sValue) {
$sDefaults .= '&' . urlencode($sName) . '=' . urlencode($sValue);
}
}
$sHtml .= $oPage->GetP("<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=modify_links&class={$sClass}&sParams&link_attr=" . $aExtraParams['link_attr'] . "&id=" . $aExtraParams['object_id'] . "&target_class={$sTargetClass}&addObjects=true{$sDefaults}\">" . Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass)) . "</a>\n");
}
}
}
break;
case 'details':
while ($oObj = $this->m_oSet->Fetch()) {
$sHtml .= $oObj->GetDetails($oPage);
// Still used ???
}
break;
case 'actions':
$sClass = $this->m_oFilter->GetClass();
$oAppContext = new ApplicationContext();
$bContextFilter = isset($aExtraParams['context_filter']) ? isset($aExtraParams['context_filter']) != 0 : false;
if ($bContextFilter) {
$aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass()));
foreach ($oAppContext->GetNames() as $sFilterCode) {
$sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null);
if (!is_null($sContextParamValue) && !empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode)) {
$this->AddCondition($sFilterCode, $sContextParamValue);
}
}
$aQueryParams = array();
if (isset($aExtraParams['query_params'])) {
$aQueryParams = $aExtraParams['query_params'];
}
$this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams);
}
$iCount = $this->m_oSet->Count();
$sHyperlink = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($this->m_oFilter->serialize());
$sHtml .= '<p><a class="actions" href="' . $sHyperlink . '">';
// Note: border set to 0 due to various browser interpretations (IE9 adding a 2px border)
$sHtml .= MetaModel::GetClassIcon($sClass, true, 'float;left;margin-right:10px;border:0;');
$sHtml .= MetaModel::GetName($sClass) . ': ' . $iCount . '</a></p>';
$sParams = $oAppContext->GetForLink();
$sHtml .= '<p>';
if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY)) {
$sHtml .= "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=new&class={$sClass}&{$sParams}\">" . Dict::Format('UI:ClickToCreateNew', MetaModel::GetName($sClass)) . "</a><br/>\n";
}
$sHtml .= "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=search_form&do_search=0&class={$sClass}&{$sParams}\">" . Dict::Format('UI:SearchFor_Class', MetaModel::GetName($sClass)) . "</a>\n";
$sHtml .= '</p>';
break;
case 'summary':
$sClass = $this->m_oFilter->GetClass();
$oAppContext = new ApplicationContext();
$sTitle = isset($aExtraParams['title[block]']) ? $aExtraParams['title[block]'] : '';
$sLabel = isset($aExtraParams['label[block]']) ? $aExtraParams['label[block]'] : '';
$sStateAttrCode = isset($aExtraParams['status[block]']) ? $aExtraParams['status[block]'] : 'status';
$sStatesList = isset($aExtraParams['status_codes[block]']) ? $aExtraParams['status_codes[block]'] : '';
$bContextFilter = isset($aExtraParams['context_filter']) ? isset($aExtraParams['context_filter']) != 0 : false;
if ($bContextFilter) {
示例5: ProcessCSVData
/**
* Process the CSV data, for real or as a simulation
* @param WebPage $oPage The page used to display the wizard
* @param bool $bSimulate Whether or not to simulate the data load
* @return array The CSV lines in error that were rejected from the load (with the header line - if any) or null
*/
function ProcessCSVData(WebPage $oPage, $bSimulate = true)
{
$aResult = array();
$sCSVData = utils::ReadParam('csvdata', '', false, 'raw_data');
$sCSVDataTruncated = utils::ReadParam('csvdata_truncated', '', false, 'raw_data');
$sSeparator = utils::ReadParam('separator', ',', false, 'raw_data');
$sTextQualifier = utils::ReadParam('text_qualifier', '"', false, 'raw_data');
$bHeaderLine = utils::ReadParam('header_line', '0') == 1;
$iSkippedLines = 0;
if (utils::ReadParam('box_skiplines', '0') == 1) {
$iSkippedLines = utils::ReadParam('nb_skipped_lines', '0');
}
$sClassName = utils::ReadParam('class_name', '', false, 'class');
$aFieldsMapping = utils::ReadParam('field', array(), false, 'raw_data');
$aSearchFields = utils::ReadParam('search_field', array(), false, 'field_name');
$iCurrentStep = $bSimulate ? 4 : 5;
$bAdvanced = utils::ReadParam('advanced', 0);
$sEncoding = utils::ReadParam('encoding', 'UTF-8');
$sSynchroScope = utils::ReadParam('synchro_scope', '', false, 'raw_data');
if (!empty($sSynchroScope)) {
$oSearch = DBObjectSearch::FromOQL($sSynchroScope);
$sClassName = $oSearch->GetClass();
// If a synchronization scope is set, then the class is fixed !
$oSet = new DBObjectSet($oSearch);
$iCount = $oSet->Count();
DisplaySynchroBanner($oPage, $sClassName, $iCount);
$sClassesSelect = "<select id=\"select_class_name\" name=\"class_name\"><option value=\"{$sClassName}\" selected>" . MetaModel::GetName($sClassName) . "</option>";
$aSynchroUpdate = utils::ReadParam('synchro_update', array());
} else {
$sSynchroScope = '';
$aSynchroUpdate = null;
}
// Parse the data set
$oCSVParser = new CSVParser($sCSVData, $sSeparator, $sTextQualifier);
$aData = $oCSVParser->ToArray($iSkippedLines);
$iRealSkippedLines = $iSkippedLines;
if ($bHeaderLine) {
$aResult[] = $sTextQualifier . implode($sTextQualifier . $sSeparator . $sTextQualifier, array_shift($aData)) . $sTextQualifier;
// Remove the first line and store it in case of error
$iRealSkippedLines++;
}
// Format for the line numbers
$sMaxLen = strlen('' . count($aData)) < 3 ? 3 : strlen('' . count($aData));
// Pad line numbers to the appropriate number of chars, but at least 3
// Compute the list of search/reconciliation criteria
$aSearchKeys = array();
foreach ($aSearchFields as $index => $sDummy) {
$sSearchField = $aFieldsMapping[$index];
$aMatches = array();
if (preg_match('/(.+)->(.+)/', $sSearchField, $aMatches) > 0) {
$sSearchField = $aMatches[1];
$aSearchKeys[$aMatches[1]] = '';
} else {
$aSearchKeys[$sSearchField] = '';
}
if (!MetaModel::IsValidFilterCode($sClassName, $sSearchField)) {
// Remove invalid or unmapped search fields
$aSearchFields[$index] = null;
unset($aSearchKeys[$sSearchField]);
}
}
// Compute the list of fields and external keys to process
$aExtKeys = array();
$aAttributes = array();
$aExternalKeysByColumn = array();
foreach ($aFieldsMapping as $iNumber => $sAttCode) {
$iIndex = $iNumber - 1;
if (!empty($sAttCode) && $sAttCode != ':none:' && $sAttCode != 'finalclass') {
if (preg_match('/(.+)->(.+)/', $sAttCode, $aMatches) > 0) {
$sAttribute = $aMatches[1];
$sField = $aMatches[2];
$aExtKeys[$sAttribute][$sField] = $iIndex;
$aExternalKeysByColumn[$iIndex] = $sAttribute;
} else {
if ($sAttCode == 'id') {
$aAttributes['id'] = $iIndex;
} else {
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
if ($oAttDef->IsExternalKey()) {
$aExtKeys[$sAttCode]['id'] = $iIndex;
$aExternalKeysByColumn[$iIndex] = $sAttCode;
} else {
$aAttributes[$sAttCode] = $iIndex;
}
}
}
}
}
$oMyChange = null;
if (!$bSimulate) {
// We're doing it for real, let's create a change
$sUserString = CMDBChange::GetCurrentUserName() . ' (CSV)';
CMDBObject::SetTrackInfo($sUserString);
CMDBObject::SetTrackOrigin('csv-interactive');
//.........这里部分代码省略.........