diff --git a/application/ui.linksdirectwidget.class.inc.php b/application/ui.linksdirectwidget.class.inc.php index f6b02ff96..797ef49e8 100644 --- a/application/ui.linksdirectwidget.class.inc.php +++ b/application/ui.linksdirectwidget.class.inc.php @@ -243,7 +243,21 @@ class UILinksWidgetDirect public function GetObjectsSelectionDlg($oPage, $oCurrentObj) { $sHtml = "
\n"; - $oFilter = new DBObjectSearch($this->sLinkedClass); + + $oLinksetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode); + $valuesDef = $oLinksetDef->GetValuesDef(); + if ($valuesDef === null) + { + $oFilter = new DBObjectSearch($this->sLinkedClass); + } + else + { + if (!$valuesDef instanceof ValueSetObjects) + { + throw new Exception('Error: only ValueSetObjects are supported for "allowed_values" in AttributeLinkedSet ('.$this->sClass.'/'.$this->sAttCode.').'); + } + $oFilter = DBObjectSearch::FromOQL($valuesDef->GetFilterExpression()); + } if ($oCurrentObj != null) { $this->SetSearchDefaultFromContext($oCurrentObj, $oFilter); @@ -276,7 +290,21 @@ class UILinksWidgetDirect { $sRemoteClass = $this->sLinkedClass; } - $oFilter = new DBObjectSearch($sRemoteClass); + $oLinksetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode); + $valuesDef = $oLinksetDef->GetValuesDef(); + if ($valuesDef === null) + { + $oFilter = new DBObjectSearch($this->sLinkedClass); + } + else + { + if (!$valuesDef instanceof ValueSetObjects) + { + throw new Exception('Error: only ValueSetObjects are supported for "allowed_values" in AttributeLinkedSet ('.$this->sClass.'/'.$this->sAttCode.').'); + } + $oFilter = DBObjectSearch::FromOQL($valuesDef->GetFilterExpression()); + } + if (($oCurrentObj != null) && MetaModel::IsSameFamilyBranch($sRemoteClass, $this->sClass)) { // Prevent linking to self if the linked object is of the same family @@ -290,7 +318,12 @@ class UILinksWidgetDirect { $oFilter->AddCondition('id', $aAlreadyLinked, 'NOTIN'); } - $oSet = new CMDBObjectSet($oFilter); + $aArgs = array(); + if ($oCurrentObj != null) + { + $aArgs = $oCurrentObj->ToArgs('this'); + } + $oFilter->SetInternalParams($aArgs); $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oP, "ResultsToAdd_{$this->sInputid}", array('menu' => false, 'cssCount'=> '#count_'.$this->sInputid , 'selection_mode' => true, 'table_id' => 'add_'.$this->sInputid)); // Don't display the 'Actions' menu on the results } diff --git a/core/metamodel.class.php b/core/metamodel.class.php index fb4b2a29e..ed31de29a 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -3311,7 +3311,7 @@ abstract class MetaModel { if(!self::IsValidAttCode($sClass, $sAttCode)) { - $aErrors[$sClass][] = "Unkown attribute code '".$sAttCode."' for the name definition"; + $aErrors[$sClass][] = "Unknown attribute code '".$sAttCode."' for the name definition"; $aSugFix[$sClass][] = "Expecting a value in ".implode(", ", self::GetAttributesList($sClass)); } } @@ -3320,7 +3320,7 @@ abstract class MetaModel { if (!empty($sReconcKeyAttCode) && !self::IsValidAttCode($sClass, $sReconcKeyAttCode)) { - $aErrors[$sClass][] = "Unkown attribute code '".$sReconcKeyAttCode."' in the list of reconciliation keys"; + $aErrors[$sClass][] = "Unknown attribute code '".$sReconcKeyAttCode."' in the list of reconciliation keys"; $aSugFix[$sClass][] = "Expecting a value in ".implode(", ", self::GetAttributesList($sClass)); } } @@ -3335,7 +3335,7 @@ abstract class MetaModel { if (!self::IsValidClass($oAttDef->GetTargetClass())) { - $aErrors[$sClass][] = "Unkown class '".$oAttDef->GetTargetClass()."' for the external key '$sAttCode'"; + $aErrors[$sClass][] = "Unknown class '".$oAttDef->GetTargetClass()."' for the external key '$sAttCode'"; $aSugFix[$sClass][] = "Expecting a value in {".implode(", ", self::GetClasses())."}"; } } @@ -3344,7 +3344,7 @@ abstract class MetaModel $sKeyAttCode = $oAttDef->GetKeyAttCode(); if (!self::IsValidAttCode($sClass, $sKeyAttCode) || !self::IsValidKeyAttCode($sClass, $sKeyAttCode)) { - $aErrors[$sClass][] = "Unkown key attribute code '".$sKeyAttCode."' for the external field $sAttCode"; + $aErrors[$sClass][] = "Unknown key attribute code '".$sKeyAttCode."' for the external field $sAttCode"; $aSugFix[$sClass][] = "Expecting a value in {".implode(", ", self::GetKeysList($sClass))."}"; } else @@ -3354,11 +3354,15 @@ abstract class MetaModel $sExtAttCode = $oAttDef->GetExtAttCode(); if (!self::IsValidAttCode($sTargetClass, $sExtAttCode)) { - $aErrors[$sClass][] = "Unkown key attribute code '".$sExtAttCode."' for the external field $sAttCode"; + $aErrors[$sClass][] = "Unknown key attribute code '".$sExtAttCode."' for the external field $sAttCode"; $aSugFix[$sClass][] = "Expecting a value in {".implode(", ", self::GetKeysList($sTargetClass))."}"; } } } + else if ($oAttDef->IsLinkSet()) + { + // Do nothing... + } else // standard attributes { // Check that the default values definition is a valid object! @@ -3391,7 +3395,7 @@ abstract class MetaModel { if (!self::IsValidAttCode($sClass, $sDependOnAttCode)) { - $aErrors[$sClass][] = "Unkown attribute code '".$sDependOnAttCode."' in the list of prerequisite attributes"; + $aErrors[$sClass][] = "Unknown attribute code '".$sDependOnAttCode."' in the list of prerequisite attributes"; $aSugFix[$sClass][] = "Expecting a value in ".implode(", ", self::GetAttributesList($sClass)); } } @@ -3418,7 +3422,7 @@ abstract class MetaModel // Lifecycle - check that the state attribute does exist as an attribute if (!self::IsValidAttCode($sClass, $sStateAttCode)) { - $aErrors[$sClass][] = "Unkown attribute code '".$sStateAttCode."' for the state definition"; + $aErrors[$sClass][] = "Unknown attribute code '".$sStateAttCode."' for the state definition"; $aSugFix[$sClass][] = "Expecting a value in {".implode(", ", self::GetAttributesList($sClass))."}"; } else @@ -3492,7 +3496,7 @@ abstract class MetaModel { if (!self::IsValidAttCode($sClass, $sMyAttCode)) { - $aErrors[$sClass][] = "Unkown attribute code '".$sMyAttCode."' from ZList '$sListCode'"; + $aErrors[$sClass][] = "Unknown attribute code '".$sMyAttCode."' from ZList '$sListCode'"; $aSugFix[$sClass][] = "Expecting a value in {".implode(", ", self::GetAttributesList($sClass))."}"; } } diff --git a/datamodels/2.x/itop-change-mgmt-itil/datamodel.itop-change-mgmt-itil.xml b/datamodels/2.x/itop-change-mgmt-itil/datamodel.itop-change-mgmt-itil.xml index 47f6c116b..ab87fbb4e 100755 --- a/datamodels/2.x/itop-change-mgmt-itil/datamodel.itop-change-mgmt-itil.xml +++ b/datamodels/2.x/itop-change-mgmt-itil/datamodel.itop-change-mgmt-itil.xml @@ -170,28 +170,29 @@ UserRequest parent_change_id - none + add_remove 0 0 Incident parent_change_id - none + add_remove 0 0 Problem related_change_id - none + add_remove 0 0 Change parent_id - none + add_remove + id]]> 0 0 diff --git a/datamodels/2.x/itop-change-mgmt/datamodel.itop-change-mgmt.xml b/datamodels/2.x/itop-change-mgmt/datamodel.itop-change-mgmt.xml index 4d27791e4..be1ef67d6 100755 --- a/datamodels/2.x/itop-change-mgmt/datamodel.itop-change-mgmt.xml +++ b/datamodels/2.x/itop-change-mgmt/datamodel.itop-change-mgmt.xml @@ -130,6 +130,7 @@ Change parent_id add_remove + id]]> 0 0 diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index 42759fad7..3c7bf3c16 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -723,7 +723,6 @@ EOF; { $aParameters['linked_class'] = $this->GetPropString($oField, 'linked_class', ''); $aParameters['ext_key_to_me'] = $this->GetPropString($oField, 'ext_key_to_me', ''); - $aParameters['allowed_values'] = 'null'; $aParameters['count_min'] = $this->GetPropNumber($oField, 'count_min', 0); $aParameters['count_max'] = $this->GetPropNumber($oField, 'count_max', 0); $sEditMode = $oField->GetChildText('edit_mode'); @@ -731,6 +730,15 @@ EOF; { $aParameters['edit_mode'] = $this->EditModeToPHP($sEditMode); } + if ($sOql = $oField->GetChildText('filter')) + { + $sEscapedOql = self::QuoteForPHP($sOql); + $aParameters['allowed_values'] = "new ValueSetObjects($sEscapedOql)"; + } + else + { + $aParameters['allowed_values'] = 'null'; + } $aParameters['depends_on'] = $sDependencies; } elseif ($sAttType == 'AttributeExternalKey')