/** * Describe (as a text string) the modifications corresponding to this change */ public function GetDescription() { $sResult = ''; $oTargetObjectClass = $this->Get('objclass'); $oTargetObjectKey = $this->Get('objkey'); $oTargetSearch = new DBObjectSearch($oTargetObjectClass); $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); $oMonoObjectSet = new DBObjectSet($oTargetSearch); if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { return ''; } // Protects against renamed attributes... $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); $sAttName = $oAttDef->GetLabel(); $sLinkClass = $oAttDef->GetLinkedClass(); $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); // Search for changes on the corresponding link // $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); $oSearch->AddCondition('change', $this->Get('change'), '='); $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); if (count($aLinkClasses) == 1) { // Faster than the whole building of the expression below for just one value ?? $oSearch->AddCondition('objclass', $sLinkClass, '='); } else { $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); $sListExpr = '(' . implode(', ', CMDBSource::Quote($aLinkClasses)) . ')'; $sOQLCondition = $oField->Render() . " IN {$sListExpr}"; $oNewCondition = Expression::FromOQL($sOQLCondition); $oSearch->AddConditionExpression($oNewCondition); } $oSet = new DBObjectSet($oSearch); $aChanges = array(); while ($oChangeOp = $oSet->Fetch()) { $aChanges[] = $oChangeOp->GetDescription(); } if (count($aChanges) == 0) { return ''; } $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); $sResult = $sAttName . ' - '; $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); $sResult .= ' : ' . implode(', ', $aChanges); } return $sResult; }
protected static function GetConditionIN($oFilter, $sFilterCode, $condition) { $oField = new FieldExpression($sFilterCode, $oFilter->GetClassAlias()); $sListExpr = '(' . implode(', ', CMDBSource::Quote($condition)) . ')'; $sOQLCondition = $oField->Render() . " IN {$sListExpr}"; $oNewCondition = Expression::FromOQL($sOQLCondition); return $oNewCondition; }
public function walkField(FieldExpression $expression) { return $expression->update($this->walk($expression->getValue()), $this->walk($expression->getName())); }
/** * Parses a string to find some smart search patterns and build the corresponding search/OQL condition * Each derived class is reponsible for defining and processing their own smart patterns, the base class * does nothing special, and just calls the default (loose) operator * @param string $sSearchText The search string to analyze for smart patterns * @param FieldExpression The FieldExpression representing the atttribute code in this OQL query * @param Hash $aParams Values of the query parameters * @return Expression The search condition to be added (AND) to the current search */ public function GetSmartConditionExpression($sSearchText, FieldExpression $oField, &$aParams) { // Possible smart patterns $aPatterns = array('between' => array('pattern' => '/^\\[(.*),(.*)\\]$/', 'operator' => 'n/a'), 'greater than or equal' => array('pattern' => '/^>=(.*)$/', 'operator' => '>='), 'greater than' => array('pattern' => '/^>(.*)$/', 'operator' => '>'), 'less than or equal' => array('pattern' => '/^<=(.*)$/', 'operator' => '<='), 'less than' => array('pattern' => '/^<(.*)$/', 'operator' => '<')); $sPatternFound = ''; $aMatches = array(); foreach ($aPatterns as $sPatName => $sPattern) { if (preg_match($sPattern['pattern'], $sSearchText, $aMatches)) { $sPatternFound = $sPatName; break; } } switch ($sPatternFound) { case 'between': $sParamName1 = $oField->GetParent() . '_' . $oField->GetName() . '_1'; $oRightExpr = new VariableExpression($sParamName1); $aParams[$sParamName1] = $aMatches[1]; $oCondition1 = new BinaryExpression($oField, '>=', $oRightExpr); $sParamName2 = $oField->GetParent() . '_' . $oField->GetName() . '_2'; $oRightExpr = new VariableExpression($sParamName2); $sOperator = $this->GetBasicFilterLooseOperator(); $aParams[$sParamName2] = $aMatches[2]; $oCondition2 = new BinaryExpression($oField, '<=', $oRightExpr); $oNewCondition = new BinaryExpression($oCondition1, 'AND', $oCondition2); break; case 'greater than': case 'greater than or equal': case 'less than': case 'less than or equal': $sSQLOperator = $aPatterns[$sPatternFound]['operator']; $sParamName = $oField->GetParent() . '_' . $oField->GetName(); $oRightExpr = new VariableExpression($sParamName); $aParams[$sParamName] = $aMatches[1]; $oNewCondition = new BinaryExpression($oField, $sSQLOperator, $oRightExpr); break; default: $oNewCondition = parent::GetSmartConditionExpression($sSearchText, $oField, $aParams); } return $oNewCondition; }
public function __construct($oName, $oParent = null) { if (is_null($oParent)) { $oParent = new OqlName('', 0); } $this->m_oParent = $oParent; $this->m_oName = $oName; parent::__construct($oName->GetValue(), $oParent->GetValue()); }