From 8569373e8cb6163f182fe13ffbc44ea1b2c961cd Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 23 Feb 2006 03:38:15 +0000 Subject: more clean up work about validators. --- framework/Web/UI/WebControls/TCompareValidator.php | 22 ++++++++------------ .../Web/UI/WebControls/TDataTypeValidator.php | 24 ++++++++++++++++------ framework/Web/UI/WebControls/TRangeValidator.php | 14 ++++++------- 3 files changed, 33 insertions(+), 27 deletions(-) (limited to 'framework/Web/UI/WebControls') diff --git a/framework/Web/UI/WebControls/TCompareValidator.php b/framework/Web/UI/WebControls/TCompareValidator.php index 6cc9d0e5..811ca50a 100644 --- a/framework/Web/UI/WebControls/TCompareValidator.php +++ b/framework/Web/UI/WebControls/TCompareValidator.php @@ -26,7 +26,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * a constant value, specify the constant value to compare with by setting the * {@link setValueToCompare ValueToCompare} property. * - * The {@link setValueType ValueType} property is used to specify the data type + * The {@link setDataType DataType} property is used to specify the data type * of both comparison values. Both values are automatically converted to this data * type before the comparison operation is performed. The following value types are supported: * - Integer A 32-bit signed integer data type. @@ -37,13 +37,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * * Use the {@link setOperator Operator} property to specify the type of comparison * to perform. Valid operators include Equal, NotEqual, GreaterThan, GreaterThanEqual, - * LessThan, LessThanEqual, and DataTypeCheck. - * - * Note, if you set {@link setOperator Operator} to DataTypeCheck, the validator - * will ignore the {@link setControlToCompare ControlToCompare} and - * {@link setValueToCompare ValueToCompare} properties and simply - * indicates whether the value entered into the input control can be converted - * to the data type specified by the {@link setValueType ValueType} property. + * LessThan and LessThanEqual. * * @author Qiang Xue * @version $Revision: $ $Date: $ @@ -55,18 +49,18 @@ class TCompareValidator extends TBaseValidator /** * @return string the data type that the values being compared are converted to before the comparison is made. Defaults to String. */ - public function getValueType() + public function getDataType() { - return $this->getViewState('ValueType','String'); + return $this->getViewState('DataType','String'); } /** * Sets the data type (Integer, Float, Currency, Date, String) that the values being compared are converted to before the comparison is made. * @param string the data type */ - public function setValueType($value) + public function setDataType($value) { - $this->setViewState('ValueType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String'); + $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String'); } /** @@ -187,7 +181,7 @@ class TCompareValidator extends TBaseValidator */ protected function getComparisonValues($value1, $value2) { - switch($this->getValueType()) + switch($this->getDataType()) { case 'Integer': return array(intval($value1), intval($value2)); @@ -232,7 +226,7 @@ class TCompareValidator extends TBaseValidator $options['valuetocompare']=$value; if(($operator=$this->getOperator())!=='Equal') $options['operator']=$operator; - $options['type']=$this->getValueType(); + $options['type']=$this->getDataType(); if(($dateFormat=$this->getDateFormat())!=='') $options['dateformat']=$dateFormat; return $options; diff --git a/framework/Web/UI/WebControls/TDataTypeValidator.php b/framework/Web/UI/WebControls/TDataTypeValidator.php index daaa9b6e..f3cf5a3c 100644 --- a/framework/Web/UI/WebControls/TDataTypeValidator.php +++ b/framework/Web/UI/WebControls/TDataTypeValidator.php @@ -18,6 +18,18 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); /** * TDataTypeValidator class * + * TDataTypeValidator verifies if the input data is of the type specified + * by {@link setDataType DataType}. + * The following data types are supported: + * - Integer A 32-bit signed integer data type. + * - Float A double-precision floating point number data type. + * - Currency A decimal data type that can contain currency symbols. + * - Date A date data type. + * - String A string data type. + * For Date type, the property {@link setDateFormat DateFormat} + * will be used to determine how to parse the date string. If it is not + * provided, the string will be assumed to be in GNU datetime format. + * * @author Wei Zhuo * @version $Revision: $ $Date: $ * @package System.Web.UI.WebControls @@ -28,18 +40,18 @@ class TDataTypeValidator extends TBaseValidator /** * @return string the data type that the values being compared are converted to before the comparison is made. Defaults to String. */ - public function getValueType() + public function getDataType() { - return $this->getViewState('ValueType','String'); + return $this->getViewState('DataType','String'); } /** - * Sets the data type (Integer, Double, Currency, Date, String) that the values being compared are converted to before the comparison is made. + * Sets the data type (Integer, Float, Currency, Date, String) that the values being compared are converted to before the comparison is made. * @param string the data type */ - public function setValueType($value) + public function setDataType($value) { - $this->setViewState('ValueType',TPropertyValue::ensureEnum($value,'Integer','Double','Date','Currency','String'),'String'); + $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String'); } /** @@ -67,7 +79,7 @@ class TDataTypeValidator extends TBaseValidator */ protected function evaluateDataTypeCheck($value) { - switch($this->getValueType()) + switch($this->getDataType()) { case 'Integer': return preg_match('/^[-+]?[0-9]+$/',trim($value)); diff --git a/framework/Web/UI/WebControls/TRangeValidator.php b/framework/Web/UI/WebControls/TRangeValidator.php index e66221df..a861c9d6 100644 --- a/framework/Web/UI/WebControls/TRangeValidator.php +++ b/framework/Web/UI/WebControls/TRangeValidator.php @@ -23,7 +23,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * TRangeValidator uses three key properties to perform its validation. * The {@link setMinValue MinValue} and {@link setMaxValue MaxValue} * properties specify the minimum and maximum values of the valid range. - * The {@link setValueType ValueType} property is used to specify the + * The {@link setDataType DataType} property is used to specify the * data type of the value and the minimum and maximum range values. * These values are converted to this data type before the validation * operation is performed. The following value types are supported: @@ -81,9 +81,9 @@ class TRangeValidator extends TBaseValidator * @return string the data type that the values being compared are * converted to before the comparison is made. Defaults to String. */ - public function getValueType() + public function getDataType() { - return $this->getViewState('ValueType','String'); + return $this->getViewState('DataType','String'); } /** @@ -91,9 +91,9 @@ class TRangeValidator extends TBaseValidator * being compared are converted to before the comparison is made. * @param string the data type */ - public function setValueType($value) + public function setDataType($value) { - $this->setViewState('ValueType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String'); + $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String'); } /** @@ -125,7 +125,7 @@ class TRangeValidator extends TBaseValidator if($value==='') return true; - switch($this->getValueType()) + switch($this->getDataType()) { case 'Integer': return $this->isValidInteger($value); @@ -273,7 +273,7 @@ class TRangeValidator extends TBaseValidator $options=parent::getClientScriptOptions(); $options['minimumvalue']=$this->getMinValue(); $options['maximumvalue']=$this->getMaxValue(); - $options['type']=$this->getValueType(); + $options['type']=$this->getDataType(); if(($dateFormat=$this->getDateFormat())!=='') $options['dateformat']=$dateFormat; return $options; -- cgit v1.2.3