summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorcarl <>2008-10-13 10:28:33 +0000
committercarl <>2008-10-13 10:28:33 +0000
commit451b5bcf4b928fbc99ef40482c51704b08734c97 (patch)
tree06b9bc0adc07addcbcc48382f08b425db3012aa8 /framework
parent1524d5f72e035410c5ee8f38e74299701dd1f731 (diff)
#756 - TDateFormat & TNumberFormat - allow settings default text when Value isn't set.
Diffstat (limited to 'framework')
-rw-r--r--framework/I18N/TDateFormat.php41
-rw-r--r--framework/I18N/TNumberFormat.php29
2 files changed, 62 insertions, 8 deletions
diff --git a/framework/I18N/TDateFormat.php b/framework/I18N/TDateFormat.php
index 2343011e..914131bd 100644
--- a/framework/I18N/TDateFormat.php
+++ b/framework/I18N/TDateFormat.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.I18N
@@ -51,6 +51,9 @@ Prado::using('System.I18N.TI18NControl');
* 'fulldate', 'longdate', 'mediumdate', 'shortdate', 'fulltime',
* 'longtime', 'mediumtime', and 'shorttime'. Custom patterns can specified
* when the Pattern property does not match the predefined patterns.
+ * - <b>DefaultText</b>, string,
+ * <br>Gets or sets the default text. If Value is not set, DefaultText will be
+ * shown instead of todays date and time.
*
* @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version v1.0, last update on Sat Dec 11 15:25:11 EST 2004
@@ -146,7 +149,11 @@ class TDateFormat extends TI18NControl implements IDataRenderer
{
$value = $this->getViewState('Value','');
if(empty($value))
- return time();
+ {
+ $defaultText = $this->getDefaultText();
+ if(empty($defaultText))
+ return time();
+ }
return $value;
}
@@ -158,6 +165,24 @@ class TDateFormat extends TI18NControl implements IDataRenderer
{
$this->setViewState('Value',$value,'');
}
+
+ /**
+ * Get the default text value for this control.
+ * @return string default text value
+ */
+ public function getDefaultText()
+ {
+ return $this->getViewState('DefaultText','');
+ }
+
+ /**
+ * Set the default text value for this control.
+ * @param string default text value
+ */
+ public function setDefaultText($value)
+ {
+ $this->setViewState('DefaultText',$value,'');
+ }
/**
* Get the date-time value for this control.
@@ -193,6 +218,11 @@ class TDateFormat extends TI18NControl implements IDataRenderer
*/
protected function getFormattedDate()
{
+ $value = $this->getValue();
+ $defaultText = $this->getDefaultText();
+ if(empty($value) && !empty($defaultText))
+ return $this->getDefaultText();
+
$app = $this->getApplication()->getGlobalization();
//initialized the default class wide formatter
@@ -205,12 +235,12 @@ class TDateFormat extends TI18NControl implements IDataRenderer
if(strlen($culture) && $app->getCulture() !== $culture)
{
$formatter = new DateFormat($culture);
- return $formatter->format($this->getValue(),
+ return $formatter->format($value,
$this->getPattern(),
$this->getCharset());
}
//return the application wide culture formatted date time.
- $result = self::$formatter->format($this->getValue(),
+ $result = self::$formatter->format($value,
$this->getPattern(),
$this->getCharset());
return $result;
@@ -221,5 +251,4 @@ class TDateFormat extends TI18NControl implements IDataRenderer
$writer->write($this->getFormattedDate());
}
-}
-?>
+} \ No newline at end of file
diff --git a/framework/I18N/TNumberFormat.php b/framework/I18N/TNumberFormat.php
index 12422521..62b43243 100644
--- a/framework/I18N/TNumberFormat.php
+++ b/framework/I18N/TNumberFormat.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.I18N
@@ -56,6 +56,9 @@ Prado::using('System.I18N.TI18NControl');
* The default is 'USD' if the Currency property is not specified.
* - <b>Pattern</b>, string,
* <br>Gets or sets the custom number formatting pattern.
+ * - <b>DefaultText</b>, string,
+ * <br>Gets or sets the default text. If Value is not set, DefaultText will be
+ * shown instead of the default currency Value/Pattern.
*
* @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version v1.0, last update on Sat Dec 11 17:49:56 EST 2004
@@ -105,6 +108,23 @@ class TNumberFormat extends TI18NControl implements IDataRenderer
$this->setViewState('Value',$value,'');
}
+ /**
+ * Get the default text value for this control.
+ * @return string default text value
+ */
+ public function getDefaultText()
+ {
+ return $this->getViewState('DefaultText','');
+ }
+
+ /**
+ * Set the default text value for this control.
+ * @param string default text value
+ */
+ public function setDefaultText($value)
+ {
+ $this->setViewState('DefaultText',$value,'');
+ }
/**
* Get the numberic value for this control.
@@ -193,6 +213,11 @@ class TNumberFormat extends TI18NControl implements IDataRenderer
*/
protected function getFormattedValue()
{
+ $value = $this->getValue();
+ $defaultText = $this->getDefaultText();
+ if(empty($value) && !empty($defaultText))
+ return $this->getDefaultText();
+
$app = $this->getApplication()->getGlobalization();
//initialized the default class wide formatter
if(is_null(self::$formatter))
@@ -223,4 +248,4 @@ class TNumberFormat extends TI18NControl implements IDataRenderer
}
}
-?>
+?>