From 1d94593d09b68786f7035e7b06ec6d8324894d77 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 7 Apr 2006 18:44:07 +0000 Subject: Format string in classes extending TListControl can now evaluate an expression --- framework/Web/UI/WebControls/TDataGridColumn.php | 30 ++++-------------------- 1 file changed, 5 insertions(+), 25 deletions(-) (limited to 'framework/Web/UI/WebControls/TDataGridColumn.php') diff --git a/framework/Web/UI/WebControls/TDataGridColumn.php b/framework/Web/UI/WebControls/TDataGridColumn.php index a22fa240..ea825360 100644 --- a/framework/Web/UI/WebControls/TDataGridColumn.php +++ b/framework/Web/UI/WebControls/TDataGridColumn.php @@ -11,9 +11,10 @@ */ /** - * Includes TDataFieldAccessor class + * Includes TDataFieldAccessor and TDataValueFormatter classes */ Prado::using('System.Util.TDataFieldAccessor'); +Prado::using('System.Util.TDataValueFormatter'); /** * TDataGridColumn class @@ -332,36 +333,15 @@ abstract class TDataGridColumn extends TApplicationComponent /** * Formats the text value according to a format string. - * If the format string is empty, the original value is converted into - * a string and returned. - * If the format string starts with '#', the string is treated as a PHP expression - * within which the token '$$' is translated with the data value to be formated. - * Otherwise, the format string and the data value are passed - * as the first and second parameters in {@link sprintf}. + * It uses {@link TDataValueFormatter} to do the actual formatting. * @param string format string * @param mixed the data associated with the cell * @return string the formatted result + * @see TDataValueFormatter::format() */ protected function formatDataValue($formatString,$value) { - if($formatString==='') - return TPropertyValue::ensureString($value); - else if($formatString[0]==='#') - { - $expression=strtr(substr($formatString,1),array('$$'=>'$value')); - try - { - if(eval("\$result=$expression;")===false) - throw new Exception(''); - return $result; - } - catch(Exception $e) - { - throw new TInvalidOperationException('datagridcolumn_expression_invalid',get_class($this),$expression,$e->getMessage()); - } - } - else - return sprintf($formatString,$value); + return TDataValueFormatter::format($formatString,$value,$this); } } -- cgit v1.2.3