Browse Source

Fixed issue with null value for an Enum that would be hidden in a given state, being handled as an empty string, which is not an allowed value.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@541 a333f486-631f-4898-b8df-5754b55c2be0
romainq 15 years ago
parent
commit
239c0a42bd
2 changed files with 19 additions and 0 deletions
  1. 8 0
      core/attributedef.class.inc.php
  2. 11 0
      core/dbobject.class.php

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

@@ -972,6 +972,14 @@ class AttributeEnum extends AttributeString
 		}
   		return $aLocalizedValues;
   }
+
+	public function MakeRealValue($proposedValue)
+	{
+		// For an enum, let's consider an empty value like a null value
+		// Could be implemented by changing the UI : no value => let the default value
+		if ($proposedValue == '') return null;
+		return parent::MakeRealValue($proposedValue);
+	}
 }
 
 /**

+ 11 - 0
core/dbobject.class.php

@@ -602,6 +602,17 @@ abstract class DBObject
 		}
 		elseif ($oAtt->IsWritable() && $oAtt->IsScalar())
 		{
+			if (is_null($toCheck))
+			{
+				if ($oAtt->IsNullAllowed())
+				{
+					return true;
+				}
+				else
+				{
+					return false;
+				}
+			}
 			$aValues = $oAtt->GetAllowedValues();
 			if (count($aValues) > 0)
 			{