Selaa lähdekoodia

#128 Allow a blob to be undefined (optional property)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@427 a333f486-631f-4898-b8df-5754b55c2be0
romainq 15 vuotta sitten
vanhempi
commit
e31f715411
2 muutettua tiedostoa jossa 19 lisäystä ja 3 poistoa
  1. 3 1
      business/itop.business.class.inc.php
  2. 16 2
      core/attributedef.class.inc.php

+ 3 - 1
business/itop.business.class.inc.php

@@ -342,7 +342,9 @@ class bizDocument extends logRealObject
 		MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum("documentation,contract,working instructions,network map,white paper,presentation,training"), "sql"=>"type", "default_value"=>"documentation", "is_null_allowed"=>false, "depends_on"=>array())));
 		MetaModel::Init_AddAttribute(new AttributeText("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
 
-		MetaModel::Init_AddAttribute(new AttributeBlob("contents", array("depends_on"=>array())));
+//		MetaModel::Init_AddAttribute(new AttributeBlob("contents", array("depends_on"=>array())));
+		MetaModel::Init_AddAttribute(new AttributeBlob("contents", array("is_null_allowed"=>true, "depends_on"=>array())));
+
 
 		MetaModel::Init_SetZListItems('details', array('name', 'status', 'org_id', 'type', 'description', 'contents')); // Attributes to be displayed for the complete details
 		MetaModel::Init_SetZListItems('list', array('name', 'status', 'org_id', 'type', 'contents')); // Attributes to be displayed for a list

+ 16 - 2
core/attributedef.class.inc.php

@@ -80,6 +80,18 @@ abstract class AttributeDefinition
 	private $m_sHostClass = '!undefined!';
 	protected function Get($sParamName) {return $this->m_aParams[$sParamName];}
 	protected function IsParam($sParamName) {return (array_key_exists($sParamName, $this->m_aParams));}
+
+	protected function GetOptional($sParamName, $default)
+	{
+		if (array_key_exists($sParamName, $this->m_aParams))
+		{
+			return $this->m_aParams[$sParamName];
+		}
+		else
+		{
+			return $default;
+		}
+	}
 	
 	public function __construct($sCode, $aParams)
 	{
@@ -353,6 +365,7 @@ class AttributeDBFieldVoid extends AttributeDefinition
 	public function GetDefaultValue() {return "";}
 	public function IsNullAllowed() {return false;}
 
+	// 
 	protected function ScalarToSQL($value) {return $value;} // format value as a valuable SQL literal (quoted outside)
 
 	public function GetSQLExpressions()
@@ -423,7 +436,7 @@ class AttributeDBField extends AttributeDBFieldVoid
 		return array_merge(parent::ListExpectedParams(), array("default_value", "is_null_allowed"));
 	}
 	public function GetDefaultValue() {return $this->Get("default_value");}
-	public function IsNullAllowed() {return strtolower($this->Get("is_null_allowed"));}
+	public function IsNullAllowed() {return $this->Get("is_null_allowed");}
 }
 
 /**
@@ -1526,7 +1539,8 @@ class AttributeBlob extends AttributeDefinition
 	public function IsScalar() {return true;} 
 	public function IsWritable() {return true;} 
 	public function GetDefaultValue() {return "";}
-	public function IsNullAllowed() {return false;}
+	public function IsNullAllowed() {return $this->GetOptional("is_null_allowed", false);}
+
 
 	// Facilitate things: allow the user to Set the value from a string
 	public function MakeRealValue($proposedValue)