summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2006-02-15 14:02:32 +0000
committerxue <>2006-02-15 14:02:32 +0000
commitba1933d83922e3eb42e93b3fa476f4614a58aebc (patch)
tree9c48973888dd8bf519a4d05710ebb05c6160feed /framework
parentc3c0ba0d974f905a8df0fd467aa9ee41ae74e968 (diff)
TDataFieldAccessor is used consistently to access all data field values.
Diffstat (limited to 'framework')
-rw-r--r--framework/Data/TDataFieldAccessor.php13
-rw-r--r--framework/Web/UI/TPage.php1
-rw-r--r--framework/Web/UI/WebControls/TBaseDataList.php12
-rw-r--r--framework/Web/UI/WebControls/TListControl.php18
4 files changed, 15 insertions, 29 deletions
diff --git a/framework/Data/TDataFieldAccessor.php b/framework/Data/TDataFieldAccessor.php
index 2c2be00f..af4d6ac0 100644
--- a/framework/Data/TDataFieldAccessor.php
+++ b/framework/Data/TDataFieldAccessor.php
@@ -52,10 +52,8 @@ class TDataFieldAccessor
{
if(Prado::getApplication()->getMode()===TApplication::STATE_PERFORMANCE)
{
- if(is_array($data))
+ if(is_array($data) || ($data instanceof ArrayAccess))
return $data[$field];
- else if(($data instanceof TMap) || ($data instanceof TList))
- return $data->itemAt($field);
else if(is_object($data))
{
if(strpos($field,'.')===false) // simple field
@@ -73,20 +71,13 @@ class TDataFieldAccessor
}
else
{
- if(is_array($data))
+ if(is_array($data) || ($data instanceof ArrayAccess))
{
if(isset($data[$field]))
return $data[$field];
else
throw new TInvalidDataValueException('datafieldaccessor_datafield_invalid',$field);
}
- else if(($data instanceof TMap) || ($data instanceof TList))
- {
- if($data->contains($field))
- return $data->itemAt($field);
- else
- throw new TInvalidDataValueException('datafieldaccessor_datafield_invalid',$field);
- }
else if(is_object($data))
{
if(strpos($field,'.')===false) // simple field
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 2e3dd68e..6e83e3be 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -13,6 +13,7 @@
//Prado::using('System.Web.UI.*');
Prado::using('System.Web.UI.WebControls.*');
Prado::using('System.Web.UI.TControl');
+Prado::using('System.Web.UI.WebControls.TWebControl');
Prado::using('System.Web.UI.TTemplateControl');
Prado::using('System.Web.UI.TForm');
Prado::using('System.Web.UI.TClientScriptManager');
diff --git a/framework/Web/UI/WebControls/TBaseDataList.php b/framework/Web/UI/WebControls/TBaseDataList.php
index c68be5f9..b7c79cbe 100644
--- a/framework/Web/UI/WebControls/TBaseDataList.php
+++ b/framework/Web/UI/WebControls/TBaseDataList.php
@@ -216,17 +216,7 @@ abstract class TBaseDataList extends TDataBoundControl
*/
protected function getDataFieldValue($data,$field)
{
- if(is_array($data))
- return $data[$field];
- else if(($data instanceof TMap) || ($data instanceof TList))
- return $data->itemAt($field);
- else if(($data instanceof TComponent) && $data->canGetProperty($field))
- {
- $getter='get'.$field;
- return $data->$getter();
- }
- else
- throw new TInvalidDataValueException('basedatalist_datafield_invalid');
+ return TDataFieldAccessor::getDataFieldValue($data,$field);
}
/**
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index 55a46171..67f5555a 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -161,15 +161,19 @@ abstract class TListControl extends TDataBoundControl
foreach($data as $key=>$object)
{
$item=new TListItem;
- if(!is_string($object) && isset($object[$textField]))
- $text=$object[$textField];
+ if(is_array($object) || is_object($object))
+ {
+ $text=TDataFieldAccessor::getDataFieldValue($object,$textField);
+ $value=TDataFieldAccessor::getDataFieldValue($object,$valueField);
+ $item->setValue($value);
+ }
else
- $text=TPropertyValue::ensureString($object);
+ {
+ $text=$object;
+ if(is_string($key))
+ $item->setValue($key);
+ }
$item->setText($textFormat===''?$text:sprintf($textFormat,$text));
- if(!is_string($object) && isset($object[$valueField]))
- $item->setValue($object[$valueField]);
- else if(!is_integer($key))
- $item->setValue($key);
$items->add($item);
}
}