summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls
diff options
context:
space:
mode:
authorxue <>2006-04-04 16:50:43 +0000
committerxue <>2006-04-04 16:50:43 +0000
commit996c6d61ffef676247f8b1c9a7ee4b7c69850654 (patch)
tree0aa967aa9a9df35094a4fc6b1e987da631e45ca2 /framework/Web/UI/WebControls
parentf6499741dd119d7021e20bcfa6c1870dbf96accb (diff)
Format string in TDataGrid columns can now evaluate an expression
Diffstat (limited to 'framework/Web/UI/WebControls')
-rw-r--r--framework/Web/UI/WebControls/TDataGridColumn.php26
1 files changed, 23 insertions, 3 deletions
diff --git a/framework/Web/UI/WebControls/TDataGridColumn.php b/framework/Web/UI/WebControls/TDataGridColumn.php
index de9d9d5c..a22fa240 100644
--- a/framework/Web/UI/WebControls/TDataGridColumn.php
+++ b/framework/Web/UI/WebControls/TDataGridColumn.php
@@ -331,17 +331,37 @@ abstract class TDataGridColumn extends TApplicationComponent
}
/**
- * Formats the text value according to format string.
- * This method invokes the {@link sprintf} to do string formatting.
+ * 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}.
* @param string format string
* @param mixed the data associated with the cell
* @return string the formatted result
*/
protected function formatDataValue($formatString,$value)
{
- return $formatString===''?TPropertyValue::ensureString($value):sprintf($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);
}
}