New type of attribute: IP address

SVN:trunk[418]
This commit is contained in:
Romain Quetiez
2010-05-18 14:34:36 +00:00
parent 280c8579be
commit d65693598b
2 changed files with 38 additions and 15 deletions

View File

@@ -815,8 +815,8 @@ class bizSubnet extends logInfra
);
MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeString("ip", array("allowed_values"=>null, "sql"=>"ip", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeString("mask", array("allowed_values"=>null, "sql"=>"mask", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeIPAddress("ip", array("allowed_values"=>null, "sql"=>"ip", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeIPAddress("mask", array("allowed_values"=>null, "sql"=>"mask", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
// Display lists
MetaModel::Init_SetZListItems('details', array('name', 'ip','mask')); // Attributes to be displayed for the complete details
@@ -898,7 +898,7 @@ class bizDevice extends logInfra
MetaModel::Init_AddAttribute(new AttributeString("brand", array("allowed_values"=>null, "sql"=>"brand", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeString("model", array("allowed_values"=>null, "sql"=>"model", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeString("serial_number", array("allowed_values"=>null, "sql"=>"serial_number", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeString("mgmt_ip", array("allowed_values"=>null, "sql"=>"mgmt_ip", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeIPAddress("mgmt_ip", array("allowed_values"=>null, "sql"=>"mgmt_ip", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
}
public static function GetRelationQueries($sRelCode)

View File

@@ -160,14 +160,6 @@ abstract class AttributeDefinition
}
public function GetValuesDef() {return null;}
public function GetPrerequisiteAttributes() {return array();}
//public function IsSearchableStd() {return $this->Get("search_std");}
//public function IsSearchableGlobal() {return $this->Get("search_global");}
//public function IsMandatory() {return $this->Get("is_mandatory");}
//public function GetMinVal() {return $this->Get("min");}
//public function GetMaxVal() {return $this->Get("max");}
//public function GetSize() {return $this->Get("size");}
//public function GetCheckRegExp() {return $this->Get("regexp");}
//public function GetCheckFunc() {return $this->Get("checkfunc");}
public function MakeRealValue($proposedValue) {return $proposedValue;} // force an allowed value (type conversion and possibly forces a value as mySQL would do upon writing!)
@@ -184,10 +176,7 @@ abstract class AttributeDefinition
public function CheckValue($value)
{
$sRegExp = $this->Get("regexp"); // ??? Does it exist ??
if (empty($sRegExp)) return true;
return preg_match(preg_escape($this->Get("regexp")), $value);
return true;
}
public function MakeValue()
@@ -587,6 +576,19 @@ class AttributeString extends AttributeDBField
public function GetEditClass() {return "String";}
protected function GetSQLCol() {return "VARCHAR(255)";}
public function CheckValue($value)
{
$sRegExp = $this->GetValidationPattern();
if (empty($sRegExp))
{
return true;
}
else
{
return preg_match(preg_escape($sRegExp), $value);
}
}
public function GetBasicFilterOperators()
{
return array(
@@ -809,6 +811,27 @@ class AttributeEmailAddress extends AttributeString
}
}
/**
* Specialization of a string: IP address
*
* @package iTopORM
* @author Romain Quetiez <romainquetiez@yahoo.fr>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.itop.com
* @since 1.0
* @version $itopversion$
*/
class AttributeIPAddress extends AttributeString
{
public function GetTypeDesc() {return "IP address";}
public function GetValidationPattern()
{
$sNum = '(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])';
return "^($sNum\\.$sNum\\.$sNum\\.$sNum)$";
}
}
/**
* Specialization of a string: OQL expression
*