summaryrefslogtreecommitdiff
path: root/framework/Web/UI
diff options
context:
space:
mode:
authorxue <>2006-02-04 23:56:29 +0000
committerxue <>2006-02-04 23:56:29 +0000
commit139ca38ddcf4998c882cfc98cb932524de210d86 (patch)
tree99471fff9e2db46d01e5473cfd5c1566c7c1209a /framework/Web/UI
parent97d5ad831a6003418562b7f44e9a08e562d88a0c (diff)
Modified TDataGrid sample to enable updating rating.
Diffstat (limited to 'framework/Web/UI')
-rw-r--r--framework/Web/UI/WebControls/TDataBoundControl.php3
-rw-r--r--framework/Web/UI/WebControls/TDataGrid.php106
-rw-r--r--framework/Web/UI/WebControls/TDataList.php45
-rw-r--r--framework/Web/UI/WebControls/TListControl.php2
-rw-r--r--framework/Web/UI/WebControls/TRepeater.php25
5 files changed, 82 insertions, 99 deletions
diff --git a/framework/Web/UI/WebControls/TDataBoundControl.php b/framework/Web/UI/WebControls/TDataBoundControl.php
index b7294383..0bb771bf 100644
--- a/framework/Web/UI/WebControls/TDataBoundControl.php
+++ b/framework/Web/UI/WebControls/TDataBoundControl.php
@@ -196,7 +196,8 @@ abstract class TDataBoundControl extends TWebControl
$this->dataBindProperties();
$this->onDataBinding(null);
$data=$this->getData();
- $this->performDataBinding($data);
+ if($data instanceof Traversable)
+ $this->performDataBinding($data);
$this->setIsDataBound(true);
$this->onDataBound(null);
}
diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php
index eceb498b..1817d03e 100644
--- a/framework/Web/UI/WebControls/TDataGrid.php
+++ b/framework/Web/UI/WebControls/TDataGrid.php
@@ -869,76 +869,66 @@ class TDataGrid extends TBaseDataList implements INamingContainer
$this->reset();
$keys=$this->getDataKeys();
$keys->clear();
- if($data instanceof Traversable)
+ $keyField=$this->getDataKeyField();
+ $this->_pagedDataSource=$ds=$this->createPagedDataSource();
+ $ds->setDataSource($data);
+ $allowPaging=$ds->getAllowPaging();
+ if($allowPaging && $ds->getCurrentPageIndex()>=$ds->getPageCount())
+ throw new TInvalidDataValueException('datagrid_currentpageindex_invalid');
+ // get all columns
+ if($this->getAutoGenerateColumns())
{
- $keyField=$this->getDataKeyField();
- $this->_pagedDataSource=$ds=$this->createPagedDataSource();
- $ds->setDataSource($data);
- $allowPaging=$ds->getAllowPaging();
- if($allowPaging && $ds->getCurrentPageIndex()>=$ds->getPageCount())
- throw new TInvalidDataValueException('datagrid_currentpageindex_invalid');
- // get all columns
- if($this->getAutoGenerateColumns())
- {
- $columns=new TList($this->getColumns());
- $autoColumns=$this->createAutoColumns($ds);
- $columns->mergeWith($autoColumns);
- }
- else
- $columns=$this->getColumns();
+ $columns=new TList($this->getColumns());
+ $autoColumns=$this->createAutoColumns($ds);
+ $columns->mergeWith($autoColumns);
+ }
+ else
+ $columns=$this->getColumns();
- $items=$this->getItems();
+ $items=$this->getItems();
- if(($columnCount=$columns->getCount())>0)
- {
- foreach($columns as $column)
- $column->initialize();
- $allowPaging=$ds->getAllowPaging();
- if($allowPaging)
- $this->createPager(-1,-1,$columnCount,$ds);
- $this->createItemInternal(-1,-1,'Header',true,null,$columns);
- $selectedIndex=$this->getSelectedItemIndex();
- $editIndex=$this->getEditItemIndex();
- $index=0;
- $dsIndex=$ds->getAllowPaging()?$ds->getFirstIndexInPage():0;
- foreach($ds as $data)
- {
- if($keyField!=='')
- $keys->add($this->getDataFieldValue($data,$keyField));
- if($index===$editIndex)
- $itemType='EditItem';
- else if($index===$selectedIndex)
- $itemType='SelectedItem';
- else if($index % 2)
- $itemType='AlternatingItem';
- else
- $itemType='Item';
- $items->add($this->createItemInternal($index,$dsIndex,$itemType,true,$data,$columns));
- $index++;
- $dsIndex++;
- }
- $this->createItemInternal(-1,-1,'Footer',true,null,$columns);
- if($allowPaging)
- $this->createPager(-1,-1,$columnCount,$ds);
- $this->setViewState('ItemCount',$index,0);
- $this->setViewState('PageCount',$ds->getPageCount(),0);
- $this->setViewState('DataSourceCount',$ds->getDataSourceCount(),0);
- }
- else
+ if(($columnCount=$columns->getCount())>0)
+ {
+ foreach($columns as $column)
+ $column->initialize();
+ $allowPaging=$ds->getAllowPaging();
+ if($allowPaging)
+ $this->createPager(-1,-1,$columnCount,$ds);
+ $this->createItemInternal(-1,-1,'Header',true,null,$columns);
+ $selectedIndex=$this->getSelectedItemIndex();
+ $editIndex=$this->getEditItemIndex();
+ $index=0;
+ $dsIndex=$ds->getAllowPaging()?$ds->getFirstIndexInPage():0;
+ foreach($ds as $data)
{
- $this->clearViewState('ItemCount');
- $this->clearViewState('PageCount');
- $this->clearViewState('DataSourceCount');
+ if($keyField!=='')
+ $keys->add($this->getDataFieldValue($data,$keyField));
+ if($index===$editIndex)
+ $itemType='EditItem';
+ else if($index===$selectedIndex)
+ $itemType='SelectedItem';
+ else if($index % 2)
+ $itemType='AlternatingItem';
+ else
+ $itemType='Item';
+ $items->add($this->createItemInternal($index,$dsIndex,$itemType,true,$data,$columns));
+ $index++;
+ $dsIndex++;
}
- $this->_pagedDataSource=null;
+ $this->createItemInternal(-1,-1,'Footer',true,null,$columns);
+ if($allowPaging)
+ $this->createPager(-1,-1,$columnCount,$ds);
+ $this->setViewState('ItemCount',$index,0);
+ $this->setViewState('PageCount',$ds->getPageCount(),0);
+ $this->setViewState('DataSourceCount',$ds->getDataSourceCount(),0);
}
else
{
- $this->_pagedDataSource=null;
$this->clearViewState('ItemCount');
$this->clearViewState('PageCount');
$this->clearViewState('DataSourceCount');
}
+ $this->_pagedDataSource=null;
}
/**
diff --git a/framework/Web/UI/WebControls/TDataList.php b/framework/Web/UI/WebControls/TDataList.php
index 825bb9db..0bdeb4a4 100644
--- a/framework/Web/UI/WebControls/TDataList.php
+++ b/framework/Web/UI/WebControls/TDataList.php
@@ -1107,32 +1107,29 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
$keys->clear();
$keyField=$this->getDataKeyField();
$itemIndex=0;
- if($data instanceof Traversable)
+ $items=$this->getItems();
+ $hasSeparator=$this->_separatorTemplate!==null;
+ $selectedIndex=$this->getSelectedItemIndex();
+ $editIndex=$this->getEditItemIndex();
+ foreach($data as $dataItem)
{
- $items=$this->getItems();
- $hasSeparator=$this->_separatorTemplate!==null;
- $selectedIndex=$this->getSelectedItemIndex();
- $editIndex=$this->getEditItemIndex();
- foreach($data as $dataItem)
- {
- if($keyField!=='')
- $keys->add($this->getDataFieldValue($dataItem,$keyField));
- if($itemIndex===0 && $this->_headerTemplate!==null)
- $this->_header=$this->createItemInternal(-1,'Header',true,null);
- if($hasSeparator && $itemIndex>0)
- $this->createItemInternal($itemIndex-1,'Separator',true,null);
- if($itemIndex===$editIndex)
- $itemType='EditItem';
- else if($itemIndex===$selectedIndex)
- $itemType='SelectedItem';
- else
- $itemType=$itemIndex%2?'AlternatingItem':'Item';
- $items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
- $itemIndex++;
- }
- if($itemIndex>0 && $this->_footerTemplate!==null)
- $this->_footer=$this->createItemInternal(-1,'Footer',true,null);
+ if($keyField!=='')
+ $keys->add($this->getDataFieldValue($dataItem,$keyField));
+ if($itemIndex===0 && $this->_headerTemplate!==null)
+ $this->_header=$this->createItemInternal(-1,'Header',true,null);
+ if($hasSeparator && $itemIndex>0)
+ $this->createItemInternal($itemIndex-1,'Separator',true,null);
+ if($itemIndex===$editIndex)
+ $itemType='EditItem';
+ else if($itemIndex===$selectedIndex)
+ $itemType='SelectedItem';
+ else
+ $itemType=$itemIndex%2?'AlternatingItem':'Item';
+ $items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
+ $itemIndex++;
}
+ if($itemIndex>0 && $this->_footerTemplate!==null)
+ $this->_footer=$this->createItemInternal(-1,'Footer',true,null);
$this->setViewState('ItemCount',$itemIndex,0);
}
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index 00381890..169cc72c 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -151,8 +151,6 @@ abstract class TListControl extends TDataBoundControl
$items=$this->getItems();
if(!$this->getAppendDataBoundItems())
$items->clear();
- if(!($data instanceof Traversable))
- return;
$textField=$this->getDataTextField();
if($textField==='')
$textField=0;
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php
index 65b3106e..716478b8 100644
--- a/framework/Web/UI/WebControls/TRepeater.php
+++ b/framework/Web/UI/WebControls/TRepeater.php
@@ -374,22 +374,19 @@ class TRepeater extends TDataBoundControl implements INamingContainer
$this->reset();
$items=$this->getItems();
$itemIndex=0;
- if($data instanceof Traversable)
+ $hasSeparator=$this->_separatorTemplate!==null;
+ foreach($data as $dataItem)
{
- $hasSeparator=$this->_separatorTemplate!==null;
- foreach($data as $dataItem)
- {
- if($itemIndex===0 && $this->_headerTemplate!==null)
- $this->_header=$this->createItemInternal(-1,'Header',true,null);
- if($hasSeparator && $itemIndex>0)
- $this->createItemInternal($itemIndex-1,'Separator',true,null);
- $itemType=$itemIndex%2==0?'Item':'AlternatingItem';
- $items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
- $itemIndex++;
- }
- if($itemIndex>0 && $this->_footerTemplate!==null)
- $this->_footer=$this->createItemInternal(-1,'Footer',true,null);
+ if($itemIndex===0 && $this->_headerTemplate!==null)
+ $this->_header=$this->createItemInternal(-1,'Header',true,null);
+ if($hasSeparator && $itemIndex>0)
+ $this->createItemInternal($itemIndex-1,'Separator',true,null);
+ $itemType=$itemIndex%2==0?'Item':'AlternatingItem';
+ $items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
+ $itemIndex++;
}
+ if($itemIndex>0 && $this->_footerTemplate!==null)
+ $this->_footer=$this->createItemInternal(-1,'Footer',true,null);
$this->setViewState('ItemCount',$itemIndex,0);
}