Prechádzať zdrojové kódy

N°984 Portal: Dependancies on autocomplete fields now works properly. (Changing value on a parent autcomplete was not resetting value on a dependant autocomplete field)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4863 a333f486-631f-4898-b8df-5754b55c2be0
glajarige 7 rokov pred
rodič
commit
799bd563d7

+ 4 - 0
core/attributedef.class.inc.php

@@ -4651,6 +4651,10 @@ class AttributeExternalKey extends AttributeDBFieldVoid
 			$oTmpField = $oFormField;
 			$oFormField->SetOnFinalizeCallback(function() use ($oTmpField, $oTmpAttDef, $oObject)
 			{
+			    /** @var $oTmpField \Combodo\iTop\Form\Field\Field */
+			    /** @var $oTmpAttDef \AttributeDefinition */
+			    /** @var $oObject \DBObject */
+
 				// We set search object only if it has not already been set (overrided)
 				if ($oTmpField->GetSearch() === null)
 				{

+ 20 - 0
datamodels/2.x/itop-portal-base/portal/src/forms/objectformmanager.class.inc.php

@@ -32,6 +32,9 @@ use \DBObject;
 use \DBObjectSet;
 use \DBSearch;
 use \DBObjectSearch;
+use \BinaryExpression;
+use \FieldExpression;
+use \ScalarExpression;
 use \DBObjectSetComparator;
 use \InlineImage;
 use \AttributeDateTime;
@@ -705,6 +708,23 @@ class ObjectFormManager extends FormManager
 							$oField->SetSearch($oScopeOriginal);
 						}
 					}
+					// - Field that require to check if the current value is among allowed ones
+                    if (in_array(get_class($oField), array('Combodo\\iTop\\Form\\Field\\SelectObjectField')))
+                    {
+                        // Note: We can't do this in AttributeExternalKey::MakeFormField() in the Field::SetOnFinalizeCallback() because at this point we have no information about the portal scope and ignore_silos flag, hence it always applies silos.
+                        // As a workaround we have to manually check if the field's current value is among the scope
+
+                        /** @var DBObjectSearch $oValuesScope */
+                        $oValuesScope = $oField->GetSearch()->DeepClone();
+                        $oBinaryExp = new BinaryExpression(new FieldExpression('id', $oValuesScope->GetClassAlias()), '=', new ScalarExpression( $oField->GetCurrentValue() ));
+                        $oValuesScope->AddConditionExpression($oBinaryExp);
+                        $oValuesSet = new DBObjectSet($oValuesScope);
+
+                        if( $oValuesSet->Count() === 0 )
+                        {
+                            $oField->SetCurrentValue(null);
+                        }
+                    }
 					// - Field that require processing on their subfields
 					if (in_array(get_class($oField), array('Combodo\\iTop\\Form\\Field\\SubFormField')))
 					{

+ 4 - 1
sources/form/field/selectobjectfield.class.inc.php

@@ -1,6 +1,6 @@
 <?php
 
-// Copyright (C) 2010-2016 Combodo SARL
+// Copyright (C) 2010-2017 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -116,6 +116,9 @@ class SelectObjectField extends Field
 		return $this;
 	}
 
+    /**
+     * @return \DBSearch
+     */
 	public function GetSearch()
 	{
 		return $this->oSearch;